Exemplo n.º 1
0
def main():
    pre_start()

    connect_control.keep_running = True
    connect_manager.https_manager.load_config()
    xlog.debug("## GAEProxy set keep_running: %s",
               connect_control.keep_running)

    CertUtil.init_ca()

    proxy_daemon = simple_http_server.HTTPServer(
        (config.LISTEN_IP, config.LISTEN_PORT), proxy_handler.GAEProxyHandler)
    proxy_thread = threading.Thread(target=proxy_daemon.serve_forever)
    proxy_thread.setDaemon(True)
    proxy_thread.start()

    if config.PAC_ENABLE:
        pac_daemon = simple_http_server.HTTPServer(
            (config.PAC_IP, config.PAC_PORT), PACServerHandler)
        pac_thread = threading.Thread(target=pac_daemon.serve_forever)
        pac_thread.setDaemon(True)
        pac_thread.start()
        try:
            urllib2.urlopen('http://127.0.0.1:%d/%s' %
                            (config.PAC_PORT, config.PAC_FILE))
        except:
            pass

    while connect_control.keep_running:
        time.sleep(1)
Exemplo n.º 2
0
def main():
    pre_start()

    connect_control.keep_running = True
    connect_manager.https_manager.load_config()
    xlog.debug("## GAEProxy set keep_running: %s", connect_control.keep_running)

    CertUtil.init_ca()

    if config.LISTEN_USERNAME:
        proxy_handler.GAEProxyHandler.handler_filters.insert(0, simple_http_server.AuthFilter(config.LISTEN_USERNAME, config.LISTEN_PASSWORD))
    proxy_daemon = simple_http_server.HTTPServer((config.LISTEN_IP, config.LISTEN_PORT), proxy_handler.GAEProxyHandler)
    proxy_thread = threading.Thread(target=proxy_daemon.serve_forever)
    proxy_thread.setDaemon(True)
    proxy_thread.start()

    if config.PAC_ENABLE:
        pac_daemon = simple_http_server.HTTPServer((config.PAC_IP, config.PAC_PORT), PACServerHandler)
        pac_thread = threading.Thread(target=pac_daemon.serve_forever)
        pac_thread.setDaemon(True)
        pac_thread.start()
        urllib2.urlopen('http://127.0.0.1:%d/%s' % (config.PAC_PORT, config.PAC_FILE))

    while connect_control.keep_running:
        time.sleep(1)

    proxy_daemon.shutdown()
    proxy_daemon.server_close()
    proxy_thread.join()
    if config.PAC_ENABLE:
        pac_daemon.shutdown()
        pac_daemon.server_close()
        pac_thread.join()
Exemplo n.º 3
0
def main():
    global ready

    connect_control.keep_running = True
    config.load()
    connect_manager.https_manager.load_config()

    xlog.debug("## GAEProxy set keep_running: %s",
               connect_control.keep_running)
    # to profile gae_proxy, run proxy.py, visit some web by proxy, then visit http://127.0.0.1:8084/quit to quit and print result.
    do_profile = False
    if do_profile:
        import cProfile, pstats
        pr = cProfile.Profile()
        pr.enable()

    global __file__
    __file__ = os.path.abspath(__file__)
    if os.path.islink(__file__):
        __file__ = getattr(os, 'readlink', lambda x: x)(__file__)
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    #xlog.basicConfig(level=xlog.DEBUG if config.LISTEN_DEBUGINFO else xlog.INFO, format='%(levelname)s - %(asctime)s %(message)s', datefmt='[%b %d %H:%M:%S]')
    pre_start()
    log_info()

    CertUtil.init_ca()

    proxy_daemon = simple_http_server.HTTPServer(
        (config.LISTEN_IP, config.LISTEN_PORT), proxy_handler.GAEProxyHandler)
    proxy_thread = threading.Thread(target=proxy_daemon.serve_forever)
    proxy_thread.setDaemon(True)
    proxy_thread.start()

    if config.PAC_ENABLE:
        pac_daemon = simple_http_server.HTTPServer(
            (config.PAC_IP, config.PAC_PORT), pac_server.PACServerHandler)
        pac_thread = threading.Thread(target=pac_daemon.serve_forever)
        pac_thread.setDaemon(True)
        pac_thread.start()

    ready = True  # checked by launcher.module_init

    while connect_control.keep_running:
        time.sleep(1)

    xlog.info("Exiting gae_proxy module...")
    proxy_daemon.shutdown()
    proxy_daemon.server_close()
    proxy_thread.join()
    if config.PAC_ENABLE:
        pac_daemon.shutdown()
        pac_daemon.server_close()
        pac_thread.join()
    ready = False  # checked by launcher.module_init
    xlog.debug("## GAEProxy set keep_running: %s",
               connect_control.keep_running)

    if do_profile:
        pr.disable()
        pr.print_stats()
