コード例 #1
0
ファイル: panelSSL.py プロジェクト: soitun/BaoTa-Panel
 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));
コード例 #2
0
ファイル: config.py プロジェクト: tjqc0512/BaoTa
 def auto_cli_php_version(self,get):
     import panelSite
     php_versions = panelSite.panelSite().GetPHPVersion(get)
     php_bin_src = "/www/server/php/%s/bin/php" % php_versions[-1]['version']
     if not os.path.exists(php_bin_src): return public.returnMsg(False,'未安装PHP!')
     get.php_version = php_versions[-1]['version']
     self.set_cli_php_version(get)
     return php_versions[-1]
コード例 #3
0
ファイル: panelSSL.py プロジェクト: WytheLi/panel
    def GetSSLInfo(self, get):
        self.__PDATA['data']['partnerOrderId'] = get.partnerOrderId
        self.__PDATA['data'] = self.De_Code(self.__PDATA['data'])
        time.sleep(3)
        result = json.loads(
            public.httpPost(self.__APIURL + '/GetSSLInfo', self.__PDATA))
        result['data'] = self.En_Code(result['data'])
        if not 'privateKey' in result['data']: return result

        #写配置到站点
        if hasattr(get, 'siteName'):
            try:
                siteName = get.siteName
                path = '/www/server/panel/vhost/cert/' + 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:
                return public.returnMsg(False, 'SET_ERROR')
        result['data'] = self.En_Code(result['data'])
        return result
コード例 #4
0
ファイル: panelSSL.py プロジェクト: soitun/BaoTa-Panel
 def GetRunPath(self,get):
     if hasattr(get,'siteName'):
         get.id = public.M('sites').where('name=?',(get.siteName,)).getField('id');
     else:
         get.id = public.M('sites').where('path=?',(get.path,)).getField('id');
     if not get.id: return False;
     import panelSite
     result = panelSite.panelSite().GetSiteRunPath(get);
     return result['runPath'];
コード例 #5
0
 def remove_loadleveling(self, get):
     upName = get.upname
     upFile = self.__nginxConf + 'leveling_' + upName + '.conf'
     if os.path.exists(upFile): os.remove(upFile)
     data = self.__read_config()
     levelingList = []
     for d in data:
         if d['name'] == upName:
             if 'site_id' in d:
                 get.id = d['site_id']
                 get.webname = d['site']
                 import panelSite
                 panelSite.panelSite().DeleteSite(get)
             continue
         levelingList.append(d)
     self.__write_config(levelingList)
     public.WriteLog('负载均衡', '删除负载均衡[' + upName + ']')
     return public.returnMsg(True, '删除成功!')
コード例 #6
0
ファイル: main.py プロジェクト: immortalChensm/python
 def POST(self):
     get = web.input()
     import panelSite
     siteObject = panelSite.panelSite()
     
     defs = ('GetSiteLogs','GetSiteDomains','GetSecurity','SetSecurity','ProxyCache','CloseToHttps','HttpToHttps','SetEdate','SetRewriteTel','GetCheckSafe','CheckSafe','GetDefaultSite','SetDefaultSite','CloseTomcat','SetTomcat','apacheAddPort','AddSite','GetPHPVersion','SetPHPVersion','DeleteSite','AddDomain','DelDomain','GetDirBinding','AddDirBinding','GetDirRewrite','DelDirBinding'
             ,'UpdateRulelist','SetSiteRunPath','GetSiteRunPath','SetPath','SetIndex','GetIndex','GetDirUserINI','SetDirUserINI','GetRewriteList','SetSSL','SetSSLConf','CreateLet','CloseSSLConf','GetSSL','SiteStart','SiteStop','GetDnsApi','SetDnsApi'
             ,'Set301Status','Get301Status','CloseLimitNet','SetLimitNet','GetLimitNet','SetProxy','GetProxy','ToBackup','DelBackup','GetSitePHPVersion','logsOpen','GetLogsStatus','CloseHasPwd','SetHasPwd','GetHasPwd')
     return publicObject(siteObject,defs);
コード例 #7
0
ファイル: config.py プロジェクト: zeus911/aaPanel
 def get_php_session_path(self,get):
     import panelSite
     site_info = public.M('sites').where('id=?', (get.id,)).field('name,path').find()
     run_path = panelSite.panelSite().GetSiteRunPath(get)["runPath"]
     user_ini_file = "{site_path}{run_path}/.user.ini".format(site_path=site_info["path"], run_path=run_path)
     conf = public.readFile(user_ini_file)
     if conf and "session.save_path" in conf:
         return True
     return False
コード例 #8
0
 def GetRunPath(self,get):
     if hasattr(get,'siteName'):
         get.id = public.M('sites').where('name=?',(get.siteName,)).getField('id');
     else:
         get.id = public.M('sites').where('path=?',(get.path,)).getField('id');
     if not get.id: return False;
     import panelSite
     result = panelSite.panelSite().GetSiteRunPath(get);
     return result['runPath'];
コード例 #9
0
ファイル: main.py プロジェクト: soitun/BaoTa-Panel
 def POST(self):
     get = web.input()
     import panelSite
     siteObject = panelSite.panelSite()
     
     defs = ('GetSiteDomains','GetSecurity','SetSecurity','ProxyCache','CloseToHttps','HttpToHttps','SetEdate','SetRewriteTel','GetCheckSafe','CheckSafe','GetDefaultSite','SetDefaultSite','CloseTomcat','SetTomcat','apacheAddPort','AddSite','GetPHPVersion','SetPHPVersion','DeleteSite','AddDomain','DelDomain','GetDirBinding','AddDirBinding','GetDirRewrite','DelDirBinding'
             ,'UpdateRulelist','SetSiteRunPath','GetSiteRunPath','SetPath','SetIndex','GetIndex','GetDirUserINI','SetDirUserINI','GetRewriteList','SetSSL','SetSSLConf','CreateLet','CloseSSLConf','GetSSL','SiteStart','SiteStop'
             ,'Set301Status','Get301Status','CloseLimitNet','SetLimitNet','GetLimitNet','SetProxy','GetProxy','ToBackup','DelBackup','GetSitePHPVersion','logsOpen','GetLogsStatus','CloseHasPwd','SetHasPwd','GetHasPwd')
     return publicObject(siteObject,defs);
コード例 #10
0
 def __create_lets(self, get):
     import panelSite
     ps = panelSite.panelSite()
     get.siteName = get.domain
     get.updateOf = "1"
     get.domains = json.dumps([get.domain])
     get.force = "true"
     psc = ps.CreateLet(get)
     if "False" in psc.values():
         return psc
