コード例 #1
0
ファイル: update.py プロジェクト: ScalaGo/XX-Net
def get_uuid():
    if need_new_uuid():
        generate_new_uuid()

    xx_net_uuid = config.get(["update", "uuid"])
    launcher_log.info("get uuid:%s", xx_net_uuid)
    return xx_net_uuid
コード例 #2
0
ファイル: update.py プロジェクト: ScalaGo/XX-Net
def check_update():
    try:
        update_rule = config.get(["update", "check_update"], "stable")
        if update_rule == "dont-check":
            return

        check_push_update()

        if update_rule != "stable" and update_rule != "test":
            return

        versions = update_from_github.get_github_versions()
        current_version = update_from_github.current_version()
        if update_rule == "test":
            if LooseVersion(current_version) < LooseVersion(versions[0][1]):
                launcher_log.info("update to test version %s", versions[0][1])
                update_from_github.update_version(versions[0][1])
        elif update_rule == "stable":
            if LooseVersion(current_version) < LooseVersion(versions[1][1]):
                launcher_log.info("update to stable version %s", versions[1][1])
                update_from_github.update_version(versions[1][1])
    except IOError as e:
        launcher_log.warn("check update fail:%r", e)
    except Exception as e:
        launcher_log.exception("check_update fail:%r", e)
コード例 #3
0
ファイル: update.py プロジェクト: joesleung/chrome-xx
def check_update():
    try:
        update_rule = config.get(["update", "check_update"], "stable")
        if update_rule == "dont-check":
            return

        check_push_update()

        if update_rule != "stable" and update_rule != "test":
            return

        versions = update_from_github.get_github_versions()
        current_version = update_from_github.current_version()
        if update_rule == "test":
            if LooseVersion(current_version) < LooseVersion(versions[0][1]):
                launcher_log.info("update to test version %s", versions[0][1])
                update_from_github.update_version(versions[0][1])
        elif update_rule == "stable":
            if LooseVersion(current_version) < LooseVersion(versions[1][1]):
                launcher_log.info("update to stable version %s",
                                  versions[1][1])
                update_from_github.update_version(versions[1][1])
    except IOError as e:
        launcher_log.warn("check update fail:%r", e)
    except Exception as e:
        launcher_log.exception("check_update fail:%r", e)
コード例 #4
0
ファイル: start.py プロジェクト: joesleung/chrome-xx
def main():
    # change path to launcher
    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__)))

    launcher_log.info("start XX-Net %s", update_from_github.current_version())

    web_control.confirm_xxnet_exit()

    setup_win_python.check_setup()

    module_init.start_all_auto()

    web_control.start()


    if has_desktop and config.get(["modules", "launcher", "popup_webui"], 1) == 1:
        host_port = config.get(["modules", "launcher", "control_port"], 8085)
        webbrowser.open("http://127.0.0.1:%s/" % host_port)

    update.start()

    if config.get(["modules", "launcher", "show_systray"], 1):
        sys_tray.serve_forever()
    else:
        while True:
            time.sleep(100)

    module_init.stop_all()
    sys.exit()
コード例 #5
0
def download_file(url, file):
    if url not in download_progress:
        download_progress[url] = {}
        download_progress[url]["status"] = "downloading"
    else:
        if download_progress[url]["status"] == "downloading":
            launcher_log.error("url in downloading, %s", url)
            return False

    try:
        launcher_log.info("download %s to %s", url, file)
        opener = get_opener()
        req = opener.open(url)
        download_progress[url]["size"] = int(
            req.headers.get('content-length') or 0)

        CHUNK = 16 * 1024
        downloaded = 0
        with open(file, 'wb') as fp:
            while True:
                chunk = req.read(CHUNK)
                if not chunk: break
                fp.write(chunk)
                downloaded += len(chunk)
                download_progress[url]["downloaded"] = downloaded

        download_progress[url]["status"] = "finished"
        return True
    except Exception as e:
        download_progress[url]["status"] = "fail"
        launcher_log.exception("download %s to %s fail:%r", url, file, e)
        return False
コード例 #6
0
def main():
    wait_xxnet_exit()
    update_environment()

    time.sleep(2)
    launcher_log.info("setup start run new launcher")
    run_new_start_script()
コード例 #7
0
ファイル: update.py プロジェクト: joesleung/chrome-xx
def get_uuid():
    if need_new_uuid():
        generate_new_uuid()

    xx_net_uuid = config.get(["update", "uuid"])
    launcher_log.info("get uuid:%s", xx_net_uuid)
    return xx_net_uuid
コード例 #8
0
ファイル: update_from_github.py プロジェクト: 23niu/XX-Net
def download_file(url, file):
    if url not in download_progress:
        download_progress[url] = {}
        download_progress[url]["status"] = "downloading"
    else:
        if download_progress[url]["status"] == "downloading":
            launcher_log.error("url in downloading, %s", url)
            return False

    try:
        launcher_log.info("download %s to %s", url, file)
        opener = get_opener()
        req = opener.open(url)
        download_progress[url]["size"] = int(req.headers.get('content-length') or 0)

        CHUNK = 16 * 1024
        downloaded = 0
        with open(file, 'wb') as fp:
            while True:
                chunk = req.read(CHUNK)
                if not chunk: break
                fp.write(chunk)
                downloaded += len(chunk)
                download_progress[url]["downloaded"] = downloaded

        download_progress[url]["status"] = "finished"
        return True
    except Exception as e:
        download_progress[url]["status"] = "fail"
        launcher_log.exception("download %s to %s fail:%r", url, file, e)
        return False
コード例 #9
0
ファイル: update_from_github.py プロジェクト: yaronhe/XX-Net
def download_overwrite_new_version(xxnet_version):
    xxnet_url = 'https://codeload.github.com/XX-net/XX-Net/zip/%s' % xxnet_version
    xxnet_zip_file = os.path.join(download_path, "XX-Net-%s.zip" % xxnet_version)
    xxnet_unzip_path = os.path.join(download_path, "XX-Net-%s" % xxnet_version)

    if not download_file(xxnet_url, xxnet_zip_file):
        raise "download xxnet zip fail:" % download_path

    with zipfile.ZipFile(xxnet_zip_file, "r") as dz:
        dz.extractall(download_path)
        dz.close()

    if config.get(["update", "uuid"], '') != 'test':
        for root, subdirs, files in os.walk(xxnet_unzip_path):
            #print "root:", root
            relate_path = root[len(xxnet_unzip_path)+1:]
            for subdir in subdirs:

                target_path = os.path.join(root_path, relate_path, subdir)
                if not os.path.isdir(target_path):
                    launcher_log.info("mkdir %s", target_path)
                    os.mkdir(target_path)

            for filename in files:
                src_file = os.path.join(root, filename)
                dst_file = os.path.join(root_path, relate_path, filename)
                if not os.path.isfile(dst_file) or sha1_file(src_file) != sha1_file(dst_file):
                    shutil.copy(src_file, dst_file)
                    launcher_log.info("copy %s => %s", src_file, dst_file)

    os.remove(xxnet_zip_file)
    shutil.rmtree(xxnet_unzip_path, ignore_errors=True)
コード例 #10
0
ファイル: setup.py プロジェクト: 23niu/XX-Net
def main():
    wait_xxnet_exit()
    update_environment()

    time.sleep(2)
    launcher_log.info("setup start run new launcher")
    run_new_start_script()
