Example #1
0
class ModuleHandler():
    """
    Handle loading, unloading and reloading of modules.
    """

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def __init__(self, root, config):
        """
        Initialize variables and modules.

        @type  root:     String
        @param root:     Full path to the FuzzLabs root directory
        @type  config:   Dictionary
        @param config:   The complete configuration as a dictionary
        """

        self.root = root
        self.config = config
        self.loaded_modules = []
        self.modules_dir = self.root + "/modules"
        self.database = DatabaseHandler(self.config, self.root)

        self.__init_modules()

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def __init_modules(self):
        """
        Initial load of modules. All modules not already loaded will get
        initialized and started.
        """

        for module_name in self.get_directories():
            if self.is_module_loaded(module_name):
                continue

            mod = self.__load_module_by_name(module_name)
            if not mod:
                self.database.log("error",
                                  "failed to load module: %s" % module_name)
                continue

            try:
                mod["instance"].start()
                self.loaded_modules.append(mod)
            except Exception, ex:
                self.database.log("error",
                                  "failed to start module: %s" % mod["name"],
                                  str(ex))
Example #2
0
class ModuleHandler():
    """
    Handle loading, unloading and reloading of modules.
    """

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def __init__(self, root, config):
        """
        Initialize variables and modules.

        @type  root:     String
        @param root:     Full path to the FuzzLabs root directory
        @type  config:   Dictionary
        @param config:   The complete configuration as a dictionary
        """

        self.root = root
        self.config = config
        self.loaded_modules = []
        self.modules_dir = self.root + "/modules"
        self.database        = DatabaseHandler(self.config, self.root)

        self.__init_modules()

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def __init_modules(self):
        """
        Initial load of modules. All modules not already loaded will get
        initialized and started.
        """

        for module_name in self.get_directories():
            if self.is_module_loaded(module_name):
                continue

            mod = self.__load_module_by_name(module_name)
            if not mod:
                self.database.log("error",
                                  "failed to load module: %s" % module_name)
                continue

            try:
                mod["instance"].start()
                self.loaded_modules.append(mod)
            except Exception, ex:
                self.database.log("error",
                                  "failed to start module: %s" % mod["name"],
                                  str(ex))
Example #3
0
class FuzzlabsDaemon():
    """
    Implement the FuzzLabs daemon which loads up modules and keeps track of
    any changes both to the loaded and new modules. Once the daemon is finished
    running the modules are unloaded.
    """

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def __init__(self, root, config):
        """
        Initialize FuzzLabs daemon.

        @type  root:     String
        @param root:     Full path to the FuzzLabs root directory
        @type  config:   Dictionary
        @param config:   The complete configuration as a dictionary
        """

        self.root            = root
        self.config          = config
        self.modules         = None
        self.stdin_path      = self.config['daemon']['stdin']
        self.stdout_path     = self.config['daemon']['stdout']
        self.stderr_path     = self.config['daemon']['stderr']
        self.pidfile_path    = self.config['daemon']['pidfile']
        self.pidfile_timeout = self.config['daemon']['pidfile_timeout']
        self.running         = True
        self.database        = DatabaseHandler(self.config, self.root)

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def __sigterm_handler(self, signum, frame):
        """
        Handle SIGTERM signal and abort execution.
        """

        self.database.log("info", "DCNWS FuzzLabs is stopping")
        self.running = False

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def run(self):
        """
        Main function of FuzzLabs.
        """

        self.database.log("info", "DCNWS FuzzLabs is initializing")

        try:
            os.setsid()
            os.umask(077)
            signal.signal(signal.SIGTERM, self.__sigterm_handler) 
        except Exception, ex:
            self.database.log("error", "failed to start daemon", str(ex))
            sys.exit(1)

        try:
            self.modules = ModuleHandler(self.root, self.config)
        except Exception, ex:
            self.database.log("error", "failed to load modules", str(ex))
            sys.exit(1)
Example #4
0
class FuzzlabsDaemon():
    """
    Implement the FuzzLabs daemon which loads up modules and keeps track of
    any changes both to the loaded and new modules. Once the daemon is finished
    running the modules are unloaded.
    """

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def __init__(self, root, config):
        """
        Initialize FuzzLabs daemon.

        @type  root:     String
        @param root:     Full path to the FuzzLabs root directory
        @type  config:   Dictionary
        @param config:   The complete configuration as a dictionary
        """

        self.root = root
        self.config = config
        self.modules = None
        self.stdin_path = self.config['daemon']['stdin']
        self.stdout_path = self.config['daemon']['stdout']
        self.stderr_path = self.config['daemon']['stderr']
        self.pidfile_path = self.config['daemon']['pidfile']
        self.pidfile_timeout = self.config['daemon']['pidfile_timeout']
        self.running = True
        self.database = DatabaseHandler(self.config, self.root)

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def __sigterm_handler(self, signum, frame):
        """
        Handle SIGTERM signal and abort execution.
        """

        self.database.log("info", "DCNWS FuzzLabs is stopping")
        self.running = False

    # -------------------------------------------------------------------------
    #
    # -------------------------------------------------------------------------

    def run(self):
        """
        Main function of FuzzLabs.
        """

        self.database.log("info", "DCNWS FuzzLabs is initializing")

        try:
            os.setsid()
            os.umask(077)
            signal.signal(signal.SIGTERM, self.__sigterm_handler)
        except Exception, ex:
            self.database.log("error", "failed to start daemon", str(ex))
            sys.exit(1)

        try:
            self.modules = ModuleHandler(self.root, self.config)
        except Exception, ex:
            self.database.log("error", "failed to load modules", str(ex))
            sys.exit(1)