From b3ba764d8918f4fe701a97948453418ae91d6007 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:25:41 +0800 Subject: [PATCH 01/19] update --- web/admin/firewall/__init__.py | 8 +++++++ web/static/app/firewall.js | 41 ++++++++++++++++++++++++++++++++++ web/utils/firewall.py | 38 +++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/web/admin/firewall/__init__.py b/web/admin/firewall/__init__.py index d2eace702..c3f655d1e 100644 --- a/web/admin/firewall/__init__.py +++ b/web/admin/firewall/__init__.py @@ -93,6 +93,14 @@ def set_fw(): status = request.form.get('status', '1') return MwFirewall.instance().setFw(status) +@blueprint.route('/set_ssh_root_status', endpoint='set_ssh_root_status', methods=['POST']) +@panel_login_required +def set_ssh_root_status(): + if mw.isAppleSystem(): + return mw.returnData(True, '开发机不能设置!') + status = request.form.get('status', '1') + return MwFirewall.instance().setSshRootStatus(status) + @blueprint.route('/set_ssh_pass_status', endpoint='set_ssh_pass_status', methods=['POST']) @panel_login_required def set_ssh_pass_status(): diff --git a/web/static/app/firewall.js b/web/static/app/firewall.js index cb5ad5fa6..70c518cde 100755 --- a/web/static/app/firewall.js +++ b/web/static/app/firewall.js @@ -53,6 +53,7 @@ function sshMgr(){ var ssh_status = rdata.status ? 'checked':''; var pass_prohibit_status = rdata.pass_prohibit_status ? 'checked':''; var pubkey_prohibit_status = rdata.pubkey_prohibit_status ? 'checked':''; + var root_prohibit_status = rdata.root_prohibit_status ? 'checked':''; var con = '
\
\ \ @@ -67,6 +68,15 @@ function sshMgr(){ \ \ \ + \ + \ + \ + \ \ \ \ \ \ - \ + \ \ \ From db39483f97a43c87817d69dcac2235353b26ea6f Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:36:05 +0800 Subject: [PATCH 06/19] Update firewall.py --- web/utils/firewall.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 2e7fcf78a..a70581963 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -474,7 +474,7 @@ class Firewall(object): rep = r"PermitRootLogin\s+(\w*)\s*\n" conf = re.sub(rep, "PermitRootLogin no\n", conf) mw.writeFile(file, conf) - mw.execShell("systemctl restart sshd.service") + mw.execShell("systemctl restart sshd") mw.writeLog("SSH管理", msg) return mw.returnData(True, msg) @@ -502,7 +502,7 @@ class Firewall(object): 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") + mw.execShell("systemctl restart sshd") mw.writeLog("SSH管理", msg) return mw.returnData(True, msg) @@ -530,7 +530,7 @@ class Firewall(object): rep = r"PubkeyAuthentication\s+(\w*)\s*\n" content = re.sub(rep, "PubkeyAuthentication no\n", content) mw.writeFile(file, content) - mw.execShell("systemctl restart sshd.service") + mw.execShell("systemctl restart sshd") mw.writeLog("SSH管理", msg) return mw.returnData(True, msg) From ea340f3fc2b9f58741605a44045a8b541e96d06d Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:36:52 +0800 Subject: [PATCH 07/19] Update firewall.py --- web/utils/firewall.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index a70581963..27d9e83e6 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -461,9 +461,9 @@ class Firewall(object): conf = mw.readFile(file) - pass_rep = r"PermitRootLogin\s+(\w*)\s*\n" - pass_status = re.search(pass_rep, conf) - if not pass_status: + root_rep = r"PermitRootLogin\s+(\w*)\s*\n" + root_status = re.search(root_rep, conf) + if not root_status: rep = r"(#)?PermitRootLogin\s+(\w*)\s*\n" conf = re.sub(rep, "PermitRootLogin yes\n", conf) From a0b468136925a5edcfea79b8246ca4513e335c3f Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:38:04 +0800 Subject: [PATCH 08/19] Update firewall.py --- web/utils/firewall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 27d9e83e6..3c897e242 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -467,7 +467,7 @@ class Firewall(object): rep = r"(#)?PermitRootLogin\s+(\w*)\s*\n" conf = re.sub(rep, "PermitRootLogin yes\n", conf) - if status == '1': + if status == '0': rep = r"PermitRootLogin\s+(\w*)\s*\n" conf = re.sub(rep, "PermitRootLogin yes\n", conf) else: From a00343d44440978700fa3c733c96c2e2055d66aa Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:38:57 +0800 Subject: [PATCH 09/19] Update firewall.py --- web/utils/firewall.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 3c897e242..0464bebfa 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -196,7 +196,7 @@ class Firewall(object): if ssh_status[0] != '': status = False - cmd = "systemctl status sshd.service | grep 'dead'|grep -v grep" + cmd = "systemctl status sshd | grep 'dead'|grep -v grep" ssh_status = mw.execShell(cmd) if ssh_status[0] != '': status = False @@ -467,7 +467,7 @@ class Firewall(object): rep = r"(#)?PermitRootLogin\s+(\w*)\s*\n" conf = re.sub(rep, "PermitRootLogin yes\n", conf) - if status == '0': + if status == '1': rep = r"PermitRootLogin\s+(\w*)\s*\n" conf = re.sub(rep, "PermitRootLogin yes\n", conf) else: From 6073357bb6efda18173ab440f48445fd3b03e443 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:44:15 +0800 Subject: [PATCH 10/19] Update firewall.js --- web/static/app/firewall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/static/app/firewall.js b/web/static/app/firewall.js index 4e4630a8f..415b89005 100755 --- a/web/static/app/firewall.js +++ b/web/static/app/firewall.js @@ -72,7 +72,7 @@ function sshMgr(){ \ \ From 5039dac0452357d62287c049bd7883da7f7ebd31 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:45:43 +0800 Subject: [PATCH 11/19] Update firewall.py --- web/utils/firewall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 0464bebfa..a6bd7fd51 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -233,7 +233,7 @@ class Firewall(object): root_rep = r"PermitRootLogin\s+(\w*)\s*\n" root_status = re.search(pass_rep, conf) if root_status: - if root_status and root_status.groups(0)[0].strip() == 'no': + if root_status and root_status.groups(0)[0].strip() == 'yes': data['root_prohibit_status'] = True else: data['root_prohibit_status'] = True From d57465d067326deb575e71806aa83df5ab81689a Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:50:33 +0800 Subject: [PATCH 12/19] Update firewall.py --- web/utils/firewall.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index a6bd7fd51..8513350a9 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -465,14 +465,14 @@ class Firewall(object): root_status = re.search(root_rep, conf) if not root_status: rep = r"(#)?PermitRootLogin\s+(\w*)\s*\n" - conf = re.sub(rep, "PermitRootLogin yes\n", conf) + conf = re.sub(rep, "PermitRootLogin no\n", conf) if status == '1': rep = r"PermitRootLogin\s+(\w*)\s*\n" - conf = re.sub(rep, "PermitRootLogin yes\n", conf) + conf = re.sub(rep, "PermitRootLogin no\n", conf) else: rep = r"PermitRootLogin\s+(\w*)\s*\n" - conf = re.sub(rep, "PermitRootLogin no\n", conf) + conf = re.sub(rep, "PermitRootLogin yes\n", conf) mw.writeFile(file, conf) mw.execShell("systemctl restart sshd") mw.writeLog("SSH管理", msg) From 0d9381b528656b4af47cf36828f9b6b71bcf0db4 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:52:12 +0800 Subject: [PATCH 13/19] Update firewall.py --- web/utils/firewall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 8513350a9..101c7091e 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -233,7 +233,7 @@ class Firewall(object): root_rep = r"PermitRootLogin\s+(\w*)\s*\n" root_status = re.search(pass_rep, conf) if root_status: - if root_status and root_status.groups(0)[0].strip() == 'yes': + if root_status and root_status.groups(0)[0].strip() == 'no': data['root_prohibit_status'] = True else: data['root_prohibit_status'] = True From 64484ef18b9b5b74cf73788b1663ef301ab0a1bf Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:53:39 +0800 Subject: [PATCH 14/19] Update firewall.py --- web/utils/firewall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 101c7091e..8513350a9 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -233,7 +233,7 @@ class Firewall(object): root_rep = r"PermitRootLogin\s+(\w*)\s*\n" root_status = re.search(pass_rep, conf) if root_status: - if root_status and root_status.groups(0)[0].strip() == 'no': + if root_status and root_status.groups(0)[0].strip() == 'yes': data['root_prohibit_status'] = True else: data['root_prohibit_status'] = True From f35a23a53de2332b1ac7e38ce2e23f29431dc1a0 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:56:10 +0800 Subject: [PATCH 15/19] Update firewall.py --- web/utils/firewall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 8513350a9..101c7091e 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -233,7 +233,7 @@ class Firewall(object): root_rep = r"PermitRootLogin\s+(\w*)\s*\n" root_status = re.search(pass_rep, conf) if root_status: - if root_status and root_status.groups(0)[0].strip() == 'yes': + if root_status and root_status.groups(0)[0].strip() == 'no': data['root_prohibit_status'] = True else: data['root_prohibit_status'] = True From 8877d7ea5573598447a29e520511650e95db02ed Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:58:08 +0800 Subject: [PATCH 16/19] Update firewall.py --- web/utils/firewall.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 101c7091e..0464bebfa 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -465,14 +465,14 @@ class Firewall(object): root_status = re.search(root_rep, conf) if not root_status: rep = r"(#)?PermitRootLogin\s+(\w*)\s*\n" - conf = re.sub(rep, "PermitRootLogin no\n", conf) + conf = re.sub(rep, "PermitRootLogin yes\n", conf) if status == '1': rep = r"PermitRootLogin\s+(\w*)\s*\n" - conf = re.sub(rep, "PermitRootLogin no\n", conf) + conf = re.sub(rep, "PermitRootLogin yes\n", conf) else: rep = r"PermitRootLogin\s+(\w*)\s*\n" - conf = re.sub(rep, "PermitRootLogin yes\n", conf) + conf = re.sub(rep, "PermitRootLogin no\n", conf) mw.writeFile(file, conf) mw.execShell("systemctl restart sshd") mw.writeLog("SSH管理", msg) From 9dae7988fd06b51b0787759130857ef99663a6d2 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 22:00:51 +0800 Subject: [PATCH 17/19] Update firewall.py --- web/utils/firewall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 0464bebfa..8eed358fb 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -230,7 +230,7 @@ class Firewall(object): data['pubkey_prohibit_status'] = True # root登陆配置检查 - root_rep = r"PermitRootLogin\s+(\w*)\s*\n" + root_rep = r"^PermitRootLogin\s+(\w*)\s*\n" root_status = re.search(pass_rep, conf) if root_status: if root_status and root_status.groups(0)[0].strip() == 'no': From 007b1bd21b74c11effbfa9c49c2b8b9e2afae200 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 22:02:50 +0800 Subject: [PATCH 18/19] Update firewall.py --- web/utils/firewall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index 8eed358fb..e50a6d8a6 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -231,7 +231,7 @@ class Firewall(object): # root登陆配置检查 root_rep = r"^PermitRootLogin\s+(\w*)\s*\n" - root_status = re.search(pass_rep, conf) + root_status = re.search(root_rep, conf) if root_status: if root_status and root_status.groups(0)[0].strip() == 'no': data['root_prohibit_status'] = True From 9bcb41ab5db0803e4ca168dbee5d16ecc6fd021c Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 22:02:57 +0800 Subject: [PATCH 19/19] Update firewall.py --- web/utils/firewall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/firewall.py b/web/utils/firewall.py index e50a6d8a6..170e44094 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -230,7 +230,7 @@ class Firewall(object): data['pubkey_prohibit_status'] = True # root登陆配置检查 - root_rep = r"^PermitRootLogin\s+(\w*)\s*\n" + root_rep = r"PermitRootLogin\s+(\w*)\s*\n" root_status = re.search(root_rep, conf) if root_status: if root_status and root_status.groups(0)[0].strip() == 'no':
禁止Root登陆\ +
\ + \ + \ +
\ +
禁止密码登陆\ @@ -252,6 +262,35 @@ function setMstscStatus(){ }); } +/** + * 设置远程服务状态 + * @param {Int} state 0.启用 1.关闭 + */ +function setSshRootStatus(){ + status = $("#root_status").prop("checked")==true?1:0; + var msg = status==1?'开启密码登陆,继续吗?':'确定禁止密码登陆吗?'; + layer.confirm(msg,{title:'警告',closeBtn:2,cancel:function(){ + if(status == 0){ + $("#root_status").prop("checked",false); + } else { + $("#root_status").prop("checked",true); + } + }},function(index){ + if(index > 0){ + layer.msg('正在处理,请稍候...',{icon:16,time:20000}); + $.post('/firewall/set_ssh_root_status','status='+status,function(rdata){ + layer.msg(rdata.msg,{icon:rdata.status?1:2}); + },'json'); + } + },function(){ + if(status == 0){ + $("#root_status").prop("checked",false); + } else { + $("#root_status").prop("checked",true); + } + }); +} + /** * 设置远程服务状态 * @param {Int} state 0.启用 1.关闭 @@ -281,6 +320,8 @@ function setSshPassStatus(){ }); } + + /** * 设置远程服务状态 * @param {Int} state 0.启用 1.关闭 diff --git a/web/utils/firewall.py b/web/utils/firewall.py index e1d68617e..2e7fcf78a 100644 --- a/web/utils/firewall.py +++ b/web/utils/firewall.py @@ -203,6 +203,7 @@ class Firewall(object): data['pubkey_prohibit_status'] = False data['pass_prohibit_status'] = False + data['root_prohibit_status'] = False port = '22' sshd_file = '/etc/ssh/sshd_config' if os.path.exists(sshd_file): @@ -228,6 +229,15 @@ class Firewall(object): else: data['pubkey_prohibit_status'] = True + # root登陆配置检查 + root_rep = r"PermitRootLogin\s+(\w*)\s*\n" + root_status = re.search(pass_rep, conf) + if root_status: + if root_status and root_status.groups(0)[0].strip() == 'no': + data['root_prohibit_status'] = True + else: + data['root_prohibit_status'] = True + data['port'] = port data['status'] = status data['ping'] = isPing @@ -440,6 +450,34 @@ class Firewall(object): self.reload() return True + def setSshRootStatus(self, status): + msg = '禁止root登陆成功' + if status == "1": + msg = '开启root登陆成功' + + file = '/etc/ssh/sshd_config' + if not os.path.exists(file): + return mw.returnJson(False, '无法设置!') + + conf = mw.readFile(file) + + pass_rep = r"PermitRootLogin\s+(\w*)\s*\n" + pass_status = re.search(pass_rep, conf) + if not pass_status: + rep = r"(#)?PermitRootLogin\s+(\w*)\s*\n" + conf = re.sub(rep, "PermitRootLogin yes\n", conf) + + if status == '1': + rep = r"PermitRootLogin\s+(\w*)\s*\n" + conf = re.sub(rep, "PermitRootLogin yes\n", conf) + else: + rep = r"PermitRootLogin\s+(\w*)\s*\n" + conf = re.sub(rep, "PermitRootLogin no\n", conf) + mw.writeFile(file, conf) + mw.execShell("systemctl restart sshd.service") + mw.writeLog("SSH管理", msg) + return mw.returnData(True, msg) + def setSshPassStatus(self, status): msg = '禁止密码登陆成功' if status == "1": From 133d560e64d73f83e609f9756de78e69f0e5beac Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:29:03 +0800 Subject: [PATCH 02/19] update --- web/static/app/firewall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/static/app/firewall.js b/web/static/app/firewall.js index 70c518cde..ac658cf60 100755 --- a/web/static/app/firewall.js +++ b/web/static/app/firewall.js @@ -69,7 +69,7 @@ function sshMgr(){
禁止Root登陆禁止root登陆\
\ \ From f990d7584ed36e9f9f294d7d8b2a37a7423a78e6 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:29:39 +0800 Subject: [PATCH 03/19] Update firewall.js --- web/static/app/firewall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/static/app/firewall.js b/web/static/app/firewall.js index ac658cf60..32c222462 100755 --- a/web/static/app/firewall.js +++ b/web/static/app/firewall.js @@ -102,7 +102,7 @@ function sshMgr(){ layer.open({ type: 1, title: "SSH管理", - area: ['300px', '260px'], + area: ['300px', '300px'], closeBtn: 1, shadeClose: false, content: '
'+con+'
', From 9dc3030c18a4401b97699ac5ffa12e9409ba243e Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:30:21 +0800 Subject: [PATCH 04/19] Update firewall.js --- web/static/app/firewall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/static/app/firewall.js b/web/static/app/firewall.js index 32c222462..5e9f7f740 100755 --- a/web/static/app/firewall.js +++ b/web/static/app/firewall.js @@ -102,7 +102,7 @@ function sshMgr(){ layer.open({ type: 1, title: "SSH管理", - area: ['300px', '300px'], + area: ['300px', '310px'], closeBtn: 1, shadeClose: false, content: '
'+con+'
', From e575511849b9d23b8eb0dbb6fab7616ae4cf8782 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 10 Sep 2025 21:33:36 +0800 Subject: [PATCH 05/19] Update firewall.js --- web/static/app/firewall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/static/app/firewall.js b/web/static/app/firewall.js index 5e9f7f740..4e4630a8f 100755 --- a/web/static/app/firewall.js +++ b/web/static/app/firewall.js @@ -73,7 +73,7 @@ function sshMgr(){
\
\ \ - \ + \
\
禁止root登陆\
\ - \ + \ \
\