Beispiel #1
0
class Win_tray():
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "web_ui", "favicon.ico")
        self.systray = SysTrayIcon(icon_path, "XX-Net", self.make_menu(), self.on_quit, left_click=self.on_show, right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
            reg_path,
            0, winreg.KEY_ALL_ACCESS)

        proxy_setting = config.get(["modules", "launcher", "proxy"], "pac")
        if proxy_setting == "pac":
            self.on_enable_pac()
        elif proxy_setting == "gae":
            self.on_enable_gae_proxy()
        elif proxy_setting == "disable":
            # Don't disable proxy setting, just do nothing.
            pass
        else:
            xlog.warn("proxy_setting:%r", proxy_setting)

    def get_proxy_state(self):
        REG_PATH = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,REG_PATH,0, winreg.KEY_ALL_ACCESS)
        try:
            AutoConfigURL, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, 'AutoConfigURL')
            if AutoConfigURL:
                if AutoConfigURL == "http://127.0.0.1:8086/proxy.pac":
                    return "pac"
                else:
                    return "unknown"
        except Exception as e:
            pass

        try:
            ProxyEnable, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, 'ProxyEnable')
            if ProxyEnable:
                ProxyServer, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, 'ProxyServer')
                if ProxyServer == "127.0.0.1:8087":
                    return "gae"
                else:
                    return "unknown"
        except Exception as e:
            pass
        
        return "disable"

    def on_right_click(self):
        self.systray.update(menu=self.make_menu())
        self.systray._show_menu()

    def make_menu(self):
        import locale
        lang_code, code_page = locale.getdefaultlocale()

        proxy_stat = self.get_proxy_state()
        gae_proxy_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat=="gae" else 0
        pac_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat=="pac" else 0
        disable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat=="disable" else 0

        if lang_code == "zh_CN":
            menu_options = ((u"设置", None, self.on_show, 0),
                        (u"全局通过GAEProxy代理", None, self.on_enable_gae_proxy, gae_proxy_checked),
                        (u"全局PAC智能代理", None, self.on_enable_pac, pac_checked),
                        (u"取消全局代理", None, self.on_disable_proxy, disable_checked),
                        (u"重启 GAEProxy", None, self.on_restart_gae_proxy, 0))
        else:
            menu_options = ((u"Config", None, self.on_show, 0),
                        (u"Set Global GAEProxy Proxy", None, self.on_enable_gae_proxy, gae_proxy_checked),
                        (u"Set Global PAC Proxy", None, self.on_enable_pac, pac_checked),
                        (u"Disable Global Proxy", None, self.on_disable_proxy, disable_checked),
                        (u"Reset GAEProxy", None, self.on_restart_gae_proxy, 0))
        return menu_options

    def on_show(self, widget=None, data=None):
        self.show_control_web()

    def on_restart_gae_proxy(self, widget=None, data=None):
        module_init.stop_all()
        module_init.start_all_auto()

    def on_check_update(self, widget=None, data=None):
        update.check_update()

    def on_enable_gae_proxy(self, widget=None, data=None):
        win32_proxy_manager.set_proxy_server("127.0.0.1", 8087)
        config.set(["modules", "launcher", "proxy"], "gae")
        config.save()

    def on_enable_pac(self, widget=None, data=None):
        win32_proxy_manager.set_proxy_auto("http://127.0.0.1:8086/proxy.pac")
        config.set(["modules", "launcher", "proxy"], "pac")
        config.save()

    def on_disable_proxy(self, widget=None, data=None):
        win32_proxy_manager.disable_proxy()
        config.set(["modules", "launcher", "proxy"], "disable")
        config.save()

    def show_control_web(self, widget=None, data=None):
        host_port = config.get(["modules", "launcher", "control_port"], 8085)
        webbrowser.open("http://127.0.0.1:%s/" % host_port)
        ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)

    def on_quit(self, widget, data=None):
        proxy_setting = config.get(["modules", "launcher", "proxy"], "disable")
        if proxy_setting != "disable":
            win32_proxy_manager.disable_proxy()
        module_init.stop_all()
        nid = win32_adapter.NotifyData(self.systray._hwnd, 0)
        win32_adapter.Shell_NotifyIcon(2, ctypes.byref(nid))
        os._exit(0)

    def serve_forever(self):
        self.systray._message_loop_func()

    def dialog_yes_no(self, msg="msg", title="Title", data=None, callback=None):
        res = ctypes.windll.user32.MessageBoxW(None, msg, title, 1)
        # Yes:1 No:2
        if callback:
            callback(data, res)
        return res
