From 7308455d9393c9764c40d58225e36bc1cb3c4797 Mon Sep 17 00:00:00 2001 From: Jrohy Date: Sun, 16 Dec 2018 16:40:00 +0800 Subject: [PATCH] Fixed: #95 #96 --- global_setting/clean_iptables.sh | 18 ++++++++++++------ global_setting/stats_ctr.py | 2 +- utils.py | 14 ++++++++++---- v2ray | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/global_setting/clean_iptables.sh b/global_setting/clean_iptables.sh index 6ae86828..30bbf251 100644 --- a/global_setting/clean_iptables.sh +++ b/global_setting/clean_iptables.sh @@ -1,8 +1,14 @@ #!/bin/bash -RESULT=$(iptables -nvL INPUT --line-number|grep dpt|awk '{print $1" " $14}'|sed 's/dpt://g'|sort -n -k1 -r) -echo "$RESULT" | while read LINE -do - LINE_ARRAY=($LINE) - [[ ${LINE_ARRAY[1]} && -z $(lsof -i:${LINE_ARRAY[1]}) ]] && iptables -D INPUT ${LINE_ARRAY[0]} -done \ No newline at end of file +clean_iptables(){ + TYPE=$1 + RESULT=$(iptables -nvL $TYPE --line-number|grep :|awk -F ':' '{print $2" " $1}'|awk '{print $2" "$1}'|sort -n -k1 -r) + echo "$RESULT" | while read LINE + do + LINE_ARRAY=($LINE) + [[ ${LINE_ARRAY[1]} && -z $(lsof -i:${LINE_ARRAY[1]}) ]] && iptables -D $TYPE ${LINE_ARRAY[0]} + done +} + +clean_iptables INPUT +clean_iptables OUTPUT \ No newline at end of file diff --git a/global_setting/stats_ctr.py b/global_setting/stats_ctr.py index 27afe917..61e92fb4 100644 --- a/global_setting/stats_ctr.py +++ b/global_setting/stats_ctr.py @@ -96,7 +96,7 @@ def print_stats(self): print("流量统计开启状态才能{}统计\n".format(action_info)) continue - if len(group_list) > 1: + if group_list[-1].node_list[-1].user_number > 1: print(profile) schoice = input("请输入所需要{}流量的组别(字母)或者序号(数字): ".format(action_info)) else: diff --git a/utils.py b/utils.py index 1f8d3374..e07b5df2 100644 --- a/utils.py +++ b/utils.py @@ -169,6 +169,11 @@ def gen_cert(domain): os.system(start_cmd.format(name)) def open_port(): + input_cmd = "iptables -I INPUT -p {0} --dport {1} -j ACCEPT" + output_cmd = "iptables -I OUTPUT -p {0} --sport {1}" + + # 自动清理没用的iptables规则 + os.system("bash /usr/local/multi-v2ray/global_setting/clean_iptables.sh") from loader import Loader @@ -177,7 +182,8 @@ def open_port(): port_set = set([group.port for group in group_list]) for port in port_set: - cmd1="iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport " + str(port) +" -j ACCEPT" - cmd2="iptables -I INPUT -m state --state NEW -m udp -p udp --dport " + str(port) +" -j ACCEPT" - os.system(cmd1) - os.system(cmd2) \ No newline at end of file + port_str = str(port) + os.system(input_cmd.format("tcp", port_str)) + os.system(input_cmd.format("udp", port_str)) + os.system(output_cmd.format("tcp", port_str)) + os.system(output_cmd.format("udp", port_str)) \ No newline at end of file diff --git a/v2ray b/v2ray index 7a08a60e..98cfaa87 100755 --- a/v2ray +++ b/v2ray @@ -1,6 +1,6 @@ #!/bin/bash -SHELL_V2RAY="v2.5.3" +SHELL_V2RAY="v2.5.4" #######color code######## RED="31m" # Error message