diff --git a/app/urls.py b/app/urls.py index 75ee9d2..a74fc79 100644 --- a/app/urls.py +++ b/app/urls.py @@ -41,6 +41,7 @@ from core.views.manage.threshold.irc import ( ThresholdIRCNetworkRelayStatus, ThresholdIRCNetworks, ThresholdIRCOverviewAlerts, + ThresholdIRCSendMessage, ThresholdIRCStats, ) @@ -214,6 +215,11 @@ urlpatterns = [ ThresholdIRCNetworkActionsList.as_view(), name="threshold_irc_network_actions_list", ), + path( + "manage/threshold/irc/msg////", + ThresholdIRCSendMessage.as_view(), + name="threshold_irc_msg", + ), ## path("api/chans/", ThresholdChans.as_view(), name="chans"), path("api/users/", ThresholdUsers.as_view(), name="users"), diff --git a/core/lib/context.py b/core/lib/context.py index 9bb677e..6ece721 100644 --- a/core/lib/context.py +++ b/core/lib/context.py @@ -42,4 +42,5 @@ def construct_query(index, net, channel, src, num, size): "fields": fields, "_source": False, } + print("QUERY", query) return query diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 7576945..75792f8 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -193,3 +193,11 @@ def get_irc_alerts(user): element["time"] = time results_parsed.append(element) return results_parsed + + +def send_irc_message(net, num, channel, msg): + channel = urllib.parse.quote(channel, safe="") + url = f"irc/msg/{net}/{num}/{channel}" + payload = {"msg": msg} + messaged = threshold_request(url, payload, method="PUT") + return messaged diff --git a/core/templates/modals/context.html b/core/templates/modals/context.html index 1ce7488..2ca4cda 100644 --- a/core/templates/modals/context.html +++ b/core/templates/modals/context.html @@ -65,31 +65,32 @@

Scrollback of {{ channel }} on {{ net }}{{ num }}

{% include 'modals/context_table.html' %} -
-
- - - - -
-
-
- -
-
-
+ {% if user.is_superuser and src == 'irc' %} +
+
+
+ + + + +
+
+
+ +
+
+
+
+ {% endif %}
diff --git a/core/templates/partials/context-input.html b/core/templates/partials/context-input.html new file mode 100644 index 0000000..6897cc5 --- /dev/null +++ b/core/templates/partials/context-input.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/core/templates/partials/notify-alt.html b/core/templates/partials/notify-alt.html new file mode 100644 index 0000000..19dc36a --- /dev/null +++ b/core/templates/partials/notify-alt.html @@ -0,0 +1,5 @@ +{% if message is not None %} +
+ {{ message }} +
+{% endif %} diff --git a/core/templates/partials/notify.html b/core/templates/partials/notify.html index 80a3852..fb0587a 100644 --- a/core/templates/partials/notify.html +++ b/core/templates/partials/notify.html @@ -2,4 +2,4 @@
{{ message }}
-{% endif %} \ No newline at end of file +{% endif %} diff --git a/core/views/manage/threshold/irc.py b/core/views/manage/threshold/irc.py index d470a9f..24a4add 100644 --- a/core/views/manage/threshold/irc.py +++ b/core/views/manage/threshold/irc.py @@ -442,3 +442,39 @@ class ThresholdIRCNetworkActionsRelay(SuperUserRequiredMixin, APIView): "class": message_class, } return render(request, self.template_name, context) + + +class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView): + parser_classes = [FormParser] + template_name = "partials/context-input.html" + + def put(self, request, net, num, channel): + """ + Send a message + """ + if "msg" not in request.data: + message = "No message to send" + message_class = "danger" + return render( + request, + self.template_name, + {"message": message, "class": message_class}, + ) + + messaged = threshold.send_irc_message(net, num, channel, request.data["msg"]) + if not messaged: + message = "Failed to send message" + message_class = "danger" + elif messaged["success"]: + message = "Send message" + message_class = "success" + else: + message = messaged["reason"] + message_class = "danger" + + context = { + "net": net, + "message": message, + "class": message_class, + } + return render(request, self.template_name, context)