|
21 | 21 | import shlex |
22 | 22 | import subprocess |
23 | 23 | from databases.models import Databases |
24 | | -from websiteFunctions.models import Websites |
| 24 | +from websiteFunctions.models import Websites, ChildDomains as CDomains |
25 | 25 | from plogical.vhost import vhost |
26 | 26 | from plogical.virtualHostUtilities import virtualHostUtilities |
27 | 27 | from plogical.mailUtilities import mailUtilities |
@@ -459,6 +459,11 @@ def CreateChildDomains(self): |
459 | 459 | logging.statusWriter(self.logFile, message, 1) |
460 | 460 | return 0 |
461 | 461 |
|
| 462 | + def createDummyChild(self, childDomain): |
| 463 | + path = '/home/%s/public_html/%s' % (self.mainDomain, childDomain) |
| 464 | + virtualHostUtilities.createDomain(self.mainDomain, childDomain, self.PHPVersion, path, 0, 0, |
| 465 | + 0, 'admin', 0) |
| 466 | + |
462 | 467 | def CreateDNSRecords(self): |
463 | 468 | try: |
464 | 469 |
|
@@ -717,6 +722,15 @@ def MainController(self): |
717 | 722 | def DeleteSite(self): |
718 | 723 | vhost.deleteVirtualHostConfigurations(self.mainDomain) |
719 | 724 |
|
| 725 | + def checkIfExists(self, virtualHostName): |
| 726 | + if Websites.objects.filter(domain=virtualHostName).count() > 0: |
| 727 | + return 1 |
| 728 | + |
| 729 | + if CDomains.objects.filter(domain=virtualHostName).count() > 0: |
| 730 | + return 1 |
| 731 | + |
| 732 | + return 0 |
| 733 | + |
720 | 734 | def RestoreEmails(self): |
721 | 735 | try: |
722 | 736 |
|
@@ -757,51 +771,59 @@ def RestoreEmails(self): |
757 | 771 | continue |
758 | 772 | if items.find('.') > -1: |
759 | 773 | for it in os.listdir(FinalMailDomainPath): |
760 | | - mailUtilities.createEmailAccount(items, it, 'cyberpanel') |
761 | | - finalEmailUsername = it + "@" + items |
762 | | - message = 'Starting restore for %s.' % (finalEmailUsername) |
763 | | - logging.statusWriter(self.logFile, message, 1) |
764 | | - eUser = EUsers.objects.get(email=finalEmailUsername) |
| 774 | + try: |
| 775 | + if self.checkIfExists(items) == 0: |
| 776 | + self.createDummyChild(items) |
765 | 777 |
|
| 778 | + mailUtilities.createEmailAccount(items, it, 'cyberpanel') |
| 779 | + finalEmailUsername = it + "@" + items |
| 780 | + message = 'Starting restore for %s.' % (finalEmailUsername) |
| 781 | + logging.statusWriter(self.logFile, message, 1) |
| 782 | + eUser = EUsers.objects.get(email=finalEmailUsername) |
766 | 783 |
|
767 | | - if self.mailFormat == cPanelImporter.MailDir: |
768 | | - eUser.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (items, it) |
769 | | - MailPath = '/home/vmail/%s/%s/Maildir/' % (items, it) |
770 | 784 |
|
771 | | - command = 'mkdir -p %s' % (MailPath) |
772 | | - ProcessUtilities.normalExecutioner(command) |
| 785 | + if self.mailFormat == cPanelImporter.MailDir: |
| 786 | + eUser.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (items, it) |
| 787 | + MailPath = '/home/vmail/%s/%s/Maildir/' % (items, it) |
773 | 788 |
|
774 | | - MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it) |
| 789 | + command = 'mkdir -p %s' % (MailPath) |
| 790 | + ProcessUtilities.normalExecutioner(command) |
775 | 791 |
|
776 | | - command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath) |
777 | | - subprocess.call(command, shell=True) |
| 792 | + MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it) |
778 | 793 |
|
779 | | - else: |
780 | | - eUser.mail = 'mdbox:/home/vmail/%s/%s/Mdbox' % (items, it) |
781 | | - MailPath = '/home/vmail/%s/%s/Mdbox/' % (items, it) |
| 794 | + command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath) |
| 795 | + subprocess.call(command, shell=True) |
782 | 796 |
|
783 | | - command = 'mkdir -p %s' % (MailPath) |
784 | | - ProcessUtilities.normalExecutioner(command) |
| 797 | + else: |
| 798 | + eUser.mail = 'mdbox:/home/vmail/%s/%s/Mdbox' % (items, it) |
| 799 | + MailPath = '/home/vmail/%s/%s/Mdbox/' % (items, it) |
785 | 800 |
|
786 | | - MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it) |
| 801 | + command = 'mkdir -p %s' % (MailPath) |
| 802 | + ProcessUtilities.normalExecutioner(command) |
787 | 803 |
|
788 | | - command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath) |
789 | | - subprocess.call(command, shell=True) |
| 804 | + MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it) |
790 | 805 |
|
791 | | - ## Also update password |
| 806 | + command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath) |
| 807 | + subprocess.call(command, shell=True) |
792 | 808 |
|
793 | | - PasswordPath = '%s/homedir/etc/%s/shadow' % (CompletPathToExtractedArchive, items) |
794 | | - PasswordData = open(PasswordPath, 'r').readlines() |
| 809 | + ## Also update password |
795 | 810 |
|
796 | | - for i in PasswordData: |
797 | | - if i.find(it) > -1: |
798 | | - finalPassword = '%s%s' % ('{CRYPT}', i.split(':')[1]) |
799 | | - eUser.password = finalPassword |
| 811 | + PasswordPath = '%s/homedir/etc/%s/shadow' % (CompletPathToExtractedArchive, items) |
| 812 | + PasswordData = open(PasswordPath, 'r').readlines() |
800 | 813 |
|
801 | | - eUser.save() |
| 814 | + for i in PasswordData: |
| 815 | + if i.find(it) > -1: |
| 816 | + finalPassword = '%s%s' % ('{CRYPT}', i.split(':')[1]) |
| 817 | + eUser.password = finalPassword |
802 | 818 |
|
803 | | - message = 'Restore completed for %s.' % (finalEmailUsername) |
804 | | - logging.statusWriter(self.logFile, message, 1) |
| 819 | + eUser.save() |
| 820 | + |
| 821 | + message = 'Restore completed for %s.' % (finalEmailUsername) |
| 822 | + logging.statusWriter(self.logFile, message, 1) |
| 823 | + except BaseException, msg: |
| 824 | + message = 'Failed to restore emails from archive file %s, For domain: %s. error message: %s. [ExtractBackup]' % ( |
| 825 | + self.backupFile, items, str(msg)) |
| 826 | + logging.statusWriter(self.logFile, message, 1) |
805 | 827 |
|
806 | 828 | command = 'chown -R vmail:vmail /home/vmail' |
807 | 829 | ProcessUtilities.normalExecutioner(command) |
|
0 commit comments