From c66ad2b7fbd95a36ab738ed42c6aec3ced76019a Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 30 Nov 2024 22:58:24 +0800 Subject: [PATCH] Update firewall.py --- web/utils/firewall.py | 47 +++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index b2e72ee32..d7a8771da 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -60,32 +60,27 @@ class Firewall(object): if t[1] != '': return True - print(t) - - # all_port = t[0].strip() - # data = all_port.split(":") - # ports_str = data[1] - # ports_list = ports_str.strip().split(' ') - - # ports_all = [] - # for pinfo in ports_list: - # info = pinfo.split('/') - - # is_same = False - # for i in range(len(ports_all)): - # if ports_all[i]['port'] == info[0] and ports_all[i]['protocol'] != info[1]: - # ports_all[i]['protocol'] = ports_all[i]['protocol']+'/'+info[1] - # is_same = True - - # if not is_same: - # t = {} - # t['port'] = info[0].replace('-',':') - # t['protocol'] = info[1] - # ports_all.append(t) - - # for add_info in ports_all: - # if thisdb.getFirewallCountByPort(add_info['port']) == 0: - # thisdb.addFirewall(add_info['port'], ps='自动识别',protocol=add_info['protocol']) + all_port = t[0].strip() + ports_list = all_port.split('\n') + + ports_all = [] + for pinfo in ports_list: + info = pinfo.split('/') + + is_same = False + for i in range(len(ports_all)): + if ports_all[i]['port'] == info[0] and ports_all[i]['protocol'] != info[1]: + ports_all[i]['protocol'] = ports_all[i]['protocol']+'/'+info[1] + is_same = True + + if not is_same: + t = {} + t['port'] = info[0].replace('-',':') + t['protocol'] = info[1] + ports_all.append(t) + for add_info in ports_all: + if thisdb.getFirewallCountByPort(add_info['port']) == 0: + thisdb.addFirewall(add_info['port'], ps='自动识别',protocol=add_info['protocol']) def AIF_Firewalld(self): # firewall-cmd --list-all | grep ' ports'