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['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/updateLinuxEn' updateInfo = json.loads(public.httpPost(sUrl, data)) if not updateInfo: return public.returnMsg(False, "CONNECT_ERR") #updateInfo['msg'] = msg; updateInfo['is_beta'] = 0 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_EN-' + 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() 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 RestartServer(self, get): if not public.IsRestart(): return public.returnMsg(False, 'EXEC_ERR_TASK') public.ExecShell("sync && /etc/init.d/bt stop && init 6 &") return public.returnMsg(True, 'SYS_REBOOT')
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: o = '' if os.path.exists('data/o.pl'): o = public.readFile('data/o.pl').strip() public.httpGet(web.ctx.session.home + '/Api/SetupCount?type=Linux&o=' + o) 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() data['o'] = '' filename = '/www/server/panel/data/o.pl' if os.path.exists(filename): data['o'] = str(public.readFile(filename)) 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 os.path.exists('data/o.pl'): import tools tools.setup_idc() if getattr(web.ctx.session, 'brand'): del (web.ctx.session.brand) #检查是否需要升级 if updateInfo['version'] == web.ctx.session.version: try: updateInfo['msg'] = public.httpGet( 'http://www.bt.cn/lib/update.txt') 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'] if hasattr(web.ctx.session, 'getCloudPlugin'): del (web.ctx.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, ex: return public.returnMsg(False, "CONNECT_ERR")
def setPanel(self, get): if not public.IsRestart(): return public.returnMsg(False, 'EXEC_ERR_TASK') isReWeb = False sess_out_path = 'data/session_timeout.pl' if 'session_timeout' in get: session_timeout = int(get.session_timeout) if int(public.readFile(sess_out_path)) != session_timeout: if session_timeout < 300: return public.returnMsg(False, '超时时间不能小于300秒') public.writeFile(sess_out_path, str(session_timeout)) isReWeb = True workers_p = 'data/workers.pl' if 'workers' in get: workers = int(get.workers) if int(public.readFile(workers_p)) != workers: if workers < 1 or workers > 1024: return public.returnMsg(False, '面板线程数范围应该在1-1024之间') public.writeFile(workers_p, str(workers)) isReWeb = True if get.domain: reg = "^([\w\-\*]{1,100}\.){1,4}(\w{1,10}|\w{1,10}\.\w{1,10})$" if not re.match(reg, get.domain): return public.returnMsg(False, 'SITE_ADD_ERR_DOMAIN') oldPort = public.GetHost(True) newPort = get.port if oldPort != get.port: get.port = str(int(get.port)) if self.IsOpen(get.port): return public.returnMsg(False, 'PORT_CHECK_EXISTS', (get.port, )) if int(get.port) >= 65535 or int(get.port) < 100: return public.returnMsg(False, 'PORT_CHECK_RANGE') public.writeFile('data/port.pl', get.port) import firewalls get.ps = public.getMsg('PORT_CHECK_PS') fw = firewalls.firewalls() fw.AddAcceptPort(get) get.port = oldPort get.id = public.M('firewall').where("port=?", (oldPort, )).getField('id') fw.DelAcceptPort(get) isReWeb = True if get.webname != session['title']: session['title'] = get.webname public.SetConfigValue('title', get.webname) limitip = public.readFile('data/limitip.conf') if get.limitip != limitip: public.writeFile('data/limitip.conf', get.limitip) public.writeFile('data/domain.conf', get.domain.strip()) public.writeFile('data/iplist.txt', get.address) public.M('config').where("id=?", ('1', )).save( 'backup_path,sites_path', (get.backup_path, get.sites_path)) session['config']['backup_path'] = os.path.join('/', get.backup_path) session['config']['sites_path'] = os.path.join('/', get.sites_path) mhost = public.GetHost() if get.domain.strip(): mhost = get.domain data = { 'uri': request.path, 'host': mhost + ':' + newPort, 'status': True, 'isReWeb': isReWeb, 'msg': public.getMsg('PANEL_SAVE') } public.WriteLog('TYPE_PANEL', 'PANEL_SET_SUCCESS', (newPort, get.domain, get.backup_path, get.sites_path, get.address, get.limitip)) if isReWeb: public.restart_panel() return data
def setPanel(self, get): if not public.IsRestart(): return public.returnMsg(False, 'EXEC_ERR_TASK') if get.domain: reg = "^([\w\-\*]{1,100}\.){1,4}(\w{1,10}|\w{1,10}\.\w{1,10})$" if not re.match(reg, get.domain): return public.returnMsg(False, 'SITE_ADD_ERR_DOMAIN') isReWeb = False try: oldPort = web.ctx.host.split(':')[1] except: oldPort = public.readFile('data/port.pl').strip() newPort = get.port if oldPort != get.port: get.port = str(int(get.port)) if self.IsOpen(get.port): return public.returnMsg(False, 'PORT_CHECK_EXISTS', (get.port, )) if int(get.port) >= 65535 or int(get.port) < 100: return public.returnMsg(False, 'PORT_CHECK_RANGE') public.writeFile('data/port.pl', get.port) import firewalls get.ps = public.getMsg('PORT_CHECK_PS') fw = firewalls.firewalls() fw.AddAcceptPort(get) get.port = oldPort get.id = public.M('firewall').where("port=?", (oldPort, )).getField('id') fw.DelAcceptPort(get) isReWeb = True if get.webname != web.ctx.session.webname: web.ctx.session.webname = get.webname public.writeFile('data/title.pl', get.webname) limitip = public.readFile('data/limitip.conf') if get.limitip != limitip: public.writeFile('data/limitip.conf', get.limitip) public.writeFile('data/domain.conf', get.domain.strip()) public.writeFile('data/iplist.txt', get.address) public.M('config').where("id=?", ('1', )).save( 'backup_path,sites_path', (get.backup_path, get.sites_path)) web.ctx.session.config['backup_path'] = get.backup_path web.ctx.session.config['sites_path'] = get.sites_path mhost = web.ctx.host.split(':')[0] if get.domain.strip(): mhost = get.domain data = { 'uri': web.ctx.fullpath, 'host': mhost + ':' + newPort, 'status': True, 'isReWeb': isReWeb, 'msg': public.getMsg('PANEL_SAVE') } public.WriteLog('TYPE_PANEL', 'PANEL_SAVE', (newPort, get.domain, get.backup_path, get.sites_path, get.address, get.limitip)) self.setService() if isReWeb: os.system("sleep 2 && /etc/init.d/bt restart &") return data
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'] = '' 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");