Пример #1
0
def test_address_resolve_ipv4():
    """
    Test `prewikka.resolve.AddressResolve` for IPv4.

    NOTE: values could change if provider change IP/domain name.
    NOTE: Test skipped if Twisted is not installed.
    """
    # Skip test if Twisted is not installed
    pytest.importorskip('twisted')

    init()

    fail_ipv4 = '127.0.13.37'
    success_ipv4 = '208.67.222.222'
    success_domain_ipv4 = 'resolver1.opendns.com'

    res = AddressResolve(fail_ipv4)

    assert str(res) == fail_ipv4
    assert not res.resolve_succeed()

    res = AddressResolve(success_ipv4)

    assert str(res) == success_domain_ipv4
    assert str(
        len(res)
    ) != 0  # exact value could change function of server used, we check if no null only
    assert res.resolve_succeed()

    # invalid IP

    with pytest.raises(TypeError):
        AddressResolve(42)
Пример #2
0
    def __init__(self, filename=None, autoupdate=False):
        self.autoupdate = autoupdate
        env.auth = None  # In case of database error
        env.config = config.Config(filename)

        env.config.general.setdefault("default_theme", "cs")
        env.config.general.setdefault("default_locale", "en_GB")
        env.config.general.setdefault("encoding", "UTF-8")
        env.config.general.setdefault("default_timezone",
                                      localization.get_system_timezone())
        env.config.general.reverse_path = env.config.general.get(
            "reverse_path", "").rstrip("/")

        env.log = log.Log(env.config.log)
        env.log.info("Starting Prewikka")

        env.dns_max_delay = env.config.general.get_float("dns_max_delay", 0.)

        if env.config.general.get_bool("external_link_new_window", True):
            env.external_link_target = "_blank"
        else:
            env.external_link_target = "_self"

        env.enable_details = env.config.general.get_bool(
            "enable_details", False)

        env.host_details_url = env.config.general.get(
            "host_details_url",
            "https://www.prelude-siem.com/host_details.php")
        env.port_details_url = env.config.general.get(
            "port_details_url",
            "https://www.prelude-siem.com/port_details.php")
        env.reference_details_url = env.config.general.get(
            "reference_details_url",
            "https://www.prelude-siem.com/reference_details.php")

        resolve.init()

        env.menumanager = None
        env.viewmanager = view.ViewManager()
        env.htdocs_mapping.update(
            (("prewikka", pkg_resources.resource_filename(__name__,
                                                          'htdocs')), ))

        self._reload_time = None
        self._reload_count = 0
        try:
            self._prewikka_initialized = False
            self._prewikka_init_if_needed()
        except:
            pass
Пример #3
0
    def __init__(self, filename=None):
        env.auth = None # In case of database error
        env.config = config.Config(filename)

        env.config.general.setdefault("default_theme", "cs")
        env.config.general.setdefault("default_locale", "en_GB")
        env.config.general.setdefault("encoding", "UTF-8")
        env.config.general.setdefault("default_timezone", localization.get_system_timezone())
        env.config.general.reverse_path = env.config.general.get("reverse_path", "").rstrip("/")

        env.log = log.Log(env.config)
        env.log.info("Starting Prewikka")

        env.dns_max_delay = float(env.config.general.get("dns_max_delay", 0))

        val = env.config.general.get("external_link_new_window", "true")
        if val is None or val.lower() in ["true", "yes"]:
            env.external_link_target = "_blank"
        else:
            env.external_link_target = "_self"

        details = env.config.general.get("enable_details", "false")
        env.enable_details = details is None or details.lower() in ["true", "yes"]

        env.host_details_url = env.config.general.get("host_details_url", "https://www.prelude-siem.com/host_details.php")
        env.port_details_url = env.config.general.get("port_details_url", "https://www.prelude-siem.com/port_details.php")
        env.reference_details_url = env.config.general.get("reference_details_url", "https://www.prelude-siem.com/reference_details.php")

        resolve.init()

        env.viewmanager = None
        env.menumanager = None
        env.htdocs_mapping.update((("prewikka", pkg_resources.resource_filename(__name__, 'htdocs')),))

        custom_theme = env.config.interface.get("custom_theme", None)
        if custom_theme:
            if os.path.isdir("%s%s" % (os.path.sep, custom_theme)):
                env.htdocs_mapping.update((("custom", custom_theme),))
            else:
                env.htdocs_mapping.update((("custom", pkg_resources.resource_filename(custom_theme, 'htdocs')),))

        try:
            self._prewikka_initialized = False
            self._prewikka_init_if_needed()
        except:
            pass
Пример #4
0
def test_address_resolve_ipv6():
    """
    Test `prewikka.resolve.AddressResolve` for IPv6.

    NOTE: values could change if provider change IP/domain name.
    NOTE: Test skipped if Twisted is not installed.
    """
    # Skip test if Twisted is not installed
    pytest.importorskip('twisted')

    init()

    success_ipv6 = '2620:0:ccc::2'
    success_ipv6_full = '2620:0000:0ccc:0000:0000:0000:0000:0002'
    success_domain_ipv6 = 'resolver1.ipv6-sandbox.opendns.com'

    assert str(AddressResolve(success_ipv6)) == success_domain_ipv6
    assert str(AddressResolve(success_ipv6_full)) == success_domain_ipv6
