Github user brutasse commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/106#discussion_r26112215 --- Diff: systemvm/patches/debian/config/opt/cloud/bin/passwd_server_ip.py --- @@ -0,0 +1,204 @@ +#!/usr/bin/env python +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# Client usage examples; +# Getting password: +# wget -q -t 3 -T 20 -O - --header "DomU_Request: send_my_password" <routerIP>:8080 +# Send ack: +# wget -t 3 -T 20 -O - --header "DomU_Request: saved_password" localhost:8080 +# Save password only from within router: +# /opt/cloud/bin/savepassword.sh -v <IP> -p <password> +# curl --header "DomU_Request: save_password" http://localhost:8080/ -F ip=<IP> -F password=<passwd> + +import binascii +import cgi +import os +import sys +import syslog +import threading +import time +import urlparse + +from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer +from SocketServer import ThreadingMixIn, ForkingMixIn + +# Global password map +passMap = {} +secureToken = None + +# Global passMap lock +lock = threading.Lock() + +def getTokenFile(): + return "/tmp/passwdsrvrtoken" + +def getPasswordFile(): + return "/var/cache/cloud/passwords" + +def initToken(): + global secureToken + f = open(getTokenFile(), "w") + secureToken = binascii.hexlify(os.urandom(16)) + f.write(secureToken) + f.close() + +def checkToken(token): + global secureToken + return token == secureToken + +def loadPasswordFile(): + global passMap + if os.path.exists(getPasswordFile()): + f = open(getPasswordFile(), "r") + data = f.read() + f.close() + for line in data.split("\n"): + splitLine = line.split("=") + if len(splitLine) == 2: + passMap[splitLine[0]] = splitLine[1] + +def savePasswordFile(): + global passMap, lock + lock.acquire() + try: + f = open(getPasswordFile(), "w") + for ip in passMap.keys(): + f.write("%s=%s\n" % (ip, passMap[ip])) + f.close() + except IOError, e: + syslog.syslog("serve_password: Unable to save to password file %s" % e) + finally: + lock.release() + +def getPassword(ip): + global passMap + if ip in passMap: + return passMap[ip] + return None + +def setPassword(ip, password): + global passMap, lock + if ip == None or ip == "" or password == None or password == "": --- End diff -- You could simply test for `if not ip or not password`
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---