2019-02-04 01:03:18 +05:00
|
|
|
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
|
2020-08-19 22:35:46 +05:00
|
|
|
import argparse
|
|
|
|
|
from serverStatus.serverStatusUtil import ServerStatusUtil
|
2019-02-04 01:03:18 +05:00
|
|
|
|
|
|
|
|
class ServiceManager:
|
|
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
slaveConfPath = '/home/cyberpanel/slaveConf'
|
|
|
|
|
|
2019-02-04 01:03:18 +05:00
|
|
|
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():
|
2020-05-23 18:17:55 +05:00
|
|
|
ipsString = ipsString + '%s/32, ' % (items.slaveServerIP)
|
|
|
|
|
ipStringNoSubnet = ipStringNoSubnet + '%s, ' % (items.slaveServerIP)
|
2019-06-26 03:57:16 +05:00
|
|
|
|
2020-05-23 18:17:55 +05:00
|
|
|
ipsString = ipsString.rstrip(', ')
|
|
|
|
|
ipStringNoSubnet = ipStringNoSubnet.rstrip(', ')
|
2019-06-26 03:57:16 +05:00
|
|
|
|
2020-05-23 01:41:06 +05:00
|
|
|
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
|
|
|
|
writeToFile = open(tempPath, 'w')
|
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
|
|
|
|
2020-05-23 01:41:06 +05:00
|
|
|
if items.find('master') > -1:
|
|
|
|
|
continue
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 01:41:06 +05:00
|
|
|
counter = counter + 1
|
2019-02-04 01:03:18 +05:00
|
|
|
|
|
|
|
|
writeToFile.writelines(items + '\n')
|
|
|
|
|
|
2020-05-23 01:41:06 +05:00
|
|
|
|
2019-02-04 01:03:18 +05:00
|
|
|
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:
|
2020-05-23 01:57:30 +05:00
|
|
|
import os
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
if not os.path.exists(ServiceManager.slaveConfPath):
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
writeToFile = open(ServiceManager.slaveConfPath, 'w')
|
|
|
|
|
writeToFile.write('configured')
|
|
|
|
|
writeToFile.close()
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
counter = 0
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
for items in data:
|
|
|
|
|
if items.find('allow-axfr-ips') > -1:
|
|
|
|
|
continue
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
if items.find('also-notify') > -1:
|
|
|
|
|
continue
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
if items.find('daemon=') > -1:
|
|
|
|
|
continue
|
2020-05-23 01:41:06 +05:00
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
if items.find('disable-axfr') > -1:
|
|
|
|
|
continue
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
if items.find('slave') > -1:
|
|
|
|
|
continue
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 01:57:30 +05:00
|
|
|
counter = counter + 1
|
|
|
|
|
|
|
|
|
|
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
|
|
|
|
writeToFile = open(tempPath, 'w')
|
|
|
|
|
|
|
|
|
|
for items in data:
|
|
|
|
|
writeToFile.writelines(items + '\n')
|
|
|
|
|
|
2020-05-23 02:04:02 +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
|
|
|
|
|
"""
|
2020-05-23 01:57:30 +05:00
|
|
|
|
|
|
|
|
writeToFile.writelines(slaveData)
|
|
|
|
|
writeToFile.close()
|
2019-02-04 01:03:18 +05:00
|
|
|
|
2020-05-23 02:04:02 +05:00
|
|
|
command = 'sudo mv ' + tempPath + ' ' + path
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
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()
|
|
|
|
|
|
2020-08-19 22:35:46 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def installElasticSearch():
|
|
|
|
|
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
|
|
|
|
|
"Packages successfully installed.[200]\n", 1)
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='CyberPanel Application Manager')
|
|
|
|
|
parser.add_argument('--function', help='Function')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
args = vars(parser.parse_args())
|
|
|
|
|
|
|
|
|
|
if args["function"] == "InstallElasticSearch":
|
|
|
|
|
ServiceManager.InstallElasticSearch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|
|
|
|
|
|