From c6b38aa996ca3d9ffa4b72ae207e7baaa75f3fdb Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 20 Dec 2018 10:45:43 +0800 Subject: [PATCH] update --- class/core/config.py | 7 ++++--- class/core/site_api.py | 31 +++++++++++++++++++++++++++++++ cli.sh | 3 ++- route/site.py | 16 ++++++++++++++++ static/app/site.js | 35 ++++++++++++++++------------------- 5 files changed, 69 insertions(+), 23 deletions(-) diff --git a/class/core/config.py b/class/core/config.py index 677757cc5..c386997b9 100644 --- a/class/core/config.py +++ b/class/core/config.py @@ -42,15 +42,16 @@ class config: app.config['SECRET_KEY'] = os.urandom(24) app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7) - # app.debug = True - # app.config.version = self.__version + str(time.time()) - self.initDB() self.initInitD() self.initRoute() app.wsgi_app = MiddleWare(app.wsgi_app) return app + def startDebug(self): + app.debug = True + app.config.version = self.__version + str(time.time()) + def initDB(self): try: sql = db.Sql().dbfile('default') diff --git a/class/core/site_api.py b/class/core/site_api.py index f653a7644..1a38dccb6 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -98,6 +98,37 @@ class site_api: data['phpversion'] = tmp[0] 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) + rep = "\s+index\s+(.+);" + tmp = re.search(rep, conf).groups() + return tmp[0].replace(' ', ',') + + def setIndex(self, sid, index): + if index.find('.') == -1: + return public.returnJson(False, '默认文档格式不正确,例:index.html') + + index = index.replace(' ', '') + index = index.replace(',,', ',') + + if len(index) < 3: + return public.returnJson(False, '默认文档不能为空!') + + siteName = public.M('sites').where("id=?", (sid,)).getField('name') + index_l = index.replace(",", " ") + file = self.getHostConf(siteName) + conf = public.readFile(file) + if conf: + rep = "\s+index\s+.+;" + conf = re.sub(rep, "\n\tindex " + index_l + ";", conf) + public.writeFile(file, conf) + + public.writeLog('TYPE_SITE', 'SITE_INDEX_SUCCESS', (siteName, index_l)) + return public.returnJson(True, '设置成功!') + def getHostConf(self, siteName): return public.getServerDir() + '/openresty/nginx/conf/vhost/' + siteName + '.conf' diff --git a/cli.sh b/cli.sh index 14454a80e..6a73685bd 100755 --- a/cli.sh +++ b/cli.sh @@ -10,8 +10,9 @@ mw_start(){ mw_start_debug(){ - gunicorn -b :7200 app:app & python task.py & + # gunicorn -b :7200 app:app + gunicorn -c setting.py app:app } mw_stop() diff --git a/route/site.py b/route/site.py index d4ac15e48..d9017fe43 100644 --- a/route/site.py +++ b/route/site.py @@ -37,6 +37,22 @@ def getDomain(): return site_api.site_api().getDomain(pid) +@site.route('get_index', methods=['POST']) +def getIndex(): + sid = request.form.get('id', '').encode('utf-8') + data = {} + index = site_api.site_api().getIndex(sid) + data['index'] = index + return public.getJson(data) + + +@site.route('set_index', methods=['POST']) +def setIndex(): + sid = request.form.get('id', '').encode('utf-8') + index = request.form.get('index', '').encode('utf-8') + return site_api.site_api().setIndex(sid, index) + + @site.route('get_logs', methods=['POST']) def getLogs(): siteName = request.form.get('siteName', '').encode('utf-8') diff --git a/static/app/site.js b/static/app/site.js index 922b6efc9..2ee74b490 100755 --- a/static/app/site.js +++ b/static/app/site.js @@ -449,24 +449,23 @@ function SetSitePs(id){ //设置默认文档 -function SetIndexEdit(id){ - $.post('/site?action=GetIndex','id='+id,function(rdata){ - rdata= rdata.replace(new RegExp(/(,)/g), "\n"); +function setIndexEdit(id){ + $.post('/site/get_index','id='+id,function(data){ + var rdata = data['index']; + rdata = rdata.replace(new RegExp(/(,)/g), "\n"); var setIndexHtml = "
\
\ \ - \ + \
\
    \ -
  • "+lan.site.default_doc_help+"
  • \ +
  • 默认文档,每行一个,优先级由上至下。
  • \
\
"; $("#webedit-con").html(setIndexHtml); - }); - + },'json'); } - /** * 停止一个站点 * @param {Int} wid 网站ID @@ -934,7 +933,7 @@ function setIndex(id){ +"" +"
" +" " - +" " + +" " +"
" +"" }); @@ -988,24 +987,22 @@ function GetDefaultSite(){ }); } -function SetIndexList(id){ +function setIndexList(id){ var Dindex = $("#Dindex").val().replace(new RegExp(/(\n)/g), ","); - if(id==undefined){ - var data="id=&Index="+Dindex; - } - else{ - var data="id="+id+"&Index="+Dindex; + if(id == undefined ){ + var data="id=&index="+Dindex; + } else{ + var data="id="+id+"&index="+Dindex; } var loadT= layer.load(2); - $.post('/site?action=SetIndex',data,function(rdata){ + $.post('/site/set_index',data,function(rdata){ layer.close(loadT); var ico = rdata.status? 1:5; layer.msg(rdata.msg,{icon:ico}); - }); + },'json'); } - /*站点修改*/ function webEdit(id,website,endTime,addtime){ var system = "{$Think.session.system}"; @@ -1014,7 +1011,7 @@ function webEdit(id,website,endTime,addtime){ +"

"+lan.site.site_menu_2+"

" +"

"+lan.site.site_menu_3+"

" +"

"+lan.site.site_menu_4+"

" - +"

"+lan.site.site_menu_5+"

" + +"

默认文档

" +"

"+lan.site.site_menu_6+"

" +"

"+lan.site.site_menu_7+"

" +"

"+lan.site.site_menu_8+"

"