def setup_idc(): try: panelPath = '/www/server/panel' filename = panelPath + '/data/o.pl' if not os.path.exists(filename): return False o = public.readFile(filename).strip() c_url = 'http://www.bt.cn/api/idc/get_idc_info_bycode?o=%s' % o idcInfo = json.loads(public.httpGet(c_url)) if not idcInfo['status']: return False pFile = panelPath + '/config/config.json' pInfo = json.loads(public.readFile(pFile)) pInfo['brand'] = idcInfo['msg']['name'] pInfo['product'] = public.GetMsg("WITH_BT_CUSTOM_EDITION") public.writeFile(pFile, json.dumps(pInfo)) tFile = panelPath + '/data/title.pl' titleNew = (pInfo['brand'] + public.GetMsg("PANEL")).encode('utf-8') if os.path.exists(tFile): title = public.readFile(tFile).strip() if title == '宝塔Linux面板' or title == '': public.writeFile(tFile, titleNew) public.SetConfigValue('title', titleNew) else: public.writeFile(tFile, titleNew) public.SetConfigValue('title', titleNew) return True except: pass
def BtcoInstall(self, get): v = public.version() if v[-2] == '.': if v < '6.9.1': public.returnMsg(False, '抱歉,面板当前版本不支持BTCO,请升级面板至最新版') else: if v < '6.9.15': public.returnMsg(False, '抱歉,面板当前版本不支持BTCO,请升级面板至最新版') if not public.GetConfigValue('btco'): initobj = open( '/www/server/panel/BTPanel/templates/default/layout.html', 'r') for initLine in initobj: for btcoin in ['<!--BTCO-->']: if btcoin.upper() in initLine.upper(): self.BtcoIns.append(btcoin) if len(self.BtcoIns) != 0: initobj.close() public.SetConfigValue('btco', True) return public.returnMsg(True, '您已安装过了.') # BTCO 强制跳转写入 BtcoAdd = '<!--BTCO-->\n <script> var a=document.location.toString().split("//");navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)&&("/"==a[1].substring(a[1].indexOf("/"))?window.location.href="/btco/index.html' + '":"/config"==a[1].substring(a[1].indexOf("/"))&&(window.location.href="/btco/index.html#/config' + '")); </script> \n <!--BTCO-->' initCoutent = open( '/www/server/panel/BTPanel/templates/default/layout.html', 'r') BtcoAddIn = initCoutent.read().split("</head>") initCoutent.close() BtcoAddin = open( '/www/server/panel/BTPanel/templates/default/layout.html', 'w') BtcoAddin.write(BtcoAddIn[0] + BtcoAdd + "</head>" + BtcoAddIn[1]) BtcoAddin.close() public.restart_panel() public.SetConfigValue('btco', True) return public.returnMsg(True, '安装成功,感谢支持.') elif public.GetConfigValue('btco'): return public.returnMsg(True, '您已安装过了.') return public.returnMsg(False, '安装失败')
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 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'] = get.backup_path session['config']['sites_path'] = 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_SAVE', (newPort, get.domain, get.backup_path, get.sites_path, get.address, get.limitip)) if isReWeb: public.restart_panel() return data
def BtcoRemove(self, get): if not public.GetConfigValue('btco'): return public.returnMsg(False, '未安装怎么移除?') initobj = open( '/www/server/panel/BTPanel/templates/default/layout.html', 'r') for initLine in initobj: for btcoin in ['<!--BTCO-->']: if btcoin.upper() in initLine.upper(): self.BtcoIns.append(btcoin) if len(self.BtcoIns) > 0: initCoutent = open( '/www/server/panel/BTPanel/templates/default/layout.html', 'r') BtcoAddOn = initCoutent.read().split("<!--BTCO-->") initCoutent.close() BtcoAddOnd = open( '/www/server/panel/BTPanel/templates/default/layout.html', 'w') BtcoAddOnd.write(BtcoAddOn[0] + BtcoAddOn[2]) BtcoAddOnd.close() public.restart_panel() public.SetConfigValue('btco', False) return public.returnMsg(True, '移除成功!') public.SetConfigValue('btco', False) return public.returnMsg(True, '移除成功')
def BtcoInstall(self, get): v = public.version() if v[-2] == '.': if v < '6.9.1': public.returnMsg(False, '抱歉,面板当前版本不支持BTCO,请升级面板至最新版') else: if v < '6.9.15': public.returnMsg(False, '抱歉,面板当前版本不支持BTCO,请升级面板至最新版') if not public.GetConfigValue('btco'): initobj = open( '/www/server/panel/BTPanel/templates/default/layout.html', 'r') for initLine in initobj: for btcoin in ['<!--BTCO-->']: if btcoin.upper() in initLine.upper(): self.BtcoIns.append(btcoin) if len(self.BtcoIns) != 0: initobj.close() public.SetConfigValue('btco', True) public.SetConfigValue('btco_init', True) return public.returnMsg(True, '您已安装过了。') # BTCO 强制跳转写入 BtcoAdd = '<!--BTCO-->\n <script> if(navigator.userAgent.match(/mobile/i)){let a=document.location.toString().split("//"),urlArr=["/","/config"],thisUrl=urlArr.indexOf(a[1].substring(a[1].indexOf("/")));if(thisUrl>-1)window.location.href="/btco/index.html#"+urlArr[thisUrl]} </script> \n <!--BTCO-->' initCoutent = open( '/www/server/panel/BTPanel/templates/default/layout.html', 'r') BtcoAddIn = initCoutent.read().split("</head>") initCoutent.close() BtcoAddin = open( '/www/server/panel/BTPanel/templates/default/layout.html', 'w') BtcoAddin.write(BtcoAddIn[0] + BtcoAdd + "</head>" + BtcoAddIn[1]) BtcoAddin.close() public.restart_panel() public.SetConfigValue('btco', True) public.SetConfigValue('btco_init', True) return public.returnMsg(True, '安装成功,感谢支持.') elif public.GetConfigValue('btco'): return public.returnMsg(True, '您已安装过了.') return public.returnMsg(False, '安装失败')
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) s_time_tmp = public.readFile(sess_out_path) if not s_time_tmp: s_time_tmp = '0' if int(s_time_tmp) != 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