Ejemplo n.º 1
0
def submit(**kwargs):
    show_tos = config.ui.tos is not None
    show_url = config.ui.allow_url_submissions
    return custom_render("submit.html",
                         show_tos=show_tos,
                         show_url=show_url,
                         **kwargs)
Ejemplo n.º 2
0
def settings(**kwargs):
    forced = 'forced' in request.args
    if forced:
        forced = 'true'
    else:
        forced = 'false'
    return custom_render("settings.html", forced=forced, **kwargs)
Ejemplo n.º 3
0
def reset():
    if not config.auth.internal.signup.enabled:
        return redirect(redirect_helper("/"))

    reset_id = request.args.get('reset_id', "")
    if reset_id and get_reset_queue(reset_id).length() == 0:
        reset_id = ""
    return custom_render("reset.html", reset_id=reset_id)
Ejemplo n.º 4
0
def submission_detail(**kwargs):
    sid = angular_safe(request.args.get("sid", None))
    new = "new" in request.args
    if new:
        new = 'true'
    else:
        new = 'false'
    return custom_render("submission_detail.html", sid=sid, new=new, **kwargs)
Ejemplo n.º 5
0
def alerts(*_, **kwargs):
    filtering_group_fields = config.core.alerter.filtering_group_fields
    non_filtering_group_fields = config.core.alerter.non_filtering_group_fields
    possible_group_fields = filtering_group_fields + non_filtering_group_fields

    search_filter = angular_safe(request.args.get("filter", "*"))

    search_text = search_filter
    if search_filter == "":
        search_filter = "*"
    elif search_filter == "*":
        search_text = ""

    filter_queries = [
        angular_safe(x) for x in request.args.getlist("fq") if x != ""
    ]

    tc = angular_safe(
        request.args.get("tc", "4{DAY}".format(**STORAGE.ds.DATE_FORMAT)))
    tc_array = [{
        "value": "",
        "name": "None (slow)"
    }, {
        "value": "24{HOUR}".format(**STORAGE.ds.DATE_FORMAT),
        "name": "24 Hours"
    }, {
        "value": "4{DAY}".format(**STORAGE.ds.DATE_FORMAT),
        "name": "4 Days"
    }, {
        "value": "7{DAY}".format(**STORAGE.ds.DATE_FORMAT),
        "name": "1 Week"
    }]
    tc_start = angular_safe(request.args.get("tc_start", None))
    view_type = angular_safe(request.args.get("view_type", "grouped"))
    group_by = angular_safe(
        request.args.get("group_by", config.core.alerter.default_group_field))
    if group_by not in possible_group_fields:
        group_by = config.core.alerter.default_group_field

    return custom_render(
        "alerts.html",
        search_text=search_text,
        filter=search_filter,
        tc_start=tc_start,
        tc=tc,
        view_type=view_type,
        filter_queries=json.dumps(filter_queries),
        group_by=group_by,
        filtering_group_fields=json.dumps(filtering_group_fields),
        non_filtering_group_fields=json.dumps(non_filtering_group_fields),
        tc_array=tc_array,
        time_separator=angular_safe(STORAGE.ds.DATE_FORMAT["SEPARATOR"]),
        **kwargs)
Ejemplo n.º 6
0
def submissions(**kwargs):
    user = kwargs['user']

    group = angular_safe(request.args.get('group', None))
    uname = None

    if not group:
        uname = angular_safe(request.args.get('user', user['uname']))

    return custom_render("submissions.html",
                         uname=uname,
                         group=group,
                         **kwargs)
Ejemplo n.º 7
0
def tos(**kwargs):
    if config.ui.tos is not None:
        kwargs['menu'] = None
        agreed_date = kwargs['user'].get('agrees_with_tos', None)
        if agreed_date:
            agreed_date = iso_to_local(agreed_date)[:19]
        tos_raw = Markup(markdown.markdown(config.ui.tos))
        return custom_render("terms.html",
                             tos=tos_raw,
                             agreed_date=agreed_date,
                             **kwargs)
    else:
        return redirect(redirect_helper("/"))
Ejemplo n.º 8
0
def alert_detail(*_, **kwargs):
    user = kwargs['user']

    alert_key = angular_safe(request.args.get("alert_key", None))
    if not alert_key:
        abort(404)

    alert = STORAGE.alert.get(alert_key, as_obj=False)
    if user and alert and Classification.is_accessible(
            user['classification'], alert['classification']):
        return custom_render("alert_detail.html",
                             alert_key=alert_key,
                             **kwargs)
    else:
        abort(403)
