Esempio n. 1
0
    def initialize(self,):

        print "CFx Loaded. Initializing Modules\n"

        # Iterating through the modules mentioned in config.json
        for key in self.json_data:
            if (key != 'CFx'):

                module = importlib.import_module(key) # Dynamically importing the modules
                class_ = getattr(module,key) # Get the class with name key from module

                _CFxHandle = CFxHandle(self) # Create a CFxHandle object for each module

                # Instantiate the class, with CFxHandle reference and configuration parameters
                instance = class_(_CFxHandle,self.json_data[key])

                _CFxHandle.CMInstance = instance
                _CFxHandle.CMConfig = self.json_data[key]

                # Store the CFxHandle object references in the dict with module name as the key
                self.CFxHandleDict[key] = _CFxHandle

                # Intialize all the CFxHandles which in turn initialize the CMs    
                _CFxHandle.initialize()

        # Start all the worker threads
        for handle in self.CFxHandleDict:
            self.CFxHandleDict[handle].CMThread.start()
            if(self.CFxHandleDict[handle].timer_thread):
                self.CFxHandleDict[handle].timer_thread.start()
Esempio n. 2
0
    def load_module(self, module_name):

        if 'enabled' in self.json_data[module_name]:
            module_enabled = self.json_data[module_name]['enabled']
        else:
            module_enabled = True

        if(module_name not in self.loaded_modules) and module_enabled == True:

            # Load dependencies of the module
            self.load_dependencies(module_name)

            # Dynamically importing the modules
            try:
                module = importlib.import_module("controller.modules."+module_name)
            except:
                if(self.vpn_type == "GroupVPN"):
                    module = importlib.import_module("controller.modules.gvpn."+module_name)
                elif(self.vpn_type == "SocialVPN"):
                    module = importlib.import_module("controller.modules.svpn."+module_name)
                else:
                    module = importlib.import_module("controller.modules."+self.vpn_type+module_name)

            # Get the class with name key from module
            module_class = getattr(module, module_name)

            # Create a CFxHandle object for each module
            handle = CFxHandle(self)

            # Instantiate the class, with CFxHandle reference and
            # configuration parameters

            # Pass the sock_list as parameter to the TincanListener
            # and TincanSender modules
            if(module_name in ['TincanListener', 'TincanSender']):
                instance = module_class(self.sock_list,
                                        handle,
                                        self.CONFIG[module_name])
            else:
                instance = module_class(handle, self.CONFIG[module_name])

            handle.CMInstance = instance
            handle.CMConfig = self.CONFIG[module_name]

            # Store the CFxHandle object references in the
            # dict with module name as the key
            self.CFxHandleDict[module_name] = handle

            # Intialize all the CFxHandles which in turn initialize the CMs
            handle.initialize()

            self.loaded_modules.append(module_name)
Esempio n. 3
0
    def load_module(self, module_name):

        if(module_name not in self.loaded_modules):

            # Load dependencies of the module
            self.load_dependencies(module_name)

            # Dynamically importing the modules
            module = importlib.import_module(module_name)

            # Get the class with name key from module
            module_class = getattr(module, module_name)

            # Create a CFxHandle object for each module
            handle = CFxHandle(self)

            # Instantiate the class, with CFxHandle reference and
            # configuration parameters

            # Append the icc flag and icc port to the modules config and
            # pass the sock_list as parameter to TincanListener
            # and TincanSender modules
            if(module_name in ['TincanListener', 'TincanSender']):
                self.CONFIG[module_name]["icc"] = self.CONFIG['CFx']["icc"]
                self.CONFIG[module_name]["icc_port"] = self.CONFIG['CFx']["icc_port"]

                instance = module_class(self.sock_list,
                                        handle,
                                        self.CONFIG[module_name])
            else:
                instance = module_class(handle, self.CONFIG[module_name])

            handle.CMInstance = instance
            handle.CMConfig = self.CONFIG[module_name]

            # Store the CFxHandle object references in the
            # dict with module name as the key
            self.CFxHandleDict[module_name] = handle

            # Intialize all the CFxHandles which in turn initialize the CMs
            handle.initialize()

            self.loaded_modules.append(module_name)
Esempio n. 4
0
    def load_module(self, module_name):

        if 'enabled' in self.json_data[module_name]:
            module_enabled = self.json_data[module_name]['enabled']
        else:
            module_enabled = True

        if (module_name not in self.loaded_modules) and module_enabled == True:

            # Load dependencies of the module
            self.load_dependencies(module_name)

            # Dynamically importing the modules
            try:
                module = importlib.import_module("controller.modules." +
                                                 module_name)
            except:
                if (self.vpn_type == "GroupVPN"):
                    module = importlib.import_module(
                        "controller.modules.gvpn." + module_name)
                elif (self.vpn_type == "SocialVPN"):
                    module = importlib.import_module(
                        "controller.modules.svpn." + module_name)
                else:
                    module = importlib.import_module("controller.modules." +
                                                     self.vpn_type +
                                                     module_name)

            # Get the class with name key from module
            module_class = getattr(module, module_name)

            # Create a CFxHandle object for each module
            handle = CFxHandle(self)

            # Instantiate the class, with CFxHandle reference and
            # configuration parameters

            # Pass the sock_list as parameter to the TincanListener
            # and TincanSender modules
            if (module_name in ['TincanListener', 'TincanSender']):
                instance = module_class(self.sock_list, handle,
                                        self.CONFIG[module_name])
            else:
                instance = module_class(handle, self.CONFIG[module_name])

            handle.CMInstance = instance
            handle.CMConfig = self.CONFIG[module_name]

            # Store the CFxHandle object references in the
            # dict with module name as the key
            self.CFxHandleDict[module_name] = handle

            # Intialize all the CFxHandles which in turn initialize the CMs
            handle.initialize()

            self.loaded_modules.append(module_name)