コード例 #11
0
 def get_cli_php_version(self,get):
     php_bin = '/usr/bin/php'
     if not os.path.exists(php_bin) or not os.path.islink(php_bin):  return self.auto_cli_php_version(get)
     link_re = os.readlink(php_bin)
     if not os.path.exists(link_re): return self.auto_cli_php_version(get)
     import panelSite
     php_versions = panelSite.panelSite().GetPHPVersion(get)
     del(php_versions[0])
     for v in php_versions:
         if link_re.find(v['version']) != -1: return {"select":v,"versions":php_versions}
     return {"select":self.auto_cli_php_version(get),"versions":php_versions}
コード例 #12
0
 def get_site_info(self, args):
     if not os.path.exists(self.__config_file):
         import panelSite
         php_versions = panelSite.panelSite().GetPHPVersion(None)
         res_versions = []
         for php_version in php_versions:
             if int(php_version['version']) < 70: continue
             res_versions.insert(0, php_version)
         return public.returnMsg(False, res_versions)
     pdata = json.loads(public.readFile(self.__config_file))
     pdata['path'] = public.M('sites').where(
         'id=?', (pdata['siteId'], )).getField('path')
     return pdata
コード例 #13
0
ファイル: __init__.py プロジェクト: linhphi9x94/aaPanel
def site(pdata = None):
    comReturn = comm.local()
    if comReturn: return comReturn
    if request.method == method_get[0] and not pdata:
        data = {}
        data['isSetup'] = True;
        data['lan'] = public.getLan('site');
        if os.path.exists(public.GetConfigValue('setup_path')+'/nginx') == False and os.path.exists(public.GetConfigValue('setup_path')+'/apache') == False: data['isSetup'] = False;
        return render_template( 'site.html',data=data)
    import panelSite
    siteObject = panelSite.panelSite()
        
    defs = ('modify_dir_auth_pass','get_dir_auth','delete_dir_auth','set_dir_auth','GetRedirectFile','SaveRedirectFile','DeleteRedirect','GetRedirectList','CreateRedirect','ModifyRedirect','GetSiteLogs','GetSiteDomains','GetSecurity','SetSecurity','ProxyCache','CloseToHttps','HttpToHttps','SetEdate','SetRewriteTel','GetCheckSafe','CheckSafe','GetDefaultSite','SetDefaultSite','CloseTomcat','SetTomcat','apacheAddPort','AddSite','GetPHPVersion','SetPHPVersion','DeleteSite','AddDomain','DelDomain','GetDirBinding','AddDirBinding','GetDirRewrite','DelDirBinding','get_site_types','add_site_type','remove_site_type','modify_site_type_name','set_site_type','UpdateRulelist','SetSiteRunPath','GetSiteRunPath','SetPath','SetIndex','GetIndex','GetDirUserINI','SetDirUserINI','GetRewriteList','SetSSL','SetSSLConf','CreateLet','CloseSSLConf','GetSSL','SiteStart','SiteStop','Set301Status','Get301Status','CloseLimitNet','SetLimitNet','GetLimitNet','RemoveProxy','GetProxyList','GetProxyDetals','CreateProxy','ModifyProxy','GetProxyFile','SaveProxyFile','ToBackup','DelBackup','GetSitePHPVersion','logsOpen','GetLogsStatus','CloseHasPwd','SetHasPwd','GetHasPwd','GetDnsApi','SetDnsApi')
    return publicObject(siteObject,defs,None,pdata);
コード例 #14
0
ファイル: panelSSL.py プロジェクト: zwt12370/BaoTa
 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 as ex:
             return public.returnMsg(False,'SET_ERROR,' + str(ex));
     result['data'] = self.En_Code(result['data']);
     return result;
コード例 #15
0
    def set_cert(self, get):
        siteName = get.siteName
        certInfo = self.get_order_find(get)
        path = '/www/server/panel/vhost/cert/' + siteName
        if not os.path.exists(path):
            public.ExecShell('mkdir -p ' + path)
        csrpath = path + "/fullchain.pem"
        keypath = path + "/privkey.pem"
        pidpath = path + "/certOrderId"

        other_file = path + '/partnerOrderId'
        if os.path.exists(other_file): os.remove(other_file)
        other_file = path + '/README'
        if os.path.exists(other_file): os.remove(other_file)

        public.writeFile(keypath, certInfo['privateKey'])
        public.writeFile(
            csrpath,
            certInfo['certificate'] + "\n" + certInfo['caCertificate'])
        public.writeFile(pidpath, get.oid)
        import panelSite
        panelSite.panelSite().SetSSLConf(get)
        public.serviceReload()
        return public.returnMsg(True, 'SET_SUCCESS')
コード例 #16
0
ファイル: jobs.py プロジェクト: zuoapp-ly/BaoTa
def site_end_task():
    global oldEdate
    if not oldEdate: oldEdate = public.readFile('data/edate.pl')
    if not oldEdate: oldEdate = '0000-00-00'
    mEdate = time.strftime('%Y-%m-%d',time.localtime())
    if oldEdate == mEdate: return False
    edateSites = public.M('sites').where('edate>? AND edate<? AND (status=? OR status=?)',('0000-00-00',mEdate,1,u'正在运行')).field('id,name').select()
    import panelSite,common
    siteObject = panelSite.panelSite()
    for site in edateSites:
        get = common.dict_obj()
        get.id = site['id']
        get.name = site['name']
        siteObject.SiteStop(get)
    oldEdate = mEdate
    public.writeFile('data/edate.pl',mEdate)
コード例 #17
0
ファイル: setPanelLets.py プロジェクト: alsyundawy/aaPanel
 def __create_site_of_panel_lets(self,get):
     import panelSite
     ps = panelSite.panelSite()
     get.webname = json.dumps({"domain":get.domain,"domainlist":[],"count":0})
     get.ps = "For panel Let's Encrypt certificate request and renewal, please do not delete"
     get.path = "/www/wwwroot/panel_ssl_site"
     get.ftp = "false"
     get.sql = "false"
     get.codeing = "utf8"
     get.type = "PHP"
     get.version = "00"
     get.type_id = "0"
     get.port = "80"
     psa = ps.AddSite(get)
     if "status" in psa.keys():
         return psa
