コード例 #1
0
    def issueSelfSignedSSL(self, virtualHost):
        try:

            try:
                website = ChildDomains.objects.get(domain=virtualHost)
                adminEmail = website.master.adminEmail
            except:
                website = Websites.objects.get(domain=virtualHost)
                adminEmail = website.adminEmail

            pathToStoreSSL = "/etc/letsencrypt/live/" + virtualHost
            command = 'mkdir -p ' + pathToStoreSSL
            ProcessUtilities.executioner(command)

            pathToStoreSSLPrivKey = "/etc/letsencrypt/live/" + virtualHost + "/privkey.pem"
            pathToStoreSSLFullChain = "/etc/letsencrypt/live/" + virtualHost + "/fullchain.pem"

            command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout ' + pathToStoreSSLPrivKey + ' -out ' + pathToStoreSSLFullChain
            ProcessUtilities.executioner(command)

            sslUtilities.installSSLForDomain(virtualHost, adminEmail)
            ProcessUtilities.restartLitespeed()
            self.printStatus(1, 'None')

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
コード例 #2
0
    def createDomain(website):
        try:
            virtualHostName = website.domain

            confPath = vhost.Server_root + "/conf/vhosts/" + virtualHostName
            completePathToConfigFile = confPath + "/vhost.conf"

            confPath = vhost.Server_root + "/conf/vhosts/" + virtualHostName
            FNULL = open(os.devnull, 'w')
            if not os.path.exists(confPath):
                command = 'mkdir -p ' + confPath
                ServerStatusUtil.executioner(command, FNULL)

            if vhost.perHostDomainConf(website.path, website.master.domain,
                                       virtualHostName,
                                       completePathToConfigFile,
                                       website.master.adminEmail,
                                       website.phpSelection,
                                       website.master.externalApp, 1) == 1:
                pass
            else:
                return 0

            retValues = vhost.createConfigInMainDomainHostFile(
                virtualHostName, website.master.domain)

            if retValues[0] == 0:
                return 0

            if os.path.exists('/etc/letsencrypt/live/' + virtualHostName):
                sslUtilities.installSSLForDomain(virtualHostName,
                                                 website.master.adminEmail)

            vhostPath = vhost.Server_root + "/conf/vhosts"
            FNULL = open(os.devnull, 'w')
            command = "chown -R " + "lsadm" + ":" + "lsadm" + " " + vhostPath
            cmd = shlex.split(command)
            subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(str(msg))
