From fda1749754d3c3d425f298a1ba3643f9b9701dd2 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Mon, 24 Aug 2020 05:50:28 +0500 Subject: [PATCH] complete: https://feedback.cyberpanel.net/b/requests/p/dns-edit-feature --- CyberCP/secMiddleware.py | 2 +- dns/dnsManager.py | 41 + dns/static/dns/dns.js | 666 +++++++++------- dns/templates/dns/addDeleteDNSRecords.html | 847 +++++++++++---------- dns/urls.py | 1 + dns/views.py | 8 + plogical/applicationInstaller.py | 345 ++++----- static/dns/dns.js | 666 +++++++++------- 8 files changed, 1428 insertions(+), 1148 deletions(-) diff --git a/CyberCP/secMiddleware.py b/CyberCP/secMiddleware.py index 7cb0562b7..8f0271330 100755 --- a/CyberCP/secMiddleware.py +++ b/CyberCP/secMiddleware.py @@ -73,7 +73,7 @@ class secMiddleware: or key == 'imageByPass' or key == 'passwordByPass' or key == 'cronCommand' \ or key == 'emailMessage' or key == 'configData' or key == 'rewriteRules' \ or key == 'modSecRules' or key == 'recordContentTXT' or key == 'SecAuditLogRelevantStatus' \ - or key == 'fileContent' or key == 'commands' or key == 'gitHost' or key == 'ipv6': + or key == 'fileContent' or key == 'commands' or key == 'gitHost' or key == 'ipv6' or key == 'contentNow': continue if value.find(';') > -1 or value.find('&&') > -1 or value.find('|') > -1 or value.find('...') > -1 \ or value.find("`") > -1 or value.find("$") > -1 or value.find("(") > -1 or value.find(")") > -1 \ diff --git a/dns/dnsManager.py b/dns/dnsManager.py index fc2654a78..d65a61376 100755 --- a/dns/dnsManager.py +++ b/dns/dnsManager.py @@ -418,6 +418,47 @@ class DNSManager: final_json = json.dumps(final_dic) return HttpResponse(final_json) + def updateRecord(self, userID = None, data = None): + try: + + currentACL = ACLManager.loadedACL(userID) + + if ACLManager.currentContextPermission(currentACL, 'addDeleteRecords') == 0: + return ACLManager.loadErrorJson('add_status', 0) + + zoneDomain = data['selectedZone'] + + admin = Administrator.objects.get(pk=userID) + if ACLManager.checkOwnershipZone(zoneDomain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadErrorJson() + + record = Records.objects.get(pk=data['id']) + + if data['nameNow'] != None: + record.name = data['nameNow'] + + if data['ttlNow'] != None: + record.ttl = int(data['ttlNow']) + + if data['priorityNow'] != None: + record.prio = int(data['priorityNow']) + + if data['contentNow'] != None: + record.content = data['contentNow'] + + record.save() + + final_dic = {'status': 1, 'error_message': "None"} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + except BaseException as msg: + final_dic = {'status': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + def deleteDNSRecord(self, userID = None, data = None): try: currentACL = ACLManager.loadedACL(userID) diff --git a/dns/static/dns/dns.js b/dns/static/dns/dns.js index 516d2f4de..18cc88645 100755 --- a/dns/static/dns/dns.js +++ b/dns/static/dns/dns.js @@ -154,346 +154,434 @@ app.controller('createDNSZone', function ($scope, $http) { app.controller('addModifyDNSRecords', function ($scope, $http) { - $scope.addRecordsBox = true; - $scope.currentRecords = true; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; - $scope.recordDeleted = true; - $scope.couldNotDeleteRecords = true; - $scope.couldNotAddRecord = true; - $scope.recordValueDefault = false; + $scope.addRecordsBox = true; + $scope.currentRecords = true; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = true; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.recordDeleted = true; + $scope.couldNotDeleteRecords = true; + $scope.couldNotAddRecord = true; + $scope.recordValueDefault = false; - // Hide records boxes - $(".aaaaRecord").hide(); - $(".cNameRecord").hide(); - $(".mxRecord").hide(); - $(".txtRecord").hide(); - $(".spfRecord").hide(); - $(".nsRecord").hide(); - $(".soaRecord").hide(); - $(".srvRecord").hide(); - $(".caaRecord").hide(); + // Hide records boxes + $(".aaaaRecord").hide(); + $(".cNameRecord").hide(); + $(".mxRecord").hide(); + $(".txtRecord").hide(); + $(".spfRecord").hide(); + $(".nsRecord").hide(); + $(".soaRecord").hide(); + $(".srvRecord").hide(); + $(".caaRecord").hide(); - var currentSelection = "aRecord"; - $("#" + currentSelection).addClass("active"); - - $scope.fetchRecordsTabs = function (recordType) { - $("#" + currentSelection).removeClass("active"); - $("." + currentSelection).hide(); - $scope.recordsLoading = false; - currentSelection = recordType; + var currentSelection = "aRecord"; $("#" + currentSelection).addClass("active"); - $("." + currentSelection).show(); - populateCurrentRecords(); - }; - - $scope.fetchRecords = function () { - $scope.recordsLoading = false; - $scope.addRecordsBox = false; - populateCurrentRecords(); - }; - - - $scope.addDNSRecord = function (type) { - - $scope.recordsLoading = false; - - - url = "/dns/addDNSRecord"; - - - // Record specific values - - var data = {}; - - if (type === "MX") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentMX = $scope.recordContentMX; - data.priority = $scope.priority; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "A") { - - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentA = $scope.recordContentA; - data.ttl = $scope.ttl; - data.recordType = type; - - } else if (type === "AAAA") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentAAAA = $scope.recordContentAAAA; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "CNAME") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentCNAME = $scope.recordContentCNAME; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "SPF") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentSPF = $scope.recordContentSPF; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "SOA") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.selectedZone; - data.recordContentSOA = $scope.recordContentSOA; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "TXT") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentTXT = $scope.recordContentTXT; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "NS") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.selectedZone; - data.recordContentNS = $scope.recordContentNS; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "SRV") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentSRV = $scope.recordContentSRV; - data.priority = $scope.priority; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "CAA") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentCAA = $scope.recordContentCAA; - data.ttl = $scope.ttl; - data.recordType = type; - } - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } + $scope.fetchRecordsTabs = function (recordType) { + $("#" + currentSelection).removeClass("active"); + $("." + currentSelection).hide(); + $scope.recordsLoading = false; + currentSelection = recordType; + $("#" + currentSelection).addClass("active"); + $("." + currentSelection).show(); + populateCurrentRecords(); }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.add_status === 1) { - - - populateCurrentRecords(); - - $scope.canNotFetchRecords = true; - $scope.recordsFetched = false; - $scope.recordDeleted = true; - $scope.recordAdded = false; - $scope.couldNotConnect = true; - $scope.couldNotAddRecord = true; - $scope.recordsLoading = true; - - - } else { - - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; - $scope.couldNotAddRecord = false; - - $scope.errorMessage = response.data.error_message; - } - - } - - function cantLoadInitialDatas(response) { - - $scope.addRecordsBox = true; - $scope.currentRecords = true; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = false; - $scope.couldNotAddRecord = true; - - - } - - }; - - - function populateCurrentRecords() { - - var selectedZone = $scope.selectedZone; - - url = "/dns/getCurrentRecordsForDomain"; - - var data = { - selectedZone: selectedZone, - currentSelection: currentSelection - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } + $scope.fetchRecords = function () { + $scope.recordsLoading = false; + $scope.addRecordsBox = false; + populateCurrentRecords(); }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + $scope.addDNSRecord = function (type) { + + $scope.recordsLoading = false; - function ListInitialDatas(response) { - if (response.data.fetchStatus === 1) { + url = "/dns/addDNSRecord"; - $scope.records = JSON.parse(response.data.data); - $scope.currentRecords = false; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = false; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; - $scope.couldNotAddRecord = true; + // Record specific values - $scope.domainFeteched = $scope.selectedZone; + var data = {}; - } else { + if (type === "MX") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentMX = $scope.recordContentMX; + data.priority = $scope.priority; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "A") { + + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentA = $scope.recordContentA; + data.ttl = $scope.ttl; + data.recordType = type; + + } else if (type === "AAAA") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentAAAA = $scope.recordContentAAAA; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "CNAME") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentCNAME = $scope.recordContentCNAME; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "SPF") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentSPF = $scope.recordContentSPF; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "SOA") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.selectedZone; + data.recordContentSOA = $scope.recordContentSOA; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "TXT") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentTXT = $scope.recordContentTXT; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "NS") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.selectedZone; + data.recordContentNS = $scope.recordContentNS; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "SRV") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentSRV = $scope.recordContentSRV; + data.priority = $scope.priority; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "CAA") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentCAA = $scope.recordContentCAA; + data.ttl = $scope.ttl; + data.recordType = type; + } + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.add_status === 1) { + + + populateCurrentRecords(); + + $scope.canNotFetchRecords = true; + $scope.recordsFetched = false; + $scope.recordDeleted = true; + $scope.recordAdded = false; + $scope.couldNotConnect = true; + $scope.couldNotAddRecord = true; + $scope.recordsLoading = true; + + + } else { + + $scope.recordsFetched = true; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.couldNotAddRecord = false; + + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { $scope.addRecordsBox = true; $scope.currentRecords = true; - $scope.canNotFetchRecords = false; + $scope.canNotFetchRecords = true; $scope.recordsFetched = true; $scope.recordDeleted = true; $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; + $scope.couldNotConnect = false; $scope.couldNotAddRecord = true; - $scope.errorMessage = response.data.error_message; + } - } - - function cantLoadInitialDatas(response) { - - $scope.addRecordsBox = true; - $scope.currentRecords = true; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = false; - $scope.couldNotAddRecord = true; - - - } - - }; - - - $scope.deleteRecord = function (id) { - - - var selectedZone = $scope.selectedZone; - - url = "/dns/deleteDNSRecord"; - - var data = { - id: id, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + function populateCurrentRecords() { + + var selectedZone = $scope.selectedZone; + + url = "/dns/getCurrentRecordsForDomain"; + + var data = { + selectedZone: selectedZone, + currentSelection: currentSelection + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - function ListInitialDatas(response) { + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - if (response.data.delete_status == 1) { + function ListInitialDatas(response) { + if (response.data.fetchStatus === 1) { + $scope.records = JSON.parse(response.data.data); + + $scope.currentRecords = false; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = false; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.couldNotAddRecord = true; + + $scope.domainFeteched = $scope.selectedZone; + + } else { + + $scope.addRecordsBox = true; + $scope.currentRecords = true; + $scope.canNotFetchRecords = false; + $scope.recordsFetched = true; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.couldNotAddRecord = true; + + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { + + $scope.addRecordsBox = true; + $scope.currentRecords = true; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = true; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = false; + $scope.couldNotAddRecord = true; + + + } + + }; + + var globalID = null; + var nameNow = null; + var ttlNow = null; + var contentNow = null; + var priorityNow = null; + + + $scope.setupContent = function (id, type, content) { + if (globalID === null) { + globalID = id; + } else { + if (globalID !== id) { + globalID = id; + nameNow = null; + ttlNow = null; + contentNow = null; + priorityNow = null; + } + } + + if (type === 'name') { + nameNow = content; + } else if (type === 'ttl') { + ttlNow = content; + } else if (type === 'content') { + contentNow = content; + } else if (type === 'priority') { + priorityNow = content; + } + }; + + $scope.saveNow = function (id) { + + if (id !== globalID) { + alert('This record is not changed'); + return; + } + $scope.recordsLoading = false; + + url = "/dns/updateRecord"; + + var data = { + selectedZone: $scope.selectedZone, + id: globalID, + nameNow: nameNow, + ttlNow: ttlNow, + contentNow: contentNow, + priorityNow: priorityNow, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.recordsLoading = true; + + if (response.data.status === 1) { + + new PNotify({ + title: 'Success!', + text: 'Record updated.', + type: 'success' + }); + + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.recordsLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + }; + + $scope.deleteRecord = function (id) { + + var selectedZone = $scope.selectedZone; + + url = "/dns/deleteDNSRecord"; + + var data = { + id: id, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.delete_status == 1) { + + + $scope.addRecordsBox = false; + $scope.currentRecords = false; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = true; + $scope.recordDeleted = false; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.recordDeleted = true; + $scope.couldNotDeleteRecords = true; + $scope.couldNotAddRecord = true; + + populateCurrentRecords(); + + + } else { + + $scope.addRecordsBox = true; + $scope.currentRecords = true; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = false; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.recordDeleted = true; + $scope.couldNotDeleteRecords = false; + $scope.couldNotAddRecord = true; + + + $scope.errorMessage = response.data.error_message; + + + } + + } + + function cantLoadInitialDatas(response) { $scope.addRecordsBox = false; $scope.currentRecords = false; $scope.canNotFetchRecords = true; $scope.recordsFetched = true; - $scope.recordDeleted = false; + $scope.recordDeleted = true; $scope.recordAdded = true; - $scope.couldNotConnect = true; + $scope.couldNotConnect = false; $scope.recordsLoading = true; $scope.recordDeleted = true; $scope.couldNotDeleteRecords = true; $scope.couldNotAddRecord = true; - populateCurrentRecords(); - - - } else { - - $scope.addRecordsBox = true; - $scope.currentRecords = true; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = false; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; - $scope.recordDeleted = true; - $scope.couldNotDeleteRecords = false; - $scope.couldNotAddRecord = true; - - - $scope.errorMessage = response.data.error_message; - } - } - function cantLoadInitialDatas(response) { - - $scope.addRecordsBox = false; - $scope.currentRecords = false; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = false; - $scope.recordsLoading = true; - $scope.recordDeleted = true; - $scope.couldNotDeleteRecords = true; - $scope.couldNotAddRecord = true; + }; - } - - - }; - - -}); + } +); /* Java script code to delete DNS Zone */ @@ -1049,7 +1137,7 @@ app.controller('addModifyDNSRecordsCloudFlare', function ($scope, $http, $window $scope.syncCF = function () { - $scope.recordsLoading = false; + $scope.recordsLoading = false; var selectedZone = $scope.selectedZone; url = "/dns/syncCF"; diff --git a/dns/templates/dns/addDeleteDNSRecords.html b/dns/templates/dns/addDeleteDNSRecords.html index 725f676d0..883795278 100755 --- a/dns/templates/dns/addDeleteDNSRecords.html +++ b/dns/templates/dns/addDeleteDNSRecords.html @@ -3,405 +3,458 @@ {% block title %}{% trans "Add/Modify DNS Records - CyberPanel" %}{% endblock %} {% block content %} -{% load static %} -{% get_current_language as LANGUAGE_CODE %} - - - -
-
-

