D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
imh-python
/
lib
/
python2.7
/
site-packages
/
cmu_ded
/
Libs
/
Filename :
WHMPluginTransfer.py
back
Copy
import os import common class WHMPluginTransfer(common.Migration): plugins = [] errors = [] # Worrying about things being up to date # Doing a special list of things that should be moved ( If they exist ) # DNSAdmin should be installed. # GoogleMX is installed by default at this time. special_modules = { 'softaculous.conf': [ 'softaculous-imh' ], 'csf.conf': [ 'csf-ded.noarch' '/etc/csf/' ], 'imhapf.conf': [ 'apf-ded.noarch', '/etc/apf/' ], 'clamavconnector.conf': [ 'httpupdate.cpanel.net/cpanelsync/addons/modules/clamavconnector-Linux-x86_64.tar.bz2' ] } def __init__(self, logger): super(WHMPluginTransfer, self).__init__(logger) # Entry point. def main(self): """ Entry Point. :return: True or false. """ return self.set_plugins() and \ self.todo() and \ self.install_modules() and \ self.move_supporting_files() def set_plugins(self): """ Finding out what plug-ins are installed. :return: Sets plugins=[] """ self.debug("Entering set_plugins.") result = self.remote_cmd_exec('ls /var/cpanel/apps') if "No such file or directory" in result: self.errors.append("Can't open /var/cpanel/apps") self.error("Can't open /var/cpanel/apps") return False else: self.plugins = result.split('\n') return True def todo(self): """ Figures out what is needed. Basically removes keys from special_modules :return: Modified version of special_modules. """ self.debug("Entering todo.") for key in self.special_modules.keys(): if key not in self.plugins: # If key error, then the file doesn't exist. self.special_modules.pop(key) return True def install_modules(self): """ Goes through and installs the modules left in special modules. :return: """ self.debug("Entering install_modules.") for mod in self.special_modules.keys(): if mod == 'clamavconnector.conf': self.clamav_install() continue self.general_install(self.special_modules[mod][0]) return True def move_supporting_files(self): """ Goes through and skips the first item in the dictionary list, which contains supporting directories. For instance, APF needs /etc/apf. :return: """ self.debug("Entering move_supporting_files.") for mod in self.special_modules.keys(): if not len(self.special_modules[mod]) < 2: continue for file in self.special_modules[mod][1:]: self.move_file(file) return True # Supporting Functions: def general_install(self, package): """ General install script. Anything different needs to be specified. :return: """ self.debug("Entering general install for %s." % package) self.local_cmd_exec('yum install -y %s' % package) def clamav_install(self): """ ClamAV has a special way of installing everything. Refer to: http://wiki.inmotionhosting.com/index.php?title=ClamAV Looks outdated, doing /scripts/update_local_rpm_versions --edit target_settings.clamav installed /scripts/check_cpanel_rpms --fix :return: """ self.debug("Entering clamav_install.") self.local_cmd_exec( "curl -s httpupdate.cpanel.net/cpanelsync/addons/modules/clamavconnector-Linux-x86_64.tar.bz2 | tar -xvj -C /usr/src" ) self.local_cmd_exec("cd /usr/src/clamavconnector-*/ ; ./install") self.local_cmd_exec("echo 'clamavconnector' >> /var/cpanel/addonmodules") self.local_cmd_exec( "echo -n `/usr/bin/clamscan -V | awk '{print $2}' | cut -d/ -f1` > /var/cpanel/addonmoduleversions/clamavconnector" ) self.local_cmd_exec("/scripts/update_local_rpm_versions --edit target_settings.clamav installed") self.local_cmd_exec("/scripts/check_cpanel_rpms --fix") self.local_cmd_exec("yum install maldet-imh -y") def __str__(self): return "\n".join(self.errors) def __repr__(self): return "<WHMPLuginTransfer: errors=%r : plugins=%r>" % (self.errors, self.plugins)