diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index 4843b9c..57ec06d 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -351,6 +351,7 @@ def query_results( return {"message": message, "class": message_class} else: size = 20 + source = None if "source" in query_params: source = query_params["source"] if source not in settings.OPENSEARCH_MAIN_SOURCES: @@ -378,30 +379,36 @@ def query_results( if date_query: if settings.DELAY_RESULTS: - if request.user.has_perm("core.bypass_delay"): - add_top.append(range_query) - else: - 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) + if source not in settings.SAFE_SOURCES: + if request.user.has_perm("core.bypass_delay"): + add_top.append(range_query) + else: + 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: add_top.append(range_query) else: if settings.DELAY_RESULTS: - if not request.user.has_perm("core.bypass_delay"): - range_query = { - "range": { - "ts": { - # "gt": , - "lt": f"now-{settings.DELAY_DURATION}d", + if source not in settings.SAFE_SOURCES: + if not request.user.has_perm("core.bypass_delay"): + range_query = { + "range": { + "ts": { + # "gt": , + "lt": f"now-{settings.DELAY_DURATION}d", + } } } - } - add_top.append(range_query) + add_top.append(range_query) if "sorting" in query_params: sorting = query_params["sorting"] @@ -571,17 +578,18 @@ def query_results( dedup_fields = ["msg", "nick", "ident", "host", "net", "channel"] results_parsed = dedup_list(results_parsed, dedup_fields) - if settings.ENCRYPTION: - encrypt_list(request.user, results_parsed, settings.ENCRYPTION_KEY) + if source not in settings.SAFE_SOURCES: + if settings.ENCRYPTION: + encrypt_list(request.user, results_parsed, settings.ENCRYPTION_KEY) - if settings.HASHING: - hash_list(request.user, results_parsed) + if settings.HASHING: + hash_list(request.user, results_parsed) - if settings.OBFUSCATION: - obfuscate_list(request.user, results_parsed) + if settings.OBFUSCATION: + obfuscate_list(request.user, results_parsed) - if settings.RANDOMISATION: - randomise_list(request.user, results_parsed) + if settings.RANDOMISATION: + randomise_list(request.user, results_parsed) # process_list(reqults) @@ -596,11 +604,13 @@ def query_results( if query: context["query"] = query if settings.DELAY_RESULTS: - if not request.user.has_perm("core.bypass_delay"): - context["delay"] = settings.DELAY_DURATION + if source not in settings.SAFE_SOURCES: + if not request.user.has_perm("core.bypass_delay"): + context["delay"] = settings.DELAY_DURATION if settings.RANDOMISATION: - if not request.user.has_perm("core.bypass_randomisation"): - context["randomised"] = True + if source not in settings.SAFE_SOURCES: + if not request.user.has_perm("core.bypass_randomisation"): + context["randomised"] = True return context diff --git a/core/templates/modals/context.html b/core/templates/modals/context.html index 19a58ef..8fec36d 100644 --- a/core/templates/modals/context.html +++ b/core/templates/modals/context.html @@ -72,7 +72,7 @@