def loadModule(self, type, dirpath, filename): module_str = "" mod_name = filename.split('.')[0] mod_dispname = '/'.join(re.split('/modules/' + type + "/", dirpath)[-1].split('/') + [mod_name]) mod_loadname = mod_dispname.replace('/', '_') mod_loadpath = os.path.join(dirpath, filename) mod_file = open(mod_loadpath) try: # import the module into memory imp.load_source(mod_loadname, mod_loadpath, mod_file) # find the module and make an instace of it _module = __import__(mod_loadname) _class = getattr(_module, mod_name) _instance = _class(self.config, self.display, self.modulelock) valid = True for r in _instance.getRequirements(): if (not r in self.config): path = Utils.validateExecutable(r) if (path): self.config[r] = path else: valid = False if (valid): module_str = "%s %s [TYPE = %s] [VALID = TRUE ]" % ( mod_name.ljust(25), _instance.getTitle().ljust(40), type.ljust(6)) else: module_str = "%s %s [TYPE = %s] [VALID = FALSE]" % ( mod_name.ljust(25), _instance.getTitle().ljust(40), type.ljust(6)) # add the module to the framework's loaded modules if (valid): if (type == "action"): if (self.config["safe_level"] > _instance.getSafeLevel()): self.display.error( 'Module \'%s\' disabled. Safety_level (%i) is below specified requirement (%i)' % ( mod_name, _instance.getSafeLevel(), self.config["safe_level"])) else: self.actionModules[mod_dispname] = _instance for t in _instance.getTriggers(): EventHandler.add(_instance, t) elif (type == "input"): self.inputModules[mod_dispname] = _instance else: self.display.error( 'Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, _instance.getRequirements())) except ImportError as e: # notify the user of missing dependencies self.display.error('Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, e)) except Exception as e: # notify the user of errors print e self.display.error('Module \'%s\' disabled.' % (mod_name)) return module_str
def loadModule(self, type, dirpath, filename): module_dict = {} mod_name = filename.split('.')[0] mod_dispname = '/'.join( re.split('/modules/' + type + "/", dirpath)[-1].split('/') + [mod_name]) mod_loadname = mod_dispname.replace('/', '_') mod_loadpath = os.path.join(dirpath, filename) mod_file = open(mod_loadpath) try: # import the module into memory imp.load_source(mod_loadname, mod_loadpath, mod_file) # find the module and make an instace of it _module = __import__(mod_loadname) _class = getattr(_module, mod_name) _instance = _class(self.config, self.display, self.modulelock) valid = True for r in _instance.getRequirements(): if not r in self.config: path = Utils.validateExecutable(r) if path: self.config[r] = path else: valid = False if valid: module_dict = { 'name': mod_name.ljust(25), 'description': _instance.getTitle().ljust(40), 'type': type.ljust(6), 'valid': True } else: module_dict = { 'name': mod_name.ljust(25), 'description': _instance.getTitle().ljust(40), 'type': type.ljust(6), 'valid': False } if type == 'action': module_dict['safelevel'] = _instance.getSafeLevel() else: module_dict['safelevel'] = None # add the module to the framework's loaded modules if valid: if type == "action": if self.config["safe_level"] > _instance.getSafeLevel(): self.display.error( 'Module \'%s\' disabled. Safety_level (%i) is below specified requirement (%i)' % (mod_name, _instance.getSafeLevel(), self.config["safe_level"])) elif self.checkExcludeTypes(_instance.getTypes()) == True: self.display.error( 'Module \'%s\' disabled. One or more of the following module types were excluded %s' % (mod_name, _instance.getTypes())) else: self.actionModules[mod_dispname] = _instance for t in _instance.getTriggers(): EventHandler.add(_instance, t) elif type == "input": self.inputModules[mod_dispname] = _instance elif type == "report": self.reportModules[mod_dispname] = _instance else: self.display.error( 'Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, _instance.getRequirements())) except ImportError as e: # notify the user of missing dependencies self.display.error( 'Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, e)) return None except Exception as e: # notify the user of errors print e self.display.error('Module \'%s\' disabled.' % (mod_name)) return None return module_dict
def loadModule(self, type, dirpath, filename): module_dict = {} # remove the beginning string of the dirpath basepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) dirpath_orig = dirpath dirpath = dirpath[len(basepath)+1:] mod_name = filename.split('.')[0] mod_dispname = '/'.join(re.split('/modules/' + type + "/", dirpath)[-1].split('/') + [mod_name]) mod_loadname = mod_dispname.replace('/', '_') mod_loadpath = os.path.join(dirpath_orig, filename) mod_file = open(mod_loadpath) try: # import the module into memory imp.load_source(mod_loadname, mod_loadpath, mod_file) # find the module and make an instace of it _module = __import__(mod_loadname) _class = getattr(_module, mod_name) _instance = _class(self.config, self.display, self.modulelock) reasons = [] valid = True for r in _instance.getRequirements(): if r == 'disable': reasons.append("Module Manually Disabled !!!") elif r == 'APIKEY': key_name = mod_name + "_apikey" if not key_name in self.config: reasons.append("API key is missing") valid = False elif not r in self.config: path = Utils.validateExecutable(r) if path: self.config[r] = path else: reasons.append("Requirement not met: %s" % r) valid = False if valid: module_dict = {'name': mod_name.ljust(25), 'description': _instance.getTitle().ljust(40), 'type': type.ljust(6), 'valid': True} else: module_dict = {'name': mod_name.ljust(25), 'description': _instance.getTitle().ljust(40), 'type': type.ljust(6), 'valid': False} if type == 'action': module_dict['safelevel'] = _instance.getSafeLevel() else: module_dict['safelevel'] = None # add the module to the framework's loaded modules if valid: if type == "action": if self.config["safe_level"] > _instance.getSafeLevel(): reasons.append("Safety_Level (%i) is below requirement: %i" % (_instance.getSafeLevel(), self.config["safe_level"])) #self.display.error( # 'Module \'%s\' disabled. Safety_level (%i) is below specified requirement (%i)' % ( # mod_name, _instance.getSafeLevel(), self.config["safe_level"])) elif self.checkExcludeTypes(_instance.getTypes()) == True: True #self.display.error( # 'Module \'%s\' disabled. One or more of the following module types were excluded %s' % ( # mod_name, _instance.getTypes())) else: self.actionModules[mod_dispname] = _instance for t in _instance.getTriggers(): EventHandler.add(_instance, t) elif type == "input": self.inputModules[mod_dispname] = _instance elif type == "report": self.reportModules[mod_dispname] = _instance #else: # self.display.error( # 'Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, _instance.getRequirements())) if reasons: self.display.error('Module \'%s\' disabled:' % mod_name) for r in reasons: self.display.error(' ' + r) except ImportError as e: # notify the user of missing dependencies self.display.error('Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, e)) return None except Exception as e: # notify the user of errors print e self.display.error('Module \'%s\' disabled.' % (mod_name)) return None return module_dict
def loadModule(self, type, dirpath, filename): module_str = "" mod_name = filename.split('.')[0] mod_dispname = '/'.join( re.split('/modules/' + type + "/", dirpath)[-1].split('/') + [mod_name]) mod_loadname = mod_dispname.replace('/', '_') mod_loadpath = os.path.join(dirpath, filename) mod_file = open(mod_loadpath) try: # import the module into memory imp.load_source(mod_loadname, mod_loadpath, mod_file) # find the module and make an instace of it _module = __import__(mod_loadname) _class = getattr(_module, mod_name) _instance = _class(self.config, self.display, self.modulelock) valid = True for r in _instance.getRequirements(): if (not r in self.config): path = Utils.validateExecutable(r) if (path): self.config[r] = path else: valid = False if (valid): module_str = "%s %s [TYPE = %s] [VALID = TRUE ]" % ( mod_name.ljust(25), _instance.getTitle().ljust(40), type.ljust(6)) else: module_str = "%s %s [TYPE = %s] [VALID = FALSE]" % ( mod_name.ljust(25), _instance.getTitle().ljust(40), type.ljust(6)) # add the module to the framework's loaded modules if (valid): if (type == "action"): if (self.config["safe_level"] > _instance.getSafeLevel()): self.display.error( 'Module \'%s\' disabled. Safety_level (%i) is below specified requirement (%i)' % (mod_name, _instance.getSafeLevel(), self.config["safe_level"])) else: self.actionModules[mod_dispname] = _instance for t in _instance.getTriggers(): EventHandler.add(_instance, t) elif (type == "input"): self.inputModules[mod_dispname] = _instance else: self.display.error( 'Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, _instance.getRequirements())) except ImportError as e: # notify the user of missing dependencies self.display.error( 'Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, e)) except Exception as e: # notify the user of errors print e self.display.error('Module \'%s\' disabled.' % (mod_name)) return module_str
def loadModule(self, type, dirpath, filename): module_dict = {} # remove the beginning string of the dirpath basepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) dirpath_orig = dirpath dirpath = dirpath[len(basepath)+1:] mod_name = filename.split('.')[0] mod_dispname = '/'.join(re.split('/modules/' + type + "/", dirpath)[-1].split('/') + [mod_name]) mod_loadname = mod_dispname.replace('/', '_') mod_loadpath = os.path.join(dirpath_orig, filename) mod_file = open(mod_loadpath) try: # import the module into memory imp.load_source(mod_loadname, mod_loadpath, mod_file) # find the module and make an instace of it _module = __import__(mod_loadname) _class = getattr(_module, mod_name) _instance = _class(self.config, self.display, self.modulelock) reasons = [] valid = True for r in _instance.getRequirements(): if r == 'disable': reasons.append("Module Manually Disabled !!!") elif r == 'APIKEY': key_name = mod_name + "_apikey" if not key_name in self.config: reasons.append("API key is missing") valid = False elif not r in self.config: path = Utils.validateExecutable(r) if path: self.config[r] = path else: reasons.append("Requirement not met: %s" % r) valid = False if valid: module_dict = {'name': mod_name.ljust(25), 'description': _instance.getTitle().ljust(40), 'type': type.ljust(6), 'valid': True} else: module_dict = {'name': mod_name.ljust(25), 'description': _instance.getTitle().ljust(40), 'type': type.ljust(6), 'valid': False} if type == 'action': module_dict['safelevel'] = _instance.getSafeLevel() else: module_dict['safelevel'] = None # add the module to the framework's loaded modules if valid: if type == "action": if self.config["safe_level"] > _instance.getSafeLevel(): reasons.append("Safety_Level (%i) is below requirement: %i" % (_instance.getSafeLevel(), self.config["safe_level"])) #self.display.error( # 'Module \'%s\' disabled. Safety_level (%i) is below specified requirement (%i)' % ( # mod_name, _instance.getSafeLevel(), self.config["safe_level"])) elif self.checkExcludeTypes(_instance.getTypes()) == True: True #self.display.error( # 'Module \'%s\' disabled. One or more of the following module types were excluded %s' % ( # mod_name, _instance.getTypes())) else: self.actionModules[mod_dispname] = _instance for t in _instance.getTriggers(): EventHandler.add(_instance, t) elif type == "input": self.inputModules[mod_dispname] = _instance elif type == "report": self.reportModules[mod_dispname] = _instance #else: # self.display.error( # 'Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, _instance.getRequirements())) if reasons: self.display.error('Module \'%s\' disabled:' % mod_name) for r in reasons: self.display.error(' ' + r) except ImportError as e: # notify the user of missing dependencies self.display.error('Module \'%s\' disabled. Dependency required: \'%s\'' % (mod_name, e)) return None except Exception as e: # notify the user of errors print e self.display.error('Module \'%s\' disabled.' % (mod_name)) return None return module_dict