def sendtestemail(): print "Content-type: text/plain\n" logging.basicConfig(filename='../logs/testemail.log', level=logging.DEBUG) try: conlen = int(os.environ['CONTENT_LENGTH']) rawinp = sys.stdin.read(conlen) except Exception: rawinp = sys.stdin.read() print >> sys.stderr, rawinp if rawinp == '': res = {'status':'Error', 'error': 'No input given.'} print json.dumps (res) sys.exit() data = json.loads(rawinp) password = data['password'] if not access.validPassword(password): access.incorrectPassword() emailConfig = data['emailConfig'] port = emailConfig['email_port'] if simpleemail.validport(port) != True: print json.dumps({'status': 'Error', 'error': simpleemail.validport(port)}) sys.exit(0) emailMsg = data['emailMsg'] simpleemail.sendemail(emailConfig, emailMsg)
try: conlen = int(os.environ['CONTENT_LENGTH']) rawinp = sys.stdin.read(conlen) except Exception: rawinp = sys.stdin.read() print >> sys.stderr, rawinp if rawinp == '': res = {'status':'Error', 'error': 'No input given.'} print json.dumps (res) sys.exit() data = json.loads(rawinp) logging.info(data); password = data['password'] if not access.validPassword(password): access.incorrectPassword() emailConfig = data['emailConfig'] emailMsg = data['emailMsg'] try: simpleemail.sendemail(emailConfig, emailMsg) except Exception, err: p_err = str(traceback.format_exc()) print json.dumps({'status': 'Error', 'error': 'Email was not sent.', 'pythonerror': p_err}) sys.exit(0) print json.dumps({'status':'OK', 'message': 'Email sent.'})
except Exception: res = {"status": "Error", "message": "Input must be in JSON format."} print json.dumps(res) sys.exit() print >> sys.stderr, rawinp conf = access.readConf() savedpassword = conf.get("password", "change") password = inp.get("password", "") if access.isDefaultPassword(savedpassword): access.changePassword() if not access.validPassword(password): access.incorrectPassword() action = inp.get("action", "") if action == "get": currentConfiguration(conf) emailSettings = conf.get("email", "") if action == "set": value = inp.get("value", "") if value == "": res = {"status": "Error", "message": "No value given."} print json.dumps(res) sys.exit()