网站统计 x16

pull/139/head
midoks 3 years ago
parent 9535a6e9c3
commit 10af462e64
  1. 55
      class/core/crontab_api.py
  2. 4
      class/core/db.py

@ -202,14 +202,30 @@ class crontab_api:
'urladdress': urladdress,
}
addData = self.add(params)
if addData > 0:
return mw.returnJson(True, '添加成功')
return mw.returnJson(False, '添加失败')
def add(self, params):
iname = params["name"]
field_type = params["field_type"]
week = params["week"]
where1 = params["where1"]
hour = params["hour"]
minute = params["minute"]
save = params["save"]
backup_to = params["backup_to"]
stype = params["stype"]
sname = params["sname"]
sbody = params["sbody"]
urladdress = params["urladdress"]
# print params
cronConfig, get, name = self.getCrondCycle(params)
cronPath = mw.getServerDir() + '/cron'
cronName = self.getShell(params)
# print cronConfig, _params, name
# print 'vv', cronPath, cronName
# print 'stype', stype
if type(cronName) == dict:
return cronName
@ -223,12 +239,10 @@ class crontab_api:
return wRes
self.crondReload()
addData = mw.M('crontab').add('name,type,where1,where_hour,where_minute,echo,addtime,status,save,backup_to,stype,sname,sbody,urladdress', (iname, field_type, where1, hour, minute, cronName, time.strftime(
'%Y-%m-%d %X', time.localtime()), 1, save, backup_to, stype, sname, sbody, urladdress))
if addData > 0:
return mw.returnJson(True, '添加成功')
return mw.returnJson(False, '添加失败')
cron_add_time = time.strftime('%Y-%m-%d %X', time.localtime())
task_id = mw.M('crontab').add('name,type,where1,where_hour,where_minute,echo,addtime,status,save,backup_to,stype,sname,sbody,urladdress',
(iname, field_type, where1, hour, minute, cron_add_time, 1, save, backup_to, stype, sname, sbody, urladdress))
return task_id
def startTaskApi(self):
sid = request.form.get('id', '')
@ -393,16 +407,18 @@ class crontab_api:
head = "#!/bin/bash\nPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin\nexport PATH\n"
log = '.log'
script_dir = mw.getServerDir() + "/mdserver-web/scripts"
wheres = {
'path': head + "python " + mw.getServerDir() + "/mdserver-web/scripts/backup.py path " + param['sname'] + " " + str(param['save']),
'site': head + "python " + mw.getServerDir() + "/mdserver-web/scripts/backup.py site " + param['sname'] + " " + str(param['save']),
'database': head + "python " + mw.getServerDir() + "/mdserver-web/scripts/backup.py database " + param['sname'] + " " + str(param['save']),
'logs': head + "python " + mw.getServerDir() + "/mdserver-web/scripts/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
'rememory': head + "/bin/bash " + mw.getServerDir() + '/mdserver-web/scripts/rememory.sh'
'path': head + "python " + script_dir + "/backup.py path " + param['sname'] + " " + str(param['save']),
'site': head + "python " + script_dir + "/backup.py site " + param['sname'] + " " + str(param['save']),
'database': head + "python " + script_dir + "/backup.py database " + param['sname'] + " " + str(param['save']),
'logs': head + "python " + script_dir + "/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
'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"
cfile = mw.getServerDir() + "/mdserver-web/plugin/" + \
param['backup_to'] + "/" + param['backup_to'] + "_main.py"
if not os.path.exists(cfile):
cfile = mw.getServerDir() + "/mdserver-web/script/backup_" + \
param['backup_to'] + ".py"
@ -410,8 +426,8 @@ class crontab_api:
'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 " + mw.getServerDir() + "/mdserver-web/scripts/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
'rememory': head + "/bin/bash " + mw.getServerDir() + '/mdserver-web/scripts/rememory.sh'
'logs': head + "python " + script_dir + "/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
'rememory': head + "/bin/bash " + script_dir + '/rememory.sh'
}
try:
shell = wheres[stype]
@ -431,6 +447,7 @@ echo "--------------------------------------------------------------------------
cronPath = mw.getServerDir() + '/cron'
if not os.path.exists(cronPath):
mw.execShell('mkdir -p ' + cronPath)
if not 'echo' in param:
cronName = mw.md5(mw.md5(str(time.time()) + '_mw'))
else:

@ -197,10 +197,10 @@ class Sql():
sql = "INSERT INTO " + self.__DB_TABLE + \
"(" + keys + ") " + "VALUES(" + values + ")"
result = self.__DB_CONN.execute(sql, param)
id = result.lastrowid
last_id = result.lastrowid
self.__close()
self.__DB_CONN.commit()
return id
return last_id
except Exception as ex:
return "error: " + str(ex)

Loading…
Cancel
Save