コード例 #18
0
ファイル: ols.py プロジェクト: CQT-IT-Service/SA-CP
 def init_ols(self, get):
     # 构造需要传入的参数
     import panelSite
     ps = panelSite.panelSite()
     siteinfo = self._make_args()
     for s in siteinfo:
         # 创建配置文件
         get.port = s['port']
         get.webname = {
             'domain': s['sitename'],
             'domainlist': s['domainlist']
         }
         ps.openlitespeed_add_site(get, siteinfo)
         # 处理证书
         if s['ssl_domain']:
             get.first_domain = s['ssl_domain']
             ps.set_ols_ssl(get, s['ssl_domain'])
コード例 #19
0
    def cerate_loadleveling(self, get):
        upName = get.upname
        if self.__get_leveling_info(upName):
            return public.returnMsg(False, '指定负载均衡已存在!')
        upExpires = int(get.upexpires)
        session_type = get.session_type
        ps = get.ps
        tmpNodes = json.loads(get.upnodes)
        domains = json.loads(get.domains)
        mainDomain = domains[0].split(':')[0]
        result = self.create_site(get)
        if 'status' in result: return result
        site_id = result['id']
        levelingInfo = {
            'name': upName,
            'pool': 'http',
            'site': mainDomain,
            'site_id': site_id,
            'ps': ps,
            'session_type': session_type,
            'expires': upExpires,
            'cookie_name': 'bt_route',
            'secure': False,
            'httponly': True,
            'time': int(time.time()),
            'nodes': tmpNodes
        }

        data = self.__read_config()
        data.append(levelingInfo)
        self.__write_config(data)
        self.__write_to_conf(upName)
        import panelSite
        s = panelSite.panelSite()

        get.name = mainDomain
        get.proxyUrl = 'http://' + upName
        get.toDomain = '$host'
        get.sub1 = ''
        get.sub2 = ''
        get.type = '1'
        s.SetProxy(get)
        public.WriteLog('负载均衡', '添加负载均衡[' + upName + ']')
        return public.returnMsg(True, '添加成功!')
コード例 #20
0
def siteEdate():
    global oldEdate
    try:
        if not oldEdate: oldEdate = public.readFile('data/edate.pl');
        if not oldEdate: oldEdate = '0000-00-00';
        mEdate = time.strftime('%Y-%m-%d',time.localtime())
        if oldEdate == mEdate: return False;
        edateSites = public.M('sites').where('edate>? AND edate<? AND (status=? OR status=?)',('0000-00-00',mEdate,1,u'正在运行')).field('id,name').select();
        import panelSite;
        siteObject = panelSite.panelSite();
        for site in edateSites:
            get = MyBad('');
            get.id = site['id'];
            get.name = site['name'];
            siteObject.SiteStop(get);
        oldEdate = mEdate;
        public.writeFile('data/edate.pl',mEdate);
    except:
         pass;
コード例 #21
0
 def create_site(self,get):
     domains = json.loads(get.domains);
     mainDomain = domains[0].split(':')
     if len(mainDomain) == 1: mainDomain.append('80');
     del(domains[0])
     get.webname = json.dumps({'domain': mainDomain[0],'domainlist':domains,'count':len(domains)});
     get.port = mainDomain[1]
     get.ftp = 'false';
     get.sql = 'false';
     get.version = '54';
     get.ps = '负载均衡['+get.upname+']的绑定站点';
     get.path = public.M('config').where("id=?",('1',)).getField('sites_path') + '/' + mainDomain[0];
     import panelSite
     s = panelSite.panelSite()
     result = s.AddSite(get);
     if 'status' in result: return result;
     result['id'] = public.M('sites').where('name=?',(mainDomain[0],)).getField('id');
     self.set_ssl_check(mainDomain[0])
     return result;
コード例 #22
0
ファイル: task.py プロジェクト: soitun/BaoTa-Panel
def siteEdate():
    global oldEdate
    try:
        if not oldEdate: oldEdate = public.readFile('data/edate.pl');
        if not oldEdate: oldEdate = '0000-00-00';
        mEdate = time.strftime('%Y-%m-%d',time.localtime())
        if oldEdate == mEdate: return False;
        edateSites = public.M('sites').where('edate>? AND edate<? AND (status=? OR status=?)',('0000-00-00',mEdate,1,u'正在运行')).field('id,name').select();
        import panelSite;
        siteObject = panelSite.panelSite();
        for site in edateSites:
            get = MyBad('');
            get.id = site['id'];
            get.name = site['name'];
            siteObject.SiteStop(get);
        oldEdate = mEdate;
        public.writeFile('data/edate.pl',mEdate);
    except:
         pass;
コード例 #23
0
 def __create_site_of_panel_lets(self, get):
     import panelSite
     ps = panelSite.panelSite()
     get.webname = json.dumps({
         "domain": get.domain,
         "domainlist": [],
         "count": 0
     })
     get.ps = "用于面板Let's Encrypt 证书申请和续签,请勿删除"
     get.path = "/www/wwwroot/panel_ssl_site"
     get.ftp = "false"
     get.sql = "false"
     get.codeing = "utf8"
     get.type = "PHP"
     get.version = "00"
     get.type_id = "0"
     get.port = "80"
     psa = ps.AddSite(get)
     if "status" in psa.keys():
         return psa
コード例 #24
0
ファイル: AutoRenew.py プロジェクト: yxsh/Encryption365_Baota
def plug_cert_to_site(siteId, certId, certData):
    s = get_site_info(siteId)
    basePath = '/www/server/panel/vhost/cert/' + s[2]
    if not os.path.exists(basePath):
        os.makedirs(basePath, 384)
    lCert = get_local_cert(certId)
    cert_file = basePath + '/fullchain.pem'
    key_file = basePath + '/privkey.pem'
    public.writeFile(cert_file, certData['cert_code'] + certData['ca_code'])
    public.writeFile(key_file, lCert[13])
    get = {
        'siteName': s[1],
        'key': lCert[13],
        'csr': certData['cert_code'] + "\n" + certData['ca_code']
    }
    gets = build_object_json(get)
    print(gets.siteName)
    rt = panelSite().SetSSL(gets)
    if rt['status']:
        write_log('success', 'cert_installed', '证书#' + str(certId) + '安装成功!',
                  certId)
    else:
        write_log('error', 'cert_install_error',
                  '证书#' + str(certId) + '安装出错: ' + status['msg'], certId)
