Skip to content

Commit

Permalink
cPanel Importer: bug fix with emails import
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Aug 21, 2019
1 parent 471acf1 commit 3c455ff
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 38 deletions.
3 changes: 3 additions & 0 deletions baseTemplate/templates/baseTemplate/index.html
Expand Up @@ -486,6 +486,9 @@
<li class="createNameServer"><a href="{% url 'createNameserver' %}"
title="{% trans 'Create Nameserver' %}"><span>{% trans "Create Nameserver" %}</span></a>
</li>
<!--<li class="createNameServer"><a href="{% url 'configureDefaultNameServers' %}"
title="{% trans 'Configure Default Nameservers' %}"><span>{% trans "CConfigure Default Nameservers" %}</span></a>-->
</li>
<li class="createDNSZone"><a href="{% url 'createDNSZone' %}"
title="{% trans 'Create DNS Zone' %}"><span>{% trans "Create DNS Zone" %}</span></a>
</li>
Expand Down
20 changes: 19 additions & 1 deletion dns/dnsManager.py
Expand Up @@ -488,4 +488,22 @@ def submitZoneDeletion(self, userID = None, data = None):
except BaseException, msg:
final_dic = {'delete_status': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
return HttpResponse(final_json)

def configureDefaultNameServers(self, request=None, userID=None):

try:
currentACL = ACLManager.loadedACL(userID)

if ACLManager.currentContextPermission(currentACL, 'deleteZone') == 0:
return ACLManager.loadError()

if not os.path.exists('/home/cyberpanel/powerdns'):
return render(request, 'dns/addDeleteDNSRecords.html', {"status": 0})

domainsList = ACLManager.findAllDomains(currentACL, userID)

return render(request, 'dns/configureDefaultNameServers.html', {"domainsList": domainsList, "status": 1})

except BaseException, msg:
return HttpResponse(str(msg))
130 changes: 130 additions & 0 deletions dns/templates/dns/configureDefaultNameServers.html
@@ -0,0 +1,130 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Create Nameserver - CyberPanel" %}{% endblock %}
{% block content %}

{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->

<div class="container">
<div id="page-title">
<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>
<p>{% trans "You can use this page to setup nameservers using which people on the internet can resolve websites hosted on this server." %}</p>
</div>
<div ng-controller="createNameserver" class="panel">
<div class="panel-body">
<h3 class="content-box-header">
{% trans "Details" %} <img ng-hide="createNameserverLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">

{% if not status %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h3>{% trans "PowerDNS is disabled." %}
<a href="{% url 'managePowerDNS' %}"><button class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Enable Now" %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button></a></h3>
</div>

{% else %}

<form action="/" class="form-horizontal bordered-row panel-body">

<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Domain Name" %}</label>
<div class="col-sm-6">
<input name="dom" type="text" class="form-control" ng-model="domainForNS" required>
</div>

<div class="current-pack">example.com</div>

</div>

<div class="form-group">
<label class="col-sm-3 control-label">{% trans "First Nameserver" %}</label>
<div class="col-sm-6">
<input name="firstNS" type="text" class="form-control" ng-model="firstNS" required>
</div>

<div class="current-pack">ns1.example.com</div>
</div>

<div class="form-group">
<label class="col-sm-3 control-label">{% trans "IP Address" %}</label>
<div class="col-sm-6">
<input value="IP Address for first nameserver." name="firstNSIP" type="text" class="form-control" ng-model="firstNSIP" required>
</div>
</div>

<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Second Nameserver (Back up)" %} </label>
<div class="col-sm-6">
<input name="secondNS" type="text" class="form-control" ng-model="secondNS" required>
</div>
<div class="current-pack">ns2.example.com</div>

</div>

<div class="form-group">
<label class="col-sm-3 control-label">{% trans "IP Address" %}</label>
<div class="col-sm-6">
<input name="secondNSIP" type="text" class="form-control" ng-model="secondNSIP" required>
</div>
</div>

<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="createNameserverFunc()" class="btn btn-primary btn-lg">{% trans "Create Nameserver" %}</button>

</div>
</div>

<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<div ng-hide="nameserverCreationFailed" class="alert alert-danger">
<p>{% trans "Nameserver cannot be created. Error message:" %} {$ errorMessage $}</p>
</div>

<div ng-hide="nameserverCreated" class="alert alert-success">
<p>{% trans "The following nameservers were successfully created:" %} <br>

<strong>{$ nameServerOne $}</strong> <br>
<strong>{$ nameServerTwo $}</strong> <br>

</p>
</div>

<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
</div>


</div>



</div>


</form>


{% endif %}




</div>
</div>
</div>



</div>


{% endblock %}
1 change: 1 addition & 0 deletions dns/urls.py
Expand Up @@ -4,6 +4,7 @@
urlpatterns = [
url(r'^$', views.loadDNSHome, name='dnsHome'),
url(r'^createNameserver', views.createNameserver, name='createNameserver'),
url(r'^configureDefaultNameServers$', views.configureDefaultNameServers, name='configureDefaultNameServers'),
url(r'^createDNSZone', views.createDNSZone, name='createDNSZone'),
url(r'^addDeleteDNSRecords', views.addDeleteDNSRecords, name='addDeleteDNSRecords'),

Expand Down
8 changes: 8 additions & 0 deletions dns/views.py
Expand Up @@ -152,6 +152,14 @@ def submitZoneDeletion(request):
return redirect(loadLoginPage)


def configureDefaultNameServers(request):
try:
userID = request.session['userID']
dm = DNSManager()
return dm.configureDefaultNameServers(request, userID)
except KeyError:
return redirect(loadLoginPage)




Expand Down
14 changes: 10 additions & 4 deletions mailServer/mailserverManager.py
Expand Up @@ -449,10 +449,16 @@ def submitPasswordChange(self):
emailDB = EUsers.objects.get(email=email)

admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(emailDB.emailOwner.domainOwner.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()
try:
if ACLManager.checkOwnership(emailDB.emailOwner.domainOwner.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()
except:
if ACLManager.checkOwnership(emailDB.emailOwner.childOwner.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()

CentOSPath = '/etc/redhat-release'
if os.path.exists(CentOSPath):
Expand Down
86 changes: 54 additions & 32 deletions plogical/cPanelImporter.py
Expand Up @@ -21,7 +21,7 @@
import shlex
import subprocess
from databases.models import Databases
from websiteFunctions.models import Websites
from websiteFunctions.models import Websites, ChildDomains as CDomains
from plogical.vhost import vhost
from plogical.virtualHostUtilities import virtualHostUtilities
from plogical.mailUtilities import mailUtilities
Expand Down Expand Up @@ -459,6 +459,11 @@ def CreateChildDomains(self):
logging.statusWriter(self.logFile, message, 1)
return 0

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 CreateDNSRecords(self):
try:

Expand Down Expand Up @@ -717,6 +722,15 @@ def MainController(self):
def DeleteSite(self):
vhost.deleteVirtualHostConfigurations(self.mainDomain)

def checkIfExists(self, virtualHostName):
if Websites.objects.filter(domain=virtualHostName).count() > 0:
return 1

if CDomains.objects.filter(domain=virtualHostName).count() > 0:
return 1

return 0

def RestoreEmails(self):
try:

Expand Down Expand Up @@ -757,51 +771,59 @@ def RestoreEmails(self):
continue
if items.find('.') > -1:
for it in os.listdir(FinalMailDomainPath):
mailUtilities.createEmailAccount(items, it, 'cyberpanel')
finalEmailUsername = it + "@" + items
message = 'Starting restore for %s.' % (finalEmailUsername)
logging.statusWriter(self.logFile, message, 1)
eUser = EUsers.objects.get(email=finalEmailUsername)
try:
if self.checkIfExists(items) == 0:
self.createDummyChild(items)

mailUtilities.createEmailAccount(items, it, 'cyberpanel')
finalEmailUsername = it + "@" + items
message = 'Starting restore for %s.' % (finalEmailUsername)
logging.statusWriter(self.logFile, message, 1)
eUser = EUsers.objects.get(email=finalEmailUsername)

if self.mailFormat == cPanelImporter.MailDir:
eUser.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (items, it)
MailPath = '/home/vmail/%s/%s/Maildir/' % (items, it)

command = 'mkdir -p %s' % (MailPath)
ProcessUtilities.normalExecutioner(command)
if self.mailFormat == cPanelImporter.MailDir:
eUser.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (items, it)
MailPath = '/home/vmail/%s/%s/Maildir/' % (items, it)

MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it)
command = 'mkdir -p %s' % (MailPath)
ProcessUtilities.normalExecutioner(command)

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

else:
eUser.mail = 'mdbox:/home/vmail/%s/%s/Mdbox' % (items, it)
MailPath = '/home/vmail/%s/%s/Mdbox/' % (items, it)
command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath)
subprocess.call(command, shell=True)

command = 'mkdir -p %s' % (MailPath)
ProcessUtilities.normalExecutioner(command)
else:
eUser.mail = 'mdbox:/home/vmail/%s/%s/Mdbox' % (items, it)
MailPath = '/home/vmail/%s/%s/Mdbox/' % (items, it)

MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it)
command = 'mkdir -p %s' % (MailPath)
ProcessUtilities.normalExecutioner(command)

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

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

PasswordPath = '%s/homedir/etc/%s/shadow' % (CompletPathToExtractedArchive, items)
PasswordData = open(PasswordPath, 'r').readlines()
## Also update password

for i in PasswordData:
if i.find(it) > -1:
finalPassword = '%s%s' % ('{CRYPT}', i.split(':')[1])
eUser.password = finalPassword
PasswordPath = '%s/homedir/etc/%s/shadow' % (CompletPathToExtractedArchive, items)
PasswordData = open(PasswordPath, 'r').readlines()

eUser.save()
for i in PasswordData:
if i.find(it) > -1:
finalPassword = '%s%s' % ('{CRYPT}', i.split(':')[1])
eUser.password = finalPassword

message = 'Restore completed for %s.' % (finalEmailUsername)
logging.statusWriter(self.logFile, message, 1)
eUser.save()

message = 'Restore completed for %s.' % (finalEmailUsername)
logging.statusWriter(self.logFile, message, 1)
except BaseException, msg:
message = 'Failed to restore emails from archive file %s, For domain: %s. error message: %s. [ExtractBackup]' % (
self.backupFile, items, str(msg))
logging.statusWriter(self.logFile, message, 1)

command = 'chown -R vmail:vmail /home/vmail'
ProcessUtilities.normalExecutioner(command)
Expand Down
2 changes: 1 addition & 1 deletion plogical/mailUtilities.py
Expand Up @@ -110,7 +110,7 @@ def createEmailAccount(domain, userName, password):

## After effects

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

Expand Down

0 comments on commit 3c455ff

Please sign in to comment.