cPanel Importer: bug fix with emails import

This commit is contained in:
Usman Nasir
2019-08-21 12:32:16 +05:00
parent 471acf17ea
commit 3c455ffec1
8 changed files with 226 additions and 38 deletions

View File

@@ -486,6 +486,9 @@
<li class="createNameServer"><a href="{% url 'createNameserver' %}" <li class="createNameServer"><a href="{% url 'createNameserver' %}"
title="{% trans 'Create Nameserver' %}"><span>{% trans "Create Nameserver" %}</span></a> title="{% trans 'Create Nameserver' %}"><span>{% trans "Create Nameserver" %}</span></a>
</li> </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' %}" <li class="createDNSZone"><a href="{% url 'createDNSZone' %}"
title="{% trans 'Create DNS Zone' %}"><span>{% trans "Create DNS Zone" %}</span></a> title="{% trans 'Create DNS Zone' %}"><span>{% trans "Create DNS Zone" %}</span></a>
</li> </li>

View File

@@ -489,3 +489,21 @@ class DNSManager:
final_dic = {'delete_status': 0, 'error_message': str(msg)} final_dic = {'delete_status': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic) 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))

View File

@@ -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 %}

View File

@@ -4,6 +4,7 @@ import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.loadDNSHome, name='dnsHome'), url(r'^$', views.loadDNSHome, name='dnsHome'),
url(r'^createNameserver', views.createNameserver, name='createNameserver'), url(r'^createNameserver', views.createNameserver, name='createNameserver'),
url(r'^configureDefaultNameServers$', views.configureDefaultNameServers, name='configureDefaultNameServers'),
url(r'^createDNSZone', views.createDNSZone, name='createDNSZone'), url(r'^createDNSZone', views.createDNSZone, name='createDNSZone'),
url(r'^addDeleteDNSRecords', views.addDeleteDNSRecords, name='addDeleteDNSRecords'), url(r'^addDeleteDNSRecords', views.addDeleteDNSRecords, name='addDeleteDNSRecords'),

View File

@@ -152,6 +152,14 @@ def submitZoneDeletion(request):
return redirect(loadLoginPage) return redirect(loadLoginPage)
def configureDefaultNameServers(request):
try:
userID = request.session['userID']
dm = DNSManager()
return dm.configureDefaultNameServers(request, userID)
except KeyError:
return redirect(loadLoginPage)

View File

@@ -449,10 +449,16 @@ class MailServerManager:
emailDB = EUsers.objects.get(email=email) emailDB = EUsers.objects.get(email=email)
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(emailDB.emailOwner.domainOwner.domain, admin, currentACL) == 1: try:
pass if ACLManager.checkOwnership(emailDB.emailOwner.domainOwner.domain, admin, currentACL) == 1:
else: pass
return ACLManager.loadErrorJson() else:
return ACLManager.loadErrorJson()
except:
if ACLManager.checkOwnership(emailDB.emailOwner.childOwner.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson()
CentOSPath = '/etc/redhat-release' CentOSPath = '/etc/redhat-release'
if os.path.exists(CentOSPath): if os.path.exists(CentOSPath):

View File

@@ -21,7 +21,7 @@ import MySQLdb.cursors as cursors
import shlex import shlex
import subprocess import subprocess
from databases.models import Databases 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.vhost import vhost
from plogical.virtualHostUtilities import virtualHostUtilities from plogical.virtualHostUtilities import virtualHostUtilities
from plogical.mailUtilities import mailUtilities from plogical.mailUtilities import mailUtilities
@@ -459,6 +459,11 @@ class cPanelImporter:
logging.statusWriter(self.logFile, message, 1) logging.statusWriter(self.logFile, message, 1)
return 0 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): def CreateDNSRecords(self):
try: try:
@@ -717,6 +722,15 @@ class cPanelImporter:
def DeleteSite(self): def DeleteSite(self):
vhost.deleteVirtualHostConfigurations(self.mainDomain) 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): def RestoreEmails(self):
try: try:
@@ -757,51 +771,59 @@ class cPanelImporter:
continue continue
if items.find('.') > -1: if items.find('.') > -1:
for it in os.listdir(FinalMailDomainPath): for it in os.listdir(FinalMailDomainPath):
mailUtilities.createEmailAccount(items, it, 'cyberpanel') try:
finalEmailUsername = it + "@" + items if self.checkIfExists(items) == 0:
message = 'Starting restore for %s.' % (finalEmailUsername) self.createDummyChild(items)
logging.statusWriter(self.logFile, message, 1)
eUser = EUsers.objects.get(email=finalEmailUsername) 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: if self.mailFormat == cPanelImporter.MailDir:
eUser.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (items, it) eUser.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (items, it)
MailPath = '/home/vmail/%s/%s/Maildir/' % (items, it) MailPath = '/home/vmail/%s/%s/Maildir/' % (items, it)
command = 'mkdir -p %s' % (MailPath) command = 'mkdir -p %s' % (MailPath)
ProcessUtilities.normalExecutioner(command) ProcessUtilities.normalExecutioner(command)
MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it) MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it)
command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath) command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath)
subprocess.call(command, shell=True) subprocess.call(command, shell=True)
else: else:
eUser.mail = 'mdbox:/home/vmail/%s/%s/Mdbox' % (items, it) eUser.mail = 'mdbox:/home/vmail/%s/%s/Mdbox' % (items, it)
MailPath = '/home/vmail/%s/%s/Mdbox/' % (items, it) MailPath = '/home/vmail/%s/%s/Mdbox/' % (items, it)
command = 'mkdir -p %s' % (MailPath) command = 'mkdir -p %s' % (MailPath)
ProcessUtilities.normalExecutioner(command) ProcessUtilities.normalExecutioner(command)
MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it) MailPathInBackup = '%s/%s' % (FinalMailDomainPath, it)
command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath) command = 'cp -R %s/* %s' % (MailPathInBackup, MailPath)
subprocess.call(command, shell=True) subprocess.call(command, shell=True)
## Also update password ## Also update password
PasswordPath = '%s/homedir/etc/%s/shadow' % (CompletPathToExtractedArchive, items) PasswordPath = '%s/homedir/etc/%s/shadow' % (CompletPathToExtractedArchive, items)
PasswordData = open(PasswordPath, 'r').readlines() PasswordData = open(PasswordPath, 'r').readlines()
for i in PasswordData: for i in PasswordData:
if i.find(it) > -1: if i.find(it) > -1:
finalPassword = '%s%s' % ('{CRYPT}', i.split(':')[1]) finalPassword = '%s%s' % ('{CRYPT}', i.split(':')[1])
eUser.password = finalPassword eUser.password = finalPassword
eUser.save() eUser.save()
message = 'Restore completed for %s.' % (finalEmailUsername) message = 'Restore completed for %s.' % (finalEmailUsername)
logging.statusWriter(self.logFile, message, 1) 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' command = 'chown -R vmail:vmail /home/vmail'
ProcessUtilities.normalExecutioner(command) ProcessUtilities.normalExecutioner(command)

View File

@@ -110,7 +110,7 @@ class mailUtilities:
## After effects ## 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 execPath = execPath + " AfterEffects --domain " + domain
ProcessUtilities.executioner(execPath, 'lscpd') ProcessUtilities.executioner(execPath, 'lscpd')