コード例 #11
0
def start(module):
    if not os.path.isdir(os.path.join(root_path, module)):
        return

    try:
        if not module in config.config["modules"]:
            launcher_log.error("module not exist %s", module)
            raise

        if module in proc_handler:
            launcher_log.error("module %s is running", module)
            return "module is running"

        if module not in proc_handler:
            proc_handler[module] = {}

        if module == 'ossftp':
            masquerade_address = config.get(
                ["modules", "ossftp", "masquerade_address"], "")
            address = config.get(["modules", "ossftp", "address"], "127.0.0.1")
            port = config.get(["modules", "ossftp", "port"], 2048)
            passive_ports_start = config.get(
                ["modules", "ossftp", "passive_ports_start"], 51000)
            passive_ports_end = config.get(
                ["modules", "ossftp", "passive_ports_end"], 53000)
            is_internal = config.get(["modules", "ossftp", "internal"], None)
            log_level = config.get(["modules", "ossftp", "log_level"], "INFO")
            bucket_endpoints = config.get(
                ["modules", "ossftp", "bucket_endpoints"], "")
            script_path = os.path.join(root_path, 'ossftp', 'ftpserver.py')
            if not os.path.isfile(script_path):
                launcher_log.critical("start module script not exist:%s",
                                      script_path)
                return "fail"
            cmd = [
                sys.executable, script_path,
                "--listen_address=%s" % address,
                "--port=%d" % port,
                "--passive_ports_start=%d" % passive_ports_start,
                "--passive_ports_end=%d" % passive_ports_end,
                "--loglevel=%s" % log_level,
                "--bucket_endpoints=%s" % bucket_endpoints
            ]
            print(cmd)
            proc_handler[module]["proc"] = subprocess.Popen(
                cmd,
                shell=False,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)

        else:
            raise ValueError("Wrong module: %s" % module)

        launcher_log.info("%s started", module)

    except Exception as e:
        launcher_log.exception("start module %s fail:%s", module, e)
        return "Except:%s" % e
    return "start success."
コード例 #12
0
    def add(name, cmd):
        file_content = plist_template % cmd
        launcher_log.info("create file:%s", plist_file_path)

        if not os.path.isdir(launch_path):
            os.mkdir(launch_path, 0755)

        with open(plist_file_path, "w") as f:
            f.write(file_content)
コード例 #13
0
 def disableProxy_(self, _):
     cmd1 = "networksetup -setwebproxystate Ethernet off"
     cmd2 = "networksetup -setwebproxystate Wi-Fi off"
     cmd3 = "networksetup -setsecurewebproxystate Ethernet off"
     cmd4 = "networksetup -setsecurewebproxystate Wi-Fi off"
     exec_command = "%s;%s;%s;%s" % (cmd1, cmd2, cmd3, cmd4)
     admin_command = """osascript -e 'do shell script "%s" with administrator privileges' """ % exec_command
     cmd = admin_command.encode('utf-8')
     launcher_log.info("try disable proxy:%s", cmd)
     os.system(cmd)
コード例 #14
0
def start_all_auto():
    for module in config.config["modules"]:
        if module == "launcher":
            continue
        
        start_time = time.time()
        start(module)
        #web_control.confirm_module_ready(config.get(["modules", module, "control_port"], 0))
        finished_time = time.time()
        launcher_log.info("start %s time cost %d", module, (finished_time - start_time) * 1000)
コード例 #15
0
ファイル: module_init.py プロジェクト: shirewong/XX-Net
def start_all_auto():
    for module in config.config["modules"]:
        if module == "launcher":
            continue
        if "auto_start" in config.config['modules'][module] and config.config['modules'][module]["auto_start"]:
            start_time = time.time()
            start(module)
            #web_control.confirm_module_ready(config.get(["modules", module, "control_port"], 0))
            finished_time = time.time()
            launcher_log.info("start %s time cost %d", module, (finished_time - start_time) * 1000)
コード例 #16
0
ファイル: mac_tray.py プロジェクト: guoyunliang/XX-Net
 def disableProxy_(self, _):
     cmd1 = "networksetup -setwebproxystate Ethernet off"
     cmd2 = "networksetup -setwebproxystate Wi-Fi off"
     cmd3 = "networksetup -setsecurewebproxystate Ethernet off"
     cmd4 = "networksetup -setsecurewebproxystate Wi-Fi off"
     exec_command = "%s;%s;%s;%s" % (cmd1, cmd2, cmd3, cmd4)
     admin_command = """osascript -e 'do shell script "%s" with administrator privileges' """ % exec_command
     cmd = admin_command.encode('utf-8')
     launcher_log.info("try disable proxy:%s", cmd)
     os.system(cmd)
コード例 #17
0
ファイル: web_control.py プロジェクト: guoyunliang/XX-Net
def stop():
    global process, server
    if process == 0:
        return

    launcher_log.info("begin to exit web control")
    server.shutdown()
    server.server_close()
    process.join()
    launcher_log.info("launcher web control exited.")
    process = 0
コード例 #18
0
def stop():
    global process, server
    if process == 0:
        return

    launcher_log.info("begin to exit web control")
    server.shutdown()
    server.server_close()
    process.join()
    launcher_log.info("launcher web control exited.")
    process = 0
コード例 #19
0
ファイル: update.py プロジェクト: joesleung/chrome-xx
def check_new_machine():

    current_path = os.path.dirname(os.path.abspath(__file__))
    if current_path != config.get(["update", "last_path"], ""):
        config.set(["update", "last_path"], current_path)
        config.save()

        if sys.platform == "win32" and platform.release() == "XP":
            notify_install_tcpz_for_winXp()

        launcher_log.info("generate desktop shortcut")
        create_desktop_shortcut()
コード例 #20
0
ファイル: module_init.py プロジェクト: sunbowei1986/XX-Net
def start_all_auto():
    for module in config.config["modules"]:
        if module == "launcher":
            continue
        if not os.path.isdir(os.path.join(root_path, module)):
            continue
        if "auto_start" in config.config['modules'][module] and config.config['modules'][module]["auto_start"]:
            start_time = time.time()
            start(module)
            #web_control.confirm_module_ready(config.get(["modules", module, "control_port"], 0))
            finished_time = time.time()
            launcher_log.info("start %s time cost %d", module, (finished_time - start_time) * 1000)
コード例 #21
0
ファイル: update.py プロジェクト: ScalaGo/XX-Net
def check_new_machine():

    current_path = os.path.dirname(os.path.abspath(__file__))
    if current_path != config.get(["update", "last_path"], ""):
        config.set(["update", "last_path"], current_path)
        config.save()

        if sys.platform == "win32" and platform.release() == "XP":
            notify_install_tcpz_for_winXp()

        launcher_log.info("generate desktop shortcut")
        create_desktop_shortcut()
コード例 #22
0
 def download_file(url, file):
     try:
         launcher_log.info("download %s to %s", url, file)
         req = opener.open(url)
         CHUNK = 16 * 1024
         with open(file, 'wb') as fp:
             while True:
                 chunk = req.read(CHUNK)
                 if not chunk: break
                 fp.write(chunk)
         return True
     except:
         launcher_log.info("download %s to %s fail", url, file)
         return False
コード例 #23
0
ファイル: setup.py プロジェクト: 23niu/XX-Net
 def download_file(url, file):
     try:
         launcher_log.info("download %s to %s", url, file)
         req = opener.open(url)
         CHUNK = 16 * 1024
         with open(file, 'wb') as fp:
             while True:
                 chunk = req.read(CHUNK)
                 if not chunk: break
                 fp.write(chunk)
         return True
     except:
         launcher_log.info("download %s to %s fail", url, file)
         return False
コード例 #24
0
 def enableProxy_(self, _):
     cmd1 = "networksetup -setwebproxy Ethernet 127.0.0.1 8087"
     cmd2 = "networksetup -setwebproxy Wi-Fi 127.0.0.1 8087"
     cmd3 = "networksetup -setwebproxystate Ethernet on"
     cmd4 = "networksetup -setwebproxystate Wi-Fi on"
     cmd5 = "networksetup -setsecurewebproxy Ethernet 127.0.0.1 8087"
     cmd6 = "networksetup -setsecurewebproxy Wi-Fi 127.0.0.1 8087"
     cmd7 = "networksetup -setsecurewebproxystate Ethernet on"
     cmd8 = "networksetup -setsecurewebproxystate Wi-Fi on"
     exec_command = "%s;%s;%s;%s;%s;%s;%s;%s" % (cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8)
     admin_command = """osascript -e 'do shell script "%s" with administrator privileges' """ % exec_command
     cmd = admin_command.encode('utf-8')
     launcher_log.info("try enable proxy:%s", cmd)
     os.system(cmd)
