def req_status_handler(self): if len(g.config.login_account) == 0 or len(g.config.login_password) == 0: return self.response_json({"res": "success", "login_account": ""}) if 'force' in self.postvars: force = int(self.postvars['force'][0]) else: force = False time_now = time.time() if force or time_now - g.last_refresh_time > 3600: g.last_refresh_time = time_now if g.session.running: update_server = False else: update_server = True res, reason = proxy_session.request_balance(g.config.login_account, g.config.login_password, is_register=False, update_server=update_server) if not res: return self.response_json( {"res": "fail", "login_account": "%s" % (g.config.login_account), "reason": reason}) if not g.session.running: g.session.start() res_arr = {"res": "success", "login_account": "%s" % (g.config.login_account), "balance": "%f" % (g.balance), "quota": "%d" % (g.quota), "quota_list": g.quota_list, "traffic": g.session.traffic } self.response_json(res_arr)
def req_login_handler(self): def check_email(email): import re if not re.match(r"[^@]+@[^@]+\.[^@]+", email): return False else: return True account = str(self.postvars['account'][0]) password = str(self.postvars['password'][0]) is_register = int(self.postvars['is_register'][0]) pa = check_email(account) if not pa: reason = "email invalid." return self.response_json({"res": "fail", "reason": reason}) elif len(password) < 6: reason = "password at least 6 charactor." return self.response_json({"res": "fail", "reason": reason}) password_hash = str(hashlib.sha256(password).hexdigest()) res, reason = proxy_session.request_balance(account, password_hash, is_register, update_server=True) if res: g.config.login_account = account g.config.login_password = password_hash g.config.save() res_arr = {"res": "success", "balance": float(g.balance)} g.last_refresh_time = time.time() g.session.start() else: res_arr = {"res": "fail", "reason": reason} return self.response_json(res_arr)
def req_login_handler(self): def check_email(email): import re if not re.match(r"[^@]+@[^@]+\.[^@]+", email): return False else: return True username = str(self.postvars['username'][0]) #username = utils.get_printable(username) password = str(self.postvars['password'][0]) promoter = self.postvars.get("promoter", [""])[0] is_register = int(self.postvars['is_register'][0]) pa = check_email(username) if not pa: return self.response_json({ "res": "fail", "reason": "Invalid email." }) elif len(password) < 6: return self.response_json({ "res": "fail", "reason": "Password needs at least 6 charactors." }) if password == "_HiddenPassword": if username == g.config.login_account and len(g.config.login_password): password_hash = g.config.login_password else: res_arr = { "res": "fail", "reason": "account not exist" } return self.response_json(res_arr) else: password_hash = str(hashlib.sha256(password).hexdigest()) res, reason = proxy_session.request_balance(username, password_hash, is_register, update_server=True, promoter=promoter) if res: g.config.login_account = username g.config.login_password = password_hash g.config.save() res_arr = { "res": "success", "balance": float(g.balance) } g.last_refresh_time = time.time() g.session.start() else: res_arr = { "res": "fail", "reason": reason } return self.response_json(res_arr)
def req_login_handler(self): def check_email(email): import re if not re.match(r"[^@]+@[^@]+\.[^@]+", email): return False else: return True username = str(self.postvars['username'][0]) password = str(self.postvars['password'][0]) promoter = self.postvars.get("promoter", [""])[0] is_register = int(self.postvars['is_register'][0]) pa = check_email(username) if not pa: return self.response_json({ "res": "fail", "reason": "Invalid email." }) elif len(password) < 6: return self.response_json({ "res": "fail", "reason": "Password needs at least 6 charactors." }) if password == "_HiddenPassword": if username == g.config.login_account and len(g.config.login_password): password_hash = g.config.login_password else: res_arr = { "res": "fail", "reason": "account not exist" } return self.response_json(res_arr) else: password_hash = str(hashlib.sha256(password).hexdigest()) res, reason = proxy_session.request_balance(username, password_hash, is_register, update_server=True, promoter=promoter) if res: g.config.login_account = username g.config.login_password = password_hash g.config.save() res_arr = { "res": "success", "balance": float(g.balance) } g.last_refresh_time = time.time() g.session.start() else: res_arr = { "res": "fail", "reason": reason } return self.response_json(res_arr)
def req_info_handler(self): if len(g.config.login_account) == 0 or len( g.config.login_password) == 0: return self.response_json({"res": "logout"}) req = urlparse.urlparse(self.path).query reqs = urlparse.parse_qs(req, keep_blank_values=True) force = False if 'force' in reqs: xlog.debug("req_info in force") force = 1 time_now = time.time() if force or time_now - g.last_refresh_time > 3600 or \ (g.last_api_error.startswith("status:") and (time_now - g.last_refresh_time > 30)): xlog.debug("x_tunnel force update info") g.last_refresh_time = time_now if g.session.running: update_server = False else: update_server = True res, reason = proxy_session.request_balance( g.config.login_account, g.config.login_password, is_register=False, update_server=update_server) if res: if g.quota and not g.session.running: g.session.start() if len(g.last_api_error) and g.last_api_error != 'balance not enough': res_arr = { "res": "fail", "login_account": "%s" % (g.config.login_account), "reason": g.last_api_error } else: res_arr = { "res": "success", "login_account": "%s" % (g.config.login_account), "balance": "%f" % (g.balance), "quota": "%d" % (g.quota), "quota_list": g.quota_list, "traffic": g.session.traffic, "last_fail": g.last_api_error } self.response_json(res_arr)
def req_info_handler(self): if len(g.config.login_account) == 0 or len(g.config.login_password) == 0: return self.response_json({ "res": "logout" }) req = urlparse.urlparse(self.path).query reqs = urlparse.parse_qs(req, keep_blank_values=True) force = False if 'force' in reqs: force = 1 time_now = time.time() if force or time_now - g.last_refresh_time > 3600 or \ (g.last_api_error.startswith("status:") and (time_now - g.last_refresh_time > 30)): xlog.debug("x_tunnel force update info") g.last_refresh_time = time_now if g.session.running: update_server = False else: update_server = True res, reason = proxy_session.request_balance( g.config.login_account, g.config.login_password, is_register=False, update_server=update_server) if res: if g.quota and not g.session.running: g.session.start() if len(g.last_api_error) and g.last_api_error != 'balance not enough': res_arr = { "res": "fail", "login_account": "%s" % (g.config.login_account), "reason": g.last_api_error } else: res_arr = { "res": "success", "login_account": "%s" % (g.config.login_account), "balance": "%f" % (g.balance), "quota": "%d" % (g.quota), "quota_list": g.quota_list, "traffic": g.session.traffic, "last_fail": g.last_api_error } self.response_json(res_arr)
def start(): if not g.server_host or not g.server_port: if g.config.server_host and g.config.server_port: xlog.info("Session Server:%s:%d", g.config.server_host, g.config.server_port) g.server_host = g.config.server_host g.server_port = g.config.server_port g.balance = 99999999 elif g.config.api_server: if not (g.config.login_account and g.config.login_password): xlog.debug("x-tunnel no account") else: res, reason = proxy_session.request_balance(g.config.login_account, g.config.login_password) if not res: xlog.warn("request_balance fail when start:%s", reason) else: xlog.debug("please check x-tunnel server in config") g.session = proxy_session.ProxySession()