Example #1
0
def list_sources():
    free_only = config.args().free
    if not sources.source_index_exists(config):
        logger.info("No source index found, running update-sources")
        try:
            update_sources()
        except exceptions.ApplicationError as err:
            logger.warning("%s: will use bundled index.", err)
    index = sources.load_source_index(config)
    for name, source in index.get_sources().items():
        is_not_free = source.get("subscribe-url")
        if free_only and is_not_free:
            continue
        print("%s: %s" % (util.bright_cyan("Name"), util.bright_magenta(name)))
        print("  %s: %s" % (util.bright_cyan("Vendor"),
                            util.bright_magenta(source["vendor"])))
        print("  %s: %s" % (util.bright_cyan("Summary"),
                            util.bright_magenta(source["summary"])))
        print("  %s: %s" % (util.bright_cyan("License"),
                            util.bright_magenta(source["license"])))
        if "tags" in source:
            print("  %s: %s" %
                  (util.bright_cyan("Tags"),
                   util.bright_magenta(", ".join(source["tags"]))))
        if "replaces" in source:
            print("  %s: %s" %
                  (util.bright_cyan("Replaces"),
                   util.bright_magenta(", ".join(source["replaces"]))))
        if "parameters" in source:
            print("  %s: %s" %
                  (util.bright_cyan("Parameters"),
                   util.bright_magenta(", ".join(source["parameters"]))))
        if "subscribe-url" in source:
            print("  %s: %s" % (util.bright_cyan("Subscription"),
                                util.bright_magenta(source["subscribe-url"])))
Example #2
0
def list_sources():
    if not sources.source_index_exists(config):
        logger.info("No source index found, running update-sources")
        update_sources()
    index = sources.load_source_index(config)
    for name, source in index.get_sources().items():
        print("%s: %s" % (util.bright_cyan("Name"), util.bright_magenta(name)))
        print("  %s: %s" % (util.bright_cyan("Vendor"),
                            util.bright_magenta(source["vendor"])))
        print("  %s: %s" % (util.bright_cyan("Summary"),
                            util.bright_magenta(source["summary"])))
        print("  %s: %s" % (util.bright_cyan("License"),
                            util.bright_magenta(source["license"])))
        if "tags" in source:
            print("  %s: %s" %
                  (util.bright_cyan("Tags"),
                   util.bright_magenta(", ".join(source["tags"]))))
        if "replaces" in source:
            print("  %s: %s" %
                  (util.bright_cyan("Replaces"),
                   util.bright_magenta(", ".join(source["replaces"]))))
        if "parameters" in source:
            print("  %s: %s" %
                  (util.bright_cyan("Parameters"),
                   util.bright_magenta(", ".join(source["parameters"]))))
        if "subscribe-url" in source:
            print("  %s: %s" % (util.bright_cyan("Subscription"),
                                util.bright_magenta(source["subscribe-url"])))