コード例 #25
0
ファイル: mac_tray.py プロジェクト: guoyunliang/XX-Net
 def enableProxy_(self, _):
     cmd1 = "networksetup -setwebproxy Ethernet 127.0.0.1 8087"
     cmd2 = "networksetup -setwebproxy Wi-Fi 127.0.0.1 8087"
     cmd3 = "networksetup -setwebproxystate Ethernet on"
     cmd4 = "networksetup -setwebproxystate Wi-Fi on"
     cmd5 = "networksetup -setsecurewebproxy Ethernet 127.0.0.1 8087"
     cmd6 = "networksetup -setsecurewebproxy Wi-Fi 127.0.0.1 8087"
     cmd7 = "networksetup -setsecurewebproxystate Ethernet on"
     cmd8 = "networksetup -setsecurewebproxystate Wi-Fi on"
     exec_command = "%s;%s;%s;%s;%s;%s;%s;%s" % (cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8)
     admin_command = """osascript -e 'do shell script "%s" with administrator privileges' """ % exec_command
     cmd = admin_command.encode('utf-8')
     launcher_log.info("try enable proxy:%s", cmd)
     os.system(cmd)
コード例 #26
0
ファイル: web_control.py プロジェクト: googolplexr/XX-Net
    def _handle_request_noblock(self):
        try:
            request, client_address = self.get_request()
        except IOError as e:
            launcher_log.warn("socket(%s:%s) accept fail(errno: %s).", self.server_address[0], self.server_address[1], e.args[0])
            if e.args[0] == 10022:
                launcher_log.info("server %s:%d restarted.", self.server_address[0], self.server_address[1])
                self.init_socket()
            return

        if self.verify_request(request, client_address):
            try:
                self.process_request(request, client_address)
            except:
                self.handle_error(request, client_address)
                self.shutdown_request(request)
コード例 #27
0
    def _handle_request_noblock(self):
        try:
            request, client_address = self.get_request()
        except IOError as e:
            launcher_log.warn("socket(%s:%s) accept fail(errno: %s).", self.server_address[0], self.server_address[1], e.args[0])
            if e.args[0] == 10022:
                launcher_log.info("server %s:%d restarted.", self.server_address[0], self.server_address[1])
                self.init_socket()
            return

        if self.verify_request(request, client_address):
            try:
                self.process_request(request, client_address)
            except:
                self.handle_error(request, client_address)
                self.shutdown_request(request)
コード例 #28
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"

    launcher_log.info("begin to start web control")
    server = LocalServer((host_addr, host_port), Http_Handler)
    process = threading.Thread(target=server.serve_forever)
    process.setDaemon(True)
    process.start()
    launcher_log.info("launcher web control started.")
コード例 #29
0
ファイル: module_init.py プロジェクト: a6708051/oss-ftp
def stop(module):
    try:
        if not module in proc_handler:
            launcher_log.error("module %s not running", module)
            return
        
        proc_handler[module]["proc"].terminate()  # Sends SIGTERM
        proc_handler[module]["proc"].wait()
        #proc_handler[module]["proc"].stop()

        del proc_handler[module]

        launcher_log.info("module %s stopped", module)
    except Exception as e:
        launcher_log.exception("stop module %s fail:%s", module, e)
        return "Except:%s" % e
    return "stop success."
コード例 #30
0
ファイル: web_control.py プロジェクト: guoyunliang/XX-Net
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"

    launcher_log.info("begin to start web control")
    server = LocalServer((host_addr, host_port), Http_Handler)
    process = threading.Thread(target=server.serve_forever)
    process.setDaemon(True)
    process.start()
    launcher_log.info("launcher web control started.")
コード例 #31
0
def stop(module):
    try:
        if not module in proc_handler:
            launcher_log.error("module %s not running", module)
            return

        proc_handler[module]["proc"].terminate()  # Sends SIGTERM
        proc_handler[module]["proc"].wait()
        #proc_handler[module]["proc"].stop()

        del proc_handler[module]

        launcher_log.info("module %s stopped", module)
    except Exception as e:
        launcher_log.exception("stop module %s fail:%s", module, e)
        return "Except:%s" % e
    return "stop success."
コード例 #32
0
def start(module):
    if not os.path.isdir(os.path.join(root_path, module)):
        return

    try:
        if module not in config.config["modules"]:
            launcher_log.error("module not exist %s", module)
            raise

        if module in proc_handler:
            launcher_log.error("module %s is running", module)
            return "module is running"

        if module not in proc_handler:
            proc_handler[module] = {}

        if os.path.isfile(os.path.join(root_path, module, "__init__.py")):
            if "imp" not in proc_handler[module]:
                proc_handler[module]["imp"] = __import__(
                    module, globals(), locals(), ['local', 'start'], -1)

            _start = proc_handler[module]["imp"].start
            p = threading.Thread(target=_start.main)
            p.daemon = True
            p.start()
            proc_handler[module]["proc"] = p

            while not _start.client.ready:
                time.sleep(0.1)
        else:
            script_path = os.path.join(root_path, module, 'start.py')
            if not os.path.isfile(script_path):
                launcher_log.warn("start module script not exist:%s",
                                  script_path)
                return "fail"

            proc_handler[module]["proc"] = subprocess.Popen(
                [sys.executable, script_path], shell=False)

        launcher_log.info("%s started", module)

    except Exception as e:
        launcher_log.exception("start module %s fail:%s", module, e)
        return "Except:%s" % e
    return "start success."
コード例 #33
0
def download_file(url, file):
    if url not in download_progress:
        download_progress[url] = {}
        download_progress[url]["status"] = "downloading"
    else:
        if download_progress[url]["status"] == "downloading":
            launcher_log.warn("url in downloading, %s", url)
            return False

    for i in range(0, 2):
        try:
            launcher_log.info("download %s to %s, retry:%d", url, file, i)
            opener = get_opener(i)
            req = opener.open(url)
            download_progress[url]["size"] = int(
                req.headers.get('content-length') or 0)

            CHUNK = 16 * 1024
            downloaded = 0
            with open(file, 'wb') as fp:
                while True:
                    chunk = req.read(CHUNK)
                    if not chunk:
                        break
                    fp.write(chunk)
                    downloaded += len(chunk)
                    download_progress[url]["downloaded"] = downloaded

            if downloaded != download_progress[url]["size"]:
                launcher_log.warn(
                    "download size:%d, need size:%d, download fail.",
                    downloaded, download_progress[url]["size"])
                continue
            else:
                download_progress[url]["status"] = "finished"
                return True
        except urllib2.URLError as e:
            launcher_log.warn("download %s to %s URL fail:%r", url, file, e)
            continue
        except Exception as e:
            launcher_log.exception("download %s to %s fail:%r", url, file, e)
            continue

    download_progress[url]["status"] = "failed"
    return False
コード例 #34
0
ファイル: module_init.py プロジェクト: 23niu/XX-Net
def start(module):
    if not os.path.isdir(os.path.join(root_path, module)):
        return

    try:
        if not module in config.config["modules"]:
            launcher_log.error("module not exist %s", module)
            raise

        if module in proc_handler:
            launcher_log.error("module %s is running", module)
            return "module is running"

        if module not in proc_handler:
            proc_handler[module] = {}

        if os.path.isfile(os.path.join(root_path, module, "__init__.py")):
            if "imp" not in proc_handler[module]:
                proc_handler[module]["imp"] = __import__(module, globals(), locals(), ['local', 'start'], -1)

            _start = proc_handler[module]["imp"].start
            p = threading.Thread(target = _start.main)
            p.daemon = True
            p.start()
            proc_handler[module]["proc"] = p

            while not _start.client.ready:
                time.sleep(0.1)
        else:
            script_path = os.path.join(root_path, module, 'start.py')
            if not os.path.isfile(script_path):
                launcher_log.warn("start module script not exist:%s", script_path)
                return "fail"

            proc_handler[module]["proc"] = subprocess.Popen([sys.executable, script_path], shell=False)


        launcher_log.info("%s started", module)

    except Exception as e:
        launcher_log.exception("start module %s fail:%s", module, e)
        return "Except:%s" % e
    return "start success."
