pull/109/head
Mr Chen 6 years ago
parent 12dbdc3659
commit cf92234cd0
  1. 107
      class/core/site_api.py
  2. 12
      route/static/app/public.js
  3. 79
      route/static/app/site.js

@ -49,8 +49,12 @@ class site_api:
##### ----- start ----- ###
def listApi(self):
limit = request.form.get('limit', '').encode('utf-8')
p = request.form.get('p', '').encode('utf-8')
start = (int(p) - 1) * (int(limit))
_list = public.M('sites').where('', ()).field(
'id,name,path,status,ps,addtime,edate').limit('0,5').order('id desc').select()
'id,name,path,status,ps,addtime,edate').limit((str(start)) + ',' + limit).order('id desc').select()
_ret = {}
_ret['data'] = _list
@ -58,10 +62,19 @@ class site_api:
_page = {}
_page['count'] = count
_page['tojs'] = 'getWeb'
_page['p'] = p
_page['row'] = limit
_ret['page'] = public.getPage(_page)
return public.getJson(_ret)
def setPsApi(self):
mid = request.form.get('id', '').encode('utf-8')
ps = request.form.get('ps', '').encode('utf-8')
if public.M('sites').where("id=?", (mid,)).setField('ps', ps):
return public.returnJson(True, '修改成功!')
return public.returnJson(False, '修改失败!')
def getPhpVersionApi(self):
return self.getPhpVersion()
@ -835,9 +848,9 @@ class site_api:
passconf = username + ':' + public.hasPwd(password)
if siteName == 'phpmyadmin':
configFile = self.setupPath + '/openresty/nginx/conf/nginx.conf'
configFile = self.getHostConf('phpmyadmin')
else:
configFile = self.setupPath + '/openresty/nginx/vhost/' + siteName + '.conf'
configFile = self.getHostConf(siteName)
# 处理Nginx配置
conf = public.readFile(configFile)
@ -846,13 +859,12 @@ class site_api:
if conf.find(rep) == -1:
rep = '#error_page 404/404.html;'
data = '''
#AUTH_START
# AUTH_START
auth_basic "Authorization";
auth_basic_user_file %s;
#AUTH_END''' % (filename,)
# AUTH_END''' % (filename,)
conf = conf.replace(rep, rep + data)
public.writeFile(configFile, conf)
# 写密码配置
passDir = self.passPath
if not os.path.exists(passDir):
@ -865,26 +877,27 @@ class site_api:
return public.returnJson(True, '设置成功!')
# 取消目录加密
# def CloseHasPwd(self, get):
# if not hasattr(get, 'siteName'):
# get.siteName = public.M('sites').where(
# 'id=?', (get.id,)).getField('name')
# if get.siteName == 'phpmyadmin':
# get.configFile = self.setupPath + '/nginx/conf/nginx.conf'
# else:
# get.configFile = self.setupPath + '/panel/vhost/nginx/' + get.siteName + '.conf'
# if os.path.exists(get.configFile):
# conf = public.readFile(get.configFile)
# rep = "\n\s*#AUTH_START(.|\n){1,200}#AUTH_END"
# conf = re.sub(rep, '', conf)
# public.writeFile(get.configFile, conf)
# public.restartWeb()
# public.WriteLog("网站管理", "SITE_AUTH_CLOSE_SUCCESS",
# (get.siteName,))
# return public.returnMsg(True, 'SET_SUCCESS')
def closeHasPwdApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
mid = request.form.get('id', '')
if siteName == '':
siteName = public.M('sites').where('id=?', (mid,)).getField('name')
if siteName == 'phpmyadmin':
configFile = self.getHostConf('phpmyadmin')
else:
configFile = self.getHostConf(siteName)
if os.path.exists(configFile):
conf = public.readFile(configFile)
rep = "\n\s*#AUTH_START(.|\n){1,200}#AUTH_END"
conf = re.sub(rep, '', conf)
public.writeFile(configFile, conf)
public.restartWeb()
msg = public.getInfo('清除网站[{1}]的密码认证!', (siteName,))
public.writeLog("网站管理", msg)
return public.returnJson(True, '设置成功!')
def delDomainApi(self):
domain = request.form.get('domain', '').encode('utf-8')
@ -931,6 +944,48 @@ class site_api:
webname = request.form.get('webname', '').encode('utf-8')
path = request.form.get('path', '0').encode('utf-8')
return self.delete(sid, webname, path)
def getProxyListApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
conf_path = self.getHostConf(siteName)
old_conf = public.readFile(conf_path)
rep = "(#PROXY-START(\n|.)+#PROXY-END)"
url_rep = "proxy_pass (.*);|ProxyPass\s/\s(.*)|Host\s(.*);"
host_rep = "Host\s(.*);"
if re.search(rep, old_conf):
# 构造代理配置
if w == "nginx":
get.todomain = str(re.search(host_rep, old_conf).group(1))
get.proxysite = str(re.search(url_rep, old_conf).group(1))
else:
get.todomain = ""
get.proxysite = str(re.search(url_rep, old_conf).group(2))
get.proxyname = "旧代理"
get.type = 1
get.proxydir = "/"
get.advanced = 0
get.cachetime = 1
get.cache = 0
get.subfilter = "[{\"sub1\":\"\",\"sub2\":\"\"},{\"sub1\":\"\",\"sub2\":\"\"},{\"sub1\":\"\",\"sub2\":\"\"}]"
# proxyname_md5 = self.__calc_md5(get.proxyname)
# 备份并替换老虚拟主机配置文件
os.system("cp %s %s_bak" % (conf_path, conf_path))
conf = re.sub(rep, "", old_conf)
public.writeFile(conf_path, conf)
# self.createProxy(get)
public.restartWeb()
proxyUrl = self.__read_config(self.__proxyfile)
sitename = sitename
proxylist = []
for i in proxyUrl:
if i["sitename"] == sitename:
proxylist.append(i)
return public.getJson(proxylist)
##### ----- end ----- ###
# 域名编码转换

