コード例 #1
0
ファイル: Settings.py プロジェクト: arieldalefe/jok3r
    def __create_tool(self, section):
        """
        Create a Tool object.

        :param str section: Section name corresponding to the tool in toolbox.conf
        :return: The newly created tool
        :rtype: Tool
        """
        tool_config = defaultdict(str)

        if not self.__parse_tool_options(section, tool_config): 
            return None
        if not self.__parse_tool_install_status(tool_config):
            return None

        return Tool(
            tool_config['name'],
            tool_config['description'],
            tool_config['target_service'],
            tool_config['installed'],
            tool_config['last_update'],
            tool_config['install'],
            tool_config['update'],
            tool_config['check_command']
        )
コード例 #2
0
    def createToolFromConfiguration(self,
                                    section,
                                    service_name,
                                    tooltype=ToolType.STANDARD):
        """
		Create tool object from a tool entry (section) into the settings file
		Note: Must be called after initializing parser for INSTALL_STATUS_CONF_FILE

		@Args		section: 		Section from config file corresponding to a tool
					service_name: 	Service targeted by the tool
					tooltype: 		ToolType
		@Returns	instance of Tool object if everything is ok, False otherwise

		"""
        if service_name not in self.general_settings.keys():
            return False

        # Parse general options
        options_general = self.parseToolGeneralOptions(section, service_name,
                                                       tooltype)
        if not options_general:
            return False

        # Parse specific info (depends on targeted service)
        options_specific = self.parseToolSpecificOptions(
            section, service_name, tooltype)

        # Create the Tool object from parsed info
        tool = Tool(
            service_name,
            self.toolbox_dir,
            tooltype,
            # General tool options
            options_general['name'],
            options_general['tool_ref_name'],
            options_general['category'],
            options_general['description'],
            options_general['command'],
            options_general['install'],
            options_general['update'],
            options_general['installed'],
            options_general['last_update'],
            # Specific tool options
            options_specific)
        return tool
コード例 #3
0
    def __create_tool(self, section):
        """
        Create a Tool object
        :param section: Tool section into the toolbox settings file
        :return: The created Tool instance
        """
        tool_config = defaultdict(str)

        if not self.__parse_tool_options(section, tool_config): return None
        if not self.__parse_tool_install_status(tool_config):   return None

        return Tool(
            tool_config['name_clean'],
            tool_config['name'],
            tool_config['description'],
            tool_config['target_service'],
            tool_config['installed'],
            tool_config['last_update'],
            tool_config['install'],
            tool_config['update'],
            tool_config['check_command']
        )
コード例 #4
0
ファイル: Settings.py プロジェクト: u53r55/jok3r
    def createToolFromConfiguration(self, section, service_name):
        """
		Create tool object from a [tool_****] entry into the settings file
		@Args		section: 		section from config file corresponding to a tool
					service_name: 	service targeted by the tool
		@Returns	instance of Tool object if everything is ok, False otherwise
		"""
        if service_name not in self.general_settings.keys():
            return False

        # First, check for the presence of all needed option for the tool
        options = self.config_parsers[service_name].options(section)
        for o in MANDATORY_TOOL_OPTIONS:
            if o not in options:
                self.output.printWarning('[{0}{1}] Section "{2}" > missing mandatory option "{3}", skipped'.format( \
                 service_name, CONF_EXT, section, o))
                return False

        # Parse general+mandatory info
        try:
            name = self.config_parsers[service_name].safeGet(
                section, 'name', '', None).strip()
            category = self.config_parsers[service_name].safeGet(
                section, 'category', '', None).strip().lower()
            description = self.config_parsers[service_name].safeGet(
                section, 'description', '', None).strip()
            raw_command = self.config_parsers[service_name].safeGet(
                section, 'command', '', None).strip()
        except:
            self.output.printWarning('[{0}{1}] Section "{2}" > syntax error with mandatory options'.format( \
             service_name, CONF_EXT, section))
            #traceback.print_exc()
            return False

        # Check general+mandatory info
        if not name:
            self.output.printWarning(
                '[{0}{1}] Section "{2}" > option "name" is empty, section skipped'
                .format(service_name, CONF_EXT, section))
            return False
        if not category:
            self.output.printWarning(
                '[{0}{1}] Section "{2}" > option "category" is empty, section skipped'
                .format(service_name, CONF_EXT, section))
            return False
        if category not in self.general_settings[service_name][
                'tools_categories']:
            self.output.printWarning(
                '[{0}{1}] Section "{2}" > option "category" ("{3}") not in "tools_categories", section skipped'
                .format(service_name, CONF_EXT, section, category))
            return False
        if not raw_command:
            self.output.printWarning(
                '[{0}{1}] Section "{2}" > option "command" is empty, section skipped'
                .format(service_name, CONF_EXT, section))
            return False

        # Parse general+optional info
        try:
            install = self.config_parsers[service_name].safeGet(
                section, 'install', '', None).strip()
            update = self.config_parsers[service_name].safeGet(
                section, 'update', '', None).strip()
            last_update = self.config_parsers[service_name].safeGet(
                section, 'last_update', '', None).strip()
            installed = self.config_parsers[service_name].safeGetBoolean(
                section, 'installed', True)
        except:
            pass

        # Parse specific info (depends on targeted service)
        # opt_specific is a dictionary: "option" => (type, value)
        opt_specific = dict()
        if service_name in SPECIFIC_TOOL_OPTIONS.keys():
            for option in SPECIFIC_TOOL_OPTIONS[service_name]:
                # Boolean options (default False)
                if SPECIFIC_TOOL_OPTIONS[service_name][option] == '':
                    opt_specific[option] = (
                        bool, self.config_parsers[service_name].safeGetBoolean(
                            section, option + '_specific', False))

                # List-type options
                else:
                    value_list = [
                        e.lower()
                        for e in self.config_parsers[service_name].safeGetList(
                            section, option + '_specific', ',', [])
                    ]
                    if value_list:
                        for e in value_list:
                            if e.lower(
                            ) not in self.general_settings[service_name][
                                    SPECIFIC_TOOL_OPTIONS[service_name]
                                [option]]:
                                value_list.remove(e)
                                self.output.printWarning(
                                    '[{0}{1}] Section "{2}" > option "{3}" contains invalid entry ("{4}")'
                                    .format(service_name, CONF_EXT, section,
                                            option, e))
                    opt_specific[option] = (list, value_list)

        # Create the Tool object from parsed info
        tool = Tool(
            service_name,
            section,
            self.toolbox_dir,
            # General+Mandatory tool options
            name,
            category,
            description,
            raw_command,
            # General+Optional tool options
            install,
            update,
            last_update,
            installed,
            # Specific tool options
            opt_specific)

        return tool