Skip to content

Commit 3c455ff

Browse files
committed
cPanel Importer: bug fix with emails import
1 parent 471acf1 commit 3c455ff

File tree

8 files changed

+226
-38
lines changed

8 files changed

+226
-38
lines changed

baseTemplate/templates/baseTemplate/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@
486486
<li class="createNameServer"><a href="{% url 'createNameserver' %}"
487487
title="{% trans 'Create Nameserver' %}"><span>{% trans "Create Nameserver" %}</span></a>
488488
</li>
489+
<!--<li class="createNameServer"><a href="{% url 'configureDefaultNameServers' %}"
490+
title="{% trans 'Configure Default Nameservers' %}"><span>{% trans "CConfigure Default Nameservers" %}</span></a>-->
491+
</li>
489492
<li class="createDNSZone"><a href="{% url 'createDNSZone' %}"
490493
title="{% trans 'Create DNS Zone' %}"><span>{% trans "Create DNS Zone" %}</span></a>
491494
</li>

dns/dnsManager.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,4 +488,22 @@ def submitZoneDeletion(self, userID = None, data = None):
488488
except BaseException, msg:
489489
final_dic = {'delete_status': 0, 'error_message': str(msg)}
490490
final_json = json.dumps(final_dic)
491-
return HttpResponse(final_json)
491+
return HttpResponse(final_json)
492+
493+
def configureDefaultNameServers(self, request=None, userID=None):
494+
495+
try:
496+
currentACL = ACLManager.loadedACL(userID)
497+
498+
if ACLManager.currentContextPermission(currentACL, 'deleteZone') == 0:
499+
return ACLManager.loadError()
500+
501+
if not os.path.exists('/home/cyberpanel/powerdns'):
502+
return render(request, 'dns/addDeleteDNSRecords.html', {"status": 0})
503+
504+
domainsList = ACLManager.findAllDomains(currentACL, userID)
505+
506+
return render(request, 'dns/configureDefaultNameServers.html', {"domainsList": domainsList, "status": 1})
507+
508+
except BaseException, msg:
509+
return HttpResponse(str(msg))
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{% extends "baseTemplate/index.html" %}
2+
{% load i18n %}
3+
{% block title %}{% trans "Create Nameserver - CyberPanel" %}{% endblock %}
4+
{% block content %}
5+
6+
{% load static %}
7+
{% get_current_language as LANGUAGE_CODE %}
8+
<!-- Current language: {{ LANGUAGE_CODE }} -->
9+
10+
<div class="container">
11+
<div id="page-title">
12+
<h2>{% trans "Create Nameserver" %} - <a target="_blank" href="http://go.cyberpanel.net/dns-records" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "DNS Docs" %}</span></a></h2>
13+
<p>{% trans "You can use this page to setup nameservers using which people on the internet can resolve websites hosted on this server." %}</p>
14+
</div>
15+
<div ng-controller="createNameserver" class="panel">
16+
<div class="panel-body">
17+
<h3 class="content-box-header">
18+
{% trans "Details" %} <img ng-hide="createNameserverLoading" src="{% static 'images/loading.gif' %}">
19+
</h3>
20+
<div class="example-box-wrapper">
21+
22+
{% if not status %}
23+
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
24+
<h3>{% trans "PowerDNS is disabled." %}
25+
<a href="{% url 'managePowerDNS' %}"><button class="btn btn-alt btn-hover btn-blue-alt">
26+
<span>{% trans "Enable Now" %}</span>
27+
<i class="glyph-icon icon-arrow-right"></i>
28+
</button></a></h3>
29+
</div>
30+
31+
{% else %}
32+
33+
<form action="/" class="form-horizontal bordered-row panel-body">
34+
35+
<div class="form-group">
36+
<label class="col-sm-3 control-label">{% trans "Domain Name" %}</label>
37+
<div class="col-sm-6">
38+
<input name="dom" type="text" class="form-control" ng-model="domainForNS" required>
39+
</div>
40+
41+
<div class="current-pack">example.com</div>
42+
43+
</div>
44+
45+
<div class="form-group">
46+
<label class="col-sm-3 control-label">{% trans "First Nameserver" %}</label>
47+
<div class="col-sm-6">
48+
<input name="firstNS" type="text" class="form-control" ng-model="firstNS" required>
49+
</div>
50+
51+
<div class="current-pack">ns1.example.com</div>
52+
</div>
53+
54+
<div class="form-group">
55+
<label class="col-sm-3 control-label">{% trans "IP Address" %}</label>
56+
<div class="col-sm-6">
57+
<input value="IP Address for first nameserver." name="firstNSIP" type="text" class="form-control" ng-model="firstNSIP" required>
58+
</div>
59+
</div>
60+
61+
<div class="form-group">
62+
<label class="col-sm-3 control-label">{% trans "Second Nameserver (Back up)" %} </label>
63+
<div class="col-sm-6">
64+
<input name="secondNS" type="text" class="form-control" ng-model="secondNS" required>
65+
</div>
66+
<div class="current-pack">ns2.example.com</div>
67+
68+
</div>
69+
70+
<div class="form-group">
71+
<label class="col-sm-3 control-label">{% trans "IP Address" %}</label>
72+
<div class="col-sm-6">
73+
<input name="secondNSIP" type="text" class="form-control" ng-model="secondNSIP" required>
74+
</div>
75+
</div>
76+
77+
<div class="form-group">
78+
<label class="col-sm-3 control-label"></label>
79+
<div class="col-sm-4">
80+
<button type="button" ng-click="createNameserverFunc()" class="btn btn-primary btn-lg">{% trans "Create Nameserver" %}</button>
81+
82+
</div>
83+
</div>
84+
85+
<div class="form-group">
86+
<label class="col-sm-3 control-label"></label>
87+
<div class="col-sm-6">
88+
<div ng-hide="nameserverCreationFailed" class="alert alert-danger">
89+
<p>{% trans "Nameserver cannot be created. Error message:" %} {$ errorMessage $}</p>
90+
</div>
91+
92+
<div ng-hide="nameserverCreated" class="alert alert-success">
93+
<p>{% trans "The following nameservers were successfully created:" %} <br>
94+
95+
<strong>{$ nameServerOne $}</strong> <br>
96+
<strong>{$ nameServerTwo $}</strong> <br>
97+
98+
</p>
99+
</div>
100+
101+
<div ng-hide="couldNotConnect" class="alert alert-danger">
102+
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
103+
</div>
104+
105+
106+
</div>
107+
108+
109+
110+
</div>
111+
112+
113+
</form>
114+
115+
116+
{% endif %}
117+
118+
119+
120+
121+
</div>
122+
</div>
123+
</div>
124+
125+
126+
127+
</div>
128+
129+
130+
{% endblock %}

