2022-08-03 08:24:13 +00:00
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
from core.lib.opensearch import client, run_main_query
|
2022-07-25 17:03:10 +00:00
|
|
|
from core.lib.threshold import threshold_request
|
|
|
|
|
2022-07-25 18:08:28 +00:00
|
|
|
|
2022-07-25 17:03:10 +00:00
|
|
|
def get_irc_stats():
|
|
|
|
url = "irc/stats"
|
|
|
|
payload = {}
|
|
|
|
stats = threshold_request(url, payload)
|
|
|
|
if not stats:
|
|
|
|
return {}
|
|
|
|
return stats
|
|
|
|
|
2022-07-25 18:08:28 +00:00
|
|
|
|
2022-07-25 17:03:10 +00:00
|
|
|
def get_irc_networks():
|
|
|
|
url = "irc/networks"
|
|
|
|
payload = {}
|
|
|
|
networks = threshold_request(url, payload)
|
|
|
|
if not networks:
|
|
|
|
return {}
|
2022-07-25 18:08:28 +00:00
|
|
|
return networks
|
2022-07-26 21:15:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_irc_network(net):
|
|
|
|
url = f"irc/network/{net}"
|
|
|
|
payload = {}
|
|
|
|
network = threshold_request(url, payload)
|
|
|
|
if not network:
|
|
|
|
return {}
|
|
|
|
return network
|
|
|
|
|
|
|
|
|
2022-07-27 07:58:57 +00:00
|
|
|
def edit_irc_network(net, data):
|
|
|
|
url = f"irc/network/{net}/edit"
|
|
|
|
payload = dict(data)
|
2022-07-27 19:53:41 +00:00
|
|
|
result = threshold_request(url, payload)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def change_network_status(net, num, status):
|
|
|
|
url = f"irc/network/{net}/{num}"
|
|
|
|
payload = {"status": status}
|
|
|
|
result = threshold_request(url, payload)
|
|
|
|
return result
|
2022-07-27 07:58:57 +00:00
|
|
|
|
|
|
|
|
2022-07-26 21:15:30 +00:00
|
|
|
def get_irc_relays(net):
|
|
|
|
url = f"irc/network/{net}/relays"
|
|
|
|
payload = {}
|
|
|
|
relays = threshold_request(url, payload)
|
|
|
|
if not relays:
|
2022-07-27 19:53:41 +00:00
|
|
|
return {}
|
2022-07-26 21:15:30 +00:00
|
|
|
return relays
|
|
|
|
|
|
|
|
|
|
|
|
def get_irc_channels(net):
|
|
|
|
url = f"irc/network/{net}/channels"
|
|
|
|
payload = {}
|
|
|
|
channels = threshold_request(url, payload)
|
|
|
|
if not channels:
|
2022-07-27 19:53:41 +00:00
|
|
|
return {}
|
2022-07-26 21:15:30 +00:00
|
|
|
return channels
|
2022-07-27 19:53:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def part_channel(net, channel):
|
2022-08-13 23:01:00 +00:00
|
|
|
url = f"irc/network/{net}/channel"
|
|
|
|
payload = {"channel": channel}
|
2022-07-27 19:53:41 +00:00
|
|
|
parted = threshold_request(url, payload, method="DELETE")
|
|
|
|
if not parted:
|
|
|
|
return {}
|
|
|
|
return parted
|
|
|
|
|
|
|
|
|
|
|
|
def join_channel(net, channel):
|
2022-08-14 08:24:21 +00:00
|
|
|
url = f"irc/network/{net}/channel"
|
|
|
|
payload = {"channel": channel}
|
2022-07-27 19:53:41 +00:00
|
|
|
joined = threshold_request(url, payload, method="PUT")
|
|
|
|
if not joined:
|
|
|
|
return {}
|
|
|
|
return joined
|
2022-07-29 21:22:22 +00:00
|
|
|
|
2022-07-29 16:28:41 +00:00
|
|
|
|
2022-07-29 21:22:22 +00:00
|
|
|
def get_aliases():
|
|
|
|
url = "aliases"
|
|
|
|
payload = {}
|
|
|
|
aliases = threshold_request(url, payload, method="GET")
|
|
|
|
return aliases
|
2022-07-29 16:28:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def add_relay(net, num):
|
2022-07-29 21:41:53 +00:00
|
|
|
if num:
|
|
|
|
url = f"irc/network/{net}/{num}"
|
|
|
|
else:
|
|
|
|
url = f"irc/network/{net}"
|
2022-07-29 16:28:41 +00:00
|
|
|
payload = {}
|
|
|
|
created = threshold_request(url, payload, method="PUT")
|
|
|
|
return created
|
2022-07-29 21:11:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def del_relay(net, num):
|
|
|
|
url = f"irc/network/{net}/{num}"
|
|
|
|
payload = {}
|
|
|
|
deleted = threshold_request(url, payload, method="DELETE")
|
|
|
|
return deleted
|
2022-08-01 18:06:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def update_aliases(aliases):
|
|
|
|
url = "aliases"
|
|
|
|
payload = aliases
|
|
|
|
deleted = threshold_request(url, payload, method="POST")
|
|
|
|
return deleted
|
2022-08-01 18:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def run_auto(net):
|
|
|
|
url = f"irc/auto/{net}"
|
|
|
|
payload = {}
|
|
|
|
deleted = threshold_request(url, payload, method="POST")
|
|
|
|
return deleted
|
2022-08-01 20:39:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def run_list(net):
|
|
|
|
url = f"irc/list/{net}"
|
|
|
|
payload = {}
|
|
|
|
ran = threshold_request(url, payload, method="POST")
|
|
|
|
return ran
|
2022-08-01 22:02:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_network(data):
|
|
|
|
url = "irc/network/create"
|
|
|
|
payload = data
|
|
|
|
ran = threshold_request(url, payload, method="PUT")
|
|
|
|
return ran
|
2022-08-02 08:04:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
def del_network(net):
|
|
|
|
url = f"irc/network/{net}"
|
|
|
|
payload = {}
|
|
|
|
deleted = threshold_request(url, payload, method="DELETE")
|
|
|
|
return deleted
|
2022-08-03 08:24:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
def construct_alert_query():
|
|
|
|
# Get the initial query
|
|
|
|
query = {
|
|
|
|
"size": 25,
|
|
|
|
"query": {
|
|
|
|
"bool": {
|
|
|
|
"must": [
|
|
|
|
{"match": {"src": "irc"}},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"sort": [
|
|
|
|
{
|
|
|
|
"ts": {
|
|
|
|
"order": "desc",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}
|
|
|
|
return query
|
|
|
|
|
|
|
|
|
|
|
|
def get_irc_alerts(user):
|
|
|
|
query = construct_alert_query()
|
|
|
|
results = run_main_query(
|
|
|
|
client,
|
|
|
|
user, # passed through run_main_query to filter_blacklisted
|
|
|
|
query,
|
|
|
|
custom_query=True,
|
|
|
|
index=settings.OPENSEARCH_INDEX_INT,
|
|
|
|
)
|
|
|
|
if not results:
|
|
|
|
return []
|
|
|
|
results_parsed = []
|
|
|
|
if "hits" in results.keys():
|
|
|
|
if "hits" in results["hits"]:
|
|
|
|
for item in results["hits"]["hits"]:
|
|
|
|
element = item["_source"]
|
|
|
|
element["id"] = item["_id"]
|
|
|
|
|
|
|
|
# Split the timestamp into date and time
|
|
|
|
ts = element["ts"]
|
|
|
|
ts_spl = ts.split("T")
|
|
|
|
date = ts_spl[0]
|
|
|
|
time = ts_spl[1]
|
|
|
|
element["date"] = date
|
|
|
|
element["time"] = time
|
|
|
|
results_parsed.append(element)
|
|
|
|
return results_parsed
|
2022-08-03 06:20:30 +00:00
|
|
|
|
|
|
|
|
2022-08-03 06:20:30 +00:00
|
|
|
def send_irc_message(net, num, channel, msg, nick=None):
|
2022-08-14 15:45:48 +00:00
|
|
|
url = f"irc/msg/{net}/{num}"
|
|
|
|
payload = {"msg": msg, "channel": channel}
|
2022-08-03 06:20:30 +00:00
|
|
|
if nick:
|
|
|
|
payload["nick"] = nick
|
2022-08-03 06:20:30 +00:00
|
|
|
messaged = threshold_request(url, payload, method="PUT")
|
|
|
|
return messaged
|
2022-08-03 06:20:30 +00:00
|
|
|
|
2022-08-12 19:45:25 +00:00
|
|
|
|
2022-08-03 06:20:30 +00:00
|
|
|
def get_irc_nick(net, num):
|
|
|
|
url = f"irc/nick/{net}/{num}"
|
|
|
|
payload = {}
|
|
|
|
nick = threshold_request(url, payload, method="GET")
|
2022-08-12 19:45:25 +00:00
|
|
|
return nick
|
2022-08-13 12:27:49 +00:00
|
|
|
|
2022-08-13 12:32:03 +00:00
|
|
|
|
2022-08-13 12:27:49 +00:00
|
|
|
def get_irc_list_info(net):
|
|
|
|
url = f"irc/list/{net}"
|
|
|
|
payload = {}
|
|
|
|
listinfo = threshold_request(url, payload, method="GET")
|
2022-08-13 12:32:03 +00:00
|
|
|
return listinfo
|
2022-08-13 19:35:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def irc_get_unreg(net=None):
|
|
|
|
if net:
|
|
|
|
url = f"irc/reg/{net}"
|
|
|
|
else:
|
|
|
|
url = "irc/reg"
|
|
|
|
payload = {}
|
|
|
|
unreg = threshold_request(url, payload, method="GET")
|
|
|
|
return unreg
|
|
|
|
|
|
|
|
|
|
|
|
def irc_confirm_accounts(tokens):
|
|
|
|
url = "irc/reg"
|
|
|
|
payload = tokens
|
|
|
|
updated = threshold_request(url, payload, method="PUT")
|
|
|
|
return updated
|
2022-08-13 19:51:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def irc_provision_relay(net, num):
|
|
|
|
url = f"irc/network/{net}/{num}/provision"
|
|
|
|
payload = {}
|
|
|
|
provisioned = threshold_request(url, payload, method="POST")
|
|
|
|
return provisioned
|
2022-08-13 21:25:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def irc_enable_auth(net, num):
|
|
|
|
url = f"irc/network/{net}/{num}/auth"
|
|
|
|
payload = {}
|
|
|
|
enabled = threshold_request(url, payload, method="POST")
|
|
|
|
return enabled
|
2022-08-14 11:43:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
def irc_check_auth(data):
|
|
|
|
url = "irc/network/auth"
|
|
|
|
payload = data
|
|
|
|
updated = threshold_request(url, payload, method="POST")
|
|
|
|
return updated
|