import subprocess import shlex import argparse import os import tarfile import shutil import time class pluginInstaller: installLogPath = "/home/cyberpanel/modSecInstallLog" tempRulesFile = "/home/cyberpanel/tempModSecRules" mirrorPath = "cyberpanel.net" @staticmethod def stdOut(message): print("\n\n") print ("[" + time.strftime( "%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n") print("[" + time.strftime("%I-%M-%S-%a-%b-%Y") + "] " + message + "\n") print ("[" + time.strftime( "%I-%M-%S-%a-%b-%Y") + "] #########################################################################\n") ### Functions Related to plugin installation. @staticmethod def extractPlugin(pluginName): pathToPlugin = pluginName + '.zip' command = 'unzip ' + pathToPlugin + ' -d /usr/local/CyberCP' subprocess.call(shlex.split(command)) @staticmethod def upgradingSettingsFile(pluginName): data = open("/usr/local/CyberCP/CyberCP/settings.py", 'r').readlines() writeToFile = open("/usr/local/CyberCP/CyberCP/settings.py", 'w') for items in data: if items.find("'emailPremium',") > -1: writeToFile.writelines(items) writeToFile.writelines(" '" + pluginName + "',\n") else: writeToFile.writelines(items) writeToFile.close() @staticmethod def upgradingURLs(pluginName): data = open("/usr/local/CyberCP/CyberCP/urls.py", 'r').readlines() writeToFile = open("/usr/local/CyberCP/CyberCP/urls.py", 'w') print('hello world') for items in data: if items.find("manageservices") > -1: writeToFile.writelines(items) writeToFile.writelines(" url(r'^" + pluginName + "/',include('" + pluginName + ".urls')),\n") print('hello world') else: writeToFile.writelines(items) writeToFile.close() @staticmethod def informCyberPanel(pluginName): pluginPath = '/home/cyberpanel/plugins' if not os.path.exists(pluginPath): os.mkdir(pluginPath) pluginFile = pluginPath + '/' + pluginName command = 'touch ' + pluginFile subprocess.call(shlex.split(command)) @staticmethod def addInterfaceLink(pluginName): data = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'r').readlines() writeToFile = open("/usr/local/CyberCP/baseTemplate/templates/baseTemplate/index.html", 'w') pluginCheck = 0 for items in data: if items.find('{% trans "Plugins" %}') > -1: pluginCheck = 1 elif pluginCheck == 1 and items.find('