def setPathInfo(self, get): #设置PATH_INFO version = get.version type = get.type if public.get_webserver() == 'nginx': path = public.GetConfigValue( 'setup_path') + '/nginx/conf/enable-php-' + version + '.conf' conf = public.readFile(path) rep = "\s+#*include\s+pathinfo.conf;" if type == 'on': conf = re.sub(rep, '\n\t\t\tinclude pathinfo.conf;', conf) else: conf = re.sub(rep, '\n\t\t\t#include pathinfo.conf;', conf) public.writeFile(path, conf) public.serviceReload() path = public.GetConfigValue( 'setup_path') + '/php/' + version + '/etc/php.ini' conf = public.readFile(path) rep = "\n*\s*cgi\.fix_pathinfo\s*=\s*([0-9]+)\s*\n" status = '0' if type == 'on': status = '1' conf = re.sub(rep, "\ncgi.fix_pathinfo = " + status + "\n", conf) public.writeFile(path, conf) public.WriteLog("TYPE_PHP", "PHP_PATHINFO_SUCCESS", (version, type)) public.phpReload(version) return public.returnMsg(True, 'SET_SUCCESS')
def disable_putenv(fun_name): try: is_set_disable = '/www/server/panel/data/disable_%s' % fun_name if os.path.exists(is_set_disable): return True php_vs = ('52', '53', '54', '55', '56', '70', '71', '72', '73', '74') php_ini = "/www/server/php/{0}/etc/php.ini" rep = "disable_functions\s*=\s*.*" for pv in php_vs: php_ini_path = php_ini.format(pv) if not os.path.exists(php_ini_path): continue php_ini_body = public.readFile(php_ini_path) tmp = re.search(rep, php_ini_body) if not tmp: continue disable_functions = tmp.group() if disable_functions.find(fun_name) != -1: continue print(disable_functions) php_ini_body = php_ini_body.replace( disable_functions, disable_functions + ',%s' % fun_name) php_ini_body.find(fun_name) public.writeFile(php_ini_path, php_ini_body) public.phpReload(pv) public.writeFile(is_set_disable, 'True') return True except: return False
def setPHPMaxSize(self, get): version = get.version max = get.max if int(max) < 2: return public.returnMsg(False, 'PHP_UPLOAD_MAX_ERR') #设置PHP path = public.GetConfigValue( 'setup_path') + '/php/' + version + '/etc/php.ini' conf = public.readFile(path) rep = u"\nupload_max_filesize\s*=\s*[0-9]+M" conf = re.sub(rep, u'\nupload_max_filesize = ' + max + 'M', conf) rep = u"\npost_max_size\s*=\s*[0-9]+M" conf = re.sub(rep, u'\npost_max_size = ' + max + 'M', conf) public.writeFile(path, conf) if public.get_webserver() == 'nginx': #设置Nginx path = public.GetConfigValue( 'setup_path') + '/nginx/conf/nginx.conf' conf = public.readFile(path) rep = "client_max_body_size\s+([0-9]+)m" tmp = re.search(rep, conf).groups() if int(tmp[0]) < int(max): conf = re.sub(rep, 'client_max_body_size ' + max + 'm', conf) public.writeFile(path, conf) public.serviceReload() public.phpReload(version) public.WriteLog("TYPE_PHP", "PHP_UPLOAD_MAX", (version, max)) return public.returnMsg(True, 'SET_SUCCESS')
def setFpmConfig(self, get): version = get.version max_children = get.max_children start_servers = get.start_servers min_spare_servers = get.min_spare_servers max_spare_servers = get.max_spare_servers pm = get.pm file = web.ctx.session.setupPath + "/php/" + version + "/etc/php-fpm.conf" conf = public.readFile(file) rep = "\s*pm.max_children\s*=\s*([0-9]+)\s*" conf = re.sub(rep, "\npm.max_children = " + max_children, conf) rep = "\s*pm.start_servers\s*=\s*([0-9]+)\s*" conf = re.sub(rep, "\npm.start_servers = " + start_servers, conf) rep = "\s*pm.min_spare_servers\s*=\s*([0-9]+)\s*" conf = re.sub(rep, "\npm.min_spare_servers = " + min_spare_servers, conf) rep = "\s*pm.max_spare_servers \s*=\s*([0-9]+)\s*" conf = re.sub(rep, "\npm.max_spare_servers = " + max_spare_servers + "\n", conf) rep = "\s*pm\s*=\s*(\w+)\s*" conf = re.sub(rep, "\npm = " + pm + "\n", conf) public.writeFile(file, conf) public.phpReload(version) public.WriteLog("TYPE_PHP", 'PHP_CHILDREN', (version, max_children, start_servers, min_spare_servers, max_spare_servers)) return public.returnMsg(True, 'SET_SUCCESS')
def setPathInfo(self,get): #设置PATH_INFO version = get.version type = get.type if public.get_webserver() == 'nginx': path = web.ctx.session.setupPath+'/nginx/conf/enable-php-'+version+'.conf'; conf = public.readFile(path); rep = "\s+#*include\s+pathinfo.conf;"; if type == 'on': conf = re.sub(rep,'\n\t\t\tinclude pathinfo.conf;',conf) else: conf = re.sub(rep,'\n\t\t\t#include pathinfo.conf;',conf) public.writeFile(path,conf) public.serviceReload(); path = web.ctx.session.setupPath+'/php/'+version+'/etc/php.ini'; conf = public.readFile(path); rep = "\n*\s*cgi\.fix_pathinfo\s*=\s*([0-9]+)\s*\n"; status = '0' if type == 'on':status = '1' conf = re.sub(rep,"\ncgi.fix_pathinfo = "+status+"\n",conf) public.writeFile(path,conf) public.WriteLog("TYPE_PHP", "PHP_PATHINFO_SUCCESS",(version,type)); public.phpReload(version); return public.returnMsg(True,'SET_SUCCESS');
def setFpmConfig(self,get): version = get.version max_children = get.max_children start_servers = get.start_servers min_spare_servers = get.min_spare_servers max_spare_servers = get.max_spare_servers pm = get.pm file = web.ctx.session.setupPath+"/php/"+version+"/etc/php-fpm.conf"; conf = public.readFile(file); rep = "\s*pm.max_children\s*=\s*([0-9]+)\s*"; conf = re.sub(rep, "\npm.max_children = "+max_children, conf); rep = "\s*pm.start_servers\s*=\s*([0-9]+)\s*"; conf = re.sub(rep, "\npm.start_servers = "+start_servers, conf); rep = "\s*pm.min_spare_servers\s*=\s*([0-9]+)\s*"; conf = re.sub(rep, "\npm.min_spare_servers = "+min_spare_servers, conf); rep = "\s*pm.max_spare_servers \s*=\s*([0-9]+)\s*"; conf = re.sub(rep, "\npm.max_spare_servers = "+max_spare_servers+"\n", conf); rep = "\s*pm\s*=\s*(\w+)\s*"; conf = re.sub(rep, "\npm = "+pm+"\n", conf); public.writeFile(file,conf) public.phpReload(version); public.WriteLog("TYPE_PHP",'PHP_CHILDREN', (version,max_children,start_servers,min_spare_servers,max_spare_servers)); return public.returnMsg(True, 'SET_SUCCESS');
def setPHPMaxSize(self,get): version = get.version max = get.max if int(max) < 2: return public.returnMsg(False,'PHP_UPLOAD_MAX_ERR') #设置PHP path = web.ctx.session.setupPath+'/php/'+version+'/etc/php.ini' conf = public.readFile(path) rep = u"\nupload_max_filesize\s*=\s*[0-9]+M" conf = re.sub(rep,u'\nupload_max_filesize = '+max+'M',conf) rep = u"\npost_max_size\s*=\s*[0-9]+M" conf = re.sub(rep,u'\npost_max_size = '+max+'M',conf) public.writeFile(path,conf) if public.get_webserver() == 'nginx': #设置Nginx path = web.ctx.session.setupPath+'/nginx/conf/nginx.conf' conf = public.readFile(path) rep = "client_max_body_size\s+([0-9]+)m" tmp = re.search(rep,conf).groups() if int(tmp[0]) < int(max): conf = re.sub(rep,'client_max_body_size '+max+'m',conf) public.writeFile(path,conf) public.serviceReload() public.phpReload(version); public.WriteLog("TYPE_PHP", "PHP_UPLOAD_MAX",(version,max)) return public.returnMsg(True,'SET_SUCCESS')
def setPHPDisable(self,get): filename = public.GetConfigValue('setup_path') + '/php/' + get.version + '/etc/php.ini' if not os.path.exists(filename): return public.returnMsg(False,'PHP_NOT_EXISTS'); phpini = public.readFile(filename); rep = "disable_functions\s*=\s*.*\n" phpini = re.sub(rep, 'disable_functions = ' + get.disable_functions + "\n", phpini); public.WriteLog('TYPE_PHP','PHP_DISABLE_FUNCTION',(get.version,get.disable_functions)) public.writeFile(filename,phpini); public.phpReload(get.version); return public.returnMsg(True,'SET_SUCCESS');
def setPHPDisable(self,get): filename = web.ctx.session.setupPath + '/php/' + get.version + '/etc/php.ini' if not os.path.exists(filename): return public.returnMsg(False,'PHP_NOT_EXISTS'); phpini = public.readFile(filename); rep = "disable_functions\s*=\s*.*\n" phpini = re.sub(rep, 'disable_functions = ' + get.disable_functions + "\n", phpini); public.WriteLog('TYPE_PHP','PHP_DISABLE_FUNCTION',(get.version,get.disable_functions)) public.writeFile(filename,phpini); public.phpReload(get.version); return public.returnMsg(True,'SET_SUCCESS');
def setPHPMaxTime(self, get): time = get.time version = get.version if int(time) < 30 or int(time) > 86400: return public.returnMsg(False, 'PHP_TIMEOUT_ERR') file = public.GetConfigValue( 'setup_path') + '/php/' + version + '/etc/php-fpm.conf' conf = public.readFile(file) rep = "request_terminate_timeout\s*=\s*([0-9]+)\n" conf = re.sub(rep, "request_terminate_timeout = " + time + "\n", conf) public.writeFile(file, conf) file = '/www/server/php/' + version + '/etc/php.ini' phpini = public.readFile(file) rep = "max_execution_time\s*=\s*([0-9]+)\r?\n" phpini = re.sub(rep, "max_execution_time = " + time + "\n", phpini) rep = "max_input_time\s*=\s*([0-9]+)\r?\n" phpini = re.sub(rep, "max_input_time = " + time + "\n", phpini) public.writeFile(file, phpini) if public.get_webserver() == 'nginx': #设置Nginx path = public.GetConfigValue( 'setup_path') + '/nginx/conf/nginx.conf' conf = public.readFile(path) rep = "fastcgi_connect_timeout\s+([0-9]+);" tmp = re.search(rep, conf).groups() if int(tmp[0]) < int(time): conf = re.sub(rep, 'fastcgi_connect_timeout ' + time + ';', conf) rep = "fastcgi_send_timeout\s+([0-9]+);" conf = re.sub(rep, 'fastcgi_send_timeout ' + time + ';', conf) rep = "fastcgi_read_timeout\s+([0-9]+);" conf = re.sub(rep, 'fastcgi_read_timeout ' + time + ';', conf) public.writeFile(path, conf) public.WriteLog("TYPE_PHP", "PHP_TIMEOUT", (version, time)) public.serviceReload() public.phpReload(version) return public.returnMsg(True, 'SET_SUCCESS')
def setPHPMaxTime(self,get): time = get.time version = get.version; if int(time) < 30 or int(time) > 86400: return public.returnMsg(False,'PHP_TIMEOUT_ERR'); file = web.ctx.session.setupPath+'/php/'+version+'/etc/php-fpm.conf'; conf = public.readFile(file); rep = "request_terminate_timeout\s*=\s*([0-9]+)\n"; conf = re.sub(rep,"request_terminate_timeout = "+time+"\n",conf); public.writeFile(file,conf) file = '/www/server/php/'+version+'/etc/php.ini'; phpini = public.readFile(file); rep = "max_execution_time\s*=\s*([0-9]+)\r?\n"; phpini = re.sub(rep,"max_execution_time = "+time+"\n",phpini); rep = "max_input_time\s*=\s*([0-9]+)\r?\n"; phpini = re.sub(rep,"max_input_time = "+time+"\n",phpini); public.writeFile(file,phpini) if public.get_webserver() == 'nginx': #设置Nginx path = web.ctx.session.setupPath+'/nginx/conf/nginx.conf'; conf = public.readFile(path); rep = "fastcgi_connect_timeout\s+([0-9]+);"; tmp = re.search(rep, conf).groups(); if int(tmp[0]) < time: conf = re.sub(rep,'fastcgi_connect_timeout '+time+';',conf); rep = "fastcgi_send_timeout\s+([0-9]+);"; conf = re.sub(rep,'fastcgi_send_timeout '+time+';',conf); rep = "fastcgi_read_timeout\s+([0-9]+);"; conf = re.sub(rep,'fastcgi_read_timeout '+time+';',conf); public.writeFile(path,conf); public.WriteLog("TYPE_PHP", "PHP_TIMEOUT",(version,time)); public.serviceReload() public.phpReload(version); return public.returnMsg(True, 'SET_SUCCESS');
def SetupPackage(self,get): name = get.dname site_name = get.site_name; php_version = get.php_version; #取基础信息 find = public.M('sites').where('name=?',(site_name,)).field('id,path,name').find(); path = find['path']; if path.replace('//','/') == '/': return public.returnMsg(False,'Dangerous website root directory!') #获取包信息 pinfo = self.GetPackageInfo(name); id = pinfo['id'] if not pinfo: return public.returnMsg(False,'The specified package does not exist.!'); #检查本地包 self.WriteLogs(json.dumps({'name':'Verifying package...','total':0,'used':0,'pre':0,'speed':0})); pack_path = self.__panelPath + '/package' if not os.path.exists(pack_path): os.makedirs(pack_path,384) packageZip = pack_path + '/'+ name + '.zip'; isDownload = False; if os.path.exists(packageZip): md5str = self.GetFileMd5(packageZip); if md5str != pinfo['versions'][0]['md5']: isDownload = True; else: isDownload = True; #下载文件 if isDownload: self.WriteLogs(json.dumps({'name':'Downloading file ...','total':0,'used':0,'pre':0,'speed':0})); if pinfo['versions'][0]['download']: self.DownloadFile('http://www.bt.cn/api/Pluginother/get_file?fname=' + pinfo['versions'][0]['download'], packageZip); if not os.path.exists(packageZip): return public.returnMsg(False,'File download failed!' + packageZip); pinfo = self.set_temp_file(packageZip,path) if not pinfo: return public.returnMsg(False,'Cannot find [aaPanel Auto Deployment Configuration File] in the installation package') #设置权限 self.WriteLogs(json.dumps({'name':'Setting permissions','total':0,'used':0,'pre':0,'speed':0})); os.system('chmod -R 755 ' + path); os.system('chown -R www.www ' + path); if pinfo['chmod'] != "": for chm in pinfo['chmod']: os.system('chmod -R ' + str(chm['mode']) + ' ' + (path + '/' + chm['path']).replace('//','/')); #安装PHP扩展 self.WriteLogs(json.dumps({'name':'Install the necessary PHP extensions','total':0,'used':0,'pre':0,'speed':0})); import files mfile = files.files(); for ext in pinfo['php_ext']: if ext == 'pathinfo': import config con = config.config(); get.version = php_version; get.type = 'on'; con.setPathInfo(get); else: get.name = ext get.version = php_version get.type = '1'; mfile.InstallSoft(get); #解禁PHP函数 if 'enable_functions' in pinfo: try: php_f = public.GetConfigValue('setup_path') + '/php/' + php_version + '/etc/php.ini' php_c = public.readFile(php_f) rep = "disable_functions\s*=\s{0,1}(.*)\n" tmp = re.search(rep,phpini).groups(); disable_functions = tmp[0].split(','); for fun in pinfo['enable_functions']: fun = fun.strip() if fun in disable_functions: disable_functions.remove(fun) disable_functions = ','.join(disable_functions) php_c = re.sub(rep, 'disable_functions = ' + disable_functions + "\n", php_c); public.writeFile(php_f,php_c) public.phpReload(php_version) except:pass #执行额外shell进行依赖安装 self.WriteLogs(json.dumps({'name':'Execute extra SHELL','total':0,'used':0,'pre':0,'speed':0})); if os.path.exists(path+'/install.sh'): os.system('cd '+path+' && bash ' + 'install.sh ' + find['name']); os.system('rm -f ' + path+'/install.sh') #是否执行Composer if os.path.exists(path + '/composer.json'): self.WriteLogs(json.dumps({'name':'Execute Composer','total':0,'used':0,'pre':0,'speed':0})); if not os.path.exists(path + '/composer.lock'): execPHP = '/www/server/php/' + php_version +'/bin/php'; if execPHP: if public.get_url().find('125.88'): os.system('cd ' +path+' && '+execPHP+' /usr/bin/composer config repo.packagist composer https://packagist.phpcomposer.com'); import panelSite; phpini = '/www/server/php/' + php_version + '/etc/php.ini' phpiniConf = public.readFile(phpini); phpiniConf = phpiniConf.replace('proc_open,proc_get_status,',''); public.writeFile(phpini,phpiniConf); os.system('nohup cd '+path+' && '+execPHP+' /usr/bin/composer install -vvv > /tmp/composer.log 2>&1 &'); #写伪静态 self.WriteLogs(json.dumps({'name':'Set URL rewrite','total':0,'used':0,'pre':0,'speed':0})); swfile = path + '/nginx.rewrite'; if os.path.exists(swfile): rewriteConf = public.readFile(swfile); dwfile = self.__panelPath + '/vhost/rewrite/' + site_name + '.conf'; public.writeFile(dwfile,rewriteConf); #删除伪静态文件 public.ExecShell("rm -f " + path + '/*.rewrite') #删除多余文件 rm_file = path + '/index.html' if os.path.exists(rm_file): rm_file_body = public.readFile(rm_file) if rm_file_body.find('panel-heading') != -1: os.remove(rm_file) #设置运行目录 self.WriteLogs(json.dumps({'name':'Set the run directory','total':0,'used':0,'pre':0,'speed':0})); if pinfo['run_path'] != '/': import panelSite; siteObj = panelSite.panelSite(); mobj = obj(); mobj.id = find['id']; mobj.runPath = pinfo['run_path']; siteObj.SetSiteRunPath(mobj); #导入数据 self.WriteLogs(json.dumps({'name':'Import database','total':0,'used':0,'pre':0,'speed':0})); if os.path.exists(path+'/import.sql'): databaseInfo = public.M('databases').where('pid=?',(find['id'],)).field('username,password').find(); if databaseInfo: os.system('/www/server/mysql/bin/mysql -u' + databaseInfo['username'] + ' -p' + databaseInfo['password'] + ' ' + databaseInfo['username'] + ' < ' + path + '/import.sql'); os.system('rm -f ' + path + '/import.sql'); siteConfigFile = (path + '/' + pinfo['db_config']).replace('//','/'); if os.path.exists(siteConfigFile): siteConfig = public.readFile(siteConfigFile) siteConfig = siteConfig.replace('BT_DB_USERNAME',databaseInfo['username']) siteConfig = siteConfig.replace('BT_DB_PASSWORD',databaseInfo['password']) siteConfig = siteConfig.replace('BT_DB_NAME',databaseInfo['username']) public.writeFile(siteConfigFile,siteConfig) #清理文件和目录 for f_path in pinfo['remove_file']: filename = (path + '/' + f_path).replace('//','/') if os.path.exists(filename): if not os.path.isdir(filename): if f_path.find('.user.ini') != -1: public.ExecShell("chattr -i " + filename) os.remove(filename) else: public.ExecShell("rm -rf " + filename) public.serviceReload(); if id: self.depTotal(id); self.WriteLogs(json.dumps({'name':'Ready to deploy','total':0,'used':0,'pre':0,'speed':0})); return public.returnMsg(True,pinfo);
def SetupPackage(self, get): name = get.dname site_name = get.site_name php_version = get.php_version #取基础信息 find = public.M('sites').where( 'name=?', (site_name, )).field('id,path,name').find() if not 'path' in find: return public.returnMsg(False, '网站不存在!') path = find['path'] if path.replace('//', '/') == '/': return public.returnMsg(False, '危险的网站根目录!') #获取包信息 pinfo = self.GetPackageInfo(name) id = pinfo['id'] if not pinfo: return public.returnMsg(False, '指定软件包不存在!') #检查本地包 self.WriteLogs( json.dumps({ 'name': '正在校验软件包...', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) pack_path = self.__panelPath + '/package' if not os.path.exists(pack_path): os.makedirs(pack_path, 384) packageZip = pack_path + '/' + name + '.zip' isDownload = False if os.path.exists(packageZip): md5str = self.GetFileMd5(packageZip) if md5str != pinfo['versions'][0]['md5']: isDownload = True else: isDownload = True #下载文件 if isDownload: self.WriteLogs( json.dumps({ 'name': '正在下载文件 ...', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) if pinfo['versions'][0]['download']: self.DownloadFile( 'http://www.bt.cn/api/Pluginother/get_file?fname=' + pinfo['versions'][0]['download'], packageZip) if not os.path.exists(packageZip): return public.returnMsg(False, '文件下载失败!' + packageZip) pinfo = self.set_temp_file(packageZip, path) if not pinfo: return public.returnMsg(False, '在安装包中找不到【宝塔自动部署配置文件】') #设置权限 self.WriteLogs( json.dumps({ 'name': '设置权限', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) os.system('chmod -R 755 ' + path) os.system('chown -R www.www ' + path) if pinfo['chmod']: for chm in pinfo['chmod']: os.system('chmod -R ' + str(chm['mode']) + ' ' + (path + '/' + chm['path']).replace('//', '/')) #安装PHP扩展 self.WriteLogs( json.dumps({ 'name': '安装必要的PHP扩展', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) import files mfile = files.files() if type(pinfo['php_ext']) == str: pinfo['php_ext'] = pinfo['php_ext'].strip().split(',') for ext in pinfo['php_ext']: if ext == 'pathinfo': import config con = config.config() get.version = php_version get.type = 'on' con.setPathInfo(get) else: get.name = ext get.version = php_version get.type = '1' mfile.InstallSoft(get) #解禁PHP函数 if 'enable_functions' in pinfo: try: if type(pinfo['enable_functions']) == str: pinfo['enable_functions'] = pinfo[ 'enable_functions'].strip().split(',') php_f = public.GetConfigValue( 'setup_path') + '/php/' + php_version + '/etc/php.ini' php_c = public.readFile(php_f) rep = "disable_functions\s*=\s{0,1}(.*)\n" tmp = re.search(rep, php_c).groups() disable_functions = tmp[0].split(',') for fun in pinfo['enable_functions']: fun = fun.strip() if fun in disable_functions: disable_functions.remove(fun) disable_functions = ','.join(disable_functions) php_c = re.sub( rep, 'disable_functions = ' + disable_functions + "\n", php_c) public.writeFile(php_f, php_c) public.phpReload(php_version) except: pass #执行额外shell进行依赖安装 self.WriteLogs( json.dumps({ 'name': '执行额外SHELL', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) if os.path.exists(path + '/install.sh'): os.system('cd ' + path + ' && bash ' + 'install.sh ' + find['name'] + " &> install.log") os.system('rm -f ' + path + '/install.sh') #是否执行Composer if os.path.exists(path + '/composer.json'): self.WriteLogs( json.dumps({ 'name': '执行Composer', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) if not os.path.exists(path + '/composer.lock'): execPHP = '/www/server/php/' + php_version + '/bin/php' if execPHP: if public.get_url().find('125.88'): os.system( 'cd ' + path + ' && ' + execPHP + ' /usr/bin/composer config repo.packagist composer https://packagist.phpcomposer.com' ) import panelSite phpini = '/www/server/php/' + php_version + '/etc/php.ini' phpiniConf = public.readFile(phpini) phpiniConf = phpiniConf.replace( 'proc_open,proc_get_status,', '') public.writeFile(phpini, phpiniConf) os.system( 'nohup cd ' + path + ' && ' + execPHP + ' /usr/bin/composer install -vvv > /tmp/composer.log 2>&1 &' ) #写伪静态 self.WriteLogs( json.dumps({ 'name': '设置伪静态', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) swfile = path + '/nginx.rewrite' if os.path.exists(swfile): rewriteConf = public.readFile(swfile) dwfile = self.__panelPath + '/vhost/rewrite/' + site_name + '.conf' public.writeFile(dwfile, rewriteConf) swfile = path + '/.htaccess' if os.path.exists(swfile): swpath = (path + '/' + pinfo['run_path'] + '/.htaccess').replace( '//', '/') if pinfo['run_path'] != '/' and not os.path.exists(swpath): public.writeFile(swpath, public.readFile(swfile)) #删除伪静态文件 public.ExecShell("rm -f " + path + '/*.rewrite') #删除多余文件 rm_file = path + '/index.html' if os.path.exists(rm_file): rm_file_body = public.readFile(rm_file) if rm_file_body.find('panel-heading') != -1: os.remove(rm_file) #设置运行目录 self.WriteLogs( json.dumps({ 'name': '设置运行目录', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) if pinfo['run_path'] != '/': import panelSite siteObj = panelSite.panelSite() mobj = obj() mobj.id = find['id'] mobj.runPath = pinfo['run_path'] siteObj.SetSiteRunPath(mobj) #导入数据 self.WriteLogs( json.dumps({ 'name': '导入数据库', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) if os.path.exists(path + '/import.sql'): databaseInfo = public.M('databases').where( 'pid=?', (find['id'], )).field('username,password').find() if databaseInfo: os.system('/www/server/mysql/bin/mysql -u' + databaseInfo['username'] + ' -p' + databaseInfo['password'] + ' ' + databaseInfo['username'] + ' < ' + path + '/import.sql') os.system('rm -f ' + path + '/import.sql') siteConfigFile = (path + '/' + pinfo['db_config']).replace( '//', '/') if os.path.exists(siteConfigFile): siteConfig = public.readFile(siteConfigFile) siteConfig = siteConfig.replace('BT_DB_USERNAME', databaseInfo['username']) siteConfig = siteConfig.replace('BT_DB_PASSWORD', databaseInfo['password']) siteConfig = siteConfig.replace('BT_DB_NAME', databaseInfo['username']) public.writeFile(siteConfigFile, siteConfig) #清理文件和目录 self.WriteLogs( json.dumps({ 'name': '清理多余的文件', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) if type(pinfo['remove_file']) == str: pinfo['remove_file'] = pinfo['remove_file'].strip().split(',') print(pinfo['remove_file']) for f_path in pinfo['remove_file']: if not f_path: continue filename = (path + '/' + f_path).replace('//', '/') if os.path.exists(filename): if not os.path.isdir(filename): if f_path.find('.user.ini') != -1: public.ExecShell("chattr -i " + filename) os.remove(filename) else: public.ExecShell("rm -rf " + filename) public.serviceReload() if id: self.depTotal(id) self.WriteLogs( json.dumps({ 'name': '准备部署', 'total': 0, 'used': 0, 'pre': 0, 'speed': 0 })) return public.returnMsg(True, pinfo)