示例#1
0
def _remove_servers(name=DEFAULT_SUBSCRIBE, all_subs=False):
    all_servers = utils.read_from_json(SERVER_CONFIG)
    if all_subs:
        all_servers.clear()
    else:
        all_servers.pop(name, None)
    utils.write_to_json(all_servers, SERVER_CONFIG)
示例#2
0
def _remove_subscribe(name=DEFAULT_SUBSCRIBE, all_subs=False):
    all_subscribes = utils.read_from_json(SUBSCRIBE_CONFIG)
    if all_subs:
        all_subscribes.clear()
    else:
        all_subscribes.pop(name, None)
    utils.write_to_json(all_subscribes, SUBSCRIBE_CONFIG)
示例#3
0
def update_config(node: dict, client_port: int):
    v2ray_config = _get_config(node['add'],
                               int(node['port']),
                               node['id'],
                               node["net"],
                               node["tls"],
                               node["path"],
                               client_port=client_port)
    utils.write_to_json(v2ray_config, V2RAY_CONFIG_FILE)
示例#4
0
def update_config(node: dict, client_port: int):
    v2ray_config = _get_config(addr=node['add'],
                               port=int(node['port']),
                               id_=node['id'],
                               alterId=int(node['aid']),
                               network=node['net'],
                               type=node['type'],
                               tls=node['tls'],
                               client_port=client_port)
    utils.write_to_json(v2ray_config, V2RAY_CONFIG_FILE)
示例#5
0
def run(name, port):
    """start v2ray with a selected node.
    """
    servers = subscribe.get_servers(name)
    menu = TerminalMenu(servers, title=name)
    index = menu.show()
    node = subscribe.get_node(index, name)
    existing_unit = utils.read_from_json(systemd.SYSTEMD_UNIT).get("unit", "")
    existing_config = utils.read_from_json(config.V2RAY_CONFIG_FILE)
    if existing_config != node:
        systemd.stop(existing_unit)
        config.update_config(node, port)
    if not systemd.is_active(existing_unit):
        unit = systemd.start(["v2ray", "-config", config.V2RAY_CONFIG_FILE])
        utils.write_to_json(unit, systemd.SYSTEMD_UNIT)
示例#6
0
def parser_subscribe(url, name=DEFAULT_SUBSCRIBE):
    try:
        resp = requests.get(url)
    except requests.exceptions.ConnectionError:
        click.echo("Can't parse the url, please check your network or make"
                   " sure you entered the correct URL!")
        sys.exit(1)
    nodes = base64.b64decode(resp.content).splitlines()
    servers = []
    for node in nodes:
        node = utils.byte2str(node).replace("vmess://", "")
        node = utils.byte2str(base64.b64decode(node))
        servers.append(json.loads(node))
    all_servers = utils.read_from_json(SERVER_CONFIG)
    all_servers.update({name: servers})
    utils.write_to_json(all_servers, SERVER_CONFIG)
示例#7
0
def parser_subscribe(url, name=DEFAULT_SUBSCRIBE):
    try:
        req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
        resp = urlopen(req)
    except URLError:
        click.echo("Can't parse the url, please check your network or make"
                   " sure you entered the correct URL!")
        sys.exit(1)
    nodes = base64.b64decode(resp.read()).splitlines()
    servers = []
    for node in nodes:
        node = utils.byte2str(node).replace("vmess://", "")
        node = utils.byte2str(base64.b64decode(node))
        servers.append(json.loads(node))
    all_servers = utils.read_from_json(SERVER_CONFIG)
    all_servers.update({name: servers})
    utils.write_to_json(all_servers, SERVER_CONFIG)
示例#8
0
def _update_config(addr, id_, port, client_port=1080):
    v2ray_config = {
        "inbounds": [{
            "port": client_port,
            "listen": "127.0.0.1",
            "protocol": "socks",
            "sniffing": {
                "enable": True,
                "destOverride": ["http", "tls"]
            },
            "settings": {
                "auth": "noauth",
                "udp": True
            }
        }],
        "outbounds": [{
            "protocol": "vmess",
            "settings": {
                "vnext": [{
                    "address": addr,
                    "port": port,
                    "users": [{
                        "id": id_
                    }]
                }]
            }
        }, {
            "protocol": "freedom",
            "tag": "direct",
            "settings": {}
        }],
        "routing": {
            "domainStrategy":
            "IPOnDemand",
            "rules": [{
                "type": "field",
                "domain": ["geosite:cn"],
                "ip": ["geoip:private", "geoip:cn"],
                "outboundTag": "direct"
            }]
        }
    }
    utils.write_to_json(v2ray_config, V2RAY_CONFIG_FILE)
示例#9
0
def add_subscribe(url, name=DEFAULT_SUBSCRIBE):
    subscribe = utils.read_from_json(SUBSCRIBE_CONFIG)
    subscribe.update({name: url})
    utils.write_to_json(subscribe, SUBSCRIBE_CONFIG)
    click.echo("Added subscribe: %s" % url)