コード例 #25
0
def siteEdate():
    # 网站到期处理
    global oldEdate
    try:
        if not oldEdate:
            oldEdate = mw.readFile('data/edate.pl')
        if not oldEdate:
            oldEdate = '0000-00-00'
        mEdate = time.strftime('%Y-%m-%d', time.localtime())
        if oldEdate == mEdate:
            return False
        edateSites = mw.M('sites').where('edate>? AND edate<? AND (status=? OR status=?)',
                                         ('0000-00-00', mEdate, 1, u'正在运行')).field('id,name').select()
        import panelSite
        siteObject = panelSite.panelSite()
        for site in edateSites:
            get = MyBad('')
            get.id = site['id']
            get.name = site['name']
            siteObject.SiteStop(get)
        oldEdate = mEdate
        mw.writeFile('data/edate.pl', mEdate)
    except:
        pass
コード例 #26
0
 def setPHPMyAdmin(self,get):
     import re
     #try:
     filename = self.__get_webserver_conffile()
     if public.get_webserver() == 'openlitespeed':
         filename = "/www/server/panel/vhost/openlitespeed/detail/phpmyadmin.conf"
     conf = public.readFile(filename)
     if not conf: return public.returnMsg(False,'ERROR')
     if hasattr(get,'port'):
         mainPort = public.readFile('data/port.pl').strip()
         rulePort = ['80','443','21','20','8080','8081','8089','11211','6379']
         oldPort = "888"
         if get.port in rulePort:
             return public.returnMsg(False,'AJAX_PHPMYADMIN_PORT_ERR')
         if public.get_webserver() == 'nginx':
             rep = "listen\s+([0-9]+)\s*;"
             oldPort = re.search(rep,conf).groups()[0]
             conf = re.sub(rep,'listen ' + get.port + ';\n',conf)
         elif public.get_webserver() == 'apache':
             rep = "Listen\s+([0-9]+)\s*\n"
             oldPort = re.search(rep,conf).groups()[0]
             conf = re.sub(rep,"Listen " + get.port + "\n",conf,1)
             rep = "VirtualHost\s+\*:[0-9]+"
             conf = re.sub(rep,"VirtualHost *:" + get.port,conf,1)
         else:
             filename = '/www/server/panel/vhost/openlitespeed/listen/888.conf'
             conf = public.readFile(filename)
             reg = "address\s+\*:(\d+)"
             tmp = re.search(reg,conf)
             if tmp:
                 oldPort = tmp.groups(1)
             conf = re.sub(reg,"address *:{}".format(get.port),conf)
         if oldPort == get.port: return public.returnMsg(False,'SOFT_PHPVERSION_ERR_PORT')
         
         public.writeFile(filename,conf)
         import firewalls
         get.ps = public.getMsg('SOFT_PHPVERSION_PS')
         fw = firewalls.firewalls()
         fw.AddAcceptPort(get)
         public.serviceReload()
         public.WriteLog('TYPE_SOFT','SOFT_PHPMYADMIN_PORT',(get.port,))
         get.id = public.M('firewall').where('port=?',(oldPort,)).getField('id')
         get.port = oldPort
         fw.DelAcceptPort(get)
         return public.returnMsg(True,'SET_PORT_SUCCESS')
     
     if hasattr(get,'phpversion'):
         if public.get_webserver() == 'nginx':
             filename = public.GetConfigValue('setup_path') + '/nginx/conf/enable-php.conf'
             conf = public.readFile(filename)
             rep = "php-cgi.*\.sock"
             conf = re.sub(rep,'php-cgi-' + get.phpversion + '.sock',conf,1)
         elif public.get_webserver() == 'apache':
             rep = "php-cgi.*\.sock"
             conf = re.sub(rep,'php-cgi-' + get.phpversion + '.sock',conf,1)
         else:
             reg = '/usr/local/lsws/lsphp\d+/bin/lsphp'
             conf = re.sub(reg,'/usr/local/lsws/lsphp{}/bin/lsphp'.format(get.phpversion),conf)
         public.writeFile(filename,conf)
         public.serviceReload()
         public.WriteLog('TYPE_SOFT','SOFT_PHPMYADMIN_PHP',(get.phpversion,))
         return public.returnMsg(True,'SOFT_PHPVERSION_SET')
     
     if hasattr(get,'password'):
         import panelSite;
         if(get.password == 'close'):
             return panelSite.panelSite().CloseHasPwd(get)
         else:
             return panelSite.panelSite().SetHasPwd(get)
     
     if hasattr(get,'status'):
         if conf.find(public.GetConfigValue('setup_path') + '/stop') != -1:
             conf = conf.replace(public.GetConfigValue('setup_path') + '/stop',public.GetConfigValue('setup_path') + '/phpmyadmin')
             msg = public.getMsg('START')
         else:
             conf = conf.replace(public.GetConfigValue('setup_path') + '/phpmyadmin',public.GetConfigValue('setup_path') + '/stop')
             msg = public.getMsg('STOP')
         
         public.writeFile(filename,conf)
         public.serviceReload()
         public.WriteLog('TYPE_SOFT','SOFT_PHPMYADMIN_STATUS',(msg,))
         return public.returnMsg(True,'SOFT_PHPMYADMIN_STATUS',(msg,))
