Example #1
0
    def listPackagesJson(self):
        try:

            records = Package.objects.all()

            json_data = "["
            checker = 0

            for items in records:
                dic = {
                    'id': items.id,
                    'packageName': items.packageName,
                    'domains': items.allowedDomains,
                    'diskSpace': items.diskSpace,
                    'bandwidth': items.bandwidth,
                    'ftpAccounts ': items.ftpAccounts,
                    'dataBases': items.dataBases,
                    'emailAccounts': items.emailAccounts
                }

                if checker == 0:
                    json_data = json_data + json.dumps(dic)
                    checker = 1
                else:
                    json_data = json_data + ',' + json.dumps(dic)

            json_data = json_data + ']'
            final_json = json.dumps(json_data)
            print final_json

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #2
0
    def listFTPJson(self, virtualHostName):
        try:

            records = FTPUtilities.getFTPRecords(virtualHostName)

            json_data = "["
            checker = 0

            for items in records:
                dic = {
                    'id': items.id,
                    'username': items.user,
                    'path': items.dir
                }

                if checker == 0:
                    json_data = json_data + json.dumps(dic)
                    checker = 1
                else:
                    json_data = json_data + ',' + json.dumps(dic)

            json_data = json_data + ']'
            final_json = json.dumps(json_data)
            print final_json

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #3
0
    def listEmailsJson(self, virtualHostName):
        try:

            records = mailUtilities.getEmailAccounts(virtualHostName)

            json_data = "["
            checker = 0

            for items in records:
                dic = {
                    'email': items.email,
                }

                if checker == 0:
                    json_data = json_data + json.dumps(dic)
                    checker = 1
                else:
                    json_data = json_data + ',' + json.dumps(dic)

            json_data = json_data + ']'
            final_json = json.dumps(json_data)
            print final_json

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #4
0
 def deleteDNSZone(self, virtualHostName):
     try:
         DNS.deleteDNSZone(virtualHostName)
         self.printStatus(1, 'None')
     except BaseException, msg:
         logger.writeforCLI(str(msg), "Error", stack()[0][3])
         self.printStatus(0, str(msg))
Example #5
0
 def deleteDNSRecord(self, recordID):
     try:
         DNS.deleteDNSRecord(recordID)
         self.printStatus(1, 'None')
     except BaseException, msg:
         logger.writeforCLI(str(msg), "Error", stack()[0][3])
         self.printStatus(0, str(msg))
Example #6
0
    def listDNSZonesJson(self):
        try:

            records = DNS.getDNSZones()

            json_data = "["
            checker = 0

            for items in records:
                dic = {
                    'id': items.id,
                    'name': items.name,
                }

                if checker == 0:
                    json_data = json_data + json.dumps(dic)
                    checker = 1
                else:
                    json_data = json_data + ',' + json.dumps(dic)

            json_data = json_data + ']'
            final_json = json.dumps(json_data)
            print final_json

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #7
0
    def listDNSJson(self, virtualHostName):
        try:

            records = DNS.getDNSRecords(virtualHostName)

            json_data = "["
            checker = 0

            for items in records:
                dic = {
                    'id': items.id,
                    'type': items.type,
                    'name': items.name,
                    'content': items.content,
                    'priority': items.prio,
                    'ttl': items.ttl
                }

                if checker == 0:
                    json_data = json_data + json.dumps(dic)
                    checker = 1
                else:
                    json_data = json_data + ',' + json.dumps(dic)

            json_data = json_data + ']'
            final_json = json.dumps(json_data)
            print final_json

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #8
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))
Example #9
0
    def listWebsitesPretty(self):
        try:
            from prettytable import PrettyTable

            websites = Websites.objects.all()
            ipFile = "/etc/cyberpanel/machineIP"
            f = open(ipFile)
            ipData = f.read()
            ipAddress = ipData.split('\n', 1)[0]

            table = PrettyTable([
                'ID', 'Domain', 'IP Address', 'Package', 'Owner', 'State',
                'Email'
            ])

            for items in websites:
                if items.state == 0:
                    state = "Suspended"
                else:
                    state = "Active"
                table.add_row([
                    items.id, items.domain, ipAddress,
                    items.package.packageName, items.admin.userName, state,
                    items.adminEmail
                ])
            print table

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #10
0
    def listDatabasesJson(self, virtualHostName):
        try:

            records = mysqlUtilities.getDatabases(virtualHostName)

            json_data = "["
            checker = 0

            for items in records:
                dic = {
                    'id': items.id,
                    'dbName': items.dbName,
                    'dbUser': items.dbUser,
                }

                if checker == 0:
                    json_data = json_data + json.dumps(dic)
                    checker = 1
                else:
                    json_data = json_data + ',' + json.dumps(dic)

            json_data = json_data + ']'
            final_json = json.dumps(json_data)
            print final_json

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #11
0
    def restoreBackup(self, fileName):
        try:
            if os.path.exists('/home/backup/' + fileName):
                dir = "CyberPanelRestore"
            else:
                dir = 'CLI'

            backupUtilities.submitRestore(fileName, dir)

            while (1):
                time.sleep(1)
                finalData = json.dumps({'backupFile': fileName, "dir": dir})
                r = requests.post("http://localhost:5003/backup/restoreStatus",
                                  data=finalData,
                                  verify=False)
                data = json.loads(r.text)

                if data['abort'] == 1 and data['running'] == "Error":
                    print 'Failed to restore backup, Error message : ' + data[
                        'status'] + '\n'
                    break
                elif data['abort'] == 1 and data['running'] == "Completed":
                    print '\n\n'
                    print 'Backup restore completed.\n'
                    break
                else:
                    print 'Waiting for restore to complete. Current status: ' + data[
                        'status']

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #12
0
 def createDNSZone(self, virtualHostName, owner):
     try:
         admin = Administrator.objects.get(userName=owner)
         DNS.dnsTemplate(virtualHostName, admin)
         self.printStatus(1, 'None')
     except BaseException, msg:
         logger.writeforCLI(str(msg), "Error", stack()[0][3])
         self.printStatus(0, str(msg))
