diff --git a/class/core/site_api.py b/class/core/site_api.py index cc1749cde..6b801af16 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -22,6 +22,7 @@ class site_api: setupPath = None # 安装路径 vhostPath = None + logsPath = None rewritePath = None sslDir = None # ssl目录 @@ -35,6 +36,8 @@ class site_api: if not os.path.exists(rw): public.execShell("mkdir -p " + rw + " && chmod -R 755 " + rw) + self.logsPath = public.getRootDir() + '/wwwlogs' + # ssl conf if public.isAppleSystem(): self.sslDir = self.setupPath + '/letsencrypt/' @@ -166,6 +169,24 @@ class site_api: public.execShell("which chattr && chattr +i " + filename) return public.returnJson(True, '已打开防跨站设置!') + def logsOpenApi(self): + mid = request.form.get('id', '').encode('utf-8') + name = public.M('sites').where("id=?", (mid,)).getField('name') + + # NGINX + filename = self.getHostConf(name) + if os.path.exists(filename): + conf = public.readFile(filename) + rep = self.logsPath + "/" + name + ".log" + if conf.find(rep) != -1: + conf = conf.replace(rep, "off") + else: + conf = conf.replace('access_log off', 'access_log ' + rep) + public.writeFile(filename, conf) + + public.restartWeb() + return public.returnJson(True, '操作成功!') + def getCertListApi(self): try: vpath = self.sslDir diff --git a/route/static/app/site.js b/route/static/app/site.js index 9b53b41b4..72fc4019f 100755 --- a/route/static/app/site.js +++ b/route/static/app/site.js @@ -339,7 +339,7 @@ function webPathEdit(id){ }); $("#logs").change(function(){ - $.post('/site?action=logsOpen','id='+id,function(userini){ + $.post('/site/logs_open','id='+id,function(userini){ layer.msg(userini.msg,{icon:userini.status?1:2}); },'josn'); });