diff --git a/README.md b/README.md index 48b55c6168..d4e9a23bd3 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ | 稳定性| 部分地区不稳定 | 稳定可用 | | 速度 | 流畅 | 下载快速,偶尔卡顿 | | 安全性| Google可看到通信内容 | 完全加密 | -| 易用 | 需扫描ip,部署服务端,导入证书 | 简单 | +| 易用 | 需开启Ipv6,部署服务端,导入证书 | 简单 | | 兼容性| 部分网站不支持 | 无问题 | | 收费 | 免费 | 付费 | @@ -22,10 +22,10 @@ ### 最新状态: - 2017-11-8 + 2017-11-9 * X-Tunnel 稳定. ([使用教程](https://github.com/XX-net/XX-Net/wiki/x-tunnel%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B)) -* GAE: 请升级到 3.7.12, 扫不到ip,请开启ipv6,请参考: +* GAE: 请升级到 3.7.13, 扫不到ip,请开启ipv6,请参考: [如何开启IPv6](https://github.com/XX-net/XX-Net/wiki/%E5%A6%82%E4%BD%95%E5%BC%80%E5%90%AFIPv6) diff --git a/code/default/download.md b/code/default/download.md index c8ea4d86b0..6830061f19 100644 --- a/code/default/download.md +++ b/code/default/download.md @@ -5,7 +5,7 @@ https://codeload.github.com/XX-net/XX-Net/zip/3.7.9 测试版(Test): -https://codeload.github.com/XX-net/XX-Net/zip/3.7.12 +https://codeload.github.com/XX-net/XX-Net/zip/3.7.13 Android: diff --git a/code/default/gae_proxy/ipv6_tunnel/switch.py b/code/default/gae_proxy/ipv6_tunnel/switch.py deleted file mode 100644 index cd998a6315..0000000000 --- a/code/default/gae_proxy/ipv6_tunnel/switch.py +++ /dev/null @@ -1,36 +0,0 @@ - -import os -import sys -import time - -current_path = os.path.dirname(os.path.abspath(__file__)) -root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) -top_path = os.path.abspath(os.path.join(root_path, os.pardir, os.pardir)) -data_path = os.path.abspath( os.path.join(top_path, 'data', 'gae_proxy')) - -python_path = os.path.abspath(os.path.join(root_path, 'python27', '1.0')) - -noarch_lib = os.path.abspath(os.path.join(python_path, 'lib', 'noarch')) -sys.path.append(noarch_lib) - -if sys.platform == "win32": - win32_lib = os.path.abspath(os.path.join(python_path, 'lib', 'win32')) - sys.path.append(win32_lib) -elif sys.platform.startswith("linux"): - linux_lib = os.path.abspath(os.path.join(python_path, 'lib', 'linux')) - sys.path.append(linux_lib) - - -from xlog import getLogger -log_file = os.path.join(data_path, "ipv6_tunnel.log") -xlog = getLogger("gae_proxy", file_name=log_file) - - -def main(): - for i in range(0, 10): - xlog.debug("log %d", i) - time.sleep(1) - - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/code/default/gae_proxy/ipv6_tunnel/win32/IPV6_note.TXT b/code/default/gae_proxy/ipv6_tunnel/win32/IPV6_note.TXT deleted file mode 100644 index dae03707e6..0000000000 --- a/code/default/gae_proxy/ipv6_tunnel/win32/IPV6_note.TXT +++ /dev/null @@ -1,104 +0,0 @@ -#ͣ�á�ip helper������ -net stop "ip helper" - -#���á�ip helper������ -net start "ip helper" - -#��ʾTeredo��Ϣ -netsh interface ipv6 show teredo - -#Teredo��6to4��isatap���� -netsh interface teredo set state default -netsh interface 6to4 set state default -netsh interface isatap set state default - -#�رպ�ж��Teredo��6to4��isatap -netsh interface teredo set state disable -netsh interface 6to4 set state disabled -netsh interface isatap set state disabled - -#��������Teredo -netsh interface Teredo set state type=default - -#����Teredo������ -netsh interface teredo set state server=teredo.remlab.net -netsh interface teredo set state server=teredo-debian.remlab.net -netsh interface teredo set state server=teredo.trex.fi - -#����Teredo������Ϊteredo.ipv6.microsoft.com����teredo���������ϣ� -netsh interface ipv6 set teredo client teredo.ipv6.microsoft.com - -#����isatap��������PING��ͨ�� -netsh int IPV6 isatap set router isatap.scu.edu.cn - -#�ֶ����Windows7��IPv6֧�ֵ�覴� -netsh interface IPV6 set global randomizeidentifiers=disabled - -#����Teredo -netsh interface ipv6 set teredo enterpriseclient -netsh int ter set state enterpriseclient - -#�ֶ����㣨IPv4�������ñ������ӣ�IPv6����ַ -#����IPv4��ַ -http://ip-lookup.net/conversion.php -#�ı�������IPv6��ַ -#����ǰ���� 48 - -#google ipv6 dns: -2001:4860:4860::8888 -2001:4860:4860::8844 - -#opendns ipv6 dns: -2620:0:ccc::2 -2620:0:ccd::2 - -#HE ipv6 dns: -2001:470:20::2 - -ipconfig /all -ipconfig /flushdns -netsh int ipv6 show int -netsh int ipv6 show route - -#����teredo״̬�Dz���qualified -netsh int ipv6 show teredo - -#ɾ�������· -route DELETE ::/0 - -#����·�� (��һ����������Ҫ��������һ��) -netsh int ipv6 add route ::/0 "Teredo Tunneling Pseudo-Interface" - -#�ڡ�start.bat���������������䣬ʵ��XXִ������ -netsh int ipv6 add route ::/0 "Teredo Tunneling Pseudo-Interface" -SET PYTHONPATH="%~dp0%start.vbs" console - -#���ȼ� -netsh int ipv6 show prefix -netsh int ipv6 set prefix 2002::/16 30 1 -netsh int ipv6 set prefix 2001::/32 5 1 - -#�鿴Teredo Tunneling Pseudo-Interface �ӿ� -route print - -#��ʾIPv6��ַ -netsh interface ipv6 show address - -#��ʾIPv6·�� -netsh interface ipv6 show route - -#����ipv6������������� -netsh interface ipv6 reset - -#����������"�������� 2"�����Լ�Ҫ�������������� -netsh interface set interface "�������� 2" disabled -netsh interface set interface "�������� 2" enabled - -#IPV6������վ�� - -http://test-ipv6.com/ -#ժҪ���ֲ�����ɺ��뵽��������Ŀ���в鿴����� -#ȫ�ǡ��ɹ������������ġ� - -http://www.kame.net/kame-mosaic.html -#IPv6���Կ�������ڹ꣬IPv4�ڹ겻�� \ No newline at end of file diff --git a/code/default/gae_proxy/ipv6_tunnel/win32/disable_ipv6.bat b/code/default/gae_proxy/ipv6_tunnel/win32/disable_ipv6.bat deleted file mode 100644 index 9058ab4759..0000000000 --- a/code/default/gae_proxy/ipv6_tunnel/win32/disable_ipv6.bat +++ /dev/null @@ -1,6 +0,0 @@ -@echo off - - -netsh interface teredo set state disable -netsh interface 6to4 set state disabled -netsh interface isatap set state disabled \ No newline at end of file diff --git a/code/default/gae_proxy/ipv6_tunnel/win32/enable_ipv6.bat b/code/default/gae_proxy/ipv6_tunnel/win32/enable_ipv6.bat deleted file mode 100644 index 03ad0523b2..0000000000 --- a/code/default/gae_proxy/ipv6_tunnel/win32/enable_ipv6.bat +++ /dev/null @@ -1,38 +0,0 @@ -@echo off - -net start "ip helper" -netsh int ipv6 reset - -netsh int teredo set state default -netsh int 6to4 set state default -netsh int isatap set state default -netsh int teredo set state server=teredo.remlab.net -netsh int ipv6 set teredo enterpriseclient -netsh int ter set state enterpriseclient -route DELETE ::/0 -netsh int ipv6 add route ::/0 "Teredo Tunneling Pseudo-Interface" -netsh int ipv6 set prefix 2002::/16 30 1 -netsh int ipv6 set prefix 2001::/32 5 1 -Reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Dnscache\Parameters /v AddrConfigControl /t REG_DWORD /d 0 /f - -netsh int teredo set state default -netsh int 6to4 set state default -netsh int isatap set state default -netsh int teredo set state server=teredo.remlab.net -netsh int ipv6 set teredo enterpriseclient -netsh int ter set state enterpriseclient -route DELETE ::/0 -netsh int ipv6 add route ::/0 "Teredo Tunneling Pseudo-Interface" -netsh int ipv6 set prefix 2002::/16 30 1 -netsh int ipv6 set prefix 2001::/32 5 1 -Reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Dnscache\Parameters /v AddrConfigControl /t REG_DWORD /d 0 /f - -ipconfig /all -ipconfig /flushdns -netsh int ipv6 show teredo -netsh int ipv6 show route -netsh int ipv6 show int -netsh int ipv6 show prefix -netsh int ipv6 show address -route print -cmd \ No newline at end of file diff --git a/code/default/gae_proxy/local/check_local_network.py b/code/default/gae_proxy/local/check_local_network.py index 0071575ade..420605354b 100644 --- a/code/default/gae_proxy/local/check_local_network.py +++ b/code/default/gae_proxy/local/check_local_network.py @@ -31,9 +31,6 @@ max_timeout = 5 -##################################### - - class CheckNetwork(object): def __init__(self, type="IPv4"): self.type = type @@ -53,7 +50,6 @@ def __init__(self, type="IPv4"): self.http_client = simple_http_client.Client(self.proxy, timeout=30) - def report_ok(self): self.network_stat = "OK" self.last_check_time = time.time() @@ -79,7 +75,6 @@ def is_ok(self): def _test_host(self, url): try: - header = { "user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36", "accept": "application/json, text/javascript, */*; q=0.01", @@ -135,7 +130,7 @@ def _triger_check_network(self, fail=False, force=False): if time_now - self.last_check_time < 10: return - self.last_check_time = time_now + self.last_check_time = time_now threading.Thread(target=self._simple_check_worker).start() @@ -168,9 +163,9 @@ def report_fail(ip): def is_ok(ip): if "." in ip: - IPv4.is_ok() + return IPv4.is_ok() else: - IPv6.is_ok() + return IPv6.is_ok() if __name__ == "__main__": diff --git a/code/default/gae_proxy/local/connect_manager.py b/code/default/gae_proxy/local/connect_manager.py index fde063d9ca..48ba95e948 100644 --- a/code/default/gae_proxy/local/connect_manager.py +++ b/code/default/gae_proxy/local/connect_manager.py @@ -15,51 +15,16 @@ every ssl connect can't change host after request. """ - -import os -import binascii import time -import socket -import struct import threading import operator -import socks - from xlog import getLogger xlog = getLogger("gae_proxy") -current_path = os.path.dirname(os.path.abspath(__file__)) -import OpenSSL -SSLError = OpenSSL.SSL.WantReadError - from config import config - - -def load_proxy_config(): - if config.PROXY_ENABLE: - if config.PROXY_TYPE == "HTTP": - proxy_type = socks.HTTP - elif config.PROXY_TYPE == "SOCKS4": - proxy_type = socks.SOCKS4 - elif config.PROXY_TYPE == "SOCKS5": - proxy_type = socks.SOCKS5 - else: - xlog.error("proxy type %s unknown, disable proxy", config.PROXY_TYPE) - config.PROXY_ENABLE = 0 - return - - socks.set_default_proxy(proxy_type, config.PROXY_HOST, config.PROXY_PORT, config.PROXY_USER, config.PROXY_PASSWD) -load_proxy_config() - - from google_ip import google_ip -from openssl_wrap import SSLConnection - -NetWorkIOError = (socket.error, SSLError, OpenSSL.SSL.Error, OSError) - -g_cacertfile = os.path.join(current_path, "cacert.pem") import connect_control import check_ip @@ -161,7 +126,7 @@ def get_need_keep_alive(self, maxtime=200): try: pool = tuple(self.pool) for sock in pool: - inactive_time = time.time() -sock.last_use_time + inactive_time = time.time() - sock.last_use_time # xlog.debug("inactive_time:%d", inactive_time * 1000) if inactive_time >= maxtime: return_list.append(sock) @@ -194,32 +159,18 @@ def to_string(self): i = 0 for item in pool: sock,t = item - out_str += "%d \t %s handshake:%d not_active_time:%d h2:%d\r\n" % (i, sock.ip, t, time.time() -sock.last_use_time, sock.h2) + out_str += "%d \t %s handshake:%d not_active_time:%d h2:%d\r\n" % (i, sock.ip, t, time.time() - sock.last_use_time, sock.h2) i += 1 finally: self.pool_lock.release() return out_str + class Https_connection_manager(object): thread_num_lock = threading.Lock() def __init__(self): - # http://docs.python.org/dev/library/ssl.html - # http://blog.ivanristic.com/2009/07/examples-of-the-information-collected-from-ssl-handshakes.html - # http://src.chromium.org/svn/trunk/src/net/third_party/nss/ssl/sslenum.c - # openssl s_server -accept 443 -key CA.crt -cert CA.crt - - # ref: http://vincent.bernat.im/en/blog/2011-ssl-session-reuse-rfc5077.html - self.openssl_context = SSLConnection.context_builder(ca_certs=g_cacertfile) - try: - self.openssl_context.set_session_id(binascii.b2a_hex(os.urandom(10))) - except: - pass - - if hasattr(OpenSSL.SSL, 'SESS_CACHE_BOTH'): - self.openssl_context.set_session_cache_mode(OpenSSL.SSL.SESS_CACHE_BOTH) - self.class_name = "Https_connection_manager" self.timeout = 4 self.max_timeout = 60 @@ -328,7 +279,7 @@ def connect_process(self): ip_str = google_ip.get_gws_ip() if not ip_str: time.sleep(60) - # xlog.warning("no enough ip") + xlog.warning("no enough ip") return #xlog.debug("create ssl conn %s", ip_str) @@ -411,8 +362,6 @@ def _create_ssl_connection(self, ip_port): ssl_sock = check_ip.connect_ssl(ip, port=443, timeout=self.timeout, check_cert=True, close_cb=google_ip.ssl_closed) - - google_ip.update_ip(ip, ssl_sock.handshake_time) xlog.debug("create_ssl update ip:%s time:%d h2:%d", ip, ssl_sock.handshake_time, ssl_sock.h2) @@ -427,7 +376,7 @@ def _create_ssl_connection(self, ip_port): if sock: sock.close() except Exception as e: - xlog.debug("%s fail:%r", ip, e) + xlog.debug("connect %s fail:%r", ip, e) google_ip.report_connect_fail(ip) connect_control.report_connect_fail() @@ -437,7 +386,6 @@ def _create_ssl_connection(self, ip_port): if sock: sock.close() finally: - connect_control.end_connect_register(high_prior=True) def get_ssl_connection(self, host=''): @@ -510,4 +458,6 @@ def get_new_ssl(self, only_h1=True): else: xlog.debug("get_new_ssl timeout fail.") return None + + https_manager = Https_connection_manager() diff --git a/code/default/gae_proxy/local/gae_handler.py b/code/default/gae_proxy/local/gae_handler.py index 66f91774e2..e220f99a17 100644 --- a/code/default/gae_proxy/local/gae_handler.py +++ b/code/default/gae_proxy/local/gae_handler.py @@ -194,7 +194,7 @@ def request_gae_server(headers, body, url, timeout): if not response: raise GAE_Exception(600, "fetch gae fail") - if response.status >= 500: + if response.status >= 600: raise GAE_Exception( response.status, "fetch gae fail:%d" % response.status) diff --git a/code/default/gae_proxy/local/ipv6_tunnel/__init__.py b/code/default/gae_proxy/local/ipv6_tunnel/__init__.py new file mode 100644 index 0000000000..abc2ff72f4 --- /dev/null +++ b/code/default/gae_proxy/local/ipv6_tunnel/__init__.py @@ -0,0 +1,18 @@ + +import os +import sys +import platform + +if "arm" in platform.machine(): + from .unknown import state, enable, disable +elif sys.platform == "win32": + # TODO: WinXP should be different + from .win10 import state, enable, disable +elif sys.platform.startswith("linux"): + from .linux import state, enable, disable +elif sys.platform == "darwin": + from .darwin import state, enable, disable +else: + from .unknown import state, enable, disable + + diff --git a/code/default/gae_proxy/local/ipv6_tunnel/common.py b/code/default/gae_proxy/local/ipv6_tunnel/common.py new file mode 100644 index 0000000000..3beab6268d --- /dev/null +++ b/code/default/gae_proxy/local/ipv6_tunnel/common.py @@ -0,0 +1,77 @@ +import os +import shlex +from subprocess import check_output + +current_path = os.path.dirname(os.path.abspath(__file__)) +root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir, os.pardir)) +data_path = os.path.abspath(os.path.join(root_path, os.pardir, os.pardir, 'data', "gae_proxy")) +if not os.path.isdir(data_path): + data_path = current_path + +log_file = os.path.join(data_path, "ipv6_tunnel.log") + +if os.path.isfile(log_file): + os.remove(log_file) + + +class Log(object): + def __init__(self): + self.fd = open(log_file, "w") + + def write(self, content): + self.fd.write(content + "\r\n") + self.fd.flush() + + +def best_server(): + # TODO: find and use the best server + # teredo.remlab.net / teredo - debian.remlab.net(Germany) + # teredo.ngix.ne.kr(South Korea) + # teredo.managemydedi.com(USA, Chicago) + # teredo.trex.fi(Finland) + # win8.ipv6.microsoft.com(The Teredo server hidden in Windows RT 8.1) of which Windows 7 has no knowledge. + # win10.ipv6.microsoft.com + return "teredo.remlab.net" + + +def run(cmd): + cmd = cmd.split() + out = check_output(cmd) + return out + + +def run_cmds(cmds): + log = Log() + cmd_pl = cmds.split("\n") + outs = [] + for cmd in cmd_pl: + if not cmd: + continue + + if cmd.startswith("#"): + log.write("%s" % cmd) + continue + + log.write("\n>: %s\n------------------------------------" % cmd) + cmd = shlex.split(cmd) + + try: + out = check_output(cmd) + except Exception as e: + out = "Exception:%r" % e + log.write(out) + outs.append(out) + return "\r\n".join(outs) + + +def get_line_value(r, n): + rls = r.split("\r\n") + if len(rls) < n + 1: + return None + + lp = rls[n].split(":") + if len(lp) < 2: + return None + + value = lp[1].strip() + return value diff --git a/code/default/gae_proxy/local/ipv6_tunnel/darwin.py b/code/default/gae_proxy/local/ipv6_tunnel/darwin.py new file mode 100644 index 0000000000..a4ce5e73f2 --- /dev/null +++ b/code/default/gae_proxy/local/ipv6_tunnel/darwin.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python2 +# coding:utf-8 + +import os +import sys +from .common import * + + +def state(): + return "Developing" + + +def enable(): + pass + + +def disable(): + pass diff --git a/code/default/gae_proxy/local/ipv6_tunnel/linux.py b/code/default/gae_proxy/local/ipv6_tunnel/linux.py new file mode 100644 index 0000000000..a4ce5e73f2 --- /dev/null +++ b/code/default/gae_proxy/local/ipv6_tunnel/linux.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python2 +# coding:utf-8 + +import os +import sys +from .common import * + + +def state(): + return "Developing" + + +def enable(): + pass + + +def disable(): + pass diff --git a/code/default/gae_proxy/local/ipv6_tunnel/unknown.py b/code/default/gae_proxy/local/ipv6_tunnel/unknown.py new file mode 100644 index 0000000000..e3d1f2d0f7 --- /dev/null +++ b/code/default/gae_proxy/local/ipv6_tunnel/unknown.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python2 +# coding:utf-8 + +import os +import sys +from .common import * + + +def state(): + return "Developing" + + +def enable(): + return "Developing" + + +def disable(): + return "Developing" diff --git a/code/default/gae_proxy/local/ipv6_tunnel/win10.py b/code/default/gae_proxy/local/ipv6_tunnel/win10.py new file mode 100644 index 0000000000..202c52f842 --- /dev/null +++ b/code/default/gae_proxy/local/ipv6_tunnel/win10.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python2 +# coding:utf-8 + +import os +import sys +import time +from .common import * + +current_path = os.path.dirname(os.path.abspath(__file__)) +python_path = os.path.abspath( os.path.join(current_path, os.pardir, os.pardir, 'python27', '1.0')) +root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) +data_path = os.path.abspath(os.path.join(root_path, os.pardir, os.pardir, 'data', "gae_proxy")) +if not os.path.isdir(data_path): + data_path = current_path + +if __name__ == "__main__": + noarch_lib = os.path.abspath( os.path.join(python_path, 'lib', 'noarch')) + sys.path.append(noarch_lib) + + if sys.platform == "win32": + win32_lib = os.path.abspath( os.path.join(python_path, 'lib', 'win32')) + sys.path.append(win32_lib) + + +from xlog import getLogger +xlog = getLogger("gae_proxy") + + +# TODO:Help to reset ipv6 if system Teredo Interface not exist +# download http://download.microsoft.com/download/3/F/3/3F3CA0F7-2FAF-4C51-8DDF-3516B4D91975/MicrosoftEasyFix20164.mini.diagcab + + +# TODO: Win7 need to change the interface name as the real one. +# can use ifconfig to get it. + +# TODO; Win10 Home and Win10 Profession is different. + +enable_cmds = """ +# Start +net start "ip helper" +netsh int ipv6 reset + +netsh int teredo set state default +netsh int 6to4 set state default +netsh int isatap set state default +netsh int teredo set state server=teredo.remlab.net +netsh int ipv6 set teredo enterpriseclient +netsh int ter set state enterpriseclient +route DELETE ::/0 +netsh int ipv6 add route ::/0 "Teredo Tunneling Pseudo-Interface" +netsh int ipv6 set prefix 2002::/16 30 1 +netsh int ipv6 set prefix 2001::/32 5 1 +Reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Dnscache\Parameters /v AddrConfigControl /t REG_DWORD /d 0 /f + +netsh int teredo set state default +netsh int 6to4 set state default +netsh int isatap set state default +netsh int teredo set state server=teredo.remlab.net +netsh int ipv6 set teredo enterpriseclient +netsh int ter set state enterpriseclient +route DELETE ::/0 +netsh int ipv6 add route ::/0 "Teredo Tunneling Pseudo-Interface" +netsh int ipv6 set prefix 2002::/16 30 1 +netsh int ipv6 set prefix 2001::/32 5 1 +Reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Dnscache\Parameters /v AddrConfigControl /t REG_DWORD /d 0 /f + +ipconfig /all +ipconfig /flushdns +netsh int ipv6 show teredo +netsh int ipv6 show route +netsh int ipv6 show int +netsh int ipv6 show prefix +netsh int ipv6 show address +route print + +# +# reboot system at first time. +# +""" + + +disable_cmds=""" +netsh interface teredo set state disable +netsh interface 6to4 set state disabled +netsh interface isatap set state disabled +""" + + +def elevate(cmd): + # use this if need admin + import win32elevate + try: + win32elevate.elevateAdminRun(cmd) + except Exception as e: + xlog.warning('elevate e:%r', e) + + +last_get_state_time = 0 +last_state = "unknown" + + +def get_teredo_interface(): + r = run("ifconfig /all") + last_state = get_line_value(r, 6) + + +def state(): + global last_get_state_time, last_state + if time.time() - last_get_state_time < 5: + return last_state + + last_get_state_time = time.time() + r = run("netsh interface Teredo show state") + last_state = get_line_value(r, 6) + if last_state == "offline": + last_state = "disable" + elif last_state in ["qualified", "dormant"]: + last_state = "enable" + + return last_state + + +def enable(): + new_enable_cmds = enable_cmds.replace("teredo.remlab.net", best_server()) + r = run_cmds(new_enable_cmds) + return r + + +def disable(): + r = run_cmds(disable_cmds) + return r + + +if __name__ == '__main__': + print enable() \ No newline at end of file diff --git a/code/default/gae_proxy/local/web_control.py b/code/default/gae_proxy/local/web_control.py index a2a04e1389..d05a0cb73b 100644 --- a/code/default/gae_proxy/local/web_control.py +++ b/code/default/gae_proxy/local/web_control.py @@ -15,11 +15,13 @@ import locale import time import hashlib +import ConfigParser -from xlog import getLogger - +import yaml +import simple_http_server +from xlog import getLogger xlog = getLogger("gae_proxy") from config import config from appids_manager import appid_manager @@ -27,29 +29,26 @@ from google_ip_range import ip_range from connect_manager import https_manager from scan_ip_log import scan_ip_log -import ConfigParser import connect_control import ip_utils import check_local_network import check_ip import cert_util -import simple_http_server import test_appid from http_dispatcher import http_dispatch import openssl_wrap +import ipv6_tunnel os.environ['HTTPS_PROXY'] = '' current_path = os.path.dirname(os.path.abspath(__file__)) + root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) top_path = os.path.abspath(os.path.join(root_path, os.pardir, os.pardir)) data_path = os.path.abspath( os.path.join(top_path, 'data', 'gae_proxy')) web_ui_path = os.path.join(current_path, os.path.pardir, "web_ui") -import yaml - - class User_special(object): def __init__(self): self.appid = '' @@ -183,11 +182,6 @@ def get_openssl_version(): deploy_proc = None -ipv6_tunnel_proc = None - - -def ipv6_tunnel_status(): - return "Developing" class ControlHandler(simple_http_server.HttpServerHandler): @@ -433,7 +427,7 @@ def req_status_handler(self): "ipv4_state": check_local_network.IPv4.get_stat(), "ipv6_state": check_local_network.IPv6.get_stat(), - "ipv6_tunnel": ipv6_tunnel_status(), + "ipv6_tunnel": ipv6_tunnel.state(), "ip_num": len(google_ip.gws_ip_list), "good_ipv4_num": google_ip.good_ipv4_num, "good_ipv6_num": google_ip.good_ipv6_num, @@ -802,7 +796,6 @@ def req_debug_handler(self): self.send_response_nc(mimetype, data) def req_ipv6_tunnel_handler(self): - global ipv6_tunnel_proc req = urlparse.urlparse(self.path).query reqs = urlparse.parse_qs(req, keep_blank_values=True) data = '' @@ -811,46 +804,34 @@ def req_ipv6_tunnel_handler(self): 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 ipv6_tunnel_proc and ipv6_tunnel_proc.poll() == None: - xlog.warn("ipv6_tunnel_proc is running, request denied.") - data = '{"res":"ipv6_tunnel_proc is running", "time":"%s"}' % time_now - - else: - cmd = reqs['cmd'][0] + if os.path.isfile(log_path): try: - if os.path.isfile(log_path): - os.remove(log_path) - - script_path = os.path.abspath(os.path.join(current_path, os.pardir, "ipv6_tunnel", 'switch.py')) - - args = [sys.executable, script_path, cmd] - - ipv6_tunnel_proc = subprocess.Popen(args) - xlog.info("ipv6_tunnel switch %s", cmd) - data = '{"res":"success", "time":"%s"}' % time_now + os.remove(log_path) except Exception as e: - data = '{"res":"%s", "time":"%s"}' % (e, time_now) + xlog.warn("remove %s fail:%r", log_path, e) - elif reqs['cmd'] == ['stop']: - if ipv6_tunnel_proc and ipv6_tunnel_proc.poll() == None: - ipv6_tunnel_proc.kill() - data = '{"res":"ipv6_tunnel is killed", "time":"%s"}' % time_now + if cmd == "enable": + ipv6_tunnel.enable() + elif cmd == "disable": + ipv6_tunnel.disable() else: - data = '{"res":"ipv6_tunnel is not running", "time":"%s"}' % time_now + xlog.warn("unknown cmd:%s", cmd) + + data = '{"res":"success", "time":"%s"}' % time_now elif reqs['cmd'] == ['get_log']: - if ipv6_tunnel_proc and os.path.isfile(log_path): + if os.path.isfile(log_path): with open(log_path, "r") as f: content = f.read() else: content = "" - if ipv6_tunnel_proc and ipv6_tunnel_proc.poll() == None: - status = 'running' - else: - status = ipv6_tunnel_status() + status = ipv6_tunnel.state() - data = json.dumps({'status': status, 'log': content, 'time': time_now}) + data = json.dumps({'status': status, 'log': content.decode("GBK"), 'time': time_now}) + + self.send_response_nc('text/html', data) - self.send_response_nc('text/html', data) \ No newline at end of file diff --git a/code/default/gae_proxy/web_ui/ipv6_tunnel.html b/code/default/gae_proxy/web_ui/ipv6_tunnel.html index a8cf1d8f57..f1d1ffea28 100644 --- a/code/default/gae_proxy/web_ui/ipv6_tunnel.html +++ b/code/default/gae_proxy/web_ui/ipv6_tunnel.html @@ -1,5 +1,5 @@ -