Пример #1
0
 def GetPHPConfig(self,get):
     import re,json
     filename = public.GetConfigValue('setup_path') + '/php/' + get.version + '/etc/php.ini'
     if public.get_webserver() == 'openlitespeed':
         filename = '/usr/local/lsws/lsphp{}/etc/php/{}.{}/litespeed/php.ini'.format(get.version,get.version[0],get.version[1])
         if os.path.exists('/etc/redhat-release'):
             filename = '/usr/local/lsws/lsphp' + get.version + '/etc/php.ini'
     if not os.path.exists(filename): return public.returnMsg(False,'PHP_NOT_EXISTS')
     phpini = public.readFile(filename)
     data = {}
     rep = "disable_functions\s*=\s{0,1}(.*)\n"
     tmp = re.search(rep,phpini).groups()
     data['disable_functions'] = tmp[0]
     
     rep = "upload_max_filesize\s*=\s*([0-9]+)(M|m|K|k)"
     tmp = re.search(rep,phpini).groups()
     data['max'] = tmp[0]
     
     rep = u"\n;*\s*cgi\.fix_pathinfo\s*=\s*([0-9]+)\s*\n"
     tmp = re.search(rep,phpini).groups()
     if tmp[0] == '0':
         data['pathinfo'] = False
     else:
         data['pathinfo'] = True
     self.getCloudPHPExt(get)
     phplib = json.loads(public.readFile('data/phplib.conf'))
     libs = []
     tasks = public.M('tasks').where("status!=?",('1',)).field('status,name').select()
     for lib in phplib:
         lib['task'] = '1'
         for task in tasks:
             tmp = public.getStrBetween('[',']',task['name'])
             if not tmp:continue
             tmp1 = tmp.split('-')
             if tmp1[0].lower() == lib['name'].lower():
                 lib['task'] = task['status']
                 lib['phpversions'] = []
                 lib['phpversions'].append(tmp1[1])
         if public.get_webserver() == 'openlitespeed':
             lib['status'] = False
             get.php_version = "{}.{}".format(get.version[0],get.version[1])
             phpini = self.php_info(get)['phpinfo']['modules'].lower()
             phpini = phpini.split()
             for i in phpini:
                 if lib['check'][:-3].lower() == i :
                     lib['status'] = True
                     break
                 if "ioncube" in lib['check'][:-3].lower() and "ioncube" == i:
                     lib['status'] = True
                     break
         else:
             if phpini.find(lib['check']) == -1:
                 lib['status'] = False
             else:
                 lib['status'] = True
             
         libs.append(lib)
     
     data['libs'] = libs
     return data
Пример #2
0
 def GetSSL(self, siteName):
     self.setupPath = '/www/server'
     path = os.path.join('/www/server/panel/vhost/cert/', siteName)
     if not os.path.isfile(os.path.join(path, "fullchain.pem")) and not os.path.isfile(os.path.join(path, "privkey.pem")):
         path = os.path.join('/etc/letsencrypt/live/', siteName)
     type = 0;
     if os.path.exists(path + '/README'):  type = 1;
     if os.path.exists(path + '/partnerOrderId'):  type = 2;
     csrpath = path + "/fullchain.pem";  # 生成证书路径
     keypath = path + "/privkey.pem";  # 密钥文件路径
     key = public.readFile(keypath);
     csr = public.readFile(csrpath);
     file = self.setupPath + '/panel/vhost/' + public.get_webserver() + '/' + siteName + '.conf';
     conf = public.readFile(file);
     keyText = 'SSLCertificateFile'
     if public.get_webserver() == 'nginx': keyText = 'ssl_certificate';
     status = True
     if not conf or conf.find(keyText) == -1:
         status = False
         type = -1
     toHttps = self.IsToHttps(siteName)
     id = public.M('sites').where("name=?", (siteName,)).getField('id')
     domains = public.M('domain').where("pid=?", (id,)).field('name').select()
     cert_data= {}
     if csr:
         cert_data = self.GetCertName(csrpath)
     email = public.M('users').where('id=?',(1,)).getField('email')
     if email == '*****@*****.**': email = ''
     return {'status': status, 'cert_data':cert_data}
Пример #3
0
    def set_dir_auth(self,get):
        '''
        get.name        auth_name
        get.site_dir         auth_dir
        get.username    username
        get.password    password
        get.id          site id
        :param get:
        :return:
        '''
        name = get.name
        site_dir = get.site_dir
        if public.get_webserver() == "openlitespeed":
            return public.returnMsg(False,"OpenLiteSpeed is currently not supported")
        if not hasattr(get,"password") or not get.password or not hasattr(get,"username") or not get.username:
            return public.returnMsg(False, 'Please enter an account or password')
        if not get.site_dir:
            return public.returnMsg(False, 'Please enter the directory to be protected')
        if not get.name:
            return public.returnMsg(False, 'Please enter the Name')

        if site_dir[0] != "/" or site_dir[-1] != "/":
            return public.returnMsg(False, 'Directory format is incorrect')
            # site_dir = site_dir[1:]
            # if site_dir[-1] == "/":
            #     site_dir = site_dir[:-1]
        passwd = public.hasPwd(get.password)
        site_info = self.get_site_info(get.id)
        site_name = site_info["site_name"]
        if self._check_site_authorization(site_name):
            return public.returnMsg(False, 'Site password protection has been set, please cancel and then set. Site directory --> Password access')
        if self._check_dir_auth(site_name, name,site_dir):
            return public.returnMsg(False, 'Directory has been protected')
        auth = "{user}:{passwd}".format(user=get.username,passwd=passwd)
        auth_file = '{setup_path}/pass/{site_name}'.format(setup_path=self.setup_path,site_name=site_name)
        if not os.path.exists(auth_file):
            os.makedirs(auth_file)
        auth_file = auth_file+"/{}.pass".format(name)
        public.writeFile(auth_file,auth)
        # 配置独立认证文件
        self.set_dir_auth_file(site_info["site_path"],site_name,name,get.username,site_dir,auth_file)
        # 配置站点主文件
        result = self.set_conf(site_name,"create")
        if result:
            return result
        # 检查配置
        webserver = public.get_webserver()
        result=self.check_site_conf(webserver,site_name,name)
        if result:
            return result
        # 写配置
        conf = {"name":name,"site_dir":get.site_dir,"auth_file":auth_file}
        self._write_conf(conf,site_name)
        public.serviceReload()
        return public.returnMsg(True,"Created successfully")