Beispiel #2
0
class Win_tray():
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "web_ui",
                                 "favicon.ico")
        self.systray = SysTrayIcon(icon_path,
                                   "XX-Net",
                                   self.make_menu(),
                                   self.on_quit,
                                   left_click=self.on_show,
                                   right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                                                reg_path, 0,
                                                winreg.KEY_ALL_ACCESS)

    def get_proxy_state(self):
        REG_PATH = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER, REG_PATH,
                                           0, winreg.KEY_ALL_ACCESS)
        try:
            AutoConfigURL, reg_type = winreg.QueryValueEx(
                INTERNET_SETTINGS, 'AutoConfigURL')
            if AutoConfigURL:
                return "auto"
            ProxyEnable, reg_type = winreg.QueryValueEx(
                INTERNET_SETTINGS, 'ProxyEnable')
            if ProxyEnable:
                return "enable"
        except Exception as e:
            pass
        return "disable"

    def on_right_click(self):
        self.systray.update(menu=self.make_menu())
        self.systray._show_menu()

    def make_menu(self):
        import locale
        lang_code, code_page = locale.getdefaultlocale()

        proxy_stat = self.get_proxy_state()
        enable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "enable" else 0
        auto_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "auto" else 0
        disable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "disable" else 0

        if lang_code == "zh_CN":
            menu_options = ((u"设置", None, self.on_show,
                             0), (u"全局通过GoAgent代理", None, self.on_enable_proxy,
                                  enable_checked),
                            (u"全局PAC智能代理", None, self.on_enable_pac,
                             auto_checked),
                            (u"取消全局代理", None, self.on_disable_proxy,
                             disable_checked), (u"重启 GoAgent", None,
                                                self.on_restart_goagent, 0))
        else:
            menu_options = ((u"Config", None, self.on_show,
                             0), (u"Set Global GoAgent Proxy", None,
                                  self.on_enable_proxy, enable_checked),
                            (u"Set Global PAC Proxy", None, self.on_enable_pac,
                             auto_checked), (u"Disable Global Proxy", None,
                                             self.on_disable_proxy,
                                             disable_checked),
                            (u"Reset GoAgent", None, self.on_restart_goagent,
                             0))
        return menu_options

    def on_show(self, widget=None, data=None):
        self.show_control_web()

    def on_restart_goagent(self, widget=None, data=None):
        module_init.stop_all()
        module_init.start_all_auto()

    def on_check_update(self, widget=None, data=None):
        update.check_update()

    def set_register(self, reg_path, name, reg_type, value):
        #_, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, name)
        winreg.SetValueEx(reg_path, name, 0, reg_type, value)
        logging.info("set register path:%r name:%s type:%d value:%s", reg_path,
                     name, reg_type, value)

    def on_enable_proxy(self, widget=None, data=None):
        self.set_register(self.INTERNET_SETTINGS, 'AutoConfigURL', 1,
                          "")  # disable auto proxy
        self.set_register(self.INTERNET_SETTINGS, 'ProxyEnable', 4, 1)
        self.set_register(self.INTERNET_SETTINGS, 'ProxyOverride', 1,
                          '*.local;<local>')  # Bypass the proxy for localhost
        self.set_register(self.INTERNET_SETTINGS, 'ProxyServer', 1,
                          '127.0.0.1:8087')

    def on_enable_pac(self, widget=None, data=None):
        self.set_register(self.INTERNET_SETTINGS, 'ProxyEnable', 4,
                          0)  # disable goagent proxy
        self.set_register(self.INTERNET_SETTINGS, 'AutoConfigURL', 1,
                          "http://127.0.0.1:8086/proxy.pac")

    def on_disable_proxy(self, widget=None, data=None):
        self.set_register(self.INTERNET_SETTINGS, 'ProxyEnable', 4,
                          0)  # disable goagent proxy
        self.set_register(self.INTERNET_SETTINGS, 'AutoConfigURL', 1,
                          "")  # disable auto proxy

    def show_control_web(self, widget=None, data=None):
        webbrowser.open("http://127.0.0.1:8085/")
        ctypes.windll.user32.ShowWindow(
            ctypes.windll.kernel32.GetConsoleWindow(), 0)

    def on_quit(self, widget, data=None):
        pass

    def serve_forever(self):
        self.systray._message_loop_func()

    def dialog_yes_no(self,
                      msg="msg",
                      title="Title",
                      data=None,
                      callback=None):
        res = ctypes.windll.user32.MessageBoxW(None, msg, title, 1)
        # Yes:1 No:2
        if callback:
            callback(data, res)
        return res