コード例 #27
0
ファイル: system.py プロジェクト: zwt12370/BaoTa
    def ServiceAdmin(self,get=None):
        #服务管理
        
        if get.name == 'mysqld': public.CheckMyCnf();
        
        if get.name == 'phpmyadmin':
            import ajax
            get.status = 'True';
            ajax.ajax().setPHPMyAdmin(get);
            return public.returnMsg(True,'SYS_EXEC_SUCCESS');
        
        #检查httpd配置文件
        if get.name == 'apache' or get.name == 'httpd':
            get.name = 'httpd';
            if not os.path.exists(self.setupPath+'/apache/bin/apachectl'): return public.returnMsg(True,'SYS_NOT_INSTALL_APACHE');
            vhostPath = self.setupPath + '/panel/vhost/apache'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath);
                public.ExecShell('/etc/init.d/httpd start');
            
            if get.type == 'start': 
                public.ExecShell('/etc/init.d/httpd stop');
                self.kill_port()
                
            result = public.ExecShell('ulimit -n 10240 && ' + self.setupPath+'/apache/bin/apachectl -t');
            if result[1].find('Syntax OK') == -1:
                public.WriteLog("TYPE_SOFT",'SYS_EXEC_ERR', (str(result),));
                return public.returnMsg(False,'SYS_CONF_APACHE_ERR',(result[1].replace("\n",'<br>'),));
            
            if get.type == 'restart':
                public.ExecShell('pkill -9 httpd');
                public.ExecShell('/etc/init.d/httpd start');
                time.sleep(0.5)
            
        #检查nginx配置文件
        elif get.name == 'nginx':
            vhostPath = self.setupPath + '/panel/vhost/rewrite'
            if not os.path.exists(vhostPath): public.ExecShell('mkdir ' + vhostPath);
            vhostPath = self.setupPath + '/panel/vhost/nginx'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath);
                public.ExecShell('/etc/init.d/nginx start');
            
            result = public.ExecShell('ulimit -n 10240 && nginx -t -c '+self.setupPath+'/nginx/conf/nginx.conf');
            if result[1].find('perserver') != -1:
                limit = self.setupPath + '/nginx/conf/nginx.conf';
                nginxConf = public.readFile(limit);
                limitConf = "limit_conn_zone $binary_remote_addr zone=perip:10m;\n\t\tlimit_conn_zone $server_name zone=perserver:10m;";
                nginxConf = nginxConf.replace("#limit_conn_zone $binary_remote_addr zone=perip:10m;",limitConf);
                public.writeFile(limit,nginxConf)
                public.ExecShell('/etc/init.d/nginx start');
                return public.returnMsg(True,'SYS_CONF_NGINX_REP');
            
            if result[1].find('proxy') != -1:
                import panelSite
                panelSite.panelSite().CheckProxy(get);
                public.ExecShell('/etc/init.d/nginx start');
                return public.returnMsg(True,'SYS_CONF_NGINX_REP');
            
            #return result
            if result[1].find('successful') == -1:
                public.WriteLog("TYPE_SOFT",'SYS_EXEC_ERR', (str(result),));
                return public.returnMsg(False,'SYS_CONF_NGINX_ERR',(result[1].replace("\n",'<br>'),));

            if get.type == 'start': 
                self.kill_port()
                time.sleep(0.5)
        
        #执行
        execStr = "/etc/init.d/"+get.name+" "+get.type
        if execStr == '/etc/init.d/pure-ftpd reload': execStr = self.setupPath+'/pure-ftpd/bin/pure-pw mkdb '+self.setupPath+'/pure-ftpd/etc/pureftpd.pdb'
        if execStr == '/etc/init.d/pure-ftpd start': os.system('pkill -9 pure-ftpd');
        if execStr == '/etc/init.d/tomcat reload': execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start';
        if execStr == '/etc/init.d/tomcat restart': execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start';
        
        if get.name != 'mysqld':
            result = public.ExecShell(execStr);
        else:
            os.system(execStr);
            result = [];
            result.append('');
            result.append('');
        
        if result[1].find('nginx.pid') != -1:
            public.ExecShell('pkill -9 nginx && sleep 1');
            public.ExecShell('/etc/init.d/nginx start');
        if get.type != 'test':
            public.WriteLog("TYPE_SOFT", 'SYS_EXEC_SUCCESS',(execStr,));
        
        if len(result[1]) > 1 and get.name != 'pure-ftpd': return public.returnMsg(False, '<p>警告消息: <p>' + result[1].replace('\n','<br>'));
        return public.returnMsg(True,'SYS_EXEC_SUCCESS');
コード例 #28
0
ファイル: site_task.py プロジェクト: wonderking/aaPanel
#coding: utf-8
import os,sys,time
os.chdir('/www/server/panel/')
sys.path.insert(0,"class/")
import public
oldEdate = public.readFile('data/edate.pl')
if not oldEdate: oldEdate = '0000-00-00'
mEdate = time.strftime('%Y-%m-%d',time.localtime())
edateSites = public.M('sites').where('edate>? AND edate<? AND (status=? OR status=?)',('0000-00-00',mEdate,1,u'正在运行')).field('id,name').select()
import panelSite
siteObject = panelSite.panelSite()
for site in edateSites:
    get = public.dict_obj()
    get.id = site['id']
    get.name = site['name']
    siteObject.SiteStop(get)
oldEdate = mEdate
public.writeFile('data/edate.pl',mEdate)
コード例 #29
0
ファイル: ajax.py プロジェクト: zhenfeii/BaoTa
    def setPHPMyAdmin(self, get):
        import re
        #try:
        if public.get_webserver() == 'nginx':
            filename = public.GetConfigValue(
                'setup_path') + '/nginx/conf/nginx.conf'
        else:
            filename = public.GetConfigValue(
                'setup_path') + '/apache/conf/extra/httpd-vhosts.conf'

        conf = public.readFile(filename)
        if hasattr(get, 'port'):
            mainPort = public.readFile('data/port.pl').strip()
            rulePort = [
                '80', '443', '21', '20', '8080', '8081', '8089', '11211',
                '6379'
            ]
            if get.port in rulePort:
                return public.returnMsg(False, 'AJAX_PHPMYADMIN_PORT_ERR')
            if public.get_webserver() == 'nginx':
                rep = "listen\s+([0-9]+)\s*;"
                oldPort = re.search(rep, conf).groups()[0]
                conf = re.sub(rep, 'listen ' + get.port + ';\n', conf)
            else:
                rep = "Listen\s+([0-9]+)\s*\n"
                oldPort = re.search(rep, conf).groups()[0]
                conf = re.sub(rep, "Listen " + get.port + "\n", conf, 1)
                rep = "VirtualHost\s+\*:[0-9]+"
                conf = re.sub(rep, "VirtualHost *:" + get.port, conf, 1)

            if oldPort == get.port:
                return public.returnMsg(False, 'SOFT_PHPVERSION_ERR_PORT')

            public.writeFile(filename, conf)
            import firewalls
            get.ps = public.getMsg('SOFT_PHPVERSION_PS')
            fw = firewalls.firewalls()
            fw.AddAcceptPort(get)
            public.serviceReload()
            public.WriteLog('TYPE_SOFT', 'SOFT_PHPMYADMIN_PORT', (get.port, ))
            get.id = public.M('firewall').where('port=?',
                                                (oldPort, )).getField('id')
            get.port = oldPort
            fw.DelAcceptPort(get)
            return public.returnMsg(True, 'SET_PORT_SUCCESS')

        if hasattr(get, 'phpversion'):
            if public.get_webserver() == 'nginx':
                filename = public.GetConfigValue(
                    'setup_path') + '/nginx/conf/enable-php.conf'
                conf = public.readFile(filename)
                rep = "php-cgi.*\.sock"
                conf = re.sub(rep, 'php-cgi-' + get.phpversion + '.sock', conf,
                              1)
            else:
                rep = "php-cgi.*\.sock"
                conf = re.sub(rep, 'php-cgi-' + get.phpversion + '.sock', conf,
                              1)

            public.writeFile(filename, conf)
            public.serviceReload()
            public.WriteLog('TYPE_SOFT', 'SOFT_PHPMYADMIN_PHP',
                            (get.phpversion, ))
            return public.returnMsg(True, 'SOFT_PHPVERSION_SET')

        if hasattr(get, 'password'):
            import panelSite
            if (get.password == 'close'):
                return panelSite.panelSite().CloseHasPwd(get)
            else:
                return panelSite.panelSite().SetHasPwd(get)

        if hasattr(get, 'status'):
            if conf.find(public.GetConfigValue('setup_path') + '/stop') != -1:
                conf = conf.replace(
                    public.GetConfigValue('setup_path') + '/stop',
                    public.GetConfigValue('setup_path') + '/phpmyadmin')
                msg = public.getMsg('START')
            else:
                conf = conf.replace(
                    public.GetConfigValue('setup_path') + '/phpmyadmin',
                    public.GetConfigValue('setup_path') + '/stop')
                msg = public.getMsg('STOP')

            public.writeFile(filename, conf)
            public.serviceReload()
            public.WriteLog('TYPE_SOFT', 'SOFT_PHPMYADMIN_STATUS', (msg, ))
            return public.returnMsg(True, 'SOFT_PHPMYADMIN_STATUS', (msg, ))
