diff --git a/dns/dnsManager.py b/dns/dnsManager.py index cc7765ace..67cf5f9e9 100644 --- a/dns/dnsManager.py +++ b/dns/dnsManager.py @@ -15,6 +15,7 @@ from models import Domains,Records from re import match,I,M from plogical.mailUtilities import mailUtilities from plogical.acl import ACLManager +from manageServices.models import PDNSStatus class DNSManager: @@ -56,7 +57,16 @@ class DNSManager: secondNSIP = data['secondNSIP'] if Domains.objects.filter(name=domainForNS).count() == 0: - newZone = Domains(admin=admin, name=domainForNS, type="NATIVE") + + try: + pdns = PDNSStatus.objects.get(pk=1) + if pdns.type == 'MASTER': + newZone = Domains(admin=admin, name=domainForNS, type="MASTER") + else: + newZone = Domains(admin=admin, name=domainForNS, type="NATIVE") + except: + newZone = Domains(admin=admin, name=domainForNS, type="NATIVE") + newZone.save() content = "ns1." + domainForNS + " hostmaster." + domainForNS + " 1 10800 3600 604800 3600" diff --git a/dns/models.py b/dns/models.py index 3a9e27305..8db112e90 100644 --- a/dns/models.py +++ b/dns/models.py @@ -1,10 +1,3 @@ -# This is an auto-generated Django model module. -# You'll have to do the following manually to clean this up: -# * Rearrange models' order -# * Make sure each model has one field with primary_key=True -# * Make sure each ForeignKey has `on_delete` set to the desired behavior. -# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table -# Feel free to rename the models, but don't rename db_table values or field names. from __future__ import unicode_literals from django.db import models @@ -91,10 +84,3 @@ class Tsigkeys(models.Model): class Meta: db_table = 'tsigkeys' unique_together = (('name', 'algorithm'),) - - - -class DNSMaster: - type = models.CharField(max_length=5, default='NATIVE') - allow_axfr_ips = models.CharField(max_length=500, default='') - also_notify = models.CharField(max_length=500, default='') diff --git a/dockerManager/decorators.py b/dockerManager/decorators.py index 0b128d144..bd06190c7 100644 --- a/dockerManager/decorators.py +++ b/dockerManager/decorators.py @@ -11,11 +11,11 @@ from plogical.acl import ACLManager def preDockerRun(function): def wrap(request, *args, **kwargs): - try: - userID = request.session['userID'] + try: + userID = request.session['userID'] except KeyError: return redirect(loadLoginPage) - + currentACL = ACLManager.loadedACL(userID) if request.method == "POST": @@ -49,4 +49,4 @@ def preDockerRun(function): return function(request, *args, **kwargs) - return wrap + return wrap \ No newline at end of file diff --git a/manageServices/models.py b/manageServices/models.py index 1dfab7604..d0e84cea8 100644 --- a/manageServices/models.py +++ b/manageServices/models.py @@ -4,3 +4,9 @@ from __future__ import unicode_literals from django.db import models # Create your models here. + +class PDNSStatus(models.Model): + serverStatus = models.IntegerField(default=1) + type = models.CharField(max_length=6, default='NATIVE') + allow_axfr_ips = models.CharField(max_length=500, default='') + also_notify = models.CharField(max_length=500, default='') \ No newline at end of file diff --git a/manageServices/serviceManager.py b/manageServices/serviceManager.py new file mode 100644 index 000000000..79e8db8eb --- /dev/null +++ b/manageServices/serviceManager.py @@ -0,0 +1,87 @@ +import subprocess, shlex +from random import randint +from plogical.processUtilities import ProcessUtilities + +class ServiceManager: + + def __init__(self, extraArgs): + self.extraArgs = extraArgs + + + def managePDNS(self): + type = self.extraArgs['type'] + path = '/etc/pdns/pdns.conf' + + data = subprocess.check_output(shlex.split('sudo cat ' + path)).splitlines() + + if type == 'MASTER': + counter = 0 + + slaveIPData = self.extraArgs['slaveIPData'] + ipsString = slaveIPData.replace(',', '/32,') + + + for items in data: + if items.find('allow-axfr-ips') > -1: + data[counter] = '#' + data[counter] + + if items.find('also-notify') > -1: + data[counter] = '#' + data[counter] + + if items.find('daemon=') > -1: + data[counter] = '#' + data[counter] + + if items.find('disable-axfr') > -1: + data[counter] = '#' + data[counter] + + if items.find('slave') > -1: + data[counter] = '#' + data[counter] + + counter = counter + 1 + + tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + writeToFile = open(tempPath, 'w') + + for items in data: + writeToFile.writelines(items + '\n') + + writeToFile.writelines('allow-axfr-ips=' + ipsString + '\n') + writeToFile.writelines('also-notify=' + slaveIPData + '\n') + writeToFile.writelines('daemon=no\n') + writeToFile.writelines('disable-axfr=no\n') + writeToFile.writelines('master=yes\n') + writeToFile.close() + else: + counter = 0 + + for items in data: + if items.find('allow-axfr-ips') > -1: + data[counter] = '#' + data[counter] + + if items.find('also-notify') > -1: + data[counter] = '#' + data[counter] + + if items.find('daemon=') > -1: + data[counter] = '#' + data[counter] + + if items.find('disable-axfr') > -1: + data[counter] = '#' + data[counter] + + if items.find('slave') > -1: + data[counter] = '#' + data[counter] + + counter = counter + 1 + + tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + writeToFile = open(tempPath, 'w') + + for items in data: + writeToFile.writelines(items + '\n') + + writeToFile.writelines('slave=yes\n') + writeToFile.writelines('daemon=no\n') + writeToFile.close() + + command = 'sudo mv ' + tempPath + ' ' + path + ProcessUtilities.executioner(command) + diff --git a/manageServices/static/manageServices/manageServices.js b/manageServices/static/manageServices/manageServices.js index 4cbee2c59..ca700620a 100644 --- a/manageServices/static/manageServices/manageServices.js +++ b/manageServices/static/manageServices/manageServices.js @@ -5,128 +5,148 @@ /* Java script code */ -app.controller('powerDNS', function($scope, $http, $timeout, $window) { +app.controller('powerDNS', function ($scope, $http, $timeout, $window) { - $scope.pdnsLoading = true; - $scope.failedToFetch = true; - $scope.couldNotConnect = true; - $scope.changesApplied = true; + $scope.pdnsLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + $scope.slaveIPs = true; - var pdnsStatus = false; + var pdnsStatus = false; - $('#pdnsStatus').change(function() { - pdnsStatus = $(this).prop('checked'); - }); + $('#pdnsStatus').change(function () { + pdnsStatus = $(this).prop('checked'); + }); - fetchPDNSStatus('powerdns'); - function fetchPDNSStatus(service){ + fetchPDNSStatus('powerdns'); + function fetchPDNSStatus(service) { - $scope.pdnsLoading = false; + $scope.pdnsLoading = false; - $('#pdnsStatus').bootstrapToggle('off'); + $('#pdnsStatus').bootstrapToggle('off'); - url = "/manageservices/fetchStatus"; + url = "/manageservices/fetchStatus"; - var data = { - 'service' : service - }; + var data = { + 'service': service + }; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - $scope.pdnsLoading = true; + $scope.pdnsLoading = true; - if(response.data.status === 1){ + if (response.data.status === 1) { - if (response.data.installCheck === 1) { - $('#pdnsStatus').bootstrapToggle('on'); - } - - }else{ - $scope.failedToFetch = false; - $scope.couldNotConnect = true; - $scope.changesApplied = true; - - $scope.errorMessage = response.data.error_message; - - } - - } - function cantLoadInitialDatas(response) { - $scope.pdnsLoading = true; - $scope.failedToFetch = true; - $scope.couldNotConnect = false; - $scope.changesApplied = true; + if (response.data.installCheck === 1) { + $('#pdnsStatus').bootstrapToggle('on'); } - } + $scope.slaveIPData = response.data.slaveIPData; + + } else { + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + $scope.errorMessage = response.data.error_message; + + } + + } + + function cantLoadInitialDatas(response) { + $scope.pdnsLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + } + + $scope.saveStatus = function (service) { + + $scope.pdnsLoading = false; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; - $scope.saveStatus = function (service) { + url = "/manageservices/saveStatus"; - $scope.pdnsLoading = false; - $scope.failedToFetch = true; - $scope.couldNotConnect = true; - $scope.changesApplied = true; + if (service === 'powerdns') { + var data = { + status: pdnsStatus, + service: service, + dnsMode: $scope.dnsMode, + slaveIPData: $scope.slaveIPData + }; + }else { + var data = { + status: pdnsStatus, + service: service + }; + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - - url = "/manageservices/saveStatus"; - - var data = { - status:pdnsStatus, - service: service - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + function ListInitialDatas(response) { + $scope.pdnsLoading = true; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + if (response.data.status === 1) { + + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = false; + + } + else { + $scope.errorMessage = response.data.error_message; + + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + } + + } + + function cantLoadInitialDatas(response) { + $scope.policyServerLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } - function ListInitialDatas(response) { - $scope.pdnsLoading = true; + }; - if(response.data.status === 1){ + $scope.modeChange = function () { + if ($scope.dnsMode === 'MASTER') { + $scope.slaveIPs = false; - $scope.failedToFetch = true; - $scope.couldNotConnect = true; - $scope.changesApplied = false; - - } - else{ - $scope.errorMessage = response.data.error_message; - - $scope.failedToFetch = false; - $scope.couldNotConnect = true; - $scope.changesApplied = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.policyServerLoading = true; - $scope.failedToFetch = true; - $scope.couldNotConnect = false; - $scope.changesApplied = true; - } - - - }; + } else { + $scope.slaveIPs = true; + } + } }); @@ -137,129 +157,129 @@ app.controller('powerDNS', function($scope, $http, $timeout, $window) { /* Java script code */ -app.controller('postfix', function($scope, $http, $timeout, $window) { +app.controller('postfix', function ($scope, $http, $timeout, $window) { - $scope.serviceLoading = true; - $scope.failedToFetch = true; - $scope.couldNotConnect = true; - $scope.changesApplied = true; + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; - var serviceStatus = false; + var serviceStatus = false; - $('#serviceStatus').change(function() { - serviceStatus = $(this).prop('checked'); - }); + $('#serviceStatus').change(function () { + serviceStatus = $(this).prop('checked'); + }); - fetchPDNSStatus('postfix'); - function fetchPDNSStatus(service){ + fetchPDNSStatus('postfix'); + function fetchPDNSStatus(service) { - $scope.serviceLoading = false; + $scope.serviceLoading = false; - $('#serviceStatus').bootstrapToggle('off'); + $('#serviceStatus').bootstrapToggle('off'); - url = "/manageservices/fetchStatus"; + url = "/manageservices/fetchStatus"; - var data = { - 'service' : service - }; + var data = { + 'service': service + }; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - $scope.serviceLoading = true; + $scope.serviceLoading = true; - if(response.data.status === 1){ + if (response.data.status === 1) { - if (response.data.installCheck === 1) { - $('#serviceStatus').bootstrapToggle('on'); - } - - }else{ - $scope.failedToFetch = false; - $scope.couldNotConnect = true; - $scope.changesApplied = true; - - $scope.errorMessage = response.data.error_message; - - } - - } - function cantLoadInitialDatas(response) { - $scope.serviceLoading = true; - $scope.failedToFetch = true; - $scope.couldNotConnect = false; - $scope.changesApplied = true; + if (response.data.installCheck === 1) { + $('#serviceStatus').bootstrapToggle('on'); } - } + } else { + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + $scope.errorMessage = response.data.error_message; + + } + + } + + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + } - $scope.saveStatus = function (service) { + $scope.saveStatus = function (service) { - $scope.serviceLoading = false; - $scope.failedToFetch = true; - $scope.couldNotConnect = true; - $scope.changesApplied = true; + $scope.serviceLoading = false; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + url = "/manageservices/saveStatus"; - url = "/manageservices/saveStatus"; + var data = { + status: serviceStatus, + service: service + }; - var data = { - status:serviceStatus, - service: service - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { - $scope.serviceLoading = true; + function ListInitialDatas(response) { + $scope.serviceLoading = true; - if(response.data.status === 1){ + if (response.data.status === 1) { - $scope.failedToFetch = true; - $scope.couldNotConnect = true; - $scope.changesApplied = false; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = false; - } - else{ - $scope.errorMessage = response.data.error_message; + } + else { + $scope.errorMessage = response.data.error_message; - $scope.failedToFetch = false; - $scope.couldNotConnect = true; - $scope.changesApplied = true; - } + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + } - } - function cantLoadInitialDatas(response) { - $scope.serviceLoading = true; - $scope.failedToFetch = true; - $scope.couldNotConnect = false; - $scope.changesApplied = true; - } + } + + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } - }; + }; }); @@ -268,129 +288,129 @@ app.controller('postfix', function($scope, $http, $timeout, $window) { /* Java script code */ -app.controller('pureFTPD', function($scope, $http, $timeout, $window) { +app.controller('pureFTPD', function ($scope, $http, $timeout, $window) { - $scope.serviceLoading = true; - $scope.failedToFetch = true; - $scope.couldNotConnect = true; - $scope.changesApplied = true; + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; - var serviceStatus = false; + var serviceStatus = false; - $('#serviceStatus').change(function() { - serviceStatus = $(this).prop('checked'); - }); + $('#serviceStatus').change(function () { + serviceStatus = $(this).prop('checked'); + }); - fetchPDNSStatus('pureftpd'); - function fetchPDNSStatus(service){ + fetchPDNSStatus('pureftpd'); + function fetchPDNSStatus(service) { - $scope.serviceLoading = false; + $scope.serviceLoading = false; - $('#serviceStatus').bootstrapToggle('off'); + $('#serviceStatus').bootstrapToggle('off'); - url = "/manageservices/fetchStatus"; + url = "/manageservices/fetchStatus"; - var data = { - 'service' : service - }; + var data = { + 'service': service + }; - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { + function ListInitialDatas(response) { - $scope.serviceLoading = true; + $scope.serviceLoading = true; - if(response.data.status === 1){ + if (response.data.status === 1) { - if (response.data.installCheck === 1) { - $('#serviceStatus').bootstrapToggle('on'); - } - - }else{ - $scope.failedToFetch = false; - $scope.couldNotConnect = true; - $scope.changesApplied = true; - - $scope.errorMessage = response.data.error_message; - - } - - } - function cantLoadInitialDatas(response) { - $scope.serviceLoading = true; - $scope.failedToFetch = true; - $scope.couldNotConnect = false; - $scope.changesApplied = true; + if (response.data.installCheck === 1) { + $('#serviceStatus').bootstrapToggle('on'); } - } + } else { + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + $scope.errorMessage = response.data.error_message; + + } + + } + + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + } - $scope.saveStatus = function (service) { + $scope.saveStatus = function (service) { - $scope.serviceLoading = false; - $scope.failedToFetch = true; - $scope.couldNotConnect = true; - $scope.changesApplied = true; + $scope.serviceLoading = false; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + url = "/manageservices/saveStatus"; - url = "/manageservices/saveStatus"; + var data = { + status: serviceStatus, + service: service + }; - var data = { - status:serviceStatus, - service: service - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); - function ListInitialDatas(response) { - $scope.serviceLoading = true; + function ListInitialDatas(response) { + $scope.serviceLoading = true; - if(response.data.status === 1){ + if (response.data.status === 1) { - $scope.failedToFetch = true; - $scope.couldNotConnect = true; - $scope.changesApplied = false; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = false; - } - else{ - $scope.errorMessage = response.data.error_message; + } + else { + $scope.errorMessage = response.data.error_message; - $scope.failedToFetch = false; - $scope.couldNotConnect = true; - $scope.changesApplied = true; - } + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + } - } - function cantLoadInitialDatas(response) { - $scope.serviceLoading = true; - $scope.failedToFetch = true; - $scope.couldNotConnect = false; - $scope.changesApplied = true; - } + } + + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } - }; + }; }); diff --git a/manageServices/templates/manageServices/managePowerDNS.html b/manageServices/templates/manageServices/managePowerDNS.html index 50b0569f2..ca0b14ca5 100644 --- a/manageServices/templates/manageServices/managePowerDNS.html +++ b/manageServices/templates/manageServices/managePowerDNS.html @@ -3,86 +3,107 @@ {% block title %}{% trans "Manage PowerDNS - CyberPanel" %}{% endblock %} {% block content %} -{% load static %} -{% get_current_language as LANGUAGE_CODE %} - + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + -
{% trans "Enable or disable DNS services. " %}
-{% trans "Enable or disable DNS services. " %}
+
-
+ {% trans "Only administrator can manage services." %}
+{% trans "Only administrator can manage services." %}
-