diff --git a/class/core/firewall_api.py b/class/core/firewall_api.py index 0bc27101c..6b8ba2702 100755 --- a/class/core/firewall_api.py +++ b/class/core/firewall_api.py @@ -48,6 +48,25 @@ class firewall_api: else: data['firewall_status'] = True return public.getJson(data) + + def setPingApi(self): + + if public.isAppleSystem(): + return public.returnJson(True, '开发机不能设置!') + + status = request.form.get('status', '1').strip() + filename = '/etc/sysctl.conf' + conf = public.readFile(filename) + if conf.find('net.ipv4.icmp_echo') != -1: + rep = u"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 + + public.writeFile(filename, conf) + public.execShell('sysctl -p') + return public.returnJson(True, '设置成功!') + ##### ----- start ----- ### def getList(self, page, limit): diff --git a/route/static/app/firewall.js b/route/static/app/firewall.js index 151bf9dfd..ad3a29746 100755 --- a/route/static/app/firewall.js +++ b/route/static/app/firewall.js @@ -10,8 +10,6 @@ setTimeout(function(){ getLogs(1); },1500); - - $(function(){ // start @@ -113,39 +111,36 @@ function mstsc(port) { * @param {Int} state 0.禁ping 1.可ping */ function ping(status){ - var msg = status==0?lan.firewall.ping_msg:lan.firewall.ping_un_msg; + var msg = status == 0 ? '禁PING后不影响服务器正常使用,但无法ping通服务器,您真的要禁PING吗?' : '解除禁PING状态可能会被黑客发现您的服务器,您真的要解禁吗?'; layer.confirm(msg,{title:lan.firewall.ping_title,closeBtn:2,cancel:function(){ if(status == 1){ $("#noping").prop("checked",true); - } - else{ + } else { $("#noping").prop("checked",false); - } - }},function(){ - layer.msg(lan.public.the,{icon:16,time:20000}); - $.post('/firewall?action=SetPing','status='+status, function(ret) { + } + }},function(){ + layer.msg('正在处理,请稍候...',{icon:16,time:20000}); + $.post('/firewall/set_ping','status='+status, function(ret) { + console.log(ret); layer.closeAll(); if (ret.status == true) { if(status == 0){ - layer.msg(lan.firewall.ping, {icon: 1}); - } - else{ - layer.msg(lan.firewall.ping_un, {icon: 1}); + layer.msg('已禁Ping', {icon: 1}); + } else { + layer.msg('已解除禁Ping', {icon: 1}); } setTimeout(function(){window.location.reload();},3000); - - } else { - layer.msg(lan.firewall.ping_err, {icon: 2}); + layer.msg('连接服务器失败', {icon: 2}); } - }) + },'json'); },function(){ if(status == 1){ $("#noping").prop("checked",true); } else { $("#noping").prop("checked",false); } - }) + }); }