Пример #5
0
    def __init__(self, filename=None):
        env.auth = None # In case of database error
        env.config = config.Config(filename)

        env.config.default_theme = env.config.general.getOptionValue("default_theme", "cs")
        env.config.default_locale = env.config.general.getOptionValue("default_locale", "en_GB")
        env.config.default_encoding = env.config.general.getOptionValue("encoding", "UTF-8")

        env.log = log.Log(env.config)
        env.log.info("Starting Prewikka")

        env.hookmgr = pluginmanager.PluginHookManager()
        env.hookmgr.declare("HOOK_TOPLAYOUT_EXTRA_CONTENT")
        env.hookmgr.declare("HOOK_PROCESS_REQUEST")
        env.hookmgr.declare("HOOK_LINK")

        env.dns_max_delay = float(env.config.general.getOptionValue("dns_max_delay", 0))

        val = env.config.general.getOptionValue("external_link_new_window", "true")
        if val.lower() in ["true", "yes"]:
            env.external_link_target = "_blank"
        else:
            env.external_link_target = "_self"

        # Get prewikka.conf option "enable_flags" and store it into environment
        env.enable_flags = env.config.general.getOptionValue("enable_flags", "true").lower() in ["true", "yes"]
        env.enable_details = env.config.general.getOptionValue("enable_details", "false").lower() in ["true", "yes"]
        env.host_details_url = env.config.general.getOptionValue("host_details_url", "https://www.prelude-siem.com/host_details.php")
        env.port_details_url = env.config.general.getOptionValue("port_details_url", "https://www.prelude-siem.com/port_details.php")
        env.reference_details_url = env.config.general.getOptionValue("reference_details_url", "https://www.prelude-siem.com/reference_details.php")

        resolve.init()

        env.viewmanager = None
        env.htdocs_mapping.update((("prewikka", pkg_resources.resource_filename(__name__, 'htdocs')),))

        try:
            self._prewikka_initialized = False
            self._prewikka_init_if_needed()
        except:
            pass
Пример #6
0
def test_address_resolve():
    """
    Test `prewikka.resolve.AddressResolve` class.

    Test methods of the class AddressResolve (resolve() method is tested in dedicated tests).
    NOTE: Test skipped if Twisted is not installed.
    """
    # Skip test if Twisted is not installed
    pytest.importorskip('twisted')

    init()

    process()

    # change env.dns_max_delay
    backup_env_max_delay = env.dns_max_delay

    env.dns_max_delay = -1

    assert not init()

    # clean
    env.dns_max_delay = backup_env_max_delay
Пример #7
0
    def __init__(self, config=None):
        class Env: pass
        self._env = Env()
        self._env.auth = None # In case of database error
        self._env.config = Config.Config(config)
        self._env.log = Log.Log(self._env.config)
        self._env.dns_max_delay = float(self._env.config.general.getOptionValue("dns_max_delay", 0))
        self._env.max_aggregated_source = int(self._env.config.general.getOptionValue("max_aggregated_source", 10))
        self._env.max_aggregated_target = int(self._env.config.general.getOptionValue("max_aggregated_target", 10))
        self._env.default_locale = self._env.config.general.getOptionValue("default_locale", None)

        if self._env.dns_max_delay != -1:
            resolve.init(self._env)

        preludedb.preludedb_init()

        self._checkVersion()

        self._database_schema_error = None
        try:
            self._initDatabase()
        except Database.DatabaseSchemaError, e:
            self._database_schema_error = e
            return
Пример #8
0
    def __init__(self, filename=None):
        env.auth = None  # In case of database error
        env.config = config.Config(filename)

        env.config.general.setdefault("default_theme", "cs")
        env.config.general.setdefault("default_locale", "en_GB")
        env.config.general.setdefault("encoding", "UTF-8")
        env.config.general.setdefault("default_timezone",
                                      localization.get_system_timezone())
        env.config.general.reverse_path = env.config.general.get(
            "reverse_path", "").rstrip("/")

        env.log = log.Log(env.config)
        env.log.info("Starting Prewikka")

        env.dns_max_delay = float(env.config.general.get("dns_max_delay", 0))

        val = env.config.general.get("external_link_new_window", "true")
        if val is None or val.lower() in ["true", "yes"]:
            env.external_link_target = "_blank"
        else:
            env.external_link_target = "_self"

        details = env.config.general.get("enable_details", "false")
        env.enable_details = details is None or details.lower() in [
            "true", "yes"
        ]

        env.host_details_url = env.config.general.get(
            "host_details_url",
            "https://www.prelude-siem.com/host_details.php")
        env.port_details_url = env.config.general.get(
            "port_details_url",
            "https://www.prelude-siem.com/port_details.php")
        env.reference_details_url = env.config.general.get(
            "reference_details_url",
            "https://www.prelude-siem.com/reference_details.php")

        resolve.init()

        env.viewmanager = None
        env.menumanager = None
        env.htdocs_mapping.update(
            (("prewikka", pkg_resources.resource_filename(__name__,
                                                          'htdocs')), ))

        custom_theme = env.config.interface.get("custom_theme", None)
        if custom_theme:
            if os.path.isdir("%s%s" % (os.path.sep, custom_theme)):
                env.htdocs_mapping.update((("custom", custom_theme), ))
            else:
                env.htdocs_mapping.update(
                    (("custom",
                      pkg_resources.resource_filename(custom_theme,
                                                      'htdocs')), ))

        try:
            self._prewikka_initialized = False
            self._prewikka_init_if_needed()
        except:
            pass