コード例 #35
0
ファイル: module_init.py プロジェクト: a6708051/oss-ftp
def start(module):
    if not os.path.isdir(os.path.join(root_path, module)):
        return

    try:
        if not module in config.config["modules"]:
            launcher_log.error("module not exist %s", module)
            raise

        if module in proc_handler:
            launcher_log.error("module %s is running", module)
            return "module is running"

        if module not in proc_handler:
            proc_handler[module] = {}

        if module == 'ossftp':
            masquerade_address = config.get(["modules", "ossftp", "masquerade_address"], "")
            address = config.get(["modules", "ossftp", "address"], "127.0.0.1")
            port = config.get(["modules", "ossftp", "port"], 2048)
            is_internal = config.get(["modules", "ossftp", "internal"], None)
            log_level = config.get(["modules", "ossftp", "log_level"], "INFO")
            bucket_endpoints = config.get(["modules", "ossftp", "bucket_endpoints"], "")
            script_path = os.path.join(root_path, 'ossftp', 'ftpserver.py')
            if not os.path.isfile(script_path):
                launcher_log.critical("start module script not exist:%s", script_path)
                return "fail"
            cmd = [sys.executable, script_path, "--listen_address=%s"%address, "--port=%d"%port, "--loglevel=%s"%log_level, "--bucket_endpoints=%s"%bucket_endpoints]
            print cmd
            proc_handler[module]["proc"] = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            #t = FTPd(masquerade_address, address, port, bucket_endpoints, is_internal, log_level)
            #t.start()
            #proc_handler[module]["proc"] = t
        else:
            raise ValueError("Wrong module: %s" % module)
        
        launcher_log.info("%s started", module)

    except Exception as e:
        launcher_log.exception("start module %s fail:%s", module, e)
        return "Except:%s" % e
    return "start success."
コード例 #36
0
def download_file(url, file):
    if url not in download_progress:
        download_progress[url] = {}
        download_progress[url]["status"] = "downloading"
    else:
        if download_progress[url]["status"] == "downloading":
            launcher_log.warn("url in downloading, %s", url)
            return False

    for i in range(0, 2):
        try:
            launcher_log.info("download %s to %s, retry:%d", url, file, i)
            opener = get_opener(i)
            req = opener.open(url)
            download_progress[url]["size"] = int(req.headers.get('content-length') or 0)

            CHUNK = 16 * 1024
            downloaded = 0
            with open(file, 'wb') as fp:
                while True:
                    chunk = req.read(CHUNK)
                    if not chunk:
                        break
                    fp.write(chunk)
                    downloaded += len(chunk)
                    download_progress[url]["downloaded"] = downloaded

            if downloaded != download_progress[url]["size"]:
                launcher_log.warn("download size:%d, need size:%d, download fail.", downloaded, download_progress[url]["size"])
                continue
            else:
                download_progress[url]["status"] = "finished"
                return True
        except urllib2.URLError as e:
            launcher_log.warn("download %s to %s URL fail:%r", url, file, e)
            continue
        except Exception as e:
            launcher_log.exception("download %s to %s fail:%r", url, file, e)
            continue

    download_progress[url]["status"] = "failed"
    return False
コード例 #37
0
def install_xxnet_files():
    def sha1_file(filename):
        import hashlib

        BLOCKSIZE = 65536
        hasher = hashlib.sha1()
        try:
            with open(filename, 'rb') as afile:
                buf = afile.read(BLOCKSIZE)
                while len(buf) > 0:
                    hasher.update(buf)
                    buf = afile.read(BLOCKSIZE)
            return hasher.hexdigest()
        except:
            return False
        pass

    for root, subdirs, files in os.walk(xxnet_unzip_path):
        #print "root:", root
        relate_path = root[len(xxnet_unzip_path) + 1:]
        for subdir in subdirs:

            target_path = os.path.join(root_path, relate_path, subdir)
            if not os.path.isdir(target_path):
                launcher_log.info("mkdir %s", target_path)
                os.mkdir(target_path)

        for filename in files:
            if relate_path == os.path.join(
                    "data", "gae_proxy") and filename == "config.ini":
                continue
            if relate_path == os.path.join(
                    "data", "launcher") and filename == "config.yaml":
                continue
            src_file = os.path.join(root, filename)
            dst_file = os.path.join(root_path, relate_path, filename)
            if not os.path.isfile(
                    dst_file) or sha1_file(src_file) != sha1_file(dst_file):
                shutil.copy(src_file, dst_file)
                launcher_log.info("copy %s => %s", src_file, dst_file)
コード例 #38
0
def copy_VCR_files():
    src_path = os.path.join(python_path, "WinSxS")
    win_path = os.environ['WINDIR']
    win_dst_path = os.path.join(win_path, "WinSxS")

    for path, dirs, files in os.walk(src_path):
        for file in files:
            sep_path = path.split(os.path.sep)
            home_path_depth = len(python_path.split(os.path.sep))
            relate_path = os.path.sep.join(sep_path[home_path_depth + 1:])
            #print relate_path
            dest_path = os.path.join(win_dst_path, relate_path)
            if not os.path.isdir(dest_path):
                launcher_log.info("setup win python, mkdir:%s", dest_path)
                os.mkdir(dest_path)
            #print "root:", path
            #print "file:", file
            src_path = os.path.join(path, file)
            target_file = os.path.join(dest_path, file)
            if not os.path.isfile(target_file):
                launcher_log.info("setup win python, copy:%s %s", src_path, target_file)
                shutil.copyfile(src_path, target_file)
コード例 #39
0
ファイル: setup.py プロジェクト: 23niu/XX-Net
def install_xxnet_files():

    def sha1_file(filename):
        import hashlib

        BLOCKSIZE = 65536
        hasher = hashlib.sha1()
        try:
            with open(filename, 'rb') as afile:
                buf = afile.read(BLOCKSIZE)
                while len(buf) > 0:
                    hasher.update(buf)
                    buf = afile.read(BLOCKSIZE)
            return hasher.hexdigest()
        except:
            return False
        pass

    for root, subdirs, files in os.walk(xxnet_unzip_path):
        #print "root:", root
        relate_path = root[len(xxnet_unzip_path)+1:]
        for subdir in subdirs:

            target_path = os.path.join(root_path, relate_path, subdir)
            if not os.path.isdir(target_path):
                launcher_log.info("mkdir %s", target_path)
                os.mkdir(target_path)

        for filename in files:
            if relate_path == os.path.join("data", "gae_proxy") and filename == "config.ini":
                continue
            if relate_path == os.path.join("data", "launcher") and filename == "config.yaml":
                continue
            src_file = os.path.join(root, filename)
            dst_file = os.path.join(root_path, relate_path, filename)
            if not os.path.isfile(dst_file) or sha1_file(src_file) != sha1_file(dst_file):
                shutil.copy(src_file, dst_file)
                launcher_log.info("copy %s => %s", src_file, dst_file)
コード例 #40
0
ファイル: module_init.py プロジェクト: 23niu/XX-Net
def stop(module):
    try:
        if not module in proc_handler:
            launcher_log.error("module %s not running", module)
            return

        if os.path.isfile(os.path.join(root_path, module, "__init__.py")):

            _start = proc_handler[module]["imp"].start
            _start.client.terminate()
            launcher_log.debug("module %s stopping", module)
            while _start.client.ready:
                time.sleep(0.1)
        else:
            proc_handler[module]["proc"].terminate()  # Sends SIGTERM
            proc_handler[module]["proc"].wait()

        del proc_handler[module]

        launcher_log.info("module %s stopped", module)
    except Exception as e:
        launcher_log.exception("stop module %s fail:%s", module, e)
        return "Except:%s" % e
    return "stop success."
コード例 #41
0
ファイル: module_init.py プロジェクト: sunbowei1986/XX-Net
def stop(module):
    try:
        if not module in proc_handler:
            launcher_log.error("module %s not running", module)
            return

        if os.path.isfile(os.path.join(root_path, module, "__init__.py")):

            _start = proc_handler[module]["imp"].start
            _start.client.config.keep_run = False
            launcher_log.debug("module %s stopping", module)
            while _start.client.ready:
                time.sleep(0.1)
        else:
            proc_handler[module]["proc"].terminate()  # Sends SIGTERM
            proc_handler[module]["proc"].wait()

        del proc_handler[module]

        launcher_log.info("module %s stopped", module)
    except Exception as e:
        launcher_log.exception("stop module %s fail:%s", module, e)
        return "Except:%s" % e
    return "stop success."