コード例 #3
0
def issueSSL(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

                data = json.loads(request.body)
                virtualHost = data['virtualHost']

                try:
                    website = ChildDomains.objects.get(domain=virtualHost)
                except:
                    website = Websites.objects.get(domain=virtualHost)

                srcPrivKey = "/etc/letsencrypt/live/" + virtualHost + "/privkey.pem"
                srcFullChain = "/etc/letsencrypt/live/" + virtualHost + "/fullchain.pem"

                pathToStoreSSL = virtualHostUtilities.Server_root + "/conf/vhosts/" + "SSL-" + virtualHost

                pathToStoreSSLPrivKey = pathToStoreSSL + "/privkey.pem"
                pathToStoreSSLFullChain = pathToStoreSSL + "/fullchain.pem"

                if os.path.exists(pathToStoreSSLPrivKey):
                    os.remove(pathToStoreSSLPrivKey)
                if os.path.exists(pathToStoreSSLFullChain):
                    os.remove(pathToStoreSSLFullChain)

                adminEmail = "email@" + virtualHost

                if not (os.path.exists(srcPrivKey)
                        and os.path.exists(srcFullChain)):
                    path = ''
                    try:
                        path = data['path']
                    except:
                        path = "/home/" + virtualHost + "/public_html"

                    ssl_responce = sslUtilities.obtainSSLForADomain(
                        virtualHost, adminEmail, path)
                    if ssl_responce == 1:
                        sslUtilities.installSSLForDomain(virtualHost)
                        installUtilities.reStartLiteSpeed()
                        website.ssl = 1
                        website.save()
                        data_ret = {"SSL": 1, 'error_message': "None"}
                        json_data = json.dumps(data_ret)
                        return HttpResponse(json_data)

                    else:
                        data_ret = {
                            "SSL":
                            0,
                            'error_message':
                            str(ssl_responce) +
                            ", for more information see CyberCP main log file."
                        }
                        json_data = json.dumps(data_ret)
                        return HttpResponse(json_data)
                else:
                    ###### Copy SSL To config location ######

                    try:
                        os.mkdir(pathToStoreSSL)
                    except BaseException, msg:
                        logging.writeToFile(
                            str(msg) +
                            " [Directory for SSL already exists.. Continuing [obtainSSLForADomain]]"
                        )

                    srcPrivKey = "/etc/letsencrypt/live/" + virtualHost + "/privkey.pem"
                    srcFullChain = "/etc/letsencrypt/live/" + virtualHost + "/fullchain.pem"

                    shutil.copy(srcPrivKey, pathToStoreSSLPrivKey)
                    shutil.copy(srcFullChain, pathToStoreSSLFullChain)

                    website.ssl = 1
                    website.save()

                    sslUtilities.installSSLForDomain(virtualHost)
                    installUtilities.reStartLiteSpeed()

                    data_ret = {"SSL": 1, 'error_message': "None"}
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

        except BaseException, msg:
            data_ret = {"SSL": 0, 'error_message': str(msg)}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
    except KeyError:
        data_ret = {"SSL": 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
コード例 #4
0
def obtainHostNameSSL(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

                data = json.loads(request.body)
                virtualHost = data['virtualHost']

                website = Websites.objects.get(domain=virtualHost)

                srcPrivKey = "/etc/letsencrypt/live/" + virtualHost + "/privkey.pem"
                srcFullChain = "/etc/letsencrypt/live/" + virtualHost + "/fullchain.pem"

                pathToStoreSSL = virtualHostUtilities.Server_root + "/conf/vhosts/" + "SSL-" + virtualHost

                pathToStoreSSLPrivKey = pathToStoreSSL + "/privkey.pem"
                pathToStoreSSLFullChain = pathToStoreSSL + "/fullchain.pem"

                destPrivKey = "/usr/local/lscp/key.pem"
                destCert = "/usr/local/lscp/cert.pem"

                ## removing old certs

                if os.path.exists(pathToStoreSSLPrivKey):
                    os.remove(pathToStoreSSLPrivKey)
                if os.path.exists(pathToStoreSSLFullChain):
                    os.remove(pathToStoreSSLFullChain)

                ## removing old certs for lscpd
                if os.path.exists(destPrivKey):
                    os.remove(destPrivKey)
                if os.path.exists(destCert):
                    os.remove(destCert)

                adminEmail = "email@" + virtualHost

                if not (os.path.exists(srcPrivKey)
                        and os.path.exists(srcFullChain)):
                    path = "/home/" + virtualHost + "/public_html"
                    ssl_responce = sslUtilities.obtainSSLForADomain(
                        virtualHost, adminEmail, path)
                    if ssl_responce == 1:
                        sslUtilities.installSSLForDomain(virtualHost)
                        installUtilities.reStartLiteSpeed()
                        website.ssl = 1
                        website.save()

                        ## lcpd specific functions

                        shutil.copy(srcPrivKey, destPrivKey)
                        shutil.copy(srcFullChain, destCert)

                        command = 'sudo systemctl restart lscpd'

                        cmd = shlex.split(command)

                        res = subprocess.call(cmd)

                        data_ret = {"SSL": 1, 'error_message': "None"}
                        json_data = json.dumps(data_ret)
                        return HttpResponse(json_data)

                    else:
                        data_ret = {
                            "SSL":
                            0,
                            'error_message':
                            str(ssl_responce) +
                            ", for more information see CyberCP main log file."
                        }
                        json_data = json.dumps(data_ret)
                        return HttpResponse(json_data)
                else:
                    ###### Copy SSL To config location ######

                    try:
                        os.mkdir(pathToStoreSSL)
                    except BaseException, msg:
                        logging.writeToFile(
                            str(msg) +
                            " [Directory for SSL already exists.. Continuing [obtainSSLForADomain]]"
                        )

                    srcPrivKey = "/etc/letsencrypt/live/" + virtualHost + "/privkey.pem"
                    srcFullChain = "/etc/letsencrypt/live/" + virtualHost + "/fullchain.pem"

                    shutil.copy(srcPrivKey, pathToStoreSSLPrivKey)
                    shutil.copy(srcFullChain, pathToStoreSSLFullChain)

                    ## lcpd specific functions

                    shutil.copy(srcPrivKey, destPrivKey)
                    shutil.copy(srcFullChain, destCert)

                    command = 'sudo systemctl restart lscpd'

                    cmd = shlex.split(command)

                    res = subprocess.call(cmd)
                    website.ssl = 1
                    website.save()

                    data_ret = {"SSL": 1, 'error_message': "None"}
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

        except BaseException, msg:
            data_ret = {"SSL": 0, 'error_message': str(msg)}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
    except KeyError:
        data_ret = {"SSL": 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)