Exemplo n.º 4
0
def main():
    global ready
    for i in range(50):
        check_network = simple_check_worker()
        if check_network:
            break
        else:
            time.sleep(3)
        if (i + 1) % 5 == 0:
            xlog.error('Failed to connect to network, please check!')
        if i + 1 == 50: return
    pre_start()

    ip_range.load()
    google_ip.check()

    connect_control.keep_running = True
    connect_manager.https_manager.load_config()
    xlog.debug("## GAEProxy set keep_running: %s",
               connect_control.keep_running)

    CertUtil.init_ca()

    proxy_daemon = simple_http_server.HTTPServer(
        (config.LISTEN_IP, config.LISTEN_PORT), proxy_handler.GAEProxyHandler)
    proxy_thread = threading.Thread(target=proxy_daemon.serve_forever)
    proxy_thread.setDaemon(True)
    proxy_thread.start()

    if config.PAC_ENABLE:
        pac_daemon = simple_http_server.HTTPServer(
            (config.PAC_IP, config.PAC_PORT), PACServerHandler)
        pac_thread = threading.Thread(target=pac_daemon.serve_forever)
        pac_thread.setDaemon(True)
        pac_thread.start()
        urllib2.urlopen('http://127.0.0.1:%d/%s' %
                        (config.PAC_PORT, config.PAC_FILE))
        #PACServerHandler.do_GET()

    ready = True  # checked by launcher.module_init

    while connect_control.keep_running:
        time.sleep(1)

    xlog.info("Exiting gae_proxy module...")
    proxy_daemon.shutdown()
    proxy_daemon.server_close()
    proxy_thread.join()
    if config.PAC_ENABLE:
        pac_daemon.shutdown()
        pac_daemon.server_close()
        pac_thread.join()
    ready = False  # checked by launcher.module_init
    xlog.debug("## GAEProxy set keep_running: %s",
               connect_control.keep_running)
Exemplo n.º 5
0
def start(allow_remote=0):
    global server
    # should use config.yaml to bind ip
    if not allow_remote:
        allow_remote = config.allow_remote_connect
    host_ip = config.control_ip
    host_port = config.control_port

    if allow_remote:
        xlog.info("allow remote access WebUI")

    listen_ips = []
    if allow_remote and ("0.0.0.0" not in listen_ips
                         or "::" not in listen_ips):
        listen_ips.append("0.0.0.0")
    else:
        if isinstance(host_ip, str):
            listen_ips = [host_ip]
        else:
            listen_ips = list(host_ip)

    addresses = [(listen_ip, host_port) for listen_ip in listen_ips]

    xlog.info("begin to start web control")

    server = simple_http_server.HTTPServer(addresses,
                                           Http_Handler,
                                           logger=xlog)
    server.start()

    xlog.info("launcher web control started.")
Exemplo n.º 6
0
def main(args):
    global ready, proxy_server
    no_mess_system = args.get("no_mess_system", 0)
    allow_remote = args.get("allow_remote", 0)

    check_create_data_path()

    log_info()

    threading.Thread(target=CertUtil.init_ca, args=(no_mess_system, )).start()

    listen_ips = front.config.listen_ip
    if isinstance(listen_ips, str):
        listen_ips = [listen_ips]
    else:
        listen_ips = list(listen_ips)

    if allow_remote and ("0.0.0.0" not in listen_ips
                         or "::" not in listen_ips):
        listen_ips = [
            ("0.0.0.0"),
        ]
    addresses = [(listen_ip, front.config.listen_port)
                 for listen_ip in listen_ips]

    front.start()
    direct_front.start()

    proxy_server = simple_http_server.HTTPServer(addresses,
                                                 proxy_handler.GAEProxyHandler,
                                                 logger=xlog)

    ready = True  # checked by launcher.module_init

    proxy_server.serve_forever()