コード例 #30
0
    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)
コード例 #31
0
    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);
コード例 #32
0
    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').find()
        path = find['path']

        #获取包信息
        pinfo = self.GetPackageInfo(name)
        if not pinfo: return public.returnMsg(False, '指定软件包不存在!')

        #检查本地包
        self.WriteLogs(
            json.dumps({
                'name': '检查软件包',
                'total': 0,
                'used': 0,
                'pre': 0,
                'speed': 0
            }))
        packageZip = self.__setupPath + '/package/' + name + '.zip'
        isDownload = False
        if os.path.exists(packageZip):
            md5str = self.GetFileMd5(packageZip)
            if md5str != pinfo['md5']: isDownload = True
        else:
            isDownload = True

        #下载文件

        if isDownload:
            self.WriteLogs(
                json.dumps({
                    'name': '下载文件',
                    'total': 0,
                    'used': 0,
                    'pre': 0,
                    'speed': 0
                }))
            self.DownloadFile(pinfo['download'], packageZip)
        if not os.path.exists(packageZip):
            return public.returnMsg(False, '文件下载失败!')
        os.system('unzip -o ' + packageZip + ' -d ' + path + '/')

        #设置权限
        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'] != "":
            access = pinfo['chmod'].split(',')
            for chm in access:
                tmp = chm.split('|')
                if len(tmp) != 2: continue
                os.system('chmod -R ' + tmp[0] + ' ' + path + '/' + tmp[1])

        #安装PHP扩展
        self.WriteLogs(
            json.dumps({
                'name': '安装必要的PHP扩展',
                'total': 0,
                'used': 0,
                'pre': 0,
                'speed': 0
            }))
        if pinfo['ext'] != '':
            exts = pinfo['ext'].split(',')
            import files
            mfile = files.files()
            for ext in exts:
                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)

        #执行额外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')
            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)

        #设置运行目录
        self.WriteLogs(
            json.dumps({
                'name': '设置运行目录',
                'total': 0,
                'used': 0,
                'pre': 0,
                'speed': 0
            }))
        if pinfo['run'] != '/':
            import panelSite
            siteObj = panelSite.panelSite()
            mobj = obj()
            mobj.id = find['id']
            mobj.runPath = pinfo['run']
            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['config']
                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)

        public.serviceReload()
        self.depTotal(name)
        self.WriteLogs(
            json.dumps({
                'name': '准备部署',
                'total': 0,
                'used': 0,
                'pre': 0,
                'speed': 0
            }))
        return public.returnMsg(True, pinfo)
コード例 #33
0
ファイル: deployment_main.py プロジェクト: soitun/BaoTa-Panel
 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').find();
     path = find['path'];
     
     #获取包信息
     pinfo = self.GetPackageInfo(name);
     if not pinfo: return public.returnMsg(False,'指定软件包不存在!');
     
     #检查本地包
     self.WriteLogs(json.dumps({'name':'检查软件包','total':0,'used':0,'pre':0,'speed':0}));
     packageZip = self.__setupPath + '/package/' + name + '.zip';
     isDownload = False;
     if os.path.exists(packageZip):
         md5str = self.GetFileMd5(packageZip);
         if md5str != pinfo['md5']: isDownload = True;
     else:
         isDownload = True;
     
     #下载文件
     
     if isDownload:
         self.WriteLogs(json.dumps({'name':'下载文件','total':0,'used':0,'pre':0,'speed':0}));
         self.DownloadFile(pinfo['download'], packageZip);
     if not os.path.exists(packageZip): return public.returnMsg(False,'文件下载失败!');
     os.system('unzip -o '+packageZip+' -d ' + path + '/');
     
     #设置权限
     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'] != "":
         access = pinfo['chmod'].split(',')
         for chm in access:
             tmp = chm.split('|');
             if len(tmp) != 2: continue;
             os.system('chmod -R ' + tmp[0] + ' ' + path + '/' + tmp[1]);
     
     #安装PHP扩展
     self.WriteLogs(json.dumps({'name':'安装必要的PHP扩展','total':0,'used':0,'pre':0,'speed':0}));
     if pinfo['ext'] != '':
         exts = pinfo['ext'].split(',');
         import files
         mfile = files.files();
         for ext in exts:
             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);
     
     
     #执行额外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');
         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);
     
     #设置运行目录
     self.WriteLogs(json.dumps({'name':'设置运行目录','total':0,'used':0,'pre':0,'speed':0}));
     if pinfo['run'] != '/':
         import panelSite;
         siteObj = panelSite.panelSite();
         mobj = obj();
         mobj.id = find['id'];
         mobj.runPath = pinfo['run'];
         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['config'];
             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)
     
     public.serviceReload();
     self.depTotal(name);
     self.WriteLogs(json.dumps({'name':'准备部署','total':0,'used':0,'pre':0,'speed':0}));
     return public.returnMsg(True,pinfo);