Beispiel #3
0
class Win_tray():
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "web_ui",
                                 "favicon.ico")
        self.systray = SysTrayIcon(icon_path,
                                   "OSS-FTP",
                                   self.make_menu(),
                                   self.on_quit,
                                   left_click=self.on_show,
                                   right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                                                reg_path, 0,
                                                winreg.KEY_ALL_ACCESS)

    def get_proxy_state(self):
        REG_PATH = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER, REG_PATH,
                                           0, winreg.KEY_ALL_ACCESS)
        try:
            AutoConfigURL, reg_type = winreg.QueryValueEx(
                INTERNET_SETTINGS, 'AutoConfigURL')
            if AutoConfigURL:
                return "auto"
        except Exception as e:
            pass

        try:
            ProxyEnable, reg_type = winreg.QueryValueEx(
                INTERNET_SETTINGS, 'ProxyEnable')
            if ProxyEnable:
                return "enable"
        except Exception as e:
            pass
        return "disable"

    def on_right_click(self):
        self.systray.update(menu=self.make_menu())
        self.systray._show_menu()

    def make_menu(self):
        import locale
        lang_code, code_page = locale.getdefaultlocale()

        proxy_stat = self.get_proxy_state()
        enable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "enable" else 0
        auto_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "auto" else 0

        if lang_code == "zh_CN":
            menu_options = ((u"设置", None, self.on_show, 0),
                            (u"重启 OSS Ftp 代理服务器", None,
                             self.on_restart_ossftp_proxy, 0))
        else:
            menu_options = ((u"Config", None, self.on_show, 0),
                            (u"Restart OSS Ftp Proxy", None,
                             self.on_restart_ossftp_proxy, 0))
        return menu_options

    def on_show(self, widget=None, data=None):
        self.show_control_web()

    def on_restart_ossftp_proxy(self, widget=None, data=None):
        module_init.stop_all()
        module_init.start_all_auto()

    def on_check_update(self, widget=None, data=None):
        update.check_update()

    def show_control_web(self, widget=None, data=None):
        webbrowser.open("http://127.0.0.1:8192/")
        ctypes.windll.user32.ShowWindow(
            ctypes.windll.kernel32.GetConsoleWindow(), 0)

    def on_quit(self, widget, data=None):
        win32_proxy_manager.disable_proxy()

    def serve_forever(self):
        self.systray._message_loop_func()

    def dialog_yes_no(self,
                      msg="msg",
                      title="Title",
                      data=None,
                      callback=None):
        res = ctypes.windll.user32.MessageBoxW(None, msg, title, 1)
        # Yes:1 No:2
        if callback:
            callback(data, res)
        return res