Пример #4
0
 def get_site_php_version(self,siteName):
     try:
         conf = public.readFile(self.setup_path + '/panel/vhost/'+public.get_webserver()+'/'+siteName+'.conf');
         if public.get_webserver() == 'nginx':
             rep = "enable-php-([0-9]{2,3})\.conf"
         else:
             rep = "php-cgi-([0-9]{2,3})\.sock"
         tmp = re.search(rep,conf).groups()
         if tmp:
             return tmp[0]
         else:
             return ""
     except:
         return public.returnMsg(False, 'SITE_PHPVERSION_ERR_A22')
Пример #5
0
    def get_php_version(self, siteName):
        try:

            if not self.web_server:
                self.web_server = public.get_webserver()

            conf = public.readFile(self.setupPath + '/panel/vhost/' +
                                   self.web_server + '/' + siteName + '.conf')
            if self.web_server == 'openlitespeed':
                conf = public.readFile(self.setupPath + '/panel/vhost/' +
                                       self.web_server + '/detail/' +
                                       siteName + '.conf')
            if self.web_server == 'nginx':
                rep = r"enable-php-(\w{2,5})\.conf"
            elif self.web_server == 'apache':
                rep = r"php-cgi-(\w{2,5})\.sock"
            else:
                rep = r"path\s*/usr/local/lsws/lsphp(\d+)/bin/lsphp"
            tmp = re.search(rep, conf).groups()
            if tmp[0] == '00':
                return 'Static'
            if tmp[0] == 'other':
                return 'Other'

            return tmp[0][0] + '.' + tmp[0][1]
        except:
            return 'Static'
Пример #6
0
    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')
Пример #7
0
    def SetRedirectNginx(self, get):
        ng_redirectfile = "%s/panel/vhost/nginx/redirect/%s/*.conf" % (
            self.setupPath, get.sitename)
        ng_file = self.setupPath + "/panel/vhost/nginx/" + get.sitename + ".conf"
        p_conf = self.__read_config(self.__redirectfile)
        if public.get_webserver() == 'nginx':
            shutil.copyfile(ng_file, '/tmp/ng_file_bk.conf')
        if os.path.exists(ng_file):
            ng_conf = public.readFile(ng_file)
            if not p_conf:
                rep = "#SSL-END(\n|.)*\/redirect\/.*\*.conf;"
                ng_conf = re.sub(rep, '#SSL-END', ng_conf)
                public.writeFile(ng_file, ng_conf)
                return
            sitenamelist = []
            for i in p_conf:
                sitenamelist.append(i["sitename"])

            if get.sitename in sitenamelist:
                rep = "include.*\/redirect\/.*\*.conf;"
                if not re.search(rep, ng_conf):
                    ng_conf = ng_conf.replace(
                        "#SSL-END", "#SSL-END\n\t%s\n\t" %
                        public.GetMsg("NGINX_REDIRECT_REP") + "include " +
                        ng_redirectfile + ";")
                    public.writeFile(ng_file, ng_conf)

            else:
                rep = "#SSL-END(\n|.)*\/redirect\/.*\*.conf;"
                ng_conf = re.sub(rep, '#SSL-END', ng_conf)
                public.writeFile(ng_file, ng_conf)
Пример #8
0
 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');
Пример #9
0
    def GetApacheValue(self):
        apachedefaultcontent = public.readFile(self.apachedefaultfile)
        apachempmcontent = public.readFile(self.apachempmfile)
        ps = ["秒,请求超时时间","保持连接","秒,连接超时时间","单次连接最大请求数"]
        gets = ["Timeout","KeepAlive","KeepAliveTimeout","MaxKeepAliveRequests"]
        if public.get_webserver() == 'apache':
            shutil.copyfile(self.apachedefaultfile, '/tmp/apdefault_file_bk.conf')
            shutil.copyfile(self.apachempmfile, '/tmp/apmpm_file_bk.conf')
        conflist = []
        n = 0
        for i in gets:
            rep = "(%s)\s+(\w+)" % i
            k = re.search(rep, apachedefaultcontent).group(1)
            v = re.search(rep, apachedefaultcontent).group(2)
            psstr = ps[n]
            kv = {"name":k,"value":v,"ps":psstr}
            conflist.append(kv)
            n += 1

        ps = ["启动时默认进程数","最大进程数","最大连接数,0为无限大","最大并发进程数"]
        gets = ["StartServers","MaxSpareServers","MaxConnectionsPerChild","MaxRequestWorkers"]
        n = 0
        for i in gets:
            rep = "(%s)\s+(\w+)" % i
            k = re.search(rep, apachempmcontent).group(1)
            v = re.search(rep, apachempmcontent).group(2)
            psstr = ps[n]
            kv = {"name": k, "value": v, "ps": psstr}
            conflist.append(kv)
            n += 1
        return(conflist)
Пример #10
0
 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')
