Skip to content

Commit

Permalink
Update firewall.py
Browse files Browse the repository at this point in the history
  • Loading branch information
midoks committed Dec 24, 2024
1 parent 26147ac commit 0a1251a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions web/utils/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ def reload(self):
else:
pass

def reloadSshd(self):
if self.__isUfw:
mw.execShell("service ssh restart")
elif self.__isIptables:
mw.execShell("/etc/init.d/sshd restart")
elif self.__isFirewalld:
mw.execShell("systemctl restart sshd.service")
else:
return False
return True

def getFwStatus(self):
if self.__isUfw:
cmd = "/usr/sbin/ufw status| grep Status | awk -F ':' '{print $2}'"
Expand Down Expand Up @@ -251,6 +262,9 @@ def setSshPort(self, port):
conf = re.sub(rep, "Port " + port + "\n", conf)
mw.writeFile(file, conf)

if not self.reloadSshd():
return mw.returnData(False, '重启sshd失败,尝试手动重启:service ssh restart!')

self.addAcceptPort(port, 'SSH端口修改', 'port')
self.reload()
return mw.returnData(True, '修改成功!')
Expand Down

0 comments on commit 0a1251a

Please sign in to comment.