pull/109/head
Mr Chen 6 years ago
parent 2ec7ae6135
commit a308dbf353
  1. 10
      class/core/public.py
  2. 43
      class/core/site_api.py
  3. 17
      data/tpl/nginx.conf
  4. 0
      plugins/ftp/js/ftp.js
  5. 30
      plugins/openresty/conf/nginx.conf
  6. 9
      plugins/openresty/conf/nginx_status.conf
  7. 5
      plugins/openresty/index.py
  8. 3
      route/site.py
  9. 1
      templates/default/site.html

@ -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)

@ -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, '站点删除成功!')

@ -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;
}

@ -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;
}

@ -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;
}
}

@ -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

@ -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)

@ -56,7 +56,6 @@
</div>
<script type="text/javascript" src="/static/laydate/laydate.js?v={{config.version}}"></script>
<script type="text/javascript" src="/static/app/ftp.js?v={{config.version}}"></script>
<script type="text/javascript" src="/static/app/site.js?v={{config.version}}"></script>
<script type="text/javascript">
setTimeout(function(){

Loading…
Cancel
Save