dns/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
urlpatterns = [
55
url(r'^$', views.loadDNSHome, name='dnsHome'),
66
url(r'^createNameserver', views.createNameserver, name='createNameserver'),
7+
url(r'^configureDefaultNameServers$', views.configureDefaultNameServers, name='configureDefaultNameServers'),
78
url(r'^createDNSZone', views.createDNSZone, name='createDNSZone'),
89
url(r'^addDeleteDNSRecords', views.addDeleteDNSRecords, name='addDeleteDNSRecords'),
910

dns/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ def submitZoneDeletion(request):
152152
return redirect(loadLoginPage)
153153

154154

155+
def configureDefaultNameServers(request):
156+
try:
157+
userID = request.session['userID']
158+
dm = DNSManager()
159+
return dm.configureDefaultNameServers(request, userID)
160+
except KeyError:
161+
return redirect(loadLoginPage)
162+
155163

156164

157165

mailServer/mailserverManager.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,16 @@ def submitPasswordChange(self):
449449
emailDB = EUsers.objects.get(email=email)
450450

451451
admin = Administrator.objects.get(pk=userID)
452-
if ACLManager.checkOwnership(emailDB.emailOwner.domainOwner.domain, admin, currentACL) == 1:
453-
pass
454-
else:
455-
return ACLManager.loadErrorJson()
452+
try:
453+
if ACLManager.checkOwnership(emailDB.emailOwner.domainOwner.domain, admin, currentACL) == 1:
454+
pass
455+
else:
456+
return ACLManager.loadErrorJson()
457+
except:
458+
if ACLManager.checkOwnership(emailDB.emailOwner.childOwner.domain, admin, currentACL) == 1:
459+
pass
460+
else:
461+
return ACLManager.loadErrorJson()
456462

457463
CentOSPath = '/etc/redhat-release'
458464
if os.path.exists(CentOSPath):

plogical/cPanelImporter.py

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import shlex
2222
import subprocess
2323
from databases.models import Databases
24-
from websiteFunctions.models import Websites
24+
from websiteFunctions.models import Websites, ChildDomains as CDomains
2525
from plogical.vhost import vhost
2626
from plogical.virtualHostUtilities import virtualHostUtilities
2727
from plogical.mailUtilities import mailUtilities
@@ -459,6 +459,11 @@ def CreateChildDomains(self):
459459
logging.statusWriter(self.logFile, message, 1)
460460
return 0
461461

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+
462467
def CreateDNSRecords(self):
463468
try:
464469

@@ -717,6 +722,15 @@ def MainController(self):
717722
def DeleteSite(self):
718723
vhost.deleteVirtualHostConfigurations(self.mainDomain)
719724

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+
720734
def RestoreEmails(self):
721735
try:
722736

@@ -757,51 +771,59 @@ def RestoreEmails(self):
757771
continue
758772
if items.find('.') > -1:
759773
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)
765777

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)
766783

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)
770784

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)
773788

774-
MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it)
789+
command = 'mkdir -p %s' % (MailPath)
790+
ProcessUtilities.normalExecutioner(command)
775791

776-
command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath)
777-
subprocess.call(command, shell=True)
792+
MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it)
778793

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)
782796

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)
785800

786-
MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it)
801+
command = 'mkdir -p %s' % (MailPath)
802+
ProcessUtilities.normalExecutioner(command)
787803

788-
command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath)
789-
subprocess.call(command, shell=True)
804+
MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it)
790805

791-
## Also update password
806+
command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath)
807+
subprocess.call(command, shell=True)
792808

793-
PasswordPath = '%s/homedir/etc/%s/shadow' % (CompletPathToExtractedArchive, items)
794-
PasswordData = open(PasswordPath, 'r').readlines()
809+
## Also update password
795810

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()
800813

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
802818

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)
805827

806828
command = 'chown -R vmail:vmail /home/vmail'
807829
ProcessUtilities.normalExecutioner(command)

plogical/mailUtilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def createEmailAccount(domain, userName, password):
110110

111111
## After effects
112112

113-
execPath = "sudo python /usr/local/CyberCP/plogical/mailUtilities.py"
113+
execPath = "/usr/local/CyberCP/bin/python2 /usr/local/CyberCP/plogical/mailUtilities.py"
114114
execPath = execPath + " AfterEffects --domain " + domain
115115
ProcessUtilities.executioner(execPath, 'lscpd')
116116

0 commit comments

Comments
 (0)