def login(): if request.method == 'POST': # { k:v[0] for k, v in dict(request.form).items() } username = request.form.get('username') password = request.form.get('password') if not username or not password: print 2 return json.dumps({'code' : 1, 'errmsg' : 'your must input login username and password.'}) query_result = app.config['mysqlconn'].get_one_result(table_name='user', fields=['password', 'role'], where={'name':username}) if not query_result: return json.dumps({'code' : 1, 'errmsg' : 'user not exists.'}) if query_result.get('password') != hashlib.md5(password).hexdigest(): return json.dumps({'code' : 1, 'errmsg' : 'password error.'}) else: data = {'last_login_time' : time.strftime('%Y-%m-%d %H:%M:%S')} app.config['mysqlconn'].execute_update_sql(table_name='user', data=data, where={'name' : username}) role = query_result.get('role') token = create_token(username, role, app.config['passport']) decode_token_result = valid_token(token, app.config['passport']) session['token'] = token session['username'] = username return json.dumps({'code' : 0, 'result' : 'login sucessful.'}) return render_template('login.html')
def login(): if request.method == 'POST': # { k:v[0] for k, v in dict(request.form).items() } username = request.form.get('username') password = request.form.get('password') if not username or not password: print 2 return json.dumps({ 'code': 1, 'errmsg': 'your must input login username and password.' }) query_result = app.config['mysqlconn'].get_one_result( table_name='user', fields=['password', 'role'], where={'name': username}) if not query_result: return json.dumps({'code': 1, 'errmsg': 'user not exists.'}) if query_result.get('password') != hashlib.md5(password).hexdigest(): return json.dumps({'code': 1, 'errmsg': 'password error.'}) else: data = {'last_login_time': time.strftime('%Y-%m-%d %H:%M:%S')} app.config['mysqlconn'].execute_update_sql( table_name='user', data=data, where={'name': username}) role = query_result.get('role') token = create_token(username, role, app.config['passport']) decode_token_result = valid_token(token, app.config['passport']) session['token'] = token session['username'] = username return json.dumps({'code': 0, 'result': 'login sucessful.'}) return render_template('login.html')
return subprocess.check_output(code, shell=True) except subprocess.CalledProcessError as e: return e.output def trace(): import traceback, StringIO buff = StringIO.StringIO() traceback.print_exc(file=buff) return buff.getvalue() if __name__ == '__main__': print "Content-Type: application/json" print import os from utils import valid_token response = {} if not os.environ['REMOTE_ADDR'] == os.environ['SERVER_ADDR']: response['error'] = 'You can access this script only from same server ' + \ '(Service.php script)' elif valid_token(): try: response['result'] = shell_exec(stdin.read()) except Exception, e: response['error'] = e.args[0] response['trace'] = trace() else: response['error'] = "The token is invalid" stdout.write(json.serialize(response))
os.chdir('..') # where are in cgi-bin try: return subprocess.check_output(code, shell=True) except subprocess.CalledProcessError as e: return e.output def trace(): import traceback, StringIO buff = StringIO.StringIO() traceback.print_exc(file=buff) return buff.getvalue() if __name__ == '__main__': print "Content-Type: application/json" print import os from utils import valid_token response = {} if not os.environ['REMOTE_ADDR'] == os.environ['SERVER_ADDR']: response['error'] = 'You can access this script only from same server ' + \ '(Service.php script)' elif valid_token(): try: response['result'] = shell_exec(stdin.read()) except Exception, e: response['error'] = e.args[0] response['trace'] = trace() else: response['error'] = "The token is invalid" stdout.write(json.serialize(response))