def createDomain(self, masterDomain, domainName, owner, php, ssl, dkim, openBasedir): try: path = '/home/' + masterDomain + '/public_html/' + domainName phpSelection = 'PHP ' + php result = virtualHostUtilities.createDomain(masterDomain, domainName, phpSelection, path, ssl, dkim, openBasedir, owner) 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]) self.printStatus(0, str(msg))
def createDummyChild(self, childDomain): path = '/home/%s/public_html/%s' % (self.mainDomain, childDomain) virtualHostUtilities.createDomain(self.mainDomain, childDomain, self.PHPVersion, path, 0, 0, 0, 'admin', 0)
def CreateChildDomains(self): try: message = 'Creating child domains from archive file: %s' % ( self.backupFile) logging.statusWriter(self.logFile, message, 1) CompletPathToExtractedArchive = cPanelImporter.mainBackupPath + self.fileName ### Find Possible Child Domains message = 'Finding Addon/Subdomains from backup file %s. Account main domain was %s.' % ( self.backupFile, self.mainDomain) logging.statusWriter(self.logFile, message, 1) UserData = '%s/userdata/main' % (CompletPathToExtractedArchive) data = open(UserData, 'r').readlines() Domains = [] addonStatus = 0 subDomainsStatus = 0 for items in data: if items.find('addon_domains') > -1: addonStatus = 1 continue if addonStatus == 1: if items.find('main_domain') > -1: addonStatus = 0 continue else: cDomain = items.split(':')[0].replace(' ', '') if len(cDomain) < 2: continue Domains.append(ChildDomains(cDomain, 1)) continue ## if items.find('sub_domains') > -1: subDomainsStatus = 1 continue existCheck = 0 if subDomainsStatus == 1: cDomain = items.split(' ')[-1].replace('\n', '') for items in Domains: if cDomain.find(items.domain) > -1: existCheck = 1 if existCheck == 0: if len(cDomain) > 2: Domains.append(ChildDomains(cDomain, 0)) message = 'Following Addon/Subdomains found for backup file %s. Account main domain was %s.' % ( self.backupFile, self.mainDomain) logging.statusWriter(self.logFile, message, 1) for items in Domains: print items.domain ## Starting Child-domains creation message = 'Starting Addon/Subdomains creation from backup file %s. Account main domain was %s.' % ( self.backupFile, self.mainDomain) logging.statusWriter(self.logFile, message, 1) for items in Domains: try: message = 'Creating %s.' % (items.domain) logging.statusWriter(self.logFile, message, 1) path = '/home/' + self.mainDomain + '/public_html/' + items.domain ## Find PHP Version if items.addon == 1: DomainMeta = '%s/userdata/%s.%s' % ( CompletPathToExtractedArchive, items.domain, self.mainDomain) else: DomainMeta = '%s/userdata/%s' % ( CompletPathToExtractedArchive, items.domain) data = open(DomainMeta, 'r').readlines() phpChecker = 1 for it in data: if it.find('phpversion') > -1: self.PHPVersion = it.split(' ')[-1].replace( '\n', '') self.PHPDecider() phpChecker = 0 break if phpChecker: self.PHPDecider() message = 'Calling core to create %s.' % (items.domain) logging.statusWriter(self.logFile, message, 1) result = virtualHostUtilities.createDomain( self.mainDomain, items.domain, self.PHPVersion, path, 0, 0, 0, 'admin', 0) if result[0] == 1: message = 'Child domain %s created from archive file: %s' % ( items.domain, self.backupFile) logging.statusWriter(self.logFile, message, 1) else: message = 'Failed to create Child domain %s from archive file: %s' % ( items.domain, self.backupFile) logging.statusWriter(self.logFile, message, 1) ## Setup SSL message = 'Detecting SSL for %s.' % (items.domain) logging.statusWriter(self.logFile, message, 1) SSLPath = '%s/apache_tls/%s' % ( CompletPathToExtractedArchive, items.domain) if os.path.exists(SSLPath): message = 'SSL found for %s, setting up.' % ( items.domain) logging.statusWriter(self.logFile, message, 1) self.SetupSSL(SSLPath, items.domain) message = 'SSL set up OK for %s.' % (items.domain) logging.statusWriter(self.logFile, message, 1) else: SSLPath = '%s/apache_tls/%s.%s' % ( CompletPathToExtractedArchive, items.domain, self.mainDomain) if os.path.exists(SSLPath): message = 'SSL found for %s, setting up.' % ( items.domain) logging.statusWriter(self.logFile, message, 1) self.SetupSSL(SSLPath, items.domain) message = 'SSL set up OK for %s.' % (items.domain) logging.statusWriter(self.logFile, message, 1) else: message = 'SSL not detected for %s, you can later issue SSL from Manage SSL in CyberPanel.' % ( items.domain) logging.statusWriter(self.logFile, message, 1) ## Creating Document root for childs message = 'Restoring document root files for %s.' % ( items.domain) logging.statusWriter(self.logFile, message, 1) externalApp = "".join( re.findall("[a-zA-Z]+", self.mainDomain))[:7] data = open(DomainMeta, 'r').readlines() for items in data: if items.find('documentroot') > -1: ChildDocRoot = items.split(' ')[-1].replace( '\n', '') break if os.path.exists(path): shutil.rmtree(path) movePath = '%s/homedir/public_html/%s' % ( CompletPathToExtractedArchive, ChildDocRoot.replace(self.documentRoot, '', 1).replace( '/', '')) if os.path.exists(movePath): shutil.move(movePath, path) else: movePath = '%s/homedir/%s' % ( CompletPathToExtractedArchive, ChildDocRoot.split('/')[-1].replace( self.documentRoot, '', 1).replace('/', '')) if os.path.exists(movePath): shutil.move(movePath, path) else: movePath = '%s/homedir/%s' % ( CompletPathToExtractedArchive, items.domain) shutil.move(movePath, path) command = 'chown -R %s:%s %s' % (externalApp, externalApp, path) ProcessUtilities.normalExecutioner(command) message = 'Successfully created child domain.' logging.statusWriter(self.logFile, message, 1) except BaseException, msg: message = 'Failed to create child domain from backup file %s, error message: %s. Moving on..' % ( self.backupFile, str(msg)) return 1
def startRestore(metaPath, statusPath): try: ## extracting master domain for later use backupMetaData = ElementTree.parse(metaPath) masterDomain = backupMetaData.find('masterDomain').text ########### Creating child/sub/addon/parked domains logging.statusWriter(statusPath, "Creating Child Domains!", 1) ### Restoring Child Domains if any. childDomains = backupMetaData.findall('ChildDomains/domain') try: for childDomain in childDomains: domain = childDomain.find('domain').text phpSelection = childDomain.find('phpSelection').text path = childDomain.find('path').text virtualHostUtilities.createDomain(masterDomain, domain, phpSelection, path, 0, 0, 0, 'admin', 0) except BaseException, msg: logging.writeToFile(str(msg) + " [startRestore]") return 0 ## Restore Aliases logging.statusWriter(statusPath, "Restoring Domain Aliases!", 1) aliases = backupMetaData.findall('Aliases/alias') for items in aliases: virtualHostUtilities.createAlias(masterDomain, items.text, 0, "", "", "admin") ## Restoring email accounts logging.statusWriter(statusPath, "Restoring email accounts!", 1) emailAccounts = backupMetaData.findall('emails/emailAccount') try: for emailAccount in emailAccounts: email = emailAccount.find('email').text username = email.split("@")[0] password = emailAccount.find('password').text result = mailUtilities.createEmailAccount( masterDomain, username, password) if result[0] == 0: logging.statusWriter( statusPath, 'Email existed, updating password according to last snapshot. %s' % (email)) if mailUtilities.changeEmailPassword( email, password, 1)[0] == 0: logging.statusWriter( statusPath, 'Failed changing password for: %s' % (email)) else: logging.statusWriter( statusPath, 'Password changed for: %s' % (email)) else: logging.statusWriter(statusPath, 'Email created: %s' % (email)) except BaseException, msg: logging.writeToFile(str(msg) + " [startRestore]") return 0