mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 04:59:25 +08:00
增加插件[备份]功能。
1. json: "hook":["backup"] -- 备份钩子开启 2.crontab的执行周期添加优化。
This commit is contained in:
+2
-3
@@ -141,15 +141,14 @@ data/ssl.pl
|
||||
data/edate.pl
|
||||
data/osname.pl
|
||||
data/system.db-journal
|
||||
data/hook_*.json
|
||||
|
||||
plugins/l2tp
|
||||
plugins/openlitespeed
|
||||
plugins/gdrive
|
||||
plugins/mtproxy
|
||||
plugins/zimg
|
||||
plugins/bk_demo
|
||||
debug.out
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+18
-11
@@ -295,9 +295,18 @@ class crontab_api:
|
||||
# 取数据列表
|
||||
def getDataListApi(self):
|
||||
stype = request.form.get('type', '')
|
||||
|
||||
bak_data = []
|
||||
|
||||
if stype == 'sites' or stype == 'databases':
|
||||
hookPath = mw.getPanelDataDir() + "/hook_backup.json"
|
||||
if os.path.exists(hookPath):
|
||||
t = mw.readFile(hookPath)
|
||||
bak_data = json.loads(t)
|
||||
|
||||
if stype == 'databases':
|
||||
db_list = {}
|
||||
db_list['orderOpt'] = []
|
||||
db_list['orderOpt'] = bak_data
|
||||
path = mw.getServerDir() + '/mysql'
|
||||
if not os.path.exists(path + '/mysql.db'):
|
||||
db_list['data'] = []
|
||||
@@ -307,8 +316,9 @@ class crontab_api:
|
||||
return mw.getJson(db_list)
|
||||
|
||||
data = {}
|
||||
data['orderOpt'] = bak_data
|
||||
|
||||
data['data'] = mw.M(stype).field('name,ps').select()
|
||||
data['orderOpt'] = []
|
||||
return mw.getJson(data)
|
||||
##### ----- start ----- ###
|
||||
|
||||
@@ -411,16 +421,13 @@ class crontab_api:
|
||||
'rememory': head + "/bin/bash " + script_dir + '/rememory.sh'
|
||||
}
|
||||
if param['backup_to'] != 'localhost':
|
||||
cfile = mw.getServerDir() + "/mdserver-web/plugin/" + \
|
||||
param['backup_to'] + "/" + param['backup_to'] + "_main.py"
|
||||
if not os.path.exists(cfile):
|
||||
cfile = script_dir + "/backup_" + \
|
||||
param['backup_to'] + ".py"
|
||||
cfile = mw.getPluginDir() + "/" + \
|
||||
param['backup_to'] + "/index.py"
|
||||
wheres = {
|
||||
'path': head + "python " + cfile + " path " + param['sname'] + " " + str(param['save']),
|
||||
'site': head + "python " + cfile + " site " + param['sname'] + " " + str(param['save']),
|
||||
'database': head + "python " + cfile + " database " + param['sname'] + " " + str(param['save']),
|
||||
'logs': head + "python " + script_dir + "/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
|
||||
'path': head + "python3 " + cfile + " path " + param['sname'] + " " + str(param['save']),
|
||||
'site': head + "python3 " + cfile + " site " + param['sname'] + " " + str(param['save']),
|
||||
'database': head + "python3 " + cfile + " database " + param['sname'] + " " + str(param['save']),
|
||||
'logs': head + "python3 " + script_dir + "/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
|
||||
'rememory': head + "/bin/bash " + script_dir + '/rememory.sh'
|
||||
}
|
||||
try:
|
||||
|
||||
+12
-8
@@ -57,10 +57,22 @@ def getPluginDir():
|
||||
return getRunDir() + '/plugins'
|
||||
|
||||
|
||||
def getPanelDataDir():
|
||||
return getRunDir() + '/data'
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return getRootDir() + '/server'
|
||||
|
||||
|
||||
def getLogsDir():
|
||||
return getRootDir() + '/wwwlogs'
|
||||
|
||||
|
||||
def getBackupDir():
|
||||
return getRootDir() + '/backup'
|
||||
|
||||
|
||||
def getWwwDir():
|
||||
file = getRunDir() + '/data/site.pl'
|
||||
if os.path.exists(file):
|
||||
@@ -73,14 +85,6 @@ def setWwwDir(wdir):
|
||||
return writeFile(file, wdir)
|
||||
|
||||
|
||||
def getLogsDir():
|
||||
return getRootDir() + '/wwwlogs'
|
||||
|
||||
|
||||
def getBackupDir():
|
||||
return getRootDir() + '/backup'
|
||||
|
||||
|
||||
def setBackupDir(bdir):
|
||||
file = getRunDir() + '/data/backup.pl'
|
||||
return writeFile(file, bdir)
|
||||
|
||||
@@ -114,6 +114,7 @@ class plugins_api:
|
||||
return mw.returnJson(False, '配置文件不存在!', ())
|
||||
|
||||
pluginInfo = json.loads(mw.readFile(infoJsonPos))
|
||||
self.hookInstall(pluginInfo)
|
||||
|
||||
execstr = "cd " + os.getcwd() + "/plugins/" + \
|
||||
name + " && /bin/bash " + pluginInfo["shell"] \
|
||||
@@ -131,6 +132,55 @@ class plugins_api:
|
||||
mw.triggerTask()
|
||||
return mw.returnJson(True, '已将安装任务添加到队列!')
|
||||
|
||||
def hookInstallFile(self, hook_name, info):
|
||||
hookPath = mw.getPanelDataDir() + "/hook_" + hook_name + ".json"
|
||||
data = []
|
||||
if os.path.exists(hookPath):
|
||||
t = mw.readFile(hookPath)
|
||||
data = json.loads(t)
|
||||
|
||||
isNeedAdd = True
|
||||
for x in range(len(data)):
|
||||
if data[x]['title'] == info['title'] and data[x]['name'] == info['name']:
|
||||
isNeedAdd = False
|
||||
|
||||
if isNeedAdd:
|
||||
tmp = {}
|
||||
tmp['title'] = info['title']
|
||||
tmp['name'] = info['name']
|
||||
data.append(tmp)
|
||||
mw.writeFile(hookPath, json.dumps(data))
|
||||
|
||||
def hookUninstallFile(self, hook_name, info):
|
||||
hookPath = mw.getPanelDataDir() + "/hook_" + hook_name + ".json"
|
||||
data = []
|
||||
if os.path.exists(hookPath):
|
||||
t = mw.readFile(hookPath)
|
||||
data = json.loads(t)
|
||||
|
||||
for idx in range(len(data)):
|
||||
if data[idx]['title'] == info['title'] and data[idx]['name'] == info['name']:
|
||||
data.remove(data[idx])
|
||||
mw.writeFile(hookPath, json.dumps(data))
|
||||
|
||||
def hookInstall(self, info):
|
||||
if 'hook' in info:
|
||||
hooks = info['hook']
|
||||
for x in hooks:
|
||||
if x in ['backup']:
|
||||
self.hookInstallFile(x, info)
|
||||
return True
|
||||
return False
|
||||
|
||||
def hookUninstall(self, info):
|
||||
if 'hook' in info:
|
||||
hooks = info['hook']
|
||||
for x in hooks:
|
||||
if x in ['backup']:
|
||||
self.hookUninstallFile(x, info)
|
||||
return True
|
||||
return False
|
||||
|
||||
def uninstallOldApi(self):
|
||||
rundir = mw.getRunDir()
|
||||
name = request.form.get('name', '')
|
||||
@@ -147,7 +197,6 @@ class plugins_api:
|
||||
return mw.returnJson(False, "配置文件不存在!", ())
|
||||
|
||||
pluginInfo = json.loads(mw.readFile(infoJsonPos))
|
||||
|
||||
execstr = "cd " + os.getcwd() + "/plugins/" + \
|
||||
name + " && /bin/bash " + pluginInfo["shell"] \
|
||||
+ " uninstall " + version
|
||||
@@ -175,13 +224,13 @@ class plugins_api:
|
||||
return mw.returnJson(False, "配置文件不存在!", ())
|
||||
|
||||
pluginInfo = json.loads(mw.readFile(infoJsonPos))
|
||||
|
||||
self.hookUninstall(pluginInfo)
|
||||
execstr = "cd " + os.getcwd() + "/plugins/" + \
|
||||
name + " && /bin/bash " + pluginInfo["shell"] \
|
||||
+ " uninstall " + version
|
||||
|
||||
data = mw.execShell(execstr)
|
||||
if mw.isAppleSystem():
|
||||
if mw.isDebugMode():
|
||||
print(execstr)
|
||||
print(data[0], data[1])
|
||||
self.removeIndex(name, version)
|
||||
@@ -793,7 +842,7 @@ class plugins_api:
|
||||
print('getIndexList:', e)
|
||||
|
||||
# 使用gevent模式时,无法使用多进程
|
||||
#plist = self.checkStatusMProcess(plist)
|
||||
# plist = self.checkStatusMProcess(plist)
|
||||
plist = self.checkStatusMThreads(plist)
|
||||
return plist
|
||||
|
||||
|
||||
+16
-11
@@ -203,6 +203,7 @@ function planAdd(){
|
||||
$("#set-Config input[name='type']").val(type);
|
||||
|
||||
var where1 = $("#ptime input[name='where1']").val();
|
||||
|
||||
var is1;
|
||||
var is2 = 1;
|
||||
switch(type){
|
||||
@@ -226,6 +227,7 @@ function planAdd(){
|
||||
return;
|
||||
}
|
||||
|
||||
where1 = $('#excode_week b').attr('val');
|
||||
$("#set-Config input[name='where1']").val(where1);
|
||||
|
||||
var hour = $("#ptime input[name='hour']").val();
|
||||
@@ -305,7 +307,9 @@ function planAdd(){
|
||||
|
||||
$("#set-Config input[name='sName']").val(sName);
|
||||
layer.msg('正在添加,请稍候...!',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
var data= $("#set-Config").serialize() + '&sBody='+sBody + '&urladdress=' + urladdress;
|
||||
var data = $("#set-Config").serialize() + '&sBody='+sBody + '&urladdress=' + urladdress;
|
||||
|
||||
console.log(data);
|
||||
$.post('/crontab/add',data,function(rdata){
|
||||
if(!rdata.status) {
|
||||
layer.msg(rdata.msg,{icon:2, time:2000});
|
||||
@@ -469,9 +473,9 @@ function toBackup(type){
|
||||
sOpt += '<li><a role="menuitem" tabindex="-1" href="javascript:;" value="'+rdata.data[i].name+'">'+rdata.data[i].name+'['+rdata.data[i].ps+']</a></li>';
|
||||
}
|
||||
|
||||
var orderOpt = ''
|
||||
var orderOpt = '';
|
||||
for (var i=0;i<rdata.orderOpt.length;i++){
|
||||
orderOpt += '<li><a role="menuitem" tabindex="-1" href="javascript:;" value="'+rdata.orderOpt[i].value+'">'+rdata.orderOpt[i].name+'</a></li>'
|
||||
orderOpt += '<li><a role="menuitem" tabindex="-1" href="javascript:;" value="'+rdata.orderOpt[i].name+'">'+rdata.orderOpt[i].title+'</a></li>'
|
||||
}
|
||||
|
||||
|
||||
@@ -514,7 +518,7 @@ function editTaskInfo(id){
|
||||
layer.msg('正在获取,请稍候...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
$.post('/crontab/get_crond_find',{id:id},function(rdata){
|
||||
layer.closeAll();
|
||||
// console.log('init:', rdata);
|
||||
// console.log('get_crond_find:', rdata);
|
||||
var sTypeName = '',sTypeDom = '',cycleName = '',cycleDom = '',weekName = '',weekDom = '',sNameName ='',sNameDom = '',backupsName = '',backupsDom ='';
|
||||
obj = {
|
||||
from:{
|
||||
@@ -557,10 +561,11 @@ function editTaskInfo(id){
|
||||
|
||||
if(obj.from.stype == 'site' || obj.from.stype == 'database' || obj.from.stype == 'path' || obj.from.stype == 'logs'){
|
||||
$.post('/crontab/get_data_list',{type:obj.from.stype == 'databases'?'database':'sites'},function(rdata){
|
||||
// console.log(rdata);
|
||||
obj.sNameArray = rdata.data;
|
||||
obj.sNameArray.unshift({name:'ALL',ps:'所有'});
|
||||
obj.backupsArray = rdata.orderOpt;
|
||||
obj.backupsArray.unshift({name:'服务器磁盘',value:'localhost'});
|
||||
obj.backupsArray.unshift({title:'服务器磁盘',name:'localhost'});
|
||||
for(var i = 0; i <obj['sNameArray'].length; i++){
|
||||
if(obj.from['sname'] == obj['sNameArray'][i]['name']){
|
||||
sNameName = obj['sNameArray'][i]['ps'];
|
||||
@@ -568,10 +573,10 @@ function editTaskInfo(id){
|
||||
sNameDom += '<li><a role="menuitem" href="javascript:;" value="'+ obj['sNameArray'][i]['name'] +'">'+ obj['sNameArray'][i]['ps'] +'</a></li>';
|
||||
}
|
||||
for(var i = 0; i <obj['backupsArray'].length; i++){
|
||||
if(obj.from['backup_to'] == obj['backupsArray'][i]['value']) {
|
||||
backupsName = obj['backupsArray'][i]['name'];
|
||||
if(obj.from['backup_to'] == obj['backupsArray'][i]['name']) {
|
||||
backupsName = obj['backupsArray'][i]['title'];
|
||||
}
|
||||
backupsDom += '<li><a role="menuitem" href="javascript:;" value="'+ obj['backupsArray'][i]['value'] +'">'+ obj['backupsArray'][i]['name'] +'</a></li>';
|
||||
backupsDom += '<li><a role="menuitem" href="javascript:;" value="'+ obj['backupsArray'][i]['name'] +'">'+ obj['backupsArray'][i]['title'] +'</a></li>';
|
||||
}
|
||||
callback();
|
||||
},'json');
|
||||
@@ -629,7 +634,7 @@ function editTaskInfo(id){
|
||||
<span class="typename controls c4 pull-left f14 text-right mr20">'+ sTypeName +'</span>\
|
||||
<div style="line-height:34px"><div class="dropdown pull-left mr20 sName_btn" style="display:'+ (obj.from.sType != "path"?'block;':'none') +'">\
|
||||
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" style="width:auto" disabled="disabled">\
|
||||
<b id="sName" val="'+ obj.from.sname +'">'+ sNameName +'</b>\
|
||||
<b id="sName" val="'+ obj.from.sname +'">'+ obj.from.sname +'</b>\
|
||||
<span class="caret"></span>\
|
||||
</button>\
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="sName">'+ sNameDom +'</ul>\
|
||||
@@ -835,10 +840,10 @@ function closeOpt(){
|
||||
//星期
|
||||
function toWeek(){
|
||||
var mBody = '<div class="dropdown planweek pull-left mr20">\
|
||||
<button class="btn btn-default dropdown-toggle" type="button" id="excode" data-toggle="dropdown">\
|
||||
<button class="btn btn-default dropdown-toggle" type="button" id="excode_week" data-toggle="dropdown">\
|
||||
<b val="1">周一</b> <span class="caret"></span>\
|
||||
</button>\
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="excode">\
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="excode_week">\
|
||||
<li><a role="menuitem" tabindex="-1" href="javascript:;" value="1">周一</a></li>\
|
||||
<li><a role="menuitem" tabindex="-1" href="javascript:;" value="2">周二</a></li>\
|
||||
<li><a role="menuitem" tabindex="-1" href="javascript:;" value="3">周三</a></li>\
|
||||
|
||||
Reference in New Issue
Block a user