Skip to content
Permalink
Browse files

cPanel Importer: bug fix with emails import

  • Loading branch information...
usmannasir committed Aug 21, 2019
1 parent 471acf1 commit 3c455ffec1615617e9b977fbb781a5a1f4452f6b
@@ -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>
@@ -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))
@@ -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 %}
@@ -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'),

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




@@ -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):
@@ -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
@@ -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:

@@ -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:

@@ -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)
@@ -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')

0 comments on commit 3c455ff

Please sign in to comment.
You can’t perform that action at this time.