From b159b10be4f4f0443ba4f0f52118e041a48c2be1 Mon Sep 17 00:00:00 2001 From: Jrohy Date: Sat, 21 Sep 2019 17:17:00 +0800 Subject: [PATCH] update v3.6.0 --- Changelog.md | 6 + v2ray_util/__init__.py | 2 +- v2ray_util/app.py | 227 ------------------------- v2ray_util/config_modify/base.py | 26 ++- v2ray_util/config_modify/cdn.py | 12 +- v2ray_util/config_modify/multiple.py | 12 +- v2ray_util/config_modify/ss.py | 5 +- v2ray_util/config_modify/stream.py | 5 +- v2ray_util/config_modify/tls.py | 16 +- v2ray_util/global_setting/ban_bt.py | 6 +- v2ray_util/global_setting/stats_ctr.py | 9 +- v2ray_util/main.py | 14 -- v2ray_util/util_core/client.py | 2 +- v2ray_util/util_core/config.py | 3 - v2ray_util/util_core/util.cfg | 6 - v2ray_util/util_core/v2ray.py | 16 ++ v2ray_util/web.py | 25 --- 17 files changed, 95 insertions(+), 297 deletions(-) delete mode 100644 v2ray_util/app.py delete mode 100644 v2ray_util/web.py diff --git a/Changelog.md b/Changelog.md index a6ed4ac9..f2aeb303 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,9 @@ +> v3.6.0 +* Fixed: #218 +* Fixed: v2ray重启失败时提示重启成功 +* Fixed: 没有修改配置文件却触发v2ray重启 +* Added: cdn 命令行传参(v2ray cdn) + > v3.5.2 * 支持80端口和443端口的cdn模式 * 支持域名按group存储 diff --git a/v2ray_util/__init__.py b/v2ray_util/__init__.py index 5c8d0b6b..a4831484 100644 --- a/v2ray_util/__init__.py +++ b/v2ray_util/__init__.py @@ -1,3 +1,3 @@ -__version__ = '3.5.2' +__version__ = '3.6.0' from .util_core.trans import _ \ No newline at end of file diff --git a/v2ray_util/app.py b/v2ray_util/app.py deleted file mode 100644 index 45ab2b28..00000000 --- a/v2ray_util/app.py +++ /dev/null @@ -1,227 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -import json -import os -from flask import request, jsonify, Blueprint - -from .util_core.loader import Loader -from .util_core.utils import ss_method, stream_list, StreamType -from .util_core.writer import NodeWriter, GroupWriter, ClientWriter, GlobalWriter, StreamWriter - -func_router = Blueprint('func_router', __name__) - -loader = Loader() - -class ResponseJson: - def __init__(self, success=True, msg="success", data=None): - self.success = success - self.msg = msg - self.data = data - -def find_client(group_list, client_index): - find, group = False, None - for single_group in group_list: - if find: - break - for index, node in enumerate(single_group.node_list): - if node.user_number == client_index: - client_index = index - group = single_group - find = True - break - return group, client_index - -@func_router.route('/list', methods=['GET']) -def node_list(): - loader.load_profile() - return json.dumps(loader.profile, default=lambda x: x.__dict__, ensure_ascii=False) - -@func_router.route('/collection/', methods=['GET']) -def collection(ctype): - success, msg, result = True, "get {} success!!!".format(ctype), None - try: - if ctype == 'ss_method': - result = ss_method() - elif ctype == 'new_port': - result = [x.value for x in stream_list()] - elif ctype == 'stream': - result = [x.value for x in StreamType] - else: - raise ValueError("{} ctype not found".format(ctype)) - except Exception as e: - success = False - msg = str(e) - return jsonify(ResponseJson(success, msg, result).__dict__) - -@func_router.route('/manage/', methods=['POST']) -def manage(action): - success, msg, result = True, "{} v2ray success!!!".format(action), None - try: - if action in ['start', 'stop', 'restart']: - os.system("service v2ray {}".format(action)) - else: - raise ValueError("{} action not found".format(action)) - except Exception as e: - success = False - msg = str(e) - return jsonify(ResponseJson(success, msg, result).__dict__) - -@func_router.route('/user', methods = ['POST']) -def add_user(): - success, msg, kw = True, "add user success!!!", dict() - try: - json_request = json.loads(request.get_data()) - group_tag = json_request['group_tag'] - kw['email'] = json_request['email'] - loader.load_profile() - group_list = loader.profile.group_list - group = list(filter(lambda group:group.tag == group_tag, group_list))[0] - nw = NodeWriter(group.tag, group.index) - nw.create_new_user(**kw) - except Exception as e: - success = False - msg = str(e) - return jsonify(ResponseJson(success, msg).__dict__) - -@func_router.route('/user/', methods = ['DELETE']) -def del_user(client_index): - success, msg = True, "del user {} success!!!".format(client_index) - try: - loader.load_profile() - group_list = loader.profile.group_list - group, client_index = find_client(group_list, client_index) - nw = NodeWriter() - nw.del_user(group, client_index) - except Exception as e: - success = False - msg = str(e) - return jsonify(ResponseJson(success, msg).__dict__) - -@func_router.route('/group', methods = ['POST']) -def add_group(): - success, msg, kw, stream_type = True, "add group {} success!!!", dict(), "" - try: - json_request = json.loads(request.get_data()) - port = int(json_request['port']) - stream_type = json_request['stream_type'] - - from .util_core.utils import stream_list - stream_list = stream_list() - if stream_type not in [x.value for x in stream_list]: - raise ValueError("stream_type {} not found".format(stream_type)) - if "data" in json_request: - kw = json_request['data'] - - stream = list(filter(lambda stream:stream.value == stream_type, stream_list))[0] - nw = NodeWriter() - nw.create_new_port(port, stream, **kw) - msg = msg.format(stream_type) - except Exception as e: - success = False - msg = str(e) - return jsonify(ResponseJson(success, msg).__dict__) - -@func_router.route('/group/', methods = ['DELETE']) -def del_group(group_tag): - success, msg = True, "del group {} success!!!".format(group_tag) - try: - loader.load_profile() - group_list = loader.profile.group_list - group = list(filter(lambda group:group.tag == group_tag, group_list))[0] - nw = NodeWriter() - nw.del_port(group) - except Exception as e: - success = False - msg = str(e) - return jsonify(ResponseJson(success, msg).__dict__) - -@func_router.route('/stream/', methods = ['PUT']) -def modify_stream(group_tag): - success, msg, kw = True, "modify group {} success!!!".format(group_tag), dict() - try: - json_request = json.loads(request.get_data()) - stream_type = json_request['stream_type'] - if stream_type not in [x.value for x in StreamType]: - raise ValueError("stream_type {} not found".format(stream_type)) - if "data" in json_request: - kw = json_request['data'] - stream = list(filter(lambda stream:stream.value == stream_type, StreamType))[0] - - loader.load_profile() - group_list = loader.profile.group_list - group = list(filter(lambda group:group.tag == group_tag, group_list))[0] - sw = StreamWriter(group.tag, group.index, stream) - sw.write(**kw) - except Exception as e: - success = False - msg = str(e) - return jsonify(ResponseJson(success, msg).__dict__) - -@func_router.route('/group/', methods = ['PUT']) -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__) - -@func_router.route('/user/', methods = ['PUT']) -def modify_user(client_index): - success, msg, modify_type = True, "modify user {} success!!!".format(client_index), "" - 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, client_index = find_client(group_list, client_index) - cw = ClientWriter(group.tag, group.index, client_index) - method = 'write_' + modify_type - if hasattr(cw, method): - func = getattr(cw, method) - 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__) - -@func_router.route('/global', methods = ['PUT']) -def modify_global(): - success, msg, modify_type = True, "modify global {} success!!!", "" - 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 - gw = GlobalWriter(group_list) - method = 'write_' + modify_type - if hasattr(gw, method): - func = getattr(gw, method) - func(value) - else: - raise RuntimeError("{} method not found".format(method)) - msg = msg.format(modify_type) - except Exception as e: - success = False - msg = str(e) - return jsonify(ResponseJson(success, msg).__dict__) \ No newline at end of file diff --git a/v2ray_util/config_modify/base.py b/v2ray_util/config_modify/base.py index d8aa76df..1e0afa4e 100644 --- a/v2ray_util/config_modify/base.py +++ b/v2ray_util/config_modify/base.py @@ -1,9 +1,11 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +from ..util_core.v2ray import restart from ..util_core.group import Vmess, Socks, Mtproto, SS from ..util_core.writer import ClientWriter, GroupWriter from ..util_core.selector import ClientSelector, GroupSelector +@restart() def alterid(): cs = ClientSelector(_('modify alterId')) group = cs.group @@ -19,11 +21,13 @@ def alterid(): cw = ClientWriter(group.tag, group.index, client_index) cw.write_aid(int(new_alterid)) print(_("alterId modify success!")) + return True else: print(_("input error, please check is number")) else: print(_("only vmess protocol can modify alterId!")) +@restart() def dyn_port(): gs = GroupSelector(_('modify dyn_port')) group = gs.group @@ -42,14 +46,17 @@ def dyn_port(): if (newAlterId.isdecimal()): gw.write_dyp(True, newAlterId) print(_("open dyn_port success!")) + return True else: print(_("input error, please check is number")) elif choice == 'n': gw.write_dyp(False) print(_("close dyn_port success!")) + return True else: print(_("input error, please input again")) +@restart() def new_email(): cs = ClientSelector(_('modify email')) group = cs.group @@ -88,7 +95,9 @@ def new_email(): cw = ClientWriter(group.tag, group.index, client_index) cw.write_email(email) print(_("modify email success!!")) + return True +@restart() def new_uuid(): cs = ClientSelector(_('modify uuid')) group = cs.group @@ -107,11 +116,13 @@ def new_uuid(): cw = ClientWriter(group.tag, group.index, client_index) cw.write_uuid(new_uuid) print(_("UUID modify success!")) + return True else: print(_("undo modify")) else: print(_("only vmess protocol can modify uuid!")) +@restart(True) def port(): gs = GroupSelector(_('modify port')) group = gs.group @@ -130,20 +141,22 @@ def port(): gw = GroupWriter(group.tag, group.index) gw.write_port(new_port_info) print(_('port modify success!')) + return True else: print(_("input error!")) +@restart() def tfo(): gs = GroupSelector(_('modify tcpFastOpen')) group = gs.group if group == None: - exit(-1) + pass else: if type(group.node_list[0]) == Mtproto or type(group.node_list[0]) == SS: print(_("V2ray MTProto/Shadowsocks don't support tcpFastOpen!!!")) print("") - exit(-1) + return print('{}: {}'.format(_("group tcpFastOpen"), group.tfo)) print("") @@ -151,6 +164,11 @@ def tfo(): print(_("2.close TFO(force close)")) print(_("3.delete TFO(use system default profile)")) choice = input(_("please select: ")) + if not choice: + return + if not choice in ("1", "2", "3"): + print(_("input error, please input again")) + return gw = GroupWriter(group.tag, group.index) if choice == "1": @@ -159,5 +177,5 @@ def tfo(): gw.write_tfo('off') elif choice == "3": gw.write_tfo('del') - else: - print(_("input error, please input again")) \ No newline at end of file + + return True \ No newline at end of file diff --git a/v2ray_util/config_modify/cdn.py b/v2ray_util/config_modify/cdn.py index 43fb26f3..db7686e9 100644 --- a/v2ray_util/config_modify/cdn.py +++ b/v2ray_util/config_modify/cdn.py @@ -3,6 +3,7 @@ import socket from .tls import TLSModifier +from ..util_core.v2ray import restart from ..util_core.selector import GroupSelector from ..util_core.writer import StreamWriter, GroupWriter from ..util_core.utils import StreamType, ColorStr, get_ip @@ -34,12 +35,13 @@ def openHttps(self): self.gw.write_port("443") TLSModifier(self.group_tag, self.group_index, self.domain).turn_on() +@restart() def modify(): gs = GroupSelector(_("run cdn mode")) group = gs.group if group == None: - exit(-1) + pass else: print("") print(_("1.80 port + ws")) @@ -47,6 +49,10 @@ def modify(): choice = input(_("please select: ")) if not choice: return + if not choice in ("1", "2"): + print(_("input error, please input again")) + return + fake_domain = input(_("please input ws fake domain(enter to no need): ")) domain = input(_("please input run cdn mode domain: ")) if not domain: @@ -75,5 +81,5 @@ def modify(): cm.openHttp() elif choice == '2': cm.openHttps() - else: - print(_("input error, please input again")) \ No newline at end of file + + return True \ No newline at end of file diff --git a/v2ray_util/config_modify/multiple.py b/v2ray_util/config_modify/multiple.py index d8868926..2b6b501d 100644 --- a/v2ray_util/config_modify/multiple.py +++ b/v2ray_util/config_modify/multiple.py @@ -3,11 +3,13 @@ import random import sys +from ..util_core.v2ray import restart from ..util_core.writer import NodeWriter, GroupWriter from ..util_core.group import Vmess, Socks, Mtproto, SS from ..util_core.selector import GroupSelector, ClientSelector from ..util_core.utils import StreamType, stream_list, is_email, clean_iptables, ColorStr +@restart(True) def new_port(new_stream=None): info = dict() if new_stream: @@ -47,16 +49,18 @@ def new_port(new_stream=None): print("") nw = NodeWriter() nw.create_new_port(int(new_port), stream, **info) + return True else: print(_("input error, please check is number")) +@restart() def new_user(): gs = GroupSelector(_('user number')) group = gs.group group_list = gs.group_list if group == None: - exit(-1) + pass else: email = "" if type(group.node_list[0]) == Vmess: @@ -84,6 +88,7 @@ def new_user(): nw = NodeWriter(group.tag, group.index) info = {'email': email} nw.create_new_user(**info) + return True elif type(group.node_list[0]) == Socks: print(_("local group is socks, please input user and password to create user")) @@ -96,6 +101,7 @@ def new_user(): info = {"user":user, "pass": password} nw = NodeWriter(group.tag, group.index) nw.create_new_user(**info) + return True elif type(group.node_list[0]) == Mtproto: print("") @@ -105,6 +111,7 @@ def new_user(): print("") print(_("Shadowsocks protocol only support one user, u can add new port to multiple SS!")) +@restart() def del_port(): gs = GroupSelector(_('del port')) group = gs.group @@ -119,9 +126,11 @@ def del_port(): nw = NodeWriter() nw.del_port(group) clean_iptables(group.port) + return True else: print(_("undo delete")) +@restart() def del_user(): cs = ClientSelector(_('del user')) group = cs.group @@ -138,5 +147,6 @@ def del_user(): clean_iptables(group.port) nw = NodeWriter() nw.del_user(group, client_index) + return True else: print(_("undo delete")) \ No newline at end of file diff --git a/v2ray_util/config_modify/ss.py b/v2ray_util/config_modify/ss.py index 2ff364a7..7fb7d907 100644 --- a/v2ray_util/config_modify/ss.py +++ b/v2ray_util/config_modify/ss.py @@ -5,6 +5,7 @@ import sys from ..util_core.group import SS +from ..util_core.v2ray import restart from ..util_core.writer import GroupWriter from ..util_core.selector import GroupSelector from ..util_core.utils import ss_method, ColorStr @@ -32,6 +33,7 @@ def get_password(self): new_pass = random_pass return new_pass +@restart() def modify(alter_type='method'): # 外部传参来决定修改哪种, 默认修改method correct_way = ("method", "password") @@ -57,4 +59,5 @@ def modify(alter_type='method'): gw.write_ss_method(sm.get_method()) elif alter_type == correct_way[1]: gw.write_ss_password(sm.get_password()) - print("{0} {1} {2}\n".format(_("modify Shadowsocks"),alter_type, _("success"))) \ No newline at end of file + print("{0} {1} {2}\n".format(_("modify Shadowsocks"),alter_type, _("success"))) + return True \ No newline at end of file diff --git a/v2ray_util/config_modify/stream.py b/v2ray_util/config_modify/stream.py index cac0eb04..cf24f45c 100644 --- a/v2ray_util/config_modify/stream.py +++ b/v2ray_util/config_modify/stream.py @@ -3,6 +3,7 @@ import random import string +from ..util_core.v2ray import restart from ..util_core.writer import StreamWriter from ..util_core.selector import GroupSelector, CommonSelector from ..util_core.group import Mtproto, SS @@ -71,12 +72,13 @@ def random_kcp(self): print("{}: {} \n".format(_("random generate (srtp | wechat-video | utp | dtls) fake header, new protocol"), ColorStr.green(kcp_list[choice - 4]))) self.select(choice) +@restart() def modify(): gs = GroupSelector(_('modify protocol')) group = gs.group if group == None: - exit(-1) + pass else: sm = StreamModifier(group.tag, group.index) @@ -96,5 +98,6 @@ def modify(): print(_("V2ray MTProto/Shadowsocks not support https, close tls success!")) sm.select(choice - 1) print(_("modify protocol success")) + return True else: print(_("input out of range!!")) \ No newline at end of file diff --git a/v2ray_util/config_modify/tls.py b/v2ray_util/config_modify/tls.py index bb772aed..3a4ec3d6 100644 --- a/v2ray_util/config_modify/tls.py +++ b/v2ray_util/config_modify/tls.py @@ -3,6 +3,7 @@ import socket import os +from ..util_core.v2ray import restart from ..util_core.writer import GroupWriter from ..util_core.group import Mtproto, SS from ..util_core.selector import GroupSelector @@ -61,17 +62,18 @@ def turn_on(self): def turn_off(self): self.writer.write_tls(False) +@restart() def modify(): gs = GroupSelector(_('modify tls')) group = gs.group if group == None: - exit(-1) + pass else: if type(group.node_list[0]) == Mtproto or type(group.node_list[0]) == SS: print(_("V2ray MTProto/Shadowsocks protocol not support https!!!")) print("") - exit(-1) + return tm = TLSModifier(group.tag, group.index) tls_status = 'open' if group.tls == 'tls' else 'close' print("{}: {}\n".format(_("group tls status"), tls_status)) @@ -79,9 +81,15 @@ def modify(): print(_("1.open TLS")) print(_("2.close TLS")) choice = input(_("please select: ")) + if not choice: + return + if not choice in ("1", "2"): + print(_("input error, please input again")) + return + if choice == '1': tm.turn_on() elif choice == '2': tm.turn_off() - else: - print(_("input error, please input again")) \ No newline at end of file + + return True \ No newline at end of file diff --git a/v2ray_util/global_setting/ban_bt.py b/v2ray_util/global_setting/ban_bt.py index 88cb6feb..bfb7d573 100644 --- a/v2ray_util/global_setting/ban_bt.py +++ b/v2ray_util/global_setting/ban_bt.py @@ -1,8 +1,10 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- from ..util_core.loader import Loader +from ..util_core.v2ray import restart from ..util_core.writer import GlobalWriter +@restart() def manage(): loader = Loader() @@ -21,4 +23,6 @@ def manage(): gw.write_ban_bittorrent(ban_bt) - print(_("modify success!")) \ No newline at end of file + print(_("modify success!")) + + return True \ No newline at end of file diff --git a/v2ray_util/global_setting/stats_ctr.py b/v2ray_util/global_setting/stats_ctr.py index 7f9e5e18..c60c8b4f 100644 --- a/v2ray_util/global_setting/stats_ctr.py +++ b/v2ray_util/global_setting/stats_ctr.py @@ -3,6 +3,7 @@ import os import re +from ..util_core.v2ray import V2ray from ..util_core.loader import Loader from ..util_core.writer import GlobalWriter from ..util_core.utils import bytes_2_human_readable, ColorStr @@ -44,11 +45,8 @@ def print_stats(self): ColorStr.cyan(bytes_2_human_readable(self.downlink_value + self.uplink_value, 2))) ) - def manage(): - RESTART_CMD = "service v2ray restart" - FIND_V2RAY_CRONTAB_CMD = "crontab -l|grep v2ray" DEL_UPDATE_TIMER_CMD = "crontab -l|sed '/SHELL=/d;/v2ray/d' > crontab.txt && crontab crontab.txt >/dev/null 2>&1 && rm -f crontab.txt >/dev/null 2>&1" @@ -86,16 +84,17 @@ def manage(): continue gw = GlobalWriter(group_list) gw.write_stats(True) - os.system(RESTART_CMD) + V2ray.restart() print(_("open traffic statistics success!")) print("") elif choice == "2": gw = GlobalWriter(group_list) gw.write_stats(False) - os.system(RESTART_CMD) + V2ray.restart() print(_("close traffic statistics success!")) print("") + elif choice == "3" or choice == "4": is_reset = (False if choice == "3" else True) action_info = ("check" if choice == "3" else "reset") diff --git a/v2ray_util/main.py b/v2ray_util/main.py index a31255ef..6cdd2610 100644 --- a/v2ray_util/main.py +++ b/v2ray_util/main.py @@ -101,28 +101,20 @@ def parse_arg(): V2ray.info() elif sys.argv[1] == "port": base.port() - open_port() - V2ray.restart() elif sys.argv[1] == "tls": tls.modify() - V2ray.restart() elif sys.argv[1] == "tfo": base.tfo() - V2ray.restart() elif sys.argv[1] == "stream": stream.modify() - V2ray.restart() elif sys.argv[1] == "stats": iptables_ctr.manage() elif sys.argv[1] == "clean": V2ray.cleanLog() elif sys.argv[1] == "del": multiple.del_port() - V2ray.restart() elif sys.argv[1] == "add": multiple.new_port() - open_port() - V2ray.restart() elif sys.argv[1] == "update": V2ray.update() elif sys.argv[1] == "new": @@ -133,11 +125,9 @@ def parse_arg(): V2ray.log() elif sys.argv[1] == "cdn": cdn.modify() - V2ray.restart() else: if sys.argv[1] == "add": multiple.new_port(sys.argv[2]) - V2ray.restart() sys.exit(0) def service_manage(): @@ -174,7 +164,6 @@ def user_manage(): multiple.del_user() elif choice == 4: multiple.del_port() - V2ray.restart() def profile_alter(): show_text = (_("modify email"), _("modify UUID"), _("modify alterID"), _("modify port"), _("modify stream"), _("modify tls"), @@ -193,7 +182,6 @@ def profile_alter(): base.alterid() elif choice == 4: base.port() - open_port() elif choice == 5: stream.modify() elif choice == 6: @@ -208,7 +196,6 @@ def profile_alter(): ss.modify('password') elif choice == 11: cdn.modify() - V2ray.restart() def global_setting(): show_text = (_("V2ray Traffic Statistics"), _("Iptables Traffic Statistics"), _("Ban Bittorrent"), _("Schedule Update V2ray"), _("Clean Log"), _("Change Language")) @@ -222,7 +209,6 @@ def global_setting(): iptables_ctr.manage() elif choice == 3: ban_bt.manage() - V2ray.restart() elif choice == 4: update_timer.manage() elif choice == 5: diff --git a/v2ray_util/util_core/client.py b/v2ray_util/util_core/client.py index dfbe9e71..70147eea 100644 --- a/v2ray_util/util_core/client.py +++ b/v2ray_util/util_core/client.py @@ -79,7 +79,7 @@ def generate(): group = cs.group if group == None: - exit(-1) + pass else: cw = ClientWriter(group, client_index) cw.transform() diff --git a/v2ray_util/util_core/config.py b/v2ray_util/util_core/config.py index 2a55841f..845a5b58 100644 --- a/v2ray_util/util_core/config.py +++ b/v2ray_util/util_core/config.py @@ -18,9 +18,6 @@ def __init__(self): def get_path(self, key): return self.config.get('path', key) - def get_web(self, key): - return self.config.get('web', key) - def get_data(self, key): return self.config.get('data', key) diff --git a/v2ray_util/util_core/util.cfg b/v2ray_util/util_core/util.cfg index cda5b0cf..1ca672a7 100644 --- a/v2ray_util/util_core/util.cfg +++ b/v2ray_util/util_core/util.cfg @@ -2,11 +2,5 @@ config_path=/etc/v2ray/config.json write_client_path=/root/config.json -[web] -port=5000 -user=user -pass=pass -index_page=index.html - [data] lang=en \ No newline at end of file diff --git a/v2ray_util/util_core/v2ray.py b/v2ray_util/util_core/v2ray.py index 40f7a3b0..c69883a6 100644 --- a/v2ray_util/util_core/v2ray.py +++ b/v2ray_util/util_core/v2ray.py @@ -6,8 +6,24 @@ import random import subprocess import pkg_resources +from functools import wraps from .utils import ColorStr, open_port +def restart(port_open=False): + """ + 运行函数/方法后重启v2ray的装饰器 + """ + def decorate(func): + @wraps(func) + def wrapper(*args, **kw): + result = func(*args, **kw) + if port_open: + open_port() + if result: + V2ray.restart() + return wrapper + return decorate + class V2ray: @staticmethod diff --git a/v2ray_util/web.py b/v2ray_util/web.py deleted file mode 100644 index 865ef44d..00000000 --- a/v2ray_util/web.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -from flask import Flask, request, jsonify, render_template -from flask_httpauth import HTTPBasicAuth - -from .app import func_router -from .util_core.config import Config - -config = Config() -app = Flask(__name__, static_url_path='/static') -app.register_blueprint(func_router) - -auth = HTTPBasicAuth() - -@auth.get_password -def get_pw(username): - return config.get_web('pass') - -@app.route('/') -@auth.login_required -def index(): - return render_template(config.get_web('index_page')) - -if __name__ == '__main__': - app.run(debug=True, port=config.get_web('port')) \ No newline at end of file