{% trans "Add/Modify DNS Zone" %} - {% trans "DNS Docs" %}

-

{% trans "On this page you can add/modify dns records for domains whose dns zone is already created." %}

-
-
-
-

- {% trans "Add Records" %} -

-
- - - {% if not status %} - -
-

{% trans "PowerDNS is disabled." %} -

-
- - - {% else %} - - -
- - -
- -
- -
-
- - -
- -
- -
- - - - -
- -
- -
- -
- -
- -
- - - -
- -
- - - - - - -
- -
- -
- -
- -
- -
- - - -
- -
- - - - - - - -
- -
- -
- -
- -
- -
- - - -
- -
- - - - - - -
- -
- -
- -
- -
- -
- -
- -
- - - -
- -
- - - - - - - -
- -
- -
- -
- - -
- -
- - - -
- -
- - - - - - -
- -
- -
- -
- - -
- -
- - - -
- -
- - - - - - -
- -
- -
- -
- - -
- -
- - - -
- -
- - - - - - -
- -
- -
- -
- - -
- -
- - - -
- -
- - - - - - -
- -
- -
- -
- -
- -
- - -
- -
- - - -
- -
- - - - - -
- -
-
- -
-
- -
-
- -
- - - - - -
- - - - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - -
{% trans "ID" %}{% trans "Type" %}{% trans "Name" %}{% trans "TTL" %}{% trans "Value" %}{% trans "Priority" %}{% trans "Delete" %}
-
-
- - - - -
- - - -
-
-

