From e3aab8c8dacc3a2b9cb22290b078d380c7a92803 Mon Sep 17 00:00:00 2001
From: Mr Chen
Date: Wed, 13 Feb 2019 16:02:16 +0800
Subject: [PATCH] update
---
class/core/site_api.py | 149 ++++++++++++++++++++++++++++++++
route/static/app/site.js | 179 +++++++++++++++++++--------------------
2 files changed, 236 insertions(+), 92 deletions(-)
diff --git a/class/core/site_api.py b/class/core/site_api.py
index f0778a326..66e5e3811 100755
--- a/class/core/site_api.py
+++ b/class/core/site_api.py
@@ -100,6 +100,56 @@ class site_api:
data['email'] = ''
return public.returnJson(True, 'OK', data)
+ def getDirBindingApi(self):
+ mid = request.form.get('id', '').encode('utf-8')
+
+ path = public.M('sites').where('id=?', (mid,)).getField('path')
+ if not os.path.exists(path):
+ checks = ['/', '/usr', '/etc']
+ if path in checks:
+ data = {}
+ data['dirs'] = []
+ data['binding'] = []
+ return public.returnJson(True, 'OK', data)
+ os.system('mkdir -p ' + path)
+ os.system('chmod 755 ' + path)
+ os.system('chown www:www ' + path)
+ siteName = public.M('sites').where(
+ 'id=?', (get.id,)).getField('name')
+ public.writeLog(
+ '网站管理', '站点[' + siteName + '],根目录[' + path + ']不存在,已重新创建!')
+
+ dirnames = []
+ for filename in os.listdir(path):
+ try:
+ filePath = path + '/' + filename
+ if os.path.islink(filePath):
+ continue
+ if os.path.isdir(filePath):
+ dirnames.append(filename)
+ except:
+ pass
+
+ data = {}
+ data['dirs'] = dirnames
+ data['binding'] = public.M('binding').where('pid=?', (mid,)).field(
+ 'id,pid,domain,path,port,addtime').select()
+ return public.returnJson(True, 'OK', data)
+
+ def getDirUserIniApi(self):
+ mid = request.form.get('id', '').encode('utf-8')
+
+ path = public.M('sites').where('id=?', (mid,)).getField('path')
+ name = public.M('sites').where("id=?", (mid,)).getField('name')
+ data = {}
+ data['logs'] = self.getLogsStatus(name)
+ data['userini'] = False
+ if os.path.exists(path + '/.user.ini'):
+ data['userini'] = True
+ data['runPath'] = self.getSiteRunPath(mid)
+ data['pass'] = self.getHasPwd(name)
+ return public.returnJson(True, 'OK', data)
+
def getCertListApi(self):
try:
vpath = self.sslDir
@@ -203,6 +253,54 @@ class site_api:
public.writeLog('TYPE_SITE', '证书已保存!')
return public.returnJson(True, '证书已保存!')
+ def closeSslConfApi(self):
+ siteName = request.form.get('siteName', '').encode('utf-8')
+
+ file = self.getHostConf(siteName)
+ conf = public.readFile(file)
+
+ if conf:
+ rep = "\n\s*#HTTP_TO_HTTPS_START(.|\n){1,300}#HTTP_TO_HTTPS_END"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_certificate\s+.+;\s+ssl_certificate_key\s+.+;"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_protocols\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_ciphers\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_prefer_server_ciphers\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_session_cache\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_session_timeout\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_ecdh_curve\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_session_tickets\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_stapling\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl_stapling_verify\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+add_header\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+add_header\s+.+;\n"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+ssl\s+on;"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+error_page\s497.+;"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+if.+server_port.+\n.+\n\s+\s*}"
+ conf = re.sub(rep, '', conf)
+ rep = "\s+listen\s+443.*;"
+ conf = re.sub(rep, '', conf)
+ public.writeFile(file, conf)
+
+ msg = public.getInfo('网站[{1}]关闭SSL成功!', (siteName,))
+ public.writeLog('TYPE_SITE', msg)
+ public.restartWeb()
+ return public.returnJson(True, 'SSL已关闭!')
+
def createLetApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
updateOf = request.form.get('updateOf', '')
@@ -589,6 +687,39 @@ class site_api:
return path
return ''
+ # 取当站点前运行目录
+ def getSiteRunPath(self, mid):
+ siteName = public.M('sites').where('id=?', (mid,)).getField('name')
+ sitePath = public.M('sites').where('id=?', (mid,)).getField('path')
+ path = sitePath
+
+ filename = self.getHostConf(siteName)
+ if os.path.exists(filename):
+ conf = public.readFile(filename)
+ rep = '\s*root\s*(.+);'
+ path = re.search(rep, conf).groups()[0]
+
+ data = {}
+ if sitePath == path:
+ data['runPath'] = '/'
+ else:
+ data['runPath'] = path.replace(sitePath, '')
+
+ dirnames = []
+ dirnames.append('/')
+ for filename in os.listdir(sitePath):
+ try:
+ filePath = sitePath + '/' + filename
+ if os.path.islink(filePath):
+ continue
+ if os.path.isdir(filePath):
+ dirnames.append('/' + filename)
+ except:
+ pass
+
+ data['dirs'] = dirnames
+ return data
+
def getHostConf(self, siteName):
return public.getServerDir() + '/openresty/nginx/conf/vhost/' + siteName + '.conf'
@@ -609,6 +740,24 @@ class site_api:
return public.returnJson(False, '日志为空')
return public.returnJson(True, public.getNumLines(logPath, 100))
+ # 取日志状态
+ def getLogsStatus(self, siteName):
+ filename = self.getHostConf(siteName)
+ conf = public.readFile(filename)
+ if conf.find('#ErrorLog') != -1:
+ return False
+ if conf.find("access_log /dev/null") != -1:
+ return False
+ return True
+
+ # 取目录加密状态
+ def getHasPwd(self, siteName):
+ filename = self.getHostConf(siteName)
+ conf = public.readFile(filename)
+ if conf.find('#AUTH_START') != -1:
+ return True
+ return False
+
def getSitePhpVersion(self, siteName):
conf = public.readFile(self.getHostConf(siteName))
rep = "enable-php-([0-9]{2,3})\.conf"
diff --git a/route/static/app/site.js b/route/static/app/site.js
index d0cb0e994..413742a08 100755
--- a/route/static/app/site.js
+++ b/route/static/app/site.js
@@ -283,66 +283,65 @@ function webAdd(type) {
//修改网站目录
function webPathEdit(id){
- $.post("/data?action=getKey","table=sites&key=path&id="+id,function(rdata){
- $.post('/site?action=GetDirUserINI','path='+rdata+'&id='+id,function(userini){
- var userinicheckeds = userini.userini?'checked':'';
- var logscheckeds = userini.logs?'checked':'';
- var opt = ''
- var selected = '';
- for(var i=0;i'+ userini.runPath.dirs[i] +''
- }
- var webPathHtml = "';
- $("#webedit-con").html(webPathHtml);
-
- $("#userini").change(function(){
- $.post('/site?action=SetDirUserINI','path='+rdata,function(userini){
- layer.msg(userini.msg+'注意:设置防跨站需要重启PHP才能生效!
',{icon:userini.status?1:2});
- });
+ $.post('/site/get_dir_user_ini','&id='+id, function(data){
+ var userini = data['data'];
+ var userinicheckeds = userini.userini?'checked':'';
+ var logscheckeds = userini.logs?'checked':'';
+ var opt = ''
+ var selected = '';
+ for(var i=0;i'+ userini.runPath.dirs[i] +''
+ }
+ var webPathHtml = "';
+ $("#webedit-con").html(webPathHtml);
+
+ $("#userini").change(function(){
+ $.post('/site?action=SetDirUserINI','path='+rdata,function(userini){
+ layer.msg(userini.msg+'注意:设置防跨站需要重启PHP才能生效!
',{icon:userini.status?1:2});
});
-
- $("#logs").change(function(){
- $.post('/site?action=logsOpen','id='+id,function(userini){
- layer.msg(userini.msg,{icon:userini.status?1:2});
- });
- });
-
});
- });
+
+ $("#logs").change(function(){
+ $.post('/site?action=logsOpen','id='+id,function(userini){
+ layer.msg(userini.msg,{icon:userini.status?1:2});
+ });
+ });
+
+ },'json');
}
//是否设置访问密码
@@ -982,9 +981,8 @@ function setIndexList(id){
/*站点修改*/
function webEdit(id,website,endTime,addtime){
- var system = "{$Think.session.system}";
var eMenu = '';
- eMenu = "子目录绑定
"
+ eMenu = "子目录绑定
"
+"网站目录
"
+"流量限制
"
+"伪静态
"
@@ -992,14 +990,14 @@ function webEdit(id,website,endTime,addtime){
+"配置文件
"
+"SSL
"
+"PHP版本
"
- +"301重定向
"
+ +"重定向
"
+"反向代理
"
+"防盗链
"
+"响应日志
";
layer.open({
type: 1,
area: '640px',
- title: lan.site.website_change+'['+website+'] -- '+lan.site.addtime+'['+addtime+']',
+ title: '站点修改['+website+'] -- 添加时间['+addtime+']',
closeBtn: 2,
shift: 0,
content: ""
+ + ""
+ + "| 域名 | 端口 | 子目录 | 操作 |
"
+ + "" + echoHtml + ""
+ + "
";
$("#webedit-con").html(body);
- })
-
+ },'json');
}
//子目录伪静态
@@ -1797,7 +1794,7 @@ function opSSL(type,id,siteName){
layer.close(loadT);
var rdata = data['data'];
if(rdata.status){
- $(".ssl-btn").append("");
+ $(".ssl-btn").append("");
}
if(rdata.key == false) rdata.key = '';
if(rdata.csr == false) rdata.csr = '';
@@ -1875,30 +1872,28 @@ function ocSSL(action,siteName){
if(!rdata.status){
if(!rdata.out){
layer.msg(rdata.msg,{icon:rdata.status?1:2});
- //setSSL(siteName);
+ setSSL(siteName);
return;
}
-
- data = ""+lan.site.get_ssl_err+":
"
+ data = "证书获取失败:
"
for(var i=0;i"+lan.site.domain+": "+rdata.out[i].Domain+"
"
- + ""+lan.site.err_type+": "+rdata.out[i].Type+"
"
- + ""+lan.site.details+": "+rdata.out[i].Detail+"
"
- + "
"
+ data += "域名: "+rdata.out[i].Domain+"
"
+ + "错误类型: "+rdata.out[i].Type+"
"
+ + "详情: "+rdata.out[i].Detail+"
"
+ + "
";
}
-
layer.msg(data,{icon:2,time:0,shade:0.3,shadeClose:true});
return;
}
-
+
setCookie('letssl',0);
- $.post('/system?action=ServiceAdmin','name='+getCookie('serverType')+'&type=reload',function(result){
- //setSSL(siteName);
- if(!result.status) layer.msg(result.msg,{icon:2});
- },'json');
+ // $.post('/system?action=ServiceAdmin','name='+getCookie('serverType')+'&type=reload',function(result){
+ // //setSSL(siteName);
+ // if(!result.status) layer.msg(result.msg,{icon:2});
+ // },'json');
layer.msg(rdata.msg,{icon:rdata.status?1:2});
- if(action == 'CloseSSLConf'){
- layer.msg(lan.site.ssl_close_info,{icon:1,time:5000});
+ if(action == 'close_ssl_conf'){
+ layer.msg('已关闭SSL,请务必清除浏览器缓存后再访问站点!',{icon:1,time:5000});
}
$(".bt-w-menu .bgw").click();
},'json');
@@ -1947,7 +1942,7 @@ function saveSSL(siteName){
if(rdata.status){
layer.msg(rdata.msg,{icon:1});
$(".ssl-btn").find(".btn-default").remove();
- $(".ssl-btn").append("");
+ $(".ssl-btn").append("");
}else{
layer.msg(rdata.msg,{icon:2,time:0,shade:0.3,shadeClose:true});
}