Exemplo n.º 7
0
def main(args):
    global ready
    load_config()
    front_dispatcher.init()
    g.data_path = data_path

    xlog.info("xxnet_version:%s", xxnet_version())

    g.running = True
    if not g.server_host or not g.server_port:
        if g.config.server_host and g.config.server_port == 443:
            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:
            pass
        else:
            xlog.debug("please check x-tunnel server in config")

    g.http_client = front_dispatcher

    g.session = proxy_session.ProxySession()

    allow_remote = args.get("allow_remote", 0)
    if allow_remote:
        listen_ip = "0.0.0.0"
    else:
        listen_ip = g.config.socks_host

    g.socks5_server = simple_http_server.HTTPServer((listen_ip, g.config.socks_port), Socks5Server, logger=xlog)
    xlog.info("Socks5 server listen:%s:%d.", g.config.socks_host, g.config.socks_port)

    ready = True
    g.socks5_server.serve_forever()
Exemplo n.º 8
0
def main(args):
    global ready, proxy_server

    check_create_data_path()

    log_info()

    CertUtil.init_ca()

    allow_remote = args.get("allow_remote", 0)

    listen_ips = front.config.listen_ip
    if isinstance(listen_ips, basestring):
        listen_ips = [listen_ips]
    else:
        listen_ips = list(listen_ips)
    if allow_remote and ("0.0.0.0" not in listen_ips
                         or "::" not in listen_ips):
        listen_ips.append("0.0.0.0")
    addresses = [(listen_ip, front.config.listen_port)
                 for listen_ip in listen_ips]

    front.start()
    direct_front.start()

    proxy_server = simple_http_server.HTTPServer(addresses,
                                                 proxy_handler.GAEProxyHandler,
                                                 logger=xlog)

    ready = True  # checked by launcher.module_init

    proxy_server.serve_forever()
Exemplo n.º 9
0
def main(args):
    global ready, proxy_server

    check_create_data_path()

    log_info()

    CertUtil.init_ca()

    allow_remote = args.get("allow_remote", 0)
    if allow_remote:
        listen_ip = "0.0.0.0"
    else:
        listen_ip = front.config.listen_ip

    front.start()
    direct_front.start()

    proxy_server = simple_http_server.HTTPServer(
        (listen_ip, front.config.listen_port),
        proxy_handler.GAEProxyHandler,
        logger=xlog)

    ready = True  # checked by launcher.module_init

    proxy_server.serve_forever()
Exemplo n.º 10
0
def run(args):
    global proc_handler, ready, g

    if not proc_handler:
        return False

    if "gae_proxy" in proc_handler:
        g.gae_proxy = proc_handler["gae_proxy"]["imp"].local
    else:
        xlog.debug("gae_proxy not running")

    if "x_tunnel" in proc_handler:
        g.x_tunnel = proc_handler["x_tunnel"]["imp"].local
    else:
        xlog.debug("x_tunnel not running")

    load_config()
    g.gfwlist = gfwlist.GfwList()
    g.ip_region = ip_region.IpRegion()

    g.domain_cache = host_records.DomainRecords(
        os.path.join(data_path, "domain_records.txt"),
        capacity=g.config.dns_cache_size,
        ttl=g.config.dns_ttl)
    g.ip_cache = host_records.IpRecord(os.path.join(data_path,
                                                    "ip_records.txt"),
                                       capacity=g.config.ip_cache_size)

    g.user_rules = user_rules.Config()

    connect_manager.load_proxy_config()
    g.connect_manager = connect_manager.ConnectManager()
    g.pipe_socks = pipe_socks.PipeSocks(g.config.pip_cache_size)
    g.pipe_socks.run()
    g.dns_client = dns_server.DnsClient()

    allow_remote = args.get("allow_remote", 0)
    if allow_remote:
        listen_ip = "0.0.0.0"
    else:
        listen_ip = g.config.proxy_bind_ip
    g.proxy_server = simple_http_server.HTTPServer(
        (listen_ip, g.config.proxy_port),
        proxy_handler.ProxyServer,
        logger=xlog)
    g.proxy_server.start()
    xlog.info("Proxy server listen:%s:%d.", listen_ip, g.config.proxy_port)

    allow_remote = args.get("allow_remote", 0)
    if allow_remote:
        listen_ip = "0.0.0.0"
    else:
        listen_ip = g.config.dns_bind_ip
    g.dns_srv = dns_server.DnsServer(bind_ip=listen_ip,
                                     port=g.config.dns_port,
                                     backup_port=g.config.dns_backup_port,
                                     ttl=g.config.dns_ttl)
    ready = True
    g.dns_srv.server_forever()