@ -97,18 +97,6 @@ function repeatPwd(a) {
$("#MyPassword").val(randomStrPwd(a))
}
function GetBakPost(b) {
$(".baktext").hide().prev().show();
var c = $(".baktext").attr("data-id");
var a = $(".baktext").val();
if(a == "") {
a = lan.bt.empty;
}
setWebPs(b, c, a);
$("a[data-id='" + c + "']").html(a);
$(".baktext").remove()
}
$(".menu-icon").click(function() {
$(".sidebar-scroll").toggleClass("sidebar-close");
$(".main-content").toggleClass("main-content-open");

@ -14,7 +14,7 @@ function getWeb(page, search) {
}
var sUrl = '/site/list';
var pdata = 'tojs=getWeb&table=sites&limit=15&p=' + page + '&search=' + search + order;
var pdata = 'limit=10&p=' + page + '&search=' + search + order;
var loadT = layer.load();
//取回数据
$.post(sUrl, pdata, function(data) {
@ -120,12 +120,41 @@ function getWeb(page, search) {
if(databak==lan.site.site_null){
databak='';
}
$(this).hide().after("<input class='baktext' type='text' data-id='"+dataid+"' name='bak' value='" + databak + "' placeholder='"+lan.site.site_bak+"' onblur='GetBakPost(\"sites\")' />");
$(this).hide().after("<input class='baktext' type='text' data-id='"+dataid+"' name='bak' value='" + databak + "' placeholder='备注信息' onblur='getBakPost(\"sites\")' />");
$(".baktext").focus();
});
},'json');
}
function getBakPost(b) {
$(".baktext").hide().prev().show();
var c = $(".baktext").attr("data-id");
var a = $(".baktext").val();
if(a == "") {
a = '空';
}
setWebPs(b, c, a);
$("a[data-id='" + c + "']").html(a);
$(".baktext").remove();
}
function setWebPs(b, e, a) {
console.log(b,e,a);
var d = layer.load({shade: true,shadeClose: false});
var c = 'ps=' + a;
$.post('/site/set_ps', 'id=' + e + "&" + c, function(data) {
if(data['status']) {
getWeb(1);
layer.closeAll();
layer.msg('修改成功!', {icon: 1});
} else {
layer.closeAll();
layer.msg('修改失败!', {icon: 2});
}
},'json');
}
//添加站点
function webAdd(type) {
if (type == 1) {
@ -352,9 +381,9 @@ function pathSafe(id){
var isPass = $('#pathSafe').prop('checked');
if(!isPass){
$(".user_pw").show();
}else{
} else {
var loadT = layer.msg(lan.public.the,{icon:16,time:10000,shade: [0.3, '#000']});
$.post('/site?action=CloseHasPwd',{id:id},function(rdata){
$.post('/site/close_has_pwd',{id:id},function(rdata){
layer.close(loadT);
layer.msg(rdata.msg,{icon:rdata.status?1:2});
$(".user_pw").hide();
@ -779,7 +808,7 @@ function isDomain(domain) {
* @param {Number} id 编号
* @param {String} name 主域名
*/
function WebBackup(id, name) {
function webBackup(id, name) {
var loadT =layer.msg(lan.database.backup_the, {icon:16,time:0,shade: [0.3, '#000']});
var data = "id="+id;
$.post('/site?action=ToBackup', data, function(rdata) {
@ -795,7 +824,7 @@ function WebBackup(id, name) {
* @param {Number} id 文件编号
* @param {String} name 主域名
*/
function WebBackupDelete(id,pid){
function webBackupDelete(id,pid){
layer.confirm(lan.site.webback_del_confirm,{title:lan.site.del_bak_file,icon:3,closeBtn:2},function(index){
var loadT =layer.msg(lan.public.the_del, {icon:16,time:0,shade: [0.3, '#000']});
$.post('/site?action=DelBackup','id='+id, function(rdata){
@ -807,9 +836,11 @@ function WebBackupDelete(id,pid){
}
function getBackup(id,name,page) {
if(page == undefined){
page = '1';
}
}
$.post('/data?action=getFind','table=sites&id=' + id, function(rdata) {
$.post('/data?action=getData','table=backup&search=' + id + '&limit=5&p='+page+'&type=0&tojs=getBackup',function(frdata){
@ -831,9 +862,9 @@ function getBackup(id,name,page) {
frdata.page = frdata.page.replace(/'/g,'"').replace(/getBackup\(/g,"getBackup(" + id + ",0,");
if(name == 0){
var sBody = "<table width='100%' id='WebBackupList' class='table table-hover'>\
<thead><tr><th>"+lan.site.filename+"</th><th>"+lan.site.filesize+"</th><th>"+lan.site.backuptime+"</th><th width='140px' class='text-right'>"+lan.site.operate+"</th></tr></thead>\
<tbody id='WebBackupBody' class='list-list'>"+body+"</tbody>\
var sBody = "<table width='100%' id='webBackupList' class='table table-hover'>\
<thead><tr><th>文件名称</th><th></th><th></th><th width='140px' class='text-right'></th></tr></thead>\
<tbody id='webBackupBody' class='list-list'>"+body+"</tbody>\
</table>"
$("#WebBackupList").html(sBody);
$(".page").html(frdata.page);
@ -849,15 +880,15 @@ function getBackup(id,name,page) {
shift: 0,
shadeClose: false,
content: "<div class='bt-form ptb15 mlr15' id='WebBackup'>\
<button class='btn btn-default btn-sm' style='margin-right:10px' type='button' onclick=\"WebBackup('" + rdata.id + "','" + rdata.name + "')\">"+lan.site.backup_title+"</button>\
<div class='divtable mtb15' style='margin-bottom:0'><table width='100%' id='WebBackupList' class='table table-hover'>\
<thead><tr><th>"+lan.site.filename+"</th><th>"+lan.site.filesize+"</th><th>"+lan.site.backuptime+"</th><th width='140px' class='text-right'>"+lan.site.operate+"</th></tr></thead>\
<tbody id='WebBackupBody' class='list-list'>"+body+"</tbody>\
<button class='btn btn-default btn-sm' style='margin-right:10px' type='button' onclick=\"webBackup('" + rdata.id + "','" + rdata.name + "')\">打包备份</button>\
<div class='divtable mtb15' style='margin-bottom:0'><table width='100%' id='webBackupList' class='table table-hover'>\
<thead><tr><th>文件名称</th><th></th><th></th><th width='140px' class='text-right'></th></tr></thead>\
<tbody id='webBackupBody' class='list-list'>"+body+"</tbody>\
</table><div class='page'>"+frdata.page+"</div></div></div>"
});
});
});
},'json');
}
@ -990,8 +1021,8 @@ function webEdit(id,website,endTime,addtime){
+"<p onclick=\"configFile('"+website+"')\" title='配置文件'>配置文件</p>"
+"<p onclick=\"setSSL("+id+",'"+website+"')\" title='SSL'>SSL</p>"
+"<p onclick=\"phpVersion('"+website+"')\" title='PHP版本'>PHP版本</p>"
+"<p onclick=\"To301('"+website+"')\" title='重定向'>重定向</p>"
+"<p onclick=\"Proxy('"+website+"')\" title='反向代理'>反向代理</p>"
// +"<p onclick=\"to301('"+website+"')\" title='重定向'>重定向</p>"
// +"<p onclick=\"proxyList('"+website+"')\" title='反向代理'>反向代理</p>"
+"<p id='site_"+id+"' onclick=\"security('"+id+"','"+website+"')\" title='防盗链'>防盗链</p>"
+"<p id='site_"+id+"' onclick=\"getSiteLogs('"+website+"')\" title='查看站点请求日志'>响应日志</p>";
layer.open({
@ -1364,7 +1395,7 @@ function delDirBind(id,siteId){
}
//反向代理
function Proxy(siteName,type){
function proxyList(siteName,type){
if(type == 1){
type = $("input[name='status']").attr('checked')?'0':'1';
toUrl = encodeURIComponent($("input[name='toUrl']").val());
@ -1418,7 +1449,7 @@ function OpenCache(siteName){
}
//301重定向
function To301(siteName,type){
function to301(siteName,type){
if(type == 1){
type = $("input[name='status']").attr('checked')?'0':'1';
toUrl = encodeURIComponent($("input[name='toUrl']").val());
@ -2223,14 +2254,14 @@ function siteDefaultPage(){
layer.open({
type: 1,
area: '460px',
title: lan.site.change_defalut_page,
title: '修改默认页',
closeBtn: 2,
shift: 0,
content: '<div class="changeDefault pd20">\
<button class="btn btn-default btn-sm mg10" style="width:188px" onclick="changeDefault(1)">'+lan.site.default_doc+'</button>\
<button class="btn btn-default btn-sm mg10" style="width:188px" onclick="changeDefault(2)">'+lan.site.err_404+'</button>\
<button class="btn btn-default btn-sm mg10" style="width:188px" onclick="changeDefault('+(stype=='nginx'?3:4)+')">'+(stype=='nginx'?'Nginx':'Apache')+lan.site.empty_page+'</button>\
<button class="btn btn-default btn-sm mg10" style="width:188px" onclick="changeDefault(5)">'+lan.site.default_page_stop+'</button>\
<button class="btn btn-default btn-sm mg10" style="width:188px" onclick="changeDefault(1)">默认文档</button>\
<button class="btn btn-default btn-sm mg10" style="width:188px" onclick="changeDefault(2)">404错误页</button>\
<button class="btn btn-default btn-sm mg10" style="width:188px" onclick="changeDefault('+(stype=='nginx'?3:4)+')">'+(stype=='nginx'?'Nginx':'Apache')+'空白页</button>\
<button class="btn btn-default btn-sm mg10" style="width:188px" onclick="changeDefault(5)">默认站点停止页</button>\
</div>'
});
}

Loading…
Cancel
Save