D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
imh-python
/
lib
/
python2.7
/
site-packages
/
cmu_ded
/
Libs
/
Filename :
NSetup.py
back
Copy
""" This file controls how we are moving custom name servers. """ import os import common import subprocess class NSetup(common.Migration): """ Requires the VPS to be on. Should be ran as the following: NSetup() NSetup.rootdir1 = "xxxx" NSetup.rootdir2 = "xxxx" main() check_nameservers() install_nameservers() """ def __init__(self, logger=None): super(NSetup, self).__init__(logger=logger) self.name_servers = [] self.errors = [] def main(self): """ Main function for everything. :return: Returns True if everything is good. """ return self.check_nameservers() and \ self.install_nameservers() def check_nameservers(self): """ Checking if we need to move the name servers here. Goes through chkservd.conf and looks for named :return: """ self.debug("Entering check_nameservers") result = self.remote_cmd_exec('cat /etc/chkserv.d/chkservd.conf') for line in result.split('\n'): if 'named' in line and '1' in line: self.info("Found Custom Nameservers") return True self.info("Custom NameServers not found.") return False def install_nameservers(self): """ Installs the name servers. Should be ran after check_nameservers. Since check_nameservers is set we can continue. :return: """ self.debug("Entering install_nameservers") result = self.remote_cmd_exec('cat /etc/wwwacct.conf') for line in result.split('\n'): if 'NS' in line and "." in line: self.name_servers.append(line) for ns in range(len(self.name_servers)): if ns != 0: pattern = "NS%s" % str(ns + 1) common.file_replace_line(self.rootdir2 + '/etc/wwwacct.conf', pattern, pattern + " " + self.name_servers[ns] + "\n") else: pattern = "NS " common.file_replace_line(self.rootdir2 + '/etc/wwwacct.conf', pattern, pattern + self.name_servers[ns] + "\n") # Should be in a decorator. result = self.local_cmd_exec('/scripts/setupnameserver bind') self.debug(result) common.file_replace_line(self.rootdir2 + '/etc/chkserv.d/chkservd.conf', 'named:0', 'named:1\n') result = self.local_cmd_exec('/sbin/service cpanel restart') self.debug(result) self.info("Setup Bind!") return True def __str__(self): return "\n".join(self.errors) def __repr__(self): return "<NSetup: errors=%r : name_servers=%r>" % (self.errors, self.name_servers)