Example #3
0
def enable_source():
    name = config.args().name

    # Check if source is already enabled.
    enabled_source_filename = sources.get_enabled_source_filename(name)
    if os.path.exists(enabled_source_filename):
        logger.error("The source %s is already enabled.", name)
        return 1

    # First check if this source was previous disabled and then just
    # re-enable it.
    disabled_source_filename = sources.get_disabled_source_filename(name)
    if os.path.exists(disabled_source_filename):
        logger.info("Re-enabling previous disabled source for %s.", name)
        os.rename(disabled_source_filename, enabled_source_filename)
        return 0

    if not os.path.exists(sources.get_index_filename()):
        logger.warning("Source index does not exist, will use bundled one.")
        logger.warning("Please run suricata-update update-sources.")

    source_index = sources.load_source_index(config)

    if not name in source_index.get_sources():
        logger.error("Unknown source: %s", name)
        return 1

    # Parse key=val options.
    opts = {}
    for param in config.args().params:
        key, val = param.split("=", 1)
        opts[key] = val

    source = source_index.get_sources()[name]

    if "subscribe-url" in source:
        print("The source %s requires a subscription. Subscribe here:" %
              (name))
        print("  %s" % source["subscribe-url"])

    params = {}
    if "parameters" in source:
        for param in source["parameters"]:
            if param in opts:
                params[param] = opts[param]
            else:
                prompt = source["parameters"][param]["prompt"]
                while True:
                    r = raw_input("%s (%s): " % (prompt, param))
                    r = r.strip()
                    if r:
                        break
                params[param] = r.strip()
    new_source = sources.SourceConfiguration(name, params=params)

    # If the source directory does not exist, create it. Also create
    # the default rule-source of et/open, unless the source being
    # enabled replaces it.
    source_directory = sources.get_source_directory()
    if not os.path.exists(source_directory):
        try:
            logger.info("Creating directory %s", source_directory)
            os.makedirs(source_directory)
        except Exception as err:
            logger.error("Failed to create directory %s: %s", source_directory,
                         err)
            return 1

        if "replaces" in source and default_source in source["replaces"]:
            logger.debug(
                "Not enabling default source as selected source replaces it")
        elif new_source.name == default_source:
            logger.debug(
                "Not enabling default source as selected source is the default"
            )
        else:
            logger.info("Enabling default source %s", default_source)
            if not source_index.get_source_by_name(default_source):
                logger.error("Default source %s not in index", default_source)
            else:
                default_source_config = sources.SourceConfiguration(
                    default_source)
                write_source_config(default_source_config, True)

    write_source_config(new_source, True)
    logger.info("Source %s enabled", new_source.name)

    if "replaces" in source:
        for replaces in source["replaces"]:
            filename = sources.get_enabled_source_filename(replaces)
            if os.path.exists(filename):
                logger.info("Removing source %s as its replaced by %s",
                            replaces, new_source.name)
                logger.debug("Deleting %s", filename)
                os.unlink(filename)
Example #4
0
def list_sources():
    enabled = config.args().enabled or \
        config.args().subcommand == "list-enabled-sources"

    if enabled:
        found = False

        # First list sources from the main config.
        config_sources = config.get("sources")
        if config_sources:
            found = True
            print("From %s:" % (config.filename))
            for source in config_sources:
                print("  - %s" % (source))

        # And local files.
        local = config.get("local")
        if local:
            found = True
            print("Local files/directories:")
            for filename in local:
                print("  - %s" % (filename))

        enabled_sources = sources.get_enabled_sources()
        if enabled_sources:
            found = True
            print("Enabled sources:")
            for source in enabled_sources.values():
                print("  - %s" % (source["source"]))

        # If no enabled sources were found, log it.
        if not found:
            logger.warning("No enabled sources.")
        return 0

    free_only = config.args().free
    if not sources.source_index_exists(config):
        logger.info("No source index found, running update-sources")
        try:
            update_sources()
        except exceptions.ApplicationError as err:
            logger.warning("%s: will use bundled index.", err)
    index = sources.load_source_index(config)
    for name, source in index.get_sources().items():
        is_not_free = source.get("subscribe-url")
        if free_only and is_not_free:
            continue
        if not config.args().all:
            if source.get("deprecated") is not None or \
               source.get("obsolete") is not None:
                continue
        print("%s: %s" % (util.bright_cyan("Name"), util.bright_magenta(name)))
        print("  %s: %s" % (util.bright_cyan("Vendor"),
                            util.bright_magenta(source["vendor"])))
        print("  %s: %s" % (util.bright_cyan("Summary"),
                            util.bright_magenta(source["summary"])))
        print("  %s: %s" % (util.bright_cyan("License"),
                            util.bright_magenta(source["license"])))
        if "tags" in source:
            print("  %s: %s" %
                  (util.bright_cyan("Tags"),
                   util.bright_magenta(", ".join(source["tags"]))))
        if "replaces" in source:
            print("  %s: %s" %
                  (util.bright_cyan("Replaces"),
                   util.bright_magenta(", ".join(source["replaces"]))))
        if "parameters" in source:
            print("  %s: %s" %
                  (util.bright_cyan("Parameters"),
                   util.bright_magenta(", ".join(source["parameters"]))))
        if "subscribe-url" in source:
            print("  %s: %s" % (util.bright_cyan("Subscription"),
                                util.bright_magenta(source["subscribe-url"])))
        if "deprecated" in source:
            print("  %s: %s" % (util.orange("Deprecated"),
                                util.bright_magenta(source["deprecated"])))
        if "obsolete" in source:
            print("  %s: %s" % (util.orange("Obsolete"),
                                util.bright_magenta(source["obsolete"])))