mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 01:39:25 +08:00
优化
This commit is contained in:
@@ -115,3 +115,4 @@ data/*.db
|
||||
data/control.conf
|
||||
data/iplist.txt
|
||||
data/json/index.json
|
||||
data/json/config.json
|
||||
|
||||
+34
-10
@@ -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')
|
||||
|
||||
+51
-3
@@ -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://'
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
<form id="set_config">
|
||||
<p class="mtb15">
|
||||
<span class="set-tit text-right">别名</span>
|
||||
<input id="webname" name="webname" class="inputtxt bt-input-text" type="text" value="MDWEB面板" ><span class="set-info c7">MDWEB面板</span>
|
||||
<input id="webname" name="webname" class="inputtxt bt-input-text" type="text" value="{{data['title']}}" ><span class="set-info c7">面板名称</span>
|
||||
</p>
|
||||
<p class="mtb15">
|
||||
<span class="set-tit text-right">面板端口</span>
|
||||
@@ -57,11 +57,6 @@
|
||||
<input name="domain" class="inputtxt bt-input-text" type="text" value="">
|
||||
<span class="set-info c7">为面板绑定一个访问域名;注意:一旦绑定域名,只能通过域名访问面板!</span>
|
||||
</p>
|
||||
<p class="mtb15">
|
||||
<span class="set-tit text-right" title="授权IP">授权IP</span>
|
||||
<input name="limitip" class="inputtxt bt-input-text" type="text" value="">
|
||||
<span class="set-info c7">设置访问授权IP,多个请使用逗号(,)隔开;注意:一旦设置授权IP,只有指定IP的电脑能访问面板!</span>
|
||||
</p>
|
||||
|
||||
<p class="mtb15">
|
||||
<span class="set-tit text-right" title="默认建站目录">默认建站目录</span>
|
||||
@@ -77,7 +72,7 @@
|
||||
|
||||
<p class="mtb15">
|
||||
<span class="set-tit text-right" title="服务器IP">服务器IP</span>
|
||||
<input name="backup_path" class="inputtxt bt-input-text" type="text" value="{{data['ip']}}">
|
||||
<input name="host_ip" class="inputtxt bt-input-text" type="text" value="{{data['ip']}}">
|
||||
<span class="set-info c7">默认为外网IP,若您在本地虚拟机测试,请填写虚拟机内网IP!</span>
|
||||
</p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user