Beispiel #4
0
class Win_tray:
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "icon",
                                 "favicon.ico")
        self.systray = SysTrayIcon(icon_path,
                                   "XX-Net",
                                   self.make_menu(),
                                   self.on_quit,
                                   left_click=self.on_show,
                                   right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                                                reg_path, 0,
                                                winreg.KEY_ALL_ACCESS)

        # proxy_setting = config.get(["modules", "launcher", "proxy"], "smart_router")
        # if proxy_setting == "pac":
        #     self.on_enable_pac()
        # elif proxy_setting == "gae":
        #     self.on_enable_gae_proxy()
        # elif proxy_setting == "x_tunnel":
        #     self.on_enable_x_tunnel()
        # elif proxy_setting == "smart_router":
        #     self.on_enable_smart_router()
        # elif proxy_setting == "disable":
        #     # Don't disable proxy setting, just do nothing.
        #     pass
        # else:
        #     xlog.warn("proxy_setting:%r", proxy_setting)

    def get_proxy_state(self):
        try:
            AutoConfigURL, reg_type = winreg.QueryValueEx(
                self.INTERNET_SETTINGS, 'AutoConfigURL')
            if AutoConfigURL:
                if AutoConfigURL == "https://www.txthinking.com/pac/white.pac":
                    return "pac"
                else:
                    return "unknown"
        except:
            pass

        try:
            ProxyEnable, reg_type = winreg.QueryValueEx(
                self.INTERNET_SETTINGS, 'ProxyEnable')
            if ProxyEnable:
                ProxyServer, reg_type = winreg.QueryValueEx(
                    self.INTERNET_SETTINGS, 'ProxyServer')
                if ProxyServer == "127.0.0.1:8087":
                    return "gae"
                if ProxyServer == "127.0.0.1:1080":
                    return "Socks5"
                else:
                    return "unknown"
        except:
            pass

        return "disable"

    def on_right_click(self):
        self.systray.update(menu=self.make_menu())
        self.systray._show_menu()

    def make_menu(self):
        global menu_options
        proxy_stat = self.get_proxy_state()
        proxy_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "disable" else 0
        pac_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "pac" else 0
        # x_tunnel_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "x_tunnel" else 0
        # smart_router_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "smart_router" else 0
        # pac_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "pac" else 0
        # disable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "disable" else 0

        if lang_code == "zh_CN":
            menu_options = [(u"设置(待完善)", None, self.on_show, 0)]
            # if config.get(["modules", "gae_proxy", "auto_start"], 0) == 1:
            # menu_options.append((u"全局通过GAEProxy代理", None, self.on_enable_gae_proxy, win32_adapter.fState.MFS_CHECKED))

            # if config.get(["modules", "x_tunnel", "auto_start"], 0) == 1:
            # menu_options.append((u"全局通过X-Tunnel代理", None, self.on_enable_x_tunnel, 0))

            # if config.get(["modules", "smart_router", "auto_start"], 0) == 1:
            # menu_options.append((u"全局通过智能路由代理", None, self.on_enable_smart_router, win32_adapter.fState.MFS_CHECKED))

            menu_options += [
                (u"全局PAC智能代理", None, self.on_enable_pac, pac_checked),
                (u"取消全局代理", None, self.on_disable_proxy, proxy_checked),
                (u'退出', None, SysTrayIcon.QUIT, False)
            ]

        return tuple(menu_options)

    def on_show(self, widget=None, data=None):
        self.show_control_web()

    def on_enable_gae_proxy(self, widget=None, data=None):
        win32_proxy_manager.set_proxy("127.0.0.1:8087")

    def on_enable_pac(self, widget=None, data=None):
        curr_path = os.path.dirname(os.path.abspath(__file__))
        try:
            cmd = r'""%s\brook_windows_386.exe" systemproxy -u https://www.txthinking.com/pac/white.pac"' % curr_path
            os.system(cmd)
            proxy_stat = self.get_proxy_state()
            if proxy_stat != "pac":
                logging.error("failed to enable pac!")
        except Exception:
            logging.error('on_enable_pac:%s' % traceback.format_exc())
        # win32_proxy_manager.set_proxy("https://www.txthinking.com/pac/white.pac")
        # config.set(["modules", "launcher", "proxy"], "pac")
        # config.save()

    def on_disable_proxy(self, widget=None, data=None):
        curr_path = os.path.dirname(os.path.abspath(__file__))
        try:
            cmd = r'""%s\brook_windows_386.exe" systemproxy -r"' % curr_path
            os.system(cmd)
            proxy_stat = self.get_proxy_state()
            if proxy_stat != "disable":
                logging.error("failed to disable pac!")
        except Exception:
            logging.error("on_disable_proxy:%s" % traceback.format_exc())
        # win32_proxy_manager.set_proxy("")
        # win32_proxy_manager.disable_proxy()
        # config.set(["modules", "launcher", "proxy"], "disable")
        # config.save()

    def show_control_web(self, widget=None, data=None):
        # host_port = config.get(["modules", "launcher", "control_port"], 8085)
        host_port = 8085
        webbrowser.open("http://127.0.0.1:%s/" % host_port)
        ctypes.windll.user32.ShowWindow(
            ctypes.windll.kernel32.GetConsoleWindow(), 0)

    def on_quit(self, widget, data=None):
        # proxy_setting = config.get(["modules", "launcher", "proxy"], "disable")
        # if proxy_setting != "disable":
        #     win32_proxy_manager.disable_proxy()
        # module_init.stop_all()
        cmd = 'taskkill /F /IM brook_windows_386.exe'
        os.system(cmd)
        nid = win32_adapter.NotifyData(self.systray._hwnd, 0)
        win32_adapter.Shell_NotifyIcon(2, ctypes.byref(nid))
        os._exit(0)

    def serve_forever(self):
        logging.info("\n\n[step3]:enter win_tray")
        self.systray._message_loop_func()

    def dialog_yes_no(self,
                      msg="msg",
                      title="Title",
                      data=None,
                      callback=None):
        res = ctypes.windll.user32.MessageBoxW(None, msg, title, 1)
        # Yes:1 No:2
        if callback:
            callback(data, res)
        return res