{% trans "Cannot fetch records. Error message:" %}{$ errorMessage $}

-
- -
-

{% trans "Cannot add record. Error message: " %}{$ errorMessage $}

-
- -
-

{% trans "Records successfully fetched for" %} {$ domainFeteched $}

-
- -
-

{% trans "Record Successfully Deleted" %}

-
- -
-

{% trans "Cannot delete record. Error message:" %} {$ errorMessage $}

-
- -
-

{% trans "Record Successfully Added." %}

-
- - -
-

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

-
- -
-
- - - -
- - {% endif %} - - - - + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + + +
+
+

{% trans "Add/Modify DNS Zone" %} - {% trans "DNS Docs" %}

+

{% trans "On this page you can add/modify dns records for domains whose dns zone is already created." %}

+
+
+

+ {% trans "Add Records" %} +

+
+ + + {% if not status %} + +
+

{% trans "PowerDNS is disabled." %} + + +

+
+ + + {% else %} + + +
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+ + + + +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + + + + + + +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + + + + + +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + + + + +
+ +
+
+ +
+
+ +
+
+ +
+ + + + +
+ + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
{% trans "Type" %}{% trans "Name" %}{% trans "TTL" %}{% trans "Value" %}{% trans "Priority" %}{% trans "Delete" %}
+ + + +
+
+
+ + + + +
+ + + +
+
+

