|
|
|
@ -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": |
|
|
|
|