mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
update
This commit is contained in:
@@ -571,7 +571,7 @@ def checkIp(ip):
|
||||
|
||||
def checkPort(port):
|
||||
# 检查端口是否合法
|
||||
ports = ['21', '25', '443', '8080', '888', '8888', '8443']
|
||||
ports = ['21', '25', '443', '7200', '8080', '888', '8888', '8443']
|
||||
if port in ports:
|
||||
return False
|
||||
intport = int(port)
|
||||
|
||||
+121
-6
@@ -38,6 +38,24 @@ class site_api:
|
||||
def getPhpVersionApi(self):
|
||||
return self.getPhpVersion()
|
||||
|
||||
def setPhpVersionApi(self):
|
||||
siteName = request.form.get('siteName', '').encode('utf-8')
|
||||
version = request.form.get('version', '').encode('utf-8')
|
||||
|
||||
# nginx
|
||||
file = self.setupPath + '/openresty/nginx/conf/vhost/' + siteName + '.conf'
|
||||
conf = public.readFile(file)
|
||||
if conf:
|
||||
rep = "enable-php-([0-9]{2,3})\.conf"
|
||||
tmp = re.search(rep, conf).group()
|
||||
conf = conf.replace(tmp, 'enable-php-' + version + '.conf')
|
||||
public.writeFile(file, conf)
|
||||
|
||||
public.restartWeb()
|
||||
msg = public.getInfo('成功切换网站[{1}]的PHP版本为PHP-{2}', (siteName, version))
|
||||
public.writeLog("TYPE_SITE", msg)
|
||||
return public.returnJson(True, msg)
|
||||
|
||||
def getDomainApi(self):
|
||||
pid = request.form.get('pid', '').encode('utf-8')
|
||||
return self.getDomain(pid)
|
||||
@@ -139,17 +157,93 @@ class site_api:
|
||||
pid = request.form.get('id', '').encode('utf-8')
|
||||
if len(domain) < 3:
|
||||
return public.returnJson(False, '域名不能为空!')
|
||||
domains = get.domain.split(',')
|
||||
domains = domain.split(',')
|
||||
for domain in domains:
|
||||
if domain == "":
|
||||
continue
|
||||
domain = domain.split(':')
|
||||
domain_name = self.ToPunycode(domain[0])
|
||||
print domain
|
||||
domain_name = self.toPunycode(domain[0])
|
||||
domain_port = '80'
|
||||
|
||||
reg = "^([\w\-\*]{1,100}\.){1,4}([\w\-]{1,24}|[\w\-]{1,24}\.[\w\-]{1,24})$"
|
||||
if not re.match(reg, domain_name):
|
||||
return public.returnJson(False, '域名格式不正确!')
|
||||
|
||||
if len(domain) == 2:
|
||||
domain_port = domain[1]
|
||||
if domain_port == "":
|
||||
domain_port = "80"
|
||||
|
||||
if not public.checkPort(domain_port):
|
||||
return public.returnJson(False, '端口范围不合法!')
|
||||
|
||||
opid = public.M('domain').where(
|
||||
"name=? AND (port=? OR pid=?)", (domain, domain_port, pid)).getField('pid')
|
||||
if opid:
|
||||
if public.M('sites').where('id=?', (opid,)).count():
|
||||
return public.returnMsg(False, '指定域名已绑定过!')
|
||||
public.M('domain').where('pid=?', (opid,)).delete()
|
||||
|
||||
if public.M('binding').where('domain=?', (domain,)).count():
|
||||
return public.returnMsg(False, '您添加的域名已存在!')
|
||||
|
||||
self.nginxAddDomain(webname, domain_name, domain_port)
|
||||
|
||||
# 添加放行端口
|
||||
# if port != '80':
|
||||
# import firewalls
|
||||
# get.ps = get.domain
|
||||
# firewalls.firewalls().AddAcceptPort(get)
|
||||
|
||||
public.restartWeb()
|
||||
msg = public.getInfo('网站[{1}]添加域名[{2}]成功!', (webname, domain_name))
|
||||
public.writeLog('TYPE_SITE', msg)
|
||||
public.M('domain').add('pid,name,port,addtime',
|
||||
(pid, domain_name, domain_port, public.getDate()))
|
||||
|
||||
return public.returnJson(True, '域名添加成功!')
|
||||
|
||||
def delDomainApi(self):
|
||||
domain = request.form.get('domain', '').encode('utf-8')
|
||||
webname = request.form.get('webname', '').encode('utf-8')
|
||||
port = request.form.get('port', '').encode('utf-8')
|
||||
pid = request.form.get('id', '')
|
||||
|
||||
find = public.M('domain').where("pid=? AND name=?",
|
||||
(pid, domain)).field('id,name').find()
|
||||
|
||||
domain_count = public.M('domain').where("pid=?", (pid,)).count()
|
||||
if domain_count == 1:
|
||||
return public.returnJson(False, '最后一个域名不能删除!')
|
||||
|
||||
file = self.setupPath + '/openresty/nginx/conf/vhost/' + webname + '.conf'
|
||||
conf = public.readFile(file)
|
||||
if conf:
|
||||
# 删除域名
|
||||
rep = "server_name\s+(.+);"
|
||||
tmp = re.search(rep, conf).group()
|
||||
newServerName = tmp.replace(' ' + domain + ';', ';')
|
||||
newServerName = newServerName.replace(' ' + domain + ' ', ' ')
|
||||
conf = conf.replace(tmp, newServerName)
|
||||
|
||||
# 删除端口
|
||||
rep = "listen\s+([0-9]+);"
|
||||
tmp = re.findall(rep, conf)
|
||||
port_count = public.M('domain').where(
|
||||
'pid=? AND port=?', (pid, port)).count()
|
||||
if public.inArray(tmp, port) == True and port_count < 2:
|
||||
rep = "\n*\s+listen\s+" + port + ";"
|
||||
conf = re.sub(rep, '', conf)
|
||||
# 保存配置
|
||||
public.writeFile(file, conf)
|
||||
|
||||
public.M('domain').where("id=?", (find['id'],)).delete()
|
||||
msg = public.getInfo('网站[{1}]删除域名[{2}]成功!', (webname, domain))
|
||||
public.writeLog('TYPE_SITE', msg)
|
||||
public.restartWeb()
|
||||
return public.returnJson(True, '站点删除成功!')
|
||||
|
||||
def deleteApi(self):
|
||||
sid = request.form.get('id', '').encode('utf-8')
|
||||
webname = request.form.get('webname', '').encode('utf-8')
|
||||
@@ -227,7 +321,7 @@ class site_api:
|
||||
logPath = public.getLogsDir() + '/' + siteName + '.log'
|
||||
if not os.path.exists(logPath):
|
||||
return public.returnJson(False, '日志为空')
|
||||
return public.returnJson(True, public.getNumLines(logPath, 1000))
|
||||
return public.returnJson(True, public.getNumLines(logPath, 100))
|
||||
|
||||
def getSitePhpVersion(self, siteName):
|
||||
conf = public.readFile(self.getHostConf(siteName))
|
||||
@@ -238,7 +332,6 @@ class site_api:
|
||||
return public.getJson(data)
|
||||
|
||||
def getIndex(self, sid):
|
||||
print sid
|
||||
siteName = public.M('sites').where("id=?", (sid,)).getField('name')
|
||||
file = self.getHostConf(siteName)
|
||||
conf = public.readFile(file)
|
||||
@@ -442,8 +535,30 @@ class site_api:
|
||||
public.execShell('chown -R www:www ' + path)
|
||||
public.execShell('chmod -R 755 ' + path)
|
||||
|
||||
def addDomain(self, domain, webname, pid):
|
||||
pass
|
||||
def nginxAddDomain(self, webname, domain, port):
|
||||
file = self.setupPath + '/openresty/nginx/conf/vhost/' + webname + '.conf'
|
||||
conf = public.readFile(file)
|
||||
if not conf:
|
||||
return
|
||||
|
||||
# 添加域名
|
||||
rep = "server_name\s*(.*);"
|
||||
tmp = re.search(rep, conf).group()
|
||||
domains = tmp.split(' ')
|
||||
if not public.inArray(domains, domain):
|
||||
newServerName = tmp.replace(';', ' ' + domain + ';')
|
||||
conf = conf.replace(tmp, newServerName)
|
||||
|
||||
# 添加端口
|
||||
rep = "listen\s+([0-9]+)\s*[default_server]*\s*;"
|
||||
tmp = re.findall(rep, conf)
|
||||
if not public.inArray(tmp, port):
|
||||
listen = re.search(rep, conf).group()
|
||||
conf = conf.replace(
|
||||
listen, listen + "\n\tlisten " + port + ';')
|
||||
# 保存配置文件
|
||||
public.writeFile(file, conf)
|
||||
return True
|
||||
|
||||
def nginxAddConf(self):
|
||||
source_tpl = public.getRunDir() + '/data/tpl/nginx.conf'
|
||||
|
||||
+22
-21
@@ -706,23 +706,24 @@ function checkDomainWebsize(obj,domain){
|
||||
*/
|
||||
function domainAdd(id, webname,type) {
|
||||
var Domain = $("#newdomain").val().split("\n");
|
||||
|
||||
var domainlist="";
|
||||
|
||||
var domainlist = '';
|
||||
for(var i=0; i<Domain.length; i++){
|
||||
domainlist += Domain[i]+",";
|
||||
domainlist += Domain[i]+ ',';
|
||||
}
|
||||
|
||||
if(domainlist.length < 3){
|
||||
layer.msg(lan.site.domain_empty,{icon:5});
|
||||
return;
|
||||
}
|
||||
|
||||
domainlist = domainlist.substring(0,domainlist.length-1);
|
||||
var loadT = layer.load();
|
||||
var data = "domain=" + domainlist + "&webname=" + webname + "&id=" + id;
|
||||
$.post('/site?action=AddDomain', data, function(retuls) {
|
||||
$.post('/site/add_domain', data, function(retuls) {
|
||||
layer.close(loadT);
|
||||
domainEdit(id,webname,retuls.msg,retuls.status);
|
||||
});
|
||||
domainEdit(id, webname, retuls.msg, retuls.status);
|
||||
},'json');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -738,20 +739,20 @@ function delDomain(wid, wname, domain, port,type) {
|
||||
layer.msg(lan.site.domain_last_cannot);
|
||||
}
|
||||
layer.confirm(lan.site.domain_del_confirm,{icon:3,closeBtn:2}, function(index) {
|
||||
var url = "/site?action=DelDomain"
|
||||
var data = "id=" + wid + "&webname=" + wname + "&domain=" + domain + "&port=" + port;
|
||||
var loadT = layer.msg(lan.public.the_del,{time:0,icon:16});
|
||||
$.post(url,data, function(ret) {
|
||||
var url = "/site/del_domain"
|
||||
var data = "id=" + wid + "&webname=" + wname + "&domain=" + domain + "&port=" + port;
|
||||
var loadT = layer.msg(lan.public.the_del,{time:0,icon:16});
|
||||
$.post(url,data, function(ret) {
|
||||
layer.close(loadT);
|
||||
layer.msg(ret.msg,{icon:ret.status?1:2})
|
||||
if(type == 1){
|
||||
layer.close(loadT);
|
||||
layer.msg(ret.msg,{icon:ret.status?1:2})
|
||||
if(type == 1){
|
||||
layer.close(loadT);
|
||||
domainEdit(wid,wname)
|
||||
}else{
|
||||
layer.closeAll();
|
||||
DomainRoot(wid, wname);
|
||||
}
|
||||
});
|
||||
domainEdit(wid,wname)
|
||||
}else{
|
||||
layer.closeAll();
|
||||
DomainRoot(wid, wname);
|
||||
}
|
||||
},'json');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2056,10 +2057,10 @@ function phpVersion(siteName){
|
||||
function setPHPVersion(siteName){
|
||||
var data = 'version='+$("#phpVersion").val()+'&siteName='+siteName;
|
||||
var loadT = layer.msg('正在保存...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
$.post('/site?action=SetPHPVersion',data,function(rdata){
|
||||
$.post('/site/set_php_version',data,function(rdata){
|
||||
layer.close(loadT);
|
||||
layer.msg(rdata.msg,{icon:rdata.status?1:2});
|
||||
});
|
||||
},'json');
|
||||
}
|
||||
|
||||
//配置文件
|
||||
|
||||
Reference in New Issue
Block a user