コード例 #42
0
ファイル: update.py プロジェクト: joesleung/chrome-xx
def install_module(module, new_version):
    import module_init
    import os, subprocess, sys

    current_path = os.path.dirname(os.path.abspath(__file__))
    new_module_version_path = os.path.abspath(
        os.path.join(current_path, os.pardir, os.pardir, module, new_version))

    #check path exist
    if not os.path.isdir(new_module_version_path):
        launcher_log.error("install module %s dir %s not exist", module,
                           new_module_version_path)
        return

    #call setup.py
    setup_script = os.path.join(new_module_version_path, "setup.py")
    if not os.path.isfile(setup_script):
        launcher_log.warn("update %s fail. setup script %s not exist", module,
                          setup_script)
        return

    config.set(["modules", module, "current_version"], str(new_version))
    config.save()

    if module == "launcher":
        module_init.stop_all()
        import web_control
        web_control.stop()

        subprocess.Popen([sys.executable, setup_script], shell=False)

        os._exit(0)

    else:
        launcher_log.info("Setup %s version %s ...", module, new_version)
        try:
            module_init.stop(module)

            subprocess.call([sys.executable, setup_script], shell=False)
            launcher_log.info("Finished new version setup.")

            launcher_log.info("Restarting new version ...")
            module_init.start(module)
        except Exception as e:
            launcher_log.error("install module %s %s fail:%s", module,
                               new_version, e)
コード例 #43
0
ファイル: update.py プロジェクト: ScalaGo/XX-Net
def install_module(module, new_version):
    import module_init
    import os, subprocess, sys

    current_path = os.path.dirname(os.path.abspath(__file__))
    new_module_version_path = os.path.abspath( os.path.join(current_path, os.pardir, os.pardir, module, new_version))

    #check path exist
    if not os.path.isdir(new_module_version_path):
        launcher_log.error("install module %s dir %s not exist", module, new_module_version_path)
        return

    #call setup.py
    setup_script = os.path.join(new_module_version_path, "setup.py")
    if not os.path.isfile(setup_script):
        launcher_log.warn("update %s fail. setup script %s not exist", module, setup_script)
        return


    config.set(["modules", module, "current_version"], str(new_version))
    config.save()

    if module == "launcher":
        module_init.stop_all()
        import web_control
        web_control.stop()


        subprocess.Popen([sys.executable, setup_script], shell=False)

        os._exit(0)

    else:
        launcher_log.info("Setup %s version %s ...", module, new_version)
        try:
            module_init.stop(module)

            subprocess.call([sys.executable, setup_script], shell=False)
            launcher_log.info("Finished new version setup.")

            launcher_log.info("Restarting new version ...")
            module_init.start(module)
        except Exception as e:
            launcher_log.error("install module %s %s fail:%s", module, new_version, e)
コード例 #44
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        current_version = update_from_github.current_version()

        if reqs['cmd'] == ['get_config']:
            config.load()
            check_update = config.get(["update", "check_update"], 1)
            if check_update == 0:
                check_update = "dont-check"
            elif check_update == 1:
                check_update = "long-term-stable"

            data = '{ "check_update": "%s", "popup_webui": %d, "allow_remote_connect": %d, "show_systray": %d, "auto_start": %d, "php_enable": %d, "gae_proxy_enable": %d }' %\
                   (check_update
                    , config.get(["modules", "launcher", "popup_webui"], 1)
                    , config.get(["modules", "launcher", "allow_remote_connect"], 0)
                    , config.get(["modules", "launcher", "show_systray"], 1)
                    , config.get(["modules", "launcher", "auto_start"], 0)
                    , config.get(["modules", "php_proxy", "auto_start"], 0)
                    , config.get(["modules", "gae_proxy", "auto_start"], 0))
        elif reqs['cmd'] == ['set_config']:
            if 'check_update' in reqs:
                check_update = reqs['check_update'][0]
                if check_update not in [
                        "dont-check", "long-term-stable", "stable", "test"
                ]:
                    data = '{"res":"fail, check_update:%s"}' % check_update
                else:
                    config.set(["update", "check_update"], check_update)
                    config.save()

                    data = '{"res":"success"}'

            elif 'popup_webui' in reqs:
                popup_webui = int(reqs['popup_webui'][0])
                if popup_webui != 0 and popup_webui != 1:
                    data = '{"res":"fail, popup_webui:%s"}' % popup_webui
                else:
                    config.set(["modules", "launcher", "popup_webui"],
                               popup_webui)
                    config.save()

                    data = '{"res":"success"}'

            elif 'allow_remote_connect' in reqs:
                allow_remote_connect = int(reqs['allow_remote_connect'][0])
                if allow_remote_connect != 0 and allow_remote_connect != 1:
                    data = '{"res":"fail, allow_remote_connect:%s"}' % allow_remote_connect
                else:
                    config.set(["modules", "launcher", "allow_remote_connect"],
                               allow_remote_connect)
                    config.save()

                    data = '{"res":"success"}'

                    launcher_log.debug("restart web control.")
                    stop()
                    time.sleep(1)
                    start()
                    launcher_log.debug("launcher web control restarted.")

            elif 'show_systray' in reqs:
                show_systray = int(reqs['show_systray'][0])
                if show_systray != 0 and show_systray != 1:
                    data = '{"res":"fail, show_systray:%s"}' % show_systray
                else:
                    config.set(["modules", "launcher", "show_systray"],
                               show_systray)
                    config.save()

                    data = '{"res":"success"}'

            elif 'auto_start' in reqs:
                auto_start = int(reqs['auto_start'][0])
                if auto_start != 0 and auto_start != 1:
                    data = '{"res":"fail, auto_start:%s"}' % auto_start
                else:
                    if auto_start:
                        autorun.enable()
                    else:
                        autorun.disable()

                    config.set(["modules", "launcher", "auto_start"],
                               auto_start)
                    config.save()

                    data = '{"res":"success"}'
            elif 'gae_proxy_enable' in reqs:
                gae_proxy_enable = int(reqs['gae_proxy_enable'][0])
                if gae_proxy_enable != 0 and gae_proxy_enable != 1:
                    data = '{"res":"fail, gae_proxy_enable:%s"}' % gae_proxy_enable
                else:
                    config.set(["modules", "gae_proxy", "auto_start"],
                               gae_proxy_enable)
                    config.save()
                    if gae_proxy_enable:
                        module_init.start("gae_proxy")
                    else:
                        module_init.stop("gae_proxy")
                    self.load_module_menus()
                    data = '{"res":"success"}'
            elif 'php_enable' in reqs:
                php_enable = int(reqs['php_enable'][0])
                if php_enable != 0 and php_enable != 1:
                    data = '{"res":"fail, php_enable:%s"}' % php_enable
                else:
                    config.set(["modules", "php_proxy", "auto_start"],
                               php_enable)
                    config.save()
                    if php_enable:
                        module_init.start("php_proxy")
                    else:
                        module_init.stop("php_proxy")
                    self.load_module_menus()
                    data = '{"res":"success"}'
            else:
                data = '{"res":"fail"}'
        elif reqs['cmd'] == ['get_new_version']:
            versions = update_from_github.get_github_versions()
            data = '{"res":"success", "test_version":"%s", "stable_version":"%s", "current_version":"%s"}' % (
                versions[0][1], versions[1][1], current_version)
            launcher_log.info("%s", data)
        elif reqs['cmd'] == ['update_version']:
            version = reqs['version'][0]
            try:
                update_from_github.update_version(version)
                data = '{"res":"success"}'
            except Exception as e:
                launcher_log.info("update_test_version fail:%r", e)
                data = '{"res":"fail", "error":"%s"}' % e

        self.send_response('text/html', data)
コード例 #45
0
ファイル: autorun.py プロジェクト: a6708051/oss-ftp
 def remove(name):
     if(os.path.isfile(plist_file_path)):
         os.unlink(plist_file_path)
         launcher_log.info("remove file:%s", plist_file_path)
コード例 #46
0
ファイル: win_tray.py プロジェクト: az0ne/XX-Net
 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)
     launcher_log.info("set register path:%r name:%s type:%d value:%s", reg_path, name, reg_type, value)