Ejemplo n.º 9
0
def search_help(**kwargs):
    field_list = {
        k: sorted([(x, y) for x, y in v.items()])
        for k, v in list_all_fields().items()
    }
    lookup = {
        "text_ws": "whitespace separated text",
        "text_ws_dsplit": "dot and whitespace separated text",
        "text_general": "tokenized text",
        "text_fuzzy": "separated fuzzy patterns",
    }
    return custom_render("search_help.html",
                         field_list=field_list,
                         lookup=lookup,
                         **kwargs)
Ejemplo n.º 10
0
def search(**kwargs):
    query = angular_safe(request.args.get('query', None))
    search_scope = angular_safe(request.args.get('search_scope', None))
    if search_scope == 'all':
        search_scope = None
    use_archive = angular_safe(request.args.get('use_archive',
                                                "unset")).lower()
    if use_archive not in ['false', 'true']:
        use_archive = None

    return custom_render("search.html",
                         query=query,
                         search_scope=search_scope,
                         use_archive=use_archive,
                         **kwargs)
Ejemplo n.º 11
0
def file_viewer(**kwargs):
    user = kwargs['user']
    sha256 = angular_safe(request.args.get("sha256", None))

    if not sha256:
        abort(404)

    data = STORAGE.file.get(sha256, as_obj=False)

    if not data:
        abort(404)

    if not Classification.is_accessible(user['classification'],
                                        data['classification']):
        abort(403)

    return custom_render("file_viewer.html", sha256=sha256, **kwargs)
Ejemplo n.º 12
0
def signature_detail(**kwargs):
    user = kwargs['user']
    sid = angular_safe(request.args.get("sid", None))

    if not sid:
        abort(404)

    data = STORAGE.signature.get(sid, as_obj=False)

    if not data:
        abort(404)

    if not Classification.is_accessible(
            user['classification'],
            data.get('classification', Classification.UNRESTRICTED)):
        abort(403)

    return custom_render("signature_detail.html",
                         sid=sid,
                         organisation=ORGANISATION,
                         **kwargs)
Ejemplo n.º 13
0
def configuration(**kwargs):
    return custom_render("configuration.html", **kwargs)
Ejemplo n.º 14
0
def dashboard(**kwargs):
    return custom_render("dashboard.html", **kwargs)
Ejemplo n.º 15
0
def heuristics_stats(*_, **kwargs):
    return custom_render("heuristics_stats.html", **kwargs)
Ejemplo n.º 16
0
def logout(**_):
    return custom_render("logout.html", )
Ejemplo n.º 17
0
def admin_user(**kwargs):
    return custom_render("admin_users.html", **kwargs)
Ejemplo n.º 18
0
def admin_services(**kwargs):
    return custom_render("admin_service_configs.html", **kwargs)
Ejemplo n.º 19
0
def classification_help(*_, **kwargs):
    return custom_render("classification_help.html", **kwargs)
Ejemplo n.º 20
0
def services(**kwargs):
    return custom_render("services.html", **kwargs)
