diff --git a/.gitignore b/.gitignore index 1c375c27e..3d7418400 100644 --- a/.gitignore +++ b/.gitignore @@ -115,3 +115,4 @@ data/*.db data/control.conf data/iplist.txt data/json/index.json +data/json/config.json diff --git a/class/core/config_api.py b/class/core/config_api.py index fdd0a7aef..e24e422f3 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -53,26 +53,50 @@ class config_api: session['username'] = name1 return public.returnJson(True, '用户修改成功!') + def setApi(self): + webname = request.form.get('webname', '') + port = request.form.get('port', '') + host_ip = request.form.get('host_ip', '') + domain = request.form.get('domain', '') + if domain != '': + reg = "^([\w\-\*]{1,100}\.){1,4}(\w{1,10}|\w{1,10}\.\w{1,10})$" + if not re.match(reg, domain): + return public.returnJson(False, '主域名格式不正确') + + if int(port) >= 65535 or int(port) < 100: + return public.returnJson(False, '端口范围不正确!') + + if webname != public.getConfig('title'): + public.setConfig('title', webname) + + if port != public.getHostPort(): + import system_api + public.setHostPort(port) + system_api.system_api().restartMw() + + if host_ip != public.getHostAddr(): + public.setHostAddr(host_ip) + + mhost = public.getHostAddr() + info = { + 'uri': '/config', + 'host': mhost + ':' + port + } + return public.returnJson(True, '保存成功!', info) + ##### ----- end ----- ### def get(self): data = {} - + data['title'] = public.getConfig('title') data['site_path'] = public.getWwwDir() data['backup_path'] = public.getBackupDir() sformat = 'date +"%Y-%m-%d %H:%M:%S %Z %z"' data['systemdate'] = public.execShell(sformat)[0].strip() - if os.path.exists('data/port.pl'): - data['port'] = public.readFile('data/port.pl').strip() - else: - data['port'] = '7200' - - if os.path.exists('data/iplist.txt'): - data['ip'] = public.readFile('data/iplist.txt').strip() - else: - data['ip'] = '127.0.0.1' + data['port'] = public.getHostPort() + data['ip'] = public.getHostAddr() data['username'] = public.M('users').where( "id=?", (1,)).getField('username') diff --git a/class/core/public.py b/class/core/public.py index eedb29ec3..27f2d7ac4 100755 --- a/class/core/public.py +++ b/class/core/public.py @@ -186,6 +186,8 @@ def retFail(msg, data=None): def returnJson(status, msg, data=None): + if data == None: + return getJson({'status': status, 'msg': msg}) return getJson({'status': status, 'msg': msg, 'data': data}) @@ -561,6 +563,54 @@ def getTimeout(url): return int((time.time() - start) * 1000) +def makeConf(): + file = getRunDir() + '/data/json/config.json' + if not os.path.exists(file): + c = {} + c['title'] = 'Linux面板' + c['home'] = 'http://github/midoks/mdserver-web' + c['recycle_bin'] = True + c['template'] = 'default' + writeFile(file, json.dumps(c)) + return c + c = readFile(file) + return json.loads(c) + + +def getConfig(k): + c = makeConf() + return c[k] + + +def setConfig(k, v): + c = makeConf() + c[k] = v + file = getRunDir() + '/data/json/config.json' + return writeFile(file, json.dumps(c)) + + +def getHostAddr(): + if os.path.exists('data/iplist.txt'): + return readFile('data/iplist.txt').strip() + return '127.0.0.1' + + +def setHostAddr(addr): + file = getRunDir() + '/data/iplist.txt' + return writeFile(file, addr) + + +def getHostPort(): + if os.path.exists('data/port.pl'): + return readFile('data/port.pl').strip() + return '7200' + + +def setHostPort(port): + file = getRunDir() + '/data/port.pl' + return writeFile(file, port) + + def auth_decode(data): # 解密数据 token = GetToken() @@ -676,9 +726,7 @@ def checkCert(certPath='ssl/certificate.pem'): return False return True - # 获取面板地址 - - +# 获取面板地址 # def getPanelAddr(): # import web # protocol = 'https://' if os.path.exists("data/ssl.pl") else 'http://' diff --git a/class/core/system_api.py b/class/core/system_api.py index 9c29fdc80..93c07d2ac 100755 --- a/class/core/system_api.py +++ b/class/core/system_api.py @@ -90,9 +90,8 @@ class system_api: @async def restartMw(self): sleep(1) - print '123123' cmd = public.getRunDir() + '/scripts/init.d/mw reload' - print public.execShell(cmd) + public.execShell(cmd) # 名取PID def getPid(self, pname): diff --git a/route/static/app/config.js b/route/static/app/config.js index 733b74a8d..c205e3812 100755 --- a/route/static/app/config.js +++ b/route/static/app/config.js @@ -1,18 +1,16 @@ - $(".set-submit").click(function(){ var data = $("#set_config").serialize(); - console.log(data); layer.msg('正在保存配置...',{icon:16,time:0,shade: [0.3, '#000']}); - $.post('/config?action=setPanel',data,function(rdata){ + $.post('/config/set',data,function(rdata){ layer.closeAll(); layer.msg(rdata.msg,{icon:rdata.status?1:2}); if(rdata.status){ setTimeout(function(){ - window.location.href = ((window.location.protocol.indexOf('https') != -1)?'https://':'http://') + rdata.host + window.location.pathname; - },1500); + window.location.href = ((window.location.protocol.indexOf('https') != -1)?'https://':'http://') + rdata.data.host + window.location.pathname; + },2500); } - }); + },'json'); }); diff --git a/route/templates/default/config.html b/route/templates/default/config.html index 247f066b7..0dd4712cf 100755 --- a/route/templates/default/config.html +++ b/route/templates/default/config.html @@ -40,7 +40,7 @@

别名 - MDWEB面板 + 面板名称

面板端口 @@ -57,11 +57,6 @@ 为面板绑定一个访问域名;注意:一旦绑定域名,只能通过域名访问面板!

-

- 授权IP - - 设置访问授权IP,多个请使用逗号(,)隔开;注意:一旦设置授权IP,只有指定IP的电脑能访问面板! -

默认建站目录 @@ -77,7 +72,7 @@

服务器IP - + 默认为外网IP,若您在本地虚拟机测试,请填写虚拟机内网IP!