DKIM Manager for Domains.

This commit is contained in:
usmannasir
2018-05-03 01:22:28 +05:00
parent 69a9dcd3d2
commit f0eba42696
14 changed files with 1525 additions and 611 deletions

View File

@@ -391,6 +391,7 @@
<li id="normalUserC"><a href="{% url 'createEmailAccount' %}" title="{% trans 'Create Email Account' %}"><span>{% trans "Create Email" %}</span></a></li>
<li><a href="{% url 'deleteEmailAccount' %}" title="{% trans 'Delete Email Account' %}"><span>{% trans "Delete Email" %}</span></a></li>
<li><a href="{% url 'changeEmailAccountPassword' %}" title="{% trans 'Change Password' %}"><span>{% trans "Change Password" %}</span></a></li>
<li><a href="{% url 'dkimManager' %}" title="{% trans 'DKIM Manager' %}"><span>{% trans "DKIM Manager" %}</span></a></li>
<li><a href="/rainloop/index.php" title="{% trans 'Access Webmail' %}" target="_blank"><span>{% trans "Access Webmail" %}</span></a></li>
</ul>

View File

@@ -357,10 +357,6 @@
</form>

View File

@@ -34,6 +34,7 @@
</div>
<!------ ModeSec Install Log box ----------------->
<div ng-hide="modSecNotifyBox" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
@@ -72,7 +73,6 @@
</div>
<!----- ModeSec Install Log box ----------------->
{% else %}

View File

@@ -63,7 +63,7 @@ app.controller('createEmailAccount', function($scope,$http) {
function ListInitialDatas(response) {
if(response.data.createEmailStatus == 1){
if(response.data.createEmailStatus === 1){
$scope.emailDetails = false;
$scope.emailLoading = true;
@@ -508,3 +508,322 @@ app.controller('changeEmailPassword', function($scope,$http) {
});
/* Java script code to create account ends here */
/* Java script code for DKIM Manager */
app.controller('dkimManager', function($scope, $http, $timeout, $window) {
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
$scope.fetchKeys = function(){
$scope.manageDKIMLoading = false;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
url = "/email/fetchDKIMKeys";
var data = {
domainName: $scope.domainName
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.fetchStatus === 1){
if(response.data.keysAvailable === 1){
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = false;
$scope.couldNotConnect = true;
$scope.domainRecords = false;
$scope.noKeysAvailable = true;
$scope.privateKey = response.data.privateKey;
$scope.publicKey = response.data.publicKey;
$scope.dkimSuccessMessage = response.data.dkimSuccessMessage;
}else{
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = false;
}
}
else{
$scope.errorMessage = response.data.error_message;
$scope.manageDKIMLoading = true;
$scope.dkimError = false;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
}
}
function cantLoadInitialDatas(response) {
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = false;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
}
};
$scope.createDomainDKIMKeys = function () {
$scope.manageDKIMLoading = false;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = false;
url = "/email/generateDKIMKeys";
var data = {
domainName: $scope.domainName
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.generateStatus === 1){
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
$scope.fetchKeys();
}
else{
$scope.errorMessage = response.data.error_message;
$scope.manageDKIMLoading = true;
$scope.dkimError = false;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = false;
}
}
function cantLoadInitialDatas(response) {
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = false;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
}
};
// Installation
$scope.openDKIMNotifyBox = true;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = true;
$scope.installOpenDKIM = function(){
$scope.openDKIMNotifyBox = true;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = false;
url = "/email/installOpenDKIM";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.installOpenDKIM === 1){
$scope.openDKIMNotifyBox = true;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = false;
$scope.manageDKIMLoading = true;
getRequestStatus();
}
else{
$scope.errorMessage = response.data.error_message;
$scope.openDKIMNotifyBox = false;
$scope.openDKIMError = false;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = true;
}
}
function cantLoadInitialDatas(response) {
$scope.openDKIMNotifyBox = false;
$scope.openDKIMError = true;
$scope.couldNotConnect = false;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = false;
}
};
function getRequestStatus(){
$scope.openDKIMNotifyBox = true;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = false;
$scope.manageDKIMLoading = false;
url = "/email/installStatusOpenDKIM";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.abort === 0){
$scope.requestData = response.data.requestStatus;
$timeout(getRequestStatus,1000);
}
else{
// Notifications
$timeout.cancel();
$scope.openDKIMNotifyBox = false;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = true;
$scope.requestData = response.data.requestStatus;
if(response.data.installed === 0) {
$scope.openDKIMError = false;
$scope.errorMessage = response.data.error_message;
}else{
$scope.openDKIMSuccessfullyInstalled = false;
$timeout(function() { $window.location.reload(); }, 3000);
}
}
}
function cantLoadInitialDatas(response) {
$scope.modSecNotifyBox = false;
$scope.modeSecInstallBox = false;
$scope.modsecLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = false;
$scope.modSecSuccessfullyInstalled = true;
$scope.installationFailed = true;
}
}
});

