diff --git a/app/urls.py b/app/urls.py index 0f04ee6..81c531e 100644 --- a/app/urls.py +++ b/app/urls.py @@ -38,12 +38,15 @@ from core.views.dynamic.insights import ( InsightsSearch, ) from core.views.dynamic.manage.threshold.irc import ( + ThresholdIRCNetworkChannels, + ThresholdIRCNetworkInfo, + ThresholdIRCNetworkRelays, ThresholdIRCNetworks, ThresholdIRCStats, ) # Management stuff -from core.views.manage.threshold import ThresholdIRCOverview +from core.views.manage.threshold import ThresholdIRCNetwork, ThresholdIRCOverview urlpatterns = [ path("", Home.as_view(), name="home"), @@ -81,15 +84,35 @@ urlpatterns = [ name="threshold_irc_overview", ), path( - "manage/threshold/irc/stats/", + "manage/threshold/irc/overview/stats/", ThresholdIRCStats.as_view(), name="threshold_irc_stats", ), path( - "manage/threshold/irc/networks/", + "manage/threshold/irc/overview/networks/", ThresholdIRCNetworks.as_view(), name="threshold_irc_networks", ), + path( + "manage/threshold/irc/network//", + ThresholdIRCNetwork.as_view(), + name="threshold_irc_network", + ), + path( + "manage/threshold/irc/network//info/", + ThresholdIRCNetworkInfo.as_view(), + name="threshold_irc_network_info", + ), + path( + "manage/threshold/irc/network//relays/", + ThresholdIRCNetworkRelays.as_view(), + name="threshold_irc_network_relays", + ), + path( + "manage/threshold/irc/network//channels/", + ThresholdIRCNetworkChannels.as_view(), + name="threshold_irc_network_channels", + ), ## path("api/chans/", ThresholdChans.as_view(), name="chans"), path("api/users/", ThresholdUsers.as_view(), name="users"), diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 63ac178..7138be1 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -17,3 +17,30 @@ def get_irc_networks(): if not networks: return {} return networks + + +def get_irc_network(net): + url = f"irc/network/{net}" + payload = {} + network = threshold_request(url, payload) + if not network: + return {} + return network + + +def get_irc_relays(net): + url = f"irc/network/{net}/relays" + payload = {} + relays = threshold_request(url, payload) + if not relays: + return [] + return relays + + +def get_irc_channels(net): + url = f"irc/network/{net}/channels" + payload = {} + channels = threshold_request(url, payload) + if not channels: + return [] + return channels diff --git a/core/lib/meta.py b/core/lib/meta.py index 231518e..5a368ea 100644 --- a/core/lib/meta.py +++ b/core/lib/meta.py @@ -10,7 +10,6 @@ def construct_query(net, nicks): # Construct the query query_nicks = [{"match": {"nick": x}} for x in nicks] query_should = query_nicks - # print("QUERY SHOULD", query_should) # Get the initial query query = { "size": settings.META_QUERY_SIZE, diff --git a/core/lib/nicktrace.py b/core/lib/nicktrace.py index 8c0137f..e7022ae 100644 --- a/core/lib/nicktrace.py +++ b/core/lib/nicktrace.py @@ -11,7 +11,6 @@ def construct_query(net, nicks): query_nicks = [{"match": {"nick": x}} for x in nicks] query_users = [{"match": {"user": x}} for x in nicks] query_should = query_nicks + query_users - # print("QUERY SHOULD", query_should) # Get the initial query query = { "size": settings.NICKTRACE_QUERY_SIZE, diff --git a/core/lib/threshold.py b/core/lib/threshold.py index e2e9bbd..e4cf70e 100644 --- a/core/lib/threshold.py +++ b/core/lib/threshold.py @@ -1,5 +1,7 @@ import logging from json import dumps +from operator import itemgetter +from typing import OrderedDict import requests from django.conf import settings @@ -27,6 +29,12 @@ def sort_data(data): for item in data: if isinstance(data[item], list): data[item].sort() + elif isinstance(data[item], dict): + + # if all([isinstance(x, int) for k, v in + # data[item].items() for x in v.values()]): + sorted_item = sorted(data[item].items(), key=itemgetter(1), reverse=True) + data[item] = OrderedDict({k: v for k, v in sorted_item}) def threshold_request(url, data): diff --git a/core/templates/dynamic/manage/threshold/irc/network/channels.html b/core/templates/dynamic/manage/threshold/irc/network/channels.html new file mode 100644 index 0000000..5b92247 --- /dev/null +++ b/core/templates/dynamic/manage/threshold/irc/network/channels.html @@ -0,0 +1,22 @@ +
+ {% if channels is not None %} +
+
+ + + {% for channel, info in channels.items %} + + + + {% endfor %} + +
+ {{ channel }} + + {{ info }} + +
+
+
+ {% endif %} +
\ No newline at end of file diff --git a/core/templates/dynamic/manage/threshold/irc/network/info.html b/core/templates/dynamic/manage/threshold/irc/network/info.html new file mode 100644 index 0000000..a6f4212 --- /dev/null +++ b/core/templates/dynamic/manage/threshold/irc/network/info.html @@ -0,0 +1,51 @@ +
+ {% if network is not None %} +
+
+ + + + + + + {% for key, item in network.items %} + + + + + {% endfor %} + +
attributevalue
{{ key }} + {% if key == 'security' %} + {% if item == 'none' %} + + + + {% elif item == 'ssl' %} + + + + {% endif %} + {% elif key == 'relays' %} + + + + {% elif key == 'channels' %} + + + + {% elif key == 'records' %} + + + + {% elif key == 'host' %} + + + + {% endif %} + {{ item }} +
+
+
+ {% endif %} +
\ No newline at end of file diff --git a/core/templates/dynamic/manage/threshold/irc/network/relays.html b/core/templates/dynamic/manage/threshold/irc/network/relays.html new file mode 100644 index 0000000..266a91a --- /dev/null +++ b/core/templates/dynamic/manage/threshold/irc/network/relays.html @@ -0,0 +1,59 @@ +
+ {% if relays is not None %} +
+
+ + + + + + + + + + + {% for relay in relays %} + + + + + + + + + {% endfor %} + +
netidregisteredenabled + + + + nick
{{ relay.net }}{{ relay.id }} + {% if relay.registered %} + + + + {% else %} + + + + {% endif %} + + {% if relay.enabled %} + + + + {% else %} + + + + {% endif %} + + + {{ relay.chans }} + + {{ relay.nick }} +
+
+
+ {% endif %} +
\ No newline at end of file diff --git a/core/templates/dynamic/manage/threshold/irc/networks.html b/core/templates/dynamic/manage/threshold/irc/overview/networks.html similarity index 77% rename from core/templates/dynamic/manage/threshold/irc/networks.html rename to core/templates/dynamic/manage/threshold/irc/overview/networks.html index e7943cc..bfc3f06 100644 --- a/core/templates/dynamic/manage/threshold/irc/networks.html +++ b/core/templates/dynamic/manage/threshold/irc/overview/networks.html @@ -9,21 +9,21 @@ {% for key, net in networks.items %} - {{ key }} + {{ key }} - + {{ net.relays }} - + {{ net.channels }} - + {{ net.records }} diff --git a/core/templates/dynamic/manage/threshold/irc/stats.html b/core/templates/dynamic/manage/threshold/irc/overview/stats.html similarity index 100% rename from core/templates/dynamic/manage/threshold/irc/stats.html rename to core/templates/dynamic/manage/threshold/irc/overview/stats.html diff --git a/core/templates/manage/threshold/irc/network.html b/core/templates/manage/threshold/irc/network.html new file mode 100644 index 0000000..18c6600 --- /dev/null +++ b/core/templates/manage/threshold/irc/network.html @@ -0,0 +1,60 @@ +{% extends "base.html" %} +{% block content %} + +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+{% endblock %} diff --git a/core/views/dynamic/manage/threshold/irc.py b/core/views/dynamic/manage/threshold/irc.py index 288087f..9125f07 100644 --- a/core/views/dynamic/manage/threshold/irc.py +++ b/core/views/dynamic/manage/threshold/irc.py @@ -1,12 +1,18 @@ from django.shortcuts import render from django.views import View -from core.lib.manage.threshold import get_irc_networks, get_irc_stats +from core.lib.manage.threshold import ( + get_irc_channels, + get_irc_network, + get_irc_networks, + get_irc_relays, + get_irc_stats, +) from core.views.manage.permissions import SuperUserRequiredMixin class ThresholdIRCStats(SuperUserRequiredMixin, View): - stats_template = "dynamic/manage/threshold/irc/stats.html" + stats_template = "dynamic/manage/threshold/irc/overview/stats.html" def post(self, request): stats = get_irc_stats() @@ -15,9 +21,36 @@ class ThresholdIRCStats(SuperUserRequiredMixin, View): class ThresholdIRCNetworks(SuperUserRequiredMixin, View): - stats_template = "dynamic/manage/threshold/irc/networks.html" + template_name = "dynamic/manage/threshold/irc/overview/networks.html" def post(self, request): - stats = get_irc_networks() - context = {"networks": stats} - return render(request, self.stats_template, context) + networks = get_irc_networks() + context = {"networks": networks} + return render(request, self.template_name, context) + + +class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View): + template_name = "dynamic/manage/threshold/irc/network/info.html" + + def post(self, request, net): + network = get_irc_network(net) + context = {"network": network} + return render(request, self.template_name, context) + + +class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View): + template_name = "dynamic/manage/threshold/irc/network/relays.html" + + def post(self, request, net): + relays = get_irc_relays(net) + context = {"relays": relays["relays"]} + return render(request, self.template_name, context) + + +class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, View): + template_name = "dynamic/manage/threshold/irc/network/channels.html" + + def post(self, request, net): + channels = get_irc_channels(net) + context = {"channels": channels["channels"]} + return render(request, self.template_name, context) diff --git a/core/views/manage/threshold.py b/core/views/manage/threshold.py index b11eb3b..2a93cb6 100644 --- a/core/views/manage/threshold.py +++ b/core/views/manage/threshold.py @@ -9,3 +9,11 @@ class ThresholdIRCOverview(SuperUserRequiredMixin, View): def get(self, request): return render(request, self.template_name) + + +class ThresholdIRCNetwork(SuperUserRequiredMixin, View): + template_name = "manage/threshold/irc/network.html" + + def get(self, request, net): + context = {"net": net} + return render(request, self.template_name, context)