From 3722f57347965f70a78aa23e0e98b52d811d6c4d Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 19 Sep 2022 16:16:25 +0800 Subject: [PATCH] up --- plugins/mail/index.py | 25 +++++++++++++++-- plugins/mail/js/mail.js | 62 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/plugins/mail/index.py b/plugins/mail/index.py index d8a4a6a65..be1122a12 100755 --- a/plugins/mail/index.py +++ b/plugins/mail/index.py @@ -4,6 +4,8 @@ import sys import io import os import time +import re +import socket from datetime import datetime @@ -460,9 +462,28 @@ class App: data = mi.mail_init().check_env() return mw.returnJson(True, 'ok', data) + def change_hostname(self): + ''' + mac + sudo scutil --set HostName mac_hostname.vm + ''' + args = self.getArgs() + hostname = args['hostname'] + rep_domain = "^(?=^.{3,255}$)[a-zA-Z0-9\_\-][a-zA-Z0-9\_\-]{0,62}(\.[a-zA-Z0-9\_\-][a-zA-Z0-9\_\-]{0,62})+$" + if not re.search(rep_domain, hostname): + return mw.returnJson(False, "请输入完整域名,例如 mail.bt.com),") + mw.execShell('hostnamectl set-hostname --static {}'.format(hostname)) + h = socket.gethostname() + if h == hostname: + return mw.returnJson(True, "设置成功!") + return mw.returnJson(False, "设置失败!") + if __name__ == "__main__": func = sys.argv[1] classApp = App() - data = eval("classApp." + func + "()") - print(data) + try: + data = eval("classApp." + func + "()") + print(data) + except Exception as e: + print('error:' + str(e)) diff --git a/plugins/mail/js/mail.js b/plugins/mail/js/mail.js index bb71e599d..b83c597ac 100755 --- a/plugins/mail/js/mail.js +++ b/plugins/mail/js/mail.js @@ -462,9 +462,14 @@ var mail = { case 'Dovecot-install': _key = 'repair_dovecot'; break; + case 'HostName': + _key = 'repair_host_name'; + break; + } + if (key == 'HostName'){ + this.repair_host_name(); + return; } - - console.log(key,_key); this.send({ tips: '正在修复' + key + ',请稍候...', @@ -475,7 +480,60 @@ var mail = { } }) }, + + // 修复hostname + repair_host_name: function () { + var _this = this; + layer.open({ + type: 1, + shift: 5, + closeBtn: 1, + shadeClose: false, + title: '修复【主机名】', + btn: ['确定', '取消'], + area: "400px", + content: '\ +
\ +
\ + 域名\ +
\ + \ +
\ +
\ + \ +
', + success: function ($layer, index) { + }, + yes: function(index){ + var hostname = $('input[name="hostname"]').val().trim(); + if (hostname === '') { + layer.msg('请输入你的完整域名', { icon: 2, closeBtn: true }); + return + } + _this.change_hostname({ + hostname: hostname, + }, function (res) { + layer.close(index); + _this.create_post_env_table(); + layer.msg(res.msg, { icon: res.status ? 1 : 5 }); + }); + } + }); + }, + // 一键修复主机名 + change_hostname: function(data, callback){ + this.send({ + tips: '正在获取修复主机名, 请稍候...', + method: 'change_hostname', + data: data, + success: function (res) { + if (callback) callback(res); + } + }); + }, str2Obj:function(str){ var data = {};