update
This commit is contained in:
parent
75ece2a5de
commit
f1ef6f6f41
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -14,19 +14,6 @@ from flask import render_template
|
|||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
# from dashboard import *
|
||||
# from site import *
|
||||
# from files import *
|
||||
# from soft import *
|
||||
# from config import *
|
||||
# from plugins import *
|
||||
# from task import *
|
||||
# from system import *
|
||||
# from database import *
|
||||
# from crontab import *
|
||||
# from control import *
|
||||
# from firewall import *
|
||||
|
||||
app = Flask(__name__, template_folder='templates/default')
|
||||
app.config.version = '0.0.1'
|
||||
app.config['SECRET_KEY'] = os.urandom(24)
|
||||
|
|
@ -47,8 +34,8 @@ def publicObject(toObject, func, action=None, get=None):
|
|||
if hasattr(toObject, name):
|
||||
efunc = 'toObject.' + name + '()'
|
||||
data = eval(efunc)
|
||||
return public.getJson(data)
|
||||
return public.retFail('Access Exception!')
|
||||
return data
|
||||
return public.retFail('访问异常!')
|
||||
|
||||
|
||||
@app.route("/check_login", methods=['POST', 'GET'])
|
||||
|
|
@ -65,7 +52,7 @@ def index(reqClass=None, reqAction=None, reqData=None):
|
|||
if (reqClass == None):
|
||||
reqClass = 'index'
|
||||
classFile = ('config', 'control', 'crontab',
|
||||
'files', 'firewall', 'index', 'login', 'system', 'site', 'soft')
|
||||
'files', 'firewall', 'index', 'plugins', 'login', 'system', 'site', 'soft')
|
||||
if not reqClass in classFile:
|
||||
return '403 no access!'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
sys.path.append("/class/core")
|
||||
import public
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
crontab = Blueprint('crontab', __name__, template_folder='templates')
|
||||
|
||||
|
||||
@crontab.route("/")
|
||||
def index():
|
||||
return render_template('default/crontab.html')
|
||||
|
||||
|
||||
@crontab.route("/list", methods=['GET', 'POST'])
|
||||
def list():
|
||||
data = []
|
||||
return public.getJson({})
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
# coding:utf-8
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from flask import Flask
|
||||
from flask import Blueprint, render_template
|
||||
from flask import jsonify
|
||||
from flask import request
|
||||
from flask import send_file, send_from_directory
|
||||
from flask import make_response
|
||||
|
||||
|
||||
sys.path.append("class/core")
|
||||
import public
|
||||
import file_api
|
||||
|
||||
files = Blueprint('files', __name__, template_folder='templates')
|
||||
|
||||
|
||||
@files.route("/")
|
||||
def index():
|
||||
return render_template('default/files.html')
|
||||
|
||||
|
||||
@files.route('/get_body', methods=['POST'])
|
||||
def getBody():
|
||||
path = request.form.get('path', '').encode('utf-8')
|
||||
return file_api.file_api().getBody(path)
|
||||
|
||||
|
||||
@files.route('/save_body', methods=['POST'])
|
||||
def saveBody():
|
||||
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 file_api.file_api().saveBody(path, data, encoding)
|
||||
|
||||
|
||||
@files.route('/download', methods=['GET'])
|
||||
def download():
|
||||
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
|
||||
|
||||
|
||||
@files.route('/zip', methods=['POST'])
|
||||
def zip():
|
||||
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 file_api.file_api().zip(sfile, dfile, stype, path)
|
||||
|
||||
|
||||
@files.route('/delete', methods=['POST'])
|
||||
def delete():
|
||||
path = request.form.get('path', '').encode('utf-8')
|
||||
return file_api.file_api().delete(path)
|
||||
|
||||
|
||||
@files.route('/file_access', methods=['POST'])
|
||||
def fileAccess():
|
||||
filename = request.form.get('filename', '').encode('utf-8')
|
||||
data = file_api.file_api().getAccess(filename)
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@files.route('/get_dir_size', methods=['POST'])
|
||||
def getDirSize():
|
||||
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)
|
||||
# print tmp
|
||||
return public.returnJson(True, tmp[0].split()[0])
|
||||
|
||||
|
||||
@files.route('/get_dir', methods=['POST'])
|
||||
def getDir():
|
||||
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')
|
||||
|
||||
# print path, int(page), int(row), search
|
||||
return file_api.file_api().getDir(path, int(page), int(row), search)
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
from flask import Flask
|
||||
from flask import Blueprint, render_template
|
||||
from flask import request
|
||||
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core/")
|
||||
import db
|
||||
import public
|
||||
import firewall_api
|
||||
|
||||
firewall = Blueprint('firewall', __name__, template_folder='templates')
|
||||
|
||||
|
||||
@firewall.route('/')
|
||||
def index():
|
||||
return render_template('default/firewall.html')
|
||||
|
||||
|
||||
@firewall.route('/get_www_path', methods=['POST'])
|
||||
def getWwwPath():
|
||||
path = public.getLogsDir()
|
||||
return public.getJson({'path': path})
|
||||
|
||||
|
||||
@firewall.route("/get_list", methods=['POST'])
|
||||
def getList():
|
||||
p = request.form.get('p', '1').strip()
|
||||
limit = request.form.get('limit', '10').strip()
|
||||
return firewall_api.firewall_api().getList(int(p), int(limit))
|
||||
|
||||
|
||||
@firewall.route("/get_log_list", methods=['POST'])
|
||||
def getLogList():
|
||||
p = request.form.get('p', '1').strip()
|
||||
limit = request.form.get('limit', '10').strip()
|
||||
search = request.form.get('search', '').strip()
|
||||
return firewall_api.firewall_api().getLogList(int(p), int(limit), search)
|
||||
|
||||
|
||||
@firewall.route('get_ssh_info', methods=['POST'])
|
||||
def getSshInfo():
|
||||
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)
|
||||
190
route/plugins.py
190
route/plugins.py
|
|
@ -1,190 +0,0 @@
|
|||
# coding:utf-8
|
||||
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import psutil
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
from flask import jsonify
|
||||
from flask import request
|
||||
|
||||
sys.path.append("class/core")
|
||||
import public
|
||||
import plugin_api
|
||||
|
||||
|
||||
plugins = Blueprint('plugins', __name__, template_folder='templates')
|
||||
__plugin_name = "plugins"
|
||||
__row_num = 3
|
||||
|
||||
|
||||
@plugins.route('/file', methods=['GET'])
|
||||
def file():
|
||||
name = request.args.get('name', '')
|
||||
if name.strip() == '':
|
||||
return ''
|
||||
|
||||
f = request.args.get('f', '')
|
||||
if f.strip() == '':
|
||||
return ''
|
||||
|
||||
file = __plugin_name + '/' + name + '/' + f
|
||||
if not os.path.exists(file):
|
||||
return ''
|
||||
|
||||
c = public.readFile(file)
|
||||
return c
|
||||
|
||||
|
||||
@plugins.route('/list', methods=['GET'])
|
||||
def list():
|
||||
sType = request.args.get('type', '0')
|
||||
sPage = request.args.get('p', '1')
|
||||
data = plugin_api.plugin_api().getPluginList(sType, int(sPage))
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@plugins.route('/index_list', methods=['GET'])
|
||||
def indexList():
|
||||
data = plugin_api.plugin_api().getIndexList()
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@plugins.route('/index_sort', methods=['POST'])
|
||||
def indexSort():
|
||||
sort = request.form.get('ssort', '')
|
||||
if sort.strip() == '':
|
||||
return public.returnJson(False, '排序数据不能为空!')
|
||||
data = plugin_api.plugin_api().setIndexSort(sort)
|
||||
if data:
|
||||
return public.returnJson(True, '成功!')
|
||||
return public.returnJson(False, '失败!')
|
||||
|
||||
|
||||
@plugins.route('/install', methods=['POST'])
|
||||
def install():
|
||||
|
||||
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 = __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"] \
|
||||
+ " 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, '已将安装任务添加到队列!')
|
||||
|
||||
|
||||
@plugins.route('/uninstall', methods=['POST'])
|
||||
def uninstall():
|
||||
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, '已将卸载任务添加到队列!')
|
||||
|
||||
|
||||
@plugins.route('/find', methods=['POST'])
|
||||
def installed():
|
||||
|
||||
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 ''
|
||||
|
||||
|
||||
@plugins.route('/check_installed', methods=['POST'])
|
||||
def checkInstalled():
|
||||
checks = ['nginx', 'apache', 'php', 'mysql']
|
||||
for name in checks:
|
||||
filename = public.getRootDir() + "/server/" + name
|
||||
if os.path.exists(filename):
|
||||
return "True"
|
||||
return "False"
|
||||
|
||||
|
||||
@plugins.route('/set_index', methods=['POST'])
|
||||
def setIndex():
|
||||
name = request.form.get('name', '')
|
||||
status = request.form.get('status', '0')
|
||||
version = request.form.get('version', '')
|
||||
if status == '1':
|
||||
return plugin_api.plugin_api().addIndex(name, version)
|
||||
return plugin_api.plugin_api().removeIndex(name, version)
|
||||
|
||||
|
||||
@plugins.route('/setting', methods=['GET'])
|
||||
def setting():
|
||||
name = request.args.get('name', '')
|
||||
html = __plugin_name + '/' + name + '/index.html'
|
||||
return public.readFile(html)
|
||||
|
||||
|
||||
@plugins.route('/run', methods=['POST', 'GET'])
|
||||
def run():
|
||||
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 = plugin_api.plugin_api().run(name, func, version, args, script)
|
||||
if data[1] == '':
|
||||
return public.returnJson(True, "OK", data[0].strip())
|
||||
return public.returnJson(False, data[1].strip())
|
||||
154
route/site.py
154
route/site.py
|
|
@ -1,154 +0,0 @@
|
|||
# coding:utf-8
|
||||
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
|
||||
from flask import Flask
|
||||
from flask import Blueprint, render_template
|
||||
from flask import request
|
||||
|
||||
site = Blueprint('site', __name__, template_folder='templates')
|
||||
|
||||
sys.path.append("class/core")
|
||||
import public
|
||||
import site_api
|
||||
|
||||
|
||||
@site.route('/')
|
||||
def index():
|
||||
return render_template('default/site.html')
|
||||
|
||||
|
||||
@site.route('/list', methods=['POST'])
|
||||
def list():
|
||||
return site_api.site_api().list()
|
||||
|
||||
|
||||
@site.route('get_php_version', methods=['POST'])
|
||||
def getPhpVersion():
|
||||
return site_api.site_api().getPhpVersion()
|
||||
|
||||
|
||||
@site.route('get_domain', methods=['POST'])
|
||||
def getDomain():
|
||||
pid = request.form.get('pid', '').encode('utf-8')
|
||||
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_limit_net', methods=['POST'])
|
||||
def getLimitNet():
|
||||
sid = request.form.get('id', '').encode('utf-8')
|
||||
return site_api.site_api().getLimitNet(sid)
|
||||
|
||||
|
||||
@site.route('save_limit_net', methods=['POST'])
|
||||
def saveLimitNet():
|
||||
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 site_api.site_api().saveLimitNet(sid, perserver, perip, limit_rate)
|
||||
|
||||
|
||||
@site.route('close_limit_net', methods=['POST'])
|
||||
def closeLimitNet():
|
||||
sid = request.form.get('id', '').encode('utf-8')
|
||||
return site_api.site_api().closeLimitNet(sid)
|
||||
|
||||
|
||||
@site.route('get_security', methods=['POST'])
|
||||
def getSecurity():
|
||||
sid = request.form.get('id', '').encode('utf-8')
|
||||
name = request.form.get('name', '').encode('utf-8')
|
||||
return site_api.site_api().getSecurity(sid, name)
|
||||
|
||||
|
||||
@site.route('set_security', methods=['POST'])
|
||||
def setSecurity():
|
||||
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 site_api.site_api().setSecurity(sid, name, fix, domains, status)
|
||||
|
||||
|
||||
@site.route('get_logs', methods=['POST'])
|
||||
def getLogs():
|
||||
siteName = request.form.get('siteName', '').encode('utf-8')
|
||||
return site_api.site_api().getLogs(siteName)
|
||||
|
||||
|
||||
@site.route('get_site_php_version', methods=['POST'])
|
||||
def getSitePhpVersion():
|
||||
siteName = request.form.get('siteName', '').encode('utf-8')
|
||||
return site_api.site_api().getSitePhpVersion(siteName)
|
||||
|
||||
|
||||
@site.route('get_host_conf', methods=['POST'])
|
||||
def getHostConf():
|
||||
siteName = request.form.get('siteName', '').encode('utf-8')
|
||||
host = site_api.site_api().getHostConf(siteName)
|
||||
return public.getJson({'host': host})
|
||||
|
||||
|
||||
@site.route('get_rewrite_conf', methods=['POST'])
|
||||
def getRewriteConf():
|
||||
siteName = request.form.get('siteName', '').encode('utf-8')
|
||||
rewrite = site_api.site_api().getRewriteConf(siteName)
|
||||
return public.getJson({'rewrite': rewrite})
|
||||
|
||||
|
||||
@site.route('get_rewrite_list', methods=['POST'])
|
||||
def getRewriteList():
|
||||
rlist = site_api.site_api().getRewriteList()
|
||||
return public.getJson(rlist)
|
||||
|
||||
|
||||
@site.route('get_root_dir', methods=['POST'])
|
||||
def getRootDir():
|
||||
data = {}
|
||||
data['dir'] = public.getWwwDir()
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@site.route('set_end_date', methods=['POST'])
|
||||
def setEndDate():
|
||||
sid = request.form.get('id', '').encode('utf-8')
|
||||
edate = request.form.get('edate', '').encode('utf-8')
|
||||
return site_api.site_api().setEndDate(sid, edate)
|
||||
|
||||
|
||||
@site.route('add', methods=['POST'])
|
||||
def add():
|
||||
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 site_api.site_api().add(webname, port, ps, path, version)
|
||||
|
||||
|
||||
@site.route('delete', methods=['POST'])
|
||||
def delete():
|
||||
sid = request.form.get('id', '').encode('utf-8')
|
||||
webname = request.form.get('webname', '').encode('utf-8')
|
||||
return site_api.site_api().delete(sid, webname)
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
# coding:utf-8
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
soft = Blueprint('soft', __name__, template_folder='templates')
|
||||
|
||||
|
||||
@soft.route("/")
|
||||
def index ():
|
||||
return render_template('default/soft.html')
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
# coding:utf-8
|
||||
|
||||
import time
|
||||
import psutil
|
||||
import os
|
||||
import sys
|
||||
|
||||
from flask import Flask, session
|
||||
from flask import Blueprint, render_template
|
||||
from flask import jsonify
|
||||
from flask import request
|
||||
|
||||
sys.path.append("class/core")
|
||||
import public
|
||||
import system_api
|
||||
|
||||
system = Blueprint('system', __name__, template_folder='templates')
|
||||
|
||||
|
||||
@system.route("/network")
|
||||
def network():
|
||||
data = system_api.system_api().getNetWork()
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@system.route("/update_server")
|
||||
def updateServer():
|
||||
stype = request.args.get('type', 'check')
|
||||
version = request.args.get('version', '')
|
||||
data = system_api.system_api().updateServer(stype, version)
|
||||
return data
|
||||
|
||||
|
||||
@system.route("/system_total")
|
||||
def systemTotal():
|
||||
data = system_api.system_api().getSystemTotal()
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@system.route("/disk_info")
|
||||
def diskInfo():
|
||||
diskInfo = system_api.system_api().getDiskInfo()
|
||||
return public.getJson(diskInfo)
|
||||
|
||||
|
||||
@system.route('/set_control', methods=['POST'])
|
||||
def setControl():
|
||||
stype = request.form.get('type', '')
|
||||
day = request.form.get('day', '')
|
||||
data = system_api.system_api().setControl(stype, day)
|
||||
return data
|
||||
|
||||
|
||||
@system.route('/get_load_average', methods=['GET'])
|
||||
def getLoadAverage():
|
||||
start = request.args.get('start', '')
|
||||
end = request.args.get('end', '')
|
||||
data = system_api.system_api().getLoadAverageData(start, end)
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@system.route('/get_cpu_io', methods=['GET'])
|
||||
def getCpuIo():
|
||||
start = request.args.get('start', '')
|
||||
end = request.args.get('end', '')
|
||||
data = system_api.system_api().getCpuIoData(start, end)
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@system.route('/get_disk_io', methods=['GET'])
|
||||
def getDiskIo():
|
||||
start = request.args.get('start', '')
|
||||
end = request.args.get('end', '')
|
||||
data = system_api.system_api().getDiskIoData(start, end)
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@system.route('/get_network_io', methods=['GET'])
|
||||
def getNetworkIo():
|
||||
start = request.args.get('start', '')
|
||||
end = request.args.get('end', '')
|
||||
data = system_api.system_api().getNetWorkIoData(start, end)
|
||||
return public.getJson(data)
|
||||
Loading…
Reference in New Issue