Exemplo n.º 11
0
def start(args):
    global proc_handler, ready, g

    if not proc_handler:
        return False

    if "gae_proxy" in proc_handler:
        g.gae_proxy = proc_handler["gae_proxy"]["imp"].local
        g.gae_proxy_listen_port = g.config.listen_port
    else:
        xlog.debug("gae_proxy not running")

    g.gfwlist = gfwlist.GfwList()
    g.ip_region = ip_region.IpRegion()
    g.user_rules = user_rules.Config()
    connect_manager.load_proxy_config()
    g.connect_manager = connect_manager.ConnectManager()
    g.pipe_socks = pipe_socks.PipeSocks(g.config.pip_cache_size)
    g.pipe_socks.run()
    g.dns_query = dns_query.CombineDnsQuery()

    allow_remote = args.get("allow_remote", 0)

    listen_ips = g.config.proxy_bind_ip
    if isinstance(listen_ips, str):
        listen_ips = [listen_ips]
    else:
        listen_ips = list(listen_ips)

    if allow_remote and ("0.0.0.0" not in listen_ips
                         or "::" not in listen_ips):
        listen_ips = [("0.0.0.0")]
    addresses = [(listen_ip, g.config.proxy_port) for listen_ip in listen_ips]

    g.proxy_server = simple_http_server.HTTPServer(addresses,
                                                   proxy_handler.ProxyServer,
                                                   logger=xlog)
    g.proxy_server.start()
    xlog.info("Proxy server listen:%s:%d.", listen_ips, g.config.proxy_port)

    listen_ips = g.config.dns_bind_ip
    if isinstance(listen_ips, str):
        listen_ips = [listen_ips]
    else:
        listen_ips = list(listen_ips)
    if allow_remote and ("0.0.0.0" not in listen_ips
                         or "::" not in listen_ips):
        listen_ips.append("0.0.0.0")

    g.dns_srv = dns_server.DnsServer(bind_ip=listen_ips,
                                     port=g.config.dns_port,
                                     backup_port=g.config.dns_backup_port,
                                     ttl=g.config.dns_ttl)
    ready = True
    g.dns_srv.server_forever()
Exemplo n.º 12
0
def main(args):
    global ready

    g.xxnet_version = xxnet_version()
    g.client_uuid = get_launcher_uuid()
    g.system = os_platform.platform + "|" + platform.version() + "|" + str(
        platform.architecture()) + "|" + sys.version

    load_config()
    front_dispatcher.init()
    g.data_path = data_path

    xlog.info("version:%s", g.xxnet_version)

    g.running = True
    if not g.server_host or not g.server_port:
        if g.config.server_host and g.config.server_port == 443:
            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:
            pass
        else:
            xlog.debug("please check x-tunnel server in config")

    g.http_client = front_dispatcher

    g.session = proxy_session.ProxySession()

    allow_remote = args.get("allow_remote", 0)

    listen_ips = g.config.socks_host
    if isinstance(listen_ips, str):
        listen_ips = [listen_ips]
    else:
        listen_ips = list(listen_ips)

    if allow_remote and ("0.0.0.0" not in listen_ips
                         or "::" not in listen_ips):
        listen_ips = [
            ("0.0.0.0"),
        ]
    addresses = [(listen_ip, g.config.socks_port) for listen_ip in listen_ips]

    g.socks5_server = simple_http_server.HTTPServer(addresses,
                                                    Socks5Server,
                                                    logger=xlog)
    xlog.info("Socks5 server listen:%s:%d.", g.config.socks_host,
              g.config.socks_port)

    ready = True
    g.socks5_server.serve_forever()