Beispiel #5
0
class Win_tray():
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "web_ui", "favicon.ico")
        self.systray = SysTrayIcon(icon_path, "XX-Net", self.make_menu(), self.on_quit, left_click=self.on_show, right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER, reg_path, 0, winreg.KEY_ALL_ACCESS)

        proxy_setting = config.os_proxy_mode
        if proxy_setting == "pac":
            self.on_enable_pac()
        elif proxy_setting == "gae":
            self.on_enable_gae_proxy()
        elif proxy_setting == "x_tunnel":
            self.on_enable_x_tunnel()
        elif proxy_setting == "smart_router":
            self.on_enable_smart_router()
        elif proxy_setting == "disable":
            # Don't disable proxy setting, just do nothing.
            pass
        else:
            xlog.warn("proxy_setting:%r", proxy_setting)

    def get_proxy_state(self):
        try:
            AutoConfigURL, reg_type = winreg.QueryValueEx(self.INTERNET_SETTINGS, 'AutoConfigURL')
            if AutoConfigURL:
                if AutoConfigURL == "http://127.0.0.1:8086/proxy.pac":
                    return "pac"
                else:
                    return "unknown"
        except:
            pass

        try:
            ProxyEnable, reg_type = winreg.QueryValueEx(self.INTERNET_SETTINGS, 'ProxyEnable')
            if ProxyEnable:
                ProxyServer, reg_type = winreg.QueryValueEx(self.INTERNET_SETTINGS, 'ProxyServer')
                if ProxyServer == "127.0.0.1:8087":
                    return "gae"
                if ProxyServer == "127.0.0.1:1080":
                    return "x_tunnel"
                if ProxyServer == "127.0.0.1:8086":
                    return "smart_router"
                else:
                    return "unknown"
        except:
            pass

        return "disable"

    def on_right_click(self):
        self.systray.update(menu=self.make_menu())
        self.systray._show_menu()

    def make_menu(self):
        proxy_stat = self.get_proxy_state()
        gae_proxy_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "gae" else 0
        x_tunnel_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "x_tunnel" else 0
        smart_router_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "smart_router" else 0
        pac_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "pac" else 0
        disable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "disable" else 0

        if lang_code == "zh_CN":
            menu_options = [("设置", None, self.on_show, 0)]
            if config.enable_gae_proxy == 1:
                menu_options.append(("全局通过GAEProxy代理", None, self.on_enable_gae_proxy, gae_proxy_checked))

            if config.enable_x_tunnel == 1:
                menu_options.append(("全局通过X-Tunnel代理", None, self.on_enable_x_tunnel, x_tunnel_checked))

            if config.enable_smart_router == 1:
                menu_options.append(("全局通过智能路由代理", None, self.on_enable_smart_router, smart_router_checked))

            menu_options += [
                ("全局PAC智能代理", None, self.on_enable_pac, pac_checked),
                ("取消全局代理", None, self.on_disable_proxy, disable_checked),
                ("重启各模块", None, self.on_restart_each_module, 0),
                ('退出', None, SysTrayIcon.QUIT, False)]
        else:
            menu_options = [("Config", None, self.on_show, 0)]
            if config.enable_gae_proxy == 1:
                menu_options.append(("Set Global GAEProxy Proxy", None, self.on_enable_gae_proxy, gae_proxy_checked))

            if config.enable_x_tunnel == 1:
                menu_options.append(("Set Global X-Tunnel Proxy", None, self.on_enable_x_tunnel, x_tunnel_checked))

            if config.enable_smart_router == 1:
                menu_options.append(("Set Global Smart-Router Proxy", None, self.on_enable_smart_router, smart_router_checked))

            menu_options += [
                ("Set Global PAC Proxy", None, self.on_enable_pac, pac_checked),
                ("Disable Global Proxy", None, self.on_disable_proxy, disable_checked),
                ("Reset Each module", None, self.on_restart_each_module, 0),
                ('Quit', None, SysTrayIcon.QUIT, False)]

        return tuple(menu_options)

    def on_show(self, widget=None, data=None):
        self.show_control_web()

    def on_restart_each_module(self, widget=None, data=None):
        module_init.stop_all()
        module_init.start_all_auto()

    def on_check_update(self, widget=None, data=None):
        update.check_update()

    def on_enable_gae_proxy(self, widget=None, data=None):
        win32_proxy_manager.set_proxy("127.0.0.1:8087")
        config.os_proxy_mode = "gae"
        config.save()

    def on_enable_x_tunnel(self, widget=None, data=None):
        win32_proxy_manager.set_proxy("127.0.0.1:1080")
        config.os_proxy_mode = "x_tunnel"
        config.save()

    def on_enable_smart_router(self, widget=None, data=None):
        win32_proxy_manager.set_proxy("127.0.0.1:8086")
        config.os_proxy_mode = "smart_router"
        config.save()

    def on_enable_pac(self, widget=None, data=None):
        win32_proxy_manager.set_proxy("http://127.0.0.1:8086/proxy.pac")
        config.os_proxy_mode = "pac"
        config.save()

    def on_disable_proxy(self, widget=None, data=None):
        win32_proxy_manager.disable_proxy()
        config.os_proxy_mode = "disable"
        config.save()

    def show_control_web(self, widget=None, data=None):
        host_port = config.control_port
        webbrowser.open("http://127.0.0.1:%s/" % host_port)
        ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)

    def on_quit(self, widget, data=None):
        if self.get_proxy_state() != "unknown":
            win32_proxy_manager.disable_proxy()

        module_init.stop_all()
        nid = win32_adapter.NotifyData(self.systray._hwnd, 0)
        win32_adapter.Shell_NotifyIcon(2, ctypes.byref(nid))
        os._exit(0)

    def serve_forever(self):
        self.systray._message_loop_func()

    def dialog_yes_no(self, msg="msg", title="Title", data=None, callback=None):
        res = ctypes.windll.user32.MessageBoxW(None, msg, title, 1)
        # Yes:1 No:2
        if callback:
            callback(data, res)
        return res
