Ejemplo n.º 1
0
    def req_ipv6_tunnel_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        log_path = os.path.join(data_path, "ipv6_tunnel.log")
        time_now = datetime.datetime.today().strftime('%H:%M:%S-%a/%d/%b/%Y')

        client_ip = self.client_address[0]
        is_local = client_ip.endswith("127.0.0.1") or client_ip == "::1"

        if reqs['cmd'] in [['enable'],
                           ['disable'],
                           ['test_teredo'],
                           ['test_teredo_usability'],
                           ['test_teredo_server'],
                           ['set_best_server']]:
            cmd = reqs['cmd'][0]
            xlog.info("ipv6_tunnel switch %s", cmd)

            # Don't remove log file at here.

            if cmd == "enable":
                result = ipv6_tunnel.enable(is_local)
            elif cmd == "disable":
                result = ipv6_tunnel.disable(is_local)
            elif cmd == "test_teredo":
                result = ipv6_tunnel.test_teredo()
            elif cmd == "test_teredo_usability":
                result = ipv6_tunnel.test_teredo(probe_server=False)
            elif cmd == "test_teredo_server":
                result = ipv6_tunnel.test_teredo(probe_nat=False)
            elif cmd == "set_best_server":
                result = ipv6_tunnel.set_best_server(is_local)
            else:
                xlog.warn("unknown cmd:%s", cmd)

            xlog.info("ipv6_tunnel switch %s, result: %s", cmd, result)

            data = json.dumps({'res': result, 'time': time_now})

        elif reqs['cmd'] == ['get_log']:
            if os.path.isfile(log_path):
                with open(log_path, "r") as f:
                    content = f.read()
            else:
                content = ""

            status = ipv6_tunnel.state()

            data = json.dumps({'status': status, 'log': content.decode("GBK"), 'time': time_now})

        elif reqs['cmd'] == ['get_priority']:
            data = json.dumps({'res': ipv6_tunnel.state_pp(), 'time': time_now})

        elif reqs['cmd'] == ['switch_pp']:
            data = json.dumps({'res': ipv6_tunnel.switch_pp(), 'time': time_now})

        self.send_response_nc('text/html', data)
Ejemplo n.º 2
0
    def req_ipv6_tunnel_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        log_path = os.path.join(data_path, "ipv6_tunnel.log")
        time_now = datetime.datetime.today().strftime('%H:%M:%S-%a/%d/%b/%Y')

        client_ip = self.client_address[0]
        is_local = client_ip.endswith("127.0.0.1") or client_ip == "::1"

        if reqs['cmd'] in [['enable'],
                           ['disable'],
                           ['test_teredo'],
                           ['test_teredo_usability'],
                           ['test_teredo_server'],
                           ['set_best_server']]:
            cmd = reqs['cmd'][0]
            xlog.info("ipv6_tunnel switch %s", cmd)

            # Don't remove log file at here.

            if cmd == "enable":
                result = ipv6_tunnel.enable(is_local)
            elif cmd == "disable":
                result = ipv6_tunnel.disable(is_local)
            elif cmd == "test_teredo":
                result = ipv6_tunnel.test_teredo()
            elif cmd == "test_teredo_usability":
                result = ipv6_tunnel.test_teredo(probe_server=False)
            elif cmd == "test_teredo_server":
                result = ipv6_tunnel.test_teredo(probe_nat=False)
            elif cmd == "set_best_server":
                result = ipv6_tunnel.set_best_server(is_local)
            else:
                xlog.warn("unknown cmd:%s", cmd)

            xlog.info("ipv6_tunnel switch %s, result: %s", cmd, result)

            data = json.dumps({'res': result, 'time': time_now})

        elif reqs['cmd'] == ['get_log']:
            if os.path.isfile(log_path):
                with open(log_path, "r") as f:
                    content = f.read()
            else:
                content = ""

            status = ipv6_tunnel.state()

            data = json.dumps({'status': status, 'log': content.decode("GBK"), 'time': time_now})

        elif reqs['cmd'] == ['get_priority']:
            data = json.dumps({'res': ipv6_tunnel.state_pp(), 'time': time_now})

        elif reqs['cmd'] == ['switch_pp']:
            data = json.dumps({'res': ipv6_tunnel.switch_pp(), 'time': time_now})

        self.send_response_nc('text/html', data)
Ejemplo n.º 3
0
    def req_ipv6_tunnel_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        log_path = os.path.join(data_path, "ipv6_tunnel.log")
        time_now = datetime.datetime.today().strftime('%H:%M:%S-%a/%d/%b/%Y')

        if reqs['cmd'] in [['enable'], ['disable']]:
            cmd = reqs['cmd'][0]
            xlog.info("ipv6_tunnel switch %s", cmd)

            if os.path.isfile(log_path):
                try:
                    os.remove(log_path)
                except Exception as e:
                    xlog.warn("remove %s fail:%r", log_path, e)

            if cmd == "enable":
                ipv6_tunnel.enable()
            elif cmd == "disable":
                ipv6_tunnel.disable()
            else:
                xlog.warn("unknown cmd:%s", cmd)

            data = '{"res":"success", "time":"%s"}' % time_now

        elif reqs['cmd'] == ['get_log']:
            if os.path.isfile(log_path):
                with open(log_path, "r") as f:
                    content = f.read()
            else:
                content = ""

            status = ipv6_tunnel.state()

            data = json.dumps({
                'status': status,
                'log': content.decode("GBK"),
                'time': time_now
            })

        self.send_response_nc('text/html', data)
Ejemplo n.º 4
0
    def req_ipv6_tunnel_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        log_path = os.path.join(data_path, "ipv6_tunnel.log")
        time_now = datetime.datetime.today().strftime('%H:%M:%S-%a/%d/%b/%Y')

        if reqs['cmd'] in [['enable'], ['disable']]:
            cmd = reqs['cmd'][0]
            xlog.info("ipv6_tunnel switch %s", cmd)

            if os.path.isfile(log_path):
                try:
                    os.remove(log_path)
                except Exception as e:
                    xlog.warn("remove %s fail:%r", log_path, e)

            if cmd == "enable":
                ipv6_tunnel.enable()
            elif cmd == "disable":
                ipv6_tunnel.disable()
            else:
                xlog.warn("unknown cmd:%s", cmd)

            data = '{"res":"success", "time":"%s"}' % time_now

        elif reqs['cmd'] == ['get_log']:
            if os.path.isfile(log_path):
                with open(log_path, "r") as f:
                    content = f.read()
            else:
                content = ""

            status = ipv6_tunnel.state()

            data = json.dumps({'status': status, 'log': content.decode("GBK"), 'time': time_now})

        self.send_response_nc('text/html', data)