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'] = u'与宝塔联合定制版' public.writeFile(pFile,json.dumps(pInfo)) tFile = panelPath + '/data/title.pl' titleNew = (pInfo['brand'] + u'面板').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 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 + '/static/language/Simplified_Chinese/public.json' pInfo = json.loads(public.readFile(pFile)) pInfo['BRAND'] = idcInfo['msg']['name'] pInfo['PRODUCT'] = public.GetMsg("WITH_BT_CUSTOM_EDITION") pInfo['NANE'] = pInfo['BRAND'] + pInfo['PRODUCT'] 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 == public.GetMsg("NAME") or title == '': public.writeFile(tFile, titleNew) else: public.writeFile(tFile, titleNew) return True except: pass
def getCloudPlugin(self, get): if hasattr(web.ctx.session, 'getCloudPlugin') and get != None: return public.returnMsg(True, '已是最新版本!') import json if not hasattr(web.ctx.session, 'downloadUrl'): web.ctx.session.downloadUrl = 'http://download.bt.cn' # 获取列表 try: newUrl = public.get_url() if os.path.exists('plugin/beta/config.conf'): downloadUrl = newUrl + '/install/list.json' else: downloadUrl = newUrl + '/install/list_new.json' data = json.loads(public.httpGet(downloadUrl)) web.ctx.session.downloadUrl = newUrl except: downloadUrl = web.ctx.session.downloadUrl + '/install/list_new.json' data = json.loads(public.httpGet(downloadUrl)) n = i = j = 0 lists = self.GetList(None) for i in range(len(data)): for pinfo in lists: if data[i]['name'] != pinfo['name']: continue data[i]['display'] = pinfo['display'] if data[i]['default']: get.name = data[i]['name'] self.install(get) public.writeFile(self.__list, json.dumps(data)) # 获取分类 try: downloadUrl = web.ctx.session.downloadUrl + '/install/type.json' types = json.loads(public.httpGet(downloadUrl)) public.writeFile(self.__type, json.dumps(types)) except: pass self.getCloudPHPExt(get) self.GetCloudWarning(get) web.ctx.session.getCloudPlugin = True return public.returnMsg(True, 'PLUGIN_UPDATE')
def _get_cloud_phplib(self): if not session.get('download_url'): session['download_url'] = 'http://download.bt.cn' download_url = session['download_url'] + '/install/lib/phplib_en.json' tstr = public.httpGet(download_url) data = json.loads(tstr) if not data: return False public.writeFile('data/phplib.conf', json.dumps(data)) return True
def GetIndex(self,get): try: if hasattr(web.ctx.session,'btyw'): return False; result = public.httpGet('https://www.bt.cn/lib/btyw.html'); public.writeFile('/www/server/panel/plugin/btyw/index.html',result); web.ctx.session.btyw = True; return True; except: return False;
def remove_waf_drop_ip(self, get): try: data = json.loads( public.httpGet('http://127.0.0.1/remove_btwaf_drop_ip?ip=' + get.ip)) self.__write_log('从防火墙解封IP【' + get.ip + '】') return data except: return public.returnMsg(False, '获取数据失败')
def GetPHPInfo(self, get): self.CheckPHPINFO() sPath = web.ctx.session.setupPath + '/phpinfo/' + get.version if not os.path.exists(sPath + '/phpinfo.php'): public.ExecShell("mkdir -p " + sPath) public.writeFile(sPath + '/phpinfo.php', '<?php phpinfo(); ?>') phpinfo = public.httpGet('http://127.0.0.2/' + get.version + '/phpinfo.php') return phpinfo
def GetPHPInfo(self,get): self.CheckPHPINFO(); sPath = web.ctx.session.setupPath + '/phpinfo/' + get.version; public.ExecShell("rm -rf /www/server/phpinfo/*"); public.ExecShell("mkdir -p " + sPath); public.writeFile(sPath + '/phpinfo.php','<?php phpinfo(); ?>'); phpinfo = public.httpGet('http://127.0.0.2/' + get.version + '/phpinfo.php'); os.system("rm -rf " + sPath); return phpinfo;
def getCloudPlugin(self,get): if hasattr(web.ctx.session,'getCloudPlugin') and get != None: return public.returnMsg(True,'您的插件列表已经是最新版本-1!'); import json if not hasattr(web.ctx.session,'downloadUrl'): web.ctx.session.downloadUrl = 'http://download.bt.cn'; #获取列表 try: newUrl = public.get_url(); if os.path.exists('plugin/beta/config.conf'): downloadUrl = newUrl + '/install/list.json' else: downloadUrl = newUrl + '/install/listTest.json' data = json.loads(public.httpGet(downloadUrl)) web.ctx.session.downloadUrl = newUrl; except: downloadUrl = web.ctx.session.downloadUrl + '/install/listTest.json' data = json.loads(public.httpGet(downloadUrl)) n = i = j = 0; lists = self.GetList(None); for i in range(len(data)): for pinfo in lists: if data[i]['name'] != pinfo['name']: continue; data[i]['display'] = pinfo['display']; if data[i]['default']: get.name = data[i]['name']; self.install(get); public.writeFile(self.__list,json.dumps(data)); #获取分类 try: downloadUrl = web.ctx.session.downloadUrl + '/install/type.json' types = json.loads(public.httpGet(downloadUrl)) public.writeFile(self.__type,json.dumps(types)); except: pass; self.getCloudPHPExt(get); self.GetCloudWarning(get); web.ctx.session.getCloudPlugin = True; return public.returnMsg(True,'PLUGIN_UPDATE');
def GetIndex(self, get): try: if hasattr(web.ctx.session, 'btyw'): return False result = public.httpGet('https://www.bt.cn/lib/btyw.html') public.writeFile('/www/server/panel/plugin/btyw/index.html', result) web.ctx.session.btyw = True return True except: return False
def GetPHPStatus(self,get): #取指定PHP版本的负载状态 self.CheckStatusConf(); import json,time,web version = web.input(version='54').version result = public.httpGet('http://127.0.0.1/phpfpm_'+version+'_status?json') tmp = json.loads(result) fTime = time.localtime(int(tmp['start time'])) tmp['start time'] = time.strftime('%Y-%m-%d %H:%M:%S',fTime) return tmp
def CheckDomain(self,get): try: epass = public.GetRandomString(32); spath = get.path + '/.well-known/pki-validation'; if not os.path.exists(spath): os.system("mkdir -p '" + spath + "'"); public.writeFile(spath + '/fileauth.txt',epass); result = public.httpGet('http://' + get.domain + '/.well-known/pki-validation/fileauth.txt'); if result == epass: return True return False except: return False
def panel_status(): time.sleep(1) panel_path = '/www/server/panel' pool = 'http://' if os.path.exists(panel_path + '/data/ssl.pl'): pool = 'https://' port = '8888' if os.path.exists(panel_path + '/data/port.pl'): port = public.readFile(panel_path + '/data/port.pl').strip() panel_url = pool + '127.0.0.1:' + port + '/service_status' panel_pid = get_panel_pid() n = 0 while True: time.sleep(1) if not panel_pid: panel_pid = get_panel_pid() if not panel_pid: run_panel() try: if psutil.Process(panel_pid).cmdline()[-1] != 'runserver:app': run_panel() time.sleep(3) panel_pid = get_panel_pid() continue except: run_panel() time.sleep(3) panel_pid = get_panel_pid() continue n += 1 if n > 18000: n = 0 result = public.httpGet(panel_url) if result == 'True': time.sleep(10) continue os.system("/etc/init.d/bt reload &") result = public.httpGet(panel_url) if result == 'True': public.WriteLog('守护程序', '检查到面板服务异常,已自动恢复!') time.sleep(10) continue
def getCloudPHPExt(self,get): import json try: if not hasattr(web.ctx.session,'downloadUrl'): web.ctx.session.downloadUrl = 'http://download.bt.cn'; downloadUrl = web.ctx.session.downloadUrl + '/install/lib/phplib.json' tstr = public.httpGet(downloadUrl) data = json.loads(tstr); if not data: return False; public.writeFile('data/phplib.conf',json.dumps(data)); return True; except: return False;
def GetCloudList(self,get): try: import web if not hasattr(web.ctx.session,'package'): downloadUrl = public.get_url() + '/install/lib/plugin/deployment/package.json'; tmp = json.loads(public.httpGet(downloadUrl)); if not tmp: return public.returnMsg(False,'从云端获取失败!'); jsonFile = self.__setupPath + '/list.json'; public.writeFile(jsonFile,json.dumps(tmp)); downloadUrl = public.get_url() + '/install/lib/plugin/deployment/type.json'; tmp = json.loads(public.httpGet(downloadUrl)); if not tmp: return public.returnMsg(False,'从云端获取失败!'); jsonFile = self.__setupPath + '/type.json'; public.writeFile(jsonFile,json.dumps(tmp)); web.ctx.session.package = True return public.returnMsg(True,'更新成功!'); return public.returnMsg(True,'无需更新!'); except: return public.returnMsg(False,'从云端获取失败!');
def getCloudPlugin(self,get): if hasattr(web.ctx.session,'getCloudPlugin') and get != None: return public.returnMsg(True,'您的插件列表已经是最新版本-1!'); import json if not hasattr(web.ctx.session,'downloadUrl'): web.ctx.session.downloadUrl = 'http://download.bt.cn'; #获取列表 try: newUrl = public.get_url(); downloadUrl = newUrl + '/install/list.json' data = json.loads(public.httpGet(downloadUrl)) web.ctx.session.downloadUrl = newUrl; except: downloadUrl = web.ctx.session.downloadUrl + '/install/list.json' data = json.loads(public.httpGet(downloadUrl)) n = i = j = 0; lists = self.GetList(None); for i in range(len(data)): for pinfo in lists: if data[i]['name'] != pinfo['name']: continue; data[i]['display'] = pinfo['display']; if data[i]['default']: get.name = data[i]['name']; self.install(get); public.writeFile(self.__list,json.dumps(data)); #获取分类 try: downloadUrl = web.ctx.session.downloadUrl + '/install/type.json' types = json.loads(public.httpGet(downloadUrl)) public.writeFile(self.__type,json.dumps(types)); except: pass; self.getCloudPHPExt(get); web.ctx.session.getCloudPlugin = True; return public.returnMsg(True,'PLUGIN_UPDATE');
def GetCloudList(self,get): try: jsonFile = self.__setupPath + '/deployment_list.json'; if not 'package' in session or not os.path.exists(jsonFile) or hasattr(get,'force'): downloadUrl = 'http://www.bt.cn/api/panel/get_deplist'; tmp = json.loads(public.httpGet(downloadUrl,3)); if not tmp: return public.returnMsg(False,'Failed to get from the cloud!'); public.writeFile(jsonFile,json.dumps(tmp)); session['package'] = True return public.returnMsg(True,'Update completed!'); return public.returnMsg(True,'No need to update!'); except: return public.returnMsg(False,'Failed to get from the cloud!');
def GetCloudList(self, get): try: import web if not hasattr(web.ctx.session, 'package'): downloadUrl = public.get_url( ) + '/install/lib/plugin/deployment/package.json' tmp = json.loads(public.httpGet(downloadUrl)) if not tmp: return public.returnMsg(False, '从云端获取失败!') jsonFile = self.__setupPath + '/list.json' public.writeFile(jsonFile, json.dumps(tmp)) downloadUrl = public.get_url( ) + '/install/lib/plugin/deployment/type.json' tmp = json.loads(public.httpGet(downloadUrl)) if not tmp: return public.returnMsg(False, '从云端获取失败!') jsonFile = self.__setupPath + '/type.json' public.writeFile(jsonFile, json.dumps(tmp)) web.ctx.session.package = True return public.returnMsg(True, '更新成功!') return public.returnMsg(True, '无需更新!') except: return public.returnMsg(False, '从云端获取失败!')
def GetNginxStatus(self,get): #取Nginx负载状态 self.CheckStatusConf(); result = public.httpGet('http://127.0.0.1/nginx_status') tmp = result.split() data = {} data['active'] = tmp[2] data['accepts'] = tmp[9] data['handled'] = tmp[7] data['requests'] = tmp[8] data['Reading'] = tmp[11] data['Writing'] = tmp[13] data['Waiting'] = tmp[15] return data
def panel_status(): time.sleep(1) panel_path = '/www/server/panel' pool = 'http://' if os.path.exists(panel_path + '/data/ssl.pl'): pool = 'https://' port = '8888' if os.path.exists(panel_path + '/data/port.pl'): port = public.readFile(panel_path + '/data/port.pl').strip() panel_url = pool + '127.0.0.1:' + port + '/service_status' while True: time.sleep(1) result = public.httpGet(panel_url) if result == 'True': time.sleep(10) continue os.system("/etc/init.d/bt reload &") result = public.httpGet(panel_url) if result == 'True': public.WriteLog('守护程序', '检查到面板服务异常,已自动恢复!') time.sleep(10) continue public.WriteLog('守护程序', '检查到面板服务异常,自动恢复失败!')
def getCloudPHPExt(self,get): import json try: if 'php_ext' in session: return True if not session.get('download_url'): session['download_url'] = 'http://download.bt.cn'; download_url = session['download_url'] + '/install/lib/phplib.json' tstr = public.httpGet(download_url) data = json.loads(tstr); if not data: return False; public.writeFile('data/phplib.conf',json.dumps(data)); session['php_ext'] = True return True; except: return False;
def GetCloudList(self, get): try: jsonFile = self.__setupPath + '/deployment_list.json' if not 'package' in session or not os.path.exists( jsonFile) or hasattr(get, 'force'): downloadUrl = 'http://www.bt.cn/api/panel/get_deplist' tmp = json.loads(public.httpGet(downloadUrl, 3)) if not tmp: return public.returnMsg(False, '从云端获取失败!') public.writeFile(jsonFile, json.dumps(tmp)) session['package'] = True return public.returnMsg(True, '更新成功!') return public.returnMsg(True, '无需更新!') except: return public.returnMsg(False, '从云端获取失败!')
def GetCloudWarning(self,get): import json if not hasattr(web.ctx.session,'downloadUrl'): web.ctx.session.downloadUrl = 'http://download.bt.cn'; downloadUrl = web.ctx.session.downloadUrl + '/install/warning.json' tstr = public.httpGet(downloadUrl) data = json.loads(tstr); if not data: return False; wfile = 'data/warning.json'; wlist = json.loads(public.readFile(wfile)); for i in range(len(data['data'])): for w in wlist['data']: if data['data'][i]['name'] != w['name']: continue; data['data'][i]['ignore_count'] = w['ignore_count']; data['data'][i]['ignore_time'] = w['ignore_time']; public.writeFile(wfile,json.dumps(data)); return data;
def sync_cnlist(self, get): if not get: self.get_config(None) self.get_site_config(None) rcnlist = public.httpGet(public.get_url() + '/cnlist.json') if not rcnlist: return public.returnMsg(False, '连接云端失败') cloudList = json.loads(rcnlist) cnlist = self.__get_rule('cn') n = 0 for ipd in cloudList: if ipd in cnlist: continue cnlist.append(ipd) n += 1 self.__write_rule('cn', cnlist) print('同步成功,本次共增加 ' + str(n) + ' 个IP段') if get: return public.returnMsg(True, '同步成功!')
def sync_rule(self): ''' @name 从云端同步规则 @author hwliang<2020-08-05> @return void ''' try: dep_path = '/www/server/panel/class/safe_warning' local_version_file = self.__path + '/version.pl' last_sync_time = local_version_file = self.__path + '/last_sync.pl' if os.path.exists(dep_path): if os.path.exists(last_sync_time): if int(public.readFile(last_sync_time)) > time.time(): return else: if os.path.exists(local_version_file): os.remove(local_version_file) download_url = public.get_url() version_url = download_url + '/install/warning/version.txt' cloud_version = public.httpGet(version_url) if cloud_version: cloud_version = cloud_version.strip() local_version = public.readFile(local_version_file) if local_version: if cloud_version == local_version: return tmp_file = '/tmp/bt_safe_warning.zip' public.ExecShell('wget -O {} {} -T 5'.format(tmp_file,download_url + '/install/warning/safe_warning_en.zip')) if not os.path.exists(tmp_file): return if os.path.getsize(tmp_file) < 2129: os.remove(tmp_file) return if not os.path.exists(dep_path): os.makedirs(dep_path,384) public.ExecShell("unzip -o {} -d {}/ >/dev/null".format(tmp_file,dep_path)) public.writeFile(local_version_file,cloud_version) public.writeFile(last_sync_time,str(int(time.time() + 7200))) if os.path.exists(tmp_file): os.remove(tmp_file) public.ExecShell("chmod -R 600 {}".format(dep_path)) except: pass
def check_php_version(version): url = 'http://127.0.0.1/phpfpm_'+version+'_status'; result = public.httpGet(url); #检查nginx if result.find('Bad Gateway') != -1: return False; #检查Apache if result.find('Service Unavailable') != -1: return False; if result.find('Not Found') != -1: check_phpinfo(); #检查Web服务是否启动 if result.find('Connection refused') != -1: global isTask if os.path.exists(isTask): isStatus = public.readFile(isTask); if isStatus == 'True': return True; filename = '/etc/init.d/nginx'; if os.path.exists(filename): os.system(filename + ' start'); filename = '/etc/init.d/httpd'; if os.path.exists(filename): os.system(filename + ' start'); return True;
def GetNginxStatus(self,get): try: if not os.path.exists('/www/server/nginx/sbin/nginx'): return public.returnMsg(False,'nginx is not install') process_cpu = {} worker = int(public.ExecShell("ps aux|grep nginx|grep 'worker process'|wc -l")[0])-1 workermen = int(public.ExecShell("ps aux|grep nginx|grep 'worker process'|awk '{memsum+=$6};END {print memsum}'")[0]) / 1024 for proc in psutil.process_iter(): if proc.name() == "nginx": self.GetProcessCpuPercent(proc.pid,process_cpu) time.sleep(0.1) #取Nginx负载状态 self.CheckStatusConf() result = public.httpGet('http://127.0.0.1/nginx_status') tmp = result.split() data = {} if "request_time" in tmp: data['accepts'] = tmp[8] data['handled'] = tmp[9] data['requests'] = tmp[10] data['Reading'] = tmp[13] data['Writing'] = tmp[15] data['Waiting'] = tmp[17] else: data['accepts'] = tmp[9] data['handled'] = tmp[7] data['requests'] = tmp[8] data['Reading'] = tmp[11] data['Writing'] = tmp[13] data['Waiting'] = tmp[15] data['active'] = tmp[2] data['worker'] = worker data['workercpu'] = round(float(process_cpu["nginx"]),2) data['workermen'] = "%s%s" % (int(workermen), "MB") return data except Exception as ex: public.WriteLog('GET_INFO','NGINX_LOAD_ERR',(ex,)) return public.returnMsg(False,'GET_DATA_ERR')
def checkPHPVersion(version): try: url = 'http://127.0.0.1/phpfpm_' + version + '_status' result = public.httpGet(url) #检查nginx if result.find('Bad Gateway') != -1: return False #检查Apache if result.find('Service Unavailable') != -1: return False if result.find('Not Found') != -1: CheckPHPINFO() #检查Web服务是否启动 if result.find('Connection refused') != -1: global isTask if os.path.exists(isTask): isStatus = public.readFile(isTask) if isStatus == 'True': return True filename = '/etc/init.d/nginx' if os.path.exists(filename): os.system(filename + ' start') filename = '/etc/init.d/httpd' if os.path.exists(filename): os.system(filename + ' start') return True except: return True
def checkPHPVersion(version): try: url = 'http://127.0.0.1/phpfpm_'+version+'_status'; result = public.httpGet(url); #检查nginx if result.find('Bad Gateway') != -1: return False; #检查Apache if result.find('Service Unavailable') != -1: return False; if result.find('Not Found') != -1: CheckPHPINFO(); #检查Web服务是否启动 if result.find('Connection refused') != -1: global isTask if os.path.exists(isTask): isStatus = public.readFile(isTask); if isStatus == 'True': return True; filename = '/etc/init.d/nginx'; if os.path.exists(filename): os.system(filename + ' start'); filename = '/etc/init.d/httpd'; if os.path.exists(filename): os.system(filename + ' start'); return True; except: return True;
def crate_let_by_file(self, data): result = {} result['status'] = False result['clecks'] = [] try: log_level = "INFO" if data['account_key']: log_level = 'ERROR' if not data['email']: data['email'] = public.M('users').getField('email') client = sewer.Client(domain_name=data['first_domain'], dns_class=None, account_key=data['account_key'], domain_alt_names=data['domains'], contact_email=str(data['email']), LOG_LEVEL=log_level, ACME_AUTH_STATUS_WAIT_PERIOD=15, ACME_AUTH_STATUS_MAX_CHECKS=5, ACME_REQUEST_TIMEOUT=20, ACME_DIRECTORY_URL=self.let_url) client.acme_register() authorizations, finalize_url = client.apply_for_cert_issuance() responders = [] sucess_domains = [] for url in authorizations: identifier_auth = self.get_identifier_authorization( client, url) authorization_url = identifier_auth["url"] http_name = identifier_auth["domain"] http_token = identifier_auth["http_token"] http_challenge_url = identifier_auth["http_challenge_url"] acme_keyauthorization, domain_http_value = client.get_keyauthorization( http_token) acme_dir = '%s/.well-known/acme-challenge' % (data['site_dir']) if not os.path.exists(acme_dir): os.makedirs(acme_dir) #写入token wellknown_path = acme_dir + '/' + http_token public.writeFile(wellknown_path, acme_keyauthorization) wellknown_url = "http://{0}/.well-known/acme-challenge/{1}".format( http_name, http_token) result['clecks'].append({ 'wellknown_url': wellknown_url, 'http_token': http_token }) is_check = False n = 0 while n < 5: print("wait_check_authorization_status") try: retkey = public.httpGet(wellknown_url, 20) if retkey == acme_keyauthorization: is_check = True break except: pass n += 1 time.sleep(1) sucess_domains.append(http_name) responders.append({ "authorization_url": authorization_url, "acme_keyauthorization": acme_keyauthorization, "http_challenge_url": http_challenge_url }) if len(sucess_domains) > 0: #验证 for i in responders: auth_status_response = client.check_authorization_status( i["authorization_url"]) if auth_status_response.json()["status"] == "pending": client.respond_to_challenge( i["acme_keyauthorization"], i["http_challenge_url"]).json() for i in responders: client.check_authorization_status(i["authorization_url"], ["valid", "invalid"]) certificate_url = client.send_csr(finalize_url) certificate = client.download_certificate(certificate_url) if certificate: certificate = self.split_ca_data(certificate) result['cert'] = certificate['cert'] result['ca_data'] = certificate['ca_data'] result['key'] = client.certificate_key result['account_key'] = client.account_key result['status'] = True else: result['msg'] = '证书获取失败,请稍后重试.' else: result[ 'msg'] = "签发失败,我们无法验证您的域名:<p>1、检查域名是否绑定到对应站点</p><p>2、检查域名是否正确解析到本服务器,或解析还未完全生效</p><p>3、如果您的站点设置了反向代理,或使用了CDN,请先将其关闭</p><p>4、如果您的站点设置了301重定向,请先将其关闭</p><p>5、如果以上检查都确认没有问题,请尝试更换DNS服务商</p>'" except Exception as e: res = str(e).split('>>>>') err = False try: err = json.loads(res[1]) except: err = False result['msg'] = [self.get_error(res[0]), err] return result
def GetAd(self,get): try: return public.httpGet(web.ctx.session.home + '/Api/GetAD?name='+get.name + '&soc=' + get.soc); except: return '';
def crate_let_by_file(self,data): result = {} result['status'] = False result['clecks'] = [] try: log_level = "INFO" if data['account_key']: log_level = 'ERROR' if not data['email']: data['email'] = public.M('users').getField('email') client = sewer.Client(domain_name = data['first_domain'],dns_class = None,account_key = data['account_key'],domain_alt_names = data['domains'],contact_email = str(data['email']),LOG_LEVEL = log_level,ACME_AUTH_STATUS_WAIT_PERIOD = 15,ACME_AUTH_STATUS_MAX_CHECKS = 5,ACME_REQUEST_TIMEOUT = 20,ACME_DIRECTORY_URL = self.let_url) client.acme_register() authorizations, finalize_url = client.apply_for_cert_issuance() responders = [] sucess_domains = [] for url in authorizations: identifier_auth = self.get_identifier_authorization(client,url) authorization_url = identifier_auth["url"] http_name = identifier_auth["domain"] http_token = identifier_auth["http_token"] http_challenge_url = identifier_auth["http_challenge_url"] acme_keyauthorization, domain_http_value = client.get_keyauthorization(http_token) acme_dir = '%s/.well-known/acme-challenge' % (data['site_dir']); if not os.path.exists(acme_dir): os.makedirs(acme_dir) #写入token wellknown_path = acme_dir + '/' + http_token public.writeFile(wellknown_path,acme_keyauthorization) wellknown_url = "http://{0}/.well-known/acme-challenge/{1}".format(http_name, http_token) result['clecks'].append({'wellknown_url':wellknown_url,'http_token':http_token}); is_check = False n = 0 while n < 5: print("wait_check_authorization_status") try: retkey = public.httpGet(wellknown_url,20) if retkey == acme_keyauthorization: is_check = True break except : pass n += 1 time.sleep(1) sucess_domains.append(http_name) responders.append({"authorization_url": authorization_url, "acme_keyauthorization": acme_keyauthorization,"http_challenge_url": http_challenge_url}) if len(sucess_domains) > 0: #验证 for i in responders: auth_status_response = client.check_authorization_status(i["authorization_url"]) if auth_status_response.json()["status"] == "pending": client.respond_to_challenge(i["acme_keyauthorization"], i["http_challenge_url"]).json() for i in responders: client.check_authorization_status(i["authorization_url"], ["valid","invalid"]) certificate_url = client.send_csr(finalize_url) certificate = client.download_certificate(certificate_url) if certificate: certificate = self.split_ca_data(certificate) result['cert'] = certificate['cert'] result['ca_data'] = certificate['ca_data'] result['key'] = client.certificate_key result['account_key'] = client.account_key result['status'] = True else: result['msg'] = 'Certificate acquisition failed, please try again later.' else: result['msg'] = "The signing failed, we were unable to verify your domain name:<p>1. Check if the domain name is bound to the corresponding site.</p><p>2. Check if the domain name is correctly resolved to the server, or the resolution is not fully effective.</p><p>3. If your site has a reverse proxy set up, or if you are using a CDN, please turn it off first.</p><p>4. If your site has a 301 redirect, please turn it off first</p><p>5. If the above checks confirm that there is no problem, please try to change the DNS service provider.</p>'" except Exception as e: res = str(e).split('>>>>') err = False try: err = json.loads(res[1]) except: err = False result['msg'] = [self.get_error(res[0]),err] return result
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 GetCloudHtml(self,get): data = public.httpGet('https://www.bt.cn/' + get.rpath) return data;