forked from usmannasir/cyberpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceManager.py
executable file
·117 lines (82 loc) · 3.27 KB
/
serviceManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import subprocess, shlex
from random import randint
from plogical.processUtilities import ProcessUtilities
from dns.models import Supermasters
from manageServices.models import SlaveServers
class ServiceManager:
def __init__(self, extraArgs):
self.extraArgs = extraArgs
def managePDNS(self):
type = self.extraArgs['type']
path = '/etc/pdns/pdns.conf'
data = ProcessUtilities.outputExecutioner('sudo cat ' + path).splitlines()
#data = subprocess.check_output(shlex.split('sudo cat ' + path)).splitlines()
if type == 'MASTER':
counter = 0
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(' ')
for items in data:
if items.find('allow-axfr-ips') > -1:
continue
if items.find('also-notify') > -1:
continue
if items.find('daemon=') > -1:
continue
if items.find('disable-axfr') > -1:
continue
if items.find('slave') > -1:
continue
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=' + ipStringNoSubnet + '\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:
continue
if items.find('also-notify') > -1:
continue
if items.find('daemon=') > -1:
continue
if items.find('disable-axfr') > -1:
continue
if items.find('slave') > -1:
continue
counter = counter + 1
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
writeToFile = open(tempPath, 'w')
for items in data:
writeToFile.writelines(items + '\n')
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)
writeToFile.close()
for items in Supermasters.objects.all():
items.delete()
Supermasters(ip=self.extraArgs['masterServerIP'], nameserver=self.extraArgs['slaveServerNS'], account='').save()
command = 'sudo mv ' + tempPath + ' ' + path
#subprocess.call(shlex.split(command))
ProcessUtilities.executioner(command)