コード例 #34
0
ファイル: ajax.py プロジェクト: novecle/baota
 def setPHPMyAdmin(self,get):
     import re;
     #try:
     if public.get_webserver() == 'nginx':
         filename = web.ctx.session.setupPath + '/nginx/conf/nginx.conf';
     else:
         filename = web.ctx.session.setupPath + '/apache/conf/extra/httpd-vhosts.conf';
     
     conf = public.readFile(filename);
     if hasattr(get,'port'):
         mainPort = public.readFile('data/port.pl').strip();
         if mainPort == get.port:
             return public.returnMsg(False,'SOFT_PHPVERSION_ERR_PORT_RE');
         if public.get_webserver() == 'nginx':
             rep = "listen\s+([0-9]+)\s*;"
             oldPort = re.search(rep,conf).groups()[0];
             conf = re.sub(rep,'listen ' + get.port + ';\n',conf);
         else:
             rep = "Listen\s+([0-9]+)\s*\n";
             oldPort = re.search(rep,conf).groups()[0];
             conf = re.sub(rep,"Listen " + get.port + "\n",conf,1);
             rep = "VirtualHost\s+\*:[0-9]+"
             conf = re.sub(rep,"VirtualHost *:" + get.port,conf,1);
         
         if oldPort == get.port: return public.returnMsg(False,'SOFT_PHPVERSION_ERR_PORT');
         
         public.writeFile(filename,conf);
         import firewalls
         get.ps = public.getMsg('SOFT_PHPVERSION_PS');
         fw = firewalls.firewalls();
         fw.AddAcceptPort(get);           
         public.serviceReload();
         public.WriteLog('TYPE_SOFT','SOFT_PHPMYADMIN_PORT',(get.port,))
         get.id = public.M('firewall').where('port=?',(oldPort,)).getField('id');
         get.port = oldPort;
         fw.DelAcceptPort(get);
         return public.returnMsg(True,'SET_PORT_SUCCESS');
     
     if hasattr(get,'phpversion'):
         if public.get_webserver() == 'nginx':
             filename = web.ctx.session.setupPath + '/nginx/conf/enable-php.conf';
             conf = public.readFile(filename);
             rep = "php-cgi.*\.sock"
             conf = re.sub(rep,'php-cgi-' + get.phpversion + '.sock',conf,1);
         else:
             rep = "php-cgi.*\.sock"
             conf = re.sub(rep,'php-cgi-' + get.phpversion + '.sock',conf,1);
             
         public.writeFile(filename,conf);
         public.serviceReload();
         public.WriteLog('TYPE_SOFT','SOFT_PHPMYADMIN_PHP',(get.phpversion,))
         return public.returnMsg(True,'SOFT_PHPVERSION_SET');
     
     if hasattr(get,'password'):
         import panelSite;
         if(get.password == 'close'):
             return panelSite.panelSite().CloseHasPwd(get);
         else:
             return panelSite.panelSite().SetHasPwd(get);
     
     if hasattr(get,'status'):
         if conf.find(web.ctx.session.setupPath + '/stop') != -1:
             conf = conf.replace(web.ctx.session.setupPath + '/stop',web.ctx.session.setupPath + '/phpmyadmin');
             msg = public.getMsg('START')
         else:
             conf = conf.replace(web.ctx.session.setupPath + '/phpmyadmin',web.ctx.session.setupPath + '/stop');
             msg = public.getMsg('STOP')
         
         public.writeFile(filename,conf);
         public.serviceReload();
         public.WriteLog('TYPE_SOFT','SOFT_PHPMYADMIN_STATUS',(msg,))
         return public.returnMsg(True,'SOFT_PHPMYADMIN_STATUS',(msg,));
コード例 #35
0
    def ServiceAdmin(self, get=None):
        #服务管理
        if get.name == 'mysqld':
            public.CheckMyCnf()
            self.__check_mysql_path()
        if get.name.find('webserver') != -1:
            get.name = public.get_webserver()

        if get.name == 'phpmyadmin':
            import ajax
            get.status = 'True'
            ajax.ajax().setPHPMyAdmin(get)
            return public.returnMsg(True, 'SYS_EXEC_SUCCESS')

        if get.name == 'openlitespeed':
            if get.type == 'stop':
                public.ExecShell(
                    'rm -f /tmp/lshttpd/*.sock* && /usr/local/lsws/bin/lswsctrl stop'
                )
            elif get.type == 'start':
                public.ExecShell(
                    'rm -f /tmp/lshttpd/*.sock* && /usr/local/lsws/bin/lswsctrl start'
                )
            else:
                public.ExecShell(
                    'rm -f /tmp/lshttpd/*.sock* && /usr/local/lsws/bin/lswsctrl restart'
                )
            return public.returnMsg(True, 'SYS_EXEC_SUCCESS')

        #检查httpd配置文件
        if get.name == 'apache' or get.name == 'httpd':
            get.name = 'httpd'
            if not os.path.exists(self.setupPath + '/apache/bin/apachectl'):
                return public.returnMsg(True, 'SYS_NOT_INSTALL_APACHE')
            vhostPath = self.setupPath + '/panel/vhost/apache'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath)
                public.ExecShell('/etc/init.d/httpd start')

            if get.type == 'start':
                public.ExecShell('/etc/init.d/httpd stop')
                self.kill_port()

            result = public.ExecShell('ulimit -n 8192 ; ' + self.setupPath +
                                      '/apache/bin/apachectl -t')
            if result[1].find('Syntax OK') == -1:
                public.WriteLog("TYPE_SOFT", 'SYS_EXEC_ERR', (str(result), ))
                return public.returnMsg(False, 'SYS_CONF_APACHE_ERR',
                                        (result[1].replace("\n", '<br>'), ))

            if get.type == 'restart':
                public.ExecShell('pkill -9 httpd')
                public.ExecShell('/etc/init.d/httpd start')
                time.sleep(0.5)

        #检查nginx配置文件
        elif get.name == 'nginx':
            vhostPath = self.setupPath + '/panel/vhost/rewrite'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath)
            vhostPath = self.setupPath + '/panel/vhost/nginx'
            if not os.path.exists(vhostPath):
                public.ExecShell('mkdir ' + vhostPath)
                public.ExecShell('/etc/init.d/nginx start')

            result = public.ExecShell('ulimit -n 8192 ; nginx -t -c ' +
                                      self.setupPath +
                                      '/nginx/conf/nginx.conf')
            if result[1].find('perserver') != -1:
                limit = self.setupPath + '/nginx/conf/nginx.conf'
                nginxConf = public.readFile(limit)
                limitConf = "limit_conn_zone $binary_remote_addr zone=perip:10m;\n\t\tlimit_conn_zone $server_name zone=perserver:10m;"
                nginxConf = nginxConf.replace(
                    "#limit_conn_zone $binary_remote_addr zone=perip:10m;",
                    limitConf)
                public.writeFile(limit, nginxConf)
                public.ExecShell('/etc/init.d/nginx start')
                return public.returnMsg(True, 'SYS_CONF_NGINX_REP')

            if result[1].find('proxy') != -1:
                import panelSite
                panelSite.panelSite().CheckProxy(get)
                public.ExecShell('/etc/init.d/nginx start')
                return public.returnMsg(True, 'SYS_CONF_NGINX_REP')

            #return result
            if result[1].find('successful') == -1:
                public.WriteLog("TYPE_SOFT", 'SYS_EXEC_ERR', (str(result), ))
                return public.returnMsg(False, 'SYS_CONF_NGINX_ERR',
                                        (result[1].replace("\n", '<br>'), ))

            if get.type == 'start':
                self.kill_port()
                time.sleep(0.5)
        if get.name == 'redis':
            redis_init = '/etc/init.d/redis'
            if os.path.exists(redis_init):
                init_body = public.ReadFile(redis_init)
                if init_body.find('pkill -9 redis') == -1:
                    public.ExecShell("wget -O " + redis_init + " " +
                                     public.get_url() + '/init/redis.init')
                    public.ExecShell("chmod +x " + redis_init)

        #执行
        execStr = "/etc/init.d/" + get.name + " " + get.type
        if execStr == '/etc/init.d/pure-ftpd reload':
            execStr = self.setupPath + '/pure-ftpd/bin/pure-pw mkdb ' + self.setupPath + '/pure-ftpd/etc/pureftpd.pdb'
        if execStr == '/etc/init.d/pure-ftpd start':
            public.ExecShell('pkill -9 pure-ftpd')
        if execStr == '/etc/init.d/tomcat reload':
            execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start'
        if execStr == '/etc/init.d/tomcat restart':
            execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start'

        if get.name != 'mysqld':
            result = public.ExecShell(execStr)
        else:
            public.ExecShell(execStr)
            result = []
            result.append('')
            result.append('')

        if result[1].find('nginx.pid') != -1:
            public.ExecShell('pkill -9 nginx && sleep 1')
            public.ExecShell('/etc/init.d/nginx start')
        if get.type != 'test':
            public.WriteLog("TYPE_SOFT", 'SYS_EXEC_SUCCESS', (execStr, ))

        if len(result[1]
               ) > 1 and get.name != 'pure-ftpd' and get.name != 'redis':
            return public.returnMsg(
                False,
                '<p>Warning message: <p>' + result[1].replace('\n', '<br>'))
        return public.returnMsg(True, 'SYS_EXEC_SUCCESS')
