Example #1
0
    def req_transfer_handler(self):
        to_account = self.postvars['to_account'][0]
        amount = float(self.postvars['amount'][0])
        transfer_type = self.postvars['transfer_type'][0]
        if transfer_type == 'balance':
            if amount > g.balance:
                reason = "balance not enough"
                xlog.warn("transfer fail:%s", reason)
                return self.response_json({"res": "fail", "reason": reason})
            end_time = 0
        elif transfer_type == "quota":
            end_time = int(self.postvars['end_time'][0])
        else:
            reason = "transfer type not support:%s" % transfer_type
            xlog.warn("transfer fail:%s", reason)
            return self.response_json({"res": "fail", "reason": reason})

        req_info = {
            "account": g.config.login_account,
            "password": g.config.login_password,
            "transfer_type": transfer_type,
            "end_time": end_time,
            "to_account": to_account,
            "amount": amount
        }

        res, info = proxy_session.call_api("/transfer", req_info)
        if not res:
            xlog.warn("transfer fail:%s", info)
            return self.response_json({"res": "fail", "reason": info})

        self.response_json({"res": "success"})
Example #2
0
    def req_transfer_handler(self):
        to_account = self.postvars['to_account'][0]
        amount = float(self.postvars['amount'][0])
        transfer_type = self.postvars['transfer_type'][0]
        if transfer_type == 'balance':
            if amount > g.balance:
                reason = "balance not enough"
                xlog.warn("transfer fail:%s", reason)
                return self.response_json({"res": "fail", "reason": reason})
            end_time = 0
        elif transfer_type == "quota":
            end_time = int(self.postvars['end_time'][0])
        else:
            reason = "transfer type not support:%s" % transfer_type
            xlog.warn("transfer fail:%s", reason)
            return self.response_json({"res": "fail", "reason": reason})

        req_info = {"account": g.config.login_account,
                    "password": g.config.login_password,
                    "transfer_type": transfer_type,
                    "end_time": end_time,
                    "to_account": to_account,
                    "amount": amount}

        res, info = proxy_session.call_api("transfer", req_info)
        if not res:
            xlog.warn("transfer fail:%s", info)
            return self.response_json({"res": "fail", "reason": info})

        self.response_json({"res": "success"})
Example #3
0
    def req_order_handler(self):
        product = self.postvars['product'][0]
        if product != 'x_tunnel':
            xlog.warn("x_tunnel order product %s not support", product)
            return self.response_json({
                "res":
                "fail",
                "reason":
                "product %s not support" % product
            })

        plan = self.postvars['plan'][0]
        if plan not in ["quarterly", "yearly"]:
            xlog.warn("x_tunnel order plan %s not support", plan)
            return self.response_json({
                "res": "fail",
                "reason": "plan %s not support" % plan
            })

        res, info = proxy_session.call_api(
            "/order", {
                "account": g.config.login_account,
                "password": g.config.login_password,
                "product": "x_tunnel",
                "plan": plan
            })
        if not res:
            xlog.warn("order fail:%s", info)
            return self.response_json({"res": "fail", "reason": info})

        self.response_json({"res": "success"})
Example #4
0
    def req_order_handler(self):
        product = self.postvars['product'][0]
        if product != 'x_tunnel':
            xlog.warn("x_tunnel order product %s not support", product)
            return self.response_json({
                "res": "fail",
                "reason": "product %s not support" % product
            })

        plan = self.postvars['plan'][0]
        if plan not in ["quarterly", "yearly"]:
            xlog.warn("x_tunnel order plan %s not support", plan)
            return self.response_json({
                "res": "fail",
                "reason": "plan %s not support" % plan
            })

        res, info = proxy_session.call_api("/order", {
            "account": g.config.login_account,
            "password": g.config.login_password,
            "product": "x_tunnel",
            "plan": plan
        })
        if not res:
            xlog.warn("order fail:%s", info)
            threading.Thread(target=proxy_session.update_quota_loop).start()
            return self.response_json({"res": "fail", "reason": info})

        self.response_json({"res": "success"})