Beispiel #6
0
class Win_tray():
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "web_ui", "favicon.ico")
        self.systray = SysTrayIcon(icon_path, "OSS-FTP", self.make_menu(), self.on_quit, left_click=self.on_show, right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
            reg_path,
            0, winreg.KEY_ALL_ACCESS)

    def get_proxy_state(self):
        REG_PATH = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,REG_PATH,0, winreg.KEY_ALL_ACCESS)
        try:
            AutoConfigURL, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, 'AutoConfigURL')
            if AutoConfigURL:
                return "auto"
        except Exception as e:
            pass

        try:
            ProxyEnable, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, 'ProxyEnable')
            if ProxyEnable:
                return "enable"
        except Exception as e:
            pass
        return "disable"

    def on_right_click(self):
        self.systray.update(menu=self.make_menu())
        self.systray._show_menu()

    def make_menu(self):
        import locale
        lang_code, code_page = locale.getdefaultlocale()

        proxy_stat = self.get_proxy_state()
        enable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat=="enable" else 0
        auto_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat=="auto" else 0   

        if lang_code == "zh_CN":
            menu_options = ((u"设置", None, self.on_show, 0),
                        (u"重启 OSS Ftp 代理服务器", None, self.on_restart_ossftp_proxy, 0))
        else:
            menu_options = ((u"Config", None, self.on_show, 0),
                        (u"Restart OSS Ftp Proxy", None, self.on_restart_ossftp_proxy, 0))
        return menu_options

    def on_show(self, widget=None, data=None):
        self.show_control_web()

    def on_restart_ossftp_proxy(self, widget=None, data=None):
        module_init.stop_all()
        module_init.start_all_auto()

    def on_check_update(self, widget=None, data=None):
        update.check_update()

    def show_control_web(self, widget=None, data=None):
        webbrowser.open("http://127.0.0.1:8192/")
        ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)

    def on_quit(self, widget, data=None):
        win32_proxy_manager.disable_proxy()

    def serve_forever(self):
        self.systray._message_loop_func()

    def dialog_yes_no(self, msg="msg", title="Title", data=None, callback=None):
        res = ctypes.windll.user32.MessageBoxW(None, msg, title, 1)
        # Yes:1 No:2
        if callback:
            callback(data, res)
        return res
