diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 9839a9cca..336769932 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -391,6 +391,7 @@
  • {% trans "Create Email" %}
  • {% trans "Delete Email" %}
  • {% trans "Change Password" %}
  • +
  • {% trans "DKIM Manager" %}
  • {% trans "Access Webmail" %}
  • diff --git a/dns/templates/dns/addDeleteDNSRecords.html b/dns/templates/dns/addDeleteDNSRecords.html index 81b526702..56248584c 100644 --- a/dns/templates/dns/addDeleteDNSRecords.html +++ b/dns/templates/dns/addDeleteDNSRecords.html @@ -318,7 +318,7 @@ -
    +
    @@ -357,10 +357,6 @@ - - - - diff --git a/firewall/templates/firewall/modSecurity.html b/firewall/templates/firewall/modSecurity.html index b3da3dd9b..d842ba6cf 100644 --- a/firewall/templates/firewall/modSecurity.html +++ b/firewall/templates/firewall/modSecurity.html @@ -34,6 +34,7 @@
    +
    @@ -57,7 +58,7 @@
    -
    +
    @@ -72,7 +73,6 @@
    - {% else %} diff --git a/mailServer/static/mailServer/mailServer.js b/mailServer/static/mailServer/mailServer.js index 879adb0df..7f3ad21f3 100644 --- a/mailServer/static/mailServer/mailServer.js +++ b/mailServer/static/mailServer/mailServer.js @@ -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; + + + } + + } + + + +}); + diff --git a/mailServer/templates/mailServer/dkimManager.html b/mailServer/templates/mailServer/dkimManager.html new file mode 100644 index 000000000..36e453cad --- /dev/null +++ b/mailServer/templates/mailServer/dkimManager.html @@ -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 %} + + + +
    +
    +

    {% trans "DKIM Manager" %}

    +

    {% trans "This page can be used to generate and view DKIM keys for Domains" %}

    +
    + +
    + + {% if openDKIMInstalled == 0 %} +
    +

    + {% trans "DKIM Manager" %} +

    +
    + +
    +

    {% trans "OpenDKIM is not installed. " %} + {% trans "Install Now" %} +

    +
    + + + + +
    + +
    + +
    +

    {% trans "Error message: " %} {$ errorMessage $}

    +
    + +
    +

    {% trans "Could not connect. Please refresh this page." %}

    +
    + +
    +

    {% trans "OpenDKIM successfully installed, refreshing page in 3 seconds.." %}

    +
    +
    +
    + + +
    + + +
    +
    + +
    +
    + +
    + + + + + + +
    +
    + {% else %} +
    +

    + {% trans "DKIM Manager" %} +

    +
    + +
    + + +
    + +
    + +
    +
    + + + +
    + +

    {% trans "Keys not available for this domain." %} + {% trans "Generate Now" %} +

    + +
    + +
    + +
    + + + + + + + + + + + + + + + + +
    {% trans "Domain" %}{% trans "Private Key" %}{% trans "Public Key" %}
    +
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + + + + +
    + +
    + +
    +

    {$ dkimSuccessMessage $}

    +
    + + +
    +

    {$ errorMessage $}

    +
    + + +
    +

    {% trans "Could not connect to server. Please refresh this page." %}

    +
    + +
    +
    + + +
    + + + +
    +
    + {% endif %} +
    + + +
    + + +{% endblock %} \ No newline at end of file diff --git a/mailServer/urls.py b/mailServer/urls.py index 0ca5656a8..1dfcc2f02 100644 --- a/mailServer/urls.py +++ b/mailServer/urls.py @@ -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'), + ] \ No newline at end of file diff --git a/mailServer/views.py b/mailServer/views.py index ed889cd18..10e63a897 100644 --- a/mailServer/views.py +++ b/mailServer/views.py @@ -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) + diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index 78095f076..9357d786f 100644 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -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() \ No newline at end of file diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 6a6d4416f..a88611a57 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -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": diff --git a/static/mailServer/mailServer.js b/static/mailServer/mailServer.js index 879adb0df..7f3ad21f3 100644 --- a/static/mailServer/mailServer.js +++ b/static/mailServer/mailServer.js @@ -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; + + + } + + } + + + +}); + diff --git a/static/websiteFunctions/websiteFunctions.js b/static/websiteFunctions/websiteFunctions.js index e779206d9..0cd8d27ba 100644 --- a/static/websiteFunctions/websiteFunctions.js +++ b/static/websiteFunctions/websiteFunctions.js @@ -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 = { diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index e779206d9..0cd8d27ba 100644 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -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 = { diff --git a/websiteFunctions/templates/websiteFunctions/website.html b/websiteFunctions/templates/websiteFunctions/website.html index 5b6b01407..f48ee3a47 100644 --- a/websiteFunctions/templates/websiteFunctions/website.html +++ b/websiteFunctions/templates/websiteFunctions/website.html @@ -338,7 +338,7 @@
    -
    +
    + +
    +
    + +
    +
    diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 6a0ae96ed..ed58ab6bb 100644 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -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)) - + val = request.session['userID'] + admin = Administrator.objects.get(pk=val) + dnsTemplate(requests, domain, admin, data['dkimCheck']) ## Zone creation.