def create_user_dir(config_file, user_home): log.debug(">>> Create user dir at given home: %s" % user_home) log.debug(">>> Using %s as source" % config_file) user_dir = os.path.join(user_home, base_paths['config_dir']) if os.path.exists(user_home): if os.access(user_home, os.R_OK and os.W_OK): if not os.path.exists(user_dir): os.mkdir(user_dir) for dirname in userdir_dirs: os.mkdir(os.path.join(user_dir, dirname)) log.debug(">>> Umit user dir (%r) successfully " "created!" % user_dir) else: log.debug(">>> Umit user dir (%r) already exists" % user_dir) else: log.warning(">>> No permissions to create user dir!") return False main_dir = os.path.dirname(config_file) for name in userdir_files: copy_config_file(name, main_dir, user_dir) return dict(user_dir = user_dir, config_dir = user_dir, config_file = os.path.join(user_dir, 'umit.conf'))
def add_plugin_to_cache(self, pkg): """ Exports the needs/provides/conflicts to the global dicts """ for attr in ('conflicts', 'provides', 'needs'): for dep in getattr(pkg, attr, []): try: name, op, ver = Version.extract_version(dep) d = getattr(self, "who_%s" % attr) d[name] = (op, ver, pkg) except Exception, err: log.warning(err) log.warning("Ignoring %s entry" % dep)
def uninstall_plugin(self, reader): """ Low level uninstall procedure @param reader a PluginReader @return True if ok or False """ try: os.remove(reader.get_path()) self.recache() return True except Exception, err: log.warning("Error in uninstall_plugin(): %s" % err) return False
def show_help(parent, url): import webbrowser url_final = get_filename(url) doc_path = abspath(join(Path.docs_dir, url_final)) log.warning(">>> Openning documentation: %s" % doc_path) if exists(doc_path) and os.access(doc_path, os.R_OK): webbrowser.open("file://%s" % doc_path, new=open_url_as()) else: d = HIGAlertDialog(parent=parent, message_format=_("Couldn't find \ documentation files!"), secondary_text=_("""Umit couldn't find the \ documentation files. Please, go to Umit's website and have the latest \ documentation in our Support & Development section.""")) d.run() d.destroy()
def show_help(parent,url): import webbrowser url_final = get_filename(url) doc_path = abspath(join(Path.docs_dir, url_final)) log.warning(">>> Openning documentation: %s" % doc_path) if exists(doc_path) and os.access(doc_path, os.R_OK): webbrowser.open("file://%s" % doc_path, new=open_url_as()) else: d = HIGAlertDialog(parent=parent, message_format=_("Couldn't find \ documentation files!"), secondary_text=_("""Umit couldn't find the \ documentation files. Please, go to Umit's website and have the latest \ documentation in our Support & Development section.""")) d.run() d.destroy()
def run(self): # Try to load psyco module, saving this information # if we care to use it later (such as in a About Dialog) if not development_mode(default=False): try: import psyco except ImportError: log.warning(_("RUNNING WITHOUT PSYCO!")) log.warning(_("psyco is a module that speeds up the execution " "of Python applications. It is not a requirement, and " "Umit will work normally without it, but you're " "encouraged to install it to have a better speed " "experience. Download psyco at http://psyco.sf.net/""")) self.using_psyco = False else: psyco.profile() self.using_psyco = True self.diff = option_parser.get_diff() if self.diff: self.__run_text() else: self.__run_gui()
def load_selected_plugins(self): """ Load the selected plugins specified in config file """ # Load the plugins in order (specified in conf file) for plugin in self.plugins.plugins: if not plugin or plugin == "": continue loaded, errmsg = self.load_plugin_from_path(plugin) if not loaded: log.warning(errmsg) if os.environ.get('UMIT_DEVELOPMENT', False): plugins = os.getenv('UMIT_PLUGINS', '') if not plugins: return for plugin in plugins.split(os.pathsep): self.load_from_directory(plugin)
def remove_plugin_from_cache(self, pkg): for attr in ('conflicts', 'provides', 'needs'): for dep in getattr(pkg, attr, []): try: name, op, ver = Version.extract_version(dep) d = getattr(self, "who_%s" % attr) # It's more probably that the entry is in the last for i in xrange(len(d[name]) - 1, -1, -1): _op, _ver, _pkg = d[name][i] if pkg == _pkg and \ ver == _ver and \ op == _op: del d[name][i] # Remove unused keys. if not d[name]: del d[name] except Exception, err: log.warning(err) log.warning("Ignoring %s entry" % dep)
def load_directory(self, modpath): if not os.environ.get('UMIT_DEVELOPMENT', False): log.error("This method should not be called in release.") return start_file = 'main' log.warning("You are loading a plugin without checking for needs,provides,conflitcts") log.warning("* You have been warned! *") log.warning("Assuming `%s' as start file!" % start_file) # Load the plugin sys.path.insert(0, os.path.abspath(modpath)) if start_file in sys.modules: sys.modules.pop(start_file) try: __builtin__.__import__ = hook_import module = hook_import(start_file, level=0) if hasattr(module, "__plugins__") and \ isinstance(module.__plugins__, list): lst = module.__plugins__ ret = [] for plug in lst: try: inst = plug() inst.start(None) ret.append(inst) except Exception, err: log.critical("Error while starting %s:" % (plug)) log.critical(generate_traceback()) log.critical("Ignoring instance.") if not ret: log.error("Not startable plugin defined in main file") else:
self.attr['rule'] = 'unknown' self._translate('version', l[7]) except IndexError: raise ScriptParseException def _translate(self, attrname, s): if s == 'nil': return lines = [x.strip() for x in s.split('\\n')] self.attr[attrname] = "\n".join(lines) # Trying to use installed Lua for parsing LuaParser = LuaReParser try: p = Popen(["lua", "-v"], stdin=PIPE, stdout=PIPE, stderr=PIPE) output, version_info = p.communicate() del p if version_info.startswith('Lua 5.'): log.warning(_("LuaParser: Native Lua parser selected")) LuaParser = LuaNativeParser else: log.warning(_("LuaParser: Your Lua version is too old so regexp parsing will be used")) except OSError, e: log.warning(_("LuaParser: Can't find lua interpreter so regexp parsing will be used")) if __name__ == "__main__": parser = LuaNativeParser('SMTP_openrelay_test.nse') print parser.attr
raise ScriptParseException def _translate(self, attrname, s): if s == 'nil': return lines = [x.strip() for x in s.split('\\n')] self.attr[attrname] = "\n".join(lines) # Trying to use installed Lua for parsing LuaParser = LuaReParser try: p = Popen(["lua", "-v"], stdin=PIPE, stdout=PIPE, stderr=PIPE) output, version_info = p.communicate() del p if version_info.startswith('Lua 5.'): log.warning(_("LuaParser: Native Lua parser selected")) LuaParser = LuaNativeParser else: log.warning( _("LuaParser: Your Lua version is too old so regexp parsing will be used" )) except OSError, e: log.warning( _("LuaParser: Can't find lua interpreter so regexp parsing will be used" )) if __name__ == "__main__": parser = LuaNativeParser('SMTP_openrelay_test.nse') print parser.attr