Beispiel #7
0
class Win_tray():
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "web_ui",
                                 "favicon.ico")
        self.systray = SysTrayIcon(icon_path,
                                   "XX-Net",
                                   self.make_menu(),
                                   self.on_quit,
                                   left_click=self.on_show,
                                   right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                                                reg_path, 0,
                                                winreg.KEY_ALL_ACCESS)

        proxy_setting = config.get(["modules", "launcher", "proxy"], "pac")
        if proxy_setting == "pac":
            self.on_enable_pac()
        elif proxy_setting == "gae":
            self.on_enable_gae_proxy()
        elif proxy_setting == "disable":
            # Don't disable proxy setting, just do nothing.
            pass
        else:
            xlog.warn("proxy_setting:%r", proxy_setting)

    def get_proxy_state(self):
        REG_PATH = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER, REG_PATH,
                                           0, winreg.KEY_ALL_ACCESS)
        try:
            AutoConfigURL, reg_type = winreg.QueryValueEx(
                INTERNET_SETTINGS, 'AutoConfigURL')
            if AutoConfigURL:
                if AutoConfigURL == "http://127.0.0.1:8086/proxy.pac":
                    return "pac"
                else:
                    return "unknown"
        except Exception as e:
            pass

        try:
            ProxyEnable, reg_type = winreg.QueryValueEx(
                INTERNET_SETTINGS, 'ProxyEnable')
            if ProxyEnable:
                ProxyServer, reg_type = winreg.QueryValueEx(
                    INTERNET_SETTINGS, 'ProxyServer')
                if ProxyServer == "127.0.0.1:8087":
                    return "gae"
                else:
                    return "unknown"
        except Exception as e:
            pass

        return "disable"

    def on_right_click(self):
        self.systray.update(menu=self.make_menu())
        self.systray._show_menu()

    def make_menu(self):
        import locale
        lang_code, code_page = locale.getdefaultlocale()

        proxy_stat = self.get_proxy_state()
        gae_proxy_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "gae" else 0
        pac_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "pac" else 0
        disable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat == "disable" else 0

        if lang_code == "zh_CN":
            menu_options = ((u"设置", None, self.on_show,
                             0), (u"全局通过GAEProxy代理", None,
                                  self.on_enable_gae_proxy, gae_proxy_checked),
                            (u"全局PAC智能代理", None, self.on_enable_pac,
                             pac_checked),
                            (u"取消全局代理", None, self.on_disable_proxy,
                             disable_checked), (u"重启 GAEProxy", None,
                                                self.on_restart_gae_proxy, 0))
        else:
            menu_options = ((u"Config", None, self.on_show,
                             0), (u"Set Global GAEProxy Proxy", None,
                                  self.on_enable_gae_proxy, gae_proxy_checked),
                            (u"Set Global PAC Proxy", None, self.on_enable_pac,
                             pac_checked), (u"Disable Global Proxy", None,
                                            self.on_disable_proxy,
                                            disable_checked),
                            (u"Reset GAEProxy", None,
                             self.on_restart_gae_proxy, 0))
        return menu_options

    def on_show(self, widget=None, data=None):
        self.show_control_web()

    def on_restart_gae_proxy(self, widget=None, data=None):
        module_init.stop_all()
        module_init.start_all_auto()

    def on_check_update(self, widget=None, data=None):
        update.check_update()

    def on_enable_gae_proxy(self, widget=None, data=None):
        win32_proxy_manager.set_proxy_server("127.0.0.1", 8087)
        config.set(["modules", "launcher", "proxy"], "gae")
        config.save()

    def on_enable_pac(self, widget=None, data=None):
        win32_proxy_manager.set_proxy_auto("http://127.0.0.1:8086/proxy.pac")
        config.set(["modules", "launcher", "proxy"], "pac")
        config.save()

    def on_disable_proxy(self, widget=None, data=None):
        win32_proxy_manager.disable_proxy()
        config.set(["modules", "launcher", "proxy"], "disable")
        config.save()

    def show_control_web(self, widget=None, data=None):
        host_port = config.get(["modules", "launcher", "control_port"], 8085)
        webbrowser.open("http://127.0.0.1:%s/" % host_port)
        ctypes.windll.user32.ShowWindow(
            ctypes.windll.kernel32.GetConsoleWindow(), 0)

    def on_quit(self, widget, data=None):
        proxy_setting = config.get(["modules", "launcher", "proxy"], "disable")
        if proxy_setting != "disable":
            win32_proxy_manager.disable_proxy()
        module_init.stop_all()
        nid = win32_adapter.NotifyData(self.systray._hwnd, 0)
        win32_adapter.Shell_NotifyIcon(2, ctypes.byref(nid))
        os._exit(0)

    def serve_forever(self):
        self.systray._message_loop_func()

    def dialog_yes_no(self,
                      msg="msg",
                      title="Title",
                      data=None,
                      callback=None):
        res = ctypes.windll.user32.MessageBoxW(None, msg, title, 1)
        # Yes:1 No:2
        if callback:
            callback(data, res)
        return res