コード例 #47
0
ファイル: web_control.py プロジェクト: guoyunliang/XX-Net
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        current_version = update_from_github.current_version()

        if reqs['cmd'] == ['get_config']:
            config.load()
            check_update = config.get(["update", "check_update"], 1)
            if check_update == 0:
                check_update = "dont-check"
            elif check_update == 1:
                check_update = "long-term-stable"

            data = '{ "check_update": "%s", "popup_webui": %d, "allow_remote_connect": %d, "show_systray": %d, "auto_start": %d, "php_enable": %d, "gae_proxy_enable": %d }' %\
                   (check_update
                    , config.get(["modules", "launcher", "popup_webui"], 1)
                    , config.get(["modules", "launcher", "allow_remote_connect"], 0)
                    , config.get(["modules", "launcher", "show_systray"], 1)
                    , config.get(["modules", "launcher", "auto_start"], 0)
                    , config.get(["modules", "php_proxy", "auto_start"], 0)
                    , config.get(["modules", "gae_proxy", "auto_start"], 0))
        elif reqs['cmd'] == ['set_config']:
            if 'check_update' in reqs:
                check_update = reqs['check_update'][0]
                if check_update not in ["dont-check", "long-term-stable", "stable", "test"]:
                    data = '{"res":"fail, check_update:%s"}' % check_update
                else:
                    config.set(["update", "check_update"], check_update)
                    config.save()

                    data = '{"res":"success"}'

            elif 'popup_webui' in reqs:
                popup_webui = int(reqs['popup_webui'][0])
                if popup_webui != 0 and popup_webui != 1:
                    data = '{"res":"fail, popup_webui:%s"}' % popup_webui
                else:
                    config.set(["modules", "launcher", "popup_webui"], popup_webui)
                    config.save()

                    data = '{"res":"success"}'

            elif 'allow_remote_connect' in reqs:
                allow_remote_connect = int(reqs['allow_remote_connect'][0])
                if allow_remote_connect != 0 and allow_remote_connect != 1:
                    data = '{"res":"fail, allow_remote_connect:%s"}' % allow_remote_connect
                else:
                    config.set(["modules", "launcher", "allow_remote_connect"], allow_remote_connect)
                    config.save()

                    data = '{"res":"success"}'

                    launcher_log.debug("restart web control.")
                    stop()
                    time.sleep(1)
                    start()
                    launcher_log.debug("launcher web control restarted.")

            elif 'show_systray' in reqs:
                show_systray = int(reqs['show_systray'][0])
                if show_systray != 0 and show_systray != 1:
                    data = '{"res":"fail, show_systray:%s"}' % show_systray
                else:
                    config.set(["modules", "launcher", "show_systray"], show_systray)
                    config.save()

                    data = '{"res":"success"}'

            elif 'auto_start' in reqs:
                auto_start = int(reqs['auto_start'][0])
                if auto_start != 0 and auto_start != 1:
                    data = '{"res":"fail, auto_start:%s"}' % auto_start
                else:
                    if auto_start:
                        autorun.enable()
                    else:
                        autorun.disable()

                    config.set(["modules", "launcher", "auto_start"], auto_start)
                    config.save()

                    data = '{"res":"success"}'
            elif 'gae_proxy_enable' in reqs :
                gae_proxy_enable = int(reqs['gae_proxy_enable'][0])
                if gae_proxy_enable != 0 and gae_proxy_enable != 1:
                    data = '{"res":"fail, gae_proxy_enable:%s"}' % gae_proxy_enable
                else:
                    config.set(["modules", "gae_proxy", "auto_start"], gae_proxy_enable)
                    config.save()
                    if gae_proxy_enable:
                        module_init.start("gae_proxy")
                    else:
                        module_init.stop("gae_proxy")
                    self.load_module_menus()
                    data = '{"res":"success"}'
            elif 'php_enable' in reqs :
                php_enable = int(reqs['php_enable'][0])
                if php_enable != 0 and php_enable != 1:
                    data = '{"res":"fail, php_enable:%s"}' % php_enable
                else:
                    config.set(["modules", "php_proxy", "auto_start"], php_enable)
                    config.save()
                    if php_enable:
                        module_init.start("php_proxy")
                    else:
                        module_init.stop("php_proxy")
                    self.load_module_menus()
                    data = '{"res":"success"}'
            else:
                data = '{"res":"fail"}'
        elif reqs['cmd'] == ['get_new_version']:
            versions = update_from_github.get_github_versions()
            data = '{"res":"success", "test_version":"%s", "stable_version":"%s", "current_version":"%s"}' % (versions[0][1], versions[1][1], current_version)
            launcher_log.info("%s", data)
        elif reqs['cmd'] == ['update_version']:
            version = reqs['version'][0]
            try:
                update_from_github.update_version(version)
                data = '{"res":"success"}'
            except Exception as e:
                launcher_log.info("update_test_version fail:%r", e)
                data = '{"res":"fail", "error":"%s"}' % e

        self.send_response('text/html', data)
コード例 #48
0
ファイル: web_control.py プロジェクト: guoyunliang/XX-Net
    def do_GET(self):
        try:
            refer = self.headers.getheader('Referer')
            netloc = urlparse.urlparse(refer).netloc
            if not netloc.startswith("127.0.0.1") and not netloc.startswitch("localhost"):
                launcher_log.warn("web control ref:%s refuse", netloc)
                return
        except:
            pass

        # check for '..', which will leak file
        if re.search(r'(\.{2})', self.path) is not None:
            self.wfile.write(b'HTTP/1.1 404\r\n\r\n')
            launcher_log.warn('%s %s %s haking', self.address_string(), self.command, self.path )
            return

        url_path = urlparse.urlparse(self.path).path
        if url_path == '/':
            return self.req_index_handler()

        url_path_list = self.path.split('/')
        if len(url_path_list) >= 3 and url_path_list[1] == "module":
            module = url_path_list[2]
            if len(url_path_list) >= 4 and url_path_list[3] == "control":
                if module not in module_init.proc_handler:
                    launcher_log.warn("request %s no module in path", url_path)
                    self.send_not_found()
                    return

                path = '/' + '/'.join(url_path_list[4:])
                controler = module_init.proc_handler[module]["imp"].local.web_control.ControlHandler(self.client_address, self.headers, self.command, path, self.rfile, self.wfile)
                controler.do_GET()
                return
            else:
                file_path = os.path.join(root_path, module, url_path_list[3:].join('/'))
        else:
            file_path = os.path.join(current_path, 'web_ui' + url_path)


        launcher_log.debug ('launcher web_control %s %s %s ', self.address_string(), self.command, self.path)
        if os.path.isfile(file_path):
            if file_path.endswith('.js'):
                mimetype = 'application/javascript'
            elif file_path.endswith('.css'):
                mimetype = 'text/css'
            elif file_path.endswith('.html'):
                mimetype = 'text/html'
            elif file_path.endswith('.jpg'):
                mimetype = 'image/jpeg'
            elif file_path.endswith('.png'):
                mimetype = 'image/png'
            else:
                mimetype = 'text/plain'


            self.send_file(file_path, mimetype)
        elif url_path == '/config':
            self.req_config_handler()
        elif url_path == '/download':
            self.req_download_handler()
        elif url_path == '/init_module':
            self.req_init_module_handler()
        elif url_path == '/quit':
            self.send_response('text/html', '{"status":"success"}')
            module_init.stop_all()
            os._exit(0)
        elif url_path == '/restart':
            self.send_response('text/html', '{"status":"success"}')
            update_from_github.restart_xxnet()
        else:
            self.wfile.write(b'HTTP/1.1 404\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n404 Not Found')
            launcher_log.info('%s "%s %s HTTP/1.1" 404 -', self.address_string(), self.command, self.path)
