Пример #1
0
def install_v2ray_by_version(version: str):
    if v2_core == "v2ray":
        url = f"https://github.com/v2fly/v2ray-core/releases/download/{version}/v2ray-linux-64.zip"
    else:
        url = f"https://github.com/XTLS/Xray-core/releases/download/{version}/Xray-linux-64.zip"

    filename = config.get_dir("v2ray_temp.zip")
    zip_dest_dir = config.get_dir("temp_v2ray")

    try:
        with requests.get(url, stream=True) as response:
            with open(filename, "wb") as f:
                for data in response.iter_content(8192):
                    f.write(data)
        file_util.mkdirs(zip_dest_dir)
        file_util.unzip_file(filename, zip_dest_dir)

        bin_dir = config.get_dir("bin")

        if v2_core == "v2ray":
            filenames = ["v2ray", "v2ctl", "geoip.dat", "geosite.dat"]
        else:
            filenames = ["xray", "geoip.dat", "geosite.dat"]

        for i in range(len(filenames)):
            name = filenames[i]

            dest_file_path = os.path.join(bin_dir, name)
            # del old file
            file_util.del_file(dest_file_path)

            # move new file to dest
            file_util.mv_file(os.path.join(zip_dest_dir, name), dest_file_path)

            # +x
            os.chmod(dest_file_path,
                     stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)

        v2_util.__version = ""
        v2_util.restart()

        return jsonify(
            Msg(
                True,
                gettext("Switch %(v2_core)s version successfully.",
                        v2_core=v2_core)))
    except Exception as e:
        logging.error(f"Download {v2_core} {version} failed.")
        logging.error(e)
        traceback.print_exc()
        return jsonify(
            Msg(
                False,
                gettext("Switch %(v2_core)s-core version failed.",
                        v2_core=v2_core)))
    finally:
        file_util.del_file(filename)
        file_util.del_dir(zip_dest_dir)
Пример #2
0
def install_v2ray_by_version(version: str):
    sys_name = sys_util.sys_name()
    if sys_name == "darwin":
        sys_name = "macos"
    arch = sys_util.arch()
    if arch == "amd64":
        arch = "64"
    elif arch == "arm64":
        arch = "arm64-v8a"
    url = f'https://github.com/XTLS/Xray-core/releases/download/{version}/Xray-{sys_name}-{arch}.zip'
    filename = config.get_dir('v2ray_temp.zip')
    zip_dest_dir = config.get_dir('temp_v2ray')
    try:
        with requests.get(url, stream=True) as response:
            if response.status_code != 200:
                raise Exception(
                    f'download xray url:{url} failed: {response.text}')
            with open(filename, 'wb') as f:
                for data in response.iter_content(8192):
                    f.write(data)
        file_util.mkdirs(zip_dest_dir)
        file_util.unzip_file(filename, zip_dest_dir)

        bin_dir = config.get_dir('bin')

        origin_names = ['xray', 'geoip.dat', 'geosite.dat']
        filenames = [v2_util.get_xray_file_name(), 'geoip.dat', 'geosite.dat']

        for i in range(len(filenames)):
            origin_name = origin_names[i]
            name = filenames[i]

            dest_file_path = os.path.join(bin_dir, name)
            # del old file
            file_util.del_file(dest_file_path)

            # move new file to dest
            file_util.mv_file(os.path.join(zip_dest_dir, origin_name),
                              dest_file_path)

            # +x
            os.chmod(dest_file_path,
                     stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)

        v2_util.__v2ray_version = ''
        v2_util.restart()

        return jsonify(Msg(True, gettext('Switch xray version success')))
    except Exception as e:
        logging.error(f'Download xray {version} failed.')
        logging.error(e)
        traceback.print_exc()
        return jsonify(Msg(False, gettext('Switch xray-core version failed.')))
    finally:
        file_util.del_file(filename)
        file_util.del_dir(zip_dest_dir)
Пример #3
0
def install_v2ray_by_version(version: str):
    url = f'https://github.com/v2fly/v2ray-core/releases/download/{version}/v2ray-linux-64.zip'
    filename = config.get_dir('v2ray_temp.zip')
    zip_dest_dir = config.get_dir('temp_v2ray')
    try:
        with requests.get(url, stream=True) as response:
            with open(filename, 'wb') as f:
                for data in response.iter_content(8192):
                    f.write(data)
        file_util.mkdirs(zip_dest_dir)
        file_util.unzip_file(filename, zip_dest_dir)

        bin_dir = config.get_dir('bin')

        origin_names = ['v2ray', 'v2ctl', 'geoip.dat', 'geosite.dat']
        filenames = ['v2ray-v2-ui', 'v2ctl', 'geoip.dat', 'geosite.dat']

        for i in range(len(filenames)):
            origin_name = origin_names[i]
            name = filenames[i]

            dest_file_path = os.path.join(bin_dir, name)
            # del old file
            file_util.del_file(dest_file_path)

            # move new file to dest
            file_util.mv_file(os.path.join(zip_dest_dir, origin_name),
                              dest_file_path)

            # +x
            os.chmod(dest_file_path,
                     stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)

        v2_util.__v2ray_version = ''
        v2_util.restart()

        return jsonify(Msg(True, gettext('Switch v2ray version success')))
    except Exception as e:
        logging.error(f'Download v2ray {version} failed.')
        logging.error(e)
        traceback.print_exc()
        return jsonify(Msg(False,
                           gettext('Switch v2ray-core version failed.')))
    finally:
        file_util.del_file(filename)
        file_util.del_dir(zip_dest_dir)
Пример #4
0
def check_v2ay_alive_job():
    if not v2_util.is_running():
        v2_util.restart(True)