From dd6d9cf09ae1939a6e39918d2fa4f40eefcb072e Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 25 Sep 2023 04:07:47 +0800 Subject: [PATCH] Update firewall_api.py --- class/core/firewall_api.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/class/core/firewall_api.py b/class/core/firewall_api.py index 7ea605485..278e6739c 100755 --- a/class/core/firewall_api.py +++ b/class/core/firewall_api.py @@ -296,11 +296,17 @@ class firewall_api: conf = mw.readFile(file) - if status == '1': + pass_rep = "PasswordAuthentication\s+(\w*)\s*\n" + pass_status = re.search(pass_rep, conf) + if not pass_status: rep = "(#)?PasswordAuthentication\s+(\w*)\s*\n" conf = re.sub(rep, "PasswordAuthentication yes\n", conf) + + if status == '1': + rep = "PasswordAuthentication\s+(\w*)\s*\n" + conf = re.sub(rep, "PasswordAuthentication yes\n", conf) else: - rep = "(#)?PasswordAuthentication\s+(\w*)\s*\n" + rep = "PasswordAuthentication\s+(\w*)\s*\n" conf = re.sub(rep, "PasswordAuthentication no\n", conf) mw.writeFile(file, conf) mw.execShell("systemctl restart sshd.service")