# coding: utf-8
import time
import os
import sys
import public
import re
import json
import pwd
import shutil
sys.path.append("/usr/local/lib/python2.7/site-packages")
import psutil
from flask import request
class site_api:
siteName = None # 网站名称
sitePath = None # 根目录
sitePort = None # 端口
phpVersion = None # PHP版本
setupPath = None # 安装路径
vhostPath = None
logsPath = None
passPath = None
rewritePath = None
sslDir = None # ssl目录
def __init__(self):
# nginx conf
self.setupPath = public.getServerDir() + '/web_conf'
self.vhostPath = vh = self.setupPath + '/nginx/vhost'
if not os.path.exists(vh):
public.execShell("mkdir -p " + vh + " && chmod -R 755 " + vh)
self.rewritePath = rw = self.setupPath + '/nginx/rewrite'
if not os.path.exists(rw):
public.execShell("mkdir -p " + rw + " && chmod -R 755 " + rw)
self.passPath = self.setupPath + '/nginx/pass'
# if not os.path.exists(pp):
# public.execShell("mkdir -p " + rw + " && chmod -R 755 " + rw)
self.logsPath = public.getRootDir() + '/wwwlogs'
# ssl conf
if public.isAppleSystem():
self.sslDir = self.setupPath + '/letsencrypt/'
else:
self.sslDir = '/etc/letsencrypt/live/'
##### ----- start ----- ###
def listApi(self):
limit = request.form.get('limit', '').encode('utf-8')
p = request.form.get('p', '').encode('utf-8')
type_id = request.form.get('type_id', '').encode('utf-8')
start = (int(p) - 1) * (int(limit))
siteM = public.M('sites')
if type_id != '' and type_id == '-1' and type_id == '0':
siteM.where('type_id=?', (type_id))
_list = siteM.field('id,name,path,status,ps,addtime,edate').limit(
(str(start)) + ',' + limit).order('id desc').select()
for i in range(len(_list)):
_list[i]['backup_count'] = public.M('backup').where(
"pid=? AND type=?", (_list[i]['id'], 0)).count()
_ret = {}
_ret['data'] = _list
count = siteM.count()
_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 stopApi(self):
mid = request.form.get('id', '').encode('utf-8')
name = request.form.get('name', '').encode('utf-8')
path = self.setupPath + '/stop'
if not os.path.exists(path):
os.makedirs(path)
public.writeFile(path + '/index.html',
'The website has been closed!!!')
binding = public.M('binding').where('pid=?', (mid,)).field(
'id,pid,domain,path,port,addtime').select()
for b in binding:
bpath = path + '/' + b['path']
if not os.path.exists(bpath):
public.execShell('mkdir -p ' + bpath)
public.execShell('ln -sf ' + path +
'/index.html ' + bpath + '/index.html')
sitePath = public.M('sites').where("id=?", (mid,)).getField('path')
# nginx
file = self.getHostConf(name)
conf = public.readFile(file)
if conf:
conf = conf.replace(sitePath, path)
public.writeFile(file, conf)
public.M('sites').where("id=?", (mid,)).setField('status', '0')
public.restartWeb()
msg = public.getInfo('网站[{1}]已被停用!', (name,))
public.writeLog('网站管理', msg)
return public.returnJson(True, '站点已停用!')
def startApi(self):
mid = request.form.get('id', '').encode('utf-8')
name = request.form.get('name', '').encode('utf-8')
path = self.setupPath + '/stop'
sitePath = public.M('sites').where("id=?", (mid,)).getField('path')
# nginx
file = self.getHostConf(name)
conf = public.readFile(file)
if conf:
conf = conf.replace(path, sitePath)
public.writeFile(file, conf)
public.M('sites').where("id=?", (mid,)).setField('status', '1')
public.restartWeb()
msg = public.getInfo('网站[{1}]已被启用!', (name,))
public.writeLog('网站管理', msg)
return public.returnJson(True, '站点已启用!')
def getBackupApi(self):
limit = request.form.get('limit', '').encode('utf-8')
p = request.form.get('p', '').encode('utf-8')
mid = request.form.get('search', '').encode('utf-8')
find = public.M('sites').where("id=?", (mid,)).field(
"id,name,path,status,ps,addtime,edate").find()
start = (int(p) - 1) * (int(limit))
_list = public.M('backup').where('pid=?', (mid,)).field('id,type,name,pid,filename,size,addtime').limit(
(str(start)) + ',' + limit).order('id desc').select()
_ret = {}
_ret['data'] = _list
count = public.M('backup').where("id=?", (mid,)).count()
info = {}
info['count'] = count
info['tojs'] = 'getBackup'
info['p'] = p
info['row'] = limit
_ret['page'] = public.getPage(info)
_ret['site'] = find
return public.getJson(_ret)
def toBackupApi(self):
mid = request.form.get('id', '').encode('utf-8')
find = public.M('sites').where(
"id=?", (mid,)).field('name,path,id').find()
fileName = find['name'] + '_' + \
time.strftime('%Y%m%d_%H%M%S', time.localtime()) + '.zip'
backupPath = public.getBackupDir() + '/site'
zipName = backupPath + '/' + fileName
if not (os.path.exists(backupPath)):
os.makedirs(backupPath)
tmps = public.getRunDir() + '/tmp/panelExec.log'
execStr = "cd '" + find['path'] + "' && zip '" + \
zipName + "' -r ./* > " + tmps + " 2>&1"
# print execStr
public.execShell(execStr)
if os.path.exists(zipName):
fsize = os.path.getsize(zipName)
else:
fsize = 0
sql = public.M('backup').add('type,name,pid,filename,size,addtime',
(0, fileName, find['id'], zipName, fsize, public.getDate()))
msg = public.getInfo('备份网站[{1}]成功!', (find['name'],))
public.writeLog('网站管理', msg)
return public.returnJson(True, '备份成功!')
def delBackupApi(self):
mid = request.form.get('id', '').encode('utf-8')
filename = public.M('backup').where(
"id=?", (mid,)).getField('filename')
if os.path.exists(filename):
os.remove(filename)
name = public.M('backup').where("id=?", (mid,)).getField('name')
msg = public.getInfo('删除网站[{1}]的备份[{2}]成功!', (name, filename))
public.writeLog('网站管理', msg)
public.M('backup').where("id=?", (mid,)).delete()
return public.returnJson(True, '站点删除成功!')
def getPhpVersionApi(self):
return self.getPhpVersion()
def setPhpVersionApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
version = request.form.get('version', '').encode('utf-8')
# nginx
file = self.getHostConf(siteName)
conf = public.readFile(file)
if conf:
rep = "enable-php-([0-9]{2,3})\.conf"
tmp = re.search(rep, conf).group()
conf = conf.replace(tmp, 'enable-php-' + version + '.conf')
public.writeFile(file, conf)
public.restartWeb()
msg = public.getInfo('成功切换网站[{1}]的PHP版本为PHP-{2}', (siteName, version))
public.writeLog("网站管理", msg)
return public.returnJson(True, msg)
def getDomainApi(self):
pid = request.form.get('pid', '').encode('utf-8')
return self.getDomain(pid)
# 获取站点所有域名
def getSiteDomainsApi(self):
pid = request.form.get('id', '').encode('utf-8')
data = {}
domains = public.M('domain').where(
'pid=?', (pid,)).field('name,id').select()
binding = public.M('binding').where(
'pid=?', (pid,)).field('domain,id').select()
if type(binding) == str:
return binding
for b in binding:
tmp = {}
tmp['name'] = b['domain']
tmp['id'] = b['id']
domains.append(tmp)
data['domains'] = domains
data['email'] = public.M('users').getField('email')
if data['email'] == '287962566@qq.com':
data['email'] = ''
return public.returnJson(True, 'OK', data)
def getDirBindingApi(self):
mid = request.form.get('id', '').encode('utf-8')
path = public.M('sites').where('id=?', (mid,)).getField('path')
if not os.path.exists(path):
checks = ['/', '/usr', '/etc']
if path in checks:
data = {}
data['dirs'] = []
data['binding'] = []
return public.returnJson(True, 'OK', data)
os.system('mkdir -p ' + path)
os.system('chmod 755 ' + path)
os.system('chown www:www ' + path)
siteName = public.M('sites').where(
'id=?', (get.id,)).getField('name')
public.writeLog(
'网站管理', '站点[' + siteName + '],根目录[' + path + ']不存在,已重新创建!')
dirnames = []
for filename in os.listdir(path):
try:
filePath = path + '/' + filename
if os.path.islink(filePath):
continue
if os.path.isdir(filePath):
dirnames.append(filename)
except:
pass
data = {}
data['dirs'] = dirnames
data['binding'] = public.M('binding').where('pid=?', (mid,)).field(
'id,pid,domain,path,port,addtime').select()
return public.returnJson(True, 'OK', data)
def getDirUserIniApi(self):
mid = request.form.get('id', '').encode('utf-8')
path = public.M('sites').where('id=?', (mid,)).getField('path')
name = public.M('sites').where("id=?", (mid,)).getField('name')
data = {}
data['logs'] = self.getLogsStatus(name)
data['userini'] = False
if os.path.exists(path + '/.user.ini'):
data['userini'] = True
data['runPath'] = self.getSiteRunPath(mid)
data['pass'] = self.getHasPwd(name)
data['path'] = path
return public.returnJson(True, 'OK', data)
def setDirUserIniApi(self):
path = request.form.get('path', '').encode('utf-8')
filename = path + '/.user.ini'
self.delUserInI(path)
if os.path.exists(filename):
public.execShell("which chattr && chattr -i " + filename)
os.remove(filename)
return public.returnJson(True, '已清除防跨站设置!')
public.writeFile(filename, 'open_basedir=' + path + '/:/tmp/:/proc/')
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
if not os.path.exists(vpath):
os.system('mkdir -p ' + vpath)
data = []
for d in os.listdir(vpath):
mpath = vpath + '/' + d + '/info.json'
if not os.path.exists(mpath):
continue
tmp = public.readFile(mpath)
if not tmp:
continue
tmp1 = json.loads(tmp)
data.append(tmp1)
return public.returnJson(True, 'OK', data)
except:
return public.returnJson(True, 'OK', [])
def getSslApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
path = self.sslDir + siteName
csrpath = path + "/fullchain.pem" # 生成证书路径
keypath = path + "/privkey.pem" # 密钥文件路径
key = public.readFile(keypath)
csr = public.readFile(csrpath)
file = self.getHostConf(siteName)
conf = public.readFile(file)
keyText = 'ssl_certificate'
status = True
stype = 0
if(conf.find(keyText) == -1):
status = False
stype = -1
toHttps = self.isToHttps(siteName)
id = public.M('sites').where("name=?", (siteName,)).getField('id')
domains = public.M('domain').where(
"pid=?", (id,)).field('name').select()
data = {'status': status, 'domain': domains, 'key': key,
'csr': csr, 'type': stype, 'httpTohttps': toHttps}
return public.returnJson(True, 'OK', data)
def setSslApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
key = request.form.get('key', '').encode('utf-8')
csr = request.form.get('csr', '').encode('utf-8')
path = self.sslDir + siteName
if not os.path.exists(path):
public.execShell('mkdir -p ' + path)
csrpath = path + "/fullchain.pem" # 生成证书路径
keypath = path + "/privkey.pem" # 密钥文件路径
if(key.find('KEY') == -1):
return public.returnJson(False, '秘钥错误,请检查!')
if(csr.find('CERTIFICATE') == -1):
return public.returnJson(False, '证书错误,请检查!')
public.writeFile('/tmp/cert.pl', csr)
if not public.checkCert('/tmp/cert.pl'):
return public.returnJson(False, '证书错误,请粘贴正确的PEM格式证书!')
public.execShell('\\cp -a ' + keypath + ' /tmp/backup1.conf')
public.execShell('\\cp -a ' + csrpath + ' /tmp/backup2.conf')
# 清理旧的证书链
if os.path.exists(path + '/README'):
public.execShell('rm -rf ' + path)
public.execShell('rm -rf ' + path + '-00*')
public.execShell('rm -rf /etc/letsencrypt/archive/' + siteName)
public.execShell(
'rm -rf /etc/letsencrypt/archive/' + siteName + '-00*')
public.execShell(
'rm -f /etc/letsencrypt/renewal/' + siteName + '.conf')
public.execShell('rm -rf /etc/letsencrypt/renewal/' +
siteName + '-00*.conf')
public.execShell('rm -rf ' + path + '/README')
public.execShell('mkdir -p ' + path)
public.writeFile(keypath, key)
public.writeFile(csrpath, csr)
# 写入配置文件
result = self.setSslConf(siteName)
# print result['msg']
if not result['status']:
return public.getJson(result)
isError = public.checkWebConfig()
if(type(isError) == str):
public.execShell('\\cp -a /tmp/backup1.conf ' + keypath)
public.execShell('\\cp -a /tmp/backup2.conf ' + csrpath)
return public.returnJson(False, 'ERROR:
' + isError.replace("\n", '
') + '')
public.restartWeb()
public.writeLog('网站管理', '证书已保存!')
return public.returnJson(True, '证书已保存!')
def setCertToSiteApi(self):
certName = request.form.get('certName', '').encode('utf-8')
siteName = request.form.get('siteName', '').encode('utf-8')
try:
path = self.sslDir + siteName
if not os.path.exists(path):
return public.returnJson(False, '证书不存在!')
result = self.setSslConf(siteName)
if not result['status']:
return public.getJson(result)
public.restartWeb()
public.writeLog('网站管理', '证书已部署!')
return public.returnJson(True, '证书已部署!')
except Exception as ex:
return public.returnJson(False, '设置错误,' + str(ex))
def removeCertApi(self):
certName = request.form.get('certName', '').encode('utf-8')
try:
path = self.sslDir + certName
if not os.path.exists(path):
return public.returnJson(False, '证书已不存在!')
os.system("rm -rf " + path)
return public.returnJson(True, '证书已删除!')
except:
return public.returnJson(False, '删除失败!')
def closeSslConfApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
file = self.getHostConf(siteName)
conf = public.readFile(file)
if conf:
rep = "\n\s*#HTTP_TO_HTTPS_START(.|\n){1,300}#HTTP_TO_HTTPS_END"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_certificate\s+.+;\s+ssl_certificate_key\s+.+;"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_protocols\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_ciphers\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_prefer_server_ciphers\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_session_cache\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_session_timeout\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_ecdh_curve\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_session_tickets\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_stapling\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+ssl_stapling_verify\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+add_header\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+add_header\s+.+;\n"
conf = re.sub(rep, '', conf)
rep = "\s+ssl\s+on;"
conf = re.sub(rep, '', conf)
rep = "\s+error_page\s497.+;"
conf = re.sub(rep, '', conf)
rep = "\s+if.+server_port.+\n.+\n\s+\s*}"
conf = re.sub(rep, '', conf)
rep = "\s+listen\s+443.*;"
conf = re.sub(rep, '', conf)
public.writeFile(file, conf)
msg = public.getInfo('网站[{1}]关闭SSL成功!', (siteName,))
public.writeLog('网站管理', msg)
public.restartWeb()
return public.returnJson(True, 'SSL已关闭!')
def createLetApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
updateOf = request.form.get('updateOf', '')
domains = request.form.get('domains', '').encode('utf-8')
force = request.form.get('force', '').encode('utf-8')
renew = request.form.get('renew', '').encode('utf-8')
email_args = request.form.get('email', '').encode('utf-8')
domains = json.loads(domains)
email = public.M('users').getField('email')
if email_args.strip() != '':
public.M('users').setField('email', email_args)
email = email_args
if not len(domains):
return public.returnJson(False, '请选择域名')
file = self.getHostConf(siteName)
if os.path.exists(file):
siteConf = public.readFile(file)
if siteConf.find('301-START') != -1:
return public.returnJson(False, '检测到您的站点做了301重定向设置,请先关闭重定向!')
letpath = self.sslDir + siteName
csrpath = letpath + "/fullchain.pem" # 生成证书路径
keypath = letpath + "/privkey.pem" # 密钥文件路径
actionstr = updateOf
siteInfo = public.M('sites').where(
'name=?', (siteName,)).field('id,name,path').find()
path = self.getSitePath(siteName)
srcPath = siteInfo['path']
# 检测acem是否安装
if public.isAppleSystem():
user = public.execShell(
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
acem = '/Users/' + user + '/.acme.sh/acme.sh'
else:
acem = '/root/.acme.sh/acme.sh'
if not os.path.exists(acem):
acem = '/.acme.sh/acme.sh'
if not os.path.exists(acem):
try:
public.execShell("curl -sS curl https://get.acme.sh | sh")
except:
return public.returnJson(False, '尝试自动安装ACME失败,请通过以下命令尝试手动安装
安装命令: curl https://get.acme.sh | sh
' + acem) if not os.path.exists(acem): return public.returnJson(False, '尝试自动安装ACME失败,请通过以下命令尝试手动安装安装命令: curl https://get.acme.sh | sh
' + acem) force_bool = False if force == 'true': force_bool = True if renew == 'true': execStr = acem + " --renew --yes-I-know-dns-manual-mode-enough-go-ahead-please" else: execStr = acem + " --issue --force" # 确定主域名顺序 domainsTmp = [] if siteName in domains: domainsTmp.append(siteName) for domainTmp in domains: if domainTmp == siteName: continue domainsTmp.append(domainTmp) domains = domainsTmp domainCount = 0 for domain in domains: if public.checkIp(domain): continue if domain.find('*.') != -1: return public.returnJson(False, '泛域名不能使用【文件验证】的方式申请证书!') execStr += ' -w ' + path execStr += ' -d ' + domain domainCount += 1 if domainCount == 0: return public.returnJson(False, '请选择域名(不包括IP地址与泛域名)!') home_path = '/root/.acme.sh/' + domains[0] home_cert = home_path + '/fullchain.cer' home_key = home_path + '/' + domains[0] + '.key' if not os.path.exists(home_cert): home_path = '/.acme.sh/' + domains[0] home_cert = home_path + '/fullchain.cer' home_key = home_path + '/' + domains[0] + '.key' if public.isAppleSystem(): user = public.execShell( "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() acem = '/Users/' + user + '/.acme.sh/' if not os.path.exists(home_cert): home_path = acem + domains[0] home_cert = home_path + '/fullchain.cer' home_key = home_path + '/' + domains[0] + '.key' # print home_cert cmd = 'export ACCOUNT_EMAIL=' + email + ' && ' + execStr print cmd result = public.execShell(cmd) if not os.path.exists(home_cert.replace("\*", "*")): data = {} data['err'] = result data['out'] = result[0] data['msg'] = '签发失败,我们无法验证您的域名:1、检查域名是否绑定到对应站点
\2、检查域名是否正确解析到本服务器,或解析还未完全生效
\3、如果您的站点设置了反向代理,或使用了CDN,请先将其关闭
\4、如果您的站点设置了301重定向,请先将其关闭
\5、如果以上检查都确认没有问题,请尝试更换DNS服务商
' data['result'] = {} if result[1].find('new-authz error:') != -1: data['result'] = json.loads( re.search("{.+}", result[1]).group()) if data['result']['status'] == 429: data['msg'] = '签发失败,您尝试申请证书的失败次数已达上限!1、检查域名是否绑定到对应站点
\2、检查域名是否正确解析到本服务器,或解析还未完全生效
\3、如果您的站点设置了反向代理,或使用了CDN,请先将其关闭
\4、如果您的站点设置了301重定向,请先将其关闭
\5、如果以上检查都确认没有问题,请尝试更换DNS服务商
' data['status'] = False return public.getJson(data) if not os.path.exists(letpath): public.execShell("mkdir -p " + letpath) public.execShell("ln -sf \"" + home_cert + "\" \"" + csrpath + '"') public.execShell("ln -sf \"" + home_key + "\" \"" + keypath + '"') public.execShell('echo "let" > "' + letpath + '/README"') if(actionstr == '2'): return public.returnJson(True, '证书已更新!') # 写入配置文件 result = self.setSslConf(siteName) if not result['status']: return public.getJson(result) result['csr'] = public.readFile(csrpath) result['key'] = public.readFile(keypath) public.restartWeb() return public.returnJson(True, 'OK', result) def httpToHttpsApi(self): siteName = request.form.get('siteName', '').encode('utf-8') file = self.getHostConf(siteName) conf = public.readFile(file) if conf: # if conf.find('ssl_certificate') == -1: # return public.returnJson(False, '当前未开启SSL') to = """#error_page 404/404.html; #HTTP_TO_HTTPS_START if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } #HTTP_TO_HTTPS_END""" conf = conf.replace('#error_page 404/404.html;', to) public.writeFile(file, conf) public.restartWeb() return public.returnJson(True, '设置成功!证书也要设置好哟!') def closeToHttpsApi(self): siteName = request.form.get('siteName', '').encode('utf-8') file = self.getHostConf(siteName) conf = public.readFile(file) if conf: rep = "\n\s*#HTTP_TO_HTTPS_START(.|\n){1,300}#HTTP_TO_HTTPS_END" conf = re.sub(rep, '', conf) rep = "\s+if.+server_port.+\n.+\n\s+\s*}" conf = re.sub(rep, '', conf) public.writeFile(file, conf) public.restartWeb() return public.returnJson(True, '关闭HTTPS跳转成功!') def getIndexApi(self): sid = request.form.get('id', '').encode('utf-8') data = {} index = self.getIndex(sid) data['index'] = index return public.getJson(data) def setIndexApi(self): sid = request.form.get('id', '').encode('utf-8') index = request.form.get('index', '').encode('utf-8') return self.setIndex(sid, index) def getLimitNetApi(self): sid = request.form.get('id', '').encode('utf-8') return self.getLimitNet(sid) def saveLimitNetApi(self): sid = request.form.get('id', '').encode('utf-8') perserver = request.form.get('perserver', '').encode('utf-8') perip = request.form.get('perip', '').encode('utf-8') limit_rate = request.form.get('limit_rate', '').encode('utf-8') return self.saveLimitNet(sid, perserver, perip, limit_rate) def closeLimitNetApi(self): sid = request.form.get('id', '').encode('utf-8') return self.closeLimitNet(sid) def getSecurityApi(self): sid = request.form.get('id', '').encode('utf-8') name = request.form.get('name', '').encode('utf-8') return self.getSecurity(sid, name) def setSecurityApi(self): fix = request.form.get('fix', '').encode('utf-8') domains = request.form.get('domains', '').encode('utf-8') status = request.form.get('status', '').encode('utf-8') name = request.form.get('name', '').encode('utf-8') sid = request.form.get('id', '').encode('utf-8') return self.setSecurity(sid, name, fix, domains, status) def getLogsApi(self): siteName = request.form.get('siteName', '').encode('utf-8') return self.getLogs(siteName) def getSitePhpVersionApi(self): siteName = request.form.get('siteName', '').encode('utf-8') return self.getSitePhpVersion(siteName) def getHostConfApi(self): siteName = request.form.get('siteName', '').encode('utf-8') host = self.getHostConf(siteName) return public.getJson({'host': host}) def getRewriteConfApi(self): siteName = request.form.get('siteName', '').encode('utf-8') rewrite = self.getRewriteConf(siteName) return public.getJson({'rewrite': rewrite}) def getRewriteTplApi(self): tplname = request.form.get('tplname', '').encode('utf-8') file = public.getRunDir() + '/rewrite/nginx/' + tplname + '.conf' if not os.path.exists(file): return public.returnJson(False, '模版不存在!') return public.returnJson(True, 'OK', file) def getRewriteListApi(self): rlist = self.getRewriteList() return public.getJson(rlist) def getRootDirApi(self): data = {} data['dir'] = public.getWwwDir() return public.getJson(data) def setEndDateApi(self): sid = request.form.get('id', '').encode('utf-8') edate = request.form.get('edate', '').encode('utf-8') return self.setEndDate(sid, edate) def addApi(self): webname = request.form.get('webinfo', '').encode('utf-8') ps = request.form.get('ps', '').encode('utf-8') path = request.form.get('path', '').encode('utf-8') version = request.form.get('version', '').encode('utf-8') port = request.form.get('port', '').encode('utf-8') return self.add(webname, port, ps, path, version) def addDomainApi(self): isError = public.checkWebConfig() if isError != True: return public.returnJson(False, 'ERROR: 检测到配置文件有错误,请先排除后再操作