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

        appid_updated = False

        try:
            if reqs['cmd'] == ['get_config']:
                ret_config = {
                    "appid": "|".join(config.GAE_APPIDS),
                    "auto_adjust_scan_ip_thread_num":
                    config.auto_adjust_scan_ip_thread_num,
                    "scan_ip_thread_num": config.max_scan_ip_thread_num,
                    "use_ipv6": config.use_ipv6,
                    "setting_level": config.setting_level,
                    "connect_receive_buffer": config.connect_receive_buffer,
                }
                data = json.dumps(ret_config, default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                appids = self.postvars['appid'][0]
                if appids != "|".join(config.GAE_APPIDS):
                    if appids and (front.ip_manager.good_ipv4_num +
                                   front.ip_manager.good_ipv6_num):
                        fail_appid_list = test_appids(appids)
                        if len(fail_appid_list):
                            fail_appid = "|".join(fail_appid_list)
                            data = json.dumps({
                                "res":
                                "fail",
                                "reason":
                                "appid fail:" + fail_appid
                            })
                            return

                    appid_updated = True
                    if appids:
                        xlog.info("set appids:%s", appids)
                        config.GAE_APPIDS = appids.split("|")
                    else:
                        config.GAE_APPIDS = []

                config.save()

                config.load()
                front.appid_manager.reset_appid()
                if appid_updated:
                    front.http_dispatcher.close_all_worker()

                front.ip_manager.reset()

                data = '{"res":"success"}'
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
            elif reqs['cmd'] == ['set_config_level']:
                setting_level = self.postvars['setting_level'][0]
                if setting_level:
                    xlog.info("set globa config level to %s", setting_level)
                    config.set_level(setting_level)
                    direct_config.set_level(setting_level)
                    front.ip_manager.load_config()
                    front.ip_manager.adjust_scan_thread_num()

                connect_receive_buffer = int(
                    self.postvars['connect_receive_buffer'][0])
                if 65536 <= connect_receive_buffer <= 2097152 and connect_receive_buffer != config.connect_receive_buffer:
                    xlog.info("set connect receive buffer to %dKB",
                              connect_receive_buffer // 1024)
                    config.connect_receive_buffer = connect_receive_buffer
                    config.save()
                    config.load()

                    front.connect_manager.new_conn_pool.clear()
                    direct_front.connect_manager.new_conn_pool.clear()
                    front.http_dispatcher.close_all_worker()
                    for _, http_dispatcher in direct_front.dispatchs.items():
                        http_dispatcher.close_all_worker()

                data = '{"res":"success"}'
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        finally:
            self.send_response_nc('text/html', data)
Exemplo n.º 2
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        appid_updated = False

        try:
            if reqs['cmd'] == ['get_config']:
                ret_config = {
                    "appid": "|".join(config.GAE_APPIDS),
                    "auto_adjust_scan_ip_thread_num": config.auto_adjust_scan_ip_thread_num,
                    "scan_ip_thread_num": config.max_scan_ip_thread_num,
                    "use_ipv6": config.use_ipv6,
                    "setting_level": config.setting_level,
                    "connect_receive_buffer": config.connect_receive_buffer,
                }
                data = json.dumps(ret_config, default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                appids = self.postvars['appid'][0]
                if appids != "|".join(config.GAE_APPIDS):
                    if appids and (front.ip_manager.good_ipv4_num + front.ip_manager.good_ipv6_num):
                        fail_appid_list = test_appids(appids)
                        if len(fail_appid_list):
                            fail_appid = "|".join(fail_appid_list)
                            data = json.dumps({"res": "fail",
                                               "reason": "appid fail:" + fail_appid
                                               })
                            return

                    appid_updated = True
                    if appids:
                        xlog.info("set appids:%s", appids)
                        config.GAE_APPIDS = appids.split("|")
                    else:
                        config.GAE_APPIDS = []

                config.save()

                config.load()
                front.appid_manager.reset_appid()
                if appid_updated:
                    front.http_dispatcher.close_all_worker()

                front.ip_manager.reset()

                data = '{"res":"success"}'
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
            elif reqs['cmd'] == ['set_config_level']:
                setting_level = self.postvars['setting_level'][0]
                if setting_level:
                    xlog.info("set globa config level to %s", setting_level)
                    config.set_level(setting_level)
                    direct_config.set_level(setting_level)
                    front.ip_manager.load_config()
                    front.ip_manager.adjust_scan_thread_num()
                    front.ip_manager.remove_slowest_ip()
                    front.ip_manager.search_more_ip()

                connect_receive_buffer = int(self.postvars['connect_receive_buffer'][0])
                if 8192 <= connect_receive_buffer <= 2097152 and connect_receive_buffer != config.connect_receive_buffer:
                    xlog.info("set connect receive buffer to %dKB", connect_receive_buffer // 1024)
                    config.connect_receive_buffer = connect_receive_buffer
                    config.save()
                    config.load()

                    front.connect_manager.new_conn_pool.clear()
                    direct_front.connect_manager.new_conn_pool.clear()
                    front.http_dispatcher.close_all_worker()
                    for _, http_dispatcher in direct_front.dispatchs.items():
                        http_dispatcher.close_all_worker()

                data = '{"res":"success"}'
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        finally:
            self.send_response_nc('text/html', data)