diff --git a/app/urls.py b/app/urls.py index c45c264..0ecc1c4 100644 --- a/app/urls.py +++ b/app/urls.py @@ -253,7 +253,7 @@ urlpatterns = [ name="threshold_irc_network_list", ), path( - "manage/threshold/irc/msg///", + "manage/threshold/irc/msg///", ThresholdIRCSendMessage.as_view(), name="threshold_irc_msg", ), diff --git a/core/__init__.py b/core/__init__.py index f4247b9..73d371f 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,5 +1,8 @@ import stripe from django.conf import settings +from redis import StrictRedis + +r = StrictRedis(unix_socket_path="/var/run/redis/redis.sock", db=0) if settings.STRIPE_TEST: stripe.api_key = settings.STRIPE_API_KEY_TEST diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index 1b3db72..abe0912 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -1,9 +1,11 @@ +from copy import deepcopy + from django.conf import settings from opensearchpy import OpenSearch from opensearchpy.exceptions import NotFoundError, RequestError from core.lib.threshold import annotate_num_chans, annotate_num_users, annotate_online -from core.views.helpers import dedup_list +from core.views.helpers import dedup_list, encrypt_list, hash_list, hash_lookup def initialise_opensearch(): @@ -258,6 +260,7 @@ def query_results( reverse=False, dedup=False, dedup_fields=None, + lookup_hashes=True, ): """ API helper to alter the OpenSearch return format into something @@ -273,6 +276,13 @@ def query_results( add_top = [] add_top_negative = [] sort = None + + # Lookup the hash values but don't disclose them to the user + if lookup_hashes: + if settings.HASHING: + query_params = deepcopy(query_params) + hash_lookup(query_params) + if request.user.is_anonymous: sizes = settings.OPENSEARCH_MAIN_SIZES_ANON else: @@ -397,6 +407,7 @@ def query_results( return {"message": message, "class": message_class} else: index = settings.OPENSEARCH_INDEX_MAIN + results = run_main_query( client, request.user, # passed through run_main_query to filter_blacklisted @@ -436,6 +447,15 @@ def query_results( dedup_fields = ["msg", "nick", "ident", "host", "net", "channel"] results_parsed = dedup_list(results_parsed, dedup_fields) + if settings.ENCRYPTION: + encrypt_list(results_parsed, settings.ENCRYPTION_KEY) + + if settings.HASHING: + hash_list(results_parsed) + + # process_list(reqults) + + # IMPORTANT! - DO NOT PASS query_params to the user! context = { "object_list": results_parsed, "card": results["hits"]["total"]["value"], diff --git a/core/static/js/column-shifter.js b/core/static/js/column-shifter.js index f454f00..d56ba4b 100644 --- a/core/static/js/column-shifter.js +++ b/core/static/js/column-shifter.js @@ -44,9 +44,8 @@ $(document).ready(function(){ "num_users": "off", "num_chans": "off", "exemption": "off", - "version_sentiment": "off", + // "version_sentiment": "off", "num": "off", - "exemption": "off", "online": "off", "mtype": "off", "realname": "off", diff --git a/core/templates/ui/drilldown/drilldown.html b/core/templates/ui/drilldown/drilldown.html index 458ceb7..e3418ba 100644 --- a/core/templates/ui/drilldown/drilldown.html +++ b/core/templates/ui/drilldown/drilldown.html @@ -49,8 +49,15 @@ populateSearch(field, value); }); } + var plain_fields = ["ts", "date", "time", "sentiment", "version_sentiment", "tokens", "num_chans", "num_users", "tokens", "src", "exemption", "hidden"]; function populateSearch(field, value) { var queryElement = document.getElementById('query'); + + if (!plain_fields.includes(field)) { + if (!value.startsWith("|") && !value.endsWith("|")) { + value = `|${value}|`; + } + } var present = true; if (present == true) { var combinations = [`${field}: "${value}"`, diff --git a/core/templates/ui/drilldown/table_results_partial.html b/core/templates/ui/drilldown/table_results_partial.html index 7313085..68fcc6f 100644 --- a/core/templates/ui/drilldown/table_results_partial.html +++ b/core/templates/ui/drilldown/table_results_partial.html @@ -238,16 +238,16 @@ class="has-text-grey is-underlined" hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-post="{% url 'modal_context' %}" - hx-vals='{"net": "{{ row.cells.net|escapejs }}", - "num": "{{ row.cells.num|escapejs }}", + hx-vals='{"net": "|{{ row.cells.net|escapejs }}|", + "num": "|{{ row.cells.num|escapejs }}|", "src": "{{ row.cells.src|escapejs }}", - "channel": "{{ row.cells.channel|escapejs }}", + "channel": "|{{ row.cells.channel|escapejs }}|", "time": "{{ row.cells.time|escapejs }}", "date": "{{ row.cells.date|escapejs }}", "index": "{{ params.index }}", - "type": "{{ row.cells.type }}", + "type": "|{{ row.cells.type }}|", "mtype": "{{ row.cells.mtype }}", - "nick": "{{ row.cells.nick|escapejs }}", + "nick": "|{{ row.cells.nick|escapejs }}|", "dedup": "{{ params.dedup }}"}' hx-target="#modals-here" hx-trigger="click" @@ -281,7 +281,7 @@