Пример #11
0
 def InstallSoft(self, get):
     import db, time
     path = public.GetConfigValue('setup_path') + '/php'
     if not os.path.exists(path): os.system("mkdir -p " + path)
     if session['server_os']['x'] != 'RHEL': get.type = '3'
     apacheVersion = 'false'
     if public.get_webserver() == 'apache':
         apacheVersion = public.readFile(
             public.GetConfigValue('setup_path') + '/apache/version.pl')
     public.writeFile('/var/bt_apacheVersion.pl', apacheVersion)
     public.writeFile('/var/bt_setupPath.conf',
                      public.GetConfigValue('root_path'))
     isTask = '/tmp/panelTask.pl'
     execstr = "cd " + public.GetConfigValue(
         'setup_path'
     ) + "/panel/install && /bin/bash install_soft.sh " + get.type + " install " + get.name + " " + get.version
     sql = db.Sql()
     if hasattr(get, 'id'):
         id = get.id
     else:
         id = None
     sql.table('tasks').add(
         'id,name,type,status,addtime,execstr',
         (None, '安装[' + get.name + '-' + get.version + ']', 'execshell',
          '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr))
     public.writeFile(isTask, 'True')
     public.WriteLog('TYPE_SETUP', 'PLUGIN_ADD', (get.name, get.version))
     time.sleep(0.1)
     return public.returnMsg(True, 'PLUGIN_ADD')
Пример #12
0
 def SetRedirectApache(self, sitename):
     ap_redirectfile = "%s/panel/vhost/apache/redirect/%s/*.conf" % (
         self.setupPath, sitename)
     ap_file = self.setupPath + "/panel/vhost/apache/" + sitename + ".conf"
     p_conf = public.readFile(self.__redirectfile)
     if public.get_webserver() == 'apache':
         shutil.copyfile(ap_file, '/tmp/ap_file_bk.conf')
     if os.path.exists(ap_file):
         ap_conf = public.readFile(ap_file)
         if p_conf == "[]":
             rep = "\n*%s\n+\s+IncludeOptiona[\s\w\/\.\*]+" % public.GetMsg(
                 "NGINX_REDIRECT_REP")
             ap_conf = re.sub(rep, '', ap_conf)
             public.writeFile(ap_file, ap_conf)
             return
         if sitename in p_conf:
             rep = "%s(\n|.)+IncludeOptional.*\/redirect\/.*conf" % public.GetMsg(
                 "NGINX_REDIRECT_REP1")
             rep1 = "combined"
             if not re.search(rep, ap_conf):
                 ap_conf = ap_conf.replace(
                     rep1,
                     rep1 + "\n\t%s" % public.GetMsg("NGINX_REDIRECT_REP") +
                     "\n\tIncludeOptional " + ap_redirectfile)
                 public.writeFile(ap_file, ap_conf)
         else:
             rep = "\n*%s\n+\s+IncludeOptiona[\s\w\/\.\*]+" % public.GetMsg(
                 "NGINX_REDIRECT_REP")
             ap_conf = re.sub(rep, '', ap_conf)
             public.writeFile(ap_file, ap_conf)
Пример #13
0
    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')
Пример #14
0
 def __get_webserver_conffile(self):
     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'
     return filename
Пример #15
0
 def _init_conf(self, website):
     self.ng_website_conf = '/www/server/panel/vhost/nginx/{}.conf'.format(
         website)
     self.ap_website_conf = '/www/server/panel/vhost/apache/{}.conf'.format(
         website)
     self.ols_website_conf = '/www/server/panel/vhost/openlitespeed/detail/{}.conf'.format(
         website)
     self.webserver = public.get_webserver()
Пример #16
0
 def get_phpmyadmin_conf(self):
     if public.get_webserver() == "nginx":
         conf_file = "/www/server/panel/vhost/nginx/phpmyadmin.conf"
         rep = "listen\s*(\d+)"
     else:
         conf_file = "/www/server/panel/vhost/apache/phpmyadmin.conf"
         rep = "Listen\s*(\d+)"
     return {"conf_file": conf_file, "rep": rep}
Пример #17
0
 def _check_site_authorization(self, site_name):
     webserver = public.get_webserver()
     conf_file = "{setup_path}/panel/vhost/{webserver}/{site_name}.conf".format(
         setup_path=self.setup_path,
         site_name=site_name,
         webserver=webserver)
     if "Authorization" in public.readFile(conf_file):
         return True
Пример #18
0
    def GetShell(self,param):
        #try:
        type=param['sType']
        if type=='toFile':
            shell=param.sFile
        else :
            head="#!/bin/bash\nPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin\nexport PATH\n"
            log='-access_log'
            python_bin = public.get_python_bin()
            if public.get_webserver()=='nginx':
                log='.log'
            if type in ['site','path'] and param['sBody'] != 'undefined' and len(param['sBody']) > 1:
                exports = param['sBody'].replace("\r\n","\n").replace("\n",",")
                head += "BT_EXCLUDE=\"" + exports.strip() + "\"\nexport BT_EXCLUDE\n"
            wheres={
                    'path': head + python_bin +" " + public.GetConfigValue('setup_path')+"/panel/script/backup.py path "+param['sName']+" "+str(param['save']),
                    'site'  :   head +python_bin+ " " + public.GetConfigValue('setup_path')+"/panel/script/backup.py site "+param['sName']+" "+str(param['save']),
                    'database': head +python_bin+ " " + public.GetConfigValue('setup_path')+"/panel/script/backup.py database "+param['sName']+" "+str(param['save']),
                    'logs'  :   head +python_bin+ " " + public.GetConfigValue('setup_path')+"/panel/script/logsBackup "+param['sName']+log+" "+str(param['save']),
                    'rememory' : head + "/bin/bash " + public.GetConfigValue('setup_path') + '/panel/script/rememory.sh',
                    'webshell': head +python_bin+ " " + public.GetConfigValue('setup_path') + '/panel/class/webshell_check.py site ' + param['sName'] +' ' +param['urladdress']
                    }
            if param['backupTo'] != 'localhost':
                cfile = public.GetConfigValue('setup_path') + "/panel/plugin/" + param['backupTo'] + "/" + param['backupTo'] + "_main.py"
                if not os.path.exists(cfile): cfile = public.GetConfigValue('setup_path') + "/panel/script/backup_" + param['backupTo'] + ".py"
                wheres={
                    'path': head + python_bin+" " + cfile + " path " + param['sName'] + " " + str(param['save']),
                    'site'  :   head + python_bin+" " + cfile + " site " + param['sName'] + " " + str(param['save']),
                    'database': head + python_bin+" " + cfile + " database " + param['sName'] + " " + str(param['save']),
                    'logs'  :   head + python_bin+" " + public.GetConfigValue('setup_path')+"/panel/script/logsBackup "+param['sName']+log+" "+str(param['save']),
                    'rememory' : head + "/bin/bash " + public.GetConfigValue('setup_path') + '/panel/script/rememory.sh',
                     'webshell': head + python_bin+" " + public.GetConfigValue('setup_path') + '/panel/class/webshell_check.py site ' + param['sName'] +' ' +param['urladdress']
                    }
                
            try:
                shell=wheres[type]
            except:
                if type == 'toUrl':
                    shell = head + "curl -sS --connect-timeout 10 -m 3600 '" + param['urladdress']+"'"
                else:
                    shell=head+param['sBody'].replace("\r\n","\n")
                    
                shell += '''
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
'''
        cronPath=public.GetConfigValue('setup_path')+'/cron'
        if not os.path.exists(cronPath): public.ExecShell('mkdir -p ' + cronPath)
        if not 'echo' in param:
            cronName=public.md5(public.md5(str(time.time()) + '_bt'))
        else:
            cronName = param['echo']
        file = cronPath+'/' + cronName
        public.writeFile(file,self.CheckScript(shell))
        public.ExecShell('chmod 750 ' + file)
        return cronName
Пример #19
0
    def set_dir_auth(self, get):
        '''
        get.name        auth_name
        get.site_dir         auth_dir
        get.username    username
        get.password    password
        get.id          site id
        :param get:
        :return:
        '''
        name = get.name
        site_dir = get.site_dir
        if not hasattr(get, "password") or not get.password or not hasattr(
                get, "username") or not get.username:
            return public.returnMsg(False, '请输入账号或密码')
        if not get.site_dir:
            return public.returnMsg(False, '请输入需要保护的目录')
        if not get.name:
            return public.returnMsg(False, '请输入名称')

        if site_dir[0] != "/" or site_dir[-1] != "/":
            return public.returnMsg(False, '目录格式不正确')
        # if site_dir[0] == "/":
        #     site_dir = site_dir[1:]
        #     if site_dir[-1] == "/":
        #         site_dir = site_dir[:-1]
        passwd = public.hasPwd(get.password)
        site_info = self.get_site_info(get.id)
        site_name = site_info["site_name"]
        if self._check_site_authorization(site_name):
            return public.returnMsg(
                False, '已经设置站点密码保护,请取消后再设置 站点配置 --> 站点目录 --> 密码访问')
        if self._check_dir_auth(site_name, name, site_dir):
            return public.returnMsg(False, '目录已经保护')
        auth = "{user}:{passwd}".format(user=get.username, passwd=passwd)
        auth_file = '{setup_path}/pass/{site_name}'.format(
            setup_path=self.setup_path, site_name=site_name)
        if not os.path.exists(auth_file):
            os.makedirs(auth_file)
        auth_file = auth_file + "/{}.pass".format(name)
        public.writeFile(auth_file, auth)
        # 配置独立认证文件
        self.set_dir_auth_file(site_info["site_path"], site_name, name,
                               get.username, site_dir, auth_file)
        # 配置站点主文件
        result = self.set_conf(site_name, "create")
        if result:
            return result
        # 检查配置
        webserver = public.get_webserver()
        result = self.check_site_conf(webserver, site_name, name)
        if result:
            return result
        # 写配置
        conf = {"name": name, "site_dir": get.site_dir, "auth_file": auth_file}
        self._write_conf(conf, site_name)
        public.serviceReload()
        return public.returnMsg(True, "创建成功")
Пример #20
0
 def __get_webserver_conffile(self):
     webserver = public.get_webserver()
     if webserver == 'nginx':
         filename = public.GetConfigValue('setup_path') + '/nginx/conf/nginx.conf'
     elif webserver == 'openlitespeed':
         filename = public.GetConfigValue('setup_path') + "/panel/vhost/openlitespeed/detail/phpmyadmin.conf"
     else:
         filename = public.GetConfigValue('setup_path') + '/apache/conf/extra/httpd-vhosts.conf'
     return filename
Пример #21
0
    def CheckStatusConf(self):
        if public.get_webserver() != 'nginx': return;
        filename = web.ctx.session.setupPath + '/panel/vhost/nginx/phpfpm_status.conf';
        if os.path.exists(filename): return;
        
        conf = '''server {
    listen 80;
    server_name 127.0.0.1;
    allow 127.0.0.1;
    location /nginx_status {
        stub_status on;
        access_log off;
    }
    location /phpfpm_52_status {
        fastcgi_pass unix:/tmp/php-cgi-52.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_53_status {
        fastcgi_pass unix:/tmp/php-cgi-53.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_54_status {
        fastcgi_pass unix:/tmp/php-cgi-54.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_55_status {
        fastcgi_pass unix:/tmp/php-cgi-55.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_56_status {
        fastcgi_pass unix:/tmp/php-cgi-56.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_70_status {
        fastcgi_pass unix:/tmp/php-cgi-70.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_71_status {
        fastcgi_pass unix:/tmp/php-cgi-71.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_72_status {
        fastcgi_pass unix:/tmp/php-cgi-72.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
}'''
        public.writeFile(filename,conf);
        public.serviceReload();
Пример #22
0
    def CheckStatusConf(self):
        if public.get_webserver() != 'nginx': return;
        filename = web.ctx.session.setupPath + '/panel/vhost/nginx/phpfpm_status.conf';
        if os.path.exists(filename): return;
        
        conf = '''server {
    listen 80;
    server_name 127.0.0.1;
    allow 127.0.0.1;
    location /nginx_status {
        stub_status on;
        access_log off;
    }
    location /phpfpm_52_status {
        fastcgi_pass unix:/tmp/php-cgi-52.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_53_status {
        fastcgi_pass unix:/tmp/php-cgi-53.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_54_status {
        fastcgi_pass unix:/tmp/php-cgi-54.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_55_status {
        fastcgi_pass unix:/tmp/php-cgi-55.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_56_status {
        fastcgi_pass unix:/tmp/php-cgi-56.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_70_status {
        fastcgi_pass unix:/tmp/php-cgi-70.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_71_status {
        fastcgi_pass unix:/tmp/php-cgi-71.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
    location /phpfpm_72_status {
        fastcgi_pass unix:/tmp/php-cgi-72.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
    }
}'''
        public.writeFile(filename,conf);
        public.serviceReload();
Пример #23
0
 def GetSSL(self, siteName):
     path = '/etc/letsencrypt/live/' + siteName;
     type = 0
     if os.path.exists(path + '/README'):  type = 1;
     if os.path.exists(path + '/partnerOrderId'):  type = 2;
     csrpath = path + "/fullchain.pem";  # 生成证书路径
     keypath = path + "/privkey.pem";  # 密钥文件路径
     key = public.readFile(keypath);
     csr = public.readFile(csrpath);
     file = self.setupPath + '/panel/vhost/' + public.get_webserver() + '/' + siteName + '.conf'
     conf = public.readFile(file);
     if not conf: return False
     keyText = 'SSLCertificateFile'
     if public.get_webserver() == 'nginx': keyText = 'ssl_certificate';
     status = True
     if (conf.find(keyText) == -1):
         status = False
         type = -1
     return status
Пример #24
0
 def get_phpmyadmin_conf(self):
     if public.get_webserver() == "nginx":
         conf_file = "/www/server/panel/vhost/nginx/phpmyadmin.conf"
         rep = "listen\s*(\d+)"
     else:
         conf_file = "/www/server/panel/vhost/apache/phpmyadmin.conf"
         rep = "Listen\s*(\d+)"
     # else:
     #     conf_file = "/www/server/panel/vhost/openlitespeed/listen/888.conf"
     #     rep = "address\s+\*:(\d+)"
     return {"conf_file":conf_file,"rep":rep}
Пример #25
0
 def CloseLogs(self,get):
     get.path = public.GetConfigValue('root_path')
     os.system('rm -f '+public.GetConfigValue('logs_path')+'/*')
     if public.get_webserver() == 'nginx':
         os.system('kill -USR1 `cat '+public.GetConfigValue('setup_path')+'/nginx/logs/nginx.pid`');
     else:
         os.system('/etc/init.d/httpd reload');
     
     public.WriteLog('TYPE_FILE','SITE_LOG_CLOSE')
     get.path = public.GetConfigValue('logs_path')
     return self.GetDirSize(get)
Пример #26
0
 def GetPHPInfo(self,get):
     if public.get_webserver() == "openlitespeed":
         shell_str = "/usr/local/lsws/lsphp{}/bin/php -i".format(get.version)
         return public.ExecShell(shell_str)[0]
     sPath = '/www/server/phpinfo'
     if os.path.exists(sPath):
         public.ExecShell("rm -rf " + sPath)
     p_file = '/dev/shm/phpinfo.php'
     public.writeFile(p_file,'<?php phpinfo(); ?>')
     phpinfo = public.request_php(get.version,'/phpinfo.php',p_file,'')
     if os.path.exists(p_file): os.remove(p_file)
     return phpinfo.decode();
Пример #27
0
 def CloseLogs(self,get):
     import web
     get.path = web.ctx.session.rootPath
     os.system('rm -f '+web.ctx.session.logsPath+'/*')
     if public.get_webserver() == 'nginx':
         os.system('kill -USR1 `cat '+web.ctx.session.setupPath+'/nginx/logs/nginx.pid`');
     else:
         os.system('/etc/init.d/httpd reload');
     
     public.WriteLog('TYPE_FILE','SITE_LOG_CLOSE')
     get.path = web.ctx.session.logsPath
     return self.GetDirSize(get)
Пример #28
0
 def CloseLogs(self,get):
     import web
     get.path = web.ctx.session.rootPath
     os.system('rm -f '+web.ctx.session.logsPath+'/*')
     if public.get_webserver() == 'nginx':
         os.system('kill -USR1 `cat '+web.ctx.session.setupPath+'/nginx/logs/nginx.pid`');
     else:
         os.system('/etc/init.d/httpd reload');
     
     public.WriteLog('TYPE_FILE','SITE_LOG_CLOSE')
     get.path = web.ctx.session.logsPath
     return self.GetDirSize(get)
Пример #29
0
    def GetShell(self,param):
        try:
            type=param['sType']
            if type=='toFile':
                shell=param.sFile
            else :
                head="#!/bin/bash\nPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin\nexport PATH\n"
                log='-access_log'
                if public.get_webserver()=='nginx':
                    log='.log'
                
                wheres={
                        'site'  :   head + "python " + web.ctx.session.setupPath+"/panel/script/backup.py site "+param['sName']+" "+param['save'],
                        'database': head + "python " + web.ctx.session.setupPath+"/panel/script/backup.py database "+param['sName']+" "+param['save'],
                        'logs'  :   head + "python " + web.ctx.session.setupPath+"/panel/script/logsBackup "+param['sName']+log+" "+param['save'],
                        'rememory' : head + "/bin/bash " + web.ctx.session.setupPath + '/panel/script/rememory.sh'
                        }
                if param['backupTo'] != 'localhost':
                    cfile = web.ctx.session.setupPath + "/panel/plugin/" + param['backupTo'] + "/" + param['backupTo'] + "_main.py";
                    if not os.path.exists(cfile): cfile = web.ctx.session.setupPath + "/panel/script/backup_" + param['backupTo'] + ".py";
                    
                    wheres={
                        'site'  :   head + "python " + cfile + " site " + param['sName'] + " " + param['save'],
                        'database': head + "python " + cfile + " database " + param['sName'] + " " + param['save'],
                        'logs'  :   head + "python " + web.ctx.session.setupPath+"/panel/script/logsBackup "+param['sName']+log+" "+param['save'],
                        'rememory' : head + "/bin/bash " + web.ctx.session.setupPath + '/panel/script/rememory.sh'
                        }
                
                try:
                    shell=wheres[type]
                except:
                    if type == 'toUrl':
                        shell = head + "curl -sS --connect-timeout 10 -m 60 '" + param.urladdress+"'"; 
                    else:
                        shell=head+param['sBody']
                    
                    shell += '''
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
'''
            cronPath=web.ctx.session.setupPath+'/cron'
            if not os.path.exists(cronPath): public.ExecShell('mkdir -p ' + cronPath);
            cronName=public.md5(public.md5(str(time.time()) + '_bt'))
            file = cronPath+'/' + cronName
            public.writeFile(file,self.CheckScript(shell))
            public.ExecShell('chmod 750 ' + file)
            return cronName
        except Exception,ex:
            return public.returnMsg(False, 'FILE_WRITE_ERR')
Пример #30
0
 def change_phpmyadmin_ssl_port(self,get):
     if public.get_webserver() == "openlitespeed":
         return public.returnMsg(False, 'NOT_SUPPORT_OLS')
     import re
     try:
         port = int(get.port)
         if 1 > port > 65535:
             return public.returnMsg(False, 'PORT_CHECK_RANGE')
     except:
         return public.returnMsg(False, 'PORT_FORMAT_ERR')
     for i in ["nginx","apache"]:
         file = "/www/server/panel/vhost/{}/phpmyadmin.conf".format(i)
         conf = public.readFile(file)
         if not conf:
             return public.returnMsg(False,"PHPMYADMIN_SSL_ERR",(i,))
         rulePort = ['80', '443', '21', '20', '8080', '8081', '8089', '11211', '6379']
         if get.port in rulePort:
             return public.returnMsg(False, 'AJAX_PHPMYADMIN_PORT_ERR')
         if i == "nginx":
             if not os.path.exists("/www/server/panel/vhost/apache/phpmyadmin.conf"):
                 return public.returnMsg(False, "PHPMYADMIN_SSL_ERR1")
             rep = "listen\s*([0-9]+)\s*.*;"
             oldPort = re.search(rep, conf)
             if not oldPort:
                 return public.returnMsg(False, 'PHPMYADMIN_SSL_ERR2')
             oldPort = oldPort.groups()[0]
             conf = re.sub(rep, 'listen ' + get.port + ' ssl;', conf)
         else:
             rep = "Listen\s*([0-9]+)\s*\n"
             oldPort = re.search(rep, conf)
             if not oldPort:
                 return public.returnMsg(False, 'PHPMYADMIN_SSL_ERR3')
             oldPort = oldPort.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(file, conf)
         public.serviceReload()
         if i=="apache":
             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')
Пример #31
0
 def change_phpmyadmin_ssl_port(self,get):
     if public.get_webserver() == "openlitespeed":
         return public.returnMsg(False, 'The current web server is openlitespeed. This function is not supported yet.')
     import re
     try:
         port = int(get.port)
         if 1 > port > 65535:
             return public.returnMsg(False, 'Port range is incorrect')
     except:
         return public.returnMsg(False, 'The port format is incorrect')
     for i in ["nginx","apache"]:
         file = "/www/server/panel/vhost/{}/phpmyadmin.conf".format(i)
         conf = public.readFile(file)
         if not conf:
             return public.returnMsg(False,"Did not find the {} configuration file, please try to close the ssl port settings before opening".format(i))
         rulePort = ['80', '443', '21', '20', '8080', '8081', '8089', '11211', '6379']
         if get.port in rulePort:
             return public.returnMsg(False, 'AJAX_PHPMYADMIN_PORT_ERR')
         if i == "nginx":
             if not os.path.exists("/www/server/panel/vhost/apache/phpmyadmin.conf"):
                 return public.returnMsg(False, "Did not find the apache phpmyadmin ssl configuration file, please try to close the ssl port settings before opening")
             rep = "listen\s*([0-9]+)\s*.*;"
             oldPort = re.search(rep, conf)
             if not oldPort:
                 return public.returnMsg(False, 'Did not detect the port that nginx phpmyadmin listens, please confirm whether the file has been manually modified.')
             oldPort = oldPort.groups()[0]
             conf = re.sub(rep, 'listen ' + get.port + ' ssl;', conf)
         else:
             rep = "Listen\s*([0-9]+)\s*\n"
             oldPort = re.search(rep, conf)
             if not oldPort:
                 return public.returnMsg(False, 'Did not detect the port that apache phpmyadmin listens, please confirm whether the file has been manually modified.')
             oldPort = oldPort.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(file, conf)
         public.serviceReload()
         if i=="apache":
             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')
Пример #32
0
 def install(self,get):
     pluginInfo = self.GetFind(get.name);
     if not pluginInfo:
         import json
         pluginInfo = json.loads(public.readFile(self.__install_path + '/' + get.name + '/info.json'));
     
     if pluginInfo['tip'] == 'lib':
         if not os.path.exists(self.__install_path + '/' + pluginInfo['name']): os.system('mkdir -p ' + self.__install_path + '/' + pluginInfo['name']);
         if not hasattr(web.ctx.session,'downloadUrl'): web.ctx.session.downloadUrl = 'http://download.bt.cn';
         downloadUrl = web.ctx.session.downloadUrl + '/install/lib/plugin/' + pluginInfo['name'] + '/install.sh';
         toFile = self.__install_path + '/' + pluginInfo['name'] + '/install.sh';
         public.downloadFile(downloadUrl,toFile);
         os.system('/bin/bash ' + toFile + ' install');
         if self.checksSetup(pluginInfo['name'],pluginInfo['checks'],pluginInfo['versions'])[0]['status'] or os.path.exists(self.__install_path + '/' + get.name):
             public.WriteLog('TYPE_SETUP','PLUGIN_INSTALL_LIB',(pluginInfo['title'],));
             os.system('rm -f ' + toFile);
             return public.returnMsg(True,'PLUGIN_INSTALL_SUCCESS');
         return public.returnMsg(False,'PLUGIN_INSTALL_ERR');
     else:
         import db,time
         path = web.ctx.session.setupPath + '/php'
         if not os.path.exists(path): os.system("mkdir -p " + path);
         issue = public.readFile('/etc/issue')
         if web.ctx.session.server_os['x'] != 'RHEL': get.type = '3'
         
         apacheVersion='false';
         if public.get_webserver() == 'apache':
             apacheVersion = public.readFile(web.ctx.session.setupPath+'/apache/version.pl');
         public.writeFile('/var/bt_apacheVersion.pl',apacheVersion)
         public.writeFile('/var/bt_setupPath.conf',web.ctx.session.rootPath)
         isTask = '/tmp/panelTask.pl'
         
         mtype = 'install';
         mmsg = '安装';
         if hasattr(get, 'upgrade'):
             if get.upgrade:
                 mtype = 'update';
                 mmsg = 'upgrade';
         execstr = "cd " + web.ctx.session.setupPath + "/panel/install && /bin/bash install_soft.sh " + get.type + " "+mtype+" " + get.name + " "+ get.version;
         sql = db.Sql()
         if hasattr(get,'id'):
             id = get.id;
         else:
             id = None;
         sql.table('tasks').add('id,name,type,status,addtime,execstr',(None, mmsg + '['+get.name+'-'+get.version+']','execshell','0',time.strftime('%Y-%m-%d %H:%M:%S'),execstr))
         public.writeFile(isTask,'True')
         public.WriteLog('TYPE_SETUP','PLUGIN_ADD',(get.name,get.version));
         return public.returnMsg(True,'PLUGIN_INSTALL');
Пример #33
0
    def CheckStatusConf(self):
        if public.get_webserver() != 'nginx': return
        filename = session['setupPath'] + '/panel/vhost/nginx/phpfpm_status.conf'
        if os.path.exists(filename):
            if public.ReadFile(filename).find('nginx_status')!=-1: return
        
        conf = '''server {
    listen 80;
    server_name 127.0.0.1;
    allow 127.0.0.1;
    location /nginx_status {
        stub_status on;
        access_log off;
    }
}'''
        public.writeFile(filename,conf)
        public.serviceReload()
Пример #34
0
    def change_phpmyadmin_ssl_port(self, get):
        import re
        try:
            port = int(get.port)
            if 1 > port > 65535:
                return public.returnMsg(False, '端口范围不正确')
        except:
            return public.returnMsg(False, '端口格式不正确')
        filename = self.get_phpmyadmin_conf()
        conf = public.readFile(filename["conf_file"])
        if conf:
            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_file"], 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')
        else:
            return public.returnMsg(False, '设置端口错误,请先开启 PhoMyAdmin SSL 后再设置')
Пример #35
0
def get_site_run_path(siteName, sitePath):
    '''
        @name 获取网站运行目录
        @author hwliang<2020-08-05>
        @param siteName(string) 网站名称
        @param sitePath(string) 网站根目录
        @return string
    '''
    global webserver_type, setupPath
    if not webserver_type:
        webserver_type = public.get_webserver()
    path = None
    if webserver_type == 'nginx':
        filename = setupPath + '/panel/vhost/nginx/' + siteName + '.conf'
        if os.path.exists(filename):
            conf = public.readFile(filename)
            rep = r'\s*root\s+(.+);'
            tmp1 = re.search(rep, conf)
            if tmp1: path = tmp1.groups()[0]

    elif webserver_type == 'apache':
        filename = setupPath + '/panel/vhost/apache/' + siteName + '.conf'
        if os.path.exists(filename):
            conf = public.readFile(filename)
            rep = r'\s*DocumentRoot\s*"(.+)"\s*\n'
            tmp1 = re.search(rep, conf)
            if tmp1: path = tmp1.groups()[0]
    else:
        filename = setupPath + '/panel/vhost/openlitespeed/' + siteName + '.conf'
        if os.path.exists(filename):
            conf = public.readFile(filename)
            rep = r"vhRoot\s*(.*)"
            path = re.search(rep, conf)
            if not path:
                path = None
            else:
                path = path.groups()[0]

    if not path:
        path = sitePath

    return path
Пример #36
0
 def InstallSoft(self,get):
     import db,time,web
     path = web.ctx.session.setupPath + '/php'
     if not os.path.exists(path): os.system("mkdir -p " + path);
     if web.ctx.session.server_os['x'] != 'RHEL': get.type = '3'
     apacheVersion='false';
     if public.get_webserver() == 'apache':
         apacheVersion = public.readFile(web.ctx.session.setupPath+'/apache/version.pl');
     public.writeFile('/var/bt_apacheVersion.pl',apacheVersion)
     public.writeFile('/var/bt_setupPath.conf',web.ctx.session.rootPath)
     isTask = '/tmp/panelTask.pl'
     execstr = "cd " + web.ctx.session.setupPath + "/panel/install && /bin/bash install_soft.sh " + get.type + " install " + get.name + " "+ get.version;
     sql = db.Sql()
     if hasattr(get,'id'):
         id = get.id;
     else:
         id = None;
     sql.table('tasks').add('id,name,type,status,addtime,execstr',(None,'安装['+get.name+'-'+get.version+']','execshell','0',time.strftime('%Y-%m-%d %H:%M:%S'),execstr))
     public.writeFile(isTask,'True')
     public.WriteLog('TYPE_SETUP','PLUGIN_ADD',(get.name,get.version));
     time.sleep(0.1);
     return public.returnMsg(True,'PLUGIN_ADD');
Пример #37
0
 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');
Пример #38
0
 def UpdatePanel(self,get):
     #return public.returnMsg(False,'演示服务器,禁止此操作!');
     try:
         if not public.IsRestart(): return public.returnMsg(False,'EXEC_ERR_TASK');
         import web,json
         if int(web.ctx.session.config['status']) == 0:
             public.httpGet(web.ctx.session.home+'/Api/SetupCount?type=Linux');
             public.M('config').where("id=?",('1',)).setField('status',1);
         
         #取回远程版本信息
         if hasattr(web.ctx.session,'updateInfo') == True and hasattr(get,'check') == False:
             updateInfo = web.ctx.session.updateInfo;
         else:
             login_temp = 'data/login.temp';
             if os.path.exists(login_temp):
                 logs = public.readFile(login_temp)
                 os.remove(login_temp);
             else:
                 logs = '';
             import psutil,panelPlugin,system;
             mem = psutil.virtual_memory();
             mplugin = panelPlugin.panelPlugin();
             mplugin.ROWS = 10000;
             panelsys = system.system();
             data = {}
             data['sites'] = str(public.M('sites').count());
             data['ftps'] = str(public.M('ftps').count());
             data['databases'] = str(public.M('databases').count());
             data['system'] = panelsys.GetSystemVersion() + '|' + str(mem.total / 1024 / 1024) + 'MB|' + public.getCpuType() + '*' + str(psutil.cpu_count()) + '|' + public.get_webserver() + '|' + web.ctx.session.version;
             data['system'] += '||'+self.GetInstalleds(mplugin.getPluginList(None));
             data['logs'] = logs
             data['oem'] = ''
             data['intrusion'] = self.get_ssh_intrusion();
             msg = public.getMsg('PANEL_UPDATE_MSG');
             sUrl = web.ctx.session.home + '/Api/updateLinux';
             betaIs = 'data/beta.pl';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False':
                     sUrl = web.ctx.session.home + '/Api/updateLinuxBeta';
                     msg = public.getMsg('PANEL_UPDATE_MSG_TEST');
             
             betaIs = 'plugin/beta/config.conf';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False':
                     sUrl = web.ctx.session.home + '/Api/updateLinuxBeta';
                     msg = public.getMsg('PANEL_UPDATE_MSG_TEST');
             
             updateInfo = json.loads(public.httpPost(sUrl,data));
             if not updateInfo: return public.returnMsg(False,"CONNECT_ERR");
             updateInfo['msg'] = msg;
             web.ctx.session.updateInfo = updateInfo;
             
         #检查是否需要升级
         if updateInfo['version'] == web.ctx.session.version:
             try:
                 return public.returnMsg(False,updateInfo['msg']);
             except:
                 return public.returnMsg(False,'PANEL_UPDATE_ERR_NEW');
         
         
         #是否执行升级程序 
         if(updateInfo['force'] == True or hasattr(get,'toUpdate') == True or os.path.exists('data/autoUpdate.pl') == True):
             setupPath = web.ctx.session.setupPath;
             uptype = 'update';
             betaIs = 'plugin/beta/config.conf';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False': uptype = 'updateTest';
             betaIs = 'data/beta.pl';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False': uptype = 'updateTest';
             httpUrl = public.get_url();
             if httpUrl: updateInfo['downUrl'] =  httpUrl + '/install/' + uptype + '/LinuxPanel-' + updateInfo['version'] + '.zip';
             
             public.downloadFile(updateInfo['downUrl'],'panel.zip');
             if os.path.getsize('panel.zip') < 1048576: return public.returnMsg(False,"PANEL_UPDATE_ERR_DOWN");
             public.ExecShell('unzip -o panel.zip -d ' + setupPath + '/');
             import compileall
             if os.path.exists(setupPath + '/panel/main.py'): public.ExecShell('rm -f ' + setupPath + '/panel/*.pyc');
             if os.path.exists(setupPath + '/panel/class/common.py'): public.ExecShell('rm -f ' + setupPath + '/panel/class/*.pyc');
             
             compileall.compile_dir(setupPath + '/panel');
             compileall.compile_dir(setupPath + '/panel/class');
             public.ExecShell('rm -f panel.zip');
             web.ctx.session.version = updateInfo['version']
             return public.returnMsg(True,'PANEL_UPDATE',(updateInfo['version'],));
         
         #输出新版本信息
         data = {
             'status' : True,
             'version': updateInfo['version'],
             'updateMsg' : updateInfo['updateMsg']
         };
         
         public.ExecShell('rm -rf /www/server/phpinfo/*');
         return data;
     except Exception,ex:
         return public.returnMsg(False,"CONNECT_ERR");
Пример #39
0
 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,));