def modify_heartbeat_conf(self, get): heartbeat = self.get_heartbeat_conf(get) heartbeat['path'] = get.hpath heartbeat['time'] = int(get.htime) heartbeat['warning'] = get.hwarning public.writeFile(self.__heartbeat, json.dumps(heartbeat)) id = public.M('crontab').where('name=?', (u'负载均衡节点心跳检测任务', )).getField('id') import crontab if id: crontab.crontab().DelCrontab({'id': id}) data = {} data['name'] = '负载均衡节点心跳检测任务' data['type'] = 'minute-n' data['where1'] = get.htime data[ 'sBody'] = 'python /www/server/panel/plugin/load_leveling/load_leveling_main.py' data['backupTo'] = 'localhost' data['sType'] = 'toShell' data['hour'] = '' data['minute'] = '' data['week'] = '' data['sName'] = '' data['urladdress'] = '' data['save'] = '' crontab.crontab().AddCrontab(data) public.WriteLog('负载均衡', '修改心跳包检测配置') return public.returnMsg(True, '设置成功!')
def set_crond(self): try: echo = public.md5(public.md5('renew_lets_ssl_bt')) cron_id = public.M('crontab').where('echo=?', (echo, )).getField('id') import crontab args_obj = public.dict_obj() if not cron_id: cronPath = public.GetConfigValue( 'setup_path') + '/cron/' + echo shell = 'python %s/panel/class/panelLets.py renew_lets_ssl ' % ( self.setupPath) public.writeFile(cronPath, shell) args_obj.id = public.M('crontab').add( 'name,type,where1,where_hour,where_minute,echo,addtime,status,save,backupTo,sType,sName,sBody,urladdress', ("续签Let's Encrypt证书", 'day', '', '0', '10', echo, time.strftime('%Y-%m-%d %X', time.localtime()), 0, '', 'localhost', 'toShell', '', shell, '')) crontab.crontab().set_cron_status(args_obj) else: cron_path = public.get_cron_path() if os.path.exists(cron_path): cron_s = public.readFile(cron_path) if cron_s.find(echo) == -1: public.M('crontab').where('echo=?', (echo, )).setField( 'status', 0) args_obj.id = cron_id crontab.crontab().set_cron_status(args_obj) except: pass
def uninstall(): # 备份数据库文件至目录 ${setup_path}/panel/data/plugin_encryption365_backup.db # 防止证书数据丢失, 待下次安装/升级插件时自动导入旧的数据库文件 public.ExecShell('cp -f /www/server/panel/plugin/encryption365/databases/main.db /www/server/panel/data/plugin_encryption365_backup.db') print('已完成数据库备份') # 调用Baota API删除已创建的CronTab db = get_baota_database().cursor() c = db.execute('select `id` from crontab where `echo` = "5eeb48072b7a0fc713483bd5ade1d59d"') cron_id = c.fetchall()[0][0] gets = public.dict_obj() gets.id = cron_id crontab().DelCrontab(gets) print('已删除 Encryption365 定时任务')
def __create_crond(self, sclient, get={}): name = '%s_%s' % (sclient['ip'], sclient['name']) cron_info = public.M('crontab').where( "name=?", ('R' + name, )).field('id').find() if cron_info: get['id'] = cron_info['id'] self.__delCronExec(get) cron_info = public.M('crontab').where( "name=?", ('定时数据同步任务【' + sclient['name'] + '】', )).field('id').find() if cron_info: get['id'] = cron_info['id'] self.__delCronExec(get) if sclient['realtime']: return True sdate = '`date +\"%Y-%m-%d %H:%M:%S\"`' self.__get_send_cmd(sclient) cmd = ''' rname="%s" plugin_path="%s" logs_file=$plugin_path/sclient/${rname}_exec.log echo "★【%s】 STSRT" >> $logs_file echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" >> $logs_file bash $plugin_path/sclient/${rname}_cmd >> $logs_file 2>&1 echo "【%s】 END★" >> $logs_file echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" >> $logs_file ''' % (sclient['name'], self.rsyn_path, sdate, sdate) data = {} data['backupTo'] = 'localhost' data['sType'] = 'toShell' data['week'] = '' data['sName'] = '' data['urladdress'] = '' data['save'] = '' data['name'] = '定时数据同步任务【' + sclient['name'] + '】' data['type'] = sclient['cron']['type'] data['where1'] = sclient['cron']['where1'] data['sBody'] = cmd data['hour'] = sclient['cron']['hour'] data['minute'] = sclient['cron']['minute'] crontab.crontab().AddCrontab(data) return True
def SaveFileBody(self, get): if sys.version_info[0] == 2: get.path = get.path.encode('utf-8') if not os.path.exists(get.path): if get.path.find('.htaccess') == -1: return public.returnMsg(False, 'FILE_NOT_EXISTS') try: isConf = -1 if os.path.exists('/etc/init.d/nginx') or os.path.exists( '/etc/init.d/httpd'): isConf = get.path.find('nginx') if isConf == -1: isConf = get.path.find('apache') if isConf == -1: isConf = get.path.find('rewrite') if isConf != -1: os.system('\\cp -a ' + get.path + ' /tmp/backup.conf') data = get.data userini = False if get.path.find('.user.ini') != -1: userini = True public.ExecShell('chattr -i ' + get.path) if get.path.find('/www/server/cron') != -1: try: import crontab data = crontab.crontab().CheckScript(data) except: pass if get.encoding == 'ascii': get.encoding = 'utf-8' if sys.version_info[0] == 2: data = data.encode(get.encoding, errors='ignore') fp = open(get.path, 'w+') else: data = data.encode(get.encoding, errors='ignore').decode(get.encoding) fp = open(get.path, 'w+', encoding=get.encoding) fp.write(data) fp.close() if isConf != -1: isError = public.checkWebConfig() if isError != True: os.system('\\cp -a /tmp/backup.conf ' + get.path) return public.returnMsg( False, 'ERROR:<br><font style="color:red;">' + isError.replace("\n", '<br>') + '</font>') public.serviceReload() if userini: public.ExecShell('chattr +i ' + get.path) public.WriteLog('TYPE_FILE', 'FILE_SAVE_SUCCESS', (get.path, )) return public.returnMsg(True, 'FILE_SAVE_SUCCESS') except Exception as ex: return public.returnMsg(False, 'FILE_SAVE_ERR' + str(ex))
def crontab(pdata = None): comReturn = comm.local() if comReturn: return comReturn if request.method == method_get[0] and not pdata: data = {} data['lan'] = public.GetLan('crontab') return render_template( 'crontab.html',data=data) import crontab crontabObject = crontab.crontab() defs = ('GetCrontab','AddCrontab','GetDataList','GetLogs','DelLogs','DelCrontab','StartTask','set_cron_status','get_crond_find','modify_crond') return publicObject(crontabObject,defs,None,pdata);
def __auto_sync_cnlist(self): id = public.M('crontab').where('name=?', (u'宝塔网站防火墙自动同步中国IP库', )).getField('id') import crontab if id: crontab.crontab().DelCrontab({'id': id}) data = {} data['name'] = u'宝塔网站防火墙自动同步中国IP库' data['type'] = 'day' data['where1'] = '' data['sBody'] = 'python /www/server/panel/plugin/btwaf/btwaf_main.py' data['backupTo'] = 'localhost' data['sType'] = 'toShell' data['hour'] = '5' data['minute'] = '30' data['week'] = '' data['sName'] = '' data['urladdress'] = '' data['save'] = '' crontab.crontab().AddCrontab(data) return public.returnMsg(True, '设置成功!')
def POST(self): get = web.input() import crontab crontabObject = crontab.crontab() defs = ('GetCrontab','AddCrontab','GetDataList','GetLogs','DelLogs','DelCrontab','StartTask') for key in defs: if key == get.action: fun = 'crontabObject.'+key+'(get)' return public.getJson(eval(fun)) return public.returnJson(False,'Invalid specified parameter!')
def install(): print("开始执行安装流程") if not os.path.exists(__plugin_path): os.makedirs(__plugin_path) copyfile(__plugin_path + "/icon.png", panelPath + "/BTPanel/static/img/soft_ico/ico-encryption365.png") print("检查并恢复备份的数据库文件...") backup_file = panelPath + '/data/plugin_encryption365_backup.db' new_database_file = panelPath + '/plugin/encryption365/databases/main.db' if os.path.isfile(backup_file) and not os.path.isfile(new_database_file): print("正在恢复备份的数据库文件...") copyfile(backup_file, new_database_file) os.remove(backup_file) # 增加Crone任务 PyEnv = get_python_env() print("PyEnv: ", get_python_env()) gets = public.dict_obj() gets.name = "Encryption365™ 证书自动化" gets.type = "minute-n" gets.where1 = "1" gets.hour = "" gets.minute = "" gets.week = "" gets.sName = "" gets.save = "" gets.sType = "toShell" gets.sBody = PyEnv + " " + __plugin_path + "/src/AutoRenew.py" gets.backupTo = "localhost" gets.urladdress = "undefined" gets.save_local = "undefined" gets.notice = "undefined" gets.notice_channel = "undefined" cronres = crontab().AddCrontab(gets) gets.notice = "0" gets.notice_channel = "" gets.save_local = "0" gets.urladdress = "" gets.id = cronres['id'] crontab().modify_crond(gets) print("安装完成咯!")
def SaveFileBody(self,get): get.path = get.path.encode('utf-8'); if not os.path.exists(get.path): if get.path.find('.htaccess') == -1: return public.returnMsg(False,'FILE_NOT_EXISTS') try: isConf = -1 if os.path.exists('/etc/init.d/nginx') or os.path.exists('/etc/init.d/httpd'): isConf = get.path.find('nginx'); if isConf == -1: isConf = get.path.find('apache'); if isConf == -1: isConf = get.path.find('rewrite'); if isConf != -1: os.system('\\cp -a '+get.path+' /tmp/backup.conf'); data = get.data[0]; userini = False; if get.path.find('.user.ini') != -1: userini = True; public.ExecShell('chattr -i ' + get.path); if get.path.find('/www/server/cron') != -1: try: import crontab data = crontab.crontab().CheckScript(data); except: pass if get.encoding == 'ascii':get.encoding = 'utf-8'; public.writeFile(get.path,data.encode(get.encoding)); if isConf != -1: isError = public.checkWebConfig(); if isError != True: os.system('\\cp -a /tmp/backup.conf '+get.path); return public.returnMsg(False,'ERROR:<br><font style="color:red;">'+isError.replace("\n",'<br>')+'</font>'); public.serviceReload(); if userini: public.ExecShell('chattr +i ' + get.path); public.WriteLog('TYPE_FILE','FILE_SAVE_SUCCESS',(get.path,)); return public.returnMsg(True,'FILE_SAVE_SUCCESS'); except: return public.returnMsg(False,'FILE_SAVE_ERR');
def __init__(self): # self.__conf = config() self.__cron = crontab() QtGui.QDialog.__init__(self) self.setupUi(self) self.messages = {} #aliases self.__uname = self.lineEdit self.__pass = self.lineEdit_2 self.__network = self.lineEdit_3 self.__updateCheck = self.checkBox self.__delay = self.spinBox self.__createLink = self.label_6 #Events QtCore.QObject.connect(self.__updateCheck, QtCore.SIGNAL("stateChanged (int)"), self.__onUpdateChange) QtCore.QObject.connect(self.__delay, QtCore.SIGNAL("valueChanged (int)"), self.__onDelayChange) QtCore.QObject.connect(self.__createLink, QtCore.SIGNAL("linkActivated(QString)"), self.__openURL)
def SaveFileBody(self,get): get.path = get.path.encode('utf-8'); if not os.path.exists(get.path): if get.path.find('.htaccess') == -1: return public.returnMsg(False,'FILE_NOT_EXISTS') try: isConf = -1 if os.path.exists('/etc/init.d/nginx') or os.path.exists('/etc/init.d/httpd'): isConf = get.path.find('nginx'); if isConf == -1: isConf = get.path.find('apache'); if isConf == -1: isConf = get.path.find('rewrite'); if isConf != -1: os.system('\\cp -a '+get.path+' /tmp/backup.conf'); data = get.data[0]; if get.path.find('/www/server/cron') != -1: try: import crontab data = crontab.crontab().CheckScript(data); except: pass if get.encoding == 'ascii':get.encoding = 'utf-8'; public.writeFile(get.path,data.encode(get.encoding)); if isConf != -1: isError = public.checkWebConfig(); if isError != True: os.system('\\cp -a /tmp/backup.conf '+get.path); return public.returnMsg(False,'ERROR:<br><font style="color:red;">'+isError.replace("\n",'<br>')+'</font>'); public.serviceReload(); public.WriteLog('TYPE_FILE','FILE_SAVE_SUCCESS',(get.path,)); return public.returnMsg(True,'FILE_SAVE_SUCCESS'); except: return public.returnMsg(False,'FILE_SAVE_ERR');
def POST(self): import crontab crontabObject = crontab.crontab() defs = ('GetCrontab', 'AddCrontab', 'GetDataList', 'GetLogs', 'DelLogs', 'DelCrontab', 'StartTask') return publicObject(crontabObject, defs)
def __delCronExec(self, get): crontab.crontab().DelCrontab(get)
def heartbeat_off(self, get): id = public.M('crontab').where('name=?', (u'负载均衡节点心跳检测任务', )).getField('id') import crontab if id: crontab.crontab().DelCrontab({'id': id}) return public.returnMsg(True, '已关闭任务')
from crontab import crontabs, crontab c = crontab() c.setMinute(5) c.setHour("*") c.setDay("*") c.setMonth("*") c.setWeekday("*") c.setUser("root") c.setCommand("echo 'test';") cs = crontabs() cs.addCron(c) cs.addCron(c) print(cs.getFileContent()) #a = ApacheConfig() #a.setDomain("www.byte.gs") #a.setAliases(["test.google.de", "bla.google.de"], True) #a.setServerAdmin("*****@*****.**") #a.setDocumentRoot("/var/www/byte.gs/www", False) #res = a.createVHost() #print(res) #a.setDomain("<script language=");
def POST(self): import crontab crontabObject = crontab.crontab() defs = ('GetCrontab','AddCrontab','GetDataList','GetLogs','DelLogs','DelCrontab','StartTask') return publicObject(crontabObject,defs);
def GET(self): import crontab get = web.input() data = crontab.crontab().GetCrontab(get) return render.crontab(data)