Beispiel #8
0
class Win_tray():
    def __init__(self):
        icon_path = os.path.join(os.path.dirname(__file__), "web_ui", "favicon.ico")
        self.systray = SysTrayIcon(icon_path, "XX-Net", self.make_menu(), self.on_quit, left_click=self.on_show, right_click=self.on_right_click)

        reg_path = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        self.INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
            reg_path,
            0, winreg.KEY_ALL_ACCESS)

    def get_proxy_state(self):
        REG_PATH = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
        INTERNET_SETTINGS = winreg.OpenKey(winreg.HKEY_CURRENT_USER,REG_PATH,0, winreg.KEY_ALL_ACCESS)
        try:
            AutoConfigURL, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, 'AutoConfigURL')
            if AutoConfigURL:
                return "auto"
            ProxyEnable, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, 'ProxyEnable')
            if ProxyEnable:
                return "enable"
        except Exception as e:
            pass
        return "disable"

    def on_right_click(self):
        self.systray.update(menu=self.make_menu())
        self.systray._show_menu()

    def make_menu(self):
        import locale
        lang_code, code_page = locale.getdefaultlocale()

        proxy_stat = self.get_proxy_state()
        enable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat=="enable" else 0
        auto_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat=="auto" else 0
        disable_checked = win32_adapter.fState.MFS_CHECKED if proxy_stat=="disable" else 0

        if lang_code == "zh_CN":
            menu_options = ((u"设置", None, self.on_show, 0),
                        (u"全局通过GoAgent代理", None, self.on_enable_proxy, enable_checked),
                        (u"全局PAC智能代理", None, self.on_enable_pac, auto_checked),
                        (u"取消全局代理", None, self.on_disable_proxy, disable_checked),
                        (u"重启 GoAgent", None, self.on_restart_goagent, 0))
        else:
            menu_options = ((u"Config", None, self.on_show, 0),
                        (u"Set Global GoAgent Proxy", None, self.on_enable_proxy, enable_checked),
                        (u"Set Global PAC Proxy", None, self.on_enable_pac, auto_checked),
                        (u"Disable Global Proxy", None, self.on_disable_proxy, disable_checked),
                        (u"Reset GoAgent", None, self.on_restart_goagent, 0))
        return menu_options

    def on_show(self, widget=None, data=None):
        self.show_control_web()


    def on_restart_goagent(self, widget=None, data=None):
        module_init.stop_all()
        module_init.start_all_auto()

    def on_check_update(self, widget=None, data=None):
        update.check_update()

    def set_register(self, reg_path, name, reg_type, value):
        #_, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, name)
        winreg.SetValueEx(reg_path, name, 0, reg_type, value)
        logging.info("set register path:%r name:%s type:%d value:%s", reg_path, name, reg_type, value)

    def on_enable_proxy(self, widget=None, data=None):
        self.set_register(self.INTERNET_SETTINGS, 'AutoConfigURL', 1, "") # disable auto proxy
        self.set_register(self.INTERNET_SETTINGS, 'ProxyEnable', 4, 1)
        self.set_register(self.INTERNET_SETTINGS, 'ProxyOverride', 1, '*.local;<local>')  # Bypass the proxy for localhost
        self.set_register(self.INTERNET_SETTINGS, 'ProxyServer', 1, '127.0.0.1:8087')

    def on_enable_pac(self, widget=None, data=None):
        self.set_register(self.INTERNET_SETTINGS, 'ProxyEnable', 4, 0) # disable goagent proxy
        self.set_register(self.INTERNET_SETTINGS, 'AutoConfigURL', 1, "http://127.0.0.1:8086/proxy.pac")

    def on_disable_proxy(self, widget=None, data=None):
        self.set_register(self.INTERNET_SETTINGS, 'ProxyEnable', 4, 0) # disable goagent proxy
        self.set_register(self.INTERNET_SETTINGS, 'AutoConfigURL', 1, "") # disable auto proxy

    def show_control_web(self, widget=None, data=None):
        webbrowser.open("http://127.0.0.1:8085/")
        ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 0)

    def on_quit(self, widget, data=None):
        pass

    def serve_forever(self):
        self.systray._message_loop_func()

    def dialog_yes_no(self, msg="msg", title="Title", data=None, callback=None):
        res = ctypes.windll.user32.MessageBoxW(None, msg, title, 1)
        # Yes:1 No:2
        if callback:
            callback(data, res)
        return res