コード例 #49
0
ファイル: update.py プロジェクト: ScalaGo/XX-Net
def check_push_update():
    global update_content, update_dict
    try:
        opener = get_opener()

        req_url = update_url + "?uuid=" + get_uuid() + "&version=" + update_from_github.current_version()
        try:
            update_content = opener.open(req_url).read()
        except Exception as e:
            launcher_log.warn("check_update fail:%r", e)
            return False

        update_dict = json.loads(update_content)
        return True

        for module in update_dict["modules"]:
            new_version = str(update_dict["modules"][module]["last_version"])
            describe = update_dict["modules"][module]["versions"][new_version]["describe"]

            if update_dict["modules"][module]["versions"][new_version]["notify"] != "true":
                continue

            if not module in config.config["modules"]:
                ignore_version = 0
                current_version = 0
                config.config["modules"][module] = {}
                config.config["modules"][module]["current_version"] = '0.0.0'
            else:
                current_version = config.get(["modules", module, "current_version"])
                if "ignore_version" in config.config["modules"][module]:
                    ignore_version = config.config["modules"][module]["ignore_version"]
                else:
                    ignore_version = current_version

            if version_to_bin(new_version) <= version_to_bin(ignore_version):
                continue

            if version_to_bin(new_version) > version_to_bin(current_version):
                launcher_log.info("new %s version:%s", module, new_version)


                if sys.platform == "linux" or sys.platform == "linux2":
                    from gtk_tray import sys_tray
                    msg = "Module %s new version: %s, Download?\nNew:%s" % (module,  new_version, describe)
                    data_download = "%s|%s|download" % (module, new_version)
                    data_ignore = "%s|%s|ignore" % (module, new_version)
                    buttons = {1: {"data":data_download, "label":"Download", 'callback':general_gtk_callback},
                               2: {"data":data_ignore, "label":"Ignore", 'callback':general_gtk_callback}}
                    sys_tray.notify_general(msg=msg, title="New Version", buttons=buttons)
                elif sys.platform == "win32":
                    from win_tray import sys_tray
                    msg = "Module %s new version: %s, Download?" % (module,  new_version)
                    if sys_tray.dialog_yes_no(msg, u"Download", None, None) == 1:
                        download_module(module, new_version)
                    else:
                        ignore_module(module, new_version)
                elif sys.platform == "darwin":
                    from mac_tray import sys_tray
                    msg = "Module %s new version: %s, Download?" % (module,  new_version)
                    if sys_tray.dialog_yes_no(msg, u"Download", None, None) == 1:
                        download_module(module, new_version)
                    else:
                        ignore_module(module, new_version)

                else:
                    download_module(module, new_version)

    except Exception as e:
        launcher_log.exception("check_update except:%s", e)
        return
コード例 #50
0
ファイル: update.py プロジェクト: ScalaGo/XX-Net
def need_new_uuid():
    if not config.get(["update", "uuid"]):
        launcher_log.info("need_new_uuid: uuid is empty")
        return True
    return False
コード例 #51
0
 def remove(name):
     if (os.path.isfile(plist_file_path)):
         os.unlink(plist_file_path)
         launcher_log.info("remove file:%s", plist_file_path)