Example #5
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)

        def is_server_available(server):
            if g.selectable and server == '':
                return True # "auto"
            else:
                for choice in g.selectable:
                    if choice[0] == server:
                        return True # "selectable"
                return False # "unselectable"

        if reqs['cmd'] == ['get']:
            g.config.load()
            server = {
                'selectable': g.selectable,
                'selected': 'auto' if g.config.server_host == '' else g.config.server_host,  # "auto" as default
                'available': is_server_available(g.config.server_host)
            }
            res = {
                'server': server,
                'promoter': g.promoter
            }
        elif reqs['cmd'] == ['set']:
            if 'server' in self.postvars:
                server = str(self.postvars['server'][0])
                server = '' if server == 'auto' else server

                promoter = self.postvars.get("promoter", [""])[0]
                if promoter != g.promoter:
                    res, info = proxy_session.call_api("/set_config", {
                        "account": g.config.login_account,
                        "password": g.config.login_password,
                        "promoter": promoter
                    })
                    if not res:
                        xlog.warn("set_config fail:%s", info)
                        return self.response_json({"res": "fail", "reason": info})
                    else:
                        g.promoter = promoter

                if is_server_available(server):
                    if server != g.config.server_host:
                        g.server_host = g.config.server_host = server
                        g.server_port = g.config.server_port = 443
                        g.config.save()

                        threading.Thread(target=g.session.reset).start()

                    res = {"res": "success"}
                else:
                    res = {
                        "res": "fail",
                        "reason": "server not available"
                    }
            else:
                res = {"res": "fail"}

        return self.response_json(res)
Example #6
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)

        def is_server_available(server):
            if g.selectable and server == '':
                return True # "auto"
            else:
                for choice in g.selectable:
                    if choice[0] == server:
                        return True # "selectable"
                return False # "unselectable"

        if reqs['cmd'] == ['get']:
            g.config.load()
            server = {
                'selectable': g.selectable,
                'selected': 'auto' if g.config.server_host == '' else g.config.server_host,  # "auto" as default
                'available': is_server_available(g.config.server_host)
            }
            res = {
                'server': server,
                'promoter': g.promoter
            }
        elif reqs['cmd'] == ['set']:
            if 'server' in self.postvars:
                server = str(self.postvars['server'][0])
                server = '' if server == 'auto' else server

                promoter = self.postvars.get("promoter", [""])[0]
                if promoter != g.promoter:
                    res, info = proxy_session.call_api("/set_config", {
                        "account": g.config.login_account,
                        "password": g.config.login_password,
                        "promoter": promoter
                    })
                    if not res:
                        xlog.warn("set_config fail:%s", info)
                        return self.response_json({"res": "fail", "reason": info})
                    else:
                        g.promoter = promoter

                if is_server_available(server):
                    if server != g.config.server_host:
                        g.server_host = g.config.server_host = server
                        g.server_port = g.config.server_port = 443
                        g.config.save()

                        threading.Thread(target=g.session.reset).start()

                    res = {"res": "success"}
                else:
                    res = {
                        "res": "fail",
                        "reason": "server not available"
                    }
            else:
                res = {"res": "fail"}

        return self.response_json(res)
Example #7
0
    def req_get_history_handler(self):
        req_info = {"account": g.config.login_account,
                    "password": g.config.login_password,
                    "start": int(self.postvars['start'][0]),
                    "end": int(self.postvars['end'][0]),
                    "limit": int(self.postvars['limit'][0]), }

        res, info = proxy_session.call_api("get_history", req_info)
        if not res:
            xlog.warn("get history fail:%s", info)
            return self.response_json({"res": "fail", "reason": info})

        self.response_json({"res": "success", "history": info["history"]})
Example #8
0
    def req_get_history_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)

        req_info = {
            "account": g.config.login_account,
            "password": g.config.login_password,
            "start": int(reqs['start'][0]),
            "end": int(reqs['end'][0]),
            "limit": int(reqs['limit'][0])
        }

        res, info = proxy_session.call_api("/get_history", req_info)
        if not res:
            xlog.warn("get history fail:%s", info)
            return self.response_json({"res": "fail", "reason": info})
        self.response_json({"res": "success", "history": info["history"]})
Example #9
0
    def req_get_history_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)

        req_info = {
            "account": g.config.login_account,
            "password": g.config.login_password,
            "start": int(reqs['start'][0]),
            "end": int(reqs['end'][0]),
            "limit": int(reqs['limit'][0])
        }

        res, info = proxy_session.call_api("/get_history", req_info)
        if not res:
            xlog.warn("get history fail:%s", info)
            return self.response_json({
                "res": "fail",
                "reason": info
            })
        self.response_json({
            "res": "success",
            "history": info["history"]
        })