コード例 #36
0
ファイル: ajax.py プロジェクト: soitun/BaoTa-Panel
 def setPHPMyAdmin(self,get):
     import re;
     #try:
     if public.get_webserver() == 'nginx':
         filename = web.ctx.session.setupPath + '/nginx/conf/nginx.conf';
     else:
         filename = web.ctx.session.setupPath + '/apache/conf/extra/httpd-vhosts.conf';
     
     conf = public.readFile(filename);
     if hasattr(get,'port'):
         mainPort = public.readFile('data/port.pl').strip();
         if mainPort == get.port:
             return public.returnMsg(False,'SOFT_PHPVERSION_ERR_PORT_RE');
         if public.get_webserver() == 'nginx':
             rep = "listen\s+([0-9]+)\s*;"
             oldPort = re.search(rep,conf).groups()[0];
             conf = re.sub(rep,'listen ' + get.port + ';\n',conf);
         else:
             rep = "Listen\s+([0-9]+)\s*\n";
             oldPort = re.search(rep,conf).groups()[0];
             conf = re.sub(rep,"Listen " + get.port + "\n",conf,1);
             rep = "VirtualHost\s+\*:[0-9]+"
             conf = re.sub(rep,"VirtualHost *:" + get.port,conf,1);
         
         if oldPort == get.port: return public.returnMsg(False,'SOFT_PHPVERSION_ERR_PORT');
         
         public.writeFile(filename,conf);
         import firewalls
         get.ps = public.getMsg('SOFT_PHPVERSION_PS');
         fw = firewalls.firewalls();
         fw.AddAcceptPort(get);           
         public.serviceReload();
         public.WriteLog('TYPE_SOFT','SOFT_PHPMYADMIN_PORT',(get.port,))
         get.id = public.M('firewall').where('port=?',(oldPort,)).getField('id');
         get.port = oldPort;
         fw.DelAcceptPort(get);
         return public.returnMsg(True,'SET_PORT_SUCCESS');
     
     if hasattr(get,'phpversion'):
         if public.get_webserver() == 'nginx':
             filename = web.ctx.session.setupPath + '/nginx/conf/enable-php.conf';
             conf = public.readFile(filename);
             rep = "php-cgi.*\.sock"
             conf = re.sub(rep,'php-cgi-' + get.phpversion + '.sock',conf,1);
         else:
             rep = "php-cgi.*\.sock"
             conf = re.sub(rep,'php-cgi-' + get.phpversion + '.sock',conf,1);
             
         public.writeFile(filename,conf);
         public.serviceReload();
         public.WriteLog('TYPE_SOFT','SOFT_PHPMYADMIN_PHP',(get.phpversion,))
         return public.returnMsg(True,'SOFT_PHPVERSION_SET');
     
     if hasattr(get,'password'):
         import panelSite;
         if(get.password == 'close'):
             return panelSite.panelSite().CloseHasPwd(get);
         else:
             return panelSite.panelSite().SetHasPwd(get);
     
     if hasattr(get,'status'):
         if conf.find(web.ctx.session.setupPath + '/stop') != -1:
             conf = conf.replace(web.ctx.session.setupPath + '/stop',web.ctx.session.setupPath + '/phpmyadmin');
             msg = public.getMsg('START')
         else:
             conf = conf.replace(web.ctx.session.setupPath + '/phpmyadmin',web.ctx.session.setupPath + '/stop');
             msg = public.getMsg('STOP')
         
         public.writeFile(filename,conf);
         public.serviceReload();
         public.WriteLog('TYPE_SOFT','SOFT_PHPMYADMIN_STATUS',(msg,))
         return public.returnMsg(True,'SOFT_PHPMYADMIN_STATUS',(msg,));