Skip to content

Commit

Permalink
Update firewall_api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
midoks committed Jul 25, 2024
1 parent 8ff13fa commit d3ce4a1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions class/core/firewall_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def addDropAddressApi(self):
port = request.form.get('port', '').strip()
ps = request.form.get('ps', '').strip()

rep = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$"
rep = r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$"
if not re.search(rep, port):
return mw.returnJson(False, '您输入的IP地址不合法!')
address = port
Expand Down Expand Up @@ -97,7 +97,7 @@ def addAcceptPortArgs(self, port, ps, stype, protocol='tcp'):
if not self.getFwStatus():
self.setFw(0)

rep = "^\d{1,5}(:\d{1,5})?$"
rep = r"^\d{1,5}(:\d{1,5})?$"
if not re.search(rep, port):
return mw.returnData(False, '端口范围不正确!')

Expand Down Expand Up @@ -217,7 +217,7 @@ def getSshInfoApi(self):

file = '/etc/ssh/sshd_config'
conf = mw.readFile(file)
rep = "#*Port\s+([0-9]+)\s*\n"
rep = r"#*Port\s+([0-9]+)\s*\n"
port = re.search(rep, conf).groups(0)[0]

isPing = True
Expand All @@ -227,7 +227,7 @@ def getSshInfoApi(self):
else:
file = '/etc/sysctl.conf'
sys_conf = mw.readFile(file)
rep = "#*net\.ipv4\.icmp_echo_ignore_all\s*=\s*([0-9]+)"
rep = r"#*net\.ipv4\.icmp_echo_ignore_all\s*=\s*([0-9]+)"
tmp = re.search(rep, sys_conf).groups(0)[0]
if tmp == '1':
isPing = False
Expand All @@ -248,7 +248,7 @@ def getSshInfoApi(self):

data['pass_prohibit_status'] = False
# 密码登陆配置检查
pass_rep = "PasswordAuthentication\s+(\w*)\s*\n"
pass_rep = r"PasswordAuthentication\s+(\w*)\s*\n"
pass_status = re.search(pass_rep, conf)
if pass_status:
if pass_status and pass_status.groups(0)[0].strip() == 'no':
Expand Down Expand Up @@ -277,7 +277,7 @@ def setSshPortApi(self):
file = '/etc/ssh/sshd_config'
conf = mw.readFile(file)

rep = "#*Port\s+([0-9]+)\s*\n"
rep = r"#*Port\s+([0-9]+)\s*\n"
conf = re.sub(rep, "Port " + port + "\n", conf)
mw.writeFile(file, conf)

Expand Down Expand Up @@ -330,17 +330,17 @@ def setSshPassStatusApi(self):

conf = mw.readFile(file)

pass_rep = "PasswordAuthentication\s+(\w*)\s*\n"
pass_rep = r"PasswordAuthentication\s+(\w*)\s*\n"
pass_status = re.search(pass_rep, conf)
if not pass_status:
rep = "(#)?PasswordAuthentication\s+(\w*)\s*\n"
rep = r"(#)?PasswordAuthentication\s+(\w*)\s*\n"
conf = re.sub(rep, "PasswordAuthentication yes\n", conf)

if status == '1':
rep = "PasswordAuthentication\s+(\w*)\s*\n"
rep = r"PasswordAuthentication\s+(\w*)\s*\n"
conf = re.sub(rep, "PasswordAuthentication yes\n", conf)
else:
rep = "PasswordAuthentication\s+(\w*)\s*\n"
rep = r"PasswordAuthentication\s+(\w*)\s*\n"
conf = re.sub(rep, "PasswordAuthentication no\n", conf)
mw.writeFile(file, conf)
mw.execShell("systemctl restart sshd.service")
Expand All @@ -355,7 +355,7 @@ def setPingApi(self):
filename = '/etc/sysctl.conf'
conf = mw.readFile(filename)
if conf.find('net.ipv4.icmp_echo') != -1:
rep = u"net\.ipv4\.icmp_echo.*"
rep = r"net\.ipv4\.icmp_echo.*"
conf = re.sub(rep, 'net.ipv4.icmp_echo_ignore_all=' + status, conf)
else:
conf += "\nnet.ipv4.icmp_echo_ignore_all=" + status
Expand Down

0 comments on commit d3ce4a1

Please sign in to comment.