Esempio n. 1
0
def connect(blocks: list):
    clean_blocks(blocks)
    if not blocks:
        connect_default()
    elif len(blocks) < 2 or len(blocks) > 2:
        print('Error format,should be `connect group nodeName` ')
        return
    else:
        conf = load_default_config()
        node_str = get_node_str(blocks[len(blocks) - 1])
        connect_by_nodestr(node_str, conf['path'], conf['http_port'],
                           conf['socks_port'])
Esempio n. 2
0
def show_info(blocks: list):
    blocks = clean_blocks(blocks)
    if not blocks:
        print('No node currently')
        return
    node_str = get_node_str(blocks[len(blocks) - 1])
    info_list = convert(node_str)
    for info in info_list:
        print(
            'Group    %s\nName     %s\nProtocol %s\nAddress  %s\nPort     %s\nLink     %s'
            % (info['Group'], info['Name'], info['Protocol'], info['Address'],
               info['Port'], info['Link']))
Esempio n. 3
0
def update(blocks: list):
    blocks = clean_blocks(blocks)
    if len(blocks) > 1:
        print('Error format,should be `update sub_name` or `update [url]`')
    if len(blocks) == 0:
        update_from_sub()
    elif blocks[0].startswith('https://') or blocks[0].startswith('http://'):
        sub_name = input('Please input sub_name : ')
        if sub_name == '':
            sub_name = ''.join(random.sample(string.ascii_lowercase, 6))
        update_from_url(blocks[0], sub_name)
    else:
        update_from_url(get_sub_url(blocks[0]))
Esempio n. 4
0
def path_about(blocks: list):
    conf = load_default_config()
    blocks = clean_blocks(blocks)
    if (not len(blocks)) or len(blocks) > 2 or len(blocks) < 1:
        print('Error Format,shoould be `path show` or `path set [path]`')
        return
    if blocks[0] == 'show':
        print('Path : %s' % conf['path'])
    elif blocks[0] == 'set':
        path = input('Please input v2ray path : ')
        conf['path'] = path
        with open(LAST_CONNECT, 'w', encoding='utf-8') as f:
            f.write(json.dumps(conf, ensure_ascii=False, indent=4))
Esempio n. 5
0
def port_about(blocks: list):
    conf = load_default_config()
    blocks = clean_blocks(blocks)
    if (not len(blocks)) or len(blocks) > 3 or len(blocks) < 1:
        print(
            'Error Format,shoould be `port show port` or `port set port [port]`'
        )
        return
    if blocks[0] == 'show':
        print('Http port  : %s\nSocks port : %s' %
              (conf['http_port'], conf['socks_port']))
    elif blocks[0] == 'set':
        http_port = int(input('Please input http port : '))
        socks_port = int(input('Please input socks port : '))
        conf['http_port'] = http_port
        conf['socks_port'] = socks_port
        with open(LAST_CONNECT, 'w', encoding='utf-8') as f:
            f.write(json.dumps(conf, ensure_ascii=False, indent=4))
Esempio n. 6
0
def delete_func(blocks: list):
    blocks = clean_blocks(blocks)
    if (not blocks) or (len(blocks) > 2):
        print(
            'Error format,should be `delete sub_name` or `delete sub_name node_name`'
        )
        return
    elif len(blocks) == 1:
        sub_name = blocks[0]
        choice = input('Be sure to delete subscription %s ? [y/n] ' % sub_name)
        if choice == 'y' or choice == 'Y':
            delete_sub(sub_name)
        else:
            return
    elif len(blocks) == 2:
        node_name = blocks[len(blocks) - 1].replace('%20', ' ')
        choice = input('Be sure to delete node %s ? [y/n] ' % node_name)
        if choice == 'y' or choice == 'Y':
            delete_node(get_node_str(node_name))
        else:
            return
        pass