From 512977da87828855a12dae9d055009282b76fe0c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 21 Feb 2019 13:24:12 +0800 Subject: [PATCH] u --- class/core/firewall_api.py | 78 ++++++++++++++++++++++++++++++------ route/static/app/firewall.js | 2 +- 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/class/core/firewall_api.py b/class/core/firewall_api.py index 86d625d49..5ecaa9259 100755 --- a/class/core/firewall_api.py +++ b/class/core/firewall_api.py @@ -26,18 +26,6 @@ class firewall_api: if public.isAppleSystem(): self.__isMac = True - def firewallReload(self): - if self.__isUfw: - public.execShell('/usr/sbin/ufw reload') - return - if self.__isFirewalld: - public.execShell('firewall-cmd --reload') - elif self.__isMac: - pass - else: - public.execShell('/etc/init.d/iptables save') - public.execShell('/etc/init.d/iptables restart') - ##### ----- start ----- ### # 添加屏蔽IP def addDropAddressApi(self): @@ -197,7 +185,7 @@ class firewall_api: if public.isAppleSystem(): data['firewall_status'] = False else: - data['firewall_status'] = True + data['firewall_status'] = self.getFwStatus() return public.getJson(data) def setPingApi(self): @@ -218,6 +206,36 @@ class firewall_api: public.execShell('sysctl -p') return public.returnJson(True, '设置成功!') + def setFirewailApi(self): + if public.isAppleSystem(): + return public.returnJson(True, '开发机不能设置!') + + status = request.form.get('status', '1') + if status == '1': + if self.__isUfw: + public.execShell('/usr/sbin/ufw stop') + return + if self.__isFirewalld: + public.execShell('firewall-cmd --stop') + elif self.__isMac: + pass + else: + public.execShell('/etc/init.d/iptables save') + public.execShell('/etc/init.d/iptables stop') + else: + if self.__isUfw: + public.execShell('/usr/sbin/ufw start') + return + if self.__isFirewalld: + public.execShell('firewall-cmd --reload') + elif self.__isMac: + pass + else: + public.execShell('/etc/init.d/iptables save') + public.execShell('/etc/init.d/iptables restart') + + return public.returnJson(True, '设置成功!') + def delPanelLogsApi(self): public.M('logs').where('id>?', (0,)).delete() public.writeLog('面板设置', '面板操作日志已清空!') @@ -264,3 +282,37 @@ class firewall_api: data['page'] = public.getPage(_page) return public.getJson(data) + + def firewallReload(self): + if self.__isUfw: + public.execShell('/usr/sbin/ufw reload') + return + if self.__isFirewalld: + public.execShell('firewall-cmd --reload') + elif self.__isMac: + pass + else: + public.execShell('/etc/init.d/iptables save') + public.execShell('/etc/init.d/iptables restart') + + def getFwStatus(self): + if self.__isUfw: + data = public.execShell( + "ps -ef|grep ufw |grep -v grep | grep -v python | awk '{print $2}'") + if data[0] == '': + return False + return True + if self.__isFirewalld: + data = public.execShell( + "ps -ef|grep firewalld |grep -v grep | grep -v python | awk '{print $2}'") + if data[0] == '': + return False + return True + elif self.__isMac: + return False + else: + data = public.execShell( + "ps -ef|grep iptables |grep -v grep | grep -v python | awk '{print $2}'") + if data[0] == '': + return False + return True diff --git a/route/static/app/firewall.js b/route/static/app/firewall.js index c21634afd..0dcdc1171 100755 --- a/route/static/app/firewall.js +++ b/route/static/app/firewall.js @@ -151,7 +151,7 @@ function ping(status){ */ function firewall(status){ var msg = status == 1 ? '禁用防火墙会增加服务器不安全性,您真的要禁用防火墙吗?' : '开启防火墙,增加服务器安全!'; - layer.confirm(msg,{title:'是否禁ping',closeBtn:2,cancel:function(){ + layer.confirm(msg,{title:'是否开启防火墙!',closeBtn:2,cancel:function(){ if(status == 1){ $("#noping").prop("checked",true); } else {