View File

@@ -0,0 +1,176 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "DKIM Manager - 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 "DKIM Manager" %}</h2>
<p>{% trans "This page can be used to generate and view DKIM keys for Domains" %}</p>
</div>
<div ng-controller="dkimManager" class="panel">
{% if openDKIMInstalled == 0 %}
<div class="panel-body">
<h3 class="title-hero">
{% trans "DKIM Manager" %} <img ng-hide="manageDKIMLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<form action="/" class="form-horizontal bordered-row">
<div class="form-group text-center">
<h3>{% trans "OpenDKIM is not installed. " %}
<a href="" ng-click="installOpenDKIM()"><strong>{% trans "Install Now" %}</strong></a>
</h3>
</div>
<!------ ModeSec Install Log box ----------------->
<div ng-hide="openDKIMNotifyBox" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-6">
<div ng-hide="openDKIMError" class="alert alert-danger">
<p>{% trans "Error message: " %} {$ errorMessage $}</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect. Please refresh this page." %} </p>
</div>
<div ng-hide="openDKIMSuccessfullyInstalled" class="alert alert-success">
<p>{% trans "OpenDKIM successfully installed, refreshing page in 3 seconds.." %}</p>
</div>
</div>
</div>
<div ng-hide="openDKIMInstallBox" class="col-md-12">
<form action="/" id="" class="form-horizontal bordered-row">
<div class="form-group">
<div style="margin-top: 2%;" class="col-sm-12">
<textarea ng-model="requestData" rows="15" class="form-control">{{ requestData }}</textarea>
</div>
</div>
</form>
</div>
<!----- ModeSec Install Log box ----------------->
</form>
</div>
</div>
{% else %}
<div class="panel-body">
<h3 class="title-hero">
{% trans "DKIM Manager" %} <img ng-hide="manageDKIMLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<form action="/" class="form-horizontal bordered-row">
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Select Website" %} </label>
<div class="col-sm-6">
<select ng-change="fetchKeys()" ng-model="domainName" class="form-control">
{% for items in websiteList %}
<option>{{ items }}</option>
{% endfor %}
</select>
</div>
</div>
<!------ List Domain Keys --------------->
<div ng-hide="noKeysAvailable" class="form-group text-center">
<h3>{% trans "Keys not available for this domain." %}
<a href="" ng-click="createDomainDKIMKeys()"><strong>{% trans "Generate Now" %}</strong></a>
</h3>
</div>
<div ng-hide="domainRecords" class="form-group">
<div class="col-sm-12">
<table class="table">
<thead>
<tr>
<th>{% trans "Domain" %}</th>
<th>{% trans "Private Key" %}</th>
<th>{% trans "Public Key" %}</th>
</tr>
</thead>
<tbody>
<tr >
<td ng-bind="domainName"></td>
<td>
<div class="form-group">
<div class="col-sm-12">
<textarea ng-bind="privateKey" rows="10" class="form-control"></textarea>
</div>
</div>
</td>
<td >
<div class="form-group">
<div class="col-sm-12">
<textarea ng-bind="publicKey" rows="5" class="form-control"></textarea>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!------ List of records --------------->
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<div ng-hide="dkimSuccess" class="alert alert-success">
<p>{$ dkimSuccessMessage $}</p>
</div>
<div ng-hide="dkimError" class="alert alert-danger">
<p>{$ errorMessage $}</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>
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -9,7 +9,7 @@ urlpatterns = [
## Delete email
url(r'^deleteEmailAccount', views.deleteEmailAccount, name='deleteEmailAccount'),
url(r'^getEmailsForDomain', views.getEmailsForDomain, name='getEmailsForDomain'),
url(r'^getEmailsForDomain$', views.getEmailsForDomain, name='getEmailsForDomain'),
url(r'^submitEmailDeletion', views.submitEmailDeletion, name='submitEmailDeletion'),
@@ -17,4 +17,13 @@ urlpatterns = [
url(r'^changeEmailAccountPassword', views.changeEmailAccountPassword, name='changeEmailAccountPassword'),
url(r'^submitPasswordChange', views.submitPasswordChange, name='submitPasswordChange'),
## DKIM Manager
url(r'^dkimManager', views.dkimManager, name='dkimManager'),
url(r'^fetchDKIMKeys', views.fetchDKIMKeys, name='fetchDKIMKeys'),
url(r'^generateDKIMKeys$', views.generateDKIMKeys, name='generateDKIMKeys'),
url(r'^installOpenDKIM', views.installOpenDKIM, name='installOpenDKIM'),
url(r'^installStatusOpenDKIM', views.installStatusOpenDKIM, name='installStatusOpenDKIM'),
]

View File

@@ -10,11 +10,14 @@ from websiteFunctions.models import Websites
from loginSystem.views import loadLoginPage
import plogical.CyberCPLogFileWriter as logging
import json
import os
import shutil
import shlex
import subprocess
from plogical.virtualHostUtilities import virtualHostUtilities
from plogical.mailUtilities import mailUtilities
import thread
from dns.models import Domains as dnsDomains
from dns.models import Records as dnsRecords
import os
def loadEmailHome(request):
try:
@@ -54,13 +57,13 @@ def submitEmailCreation(request):
if request.method == 'POST':
data = json.loads(request.body)
domain = data['domain']
domainName = data['domain']
userName = data['username']
password = data['password']
## Check if already exists
finalEmailUsername = userName + "@" + domain
finalEmailUsername = userName + "@" + domainName
if EUsers.objects.filter(email=finalEmailUsername).exists():
data_ret = {'createEmailStatus': 0, 'error_message': "This account already exists!"}
@@ -69,11 +72,11 @@ def submitEmailCreation(request):
## Check for email limits.
website = Websites.objects.get(domain=domain)
website = Websites.objects.get(domain=domainName)
try:
newEmailDomain = Domains(domainOwner=website, domain=domain)
newEmailDomain = Domains(domainOwner=website, domain=domainName)
newEmailDomain.save()
if website.package.emailAccounts == 0 or (
@@ -87,7 +90,7 @@ def submitEmailCreation(request):
except:
emailDomain = Domains.objects.get(domain=domain)
emailDomain = Domains.objects.get(domain=domainName)
if website.package.emailAccounts == 0 or (
emailDomain.eusers_set.all().count() < website.package.emailAccounts):
@@ -103,13 +106,13 @@ def submitEmailCreation(request):
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
execPath = execPath + " createEmailAccount --domain " + domain
execPath = execPath + " createEmailAccount --domain " + domainName
output = subprocess.check_output(shlex.split(execPath))
if output.find("1,None") > -1:
emailDomain = Domains.objects.get(domain=domain)
emailDomain = Domains.objects.get(domain=domainName)
emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password)
emailAcct.save()
@@ -302,3 +305,227 @@ def submitPasswordChange(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def dkimManager(request):
try:
val = request.session['userID']
openDKIMInstalled = 0
if mailUtilities.checkIfDKIMInstalled() == 1:
openDKIMInstalled = 1
admin = Administrator.objects.get(pk=val)
if admin.type == 1:
websites = Websites.objects.all()
websitesName = []
for items in websites:
websitesName.append(items.domain)
else:
if admin.type == 2:
websites = admin.websites_set.all()
admins = Administrator.objects.filter(owner=admin.pk)
websitesName = []
for items in websites:
websitesName.append(items.domain)
for items in admins:
webs = items.websites_set.all()
for web in webs:
websitesName.append(web.domain)
else:
websitesName = []
websites = Websites.objects.filter(admin=admin)
for items in websites:
websitesName.append(items.domain)
return render(request, 'mailServer/dkimManager.html',
{'websiteList': websitesName, 'openDKIMInstalled': openDKIMInstalled})
return render(request, 'mailServer/dkimManager.html',
{'openDKIMInstalled': openDKIMInstalled})
except KeyError:
return redirect(loadLoginPage)
def fetchDKIMKeys(request):
try:
val = request.session['userID']
try:
if request.method == 'POST':
data = json.loads(request.body)
domainName = data['domainName']
try:
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
command = "sudo cat " + path
output = subprocess.check_output(shlex.split(command))
path = "/etc/opendkim/keys/" + domainName + "/default.private"
command = "sudo cat " + path
privateKey = subprocess.check_output(shlex.split(command))
data_ret = {'fetchStatus': 1, 'keysAvailable': 1, 'publicKey': output[53:269],
'privateKey': privateKey, 'dkimSuccessMessage': 'Keys successfully fetched!', 'error_message': "None"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException,msg:
data_ret = {'fetchStatus': 1, 'keysAvailable': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException,msg:
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except KeyError,msg:
data_ret = {'fetchStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def generateDKIMKeys(request):
try:
val = request.session['userID']
try:
if request.method == 'POST':
data = json.loads(request.body)
domainName = data['domainName']
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
execPath = execPath + " generateKeys --domain " + domainName
output = subprocess.check_output(shlex.split(execPath))
if output.find("1,None") > -1:
zone = dnsDomains.objects.get(name=domainName)
zone.save()
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
command = "sudo cat " + path
output = subprocess.check_output(shlex.split(command))
record = dnsRecords(domainOwner=zone,
domain_id=zone.id,
name="default._domainkey." + domainName,
type="TXT",
content="v=DKIM1; k=rsa; p=" + output[53:269],
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
data_ret = {'generateStatus': 1, 'error_message': "None"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
data_ret = {'generateStatus': 0, 'error_message': output}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException,msg:
data_ret = {'generateStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException, msg:
data_ret = {'generateStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def installOpenDKIM(request):
try:
val = request.session['userID']
try:
thread.start_new_thread(mailUtilities.installOpenDKIM, ('Install','openDKIM'))
final_json = json.dumps({'installOpenDKIM': 1, 'error_message': "None"})
return HttpResponse(final_json)
except BaseException,msg:
final_dic = {'installOpenDKIM': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except KeyError:
final_dic = {'installOpenDKIM': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def installStatusOpenDKIM(request):
try:
val = request.session['userID']
try:
if request.method == 'POST':
installStatus = unicode(open(mailUtilities.installLogPath, "r").read())
if installStatus.find("[200]")>-1:
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
execPath = execPath + " configureOpenDKIM"
output = subprocess.check_output(shlex.split(execPath))
if output.find("1,None") > -1:
pass
else:
final_json = json.dumps({
'error_message': "Failed to install OpenDKIM configurations.",
'requestStatus': installStatus,
'abort': 1,
'installed': 0,
})
return HttpResponse(final_json)
final_json = json.dumps({
'error_message': "None",
'requestStatus': installStatus,
'abort':1,
'installed': 1,
})
return HttpResponse(final_json)
elif installStatus.find("[404]") > -1:
final_json = json.dumps({
'abort':1,
'installed':0,
'error_message': "None",
'requestStatus': installStatus,
})
return HttpResponse(final_json)
else:
final_json = json.dumps({
'abort':0,
'error_message': "None",
'requestStatus': installStatus,
})
return HttpResponse(final_json)
except BaseException,msg:
final_dic = {'abort':1,'installed':0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except KeyError:
final_dic = {'abort':1,'installed':0, 'error_message': "Not Logged In, please refresh the page or login again."}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)

View File

@@ -8,6 +8,8 @@ import shlex
class mailUtilities:
installLogPath = "/home/cyberpanel/modSecInstallLog"
@staticmethod
def createEmailAccount(domain):
try:
@@ -126,6 +128,110 @@ class mailUtilities:
str(msg) + " [checkIfDKIMInstalled]")
return 0
@staticmethod
def generateKeys(domain):
try:
result = mailUtilities.setupDKIM(domain)
if result[0] == 0:
raise BaseException(result[1])
else:
print "1,None"
except BaseException,msg:
logging.CyberCPLogFileWriter.writeToFile(
str(msg) + " [generateKeys]")
print "0," + str(msg)
@staticmethod
def configureOpenDKIM():
try:
## Configure OpenDKIM specific settings
openDKIMConfigurePath = "/etc/opendkim.conf"
configData = """
Mode sv
Canonicalization relaxed/simple
KeyTable refile:/etc/opendkim/KeyTable
SigningTable refile:/etc/opendkim/SigningTable
ExternalIgnoreList refile:/etc/opendkim/TrustedHosts
InternalHosts refile:/etc/opendkim/TrustedHosts
"""
writeToFile = open(openDKIMConfigurePath, 'a')
writeToFile.write(configData)
writeToFile.close()
## Configure postfix specific settings
postfixFilePath = "/etc/postfix/main.cf"
configData = """
smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = $smtpd_milters
milter_default_action = accept
"""
writeToFile = open(postfixFilePath, 'a')
writeToFile.write(configData)
writeToFile.close()
#### Restarting Postfix and OpenDKIM
command = "systemctl start opendkim"
subprocess.call(shlex.split(command))
command = "systemctl enable opendkim"
subprocess.call(shlex.split(command))
##
command = "systemctl start postfix"
subprocess.call(shlex.split(command))
print "1,None"
return
except OSError, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [configureOpenDKIM]")
print "0," + str(msg)
return
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [configureOpenDKIM]")
print "0," + str(msg)
return
@staticmethod
def installOpenDKIM(install, openDKIMINstall):
try:
command = 'sudo yum install opendkim -y'
cmd = shlex.split(command)
with open(mailUtilities.installLogPath, 'w') as f:
res = subprocess.call(cmd, stdout=f)
if res == 1:
writeToFile = open(mailUtilities.installLogPath, 'a')
writeToFile.writelines("Can not be installed.[404]\n")
writeToFile.close()
logging.CyberCPLogFileWriter.writeToFile("[Could not Install]")
return 0
else:
writeToFile = open(mailUtilities.installLogPath, 'a')
writeToFile.writelines("OpenDKIM Installed.[200]\n")
writeToFile.close()
return 1
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installOpenDKIM]")
def main():
@@ -138,6 +244,10 @@ def main():
if args.function == "createEmailAccount":
mailUtilities.createEmailAccount(args.domain)
elif args.function == "generateKeys":
mailUtilities.generateKeys(args.domain)
elif args.function == "configureOpenDKIM":
mailUtilities.configureOpenDKIM()
if __name__ == "__main__":
main()

View File

@@ -911,7 +911,7 @@ def createVirtualHost(virtualHostName,administratorEmail,phpVersion,virtualHostU
if dkimCheck == 1:
if mailUtilities.checkIfDKIMInstalled() == 0:
print "0,OpenDKIM is not installed, install OpenDKIM from DKIM Manager."
print "0, OpenDKIM is not installed, install OpenDKIM from DKIM Manager."
return
result = mailUtilities.setupDKIM(virtualHostName)
@@ -963,14 +963,22 @@ def createVirtualHost(virtualHostName,administratorEmail,phpVersion,virtualHostU
str(msg) + " [createVirtualHost]")
print "0,"+str(msg)
def createDomain(masterDomain, virtualHostName, phpVersion, path,administratorEmail,virtualHostUser,restart,numberOfSites,ssl):
def createDomain(masterDomain, virtualHostName, phpVersion, path,administratorEmail,virtualHostUser,restart,numberOfSites,ssl, dkimCheck):
try:
if virtualHostUtilities.checkIfVirtualHostExists(virtualHostName) == 1:
print "0,Virtual Host Directory already exists!"
return
if dkimCheck == 1:
if mailUtilities.checkIfDKIMInstalled() == 0:
print "0, OpenDKIM is not installed, install OpenDKIM from DKIM Manager."
return
result = mailUtilities.setupDKIM(virtualHostName)
if result[0] == 0:
raise BaseException(result[1])
FNULL = open(os.devnull, 'w')
retValues = virtualHostUtilities.createDirectoryForDomain(masterDomain, virtualHostName, phpVersion, path,administratorEmail,virtualHostUser)
@@ -1824,7 +1832,11 @@ def main():
elif args.function == "deleteVirtualHostConfigurations":
virtualHostUtilities.deleteVirtualHostConfigurations(args.virtualHostName,int(args.numberOfSites))
elif args.function == "createDomain":
createDomain(args.masterDomain, args.virtualHostName, args.phpVersion, args.path,args.administratorEmail,args.virtualHostUser,args.restart,int(args.numberOfSites),int(args.ssl))
try:
dkimCheck = int(args.dkimCheck)
except:
dkimCheck = 0
createDomain(args.masterDomain, args.virtualHostName, args.phpVersion, args.path,args.administratorEmail,args.virtualHostUser,args.restart,int(args.numberOfSites),int(args.ssl),dkimCheck)
elif args.function == "issueSSL":
issueSSL(args.virtualHostName,args.path,args.administratorEmail)
elif args.function == "changePHP":

View File

@@ -63,7 +63,7 @@ app.controller('createEmailAccount', function($scope,$http) {
function ListInitialDatas(response) {
if(response.data.createEmailStatus == 1){
if(response.data.createEmailStatus === 1){
$scope.emailDetails = false;
$scope.emailLoading = true;
@@ -508,3 +508,322 @@ app.controller('changeEmailPassword', function($scope,$http) {
});
/* Java script code to create account ends here */
/* Java script code for DKIM Manager */
app.controller('dkimManager', function($scope, $http, $timeout, $window) {
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
$scope.fetchKeys = function(){
$scope.manageDKIMLoading = false;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
url = "/email/fetchDKIMKeys";
var data = {
domainName: $scope.domainName
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.fetchStatus === 1){
if(response.data.keysAvailable === 1){
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = false;
$scope.couldNotConnect = true;
$scope.domainRecords = false;
$scope.noKeysAvailable = true;
$scope.privateKey = response.data.privateKey;
$scope.publicKey = response.data.publicKey;
$scope.dkimSuccessMessage = response.data.dkimSuccessMessage;
}else{
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = false;
}
}
else{
$scope.errorMessage = response.data.error_message;
$scope.manageDKIMLoading = true;
$scope.dkimError = false;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
}
}
function cantLoadInitialDatas(response) {
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = false;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
}
};
$scope.createDomainDKIMKeys = function () {
$scope.manageDKIMLoading = false;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = false;
url = "/email/generateDKIMKeys";
var data = {
domainName: $scope.domainName
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.generateStatus === 1){
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
$scope.fetchKeys();
}
else{
$scope.errorMessage = response.data.error_message;
$scope.manageDKIMLoading = true;
$scope.dkimError = false;
$scope.dkimSuccess = true;
$scope.couldNotConnect = true;
$scope.domainRecords = true;
$scope.noKeysAvailable = false;
}
}
function cantLoadInitialDatas(response) {
$scope.manageDKIMLoading = true;
$scope.dkimError = true;
$scope.dkimSuccess = true;
$scope.couldNotConnect = false;
$scope.domainRecords = true;
$scope.noKeysAvailable = true;
}
};
// Installation
$scope.openDKIMNotifyBox = true;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = true;
$scope.installOpenDKIM = function(){
$scope.openDKIMNotifyBox = true;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = false;
url = "/email/installOpenDKIM";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.installOpenDKIM === 1){
$scope.openDKIMNotifyBox = true;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = false;
$scope.manageDKIMLoading = true;
getRequestStatus();
}
else{
$scope.errorMessage = response.data.error_message;
$scope.openDKIMNotifyBox = false;
$scope.openDKIMError = false;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = true;
}
}
function cantLoadInitialDatas(response) {
$scope.openDKIMNotifyBox = false;
$scope.openDKIMError = true;
$scope.couldNotConnect = false;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = false;
}
};
function getRequestStatus(){
$scope.openDKIMNotifyBox = true;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = false;
$scope.manageDKIMLoading = false;
url = "/email/installStatusOpenDKIM";
var data = {};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.abort === 0){
$scope.requestData = response.data.requestStatus;
$timeout(getRequestStatus,1000);
}
else{
// Notifications
$timeout.cancel();
$scope.openDKIMNotifyBox = false;
$scope.openDKIMError = true;
$scope.couldNotConnect = true;
$scope.openDKIMSuccessfullyInstalled = true;
$scope.openDKIMInstallBox = true;
$scope.manageDKIMLoading = true;
$scope.requestData = response.data.requestStatus;
if(response.data.installed === 0) {
$scope.openDKIMError = false;
$scope.errorMessage = response.data.error_message;
}else{
$scope.openDKIMSuccessfullyInstalled = false;
$timeout(function() { $window.location.reload(); }, 3000);
}
}
}
function cantLoadInitialDatas(response) {
$scope.modSecNotifyBox = false;
$scope.modeSecInstallBox = false;
$scope.modsecLoading = true;
$scope.failedToStartInallation = true;
$scope.couldNotConnect = false;
$scope.modSecSuccessfullyInstalled = true;
$scope.installationFailed = true;
}
}
});

View File

@@ -1150,14 +1150,14 @@ app.controller('websitePages', function($scope,$http) {
$scope.installationDetailsForm = !$scope.installationDetailsForm;
$scope.installationDetailsFormJoomla = true;
}
};
$scope.installationDetailsJoomla = function(){
$scope.installationDetailsFormJoomla = !$scope.installationDetailsFormJoomla;
$scope.installationDetailsForm = true;
}
};
$scope.installWordpress = function(){
@@ -1550,6 +1550,13 @@ app.controller('websitePages', function($scope,$http) {
var ssl = 0
}
if ($scope.dkimCheck === true){
var dkimCheck = 1;
}
else{
var dkimCheck = 0
}
url = "/websites/submitDomainCreation";
var domainName = $scope.domainNameCreate;
@@ -1568,6 +1575,7 @@ app.controller('websitePages', function($scope,$http) {
ssl:ssl,
path:path,
masterDomain:$("#domainNamePage").text(),
dkimCheck:dkimCheck
};
var config = {

View File

@@ -1150,14 +1150,14 @@ app.controller('websitePages', function($scope,$http) {
$scope.installationDetailsForm = !$scope.installationDetailsForm;
$scope.installationDetailsFormJoomla = true;
}
};
$scope.installationDetailsJoomla = function(){
$scope.installationDetailsFormJoomla = !$scope.installationDetailsFormJoomla;
$scope.installationDetailsForm = true;
}
};
$scope.installWordpress = function(){
@@ -1550,6 +1550,13 @@ app.controller('websitePages', function($scope,$http) {
var ssl = 0
}
if ($scope.dkimCheck === true){
var dkimCheck = 1;
}
else{
var dkimCheck = 0
}
url = "/websites/submitDomainCreation";
var domainName = $scope.domainNameCreate;
@@ -1568,6 +1575,7 @@ app.controller('websitePages', function($scope,$http) {
ssl:ssl,
path:path,
masterDomain:$("#domainNamePage").text(),
dkimCheck:dkimCheck
};
var config = {

View File

@@ -338,7 +338,7 @@
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Additional Features" %}</label>
<div class="col-sm-6">
<div class="col-sm-9">
<div class="checkbox">
<label>
<input ng-model="sslCheck" type="checkbox" value="">
@@ -349,6 +349,15 @@
</label>
</div>
</div>
<label class="col-sm-3 control-label"></label>
<div class="col-sm-9">
<div class="checkbox">
<label>
<input ng-model="dkimCheck" type="checkbox" value="">
DKIM Support
</label>
</div>
</div>
</div>

View File

@@ -172,6 +172,303 @@ def deleteWebsite(request):
return redirect(loadLoginPage)
def dnsTemplate(request, domain, admin, dkimCheck):
try:
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
import tldextract
extractDomain = tldextract.extract(domain)
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
subDomain = extractDomain.subdomain
if len(subDomain) == 0:
if Domains.objects.filter(name=topLevelDomain).count() == 0:
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
zone.save()
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
soaRecord = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="SOA",
content=content,
ttl=3600,
prio=0,
disabled=0,
auth=1)
soaRecord.save()
## Main A record.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
cNameValue = "ftp." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## MX Record.
mxValue = "mail." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="MX",
content=mxValue,
ttl=3600,
prio="10",
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name=mxValue,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## TXT Records for mail
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="TXT",
content="v=spf1 a mx ip4:" + ipAddress + " ~all",
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name="_dmarc." + topLevelDomain,
type="TXT",
content="v=DMARC1; p=none",
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name="_domainkey." + topLevelDomain,
type="TXT",
content="t=y; o=~;",
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## DKIM Support
if dkimCheck == 1:
path = "/etc/opendkim/keys/" + topLevelDomain + "/default.txt"
command = "sudo cat " + path
output = subprocess.check_output(shlex.split(command))
record = Records(domainOwner=zone,
domain_id=zone.id,
name="default._domainkey." + topLevelDomain,
type="TXT",
content="v=DKIM1; k=rsa; p=" + output[53:269],
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
else:
if Domains.objects.filter(name=topLevelDomain).count() == 0:
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
zone.save()
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
soaRecord = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="SOA",
content=content,
ttl=3600,
prio=0,
disabled=0,
auth=1)
soaRecord.save()
## Main A record.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
cNameValue = "ftp." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## MX Record.
mxValue = "mail." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="MX",
content=mxValue,
ttl=3600,
prio="10",
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name=mxValue,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## DKIM Support
if dkimCheck == 1:
path = "/etc/opendkim/keys/" + topLevelDomain + "/default.txt"
command = "sudo cat " + path
output = subprocess.check_output(shlex.split(command))
record = Records(domainOwner=zone,
domain_id=zone.id,
name="default._domainkey." + topLevelDomain,
type="TXT",
content="v=DKIM1; k=rsa; p=" + output[53:269],
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## Creating sub-domain level record.
zone = Domains.objects.get(name=topLevelDomain)
actualSubDomain = subDomain + "." + topLevelDomain
## Main A record.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=actualSubDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + actualSubDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=actualSubDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(
"We had errors while creating DNS records for: " + domain + ". Error message: " + str(msg))
def siteState(request):
try:
val = request.session['userID']
@@ -306,290 +603,7 @@ def submitWebsiteCreation(request):
##### Zone creation
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
try:
import tldextract
extractDomain = tldextract.extract(domain)
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
subDomain = extractDomain.subdomain
if len(subDomain) == 0:
if Domains.objects.filter(name=topLevelDomain).count() == 0:
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
zone.save()
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
soaRecord = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="SOA",
content=content,
ttl=3600,
prio=0,
disabled=0,
auth=1)
soaRecord.save()
## Main A record.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
cNameValue = "ftp." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## MX Record.
mxValue = "mail." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="MX",
content=mxValue,
ttl=3600,
prio="10",
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name=mxValue,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## TXT Records for mail
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="TXT",
content="v=spf1 a mx ip4:" + ipAddress + " ~all",
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name="_dmarc." + topLevelDomain,
type="TXT",
content="v=DMARC1; p=none",
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name="_domainkey." + topLevelDomain,
type="TXT",
content="t=y; o=~;",
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## DKIM Support
if data['dkimCheck'] == 1:
path = "/etc/opendkim/keys/" + topLevelDomain + "/default.txt"
command = "sudo cat " + path
output = subprocess.check_output(shlex.split(command))
record = Records(domainOwner=zone,
domain_id=zone.id,
name="default._domainkey." + topLevelDomain,
type="TXT",
content="v=DKIM1; k=rsa; p=" + output[53:269],
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
else:
if Domains.objects.filter(name=topLevelDomain).count() == 0:
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
zone.save()
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
soaRecord = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="SOA",
content=content,
ttl=3600,
prio=0,
disabled=0,
auth=1)
soaRecord.save()
## Main A record.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
cNameValue = "ftp." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## MX Record.
mxValue = "mail." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="MX",
content=mxValue,
ttl=3600,
prio="10",
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name=mxValue,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## Creating sub-domain level record.
zone = Domains.objects.get(name=topLevelDomain)
actualSubDomain = subDomain + "." + topLevelDomain
## Main A record.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=actualSubDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + actualSubDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=actualSubDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except BaseException,msg:
logging.CyberCPLogFileWriter.writeToFile("We had errors while creating DNS records for: " + domain + ". Error message: " + str(msg))
dnsTemplate(requests, domain, admin, data['dkimCheck'])
## zone creation
@@ -675,7 +689,7 @@ def submitDomainCreation(request):
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
execPath = execPath + " createDomain --masterDomain " + masterDomain + " --virtualHostName " + domain + " --administratorEmail " + master.adminEmail + " --phpVersion '" + phpSelection + "' --virtualHostUser " + externalApp + " --numberOfSites " + numberOfWebsites + " --ssl " + str(
data['ssl']) + " --path " + path
data['ssl']) + " --path " + path + " --dkimCheck " + str(data['dkimCheck'])
output = subprocess.check_output(shlex.split(execPath))
@@ -689,307 +703,13 @@ def submitDomainCreation(request):
### Zone creation.
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
try:
restore = data['restore']
restart = 0
except BaseException,msg:
try:
val = request.session['userID']
admin = Administrator.objects.get(pk=val)
import tldextract
extractDomain = tldextract.extract(domain)
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
subDomain = extractDomain.subdomain
if len(subDomain) == 0:
if Domains.objects.filter(name=topLevelDomain).count() == 0:
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
zone.save()
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
soaRecord = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="SOA",
content=content,
ttl=3600,
prio=0,
disabled=0,
auth=1)
soaRecord.save()
## Main A record.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
cNameValue = "ftp." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## MX Record.
mxValue = "mail." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="MX",
content=mxValue,
ttl=3600,
prio="10",
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name=mxValue,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
else:
if Domains.objects.filter(name=topLevelDomain).count() == 0:
zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
zone.save()
content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"
soaRecord = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="SOA",
content=content,
ttl=3600,
prio=0,
disabled=0,
auth=1)
soaRecord.save()
## Main A record.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
cNameValue = "ftp." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=topLevelDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## MX Record.
mxValue = "mail." + topLevelDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=topLevelDomain,
type="MX",
content=mxValue,
ttl=3600,
prio="10",
disabled=0,
auth=1)
record.save()
record = Records(domainOwner=zone,
domain_id=zone.id,
name=mxValue,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
## Creating sub-domain level record.
zone = Domains.objects.get(name=topLevelDomain)
actualSubDomain = subDomain + "." + topLevelDomain
## Main A record.
record = Records(domainOwner=zone,
domain_id=zone.id,
name=actualSubDomain,
type="A",
content=ipAddress,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# CNAME Records.
cNameValue = "www." + actualSubDomain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=actualSubDomain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except BaseException,msg:
try:
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
recordContentA = ipData.split('\n', 1)[0]
try:
zone = Domains.objects.get(name=domain)
record = Records(domainOwner=zone,
domain_id=zone.id,
name=domain,
type="A",
content=recordContentA,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except:
newZone = Domains(admin=admin, name=domain, type="NATIVE")
newZone.save()
content = "ns1." + domain + " hostmaster." + domain + " 1 10800 3600 604800 3600"
soaRecord = Records(domainOwner=newZone,
domain_id=newZone.id,
name=domain,
type="SOA",
content=content,
ttl=3600,
prio=0,
disabled=0,
auth=1)
soaRecord.save()
try:
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
recordContentA = ipData.split('\n', 1)[0]
zone = Domains.objects.get(name=domain)
record = Records(domainOwner=zone,
domain_id=zone.id,
name=domain,
type="A",
content=recordContentA,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
# For www part
cNameValue = "www." + domain
record = Records(domainOwner=zone,
domain_id=zone.id,
name=cNameValue,
type="CNAME",
content=domain,
ttl=3600,
prio=0,
disabled=0,
auth=1)
record.save()
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(
"Unable to add A record while creating website, error: " + str(msg))
except BaseException,msg:
logging.CyberCPLogFileWriter.writeToFile("Unable to add A record while creating website, error: " + str(msg))
dnsTemplate(requests, domain, admin, data['dkimCheck'])
## Zone creation.