Ejemplo n.º 21
0
def login():
    ui4_path = request.cookies.get('ui4_path', None)
    if ui4_path is not None:
        resp = redirect(
            redirect_helper(f"{ui4_path}?{request.query_string.decode()}"))
        resp.delete_cookie("ui4_path")
        return resp

    registration_key = request.args.get('registration_key', None)

    avatar = None
    oauth_token = ''
    oauth_error = ''
    username = ''
    oauth_validation = config.auth.oauth.enabled and 'code' in request.args and 'state' in request.args
    oauth_provider = request.args.get('provider', None)
    up_login = config.auth.internal.enabled or config.auth.ldap.enabled

    next_url = angular_safe(
        request.args.get('next', request.cookies.get('next_url', "/")))
    if "login.html" in next_url or "logout.html" in next_url:
        next_url = "/"

    if registration_key and config.auth.internal.signup.enabled:
        try:
            signup_queue = get_signup_queue(registration_key)
            members = signup_queue.members()
            signup_queue.delete()
            if members:
                user_info = members[0]
                user = User(user_info)
                username = user.uname

                STORAGE.user.save(username, user)
        except (KeyError, ValueError):
            pass

    if config.auth.oauth.enabled:
        providers = str([
            name for name, p in config.auth.oauth.providers.items()
            if p['client_id'] and p['client_secret']
        ])

        if oauth_validation:
            oauth = current_app.extensions.get(
                'authlib.integrations.flask_client')
            provider = oauth.create_client(oauth_provider)

            if provider:
                # noinspection PyBroadException
                try:
                    # Test oauth access token
                    token = provider.authorize_access_token()
                    oauth_provider_config = config.auth.oauth.providers[
                        oauth_provider]

                    # Get user data
                    resp = provider.get(oauth_provider_config.user_get)
                    if resp.ok:
                        user_data = resp.json()

                        # Add group data if API is configured for it
                        if oauth_provider_config.user_groups:
                            resp_grp = provider.get(
                                oauth_provider_config.user_groups)
                            if resp_grp.ok:
                                groups = resp_grp.json()

                                if oauth_provider_config.user_groups_data_field:
                                    groups = groups[oauth_provider_config.
                                                    user_groups_data_field]

                                if oauth_provider_config.user_groups_name_field:
                                    groups = [
                                        x[oauth_provider_config.
                                          user_groups_name_field]
                                        for x in groups
                                    ]

                                user_data['groups'] = groups

                        data = parse_profile(user_data, oauth_provider_config)
                        has_access = data.pop('access', False)
                        if has_access:
                            oauth_avatar = data.pop('avatar', None)

                            # Find if user already exists
                            users = STORAGE.user.search(
                                f"email:{data['email']}",
                                fl="uname",
                                as_obj=False)['items']
                            if users:
                                cur_user = STORAGE.user.get(
                                    users[0]['uname'], as_obj=False) or {}
                                # Do not update username and password from the current user
                                data['uname'] = cur_user.get(
                                    'uname', data['uname'])
                                data['password'] = cur_user.get(
                                    'password', data['password'])
                            else:
                                if data['uname'] != data['email']:
                                    # Username was computed using a regular expression, lets make sure we don't
                                    # assign the same username to two users
                                    res = STORAGE.user.search(
                                        f"uname:{data['uname']}",
                                        rows=0,
                                        as_obj=False)
                                    if res['total'] > 0:
                                        cnt = res['total']
                                        new_uname = f"{data['uname']}{cnt}"
                                        while STORAGE.user.get(
                                                new_uname) is not None:
                                            cnt += 1
                                            new_uname = f"{data['uname']}{cnt}"
                                        data['uname'] = new_uname
                                cur_user = {}

                            username = data['uname']

                            # Make sure the user exists in AL and is in sync
                            if (not cur_user and oauth_provider_config.auto_create) or \
                                    (cur_user and oauth_provider_config.auto_sync):

                                # Update the current user
                                cur_user.update(data)

                                # Save avatar
                                if oauth_avatar:
                                    avatar = fetch_avatar(
                                        oauth_avatar, provider,
                                        oauth_provider_config)
                                    if avatar:
                                        STORAGE.user_avatar.save(
                                            username, avatar)

                                # Save updated user
                                STORAGE.user.save(username, cur_user)

                            if cur_user:
                                if avatar is None:
                                    avatar = STORAGE.user_avatar.get(
                                        username
                                    ) or "/static/images/user_default.png"
                                oauth_token = hashlib.sha256(
                                    str(token).encode(
                                        "utf-8",
                                        errors='replace')).hexdigest()
                                get_token_store(username).add(oauth_token)
                            else:
                                oauth_validation = False
                                avatar = None
                                username = ''
                                oauth_error = "User auto-creation is disabled"
                        else:
                            oauth_validation = False
                            oauth_error = "This user is not allowed access to the system"

                except Exception as _:
                    oauth_validation = False
                    oauth_error = "Invalid oAuth2 token, try again"
    else:
        providers = str([])

    return custom_render("login.html",
                         next=next_url,
                         avatar=avatar,
                         username=username,
                         oauth_error=oauth_error,
                         oauth_token=oauth_token,
                         providers=providers,
                         signup=config.auth.internal.enabled
                         and config.auth.internal.signup.enabled,
                         oauth_validation=str(oauth_validation).lower(),
                         up_login=str(up_login).lower())
Ejemplo n.º 22
0
def report(**kwargs):
    sid = angular_safe(request.args.get("sid", None))
    return custom_render("report.html", sid=sid, **kwargs)
Ejemplo n.º 23
0
def workflows(**kwargs):
    return custom_render("workflows.html", **kwargs)
Ejemplo n.º 24
0
def signatures(**kwargs):
    return custom_render("signatures.html", org=ORGANISATION, **kwargs)
Ejemplo n.º 25
0
def admin_errors(**kwargs):
    query = angular_safe(request.args.get('filter', ""))
    return custom_render("admin_errors.html", filter=query, **kwargs)
Ejemplo n.º 26
0
def signature_management(**kwargs):
    return custom_render("source_management.html", **kwargs)
Ejemplo n.º 27
0
def admin_site_map(**kwargs):
    return custom_render("admin_site_map.html", **kwargs)
Ejemplo n.º 28
0
def signature_statistics(*_, **kwargs):
    return custom_render("signature_statistics.html", **kwargs)
Ejemplo n.º 29
0
def api_doc(**kwargs):
    return custom_render("api_doc.html", **kwargs)
Ejemplo n.º 30
0
def account(**kwargs):
    return custom_render("account.html", **kwargs)