2019-02-04 01:03:18 +05:00
|
|
|
import subprocess, shlex
|
|
|
|
|
from random import randint
|
|
|
|
|
from plogical.processUtilities import ProcessUtilities
|
2019-06-26 03:57:16 +05:00
|
|
|
from dns.models import Supermasters
|
|
|
|
|
from manageServices.models import SlaveServers
|
2019-02-04 01:03:18 +05:00
|
|
|
|
|
|
|
|
class ServiceManager:
|
|
|
|
|
|
|
|
|
|
def __init__(self, extraArgs):
|
|
|
|
|
self.extraArgs = extraArgs
|
|
|
|
|
|
|
|
|
|
def managePDNS(self):
|
|
|
|
|
type = self.extraArgs['type']
|
|
|
|
|
path = '/etc/pdns/pdns.conf'
|
|
|
|
|
|
2019-06-26 03:57:16 +05:00
|
|
|
data = ProcessUtilities.outputExecutioner('sudo cat ' + path).splitlines()
|
|
|
|
|
#data = subprocess.check_output(shlex.split('sudo cat ' + path)).splitlines()
|
|
|
|
|
|
2019-02-04 01:03:18 +05:00
|
|
|
|
|
|
|
|
if type == 'MASTER':
|
|
|
|
|
counter = 0
|
|
|
|
|
|
2019-06-26 03:57:16 +05:00
|
|
|
ipsString = ''
|
|
|
|
|
ipStringNoSubnet = ''
|
|
|
|
|
|
|
|
|
|
for items in SlaveServers.objects.all():
|
|
|
|
|
ipsString = ipsString + '%s/32 ' % (items.slaveServerIP)
|
|
|
|
|
ipStringNoSubnet = ipStringNoSubnet + '%s ' % (items.slaveServerIP)
|
|
|
|
|
|
|
|
|
|
ipsString = ipsString.rstrip(' ')
|
|
|
|
|
ipStringNoSubnet = ipStringNoSubnet.rstrip(' ')
|
|
|
|
|
|
|
|
|
|
|
2019-02-04 01:03:18 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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')
|
2019-06-26 03:57:16 +05:00
|
|
|
writeToFile.writelines('also-notify=' + ipStringNoSubnet + '\n')
|
2019-02-04 01:03:18 +05:00
|
|
|
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()
|
|
|
|
|
|
2019-06-26 03:57:16 +05:00
|
|
|
for items in Supermasters.objects.all():
|
|
|
|
|
items.delete()
|
|
|
|
|
|
|
|
|
|
Supermasters(ip=self.extraArgs['masterServerIP'], nameserver=self.extraArgs['slaveServerNS'], account='').save()
|
|
|
|
|
|
2019-02-04 01:03:18 +05:00
|
|
|
command = 'sudo mv ' + tempPath + ' ' + path
|
2019-06-26 03:57:16 +05:00
|
|
|
#subprocess.call(shlex.split(command))
|
2019-02-04 01:03:18 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|