Ejemplo n.º 1
0
class TLSModifier:
    def __init__(self, group_tag, group_index):
        self.writer = GroupWriter(group_tag, group_index)
    
    def turn_on(self):
        print("1. Let’s Encrypt 生成证书(准备域名)")
        print("2. 自定义已存在的其他路径的证书(准备证书文件路径)\n")
        choice=input("请选择使用证书方式: ")
        if choice == "1":
            print("\n请将您的域名解析到本VPS的IP地址,否则程序会出错!!\n")
            local_ip = get_ip()
            print("本机器IP地址为:" + local_ip + "\n")
            input_domain=input("请输入您绑定的域名:")
            try:
                input_ip = socket.gethostbyname(input_domain)
            except Exception:
                print("\n域名检测错误!!!\n")
                return
            if input_ip != local_ip:
                print("\n输入的域名与本机ip不符!!!\n")
                return

            print("")
            print("正在获取SSL证书,请稍等。。。")
            gen_cert(input_domain)
            crt_file = "/root/.acme.sh/" + input_domain +"_ecc"+ "/fullchain.cer"
            key_file = "/root/.acme.sh/" + input_domain +"_ecc"+ "/"+ input_domain +".key"

            self.writer.write_tls(True, crt_file=crt_file, key_file=key_file, domain=input_domain)

        elif choice == "2":
            crt_file = input("请输入证书cert文件路径: ")
            key_file = input("请输入证书key文件路径: ")
            if not os.path.exists(crt_file) or not os.path.exists(key_file):
                print("证书crt文件或者key文件指定路径不存在!\n")
                return
            domain = get_domain_by_crt_file(crt_file)
            if not domain:
                print("证书文件有误!\n")
                return
            self.writer.write_tls(True, crt_file=crt_file, key_file=key_file, domain=domain)
        else:
            print("输入有误!\n")
    
    def turn_off(self):
        self.writer.write_tls(False)
Ejemplo n.º 2
0
def modify_group(group_tag):
    success, msg = True, "modify group {} success!!!".format(group_tag)
    try:
        json_request = json.loads(request.get_data())
        modify_type = json_request['modify_type']
        value = json_request['value']
        loader.load_profile()
        group_list = loader.profile.group_list
        group = list(filter(lambda group: group.tag == group_tag,
                            group_list))[0]
        gw = GroupWriter(group.tag, group.index)
        method = 'write_' + modify_type
        if hasattr(gw, method):
            func = getattr(gw, method)
            if modify_type == "dyp":
                func(bool(value['status']), int(value['aid']))
            else:
                func(value)
        else:
            raise RuntimeError("{} method not found".format(method))
    except Exception as e:
        success = False
        msg = str(e)
    return jsonify(ResponseJson(success, msg).__dict__)
Ejemplo n.º 3
0
if __name__ == '__main__':

    # 外部传参来决定修改哪种, 默认修改method
    choice = "method"
    correct_way = ("method", "password")

    if len(sys.argv) > 1:
        choice = sys.argv[1]
        if choice not in correct_way:
            print("传参有误!")
            exit(-1)
    else:
        print("请传以下参数来修改ss配置: {}".format(correct_way))
        exit(-1)

    gs = GroupSelector('修改SS')
    group = gs.group

    if group == None:
        exit(-1)
    elif type(group.node_list[0]) != SS:
        print("\n当前选择组不是Shadowsocks协议!\n")
        exit(-1)
    else:
        sm = SSFactory()
        gw = GroupWriter(group.tag, group.index)
        if choice == correct_way[0]:
            gw.write_ss_method(sm.get_method())
        elif choice == correct_way[1]:
            gw.write_ss_password(sm.get_password())
        print("修改Shadowsocks {}成功!\n".format(choice))
Ejemplo n.º 4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
from writer import GroupWriter
from selector import GroupSelector

gs = GroupSelector('修改port')
group = gs.group

if group == None:
    exit(-1)
else:
    if group.end_port:
        port_info = "{0}-{1}".format(group.port, group.end_port)
    else:
        port_info = group.port
    print('当前组的端口信息为:{}'.format(port_info))

    port_strategy = "always"
    new_port_info = input("请输入新端口(支持输入端口范围, 用'-'隔开, 表示该范围的全部端口生效):")
    if new_port_info.isdecimal() or re.match(r'^\d+\-\d+$', new_port_info):
        gw = GroupWriter(group.tag, group.index)
        gw.write_port(new_port_info)
        print('端口修改成功!')
    else:
        print("输入错误!")
Ejemplo n.º 5
0
 def __init__(self, group_tag, group_index):
     self.writer = GroupWriter(group_tag, group_index)
Ejemplo n.º 6
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from writer import GroupWriter
from selector import GroupSelector

gs = GroupSelector('修改动态端口')
group = gs.group

if group == None:
    pass
else:
    print('当前组的动态端口状态:{}'.format(group.dyp))
    gw = GroupWriter(group.tag, group.index)

    choice = input("是否开启动态端口(y/n): ").lower()

    if choice == 'y':
        newAlterId = input("请为动态端口设置alterID(默认32): ")
        newAlterId = '32' if newAlterId == '' else newAlterId
        if (newAlterId.isdecimal()):
            gw.write_dyp(True, newAlterId)
            print("\n成功开启动态端口!")
        else:
            print("\n输入错误,请检查是否为数字")
    elif choice == 'n':
        gw.write_dyp(False)
        print("\n成功关闭动态端口!")
    else:
        print("\n输入错误,请检查重新输入")
Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
from group import Mtproto, SS
from writer import GroupWriter
from selector import GroupSelector

gs = GroupSelector('修改tcpFastOpen')
group = gs.group

if group == None:
    exit(-1)
else:
    if type(group.node_list[0]) == Mtproto or type(group.node_list[0]) == SS:
        print("\nv2ray MTProto/Shadowsocks协议不支持配置tcpFastOpen!!!\n")
        exit(-1)
    
    print('当前组的tcpFastOpen状态:{}'.format(group.tfo))
    print("")
    print("1.开启TFO(强制开启)")
    print("2.关闭TFO(强制关闭)")
    print("3.删除TFO(使用系统默认设置)")
    choice = input("请输入数字选择功能:")
    
    gw = GroupWriter(group.tag, group.index)
    if choice == "1":
        gw.write_tfo('on')
    elif choice == "2":
        gw.write_tfo('off')
    elif choice == "3":
        gw.write_tfo('del')
    else:
        print("输入错误,请重试!")