pull/109/head
Mr Chen 6 years ago
parent 88dd055460
commit 512977da87
  1. 78
      class/core/firewall_api.py
  2. 2
      route/static/app/firewall.js

@ -26,18 +26,6 @@ class firewall_api:
if public.isAppleSystem(): if public.isAppleSystem():
self.__isMac = True 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 ----- ### ##### ----- start ----- ###
# 添加屏蔽IP # 添加屏蔽IP
def addDropAddressApi(self): def addDropAddressApi(self):
@ -197,7 +185,7 @@ class firewall_api:
if public.isAppleSystem(): if public.isAppleSystem():
data['firewall_status'] = False data['firewall_status'] = False
else: else:
data['firewall_status'] = True data['firewall_status'] = self.getFwStatus()
return public.getJson(data) return public.getJson(data)
def setPingApi(self): def setPingApi(self):
@ -218,6 +206,36 @@ class firewall_api:
public.execShell('sysctl -p') public.execShell('sysctl -p')
return public.returnJson(True, '设置成功!') 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): def delPanelLogsApi(self):
public.M('logs').where('id>?', (0,)).delete() public.M('logs').where('id>?', (0,)).delete()
public.writeLog('面板设置', '面板操作日志已清空!') public.writeLog('面板设置', '面板操作日志已清空!')
@ -264,3 +282,37 @@ class firewall_api:
data['page'] = public.getPage(_page) data['page'] = public.getPage(_page)
return public.getJson(data) 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

@ -151,7 +151,7 @@ function ping(status){
*/ */
function firewall(status){ function firewall(status){
var msg = status == 1 ? '禁用防火墙会增加服务器不安全性,您真的要禁用防火墙吗?' : '开启防火墙,增加服务器安全!'; var msg = status == 1 ? '禁用防火墙会增加服务器不安全性,您真的要禁用防火墙吗?' : '开启防火墙,增加服务器安全!';
layer.confirm(msg,{title:'是否禁ping',closeBtn:2,cancel:function(){ layer.confirm(msg,{title:'是否开启防火墙!',closeBtn:2,cancel:function(){
if(status == 1){ if(status == 1){
$("#noping").prop("checked",true); $("#noping").prop("checked",true);
} else { } else {

Loading…
Cancel
Save