{% trans "Cannot fetch records. Error message:" %}{$ errorMessage $}

+
+ +
+

{% trans "Cannot add record. Error message: " %}{$ errorMessage $}

+
+ +
+

{% trans "Records successfully fetched for" %} {$ domainFeteched + $}

+
+ +
+

{% trans "Record Successfully Deleted" %}

+
+ +
+

{% trans "Cannot delete record. Error message:" %} {$ errorMessage $}

+
+ +
+

{% trans "Record Successfully Added." %}

+
+ + +
+

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

+
+ +
+
+ + +
+ + {% endif %} + + +
+
+
+ +
-
- - -
{% endblock %} diff --git a/dns/urls.py b/dns/urls.py index 94969f35f..fd175330d 100755 --- a/dns/urls.py +++ b/dns/urls.py @@ -19,6 +19,7 @@ urlpatterns = [ url(r'^submitZoneDeletion',views.submitZoneDeletion,name='submitZoneDeletion'), url(r'^saveNSConfigurations$', views.saveNSConfigurations, name='saveNSConfigurations'), url(r'^saveCFConfigs$', views.saveCFConfigs, name='saveCFConfigs'), + url(r'^updateRecord$', views.updateRecord, name='updateRecord'), url(r'^getCurrentRecordsForDomainCloudFlare$', views.getCurrentRecordsForDomainCloudFlare, name='getCurrentRecordsForDomainCloudFlare'), url(r'^deleteDNSRecordCloudFlare$', views.deleteDNSRecordCloudFlare, name='deleteDNSRecordCloudFlare'), diff --git a/dns/views.py b/dns/views.py index d5fe5c359..a28af54af 100755 --- a/dns/views.py +++ b/dns/views.py @@ -78,6 +78,14 @@ def addDeleteDNSRecords(request): except KeyError: return redirect(loadLoginPage) +def updateRecord(request): + try: + userID = request.session['userID'] + dm = DNSManager() + return dm.updateRecord(userID, json.loads(request.body)) + except KeyError: + return redirect(loadLoginPage) + def getCurrentRecordsForDomain(request): try: userID = request.session['userID'] diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index e8d3081a2..83e97ad36 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -814,175 +814,176 @@ class ApplicationInstaller(multi.Thread): logging.writeToFile(str(msg)) return 0 - def installMagento(self): - try: - - username = self.extraArgs['username'] - domainName = self.extraArgs['domainName'] - home = self.extraArgs['home'] - firstName = self.extraArgs['firstName'] - lastName = self.extraArgs['lastName'] - email = self.extraArgs['email'] - password = self.extraArgs['password'] - tempStatusPath = self.extraArgs['tempStatusPath'] - sampleData = self.extraArgs['sampleData'] - self.tempStatusPath = tempStatusPath - - FNULL = open(os.devnull, 'w') - - ## Open Status File - - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Setting up paths,0') - statusFile.close() - - finalPath = '' - self.premPath = '' - - try: - website = ChildDomains.objects.get(domain=domainName) - externalApp = website.master.externalApp - self.masterDomain = website.master.domain - - if home == '0': - path = self.extraArgs['path'] - finalPath = website.path.rstrip('/') + "/" + path + "/" - else: - finalPath = website.path + "/" - - if website.master.package.dataBases > website.master.databases_set.all().count(): - pass - else: - raise BaseException( "Maximum database limit reached for this website.") - - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Setting up Database,20') - statusFile.close() - - dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website.master) - self.permPath = website.path - - except: - website = Websites.objects.get(domain=domainName) - externalApp = website.externalApp - self.masterDomain = website.domain - - if home == '0': - path = self.extraArgs['path'] - finalPath = "/home/" + domainName + "/public_html/" + path + "/" - else: - finalPath = "/home/" + domainName + "/public_html/" - - if website.package.dataBases > website.databases_set.all().count(): - pass - else: - raise BaseException( "Maximum database limit reached for this website.") - - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Setting up Database,20') - statusFile.close() - - dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website) - self.permPath = '/home/%s/public_html' % (website.domain) - - ## Security Check - - if finalPath.find("..") > -1: - raise BaseException( "Specified path must be inside virtual host home.") - - command = 'chmod 755 %s' % (self.permPath) - ProcessUtilities.executioner(command) - - if not os.path.exists(finalPath): - command = 'mkdir -p ' + finalPath - ProcessUtilities.executioner(command, externalApp) - - ## checking for directories/files - - if self.dataLossCheck(finalPath, tempStatusPath) == 0: - raise BaseException('Directory not empty.') - - #### - - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Downloading Magento Community Core via composer to document root ..,30') - statusFile.close() - - command = 'composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition %s' % (finalPath) - - ProcessUtilities.executioner(command, externalApp) - - ### - - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Configuring the installation,40') - statusFile.close() - - if home == '0': - path = self.extraArgs['path'] - # finalURL = domainName + '/' + path - finalURL = domainName - else: - finalURL = domainName - - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Installing and configuring Magento..,60') - statusFile.close() - - command = '/usr/local/lsws/lsphp73/bin/php -d memory_limit=512M %sbin/magento setup:install --base-url="http://%s" ' \ - ' --db-host="localhost" --db-name="%s" --db-user="%s" --db-password="%s" --admin-firstname="%s" ' \ - ' --admin-lastname="%s" --admin-email="%s" --admin-user="%s" --admin-password="%s" --language="%s" --timezone="%s" ' \ - ' --use-rewrites=1 --search-engine="elasticsearch7" --elasticsearch-host="localhost" --elasticsearch-port="9200" ' \ - ' --elasticsearch-index-prefix="%s"' \ - % (finalPath, finalURL, dbName, dbUser, dbPassword, firstName, lastName, email, username, password, language, timezone, dbName ) - result = ProcessUtilities.outputExecutioner(command, externalApp) - logging.writeToFile(result) - - ## - - ProcessUtilities.executioner(command, externalApp) - - ## - - from filemanager.filemanager import FileManager - - fm = FileManager(None, None) - fm.fixPermissions(self.masterDomain) - - installUtilities.reStartLiteSpeed() - - statusFile = open(tempStatusPath, 'w') - statusFile.writelines("Successfully Installed. [200]") - statusFile.close() - return 0 - - - except BaseException as msg: - # remove the downloaded files - - homeDir = "/home/" + domainName + "/public_html" - - if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: - groupName = 'nobody' - else: - groupName = 'nogroup' - - if not os.path.exists(homeDir): - command = "chown -R " + externalApp + ":" + groupName + " " + homeDir - ProcessUtilities.executioner(command, externalApp) - - try: - mysqlUtilities.deleteDatabase(dbName, dbUser) - db = Databases.objects.get(dbName=dbName) - db.delete() - except: - pass - - permPath = '/home/%s/public_html' % (domainName) - command = 'chmod 750 %s' % (permPath) - ProcessUtilities.executioner(command) - - statusFile = open(self.tempStatusPath, 'w') - statusFile.writelines(str(msg) + " [404]") - statusFile.close() - return 0 + # def installMagento(self): + # try: + # + # username = self.extraArgs['username'] + # domainName = self.extraArgs['domainName'] + # home = self.extraArgs['home'] + # firstName = self.extraArgs['firstName'] + # lastName = self.extraArgs['lastName'] + # email = self.extraArgs['email'] + # password = self.extraArgs['password'] + # tempStatusPath = self.extraArgs['tempStatusPath'] + # sampleData = self.extraArgs['sampleData'] + # self.tempStatusPath = tempStatusPath + # + # FNULL = open(os.devnull, 'w') + # + # ## Open Status File + # + # statusFile = open(tempStatusPath, 'w') + # statusFile.writelines('Setting up paths,0') + # statusFile.close() + # + # finalPath = '' + # self.premPath = '' + # + # try: + # website = ChildDomains.objects.get(domain=domainName) + # externalApp = website.master.externalApp + # self.masterDomain = website.master.domain + # + # if home == '0': + # path = self.extraArgs['path'] + # finalPath = website.path.rstrip('/') + "/" + path + "/" + # else: + # finalPath = website.path + "/" + # + # if website.master.package.dataBases > website.master.databases_set.all().count(): + # pass + # else: + # raise BaseException( "Maximum database limit reached for this website.") + # + # statusFile = open(tempStatusPath, 'w') + # statusFile.writelines('Setting up Database,20') + # statusFile.close() + # + # dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website.master) + # self.permPath = website.path + # + # except: + # website = Websites.objects.get(domain=domainName) + # externalApp = website.externalApp + # self.masterDomain = website.domain + # + # if home == '0': + # path = self.extraArgs['path'] + # finalPath = "/home/" + domainName + "/public_html/" + path + "/" + # else: + # finalPath = "/home/" + domainName + "/public_html/" + # + # if website.package.dataBases > website.databases_set.all().count(): + # pass + # else: + # raise BaseException( "Maximum database limit reached for this website.") + # + # statusFile = open(tempStatusPath, 'w') + # statusFile.writelines('Setting up Database,20') + # statusFile.close() + # + # dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website) + # self.permPath = '/home/%s/public_html' % (website.domain) + # + # ## Security Check + # + # if finalPath.find("..") > -1: + # raise BaseException( "Specified path must be inside virtual host home.") + # + # command = 'chmod 755 %s' % (self.permPath) + # ProcessUtilities.executioner(command) + # + # if not os.path.exists(finalPath): + # command = 'mkdir -p ' + finalPath + # ProcessUtilities.executioner(command, externalApp) + # + # ## checking for directories/files + # + # if self.dataLossCheck(finalPath, tempStatusPath) == 0: + # raise BaseException('Directory not empty.') + # + # #### + # + # statusFile = open(tempStatusPath, 'w') + # statusFile.writelines('Downloading Magento Community Core via composer to document root ..,30') + # statusFile.close() + # + # command = 'composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition %s' % (finalPath) + # + # ProcessUtilities.executioner(command, externalApp) + # + # ### + # + # statusFile = open(tempStatusPath, 'w') + # statusFile.writelines('Configuring the installation,40') + # statusFile.close() + # + # if home == '0': + # path = self.extraArgs['path'] + # # finalURL = domainName + '/' + path + # finalURL = domainName + # else: + # finalURL = domainName + # + # statusFile = open(tempStatusPath, 'w') + # statusFile.writelines('Installing and configuring Magento..,60') + # statusFile.close() + # + # command = '/usr/local/lsws/lsphp73/bin/php -d memory_limit=512M %sbin/magento setup:install --base-url="http://%s" ' \ + # ' --db-host="localhost" --db-name="%s" --db-user="%s" --db-password="%s" --admin-firstname="%s" ' \ + # ' --admin-lastname="%s" --admin-email="%s" --admin-user="%s" --admin-password="%s" --language="%s" --timezone="%s" ' \ + # ' --use-rewrites=1 --search-engine="elasticsearch7" --elasticsearch-host="localhost" --elasticsearch-port="9200" ' \ + # ' --elasticsearch-index-prefix="%s"' \ + # % (finalPath, finalURL, dbName, dbUser, dbPassword, firstName, lastName, email, username, password, 'language', 'timezone', dbName ) + # + # result = ProcessUtilities.outputExecutioner(command, externalApp) + # logging.writeToFile(result) + # + # ## + # + # ProcessUtilities.executioner(command, externalApp) + # + # ## + # + # from filemanager.filemanager import FileManager + # + # fm = FileManager(None, None) + # fm.fixPermissions(self.masterDomain) + # + # installUtilities.reStartLiteSpeed() + # + # statusFile = open(tempStatusPath, 'w') + # statusFile.writelines("Successfully Installed. [200]") + # statusFile.close() + # return 0 + # + # + # except BaseException as msg: + # # remove the downloaded files + # + # homeDir = "/home/" + domainName + "/public_html" + # + # if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + # groupName = 'nobody' + # else: + # groupName = 'nogroup' + # + # if not os.path.exists(homeDir): + # command = "chown -R " + externalApp + ":" + groupName + " " + homeDir + # ProcessUtilities.executioner(command, externalApp) + # + # try: + # mysqlUtilities.deleteDatabase(dbName, dbUser) + # db = Databases.objects.get(dbName=dbName) + # db.delete() + # except: + # pass + # + # permPath = '/home/%s/public_html' % (domainName) + # command = 'chmod 750 %s' % (permPath) + # ProcessUtilities.executioner(command) + # + # statusFile = open(self.tempStatusPath, 'w') + # statusFile.writelines(str(msg) + " [404]") + # statusFile.close() + # return 0 diff --git a/static/dns/dns.js b/static/dns/dns.js index 516d2f4de..18cc88645 100644 --- a/static/dns/dns.js +++ b/static/dns/dns.js @@ -154,346 +154,434 @@ app.controller('createDNSZone', function ($scope, $http) { app.controller('addModifyDNSRecords', function ($scope, $http) { - $scope.addRecordsBox = true; - $scope.currentRecords = true; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; - $scope.recordDeleted = true; - $scope.couldNotDeleteRecords = true; - $scope.couldNotAddRecord = true; - $scope.recordValueDefault = false; + $scope.addRecordsBox = true; + $scope.currentRecords = true; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = true; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.recordDeleted = true; + $scope.couldNotDeleteRecords = true; + $scope.couldNotAddRecord = true; + $scope.recordValueDefault = false; - // Hide records boxes - $(".aaaaRecord").hide(); - $(".cNameRecord").hide(); - $(".mxRecord").hide(); - $(".txtRecord").hide(); - $(".spfRecord").hide(); - $(".nsRecord").hide(); - $(".soaRecord").hide(); - $(".srvRecord").hide(); - $(".caaRecord").hide(); + // Hide records boxes + $(".aaaaRecord").hide(); + $(".cNameRecord").hide(); + $(".mxRecord").hide(); + $(".txtRecord").hide(); + $(".spfRecord").hide(); + $(".nsRecord").hide(); + $(".soaRecord").hide(); + $(".srvRecord").hide(); + $(".caaRecord").hide(); - var currentSelection = "aRecord"; - $("#" + currentSelection).addClass("active"); - - $scope.fetchRecordsTabs = function (recordType) { - $("#" + currentSelection).removeClass("active"); - $("." + currentSelection).hide(); - $scope.recordsLoading = false; - currentSelection = recordType; + var currentSelection = "aRecord"; $("#" + currentSelection).addClass("active"); - $("." + currentSelection).show(); - populateCurrentRecords(); - }; - - $scope.fetchRecords = function () { - $scope.recordsLoading = false; - $scope.addRecordsBox = false; - populateCurrentRecords(); - }; - - - $scope.addDNSRecord = function (type) { - - $scope.recordsLoading = false; - - - url = "/dns/addDNSRecord"; - - - // Record specific values - - var data = {}; - - if (type === "MX") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentMX = $scope.recordContentMX; - data.priority = $scope.priority; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "A") { - - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentA = $scope.recordContentA; - data.ttl = $scope.ttl; - data.recordType = type; - - } else if (type === "AAAA") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentAAAA = $scope.recordContentAAAA; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "CNAME") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentCNAME = $scope.recordContentCNAME; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "SPF") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentSPF = $scope.recordContentSPF; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "SOA") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.selectedZone; - data.recordContentSOA = $scope.recordContentSOA; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "TXT") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentTXT = $scope.recordContentTXT; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "NS") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.selectedZone; - data.recordContentNS = $scope.recordContentNS; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "SRV") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentSRV = $scope.recordContentSRV; - data.priority = $scope.priority; - data.ttl = $scope.ttl; - data.recordType = type; - } else if (type === "CAA") { - data.selectedZone = $scope.selectedZone; - data.recordName = $scope.recordName; - data.recordContentCAA = $scope.recordContentCAA; - data.ttl = $scope.ttl; - data.recordType = type; - } - - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } + $scope.fetchRecordsTabs = function (recordType) { + $("#" + currentSelection).removeClass("active"); + $("." + currentSelection).hide(); + $scope.recordsLoading = false; + currentSelection = recordType; + $("#" + currentSelection).addClass("active"); + $("." + currentSelection).show(); + populateCurrentRecords(); }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if (response.data.add_status === 1) { - - - populateCurrentRecords(); - - $scope.canNotFetchRecords = true; - $scope.recordsFetched = false; - $scope.recordDeleted = true; - $scope.recordAdded = false; - $scope.couldNotConnect = true; - $scope.couldNotAddRecord = true; - $scope.recordsLoading = true; - - - } else { - - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; - $scope.couldNotAddRecord = false; - - $scope.errorMessage = response.data.error_message; - } - - } - - function cantLoadInitialDatas(response) { - - $scope.addRecordsBox = true; - $scope.currentRecords = true; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = false; - $scope.couldNotAddRecord = true; - - - } - - }; - - - function populateCurrentRecords() { - - var selectedZone = $scope.selectedZone; - - url = "/dns/getCurrentRecordsForDomain"; - - var data = { - selectedZone: selectedZone, - currentSelection: currentSelection - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } + $scope.fetchRecords = function () { + $scope.recordsLoading = false; + $scope.addRecordsBox = false; + populateCurrentRecords(); }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + $scope.addDNSRecord = function (type) { + + $scope.recordsLoading = false; - function ListInitialDatas(response) { - if (response.data.fetchStatus === 1) { + url = "/dns/addDNSRecord"; - $scope.records = JSON.parse(response.data.data); - $scope.currentRecords = false; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = false; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; - $scope.couldNotAddRecord = true; + // Record specific values - $scope.domainFeteched = $scope.selectedZone; + var data = {}; - } else { + if (type === "MX") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentMX = $scope.recordContentMX; + data.priority = $scope.priority; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "A") { + + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentA = $scope.recordContentA; + data.ttl = $scope.ttl; + data.recordType = type; + + } else if (type === "AAAA") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentAAAA = $scope.recordContentAAAA; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "CNAME") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentCNAME = $scope.recordContentCNAME; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "SPF") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentSPF = $scope.recordContentSPF; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "SOA") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.selectedZone; + data.recordContentSOA = $scope.recordContentSOA; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "TXT") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentTXT = $scope.recordContentTXT; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "NS") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.selectedZone; + data.recordContentNS = $scope.recordContentNS; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "SRV") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentSRV = $scope.recordContentSRV; + data.priority = $scope.priority; + data.ttl = $scope.ttl; + data.recordType = type; + } else if (type === "CAA") { + data.selectedZone = $scope.selectedZone; + data.recordName = $scope.recordName; + data.recordContentCAA = $scope.recordContentCAA; + data.ttl = $scope.ttl; + data.recordType = type; + } + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.add_status === 1) { + + + populateCurrentRecords(); + + $scope.canNotFetchRecords = true; + $scope.recordsFetched = false; + $scope.recordDeleted = true; + $scope.recordAdded = false; + $scope.couldNotConnect = true; + $scope.couldNotAddRecord = true; + $scope.recordsLoading = true; + + + } else { + + $scope.recordsFetched = true; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.couldNotAddRecord = false; + + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { $scope.addRecordsBox = true; $scope.currentRecords = true; - $scope.canNotFetchRecords = false; + $scope.canNotFetchRecords = true; $scope.recordsFetched = true; $scope.recordDeleted = true; $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; + $scope.couldNotConnect = false; $scope.couldNotAddRecord = true; - $scope.errorMessage = response.data.error_message; + } - } - - function cantLoadInitialDatas(response) { - - $scope.addRecordsBox = true; - $scope.currentRecords = true; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = false; - $scope.couldNotAddRecord = true; - - - } - - }; - - - $scope.deleteRecord = function (id) { - - - var selectedZone = $scope.selectedZone; - - url = "/dns/deleteDNSRecord"; - - var data = { - id: id, - }; - - var config = { - headers: { - 'X-CSRFToken': getCookie('csrftoken') - } }; - $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + function populateCurrentRecords() { + + var selectedZone = $scope.selectedZone; + + url = "/dns/getCurrentRecordsForDomain"; + + var data = { + selectedZone: selectedZone, + currentSelection: currentSelection + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - function ListInitialDatas(response) { + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - if (response.data.delete_status == 1) { + function ListInitialDatas(response) { + if (response.data.fetchStatus === 1) { + $scope.records = JSON.parse(response.data.data); + + $scope.currentRecords = false; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = false; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.couldNotAddRecord = true; + + $scope.domainFeteched = $scope.selectedZone; + + } else { + + $scope.addRecordsBox = true; + $scope.currentRecords = true; + $scope.canNotFetchRecords = false; + $scope.recordsFetched = true; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.couldNotAddRecord = true; + + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { + + $scope.addRecordsBox = true; + $scope.currentRecords = true; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = true; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = false; + $scope.couldNotAddRecord = true; + + + } + + }; + + var globalID = null; + var nameNow = null; + var ttlNow = null; + var contentNow = null; + var priorityNow = null; + + + $scope.setupContent = function (id, type, content) { + if (globalID === null) { + globalID = id; + } else { + if (globalID !== id) { + globalID = id; + nameNow = null; + ttlNow = null; + contentNow = null; + priorityNow = null; + } + } + + if (type === 'name') { + nameNow = content; + } else if (type === 'ttl') { + ttlNow = content; + } else if (type === 'content') { + contentNow = content; + } else if (type === 'priority') { + priorityNow = content; + } + }; + + $scope.saveNow = function (id) { + + if (id !== globalID) { + alert('This record is not changed'); + return; + } + $scope.recordsLoading = false; + + url = "/dns/updateRecord"; + + var data = { + selectedZone: $scope.selectedZone, + id: globalID, + nameNow: nameNow, + ttlNow: ttlNow, + contentNow: contentNow, + priorityNow: priorityNow, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.recordsLoading = true; + + if (response.data.status === 1) { + + new PNotify({ + title: 'Success!', + text: 'Record updated.', + type: 'success' + }); + + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + } + } + + function cantLoadInitialDatas(response) { + $scope.recordsLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + }; + + $scope.deleteRecord = function (id) { + + var selectedZone = $scope.selectedZone; + + url = "/dns/deleteDNSRecord"; + + var data = { + id: id, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.delete_status == 1) { + + + $scope.addRecordsBox = false; + $scope.currentRecords = false; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = true; + $scope.recordDeleted = false; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.recordDeleted = true; + $scope.couldNotDeleteRecords = true; + $scope.couldNotAddRecord = true; + + populateCurrentRecords(); + + + } else { + + $scope.addRecordsBox = true; + $scope.currentRecords = true; + $scope.canNotFetchRecords = true; + $scope.recordsFetched = false; + $scope.recordDeleted = true; + $scope.recordAdded = true; + $scope.couldNotConnect = true; + $scope.recordsLoading = true; + $scope.recordDeleted = true; + $scope.couldNotDeleteRecords = false; + $scope.couldNotAddRecord = true; + + + $scope.errorMessage = response.data.error_message; + + + } + + } + + function cantLoadInitialDatas(response) { $scope.addRecordsBox = false; $scope.currentRecords = false; $scope.canNotFetchRecords = true; $scope.recordsFetched = true; - $scope.recordDeleted = false; + $scope.recordDeleted = true; $scope.recordAdded = true; - $scope.couldNotConnect = true; + $scope.couldNotConnect = false; $scope.recordsLoading = true; $scope.recordDeleted = true; $scope.couldNotDeleteRecords = true; $scope.couldNotAddRecord = true; - populateCurrentRecords(); - - - } else { - - $scope.addRecordsBox = true; - $scope.currentRecords = true; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = false; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = true; - $scope.recordsLoading = true; - $scope.recordDeleted = true; - $scope.couldNotDeleteRecords = false; - $scope.couldNotAddRecord = true; - - - $scope.errorMessage = response.data.error_message; - } - } - function cantLoadInitialDatas(response) { - - $scope.addRecordsBox = false; - $scope.currentRecords = false; - $scope.canNotFetchRecords = true; - $scope.recordsFetched = true; - $scope.recordDeleted = true; - $scope.recordAdded = true; - $scope.couldNotConnect = false; - $scope.recordsLoading = true; - $scope.recordDeleted = true; - $scope.couldNotDeleteRecords = true; - $scope.couldNotAddRecord = true; + }; - } - - - }; - - -}); + } +); /* Java script code to delete DNS Zone */ @@ -1049,7 +1137,7 @@ app.controller('addModifyDNSRecordsCloudFlare', function ($scope, $http, $window $scope.syncCF = function () { - $scope.recordsLoading = false; + $scope.recordsLoading = false; var selectedZone = $scope.selectedZone; url = "/dns/syncCF";