def ReMemory(self,get): os.system('sync'); scriptFile = 'script/rememory.sh' if not os.path.exists(scriptFile): public.downloadFile(public.GetConfigValue('home') + '/script/rememory.sh',scriptFile); public.ExecShell("/bin/bash " + self.setupPath + '/panel/' + scriptFile); return self.GetMemInfo();
def checkBackup(self): if cache.get('check_backup'): return None #检查备份脚本是否存在 filePath = public.GetConfigValue('setup_path') + '/panel/script/backup' if not os.path.exists(filePath): public.downloadFile( public.GetConfigValue('home') + '/linux/backup.sh', filePath) #检查日志切割脚本是否存在 filePath = public.GetConfigValue( 'setup_path') + '/panel/script/logsBackup' if not os.path.exists(filePath): public.downloadFile( public.GetConfigValue('home') + '/linux/logsBackup.py', filePath) #检查计划任务服务状态 import system sm = system.system() if os.path.exists('/etc/init.d/crond'): if not public.process_exists('crond'): public.ExecShell('/etc/init.d/crond start') elif os.path.exists('/etc/init.d/cron'): if not public.process_exists('cron'): public.ExecShell('/etc/init.d/cron start') elif os.path.exists('/usr/lib/systemd/system/crond.service'): if not public.process_exists('crond'): public.ExecShell('systemctl start crond') cache.set('check_backup', True, 3600)
def checkBackup(self): # 检查备份脚本是否存在 filePath = web.ctx.session.setupPath + '/panel/script/backup' if not os.path.exists(filePath): public.downloadFile(web.ctx.session.home + '/linux/backup.sh', filePath) # 检查日志切割脚本是否存在 filePath = web.ctx.session.setupPath + '/panel/script/logsBackup' if not os.path.exists(filePath): public.downloadFile(web.ctx.session.home + '/linux/logsBackup.py', filePath) # 检查计划任务服务状态 if os.path.exists('/etc/init.d/crond'): if public.ExecShell('/etc/init.d/crond status')[0].find( 'running') == -1: public.ExecShell('/etc/init.d/crond start') elif os.path.exists('/etc/init.d/cron'): if public.ExecShell('/etc/init.d/cron status')[0].find( 'running') == -1: public.ExecShell('/etc/init.d/cron start') elif os.path.exists('/usr/lib/systemd/system/crond.service'): if public.ExecShell('systemctl status crond')[0].find( 'running') == -1: public.ExecShell('systemctl start crond')
def GetShell(self, param): try: filePath = '/tmp/freememory.sh' if not os.path.exists(filePath): public.downloadFile( 'https://basoro.id/downloads/freememory.sh', filePath) head = "#!/bin/bash\nPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin\nexport PATH\n" type = param['sType'] if type == 'rememory': shell = head + '/bin/bash /tmp/freememory.sh' elif type == 'toUrl': shell = head + 'curl -sS --connect-timeout 10 -m 60 ' + param.urladdress else: shell = head + param['sBody'] shell += ''' echo "----------------------------------------------------------------------------" endDate=`date +"%Y-%m-%d %H:%M:%S"` echo "★[$endDate] Task execution succeeded" echo "----------------------------------------------------------------------------" ''' cronPath = web.ctx.session.setupPath + '/cron' if not os.path.exists(cronPath): public.ExecShell('mkdir -p ' + cronPath) cronName = public.md5(public.md5(str(time.time()) + '_bt')) file = cronPath + '/' + cronName public.writeFile(file, self.CheckScript(shell)) public.ExecShell('chmod 750 ' + file) return cronName except Exception, ex: return public.returnMsg(False, 'File write failed!')
def updateWaf(self, get): names = ['args', 'cookie', 'post', 'url', 'user-agent'] furl = 'http://download.bt.cn/install/waf/wafconf' fpath = '/www/server/panel/vhost/wafconf' for name in names: public.downloadFile(furl + '/' + name, fpath + '/' + name) public.serviceReload() return public.returnMsg(True, 'WAF_UPDATE')
def ReMemory(self, get): os.system('sync') scriptFile = 'script/rememory.sh' if not os.path.exists(scriptFile): public.downloadFile(web.ctx.session.home + '/script/rememory.sh', scriptFile) public.ExecShell("/bin/bash " + self.setupPath + '/panel/' + scriptFile) return self.GetMemInfo()
def GetOS(self): filename = web.ctx.session.setupPath+"/panel/data/osname.pl"; if not os.path.exists(filename): scriptFile = 'GetOS.sh' if not os.path.exists(scriptFile): public.downloadFile(web.ctx.session.downloadUrl+'/GetOS.sh',scriptFile); os.system("bash "+web.ctx.session.setupPath+"/panel/GetOS.sh") public.ExecShell("rm -f "+web.ctx.session.setupPath+"/panel/GetOS.sh"); tmp = {} tmp['x'] = 'RHEL'; tmp['osname'] = public.readFile(filename).strip(); ds = ['Debian','Ubuntu','Raspbian','Deepin'] if tmp['osname'] in ds: tmp['x'] = 'Debian'; return tmp
def install(self,get): pluginInfo = self.GetFind(get.name); if not pluginInfo: import json pluginInfo = json.loads(public.readFile(self.__install_path + '/' + get.name + '/info.json')); if pluginInfo['tip'] == 'lib': if not os.path.exists(self.__install_path + '/' + pluginInfo['name']): os.system('mkdir -p ' + self.__install_path + '/' + pluginInfo['name']); if not hasattr(web.ctx.session,'downloadUrl'): web.ctx.session.downloadUrl = 'http://download.bt.cn'; downloadUrl = web.ctx.session.downloadUrl + '/install/lib/plugin/' + pluginInfo['name'] + '/install.sh'; toFile = self.__install_path + '/' + pluginInfo['name'] + '/install.sh'; public.downloadFile(downloadUrl,toFile); os.system('/bin/bash ' + toFile + ' install'); if self.checksSetup(pluginInfo['name'],pluginInfo['checks'],pluginInfo['versions'])[0]['status'] or os.path.exists(self.__install_path + '/' + get.name): public.WriteLog('TYPE_SETUP','PLUGIN_INSTALL_LIB',(pluginInfo['title'],)); os.system('rm -f ' + toFile); return public.returnMsg(True,'PLUGIN_INSTALL_SUCCESS'); return public.returnMsg(False,'PLUGIN_INSTALL_ERR'); else: import db,time path = web.ctx.session.setupPath + '/php' if not os.path.exists(path): os.system("mkdir -p " + path); issue = public.readFile('/etc/issue') if web.ctx.session.server_os['x'] != 'RHEL': get.type = '3' apacheVersion='false'; if public.get_webserver() == 'apache': apacheVersion = public.readFile(web.ctx.session.setupPath+'/apache/version.pl'); public.writeFile('/var/bt_apacheVersion.pl',apacheVersion) public.writeFile('/var/bt_setupPath.conf',web.ctx.session.rootPath) isTask = '/tmp/panelTask.pl' mtype = 'install'; mmsg = '安装'; if hasattr(get, 'upgrade'): if get.upgrade: mtype = 'update'; mmsg = 'upgrade'; execstr = "cd " + web.ctx.session.setupPath + "/panel/install && /bin/bash install_soft.sh " + get.type + " "+mtype+" " + get.name + " "+ get.version; sql = db.Sql() if hasattr(get,'id'): id = get.id; else: id = None; sql.table('tasks').add('id,name,type,status,addtime,execstr',(None, mmsg + '['+get.name+'-'+get.version+']','execshell','0',time.strftime('%Y-%m-%d %H:%M:%S'),execstr)) public.writeFile(isTask,'True') public.WriteLog('TYPE_SETUP','PLUGIN_ADD',(get.name,get.version)); return public.returnMsg(True,'PLUGIN_INSTALL');
def checkBackup(self): #检查备份脚本是否存在 filePath=web.ctx.session.setupPath+'/panel/script/backup' if not os.path.exists(filePath): public.downloadFile(web.ctx.session.home + '/linux/backup.sh',filePath) #检查日志切割脚本是否存在 filePath=web.ctx.session.setupPath+'/panel/script/logsBackup' if not os.path.exists(filePath): public.downloadFile(web.ctx.session.home + '/linux/logsBackup.py',filePath) #检查计划任务服务状态 if os.path.exists('/etc/init.d/crond'): if public.ExecShell('/etc/init.d/crond status')[0].find('running') == -1: public.ExecShell('/etc/init.d/crond start') elif os.path.exists('/etc/init.d/cron'): if public.ExecShell('/etc/init.d/cron status')[0].find('running') == -1: public.ExecShell('/etc/init.d/cron start') elif os.path.exists('/usr/lib/systemd/system/crond.service'): if public.ExecShell('systemctl status crond')[0].find('running') == -1: public.ExecShell('systemctl start crond')
def unInstall(self, get): pluginInfo = self.GetFind(get.name) if not pluginInfo: import json pluginInfo = json.loads( public.readFile(self.__install_path + '/' + get.name + '/info.json')) if pluginInfo['tip'] == 'lib': if not os.path.exists(self.__install_path + '/' + pluginInfo['name']): os.system('mkdir -p ' + self.__install_path + '/' + pluginInfo['name']) downloadUrl = web.ctx.session.downloadUrl + \ '/install/lib/plugin/' + pluginInfo['name'] + '/install.sh' toFile = self.__install_path + '/' + \ pluginInfo['name'] + '/uninstall.sh' public.downloadFile(downloadUrl, toFile) os.system('/bin/bash ' + toFile + ' uninstall') os.system('rm -rf ' + web.ctx.session.downloadUrl + '/install/lib/plugin/' + pluginInfo['name']) pluginPath = self.__install_path + '/' + pluginInfo['name'] if os.path.exists(pluginPath + '/install.sh'): os.system('/bin/bash ' + pluginPath + '/install.sh uninstall') if os.path.exists(pluginPath): public.ExecShell('rm -rf ' + pluginPath) public.WriteLog('TYPE_SETUP', 'PLUGIN_UNINSTALL_SOFT', (pluginInfo['title'], )) return public.returnMsg(True, 'PLUGIN_UNINSTALL') else: get.type = '0' issue = public.readFile('/etc/issue') if web.ctx.session.server_os['x'] != 'RHEL': get.type = '3' public.writeFile('/var/bt_setupPath.conf', web.ctx.session.rootPath) execstr = "cd /www/server/panel/install && /bin/bash install_soft.sh " + \ get.type+" uninstall " + get.name.lower() + " " + get.version.replace('.', '') os.system(execstr) public.WriteLog('TYPE_SETUP', 'PLUGIN_UNINSTALL', (get.name, get.version)) return public.returnMsg(True, "PLUGIN_UNINSTALL")
def update_to6(): print("====================================================") print(public.GetMsg("PLUG_UPDATEING")) print("====================================================") download_address = public.get_url() exlodes = ['gitlab','pm2','mongodb','deployment_jd','logs','docker','beta','btyw'] for pname in os.listdir('plugin/'): if not os.path.isdir('plugin/' + pname): continue if pname in exlodes: continue print("|-upgrading【%s】..." % pname), download_url = download_address + '/install/plugin/' + pname + '/install.sh'; to_file = '/tmp/%s.sh' % pname public.downloadFile(download_url,to_file); os.system('/bin/bash ' + to_file + ' install &> /tmp/plugin_update.log 2>&1'); print(" \033[32m[success]\033[0m") print("====================================================") print("\033[32m"+public.GetMsg("PLUG_UPDATE_TO_6")+"\033[0m") print("====================================================")
def update_to6(): print("====================================================") print("正在升级插件...") print("====================================================") download_address = public.get_url() exlodes = ['gitlab','pm2','mongodb','deployment_jd','logs','docker','beta','btyw'] for pname in os.listdir('plugin/'): if not os.path.isdir('plugin/' + pname): continue if pname in exlodes: continue print("|-正在升级【%s】..." % pname), download_url = download_address + '/install/plugin/' + pname + '/install.sh'; to_file = '/tmp/%s.sh' % pname public.downloadFile(download_url,to_file); os.system('/bin/bash ' + to_file + ' install &> /tmp/plugin_update.log 2>&1'); print(" \033[32m[成功]\033[0m") print("====================================================") print("\033[32m所有插件已成功升级到6.0兼容!\033[0m") print("====================================================")
def unInstall(self,get): pluginInfo = self.GetFind(get.name); if not pluginInfo: import json pluginInfo = json.loads(public.readFile(self.__install_path + '/' + get.name + '/info.json')); if pluginInfo['tip'] == 'lib': if not os.path.exists(self.__install_path+ '/' + pluginInfo['name']): os.system('mkdir -p ' + self.__install_path + '/' + pluginInfo['name']); downloadUrl = web.ctx.session.downloadUrl + '/install/lib/plugin/' + pluginInfo['name'] + '/install.sh'; toFile = self.__install_path + '/' + pluginInfo['name'] + '/install.sh'; public.downloadFile(downloadUrl,toFile) os.system('/bin/bash ' + toFile + ' uninstall') os.system('rm -rf ' + web.ctx.session.downloadUrl + '/install/lib/plugin/' + pluginInfo['name']) public.WriteLog('TYPE_SETUP','PLUGIN_UNINSTALL_SOFT',(pluginInfo['title'],)); return public.returnMsg(True,'PLUGIN_UNINSTALL'); else: get.type = '0' issue = public.readFile('/etc/issue') if web.ctx.session.server_os['x'] != 'RHEL': get.type = '3' public.writeFile('/var/bt_setupPath.conf',web.ctx.session.rootPath) execstr = "cd " + web.ctx.session.setupPath + "/panel/install && /bin/bash install_soft.sh "+get.type+" uninstall " + get.name.lower() + " "+ get.version.replace('.',''); os.system(execstr); public.WriteLog('TYPE_SETUP','PLUGIN_UNINSTALL',(get.name,get.version)); return public.returnMsg(True,"PLUGIN_UNINSTALL");
def UpdatePanel(self,get): #return public.returnMsg(False,'演示服务器,禁止此操作!'); try: if not public.IsRestart(): return public.returnMsg(False,'EXEC_ERR_TASK'); import web,json if int(web.ctx.session.config['status']) == 0: public.httpGet(web.ctx.session.home+'/Api/SetupCount?type=Linux'); public.M('config').where("id=?",('1',)).setField('status',1); #取回远程版本信息 if hasattr(web.ctx.session,'updateInfo') == True and hasattr(get,'check') == False: updateInfo = web.ctx.session.updateInfo; else: login_temp = 'data/login.temp'; if os.path.exists(login_temp): logs = public.readFile(login_temp) os.remove(login_temp); else: logs = ''; import psutil,panelPlugin,system; mem = psutil.virtual_memory(); mplugin = panelPlugin.panelPlugin(); mplugin.ROWS = 10000; panelsys = system.system(); data = {} data['sites'] = str(public.M('sites').count()); data['ftps'] = str(public.M('ftps').count()); data['databases'] = str(public.M('databases').count()); data['system'] = panelsys.GetSystemVersion() + '|' + str(mem.total / 1024 / 1024) + 'MB|' + public.getCpuType() + '*' + str(psutil.cpu_count()) + '|' + public.get_webserver() + '|' + web.ctx.session.version; data['system'] += '||'+self.GetInstalleds(mplugin.getPluginList(None)); data['logs'] = logs data['oem'] = '' data['intrusion'] = self.get_ssh_intrusion(); msg = public.getMsg('PANEL_UPDATE_MSG'); sUrl = web.ctx.session.home + '/Api/updateLinux'; betaIs = 'data/beta.pl'; betaStr = public.readFile(betaIs); if betaStr: if betaStr.strip() != 'False': sUrl = web.ctx.session.home + '/Api/updateLinuxBeta'; msg = public.getMsg('PANEL_UPDATE_MSG_TEST'); betaIs = 'plugin/beta/config.conf'; betaStr = public.readFile(betaIs); if betaStr: if betaStr.strip() != 'False': sUrl = web.ctx.session.home + '/Api/updateLinuxBeta'; msg = public.getMsg('PANEL_UPDATE_MSG_TEST'); updateInfo = json.loads(public.httpPost(sUrl,data)); if not updateInfo: return public.returnMsg(False,"CONNECT_ERR"); updateInfo['msg'] = msg; web.ctx.session.updateInfo = updateInfo; #检查是否需要升级 if updateInfo['version'] == web.ctx.session.version: try: return public.returnMsg(False,updateInfo['msg']); except: return public.returnMsg(False,'PANEL_UPDATE_ERR_NEW'); #是否执行升级程序 if(updateInfo['force'] == True or hasattr(get,'toUpdate') == True or os.path.exists('data/autoUpdate.pl') == True): setupPath = web.ctx.session.setupPath; uptype = 'update'; betaIs = 'plugin/beta/config.conf'; betaStr = public.readFile(betaIs); if betaStr: if betaStr.strip() != 'False': uptype = 'updateTest'; betaIs = 'data/beta.pl'; betaStr = public.readFile(betaIs); if betaStr: if betaStr.strip() != 'False': uptype = 'updateTest'; httpUrl = public.get_url(); if httpUrl: updateInfo['downUrl'] = httpUrl + '/install/' + uptype + '/LinuxPanel-' + updateInfo['version'] + '.zip'; public.downloadFile(updateInfo['downUrl'],'panel.zip'); if os.path.getsize('panel.zip') < 1048576: return public.returnMsg(False,"PANEL_UPDATE_ERR_DOWN"); public.ExecShell('unzip -o panel.zip -d ' + setupPath + '/'); import compileall if os.path.exists(setupPath + '/panel/main.py'): public.ExecShell('rm -f ' + setupPath + '/panel/*.pyc'); if os.path.exists(setupPath + '/panel/class/common.py'): public.ExecShell('rm -f ' + setupPath + '/panel/class/*.pyc'); compileall.compile_dir(setupPath + '/panel'); compileall.compile_dir(setupPath + '/panel/class'); public.ExecShell('rm -f panel.zip'); web.ctx.session.version = updateInfo['version'] return public.returnMsg(True,'PANEL_UPDATE',(updateInfo['version'],)); #输出新版本信息 data = { 'status' : True, 'version': updateInfo['version'], 'updateMsg' : updateInfo['updateMsg'] }; public.ExecShell('rm -rf /www/server/phpinfo/*'); return data; except Exception,ex: return public.returnMsg(False,"CONNECT_ERR");
def UpdatePanel(self,get): try: if not public.IsRestart(): return public.returnMsg(False,'EXEC_ERR_TASK'); import json if int(session['config']['status']) == 0: public.HttpGet(public.GetConfigValue('home')+'/Api/SetupCount?type=Linux'); public.M('config').where("id=?",('1',)).setField('status',1); #取回远程版本信息 if 'updateInfo' in session and hasattr(get,'check') == False: updateInfo = session['updateInfo']; else: login_temp = 'data/login.temp'; if os.path.exists(login_temp): logs = public.readFile(login_temp) os.remove(login_temp); else: logs = ''; import psutil,panelPlugin,system; mem = psutil.virtual_memory(); mplugin = panelPlugin.panelPlugin(); mplugin.ROWS = 10000; panelsys = system.system(); data = {} data['sites'] = str(public.M('sites').count()); data['ftps'] = str(public.M('ftps').count()); data['databases'] = str(public.M('databases').count()); data['system'] = panelsys.GetSystemVersion() + '|' + str(mem.total / 1024 / 1024) + 'MB|' + public.getCpuType() + '*' + str(psutil.cpu_count()) + '|' + public.get_webserver() + '|' +session['version']; data['system'] += '||'+self.GetInstalleds(mplugin.getPluginList(None)); data['logs'] = logs data['oem'] = '' data['intrusion'] = 0; msg = public.getMsg('PANEL_UPDATE_MSG'); sUrl = public.GetConfigValue('home') + '/api/panel/updateLinux'; updateInfo = json.loads(public.httpPost(sUrl,data)); if not updateInfo: return public.returnMsg(False,"CONNECT_ERR"); updateInfo['msg'] = msg; session['updateInfo'] = updateInfo; #检查是否需要升级 if updateInfo['version'] ==session['version']: try: return public.returnMsg(False,updateInfo['msg']); except: return public.returnMsg(False,'PANEL_UPDATE_ERR_NEW'); #是否执行升级程序 if(updateInfo['force'] == True or hasattr(get,'toUpdate') == True or os.path.exists('data/autoUpdate.pl') == True): setupPath = public.GetConfigValue('setup_path'); uptype = 'update'; httpUrl = public.get_url(); if httpUrl: updateInfo['downUrl'] = httpUrl + '/install/' + uptype + '/LinuxPanel-' + updateInfo['version'] + '.zip'; public.downloadFile(updateInfo['downUrl'],'panel.zip'); if os.path.getsize('panel.zip') < 1048576: return public.returnMsg(False,"PANEL_UPDATE_ERR_DOWN"); public.ExecShell('unzip -o panel.zip -d ' + setupPath + '/'); import compileall if os.path.exists('/www/server/panel/runserver.py'): public.ExecShell('rm -f /www/server/panel/*.pyc'); if os.path.exists('/www/server/panel/class/common.py'): public.ExecShell('rm -f /www/server/panel/class/*.pyc'); if os.path.exists('panel.zip'):os.remove("panel.zip") session['version'] = updateInfo['version'] if 'getCloudPlugin' in session: del(session['getCloudPlugin']); return public.returnMsg(True,'PANEL_UPDATE',(updateInfo['version'],)); #输出新版本信息 data = { 'status' : True, 'version': updateInfo['version'], 'updateMsg' : updateInfo['updateMsg'] }; public.ExecShell('rm -rf /www/server/phpinfo/*'); return data; except Exception as ex: return public.returnMsg(False,"CONNECT_ERR");
def UpdatePanel(self, get): try: if not public.IsRestart(): return public.returnMsg(False, 'EXEC_ERR_TASK') import json if int(session['config']['status']) == 0: public.HttpGet( public.GetConfigValue('home') + '/Api/SetupCount?type=Linux') public.M('config').where("id=?", ('1', )).setField('status', 1) #取回远程版本信息 if 'updateInfo' in session and hasattr(get, 'check') == False: updateInfo = session['updateInfo'] else: logs = '' import psutil, system, sys mem = psutil.virtual_memory() import panelPlugin mplugin = panelPlugin.panelPlugin() mplugin.ROWS = 10000 panelsys = system.system() data = {} data['sites'] = str(public.M('sites').count()) data['ftps'] = str(public.M('ftps').count()) data['databases'] = str(public.M('databases').count()) data['system'] = panelsys.GetSystemVersion() + '|' + str( mem.total / 1024 / 1024) + 'MB|' + str(public.getCpuType()) + '*' + str( psutil.cpu_count()) + '|' + str( public.get_webserver()) + '|' + session['version'] data['system'] += '||' + self.GetInstalleds( mplugin.getPluginList(None)) data['logs'] = logs data['client'] = request.headers.get('User-Agent') data['oem'] = '' data['intrusion'] = 0 data['uid'] = self.get_uid() #msg = public.getMsg('PANEL_UPDATE_MSG'); data['o'] = '' filename = '/www/server/panel/data/o.pl' if os.path.exists(filename): data['o'] = str(public.readFile(filename)) sUrl = public.GetConfigValue('home') + '/api/panel/updateLinux' updateInfo = json.loads(public.httpPost(sUrl, data)) if not updateInfo: return public.returnMsg(False, "CONNECT_ERR") #updateInfo['msg'] = msg; session['updateInfo'] = updateInfo #检查是否需要升级 if updateInfo['is_beta'] == 1: if updateInfo['beta']['version'] == session['version']: return public.returnMsg(False, updateInfo) else: if updateInfo['version'] == session['version']: return public.returnMsg(False, updateInfo) #是否执行升级程序 if (updateInfo['force'] == True or hasattr(get, 'toUpdate') == True or os.path.exists('data/autoUpdate.pl') == True): if updateInfo['is_beta'] == 1: updateInfo['version'] = updateInfo['beta']['version'] setupPath = public.GetConfigValue('setup_path') uptype = 'update' httpUrl = public.get_url() if httpUrl: updateInfo[ 'downUrl'] = httpUrl + '/install/' + uptype + '/LinuxPanel-' + updateInfo[ 'version'] + '.zip' public.downloadFile(updateInfo['downUrl'], 'panel.zip') if os.path.getsize('panel.zip') < 1048576: return public.returnMsg(False, "PANEL_UPDATE_ERR_DOWN") public.ExecShell('unzip -o panel.zip -d ' + setupPath + '/') import compileall if os.path.exists('/www/server/panel/runserver.py'): public.ExecShell('rm -f /www/server/panel/*.pyc') if os.path.exists('/www/server/panel/class/common.py'): public.ExecShell('rm -f /www/server/panel/class/*.pyc') if os.path.exists('panel.zip'): os.remove("panel.zip") session['version'] = updateInfo['version'] if 'getCloudPlugin' in session: del (session['getCloudPlugin']) if updateInfo['is_beta'] == 1: self.to_beta() public.ExecShell("/etc/init.d/bt start") public.writeFile('data/restart.pl', 'True') return public.returnMsg(True, 'PANEL_UPDATE', (updateInfo['version'], )) #输出新版本信息 data = { 'status': True, 'version': updateInfo['version'], 'updateMsg': updateInfo['updateMsg'] } public.ExecShell('rm -rf /www/server/phpinfo/*') return public.returnMsg(True, updateInfo) except Exception as ex: return public.returnMsg(False, "CONNECT_ERR")
def UpdatePanel(self,get): #return public.returnMsg(False,'演示服务器,禁止此操作!'); try: if not public.IsRestart(): return public.returnMsg(False,'EXEC_ERR_TASK'); import web,json if int(web.ctx.session.config['status']) == 0: public.httpGet(web.ctx.session.home+'/Api/SetupCount?type=Linux'); public.M('config').where("id=?",('1',)).setField('status',1); #取回远程版本信息 if hasattr(web.ctx.session,'updateInfo') == True and hasattr(get,'check') == False: updateInfo = web.ctx.session.updateInfo; else: login_temp = 'data/login.temp'; if os.path.exists(login_temp): logs = public.readFile(login_temp) os.remove(login_temp); else: logs = ''; import psutil,panelPlugin,system; mem = psutil.virtual_memory(); mplugin = panelPlugin.panelPlugin(); mplugin.ROWS = 10000; panelsys = system.system(); data = {} data['sites'] = str(public.M('sites').count()); data['ftps'] = str(public.M('ftps').count()); data['databases'] = str(public.M('databases').count()); data['system'] = panelsys.GetSystemVersion() + '|' + str(mem.total / 1024 / 1024) + 'MB|' + public.getCpuType() + '*' + str(psutil.cpu_count()) + '|' + public.get_webserver() + '|' + web.ctx.session.version; data['system'] += '||'+self.GetInstalleds(mplugin.getPluginList(None)); data['logs'] = logs data['oem'] = '' data['intrusion'] = self.get_ssh_intrusion(); msg = public.getMsg('PANEL_UPDATE_MSG'); sUrl = web.ctx.session.home + '/Api/updateLinux'; betaIs = 'data/beta.pl'; betaStr = public.readFile(betaIs); if betaStr: if betaStr.strip() != 'False': sUrl = web.ctx.session.home + '/Api/updateLinuxBeta'; msg = public.getMsg('PANEL_UPDATE_MSG_TEST'); betaIs = 'plugin/beta/config.conf'; betaStr = public.readFile(betaIs); if betaStr: if betaStr.strip() != 'False': sUrl = web.ctx.session.home + '/Api/updateLinuxBeta'; msg = public.getMsg('PANEL_UPDATE_MSG_TEST'); updateInfo = json.loads(public.httpPost(sUrl,data)); if not updateInfo: return public.returnMsg(False,"CONNECT_ERR"); updateInfo['msg'] = msg; web.ctx.session.updateInfo = updateInfo; #检查是否需要升级 if updateInfo['version'] == web.ctx.session.version: try: return public.returnMsg(False,updateInfo['msg']); except: return public.returnMsg(False,'PANEL_UPDATE_ERR_NEW'); #是否执行升级程序 if(updateInfo['force'] == True or hasattr(get,'toUpdate') == True or os.path.exists('data/autoUpdate.pl') == True): setupPath = web.ctx.session.setupPath; uptype = 'update'; betaIs = 'plugin/beta/config.conf'; betaStr = public.readFile(betaIs); if betaStr: if betaStr.strip() != 'False': uptype = 'updateTest'; betaIs = 'data/beta.pl'; betaStr = public.readFile(betaIs); if betaStr: if betaStr.strip() != 'False': uptype = 'updateTest'; httpUrl = public.get_url(); if httpUrl: updateInfo['downUrl'] = httpUrl + '/install/' + uptype + '/LinuxPanel-' + updateInfo['version'] + '.zip'; public.downloadFile(updateInfo['downUrl'],'panel.zip'); if os.path.getsize('panel.zip') < 1048576: return public.returnMsg(False,"PANEL_UPDATE_ERR_DOWN"); public.ExecShell('unzip -o panel.zip -d ' + setupPath + '/'); import compileall if os.path.exists(setupPath + '/panel/main.py'): public.ExecShell('rm -f ' + setupPath + '/panel/*.pyc'); if os.path.exists(setupPath + '/panel/class/common.py'): public.ExecShell('rm -f ' + setupPath + '/panel/class/*.pyc'); compileall.compile_dir(setupPath + '/panel'); compileall.compile_dir(setupPath + '/panel/class'); public.ExecShell('rm -f panel.zip'); web.ctx.session.version = updateInfo['version'] return public.returnMsg(True,'PANEL_UPDATE',(updateInfo['version'],)); #输出新版本信息 data = { 'status' : True, 'version': updateInfo['version'], 'updateMsg' : updateInfo['updateMsg'] }; public.ExecShell('rm -rf /www/server/phpinfo/*'); return data; except Exception,ex: return public.returnMsg(False,"CONNECT_ERR");