Example #13
0
    def deleteWebsite(self, domainName):
        try:
            vhost.deleteVirtualHostConfigurations(domainName)
            self.printStatus(1, 'None')

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #14
0
    def deletePackage(self, packageName):
        try:

            delPack = Package.objects.get(packageName=packageName)
            delPack.delete()
            self.printStatus(1, 'None')

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Example #15
0
 def createDNSRecord(self, virtualHostName, name, recordType, value,
                     priority, ttl):
     try:
         zone = DNS.getZoneObject(virtualHostName)
         DNS.createDNSRecord(zone, name, recordType, value, int(priority),
                             int(ttl))
         self.printStatus(1, 'None')
     except BaseException, msg:
         logger.writeforCLI(str(msg), "Error", stack()[0][3])
         self.printStatus(0, str(msg))
Example #16
0
    def deleteFTPAccount(self, userName):
        try:

            result = FTPUtilities.submitFTPDeletion(userName)
            if result[0] == 1:
                self.printStatus(1, 'None')
            else:
                self.printStatus(1, result[1])
        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Example #17
0
    def deleteWebsite(self, domainName):
        try:

            numberOfWebsites = Websites.objects.count(
            ) + ChildDomains.objects.count()
            vhost.deleteVirtualHostConfigurations(domainName, numberOfWebsites)
            self.printStatus(1, 'None')

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #18
0
    def deleteEmail(self, email):
        try:

            result = mailUtilities.deleteEmailAccount(email)
            if result[0] == 1:
                self.printStatus(1, 'None')
            else:
                self.printStatus(1, result[1])
        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Example #19
0
    def changeFTPPassword(self, userName, password):
        try:

            result = FTPUtilities.changeFTPPassword(userName, password)
            if result[0] == 1:
                self.printStatus(1, 'None')
            else:
                self.printStatus(1, result[1])
        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Example #20
0
    def createFTPAccount(self, domain, userName, password, owner):
        try:

            result = FTPUtilities.submitFTPCreation(domain, userName, password,
                                                    'None', owner)
            if result[0] == 1:
                self.printStatus(1, 'None')
            else:
                self.printStatus(1, result[1])
        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Example #21
0
    def createEmail(self, domain, userName, password):
        try:

            result = mailUtilities.createEmailAccount(domain, userName,
                                                      password)
            if result[0] == 1:
                self.printStatus(1, 'None')
            else:
                self.printStatus(1, result[1])
        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Example #22
0
    def createBackup(self, virtualHostName):
        try:
            backupLogPath = "/usr/local/lscp/logs/backup_log." + time.strftime(
                "%I-%M-%S-%a-%b-%Y")

            print 'Backup logs to be generated in %s' % (backupLogPath)

            backupSchedule.createLocalBackup(virtualHostName, backupLogPath)

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #23
0
    def deleteDatabase(self, dbName):
        try:

            result = mysqlUtilities.submitDBDeletion(dbName)

            if result[0] == 1:
                self.printStatus(1, 'None')
            else:
                self.printStatus(1, result[1])
        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Example #24
0
    def createDatabase(self, dbName, dbUsername, dbPassword, databaseWebsite):
        try:

            result = mysqlUtilities.submitDBCreation(dbName, dbUsername,
                                                     dbPassword,
                                                     databaseWebsite)
            if result[0] == 1:
                self.printStatus(1, 'None')
            else:
                self.printStatus(1, result[1])
        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Example #25
0
    def deleteChild(self, childDomain):
        try:

            result = virtualHostUtilities.deleteDomain(childDomain)

            if result[0] == 1:
                self.printStatus(1, 'None')
            else:
                self.printStatus(0, result[1])

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #26
0
    def listDNSZonesPretty(self):
        try:
            from prettytable import PrettyTable

            records = records = DNS.getDNSZones()

            table = PrettyTable(['ID', 'Name'])

            for items in records:
                table.add_row([items.id, items.name])
            print table

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #27
0
    def listFTPPretty(self, virtualHostName):
        try:
            from prettytable import PrettyTable

            records = FTPUtilities.getFTPRecords(virtualHostName)

            table = PrettyTable(['ID', 'User', 'Path'])

            for items in records:
                table.add_row([items.id, items.user, items.dir])
            print table

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #28
0
    def listDatabasesPretty(self, virtualHostName):
        try:
            from prettytable import PrettyTable

            records = mysqlUtilities.getDatabases(virtualHostName)

            table = PrettyTable(['ID', 'Database Name', 'Database User'])

            for items in records:
                table.add_row([items.id, items.dbName, items.dbUser])
            print table

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #29
0
    def listEmailsPretty(self, virtualHostName):
        try:
            from prettytable import PrettyTable

            records = mailUtilities.getEmailAccounts(virtualHostName)

            table = PrettyTable(['Email'])

            for items in records:
                table.add_row([items.email])
            print table

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print 0
Example #30
0
    def changePackage(self, virtualHostName, packageName):
        try:
            if Websites.objects.filter(domain=virtualHostName).count() == 0:
                self.printStatus(0, 'This website does not exists.')
            if Package.objects.filter(packageName=packageName).count() == 0:
                self.printStatus(0, 'This package does not exists.')

            website = Websites.objects.get(domain=virtualHostName)
            package = Package.objects.get(packageName=packageName)

            website.package = package
            website.save()

            self.printStatus(1, 'None')

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))