Delay results

This commit is contained in:
Mark Veidemanis 2022-08-27 12:53:37 +01:00
parent 0eda404732
commit a2d572baf4
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
5 changed files with 61 additions and 4 deletions

View File

@ -38,6 +38,10 @@ OBFUSCATE_COLON_NUM = 1
SEARCH_FIELDS_DENY = ["ts", "date", "time"] SEARCH_FIELDS_DENY = ["ts", "date", "time"]
DELAY_RESULTS = True
# Delay results by this many days
DELAY_DURATION = 10
# Common to encryption and hashing # Common to encryption and hashing
WHITELIST_FIELDS = [ WHITELIST_FIELDS = [
"ts", "ts",
@ -58,7 +62,7 @@ WHITELIST_FIELDS = [
# Don't obfuscate these parameters, or lookup hashes in them # Don't obfuscate these parameters, or lookup hashes in them
NO_OBFUSCATE_PARAMS = [ NO_OBFUSCATE_PARAMS = [
"query", "query",
# "query_full", # "query_full",
"size", "size",
"source", "source",
"sorting", "sorting",

View File

@ -1,4 +1,5 @@
from copy import deepcopy from copy import deepcopy
from datetime import datetime, timedelta
from django.conf import settings from django.conf import settings
from opensearchpy import OpenSearch from opensearchpy import OpenSearch
@ -327,8 +328,8 @@ def query_results(
elif isinstance(x, LookupDenied): elif isinstance(x, LookupDenied):
message += f"Lookup({x.key}: {x.value}) " message += f"Lookup({x.key}: {x.value}) "
if denied: if denied:
#message = [f"{i}" for i in message] # message = [f"{i}" for i in message]
#message = "\n".join(message) # message = "\n".join(message)
message_class = "danger" message_class = "danger"
return {"message": message, "class": message_class} return {"message": message, "class": message_class}
@ -353,6 +354,8 @@ def query_results(
return {"message": message, "class": message_class} return {"message": message, "class": message_class}
if source != "all": if source != "all":
add_bool.append({"src": source}) add_bool.append({"src": source})
date_query = False
if set({"from_date", "to_date", "from_time", "to_time"}).issubset( if set({"from_date", "to_date", "from_time", "to_time"}).issubset(
query_params.keys() query_params.keys()
): ):
@ -366,7 +369,31 @@ def query_results(
} }
} }
} }
add_top.append(range_query) if not settings.DELAY_RESULTS:
add_top.append(range_query)
else:
date_query = True
if settings.DELAY_RESULTS:
if date_query:
if not request.user.has_perm("bypass_delay"):
delay_as_ts = datetime.now() - timedelta(days=settings.DELAY_DURATION)
lt_as_ts = datetime.strptime(
range_query["range"]["ts"]["lt"], "%Y-%m-%dT%H:%MZ"
)
if lt_as_ts > delay_as_ts:
range_query["range"]["ts"]["lt"] = f"now-{settings.DELAY_DURATION}d"
add_top.append(range_query)
else:
range_query = {
"range": {
"ts": {
# "gt": ,
"lt": f"now-{settings.DELAY_DURATION}d",
}
}
}
add_top.append(range_query)
if "sorting" in query_params: if "sorting" in query_params:
sorting = query_params["sorting"] sorting = query_params["sorting"]
if sorting not in ("asc", "desc", "none"): if sorting not in ("asc", "desc", "none"):
@ -556,6 +583,9 @@ def query_results(
} }
if query: if query:
context["query"] = query context["query"] = query
if settings.DELAY_RESULTS:
if not request.user.has_perm("bypass_delay"):
context["delay"] = settings.DELAY_DURATION
return context return context

View File

@ -0,0 +1,17 @@
# Generated by Django 4.0.6 on 2022-08-27 11:50
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0007_perms'),
]
operations = [
migrations.AlterModelOptions(
name='perms',
options={'permissions': (('bypass_hashing', 'Can bypass field hashing'), ('bypass_blacklist', 'Can bypass the blacklist'), ('bypass_encryption', 'Can bypass field encryption'), ('bypass_obfuscation', 'Can bypass field obfuscation'), ('bypass_delay', 'Can bypass data delay'), ('post_irc', 'Can post to IRC'), ('post_discord', 'Can post to Discord'), ('query_search', 'Can search with query strings'), ('use_insights', 'Can use the Insights page'), ('index_int', 'Can use the internal index'), ('index_meta', 'Can use the meta index'))},
),
]

View File

@ -111,6 +111,7 @@ class Perms(models.Model):
("bypass_blacklist", "Can bypass the blacklist"), ("bypass_blacklist", "Can bypass the blacklist"),
("bypass_encryption", "Can bypass field encryption"), ("bypass_encryption", "Can bypass field encryption"),
("bypass_obfuscation", "Can bypass field obfuscation"), ("bypass_obfuscation", "Can bypass field obfuscation"),
("bypass_delay", "Can bypass data delay"),
("post_irc", "Can post to IRC"), ("post_irc", "Can post to IRC"),
("post_discord", "Can post to Discord"), ("post_discord", "Can post to Discord"),
("query_search", "Can search with query strings"), ("query_search", "Can search with query strings"),

View File

@ -26,6 +26,11 @@
</div> </div>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if delay is not None %}
<div class="nowrap-child">
<p>delayed by {{ delay }} days</p>
</div>
{% endif %}
</div> </div>
{% if params.index != 'int' and params.index != 'meta' %} {% if params.index != 'int' and params.index != 'meta' %}
<div class="box"> <div class="box">