Exemplo n.º 13
0
def main():
    global ready
    load_config()
    g.cert = os.path.abspath(os.path.join(data_path, "CA.crt"))
    g.data_path = data_path

    start()

    g.socks5_server = simple_http_server.HTTPServer((g.config.socks_host, g.config.socks_port), Socks5Server)
    xlog.info("Socks5 server listen:%s:%d.", g.config.socks_host, g.config.socks_port)

    ready = True
    g.socks5_server.serve_forever()
Exemplo n.º 14
0
    def test_get(self):
        server = simple_http_server.HTTPServer(
            ('', 8880), simple_http_server.TestHttpServer, ".")
        server.start()

        client = simple_http_client.Client(timeout=5)
        url = "http://localhost:8880/test"
        res = client.request("GET", url)
        self.assertEqual(res.status, 200)
        content = utils.to_str(res.text)
        print(content)

        server.shutdown()
Exemplo n.º 15
0
def main():
    global ready
    load_config()
    g.data_path = data_path

    xlog.info("xxnet_version:%s", xxnet_version())

    start()

    g.socks5_server = simple_http_server.HTTPServer(
        (g.config.socks_host, g.config.socks_port), Socks5Server)
    xlog.info("Socks5 server listen:%s:%d.", g.config.socks_host,
              g.config.socks_port)

    ready = True
    g.socks5_server.serve_forever()
Exemplo n.º 16
0
def start(allow_remote=0):
    global server
    # should use config.yaml to bind ip
    if not allow_remote:
        allow_remote = config.get(["modules", "launcher", "allow_remote_connect"], 0)
    host_port = config.get(["modules", "launcher", "control_port"], 8085)

    if allow_remote:
        host_addr = "0.0.0.0"
        xlog.info("allow remote access WebUI")
    else:
        host_addr = "127.0.0.1"

    xlog.info("begin to start web control")

    server = simple_http_server.HTTPServer((host_addr, host_port), Http_Handler, logger=xlog)
    server.start()

    xlog.info("launcher web control started.")
Exemplo n.º 17
0
def start():
    global process, server
    # should use config.yaml to bing ip
    allow_remote = config.get(["modules", "launcher", "allow_remote_connect"], 0)
    host_port = config.get(["modules", "launcher", "control_port"], 8085)

    if allow_remote:
        host_addr = "0.0.0.0"
    else:
        host_addr = "127.0.0.1"

    xlog.info("begin to start web control")

    server = simple_http_server.HTTPServer((host_addr, host_port), Http_Handler)
    process = threading.Thread(target=server.serve_forever)
    process.setDaemon(True)
    process.start()
    
    xlog.info("launcher web control started.")
Exemplo n.º 18
0
def main(args):
    global ready
    load_config()
    g.data_path = data_path

    xlog.info("xxnet_version:%s", xxnet_version())

    start()

    allow_remote = args.get("allow_remote", 0)
    if allow_remote:
        listen_ip = "0.0.0.0"
    else:
        listen_ip = g.config.socks_host

    g.socks5_server = simple_http_server.HTTPServer((listen_ip, g.config.socks_port), Socks5Server, logger=xlog)
    xlog.info("Socks5 server listen:%s:%d.", g.config.socks_host, g.config.socks_port)

    ready = True
    g.socks5_server.serve_forever()
Exemplo n.º 19
0
    def __init__(self):
        self.xtunnel_login_status = False
        self.running = True

        self.pth = None
        self.log_fp = None
        self.log_fn = None

        # Lock for one integrate testing at the same time.
        # github act running in local will run multi python version in same VM, so we need to lock to avoid conflict.
        while True:
            try:
                res = simple_http_client.request("GET",
                                                 "http://127.0.0.1:8888/test")
                if res and res.status == 200:
                    time.sleep(1)
                    continue
                else:
                    break
            except:
                break

        self.lock_server = simple_http_server.HTTPServer(
            ('', 8888), simple_http_server.TestHttpServer, ".")
        self.lock_server.start()

        if self.check_web_console():
            xlog.info("APP was running externally.")
            self.th = None
            return

        self.log_fn = os.path.join(root_path, "running.log")
        if sys.version_info[0] == 3:
            self.log_fp = open(self.log_fn, "wb")
        else:
            self.log_fp = open(self.log_fn, "w")

        self.th = threading.Thread(target=self.start_xxnet)
        self.th.start()