Files
CyberPanel/manageServices/serviceManager.py

118 lines
3.3 KiB
Python
Raw Normal View History

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()
2019-12-15 13:30:40 +05:00
#data = subprocess.check_output(shlex.split('sudo cat ' + path)).decode("utf-8").splitlines()
2019-06-26 03:57:16 +05:00
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:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
if items.find('also-notify') > -1:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
if items.find('daemon=') > -1:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
if items.find('disable-axfr') > -1:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
if items.find('slave') > -1:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
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:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
if items.find('also-notify') > -1:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
if items.find('daemon=') > -1:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
if items.find('disable-axfr') > -1:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
if items.find('slave') > -1:
2019-06-27 13:07:47 +05:00
continue
2019-02-04 01:03:18 +05:00
counter = counter + 1
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempPath, 'w')
for items in data:
writeToFile.writelines(items + '\n')
2019-06-27 13:07:47 +05:00
slaveData = """slave=yes
daemon=yes
disable-axfr=yes
guardian=yes
local-address=0.0.0.0
local-port=53
master=no
slave-cycle-interval=60
setgid=pdns
setuid=pdns
superslave=yes
"""
writeToFile.writelines(slaveData)
2019-02-04 01:03:18 +05:00
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)