def Completed(self,get): self.__PDATA['data']['partnerOrderId'] = get.partnerOrderId; self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); if hasattr(get,'siteName'): get.path = public.M('sites').where('name=?',(get.siteName,)).getField('path'); runPath = self.GetRunPath(get); if runPath != False and runPath != '/': get.path += runPath; sslInfo = json.loads(public.httpPost(self.__APIURL + '/SyncOrder',self.__PDATA)); sslInfo['data'] = self.En_Code(sslInfo['data']); try: spath = get.path + '/.well-known/pki-validation'; if not os.path.exists(spath): os.system("mkdir -p '" + spath + "'"); public.writeFile(spath + '/fileauth.txt',sslInfo['data']['authValue']); except: return public.returnMsg(False,'SSL_CHECK_WRITE_ERR'); try: result = json.loads(public.httpPost(self.__APIURL + '/Completed',self.__PDATA)); except: result = public.returnMsg(True,'CHECKING') n = 0; my_ok = False while True: if n > 5: break; time.sleep(5); rRet = json.loads(public.httpPost(self.__APIURL + '/SyncOrder',self.__PDATA)); n +=1 rRet['data'] = self.En_Code(rRet['data']); try: if rRet['data']['stateCode'] == 'COMPLETED': my_ok = True break; except: return public.get_error_info() if not my_ok: return result; return rRet;
def depTotal(self,id): import panelAuth p = panelAuth.panelAuth() pdata = p.create_serverid(None); pdata['pid'] = id; p_url = 'http://www.bt.cn/api/pluginother/create_order_okey' public.httpPost(p_url,pdata)
def SyncOrder(self, get): self.__PDATA['data']['partnerOrderId'] = get.partnerOrderId self.__PDATA['data'] = self.De_Code(self.__PDATA['data']) result = json.loads( public.httpPost(self.__APIURL + '/SyncOrder', self.__PDATA)) result['data'] = self.En_Code(result['data']) return result
def SubmitSetScore(self,key,value): self.CheckToken(); self.__PDATA['data'][key] = value self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = json.loads(public.httpPost(self.__APIURL+'/SetSocre',self.__PDATA)); result['data'] = self.En_Code(result['data']); return result;
def is_pro(self, get): import panelAuth, json pdata = panelAuth.panelAuth().create_serverid(None) url = public.GetConfigValue('home') + '/api/panel/is_pro' pluginTmp = public.httpPost(url, pdata) pluginInfo = json.loads(pluginTmp) return pluginInfo
def Completed(self,get): self.__PDATA['data']['partnerOrderId'] = get.partnerOrderId; self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); if hasattr(get,'siteName'): get.path = public.M('sites').where('name=?',(get.siteName,)).getField('path'); runPath = self.GetRunPath(get); if runPath != False and runPath != '/': get.path += runPath; sslInfo = json.loads(public.httpPost(self.__APIURL + '/SyncOrder',self.__PDATA)); sslInfo['data'] = self.En_Code(sslInfo['data']); try: public.writeFile(get.path + '/.well-known/pki-validation/fileauth.txt',sslInfo['data']['authValue']); except: return public.returnMsg(False,'SSL_CHECK_WRITE_ERR'); result = json.loads(public.httpPost(self.__APIURL + '/Completed',self.__PDATA)); result['data'] = self.En_Code(result['data']); return result;
def GetSSLInfo(self,get): self.__PDATA['data']['partnerOrderId'] = get.partnerOrderId; self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = json.loads(public.httpPost(self.__APIURL + '/GetSSLInfo',self.__PDATA)); result['data'] = self.En_Code(result['data']); #写配置到站点 if hasattr(get,'siteName'): try: siteName = get.siteName; path = '/etc/letsencrypt/live/'+ siteName; if not os.path.exists(path): public.ExecShell('mkdir -p ' + path) csrpath = path+"/fullchain.pem"; keypath = path+"/privkey.pem"; pidpath = path+"/partnerOrderId"; #清理旧的证书链 public.ExecShell('rm -f ' + keypath) public.ExecShell('rm -f ' + csrpath) public.ExecShell('rm -rf ' + path + '-00*') public.ExecShell('rm -rf /etc/letsencrypt/archive/' + get.siteName) public.ExecShell('rm -rf /etc/letsencrypt/archive/' + get.siteName + '-00*') public.ExecShell('rm -f /etc/letsencrypt/renewal/'+ get.siteName + '.conf') public.ExecShell('rm -f /etc/letsencrypt/renewal/'+ get.siteName + '-00*.conf') public.ExecShell('rm -f ' + path + '/README'); public.writeFile(keypath,result['data']['privateKey']); public.writeFile(csrpath,result['data']['cert']+result['data']['certCa']); public.writeFile(pidpath,get.partnerOrderId); import panelSite panelSite.panelSite().SetSSLConf(get); public.serviceReload(); return public.returnMsg(True,'SET_SUCCESS'); except Exception,ex: return public.returnMsg(False,'SET_ERROR,' + str(ex));
def GetDVSSL(self, get): get.id = public.M('domain').where('name=?', (get.domain, )).getField('pid') if hasattr(get, 'siteName'): get.path = public.M('sites').where('id=?', (get.id, )).getField('path') else: get.siteName = public.M('sites').where('id=?', (get.id, )).getField('name') runPath = self.GetRunPath(get) if runPath != False and runPath != '/': get.path += runPath authfile = get.path + '/.well-known/pki-validation/fileauth.txt' if not self.CheckDomain(get): if not os.path.exists(authfile): return public.returnMsg(False, '无法创建[' + authfile + ']') action = 'GetDVSSL' if hasattr(get, 'partnerOrderId'): self.__PDATA['data']['partnerOrderId'] = get.partnerOrderId action = 'ReDVSSL' self.__PDATA['data']['domain'] = get.domain self.__PDATA['data'] = self.De_Code(self.__PDATA['data']) result = public.httpPost(self.__APIURL + '/' + action, self.__PDATA) try: result = json.loads(result) except: return result result['data'] = self.En_Code(result['data']) if hasattr(result['data'], 'authValue'): public.writeFile(authfile, result['data']['authValue']) return result
def GetDVSSL(self,get): get.id = public.M('domain').where('name=?',(get.domain,)).getField('pid'); if hasattr(get,'siteName'): get.path = public.M('sites').where('id=?',(get.id,)).getField('path'); else: get.siteName = public.M('sites').where('id=?',(get.id,)).getField('name'); if get.domain[:4] == 'www.': if not public.M('domain').where('name=?',(get.domain[4:],)).count(): return public.returnMsg(False,"申请[%s]证书需要验证[%s]请将[%s]绑定并解析到站点!" % (get.domain,get.domain[4:],get.domain[4:])) runPath = self.GetRunPath(get); if runPath != False and runPath != '/': get.path += runPath; authfile = get.path + '/.well-known/pki-validation/fileauth.txt'; if not self.CheckDomain(get): if not os.path.exists(authfile): return public.returnMsg(False,'无法创建['+authfile+']'); action = 'GetDVSSL'; if hasattr(get,'partnerOrderId'): self.__PDATA['data']['partnerOrderId'] = get.partnerOrderId; action = 'ReDVSSL'; self.__PDATA['data']['domain'] = get.domain; self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = public.httpPost(self.__APIURL + '/' + action,self.__PDATA) try: result = json.loads(result); except: return result; result['data'] = self.En_Code(result['data']); if hasattr(result['data'],'authValue'): public.writeFile(authfile,result['data']['authValue']); return result;
def GetDVSSL(self,get): get.id = public.M('domain').where('name=?',(get.domain,)).getField('pid') if hasattr(get,'siteName'): get.path = public.M('sites').where('id=?',(get.id,)).getField('path') else: get.siteName = public.M('sites').where('id=?',(get.id,)).getField('name') if get.domain[:4] == 'www.': if not public.M('domain').where('name=?',(get.domain[4:],)).count(): return public.returnMsg(False,"Apply for [%s] certificate to verify [%s] Please bind [%s] and resolve to the site!" % (get.domain,get.domain[4:],get.domain[4:])) runPath = self.GetRunPath(get) if runPath != False and runPath != '/': get.path += runPath authfile = get.path + '/.well-known/pki-validation/fileauth.txt' if not self.CheckDomain(get): if not os.path.exists(authfile): return public.returnMsg(False,'CANT_CREATE',(authfile,)) action = 'GetDVSSL' if hasattr(get,'partnerOrderId'): self.__PDATA['data']['partnerOrderId'] = get.partnerOrderId action = 'ReDVSSL' self.__PDATA['data']['domain'] = get.domain self.__PDATA['data'] = self.De_Code(self.__PDATA['data']) result = public.httpPost(self.__APIURL + '/' + action,self.__PDATA) try: result = json.loads(result) except: return result result['data'] = self.En_Code(result['data']) if hasattr(result['data'],'authValue'): public.writeFile(authfile,result['data']['authValue']) return result
def GetToken(self, get): rtmp = "" data = {} data['identification'] = self.en_code_rsa(get.username) data['password'] = self.en_code_rsa(get.password) data['from_panel'] = self.en_code_rsa('1') try: rtmp = public.httpPost(self.__APIURL + '/login', data) result = json.loads(rtmp) if result['success']: bind = 'data/bind.pl' if os.path.exists(bind): os.remove(bind) userinfo = result['res']['user_data'] userinfo['token'] = result['res']['access_token'] public.writeFile(self.__UPATH, json.dumps(userinfo)) session['focre_cloud'] = True return public.returnMsg(True, 'Bind successfully') else: return public.returnMsg( False, 'Invalid username or email or password! please check and try again!' ) except Exception as ex: bind = 'data/bind.pl' if os.path.exists(bind): os.remove(bind) return public.returnMsg( False, '%s<br>%s' % (public.GetMsg("CONNECT_ERR"), str(rtmp)))
def GetServerInfo(self,get): #self.SendToken(); self.__init__(); self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = json.loads(public.httpPost(self.__APIURL + '/GetServerInfo',self.__PDATA)); result['data'] = self.En_Code(result['data']); return result;
def GetScore(self, get): self.CheckToken() self.__PDATA['data'] = self.De_Code(self.__PDATA['data']) result = json.loads( public.httpPost(self.__APIURL + '/GetSocre', self.__PDATA)) result['data'] = self.En_Code(result['data']) return result
def GetOrderList(self, get): if hasattr(get, 'siteName'): path = '/etc/letsencrypt/live/' + get.siteName + '/partnerOrderId' if os.path.exists(path): self.__PDATA['data']['partnerOrderId'] = public.readFile(path) else: path = '/www/server/panel/vhost/cert/' + get.siteName + '/partnerOrderId' if os.path.exists(path): self.__PDATA['data']['partnerOrderId'] = public.readFile( path) self.__PDATA['data'] = self.De_Code(self.__PDATA['data']) rs = public.httpPost(self.__APIURL + '/GetSSLList', self.__PDATA) try: result = json.loads(rs) except: return public.returnMsg(False, 'Failed to get, please try again later!') result['data'] = self.En_Code(result['data']) for i in range(len(result['data'])): result['data'][i]['endtime'] = self.add_months( result['data'][i]['createTime'], result['data'][i]['validityPeriod']) return result
def get_order_stat(self, get): pdata = self.create_serverid(get) pdata['order_id'] = get.oid p_url = public.GetConfigValue('home') + '/api/Pluginother/order_stat' if get.type == '1': p_url = public.GetConfigValue( 'home') + '/api/Pluginother/re_order_stat' return json.loads(public.httpPost(p_url, pdata))
def request(self, dname): self.__PDATA['data'] = json.dumps(self.__PDATA['data']) try: result = public.httpPost(self.__APIURL2 + '/' + dname, self.__PDATA) result = json.loads(result) except: pass return result
def create_plugin_other_order(self,get): pdata = self.create_serverid(get) pdata['pid'] = get.pid pdata['cycle'] = get.cycle p_url = public.GetConfigValue('home') + '/api/Pluginother/create_order' if get.type == '1': pdata['renew'] = 1 p_url = public.GetConfigValue('home') + '/api/Pluginother/renew_order' return json.loads(public.httpPost(p_url,pdata))
def request(self, dname): self.__PDATA['data'] = json.dumps(self.__PDATA['data']) result = public.returnMsg( False, 'The request failed, please try again later!') try: result = public.httpPost(self.__APIURL2 + '/' + dname, self.__PDATA) result = json.loads(result) except: pass return result
def SetBeta(self,get): data = {} data['username'] = get.bbs_name data['qq'] = get.qq data['email'] = get.email result = public.httpPost(public.GetConfigValue('home') + '/Api/LinuxBeta',data) import json data = json.loads(result) if data['status']: public.writeFile('data/beta.pl',get.bbs_name + '|' + get.qq + '|' + get.email) return data
def SetConfig(self,get): data = {} data['username'] = get.bbs_name data['qq'] = get.qq data['email'] = get.email result = public.httpPost('https://www.bt.cn/Api/LinuxBeta',data); import json; data = json.loads(result); if data['status']: public.writeFile(self.__setupPath + '/config.conf',get.bbs_name + '|' + get.qq + '|' + get.email); return data;
def SetBeta(self,get): data = {} data['username'] = get.bbs_name data['qq'] = get.qq data['email'] = get.email result = public.httpPost(web.ctx.session.home + '/Api/LinuxBeta',data); import json; data = json.loads(result); if data['status']: public.writeFile('data/beta.pl',get.bbs_name + '|' + get.qq + '|' + get.email); return data;
def GetToken(self,get): data = {} data['username'] = get.username; data['password'] = public.md5(get.password); pdata = {} pdata['data'] = self.De_Code(data); result = json.loads(public.httpPost(self.__APIURL+'/GetToken',pdata)); result['data'] = self.En_Code(result['data']); if result['data']: public.writeFile(self.__UPATH,json.dumps(result['data'])); del(result['data']); return result;
def send_baota2(self, filename): cloudUrl = 'http://www.bt.cn/api/panel/btwaf_submit' pdata = { 'codetxt': public.ReadFile(filename), 'md5': self.read_file_md5(filename), 'type': '0', 'host_ip': public.GetLocalIp(), 'size': os.path.getsize(filename) } ret = public.httpPost(cloudUrl, pdata) return True
def SubmitScore(self,get): try: self.CheckToken(); pdata = self.GetConfig(get); if not pdata['total_score']: return public.returnMsg(False,'请先跑分!'); pdata['secret_key'] = self.__PDATA['data']['secret_key']; self.__PDATA['data'] = self.De_Code(pdata); result = json.loads(public.httpPost(self.__APIURL+'/SubmitScore',self.__PDATA)); result['data'] = self.En_Code(result['data']); return result; except: return None;
def SetConfig(self, get): data = {} data['username'] = get.bbs_name data['qq'] = get.qq data['email'] = get.email result = public.httpPost('http://www.bt.cn/Api/LinuxBeta', data) import json data = json.loads(result) if data['status']: public.writeFile(self.__setupPath + '/config.conf', get.bbs_name + '|' + get.qq + '|' + get.email) return data
def SubmitScore(self,get): try: self.CheckToken(); pdata = self.GetConfig(get); if not pdata['total_score']: return public.returnMsg(False,'请先跑分!'); pdata['secret_key'] = self.__userInfo['secret_key']; self.__PDATA['data'] = self.De_Code(pdata); result = json.loads(public.httpPost(self.__APIURL+'/SubmitScore',self.__PDATA)); result['data'] = self.En_Code(result['data']); return result; except: return None;
def GetOrderList(self,get): if hasattr(get,'siteName'): path = '/etc/letsencrypt/live/'+ get.siteName + '/partnerOrderId'; if os.path.exists(path): self.__PDATA['data']['partnerOrderId'] = public.readFile(path); self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = json.loads(public.httpPost(self.__APIURL + '/GetSSLList',self.__PDATA)); result['data'] = self.En_Code(result['data']); for i in range(len(result['data'])): result['data'][i]['endtime'] = self.add_months(result['data'][i]['createTime'],result['data'][i]['validityPeriod']) return result;
def send_baota(self, filename): if not os.path.exists(filename): return False cloudUrl = 'http://www.bt.cn/api/panel/btwaf_submit' pdata = {'codetxt': public.ReadFile(filename), 'md5': self.read_file_md5(filename), 'type': '0', 'host_ip': public.GetLocalIp(), 'size': os.path.getsize(filename)} ret = public.httpPost(cloudUrl, pdata) if ret == '1': return self.check_webshell(filename) elif ret == '-1': return self.check_webshell(filename) else: return False
def GetDVSSL(self,get): get.id = public.M('domain').where('name',get.domain).getField('pid'); get.siteName = public.M('sites').where('id',get.id).getField('name'); runPath = self.GetRunPath(get); if runPath != False and runPath != '/': get.path += runPath; if not self.CheckDomain(get): return public.returnMsg(False,'SSL_CHECK_DNS_ERR',(get.domain,)); self.__PDATA['data']['domain'] = get.domain; self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = json.loads(public.httpPost(self.__APIURL + '/GetDVSSL',self.__PDATA)); result['data'] = self.En_Code(result['data']); if hasattr(result['data'],'authValue'): public.writeFile(get.path + '/.well-known/pki-validation/fileauth.txt',result['data']['authValue']); return result;
def check_webshell(self, filename): if not os.path.exists(filename): return False cloudUrl = 'http://www.bt.cn/api/panel/btwaf_check_file' pdata = {'md5': self.read_file_md5(filename), 'size': os.path.getsize(filename)} ret = public.httpPost(cloudUrl, pdata) if ret == '0': return False elif ret == '1': return False elif ret == '-1': return False else: return False
def GetToken(self,get): data = {} data['username'] = get.username; data['password'] = public.md5(get.password); data['o'] = ''; filename = '/www/server/panel/data/o.pl' if os.path.exists(filename): data['o'] = str(public.readFile(filename)) pdata = {} pdata['data'] = self.De_Code(data); result = json.loads(public.httpPost(self.__APIURL+'/GetToken',pdata)); result['data'] = self.En_Code(result['data']); if result['data']: public.writeFile(self.__UPATH,json.dumps(result['data'])); del(result['data']); return result;
def send_cloud(self,module,params): try: cloudURL = 'http://www.bt.cn/api/Plugin/'; userInfo = self.create_serverid(None); if 'status' in userInfo: params['uid'] = 0; params['serverid'] = ''; else: params['uid'] = userInfo['uid']; params['serverid'] = userInfo['serverid']; result = public.httpPost(cloudURL + module,params); result = json.loads(result.strip()); if not result: return None; return result; except: return None
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 GetSSLProduct(self,get): self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = json.loads(public.httpPost(self.__APIURL + '/GetSSLProduct',self.__PDATA)); result['data'] = self.En_Code(result['data']); return result;
def GetScore(self,get): self.CheckToken(); self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = json.loads(public.httpPost(self.__APIURL+'/GetSocre',self.__PDATA)); result['data'] = self.En_Code(result['data']); return result;
def SyncOrder(self,get): self.__PDATA['data']['partnerOrderId'] = get.partnerOrderId; self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = json.loads(public.httpPost(self.__APIURL + '/SyncOrder',self.__PDATA)); result['data'] = self.En_Code(result['data']); return result;
def get_node_list(self,get): self.__PDATA['data'] = self.De_Code(self.__PDATA['data']); result = json.loads(public.httpPost(self.__APIURL + '/GetNodeList',self.__PDATA)); result['data'] = self.En_Code(result['data']); return result;