mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
update
This commit is contained in:
@@ -9,12 +9,69 @@ import re
|
||||
import json
|
||||
import pwd
|
||||
|
||||
from flask import request
|
||||
from flask import send_file, send_from_directory
|
||||
from flask import make_response
|
||||
|
||||
class file_api:
|
||||
|
||||
class files_api:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
##### ----- start ----- ###
|
||||
def getBodyApi(self):
|
||||
path = request.form.get('path', '').encode('utf-8')
|
||||
return self.getBody(path)
|
||||
|
||||
def saveBodyApi(self):
|
||||
path = request.form.get('path', '').encode('utf-8')
|
||||
data = request.form.get('data', '').encode('utf-8')
|
||||
encoding = request.form.get('encoding', '').encode('utf-8')
|
||||
return self.saveBody(path, data, encoding)
|
||||
|
||||
def downloadApi(self):
|
||||
filename = request.args.get('filename', '').encode('utf-8')
|
||||
if not os.path.exists(filename):
|
||||
return ''
|
||||
response = make_response(send_from_directory(
|
||||
os.path.dirname(filename), os.path.basename(filename), as_attachment=True))
|
||||
return response
|
||||
|
||||
def zipApi(self):
|
||||
sfile = request.form.get('sfile', '').encode('utf-8')
|
||||
dfile = request.form.get('dfile', '').encode('utf-8')
|
||||
stype = request.form.get('type', '').encode('utf-8')
|
||||
path = request.form.get('path', '').encode('utf-8')
|
||||
return self.zip(sfile, dfile, stype, path)
|
||||
|
||||
def deleteApi(self):
|
||||
path = request.form.get('path', '').encode('utf-8')
|
||||
return self.delete(path)
|
||||
|
||||
def fileAccessApi(self):
|
||||
filename = request.form.get('filename', '').encode('utf-8')
|
||||
data = self.getAccess(filename)
|
||||
return public.getJson(data)
|
||||
|
||||
def getDirSizeApi(self):
|
||||
path = request.form.get('path', '').encode('utf-8')
|
||||
if public.getOs() == 'darwin':
|
||||
tmp = public.execShell('du -sh ' + path)
|
||||
else:
|
||||
tmp = public.execShell('du -sbh ' + path)
|
||||
return public.returnJson(True, tmp[0].split()[0])
|
||||
|
||||
def getDirApi(self):
|
||||
path = request.form.get('path', '').encode('utf-8')
|
||||
if not os.path.exists(path):
|
||||
path = public.getRootDir() + "/wwwroot"
|
||||
search = request.args.get('search', '').strip().lower()
|
||||
page = request.args.get('p', '1').strip().lower()
|
||||
row = request.args.get('showRow', '10')
|
||||
return self.getDir(path, int(page), int(row), search)
|
||||
##### ----- start ----- ###
|
||||
|
||||
def setFileAccept(self, filename):
|
||||
auth = 'www:www'
|
||||
if public.getOs() == 'darwin':
|
||||
@@ -9,12 +9,47 @@ import re
|
||||
import json
|
||||
import pwd
|
||||
|
||||
from flask import request
|
||||
|
||||
|
||||
class firewall_api:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
##### ----- start ----- ###
|
||||
def getWwwPathApi(self):
|
||||
path = public.getLogsDir()
|
||||
return public.getJson({'path': path})
|
||||
|
||||
def getListApi(self):
|
||||
p = request.form.get('p', '1').strip()
|
||||
limit = request.form.get('limit', '10').strip()
|
||||
return self.getList(int(p), int(limit))
|
||||
|
||||
def getLogListApi(self):
|
||||
p = request.form.get('p', '1').strip()
|
||||
limit = request.form.get('limit', '10').strip()
|
||||
search = request.form.get('search', '').strip()
|
||||
return self.getLogList(int(p), int(limit), search)
|
||||
|
||||
def getSshInfo(self):
|
||||
file = '/etc/ssh/sshd_config'
|
||||
conf = public.readFile(file)
|
||||
rep = "#*Port\s+([0-9]+)\s*\n"
|
||||
port = re.search(rep, conf).groups(0)[0]
|
||||
|
||||
data = {}
|
||||
data['port'] = port
|
||||
data['status'] = True
|
||||
data['ping'] = True
|
||||
if public.isAppleSystem():
|
||||
data['firewall_status'] = False
|
||||
else:
|
||||
data['firewall_status'] = True
|
||||
return public.getJson(data)
|
||||
##### ----- start ----- ###
|
||||
|
||||
def getList(self, page, limit):
|
||||
|
||||
start = (page - 1) * limit
|
||||
|
||||
+2
-2
@@ -29,8 +29,8 @@ class Page():
|
||||
__END_NUM = None # 结束行
|
||||
|
||||
def __init__(self):
|
||||
tmp = public.getMsg('PAGE')
|
||||
if tmp:
|
||||
# tmp = public.getMsg('PAGE')
|
||||
if False:
|
||||
self.__PREV = tmp['PREV']
|
||||
self.__NEXT = tmp['NEXT']
|
||||
self.__START = tmp['START']
|
||||
|
||||
@@ -10,6 +10,8 @@ import json
|
||||
import threading
|
||||
import multiprocessing
|
||||
|
||||
from flask import request
|
||||
|
||||
|
||||
class pa_thread(threading.Thread):
|
||||
|
||||
@@ -27,7 +29,7 @@ class pa_thread(threading.Thread):
|
||||
return None
|
||||
|
||||
|
||||
class plugin_api:
|
||||
class plugins_api:
|
||||
__tasks = None
|
||||
__plugin_dir = 'plugins'
|
||||
__type = 'data/json/type.json'
|
||||
@@ -38,6 +40,156 @@ class plugin_api:
|
||||
self.setupPath = 'server'
|
||||
# self.__plugin_dir = public.getRunDir() + '/plugins'
|
||||
|
||||
##### ----- start ----- ###
|
||||
def listApi(self):
|
||||
sType = request.args.get('type', '0')
|
||||
sPage = request.args.get('p', '1')
|
||||
print sPage
|
||||
data = self.getPluginList(sType, int(sPage))
|
||||
return public.getJson(data)
|
||||
|
||||
def fileApi(self):
|
||||
name = request.args.get('name', '')
|
||||
if name.strip() == '':
|
||||
return ''
|
||||
|
||||
f = request.args.get('f', '')
|
||||
if f.strip() == '':
|
||||
return ''
|
||||
|
||||
file = self.__plugin_dir + '/' + name + '/' + f
|
||||
if not os.path.exists(file):
|
||||
return ''
|
||||
|
||||
c = public.readFile(file)
|
||||
return c
|
||||
|
||||
def indexListApi(self):
|
||||
data = self.getIndexList()
|
||||
return public.getJson(data)
|
||||
|
||||
def indexSortApi(self):
|
||||
sort = request.form.get('ssort', '')
|
||||
if sort.strip() == '':
|
||||
return public.returnJson(False, '排序数据不能为空!')
|
||||
data = self.setIndexSort(sort)
|
||||
if data:
|
||||
return public.returnJson(True, '成功!')
|
||||
return public.returnJson(False, '失败!')
|
||||
|
||||
def installApi(self):
|
||||
rundir = public.getRunDir()
|
||||
name = request.form.get('name', '')
|
||||
version = request.form.get('version', '')
|
||||
|
||||
mmsg = '安装'
|
||||
if hasattr(request.form, 'upgrade'):
|
||||
mtype = 'update'
|
||||
mmsg = 'upgrade'
|
||||
|
||||
if name.strip() == '':
|
||||
return public.returnJson(False, '缺少插件名称!', ())
|
||||
|
||||
if version.strip() == '':
|
||||
return public.returnJson(False, '缺少版本信息!', ())
|
||||
|
||||
infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json'
|
||||
|
||||
if not os.path.exists(infoJsonPos):
|
||||
return public.retJson(False, '配置文件不存在!', ())
|
||||
|
||||
pluginInfo = json.loads(public.readFile(infoJsonPos))
|
||||
|
||||
execstr = "cd " + os.getcwd() + "/plugins/" + \
|
||||
name + " && /bin/bash " + pluginInfo["shell"] \
|
||||
+ " install " + version
|
||||
|
||||
taskAdd = (None, mmsg + '[' + name + '-' + version + ']',
|
||||
'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr)
|
||||
|
||||
public.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
|
||||
return public.returnJson(True, '已将安装任务添加到队列!')
|
||||
|
||||
def uninstallApi(self):
|
||||
rundir = public.getRunDir()
|
||||
name = request.form.get('name', '')
|
||||
version = request.form.get('version', '')
|
||||
if name.strip() == '':
|
||||
return public.returnJson(False, "缺少插件名称!", ())
|
||||
|
||||
if version.strip() == '':
|
||||
return public.returnJson(False, "缺少版本信息!", ())
|
||||
|
||||
infoJsonPos = __plugin_name + '/' + name + '/' + 'info.json'
|
||||
|
||||
if not os.path.exists(infoJsonPos):
|
||||
return public.retJson(False, "配置文件不存在!", ())
|
||||
|
||||
pluginInfo = json.loads(public.readFile(infoJsonPos))
|
||||
|
||||
execstr = "cd " + os.getcwd() + "/plugins/" + \
|
||||
name + " && /bin/bash " + pluginInfo["shell"] \
|
||||
+ " uninstall " + version
|
||||
|
||||
taskAdd = (None, '卸载[' + name + '-' + version + ']',
|
||||
'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr)
|
||||
|
||||
public.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
|
||||
return public.returnJson(True, '已将卸载任务添加到队列!')
|
||||
|
||||
def installed(self):
|
||||
rundir = public.getRunDir()
|
||||
name = request.form.get('name', '')
|
||||
|
||||
if name.strip() == '':
|
||||
return public.retJson(-1, "缺少插件名称!", ())
|
||||
|
||||
infoJsonPos = __plugin_name + '/' + name + '/' + 'info.json'
|
||||
if not os.path.exists(infoJsonPos):
|
||||
return public.returnJson(-1, "配置文件不存在!", ())
|
||||
|
||||
pluginInfo = json.loads(public.readFile(infoJsonPos))
|
||||
|
||||
sh = __plugin_name + '/' + name + '/' + pluginInfo['shell']
|
||||
os.system('/bin/bash ' + sh + ' install')
|
||||
print request.args
|
||||
return ''
|
||||
|
||||
def checkInstalled(self):
|
||||
checks = ['nginx', 'apache', 'php', 'mysql']
|
||||
for name in checks:
|
||||
filename = public.getRootDir() + "/server/" + name
|
||||
if os.path.exists(filename):
|
||||
return "True"
|
||||
return "False"
|
||||
|
||||
def setIndexApi(self):
|
||||
name = request.form.get('name', '')
|
||||
status = request.form.get('status', '0')
|
||||
version = request.form.get('version', '')
|
||||
if status == '1':
|
||||
return self.addIndex(name, version)
|
||||
return self.removeIndex(name, version)
|
||||
|
||||
def settingApi(self):
|
||||
name = request.args.get('name', '')
|
||||
html = self.__plugin_dir + '/' + name + '/index.html'
|
||||
return public.readFile(html)
|
||||
|
||||
def runApi(self):
|
||||
name = request.form.get('name', '')
|
||||
func = request.form.get('func', '')
|
||||
version = request.form.get('version', '')
|
||||
args = request.form.get('args', '')
|
||||
script = request.form.get('script', 'index')
|
||||
|
||||
data = self.run(name, func, version, args, script)
|
||||
if data[1] == '':
|
||||
return public.returnJson(True, "OK", data[0].strip())
|
||||
return public.returnJson(False, data[1].strip())
|
||||
|
||||
##### ----- end ----- ###
|
||||
|
||||
# 进程是否存在
|
||||
def processExists(self, pname, exe=None):
|
||||
try:
|
||||
@@ -414,6 +566,7 @@ class plugin_api:
|
||||
return plugins_info
|
||||
|
||||
def getPluginList(self, sType, sPage=1, sPageSize=10):
|
||||
print sType, sPage, sPageSize
|
||||
|
||||
ret = {}
|
||||
ret['type'] = json.loads(public.readFile(self.__type))
|
||||
@@ -170,6 +170,7 @@ def returnData(status, msg, data):
|
||||
|
||||
def retOK(data):
|
||||
return {'status': True, 'msg': 'OK!', 'data': data}
|
||||
return getJson(info)
|
||||
|
||||
|
||||
def retFail(msg, data=None):
|
||||
|
||||
+98
-1
@@ -27,7 +27,104 @@ class site_api:
|
||||
if not os.path.exists(path):
|
||||
public.execShell("mkdir -p " + path + " && chmod -R 755 " + path)
|
||||
|
||||
# 域名编码转换
|
||||
##### ----- start ----- ###
|
||||
def listApi(self):
|
||||
return self.list()
|
||||
|
||||
def getPhpVersionApi(self):
|
||||
return self.getPhpVersion()
|
||||
|
||||
def getDomainApi(self):
|
||||
pid = request.form.get('pid', '').encode('utf-8')
|
||||
return self.getDomain(pid)
|
||||
|
||||
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 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 deleteApi(self):
|
||||
sid = request.form.get('id', '').encode('utf-8')
|
||||
webname = request.form.get('webname', '').encode('utf-8')
|
||||
return self.delete(sid, webname)
|
||||
##### ----- end ----- ###
|
||||
|
||||
# 域名编码转换
|
||||
def toPunycode(self, domain):
|
||||
import re
|
||||
if sys.version_info[0] == 2:
|
||||
|
||||
@@ -8,6 +8,7 @@ import math
|
||||
import json
|
||||
|
||||
from flask import Flask, session
|
||||
from flask import request
|
||||
|
||||
import db
|
||||
import public
|
||||
@@ -25,13 +26,48 @@ class system_api:
|
||||
def networkApi(self):
|
||||
return self.getNetWork()
|
||||
|
||||
# @system.route("/update_server")
|
||||
def updateServerApi(self):
|
||||
stype = request.args.get('type', 'check')
|
||||
version = request.args.get('version', '')
|
||||
data = self.updateServer(stype, version)
|
||||
return self.updateServer(stype, version)
|
||||
|
||||
def systemTotalApi(self):
|
||||
data = self.getSystemTotal()
|
||||
return public.getJson(data)
|
||||
|
||||
def diskInfoApi(self):
|
||||
diskInfo = self.getDiskInfo()
|
||||
return public.getJson(diskInfo)
|
||||
|
||||
def setControlApi(self):
|
||||
stype = request.form.get('type', '')
|
||||
day = request.form.get('day', '')
|
||||
data = self.setControl(stype, day)
|
||||
return data
|
||||
|
||||
def getLoadAverageApi(self):
|
||||
start = request.args.get('start', '')
|
||||
end = request.args.get('end', '')
|
||||
data = self.getLoadAverageData(start, end)
|
||||
return public.getJson(data)
|
||||
|
||||
def getCpuIoApi(self):
|
||||
start = request.args.get('start', '')
|
||||
end = request.args.get('end', '')
|
||||
data = self.getCpuIoData(start, end)
|
||||
return public.getJson(data)
|
||||
|
||||
def getDiskIoApi(self):
|
||||
start = request.args.get('start', '')
|
||||
end = request.args.get('end', '')
|
||||
data = self.getDiskIoData(start, end)
|
||||
return public.getJson(data)
|
||||
|
||||
def getNetworkIoApi(self):
|
||||
start = request.args.get('start', '')
|
||||
end = request.args.get('end', '')
|
||||
data = self.getNetWorkIoData(start, end)
|
||||
return public.getJson(data)
|
||||
##### ----- end ----- ###
|
||||
|
||||
# 名取PID
|
||||
|
||||
Reference in New Issue
Block a user