From a308dbf35381b0659e5f3c6ffea06ca4d9b45774 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 18 Dec 2018 13:17:37 +0800 Subject: [PATCH] update --- class/core/public.py | 10 ++++++ class/core/site_api.py | 43 +++++++++++++++++------- data/tpl/nginx.conf | 17 +++++----- {static/app => plugins/ftp/js}/ftp.js | 0 plugins/openresty/conf/nginx.conf | 30 ++++------------- plugins/openresty/conf/nginx_status.conf | 9 ----- plugins/openresty/index.py | 5 --- route/site.py | 3 +- templates/default/site.html | 1 - 9 files changed, 58 insertions(+), 60 deletions(-) rename {static/app => plugins/ftp/js}/ftp.js (100%) delete mode 100644 plugins/openresty/conf/nginx_status.conf diff --git a/class/core/public.py b/class/core/public.py index 8436cdcb0..24b6294e6 100755 --- a/class/core/public.py +++ b/class/core/public.py @@ -58,11 +58,21 @@ def getWwwDir(): return getRootDir() + '/wwwroot' +def getLogsDir(): + return getRootDir() + '/wwwlogs' + + def getOs(): os = execShell('uname') return os[0].lower().strip() +def isAppleSystem(): + if getOs() == 'darwin': + return True + return False + + def M(table): sql = db.Sql() return sql.table(table) diff --git a/class/core/site_api.py b/class/core/site_api.py index 348410b21..5a0d499d4 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -22,15 +22,10 @@ class site_api: self.setupPath = public.getServerDir() path = self.setupPath + '/openresty/nginx/conf/vhost' if not os.path.exists(path): - public.execShell("mkdir -p " + path + " && chmod -R 644 " + path) + public.execShell("mkdir -p " + path + " && chmod -R 755 " + path) path = self.setupPath + '/openresty/nginx/conf/rewrite' if not os.path.exists(path): - public.execShell("mkdir -p " + path + " && chmod -R 644 " + path) - path = self.setupPath + '/stop' - if not os.path.exists(path): - os.system('mkdir -p ' + path) - # os.system('wget -O ' + path + '/index.html ' + - # public.get_url() + '/stop.html &') + public.execShell("mkdir -p " + path + " && chmod -R 755 " + path) # 域名编码转换 def toPunycode(self, domain): @@ -105,11 +100,26 @@ class site_api: def createRootDir(self, path): if not os.path.exists(path): os.makedirs(path) - print public.execShell('chown -R www:www ' + path) + if not public.isAppleSystem(): + public.execShell('chown -R www:www ' + path) public.execShell('chmod -R 755 ' + path) def nginxAddConf(self): - pass + source_tpl = public.getRunDir() + '/data/tpl/nginx.conf' + desc_file = self.setupPath + '/openresty/nginx/conf/vhost/' + self.siteName + '.conf' + content = public.readFile(source_tpl) + + content = content.replace('{$PORT}', self.sitePort) + content = content.replace('{$SERVER_NAME}', self.siteName) + content = content.replace('{$ROOT_DIR}', self.sitePath) + content = content.replace('{$PHPVER}', self.phpVersion) + + or_rewrite = self.setupPath + '/openresty/nginx/conf/rewrite' + content = content.replace('{$OR_REWRITE}', or_rewrite) + + logsPath = public.getLogsDir() + content = content.replace('{$LOGPATH}', logsPath) + public.writeFile(desc_file, content) def add(self, webname, port, ps, path, version): @@ -119,10 +129,15 @@ class site_api: self.sitePath = self.toPunycodePath( self.getPath(path.replace(' ', ''))) self.sitePort = port.strip().replace(' ', '') + self.phpVersion = version + + siteM = public.M('sites') + if siteM.where("name=?", (self.siteName,)).count(): + return public.returnJson(False, '您添加的站点已存在!') # 写入数据库 - pid = public.M('sites').add('name,path,status,ps,edate,addtime', - (self.siteName, self.sitePath, '1', ps, '0000-00-00', public.getDate())) + pid = siteM.add('name,path,status,ps,edate,addtime', + (self.siteName, self.sitePath, '1', ps, '0000-00-00', public.getDate())) self.createRootDir(self.sitePath) # public.M('domain').add('pid,name,port,addtime', @@ -134,7 +149,11 @@ class site_api: data['siteStatus'] = False return public.getJson(data) - def delete(self, sid): + def delete(self, sid, webname): + + confPath = self.setupPath + '/openresty/nginx/conf/vhost/' + webname + '.conf' + if os.path.exists(confPath): + os.remove(confPath) public.M('sites').where("id=?", (sid,)).delete() return public.returnJson(True, '站点删除成功!') diff --git a/data/tpl/nginx.conf b/data/tpl/nginx.conf index 19a1122d2..7796cc3e0 100755 --- a/data/tpl/nginx.conf +++ b/data/tpl/nginx.conf @@ -1,9 +1,9 @@ server { - listen %s; - server_name %s; + listen {$PORT}; + server_name {$SERVER_NAME}; index index.php index.html index.htm default.php default.htm default.html; - root %s; + root {$ROOT_DIR}; #SSL-START %s #error_page 404/404.html; @@ -15,11 +15,11 @@ server #ERROR-PAGE-END #PHP-INFO-START %s - include enable-php-%s.conf; + include enable-php-{$PHPVER}.conf; #PHP-INFO-END #REWRITE-START %s - include %s/panel/vhost/rewrite/%s.conf; + include {$OR_REWRITE}/{$SERVER_NAME}.conf; #REWRITE-END #禁止访问的文件或目录 @@ -35,7 +35,7 @@ server location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$ { - expires 30d; + expires 30d; error_log off; access_log /dev/null; } @@ -46,6 +46,7 @@ server error_log off; access_log /dev/null; } - access_log %s.log; - error_log %s.error.log; + + access_log {$LOGPATH}/{$SERVER_NAME}.log; + error_log {$LOGPATH}/{$SERVER_NAME}.error.log; } \ No newline at end of file diff --git a/static/app/ftp.js b/plugins/ftp/js/ftp.js similarity index 100% rename from static/app/ftp.js rename to plugins/ftp/js/ftp.js diff --git a/plugins/openresty/conf/nginx.conf b/plugins/openresty/conf/nginx.conf index b61a02d11..9e2297815 100644 --- a/plugins/openresty/conf/nginx.conf +++ b/plugins/openresty/conf/nginx.conf @@ -58,32 +58,14 @@ http server_tokens off; access_log off; - server - { + server { listen 80; - server_name 0.0.0.0; - index index.html index.htm index.php; - root /www/server/phpmyadmin; - - #error_page 404 /404.html; - #include enable-php.conf; - - location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ - { - expires 30d; - } - - location ~ .*\.(js|css)?$ - { - expires 12h; + server_name 127.0.0.1; + allow 127.0.0.1; + location /nginx_status { + stub_status on; + access_log off; } - - location ~ /\. - { - deny all; - } - - access_log {$SERVER_PATH}/openresty/nginx/logs/access.log; } include {$SERVER_PATH}/openresty/nginx/conf/vhost/*.conf; } diff --git a/plugins/openresty/conf/nginx_status.conf b/plugins/openresty/conf/nginx_status.conf deleted file mode 100644 index e8dd05cef..000000000 --- a/plugins/openresty/conf/nginx_status.conf +++ /dev/null @@ -1,9 +0,0 @@ -server { - listen 80; - server_name 127.0.0.1; - allow 127.0.0.1; - location /nginx_status { - stub_status on; - access_log off; - } -} diff --git a/plugins/openresty/index.py b/plugins/openresty/index.py index ec79632a3..93f341e7d 100755 --- a/plugins/openresty/index.py +++ b/plugins/openresty/index.py @@ -86,11 +86,6 @@ def makeConf(): if not os.path.exists(vhost): os.mkdir(vhost) - source_vhost = getPluginDir() + '/conf/nginx_status.conf' - dest_vhost = vhost + '/nginx_status.conf' - # if not os.path.exists(dest_vhost): - shutil.copyfile(source_vhost, dest_vhost) - def getFileOwner(filename): import pwd diff --git a/route/site.py b/route/site.py index 239d8d66b..c0bd20c17 100644 --- a/route/site.py +++ b/route/site.py @@ -58,4 +58,5 @@ def add(): @site.route('delete', methods=['POST']) def delete(): sid = request.form.get('id', '').encode('utf-8') - return site_api.site_api().delete(sid) + webname = request.form.get('webname', '').encode('utf-8') + return site_api.site_api().delete(sid, webname) diff --git a/templates/default/site.html b/templates/default/site.html index d82e55663..7e5d92e57 100755 --- a/templates/default/site.html +++ b/templates/default/site.html @@ -56,7 +56,6 @@ -