2022-07-25 17:03:10 +00:00
|
|
|
from django.shortcuts import render
|
2022-07-25 18:08:28 +00:00
|
|
|
from django.views import View
|
2022-07-27 07:29:20 +00:00
|
|
|
from rest_framework.parsers import FormParser
|
|
|
|
from rest_framework.views import APIView
|
2022-07-25 18:08:28 +00:00
|
|
|
|
2022-07-26 21:15:30 +00:00
|
|
|
from core.lib.manage.threshold import (
|
2022-07-27 07:58:57 +00:00
|
|
|
edit_irc_network,
|
2022-07-26 21:15:30 +00:00
|
|
|
get_irc_channels,
|
|
|
|
get_irc_network,
|
|
|
|
get_irc_networks,
|
|
|
|
get_irc_relays,
|
|
|
|
get_irc_stats,
|
|
|
|
)
|
2022-07-25 17:03:10 +00:00
|
|
|
from core.views.manage.permissions import SuperUserRequiredMixin
|
2022-07-25 18:08:28 +00:00
|
|
|
|
2022-07-25 17:03:10 +00:00
|
|
|
|
|
|
|
class ThresholdIRCStats(SuperUserRequiredMixin, View):
|
2022-07-27 12:12:16 +00:00
|
|
|
stats_template = "manage/threshold/irc/overview/stats.html"
|
2022-07-25 17:03:10 +00:00
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
stats = get_irc_stats()
|
|
|
|
context = {"stats": stats}
|
|
|
|
return render(request, self.stats_template, context)
|
|
|
|
|
|
|
|
|
|
|
|
class ThresholdIRCNetworks(SuperUserRequiredMixin, View):
|
2022-07-27 12:12:16 +00:00
|
|
|
template_name = "manage/threshold/irc/overview/networks.html"
|
2022-07-25 17:03:10 +00:00
|
|
|
|
|
|
|
def post(self, request):
|
2022-07-26 21:15:30 +00:00
|
|
|
networks = get_irc_networks()
|
|
|
|
context = {"networks": networks}
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
|
|
|
|
class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View):
|
2022-07-27 12:12:16 +00:00
|
|
|
template_name = "manage/threshold/irc/network/info.html"
|
2022-07-26 21:15:30 +00:00
|
|
|
|
|
|
|
def post(self, request, net):
|
|
|
|
network = get_irc_network(net)
|
|
|
|
context = {"network": network}
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
|
2022-07-27 07:29:20 +00:00
|
|
|
class ThresholdIRCNetworkInfoEdit(SuperUserRequiredMixin, APIView):
|
2022-07-27 12:12:16 +00:00
|
|
|
template_name = "manage/threshold/irc/network/edit-network.html"
|
2022-07-27 07:29:20 +00:00
|
|
|
parser_classes = [FormParser]
|
|
|
|
|
|
|
|
def get(self, request, net):
|
|
|
|
"""
|
|
|
|
Return the form to edit a network.
|
|
|
|
"""
|
|
|
|
network = get_irc_network(net)
|
|
|
|
editable = ["auth", "host", "last", "port", "security"]
|
|
|
|
context = {
|
|
|
|
"net": net,
|
|
|
|
"network": {k: v for k, v in network.items() if k in editable},
|
|
|
|
}
|
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
|
|
|
def post(self, request, net):
|
|
|
|
"""
|
|
|
|
Actually edit the network.
|
|
|
|
Returns the info pane with a message about the success.
|
|
|
|
"""
|
2022-07-27 12:12:16 +00:00
|
|
|
template_name = "manage/threshold/irc/network/info.html"
|
2022-07-27 07:58:57 +00:00
|
|
|
edited = edit_irc_network(net, request.data)
|
|
|
|
if edited["success"]:
|
|
|
|
message = "Successfully edited!"
|
|
|
|
message_class = "success"
|
|
|
|
else:
|
|
|
|
if "reason" in edited:
|
|
|
|
message = f"Error editing network: {edited['reason']}"
|
|
|
|
else:
|
|
|
|
message = "Error editing network"
|
|
|
|
message_class = "danger"
|
2022-07-27 07:29:20 +00:00
|
|
|
network = get_irc_network(net)
|
2022-07-27 07:58:57 +00:00
|
|
|
context = {"network": network, "message": message, "class": message_class}
|
2022-07-27 07:29:20 +00:00
|
|
|
return render(request, template_name, context)
|
|
|
|
|
|
|
|
|
2022-07-26 21:15:30 +00:00
|
|
|
class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View):
|
2022-07-27 12:12:16 +00:00
|
|
|
template_name = "manage/threshold/irc/network/relays.html"
|
2022-07-26 21:15:30 +00:00
|
|
|
|
|
|
|
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):
|
2022-07-27 12:12:16 +00:00
|
|
|
template_name = "manage/threshold/irc/network/channels.html"
|
2022-07-26 21:15:30 +00:00
|
|
|
|
|
|
|
def post(self, request, net):
|
|
|
|
channels = get_irc_channels(net)
|
|
|
|
context = {"channels": channels["channels"]}
|
|
|
|
return render(request, self.template_name, context)
|