def upload(self, get): filename = pluginPath + '/temp/import.tar.gz' try: from flask import request file = request.files['import'] if file.filename[-7:] == '.tar.gz' or file.filename[-4:] == '.zip': if file.filename[-4:] == '.zip': filename = pluginPath + '/temp/import.zip' os.system('rm -rf ' + pluginPath + '/temp/import') os.system('mkdir -p ' + pluginPath + '/temp/import') os.system('mkdir -p ' + pluginPath + '/bin') os.system('rm -rf ' + filename) file.save(filename) import panelTask panelTask.bt_task()._unzip(filename, pluginPath + '/temp/import', '', '/dev/null') success, failed = public.ExecShell( 'find %s/temp/import -name frps' % pluginPath) if success.strip() != '': os.system('mv -f %s %s' % (success.strip(), frpsPath)) os.system('chown root:root ' + frpsPath) os.system('chmod +x ' + frpsPath) os.system('rm -rf ' + pluginPath + '/temp/import') os.system('rm -rf ' + filename) if os.path.isfile(frpsPath): return self.check(get) except: pass return public.returnMsg(False, '无效文件或未找到 frps')
def Zip(self,get) : if not 'z_type' in get: get.z_type = 'rar' import panelTask task_obj = panelTask.bt_task() task_obj.create_task('压缩文件',3,get.path,json.dumps({"sfile":get.sfile,"dfile":get.dfile,"z_type":get.z_type})) public.WriteLog("TYPE_FILE", 'ZIP_SUCCESS',(get.sfile,get.dfile)); return public.returnMsg(True,'已将压缩任务添加到消息队列!')
def UnZip(self,get): import panelTask if not 'password' in get:get.password = '' task_obj = panelTask.bt_task() task_obj.create_task('解压文件',2,get.sfile,json.dumps({"dfile":get.dfile,"password":get.password})) public.WriteLog("TYPE_FILE", 'UNZIP_SUCCESS',(get.sfile,get.dfile)); return public.returnMsg(True,'已将解压任务添加到消息队列!')
def UnZip(self,get): import panelTask if not 'password' in get:get.password = '' task_obj = panelTask.bt_task() task_obj.create_task(public.GetMsg("DECOMPRESSION_FILE"),2,get.sfile,json.dumps({"dfile":get.dfile,"password":get.password})) public.WriteLog("TYPE_FILE", 'UNZIP_SUCCESS',(get.sfile,get.dfile)); return public.returnMsg(True,'ADD_DECOMPRESSION_TO_LINEUP')
def Zip(self,get) : if not 'z_type' in get: get.z_type = 'rar' import panelTask task_obj = panelTask.bt_task() task_obj.create_task(public.GetMsg("COMPRESSION_FILE"),3,get.path,json.dumps({"sfile":get.sfile,"dfile":get.dfile,"z_type":get.z_type})) public.WriteLog("TYPE_FILE", 'ZIP_SUCCESS',(get.sfile,get.dfile)); return public.returnMsg(True,'ADD_COMPRESSION_TO_LINEUP')
def Renew_SSL(self, get): if not os.path.isfile("/www/server/panel/vhost/crontab.json"): return {"status": False, "msg": "当前没有可以续订的证书!"} cmd_list = json.loads( public.ReadFile("/www/server/panel/vhost/crontab.json")) import panelTask task = panelTask.bt_task() Renew = True for xt in task.get_task_list(): if xt['status'] != 1: Renew = False if not Renew: return {"status": False, "msg": "当前有续订任务正在执行!"} for j in cmd_list: siteName = j['siteName'] home_path = os.path.join("/www/server/panel/vhost/cert/", siteName) public.ExecShell("mkdir -p {}".format(home_path)) public.ExecShell( '''cd {} && rm -rf check_authorization_status_response Confirmation_verification domain_txt_dns_value.json apply_for_cert_issuance_response timeout_info''' .format(home_path)) cmd = j['cmd'] for x in task.get_task_list(): if x['name'] == siteName: get.id = x['id'] task.remove_task(get) # 删除旧的任务 task.create_task(siteName, 0, cmd) return {"status": True, "msg": "已将续订任务添加到队列!"}
def main(): main_pid = 'logs/task.pid' if os.path.exists(main_pid): os.system("kill -9 $(cat {}) &> /dev/null".format(main_pid)) pid = os.fork() if pid: sys.exit(0) #os.umask(0) os.setsid() _pid = os.fork() if _pid: public.writeFile(main_pid, str(_pid)) sys.exit(0) sys.stdout.flush() sys.stderr.flush() task_log_file = 'logs/task.log' logging.basicConfig( level=logging.DEBUG, format='%(asctime)s [%(levelname)s] at %(lineno)d: %(message)s', datefmt='%Y-%m-%d(%a)%H:%M:%S', filename=task_log_file, filemode='a+') logging.info('Service started') import threading t = threading.Thread(target=systemTask) t.setDaemon(True) t.start() p = threading.Thread(target=check502Task) p.setDaemon(True) p.start() pl = threading.Thread(target=panel_status) pl.setDaemon(True) pl.start() p = threading.Thread(target=restart_panel_service) p.setDaemon(True) p.start() p = threading.Thread(target=check_panel_ssl) p.setDaemon(True) p.start() p = threading.Thread(target=send_mail_time) p.setDaemon(True) p.start() task_obj = panelTask.bt_task() task_obj.not_web = True p = threading.Thread(target=task_obj.start_task) p.setDaemon(True) p.start() startTask()
def task(pdata=None): comReturn = comm.local() if comReturn: return comReturn import panelTask toObject = panelTask.bt_task() defs = ('get_task_lists', 'remove_task', 'get_task_find') result = publicObject(toObject, defs, None, pdata) return result
def Get_Renew_SSL(self, get): if not os.path.isfile("/www/server/panel/vhost/crontab.json"): return {"status": False, "msg": public.GetMsg("GET_FAIL_NOT_RESULT"), "data": []} cmd_list = json.loads(public.ReadFile("/www/server/panel/vhost/crontab.json")) import panelTask CertList = self.GetCertList(get) data = [] for j in cmd_list: siteName = j['siteName'] cmd = j['cmd'] home_path = os.path.join("/www/server/panel/vhost/cert/", siteName) home_csr = os.path.join(home_path, "fullchain.pem") home_key = os.path.join(home_path, "privkey.pem") task = panelTask.bt_task() for i in task.get_task_list(): if i['name'] == siteName: siteName_task = {'status': i['status']} siteName_task['subject'] = siteName siteName_task['dns'] = [siteName, ] for item in CertList: if siteName == item['subject']: siteName_task['dns'] = item['dns'] siteName_task['notAfter'] = item['notAfter'] siteName_task['issuer'] = item['issuer'] timeArray = time.localtime(i['addtime']) siteName_task['addtime'] = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) if i['endtime']: timeArray = time.localtime(i['endtime']) siteName_task['endtime'] = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) else: siteName_task['endtime'] = i['endtime'] if i['status'] == -1: siteName_task['msg'] = public.GetMsg("RENEW_NOW") if i['status'] == 0: siteName_task['msg'] = public.GetMsg("WAIT_RENEW") if i['status'] == 1: get.keyPath =home_key get.certPath = home_csr self.SaveCert(get); siteName_task['msg'] = public.GetMsg("RENEW_SUCCESS") siteName_task['status'] = True if not os.path.isfile(home_key) and not os.path.isfile(home_csr): siteName_task['msg'] = public.GetMsg("RENEW_FAIL") siteName_task['status'] = False if os.path.isfile(os.path.join(home_path, "check_authorization_status_response")): siteName_task['msg'] = public.GetMsg("RENEW_FAIL1") siteName_task['status'] = False if os.path.isfile(os.path.join(home_path, "apply_for_cert_issuance_response")): siteName_task['msg'] = public.GetMsg("RENEW_FAIL2") siteName_task['status'] = False data.append(siteName_task) break if data: return {"status": True, "msg": public.GetMsg("SSL_GET_SUCCESS"), "data": data} else: return {"status": False, "msg": public.GetMsg("GET_FAIL_NOT_RESULT"), "data": []}
def main(): main_pid = 'logs/task.pid' if os.path.exists(main_pid): os.system("kill -9 $(cat {}) &> /dev/null".format(main_pid)) pid = os.fork() if pid: sys.exit(0) #os.umask(0) os.setsid() _pid = os.fork() if _pid: public.writeFile(main_pid, str(_pid)) sys.exit(0) sys.stdout.flush() sys.stderr.flush() task_log_file = 'logs/task.log' if not os.path.exists(task_log_file): open(task_log_file, 'w+').close() err_f = open(task_log_file, 'a+') os.dup2(err_f.fileno(), sys.stderr.fileno()) err_f.close() public.ExecShell('rm -rf /www/server/phpinfo/*') import threading t = threading.Thread(target=systemTask) t.setDaemon(True) t.start() p = threading.Thread(target=check502Task) p.setDaemon(True) p.start() pl = threading.Thread(target=panel_status) pl.setDaemon(True) pl.start() p = threading.Thread(target=restart_panel_service) p.setDaemon(True) p.start() p = threading.Thread(target=check_panel_ssl) p.setDaemon(True) p.start() p = threading.Thread(target=send_mail_time) p.setDaemon(True) p.start() task_obj = panelTask.bt_task() p = threading.Thread(target=task_obj.start_task) p.setDaemon(True) p.start() startTask()
def DownloadFile(self, get): import panelTask task_obj = panelTask.bt_task() task_obj.create_task('下载文件', 1, get.url, get.path + '/' + get.filename) #if sys.version_info[0] == 2: get.path = get.path.encode('utf-8'); #import db,time #isTask = '/tmp/panelTask.pl' #execstr = get.url +'|bt|'+get.path+'/'+get.filename #sql = db.Sql() #sql.table('tasks').add('name,type,status,addtime,execstr',('下载文件['+get.filename+']','download','0',time.strftime('%Y-%m-%d %H:%M:%S'),execstr)) #public.writeFile(isTask,'True') #self.SetFileAccept(get.path+'/'+get.filename); public.WriteLog('TYPE_FILE', 'FILE_DOWNLOAD', (get.url, get.path)) return public.returnMsg(True, 'FILE_DOANLOAD')
fastcgi_index index.php; include fastcgi.conf; include pathinfo.conf; }''' public.writeFile(pfile, pconf) import threading t = threading.Thread(target=systemTask) t.setDaemon(True) t.start() p = threading.Thread(target=check502Task) p.setDaemon(True) p.start() pl = threading.Thread(target=panel_status) pl.setDaemon(True) pl.start() p = threading.Thread(target=restart_panel_service) p.setDaemon(True) p.start() task_obj = panelTask.bt_task() p = threading.Thread(target=task_obj.start_task) p.setDaemon(True) p.start() #public.check_home() startTask()
def Get_Renew_SSL(self, get): if not os.path.isfile("/www/server/panel/vhost/crontab.json"): return {"status": False, "msg": "获取失败,当前没有结果!", "data": []} cmd_list = json.loads( public.ReadFile("/www/server/panel/vhost/crontab.json")) import panelTask CertList = self.GetCertList(get) data = [] for j in cmd_list: siteName = j['siteName'] cmd = j['cmd'] home_path = os.path.join("/www/server/panel/vhost/cert/", siteName) home_csr = os.path.join(home_path, "fullchain.pem") home_key = os.path.join(home_path, "privkey.pem") task = panelTask.bt_task() for i in task.get_task_list(): if i['name'] == siteName: siteName_task = {'status': i['status']} siteName_task['subject'] = siteName siteName_task['dns'] = [ siteName, ] for item in CertList: if siteName == item['subject']: siteName_task['dns'] = item['dns'] siteName_task['notAfter'] = item['notAfter'] siteName_task['issuer'] = item['issuer'] timeArray = time.localtime(i['addtime']) siteName_task['addtime'] = time.strftime( "%Y-%m-%d %H:%M:%S", timeArray) if i['endtime']: timeArray = time.localtime(i['endtime']) siteName_task['endtime'] = time.strftime( "%Y-%m-%d %H:%M:%S", timeArray) else: siteName_task['endtime'] = i['endtime'] if i['status'] == -1: siteName_task['msg'] = "正在续订中" if i['status'] == 0: siteName_task['msg'] = "等待续订中" if i['status'] == 1: get.keyPath = home_key get.certPath = home_csr self.SaveCert(get) siteName_task['msg'] = "续订成功" siteName_task['status'] = True if not os.path.isfile(home_key) and not os.path.isfile( home_csr): siteName_task[ 'msg'] = '续签失败,请尝试关闭SSL,使用文件验证或DNS验证方式重新申请此域名证书!' siteName_task['status'] = False if os.path.isfile( os.path.join( home_path, "check_authorization_status_response")): siteName_task['msg'] = '续签失败,域名解析错误,或解析未生效!' siteName_task['status'] = False if os.path.isfile( os.path.join( home_path, "apply_for_cert_issuance_response")): siteName_task['msg'] = '续签失败,您尝试申请证书的失败次数已达上限!' siteName_task['status'] = False data.append(siteName_task) break if data: return {"status": True, "msg": "获取成功!", "data": data} else: return {"status": False, "msg": "获取失败,当前没有结果!", "data": []}