コード例 #52
0
ファイル: web_control.py プロジェクト: a6708051/oss-ftp
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''        

        if reqs['cmd'] == ['get_config']:
            config.load()
            data = '{ "popup_webui": %d, "show_systray": %d, "auto_start": %d, "ossftp_address": "%s", "ossftp_port": %d, "ossftp_loglevel": "%s", "ossftp_bucketendpoints": "%s" }' %\
                   (config.get(["modules", "launcher", "popup_webui"], 1)
                    , config.get(["modules", "launcher", "show_systray"], 1)
                    , config.get(["modules", "launcher", "auto_start"], 0)
                    , config.get(["modules", "ossftp", "address"], '127.0.0.1')
                    , config.get(["modules", "ossftp", "port"], 2048)
                    , config.get(["modules", "ossftp", "log_level"], 'INFO')
                    , config.get(["modules", "ossftp", "bucket_endpoints"], ''))
        elif reqs['cmd'] == ['set_config']:
            success = True
            popup_webui = config.get(["modules", "launcher", "popup_webui"], 1)
            auto_start = config.get(["modules", "launcher", "auto_start"], 0)
            show_systray = config.get(["modules", "launcher", "show_systray"], 1)
            ossftp_address = config.get(["modules", "ossftp", "address"], "127.0.0.1")
            ossftp_port = config.get(["modules", "ossftp", "port"], 2048)
            ossftp_loglevel = config.get(["modules", "ossftp", "log_level"], 'INFO')
            ossftp_bucketendpoints = config.get(["modules", "ossftp", "bucket_endpoints"], '')
            data = '{"res":"fail"}'
            if success and 'popup_webui' in reqs :
                popup_webui = int(reqs['popup_webui'][0])
                if popup_webui != 0 and popup_webui != 1:
                    success = False
                    data = '{"res":"fail, popup_webui:%s"}' % popup_webui
            if success and 'show_systray' in reqs :
                show_systray = int(reqs['show_systray'][0])
                if show_systray != 0 and show_systray != 1:
                    success = False
                    data = '{"res":"fail, show_systray:%s"}' % show_systray        
            if success and 'auto_start' in reqs :
                auto_start = int(reqs['auto_start'][0])
                if auto_start != 0 and auto_start != 1:
                    success = False
                    data = '{"res":"fail, auto_start:%s"}' % auto_start
            if success and 'ossftp_address' in reqs:
                ossftp_address = reqs['ossftp_address'][0].strip()
                if not self.ip_check(ossftp_address):
                    success = False
                    data = '{"res":"fail, ilegal ossftp address: %s"}' % ossftp_address
 
            if success and 'ossftp_port' in reqs:
                ossftp_port = int(reqs['ossftp_port'][0])
                if ossftp_port < 0:
                    success = False
                    data = '{"res":"fail, ilegal ossftp port: %d"}' % ossftp_port
            if success and 'ossftp_loglevel' in reqs:
                ossftp_loglevel = reqs['ossftp_loglevel'][0].strip().upper()
                if (ossftp_loglevel not in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']):
                    success = False
                    data = '{"res":"fail, illegal ossftp log level: %s. Must be: DEBUG, INFO, WARNING, ERROR, CRITICAL"}' % ossftp_loglevel
            if success and 'ossftp_bucketendpoints' in reqs:
                ossftp_bucketendpoints = reqs['ossftp_bucketendpoints'][0].strip()
                
            if success:
                config.set(["modules", "launcher", "popup_webui"], popup_webui)
                config.set(["modules", "launcher", "show_systray"], show_systray)
                config.set(["modules", "launcher", "auto_start"], auto_start)
                config.set(["modules", "ossftp", "address"], ossftp_address)
                config.set(["modules", "ossftp", "port"], ossftp_port)
                config.set(["modules", "ossftp", "log_level"], ossftp_loglevel)
                config.set(["modules", "ossftp", "bucket_endpoints"], ossftp_bucketendpoints)
                config.save()
                if auto_start:
                    autorun.enable()
                else:
                    autorun.disable()
                data = '{"res":"success"}'
                launcher_log.info('Set config: %s', json.dumps(config.config, sort_keys=True, separators=(',',':'), indent=2))
            else:
                launcher_log.error(data)

        self.send_response('text/html', data)
コード例 #53
0
    def do_GET(self):
        refer = self.headers.getheader('Referer')
        if refer:
            refer_loc = urlparse.urlparse(refer).netloc
            host = self.headers.getheader('host')
            if refer_loc != host:
                launcher_log.warn("web control ref:%s host:%s", refer_loc,
                                  host)
                return

        # check for '..', which will leak file
        if re.search(r'(\.{2})', self.path) is not None:
            self.wfile.write(b'HTTP/1.1 404\r\n\r\n')
            launcher_log.warn('%s %s %s haking', self.address_string(),
                              self.command, self.path)
            return

        url_path = urlparse.urlparse(self.path).path
        if url_path == '/':
            return self.req_index_handler()

        url_path_list = self.path.split('/')
        if len(url_path_list) >= 3 and url_path_list[1] == "module":
            module = url_path_list[2]
            if len(url_path_list) >= 4 and url_path_list[3] == "control":
                if module not in module_init.proc_handler:
                    launcher_log.warn("request %s no module in path", url_path)
                    self.send_not_found()
                    return

                if "imp" not in module_init.proc_handler[module]:
                    launcher_log.warn("request module:%s start fail", module)
                    self.send_not_found()
                    return

                path = '/' + '/'.join(url_path_list[4:])
                controler = module_init.proc_handler[module][
                    "imp"].local.web_control.ControlHandler(
                        self.client_address, self.headers, self.command, path,
                        self.rfile, self.wfile)
                controler.do_GET()
                return
            else:
                file_path = os.path.join(root_path, module,
                                         url_path_list[3:].join('/'))
        else:
            file_path = os.path.join(current_path, 'web_ui' + url_path)

        launcher_log.debug('launcher web_control %s %s %s ',
                           self.address_string(), self.command, self.path)
        if os.path.isfile(file_path):
            if file_path.endswith('.js'):
                mimetype = 'application/javascript'
            elif file_path.endswith('.css'):
                mimetype = 'text/css'
            elif file_path.endswith('.html'):
                mimetype = 'text/html'
            elif file_path.endswith('.jpg'):
                mimetype = 'image/jpeg'
            elif file_path.endswith('.png'):
                mimetype = 'image/png'
            else:
                mimetype = 'text/plain'

            self.send_file(file_path, mimetype)
        elif url_path == '/config':
            self.req_config_handler()
        elif url_path == '/download':
            self.req_download_handler()
        elif url_path == '/init_module':
            self.req_init_module_handler()
        elif url_path == '/quit':
            self.send_response('text/html', '{"status":"success"}')
            module_init.stop_all()
            os._exit(0)
        elif url_path == '/restart':
            self.send_response('text/html', '{"status":"success"}')
            update_from_github.restart_xxnet()
        else:
            self.wfile.write(
                b'HTTP/1.1 404\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n404 Not Found'
            )
            launcher_log.info('%s "%s %s HTTP/1.1" 404 -',
                              self.address_string(), self.command, self.path)
コード例 #54
0
ファイル: update.py プロジェクト: joesleung/chrome-xx
def generate_new_uuid():
    xx_net_uuid = str(uuid.uuid4())
    config.set(["update", "uuid"], xx_net_uuid)
    launcher_log.info("generate uuid:%s", xx_net_uuid)
    config.save()
コード例 #55
0
 def add(name, cmd):
     file_content = plist_template % cmd
     launcher_log.info("create file:%s", plist_file_path)
     with open(plist_file_path, "w") as f:
         f.write(file_content)
コード例 #56
0
ファイル: update.py プロジェクト: ScalaGo/XX-Net
def generate_new_uuid():
    xx_net_uuid = str(uuid.uuid4())
    config.set(["update", "uuid"], xx_net_uuid)
    launcher_log.info("generate uuid:%s", xx_net_uuid)
    config.save()
コード例 #57
0
    def req_config_handler(self):
        req = urlparse(self.path).query
        reqs = parse_qs(req, keep_blank_values=True)
        data = ''

        if reqs['cmd'] == ['get_config']:
            config.load()
            data = '{ "popup_webui": %d, "show_systray": %d, "auto_start": %d, "language": "%s", "ossftp_address": "%s", "ossftp_port": %d, "ossftp_loglevel": "%s", "ossftp_bucketendpoints": "%s", "passive_ports_start":%d, "passive_ports_end":%d}' %\
                   (config.get(["modules", "launcher", "popup_webui"], 1)
                    , config.get(["modules", "launcher", "show_systray"], 1)
                    , config.get(["modules", "launcher", "auto_start"], 0)
                    , config.get(["modules", "launcher", "language"], "cn")
                    , config.get(["modules", "ossftp", "address"], '127.0.0.1')
                    , config.get(["modules", "ossftp", "port"], 2048)
                    , config.get(["modules", "ossftp", "log_level"], 'INFO')
                    , config.get(["modules", "ossftp", "bucket_endpoints"], '')
                    , config.get(["modules", "ossftp", "passive_ports_start"], 51000)
                    , config.get(["modules", "ossftp", "passive_ports_end"], 53000))
        elif reqs['cmd'] == ['set_config']:
            success = True
            popup_webui = config.get(["modules", "launcher", "popup_webui"], 1)
            auto_start = config.get(["modules", "launcher", "auto_start"], 0)
            show_systray = config.get(["modules", "launcher", "show_systray"],
                                      1)
            language = config.get(["modules", "launcher", "language"], "cn")
            ossftp_address = config.get(["modules", "ossftp", "address"],
                                        "127.0.0.1")
            ossftp_port = config.get(["modules", "ossftp", "port"], 2048)
            ossftp_loglevel = config.get(["modules", "ossftp", "log_level"],
                                         'INFO')
            ossftp_bucketendpoints = config.get(
                ["modules", "ossftp", "bucket_endpoints"], '')
            passive_ports_start = config.get(
                ["modules", "ossftp", "passive_ports_start"], 51000)
            passive_ports_end = config.get(
                ["modules", "ossftp", "passive_ports_end"], 53000)
            data = '{"res":"fail"}'
            if success and 'language' in reqs:
                language = reqs['language'][0]
                if language != 'en' and language != 'cn':
                    success = False
                    data = '{"res":"fail, language:%s"}' % language
            if success and 'popup_webui' in reqs:
                popup_webui = int(reqs['popup_webui'][0])
                if popup_webui != 0 and popup_webui != 1:
                    success = False
                    data = '{"res":"fail, popup_webui:%s"}' % popup_webui
            if success and 'show_systray' in reqs:
                show_systray = int(reqs['show_systray'][0])
                if show_systray != 0 and show_systray != 1:
                    success = False
                    data = '{"res":"fail, show_systray:%s"}' % show_systray
            if success and 'auto_start' in reqs:
                auto_start = int(reqs['auto_start'][0])
                if auto_start != 0 and auto_start != 1:
                    success = False
                    data = '{"res":"fail, auto_start:%s"}' % auto_start
            if success and 'ossftp_address' in reqs:
                ossftp_address = reqs['ossftp_address'][0].strip()
                if not self.ip_check(ossftp_address):
                    success = False
                    data = '{"res":"fail, ilegal ossftp address: %s"}' % ossftp_address

            if success and 'ossftp_port' in reqs:
                ossftp_port = int(reqs['ossftp_port'][0])
                if ossftp_port < 0:
                    success = False
                    data = '{"res":"fail, ilegal ossftp port: %d"}' % ossftp_port
            if success and 'ossftp_loglevel' in reqs:
                ossftp_loglevel = reqs['ossftp_loglevel'][0].strip().upper()
                if (ossftp_loglevel not in [
                        'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'
                ]):
                    success = False
                    data = '{"res":"fail, illegal ossftp log level: %s. Must be: DEBUG, INFO, WARNING, ERROR, CRITICAL"}' % ossftp_loglevel
            if success and 'ossftp_bucketendpoints' in reqs:
                ossftp_bucketendpoints = reqs['ossftp_bucketendpoints'][
                    0].strip()
            if success and 'passive_ports_start' in reqs:
                passive_ports_start = int(reqs['passive_ports_start'][0])
                if passive_ports_end < 0:
                    success = False
                    data = '{"res":"fail, illegal ossftp passive_ports_start: %d"}' % passive_ports_start
            if success and 'passive_ports_end' in reqs:
                passive_ports_end = int(reqs['passive_ports_end'][0])
                if passive_ports_end < 0:
                    success = False
                    data = '{"res":"fail, illegal ossftp passive_ports_end: %d"}' % passive_ports_end

            if success:
                config.set(["modules", "launcher", "popup_webui"], popup_webui)
                config.set(["modules", "launcher", "show_systray"],
                           show_systray)
                config.set(["modules", "launcher", "auto_start"], auto_start)
                config.set(["modules", "launcher", "language"], language)
                config.set(["modules", "ossftp", "address"], ossftp_address)
                config.set(["modules", "ossftp", "port"], ossftp_port)
                config.set(["modules", "ossftp", "log_level"], ossftp_loglevel)
                config.set(["modules", "ossftp", "bucket_endpoints"],
                           ossftp_bucketendpoints)
                config.set(["modules", "ossftp", "passive_ports_start"],
                           passive_ports_start)
                config.set(["modules", "ossftp", "passive_ports_end"],
                           passive_ports_end)
                config.save()
                if auto_start:
                    autorun.enable()
                else:
                    autorun.disable()
                data = '{"res":"success"}'

                import copy
                tmp_config = copy.deepcopy(config.config.copy())
                del tmp_config['modules']['accounts']
                launcher_log.info(
                    'Set config: %s',
                    json.dumps(tmp_config,
                               sort_keys=True,
                               separators=(',', ':'),
                               indent=2))
            else:
                launcher_log.error(data)

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