Reformat legacy project
This commit is contained in:
parent
19ee7071f5
commit
a198f2a487
|
@ -2,12 +2,11 @@ import functools
|
||||||
from json import JSONDecodeError, dumps, loads
|
from json import JSONDecodeError, dumps, loads
|
||||||
from string import digits
|
from string import digits
|
||||||
|
|
||||||
from klein import Klein
|
|
||||||
from twisted.web.server import Request
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
from klein import Klein
|
||||||
from modules import chankeep, helpers, provision, regproc, userinfo
|
from modules import chankeep, helpers, provision, regproc, userinfo
|
||||||
from modules.network import Network
|
from modules.network import Network
|
||||||
|
from twisted.web.server import Request
|
||||||
from utils.logging.log import warn
|
from utils.logging.log import warn
|
||||||
|
|
||||||
|
|
||||||
|
@ -217,7 +216,12 @@ class API(object):
|
||||||
for net_name in nets:
|
for net_name in nets:
|
||||||
conns = helpers.get_connected_relays(net_name)
|
conns = helpers.get_connected_relays(net_name)
|
||||||
if not conns:
|
if not conns:
|
||||||
return dumps({"success": False, "reason": f"failed to get instances for {net_name}."})
|
return dumps(
|
||||||
|
{
|
||||||
|
"success": False,
|
||||||
|
"reason": f"failed to get instances for {net_name}.",
|
||||||
|
}
|
||||||
|
)
|
||||||
if func == "recheckauth":
|
if func == "recheckauth":
|
||||||
for conn in conns:
|
for conn in conns:
|
||||||
conn.regPing(reset=True)
|
conn.regPing(reset=True)
|
||||||
|
@ -279,18 +283,24 @@ class API(object):
|
||||||
elif item == "last":
|
elif item == "last":
|
||||||
last = data[item][0]
|
last = data[item][0]
|
||||||
if not last.isdigit():
|
if not last.isdigit():
|
||||||
return dumps({"success": False, "reason": "invalid last: not a number."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "invalid last: not a number."}
|
||||||
|
)
|
||||||
elif item == "port":
|
elif item == "port":
|
||||||
port = data[item][0]
|
port = data[item][0]
|
||||||
if not port.isdigit():
|
if not port.isdigit():
|
||||||
return dumps({"success": False, "reason": "invalid port: not a number."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "invalid port: not a number."}
|
||||||
|
)
|
||||||
port = int(port)
|
port = int(port)
|
||||||
elif item == "chanlimit":
|
elif item == "chanlimit":
|
||||||
chanlimit = data[item][0]
|
chanlimit = data[item][0]
|
||||||
if chanlimit == "None":
|
if chanlimit == "None":
|
||||||
chanlimit = None
|
chanlimit = None
|
||||||
elif not chanlimit.isdigit():
|
elif not chanlimit.isdigit():
|
||||||
return dumps({"success": False, "reason": "invalid chanlimit: not a number."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "invalid chanlimit: not a number."}
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
chanlimit = int(chanlimit)
|
chanlimit = int(chanlimit)
|
||||||
online_relays = helpers.get_connected_relays(net)
|
online_relays = helpers.get_connected_relays(net)
|
||||||
|
@ -324,9 +334,16 @@ class API(object):
|
||||||
if item == "net":
|
if item == "net":
|
||||||
net = data[item]
|
net = data[item]
|
||||||
if net in main.network.keys():
|
if net in main.network.keys():
|
||||||
return dumps({"success": False, "reason": "network already exists."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "network already exists."}
|
||||||
|
)
|
||||||
if set(net).intersection(set(digits)):
|
if set(net).intersection(set(digits)):
|
||||||
return dumps({"success": False, "reason": "network name cannot contain numbers."})
|
return dumps(
|
||||||
|
{
|
||||||
|
"success": False,
|
||||||
|
"reason": "network name cannot contain numbers.",
|
||||||
|
}
|
||||||
|
)
|
||||||
elif item == "auth":
|
elif item == "auth":
|
||||||
auth = data[item]
|
auth = data[item]
|
||||||
if auth not in ["sasl", "ns", "none"]:
|
if auth not in ["sasl", "ns", "none"]:
|
||||||
|
@ -336,7 +353,9 @@ class API(object):
|
||||||
elif item == "port":
|
elif item == "port":
|
||||||
port = data[item]
|
port = data[item]
|
||||||
if not port.isdigit():
|
if not port.isdigit():
|
||||||
return dumps({"success": False, "reason": "invalid port: not a number."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "invalid port: not a number."}
|
||||||
|
)
|
||||||
port = int(port)
|
port = int(port)
|
||||||
elif item == "security":
|
elif item == "security":
|
||||||
security = data[item]
|
security = data[item]
|
||||||
|
@ -408,7 +427,9 @@ class API(object):
|
||||||
num = int(num)
|
num = int(num)
|
||||||
net_inst = main.network[net]
|
net_inst = main.network[net]
|
||||||
if num in net_inst.relays:
|
if num in net_inst.relays:
|
||||||
return dumps({"success": False, "reason": "network already has this relay."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "network already has this relay."}
|
||||||
|
)
|
||||||
id, alias = net_inst.add_relay(num)
|
id, alias = net_inst.add_relay(num)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
return dumps({"success": True, "id": id, "alias": alias})
|
return dumps({"success": True, "id": id, "alias": alias})
|
||||||
|
@ -433,7 +454,9 @@ class API(object):
|
||||||
num = int(num)
|
num = int(num)
|
||||||
net_inst = main.network[net]
|
net_inst = main.network[net]
|
||||||
if num not in net_inst.relays:
|
if num not in net_inst.relays:
|
||||||
return dumps({"success": False, "reason": "network does not have this relay."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "network does not have this relay."}
|
||||||
|
)
|
||||||
net_inst.delete_relay(num)
|
net_inst.delete_relay(num)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
return dumps({"success": True})
|
return dumps({"success": True})
|
||||||
|
@ -448,7 +471,9 @@ class API(object):
|
||||||
num = int(num)
|
num = int(num)
|
||||||
net_inst = main.network[net]
|
net_inst = main.network[net]
|
||||||
if num not in net_inst.relays:
|
if num not in net_inst.relays:
|
||||||
return dumps({"success": False, "reason": "network does not have this relay."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "network does not have this relay."}
|
||||||
|
)
|
||||||
provision.provisionRelay(num, net)
|
provision.provisionRelay(num, net)
|
||||||
return dumps({"success": True})
|
return dumps({"success": True})
|
||||||
|
|
||||||
|
@ -465,7 +490,11 @@ class API(object):
|
||||||
net_chans = main.IRCPool[name].channels
|
net_chans = main.IRCPool[name].channels
|
||||||
channels_annotated = userinfo.getUserNum(net, net_chans)
|
channels_annotated = userinfo.getUserNum(net, net_chans)
|
||||||
for channel in net_chans:
|
for channel in net_chans:
|
||||||
channel_inst = {"name": channel, "users": channels_annotated[channel], "num": num}
|
channel_inst = {
|
||||||
|
"name": channel,
|
||||||
|
"users": channels_annotated[channel],
|
||||||
|
"num": num,
|
||||||
|
}
|
||||||
channels.append(channel_inst)
|
channels.append(channel_inst)
|
||||||
# channels[channel] = channels_annotated[channel]
|
# channels[channel] = channels_annotated[channel]
|
||||||
|
|
||||||
|
@ -504,7 +533,9 @@ class API(object):
|
||||||
return dumps({"success": False, "reason": "no such net."})
|
return dumps({"success": False, "reason": "no such net."})
|
||||||
joined = chankeep.joinSingle(net, channel)
|
joined = chankeep.joinSingle(net, channel)
|
||||||
if not joined:
|
if not joined:
|
||||||
return dumps({"success": False, "reason": "could not allocate channel to relay."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "could not allocate channel to relay."}
|
||||||
|
)
|
||||||
return dumps({"success": True, "relays": joined})
|
return dumps({"success": True, "relays": joined})
|
||||||
|
|
||||||
@app.route("/irc/network/<net>/channel/<channel>/", methods=["PUT"])
|
@app.route("/irc/network/<net>/channel/<channel>/", methods=["PUT"])
|
||||||
|
@ -514,7 +545,9 @@ class API(object):
|
||||||
return dumps({"success": False, "reason": "no such net."})
|
return dumps({"success": False, "reason": "no such net."})
|
||||||
joined = chankeep.joinSingle(net, channel)
|
joined = chankeep.joinSingle(net, channel)
|
||||||
if not joined:
|
if not joined:
|
||||||
return dumps({"success": False, "reason": "could not allocate channel to relay."})
|
return dumps(
|
||||||
|
{"success": False, "reason": "could not allocate channel to relay."}
|
||||||
|
)
|
||||||
return dumps({"success": True, "relays": joined})
|
return dumps({"success": True, "relays": joined})
|
||||||
|
|
||||||
@app.route("/aliases/", methods=["GET"])
|
@app.route("/aliases/", methods=["GET"])
|
||||||
|
@ -563,7 +596,12 @@ class API(object):
|
||||||
provision.provisionRelay(num, net)
|
provision.provisionRelay(num, net)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
|
|
||||||
return dumps({"success": True, "message": f"created relay {num} with alias {alias} on {net}"})
|
return dumps(
|
||||||
|
{
|
||||||
|
"success": True,
|
||||||
|
"message": f"created relay {num} with alias {alias} on {net}",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@app.route("/irc/list/<net>/", methods=["POST"])
|
@app.route("/irc/list/<net>/", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -572,9 +610,16 @@ class API(object):
|
||||||
return dumps({"success": False, "reason": "no such net."})
|
return dumps({"success": False, "reason": "no such net."})
|
||||||
first_relay = helpers.get_first_relay(net)
|
first_relay = helpers.get_first_relay(net)
|
||||||
if not first_relay:
|
if not first_relay:
|
||||||
return dumps({"success": False, "reason": f"could not get first relay for {net}"})
|
return dumps(
|
||||||
|
{"success": False, "reason": f"could not get first relay for {net}"}
|
||||||
|
)
|
||||||
first_relay.list()
|
first_relay.list()
|
||||||
return dumps({"success": True, "message": f"requested list with instance {first_relay.num} of {net}"})
|
return dumps(
|
||||||
|
{
|
||||||
|
"success": True,
|
||||||
|
"message": f"requested list with instance {first_relay.num} of {net}",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@app.route("/irc/list/<net>/", methods=["GET"])
|
@app.route("/irc/list/<net>/", methods=["GET"])
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -623,7 +668,9 @@ class API(object):
|
||||||
main.IRCPool[name].sendmsg(nick, msg, in_query=in_query)
|
main.IRCPool[name].sendmsg(nick, msg, in_query=in_query)
|
||||||
else:
|
else:
|
||||||
main.IRCPool[name].sendmsg(channel, msg, in_query=in_query)
|
main.IRCPool[name].sendmsg(channel, msg, in_query=in_query)
|
||||||
return dumps({"success": True, "message": f"sent message to {channel} on {name}"})
|
return dumps(
|
||||||
|
{"success": True, "message": f"sent message to {channel} on {name}"}
|
||||||
|
)
|
||||||
|
|
||||||
@app.route("/irc/nick/<net>/<num>/", methods=["GET"])
|
@app.route("/irc/nick/<net>/<num>/", methods=["GET"])
|
||||||
@login_required
|
@login_required
|
||||||
|
|
|
@ -6,7 +6,9 @@ class AdmallCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.admall(*args)
|
self.admall(*args)
|
||||||
|
|
||||||
def admall(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def admall(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length > 2:
|
if length > 2:
|
||||||
for i in main.network.keys():
|
for i in main.network.keys():
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
from yaml import dump
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from modules import alias
|
from modules import alias
|
||||||
|
from yaml import dump
|
||||||
|
|
||||||
|
|
||||||
class AliasCommand:
|
class AliasCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.alias(*args)
|
self.alias(*args)
|
||||||
|
|
||||||
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def alias(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
info(dump(main.alias))
|
info(dump(main.alias))
|
||||||
|
|
|
@ -6,7 +6,9 @@ class AllCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.all(*args)
|
self.all(*args)
|
||||||
|
|
||||||
def all(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def all(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length > 2:
|
if length > 2:
|
||||||
for i in main.network.keys():
|
for i in main.network.keys():
|
||||||
|
@ -15,7 +17,10 @@ class AllCommand:
|
||||||
net = main.network[i].relays[x]["net"]
|
net = main.network[i].relays[x]["net"]
|
||||||
alias = main.alias[x]["nick"]
|
alias = main.alias[x]["nick"]
|
||||||
commands = {spl[1]: [" ".join(spl[2:])]}
|
commands = {spl[1]: [" ".join(spl[2:])]}
|
||||||
success("Sending commands to relay %s as user %s" % (num, alias + "/" + net))
|
success(
|
||||||
|
"Sending commands to relay %s as user %s"
|
||||||
|
% (num, alias + "/" + net)
|
||||||
|
)
|
||||||
deliverRelayCommands(num, commands, user=alias + "/" + net)
|
deliverRelayCommands(num, commands, user=alias + "/" + net)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -6,7 +6,9 @@ class AllcCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.allc(*args)
|
self.allc(*args)
|
||||||
|
|
||||||
def allc(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def allc(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length > 4:
|
if length > 4:
|
||||||
targets = []
|
targets = []
|
||||||
|
@ -20,7 +22,8 @@ class AllcCommand:
|
||||||
[
|
[
|
||||||
targets.append((i, x))
|
targets.append((i, x))
|
||||||
for x in main.alias.keys()
|
for x in main.alias.keys()
|
||||||
if main.alias[x]["nick"] == spl[2] and x in main.network[i].aliases.keys()
|
if main.alias[x]["nick"] == spl[2]
|
||||||
|
and x in main.network[i].aliases.keys()
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
incUsage("allc")
|
incUsage("allc")
|
||||||
|
@ -33,7 +36,10 @@ class AllcCommand:
|
||||||
num = i[1]
|
num = i[1]
|
||||||
alias = main.alias[num]["nick"]
|
alias = main.alias[num]["nick"]
|
||||||
commands = {spl[3]: [" ".join(spl[4:])]}
|
commands = {spl[3]: [" ".join(spl[4:])]}
|
||||||
success("Sending commands to relay %i as user %s" % (num, alias + "/" + net))
|
success(
|
||||||
|
"Sending commands to relay %i as user %s"
|
||||||
|
% (num, alias + "/" + net)
|
||||||
|
)
|
||||||
deliverRelayCommands(num, commands, user=alias + "/" + net)
|
deliverRelayCommands(num, commands, user=alias + "/" + net)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -5,7 +5,9 @@ class AuthcheckCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.authcheck(*args)
|
self.authcheck(*args)
|
||||||
|
|
||||||
def authcheck(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def authcheck(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
results = []
|
results = []
|
||||||
|
@ -13,7 +15,9 @@ class AuthcheckCommand:
|
||||||
num = main.IRCPool[i].num
|
num = main.IRCPool[i].num
|
||||||
net = main.IRCPool[i].net
|
net = main.IRCPool[i].net
|
||||||
if not main.IRCPool[i].authenticated:
|
if not main.IRCPool[i].authenticated:
|
||||||
results.append("%s - %s: %s" % (net, num, main.alias[num]["nick"]))
|
results.append(
|
||||||
|
"%s - %s: %s" % (net, num, main.alias[num]["nick"])
|
||||||
|
)
|
||||||
info("\n".join(results))
|
info("\n".join(results))
|
||||||
return
|
return
|
||||||
elif length == 2:
|
elif length == 2:
|
||||||
|
@ -27,7 +31,9 @@ class AuthcheckCommand:
|
||||||
if not net == spl[1]:
|
if not net == spl[1]:
|
||||||
continue
|
continue
|
||||||
if not main.IRCPool[i].authenticated:
|
if not main.IRCPool[i].authenticated:
|
||||||
results.append("%s - %s: %s" % (net, num, main.alias[num]["nick"]))
|
results.append(
|
||||||
|
"%s - %s: %s" % (net, num, main.alias[num]["nick"])
|
||||||
|
)
|
||||||
info("\n".join(results))
|
info("\n".join(results))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -6,7 +6,9 @@ class AutoCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.auto(*args)
|
self.auto(*args)
|
||||||
|
|
||||||
def auto(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def auto(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
for i in main.network.keys():
|
for i in main.network.keys():
|
||||||
|
@ -14,9 +16,15 @@ class AutoCommand:
|
||||||
info("Skipping %s - first relay exists" % i)
|
info("Skipping %s - first relay exists" % i)
|
||||||
else:
|
else:
|
||||||
num, alias = main.network[i].add_relay(1)
|
num, alias = main.network[i].add_relay(1)
|
||||||
success("Successfully created first relay on network %s with alias %s" % (i, alias))
|
success(
|
||||||
|
"Successfully created first relay on network %s with alias %s"
|
||||||
|
% (i, alias)
|
||||||
|
)
|
||||||
provision.provisionRelay(num, i)
|
provision.provisionRelay(num, i)
|
||||||
success("Started provisioning network %s on first relay for alias %s" % (i, alias))
|
success(
|
||||||
|
"Started provisioning network %s on first relay for alias %s"
|
||||||
|
% (i, alias)
|
||||||
|
)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
return
|
return
|
||||||
elif length == 2:
|
elif length == 2:
|
||||||
|
@ -27,9 +35,15 @@ class AutoCommand:
|
||||||
failure("First relay exists on %s" % spl[1])
|
failure("First relay exists on %s" % spl[1])
|
||||||
return
|
return
|
||||||
num, alias = main.network[spl[1]].add_relay(1)
|
num, alias = main.network[spl[1]].add_relay(1)
|
||||||
success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias))
|
success(
|
||||||
|
"Successfully created relay %i on network %s with alias %s"
|
||||||
|
% (num, spl[1], alias)
|
||||||
|
)
|
||||||
provision.provisionRelay(num, spl[1])
|
provision.provisionRelay(num, spl[1])
|
||||||
success("Started provisioning network %s on relay %s for alias %s" % (spl[1], num, alias))
|
success(
|
||||||
|
"Started provisioning network %s on relay %s for alias %s"
|
||||||
|
% (spl[1], num, alias)
|
||||||
|
)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
from yaml import dump
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
from yaml import dump
|
||||||
|
|
||||||
|
|
||||||
class BlacklistCommand:
|
class BlacklistCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.blacklist(*args)
|
self.blacklist(*args)
|
||||||
|
|
||||||
def blacklist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def blacklist(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
info(dump(main.blacklist))
|
info(dump(main.blacklist))
|
||||||
|
|
|
@ -5,7 +5,9 @@ class ChansCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.chans(*args)
|
self.chans(*args)
|
||||||
|
|
||||||
def chans(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def chans(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if len(spl) < 2:
|
if len(spl) < 2:
|
||||||
incUsage("chans")
|
incUsage("chans")
|
||||||
|
|
|
@ -5,7 +5,9 @@ class CmdCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.cmd(*args)
|
self.cmd(*args)
|
||||||
|
|
||||||
def cmd(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def cmd(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length > 4:
|
if length > 4:
|
||||||
if not spl[1].isdigit():
|
if not spl[1].isdigit():
|
||||||
|
|
|
@ -6,7 +6,9 @@ class ConfirmCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.confirm(*args)
|
self.confirm(*args)
|
||||||
|
|
||||||
def confirm(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def confirm(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 4:
|
if length == 4:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
|
@ -19,7 +21,10 @@ class ConfirmCommand:
|
||||||
failure("No such relay on %s: %s" % (spl[1], spl[2]))
|
failure("No such relay on %s: %s" % (spl[1], spl[2]))
|
||||||
return
|
return
|
||||||
regproc.confirmAccount(spl[1], int(spl[2]), spl[3])
|
regproc.confirmAccount(spl[1], int(spl[2]), spl[3])
|
||||||
success("Requested confirmation on %s - %s with token %s" % (spl[1], spl[2], spl[3]))
|
success(
|
||||||
|
"Requested confirmation on %s - %s with token %s"
|
||||||
|
% (spl[1], spl[2], spl[3])
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
incUsage("confirm")
|
incUsage("confirm")
|
||||||
|
|
|
@ -8,7 +8,9 @@ class DedupCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.dedup(*args)
|
self.dedup(*args)
|
||||||
|
|
||||||
def dedup(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def dedup(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
dupes = chankeep.getDuplicateChannels()
|
dupes = chankeep.getDuplicateChannels()
|
||||||
|
|
|
@ -6,7 +6,9 @@ class DisableCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.disable(*args)
|
self.disable(*args)
|
||||||
|
|
||||||
def disable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def disable(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 3:
|
if length == 3:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
|
|
|
@ -7,7 +7,9 @@ class DistCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.dist(*args)
|
self.dist(*args)
|
||||||
|
|
||||||
def dist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def dist(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if main.config["Dist"]["Enabled"]:
|
if main.config["Dist"]["Enabled"]:
|
||||||
rtrn = run([main.config["Dist"]["File"]], shell=True, stdout=PIPE)
|
rtrn = run([main.config["Dist"]["File"]], shell=True, stdout=PIPE)
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
from yaml import dump
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
from yaml import dump
|
||||||
|
|
||||||
|
|
||||||
class EmailCommand:
|
class EmailCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.email(*args)
|
self.email(*args)
|
||||||
|
|
||||||
def email(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def email(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 4:
|
if length == 4:
|
||||||
if spl[1] == "add":
|
if spl[1] == "add":
|
||||||
|
@ -19,10 +20,15 @@ class EmailCommand:
|
||||||
if not spl[3] in main.alias[num]["emails"]:
|
if not spl[3] in main.alias[num]["emails"]:
|
||||||
main.alias[num]["emails"].append(spl[3])
|
main.alias[num]["emails"].append(spl[3])
|
||||||
main.saveConf("alias")
|
main.saveConf("alias")
|
||||||
success("Successfully added email %s to alias %i" % (spl[3], num))
|
success(
|
||||||
|
"Successfully added email %s to alias %i"
|
||||||
|
% (spl[3], num)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
failure("Email already exists in alias %i: %s" % (num, spl[3]))
|
failure(
|
||||||
|
"Email already exists in alias %i: %s" % (num, spl[3])
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
failure("Must be a number, not %s" % spl[2])
|
failure("Must be a number, not %s" % spl[2])
|
||||||
|
@ -33,10 +39,16 @@ class EmailCommand:
|
||||||
return
|
return
|
||||||
if domain not in main.irc["_"]["domains"]:
|
if domain not in main.irc["_"]["domains"]:
|
||||||
main.irc["_"]["domains"].append(domain)
|
main.irc["_"]["domains"].append(domain)
|
||||||
success("Successfully added domain %s to default config" % domain)
|
success(
|
||||||
|
"Successfully added domain %s to default config"
|
||||||
|
% domain
|
||||||
|
)
|
||||||
main.saveConf("irc")
|
main.saveConf("irc")
|
||||||
else:
|
else:
|
||||||
failure("Domain already exists in default config: %s" % domain)
|
failure(
|
||||||
|
"Domain already exists in default config: %s"
|
||||||
|
% domain
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
elif spl[1] == "del":
|
elif spl[1] == "del":
|
||||||
|
@ -47,10 +59,16 @@ class EmailCommand:
|
||||||
|
|
||||||
if domain in main.irc["_"]["domains"]:
|
if domain in main.irc["_"]["domains"]:
|
||||||
main.irc["_"]["domains"].remove(domain)
|
main.irc["_"]["domains"].remove(domain)
|
||||||
success("Successfully removed domain %s to default config" % domain)
|
success(
|
||||||
|
"Successfully removed domain %s to default config"
|
||||||
|
% domain
|
||||||
|
)
|
||||||
main.saveConf("irc")
|
main.saveConf("irc")
|
||||||
else:
|
else:
|
||||||
failure("Domain does not exist in default config: %s" % domain)
|
failure(
|
||||||
|
"Domain does not exist in default config: %s"
|
||||||
|
% domain
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
elif spl[1] == "del":
|
elif spl[1] == "del":
|
||||||
|
@ -60,10 +78,15 @@ class EmailCommand:
|
||||||
if spl[3] in main.alias[num]["emails"]:
|
if spl[3] in main.alias[num]["emails"]:
|
||||||
main.alias[num]["emails"].remove(spl[3])
|
main.alias[num]["emails"].remove(spl[3])
|
||||||
main.saveConf("alias")
|
main.saveConf("alias")
|
||||||
success("Successfully removed email %s from alias %i" % (spl[3], num))
|
success(
|
||||||
|
"Successfully removed email %s from alias %i"
|
||||||
|
% (spl[3], num)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
failure("Email does not exist in alias %i: %s" % (spl[3], num))
|
failure(
|
||||||
|
"Email does not exist in alias %i: %s" % (spl[3], num)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
elif length == 2:
|
elif length == 2:
|
||||||
if spl[1] == "list":
|
if spl[1] == "list":
|
||||||
|
@ -76,7 +99,10 @@ class EmailCommand:
|
||||||
if spl[1] == "list":
|
if spl[1] == "list":
|
||||||
if spl[2] == "domain":
|
if spl[2] == "domain":
|
||||||
filtered = {
|
filtered = {
|
||||||
f"{k}:{k2}": v2 for k, v in main.irc.items() for k2, v2 in v.items() if k2 == "domains"
|
f"{k}:{k2}": v2
|
||||||
|
for k, v in main.irc.items()
|
||||||
|
for k2, v2 in v.items()
|
||||||
|
if k2 == "domains"
|
||||||
}
|
}
|
||||||
info(dump(filtered))
|
info(dump(filtered))
|
||||||
return
|
return
|
||||||
|
|
|
@ -6,7 +6,9 @@ class EnableCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.enable(*args)
|
self.enable(*args)
|
||||||
|
|
||||||
def enable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def enable(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 3:
|
if length == 3:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
|
|
|
@ -2,7 +2,9 @@ class ExecCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.exec(*args)
|
self.exec(*args)
|
||||||
|
|
||||||
def exec(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def exec(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length > 1:
|
if length > 1:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -6,7 +6,9 @@ class GetstrCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.getstr(*args)
|
self.getstr(*args)
|
||||||
|
|
||||||
def getstr(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def getstr(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 3:
|
if length == 3:
|
||||||
net = spl[1]
|
net = spl[1]
|
||||||
|
|
|
@ -5,7 +5,9 @@ class HelpCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.help(*args)
|
self.help(*args)
|
||||||
|
|
||||||
def help(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def help(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
helpMap = []
|
helpMap = []
|
||||||
for i in main.help.keys():
|
for i in main.help.keys():
|
||||||
|
|
|
@ -6,7 +6,9 @@ class JoinCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.join(*args)
|
self.join(*args)
|
||||||
|
|
||||||
def join(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def join(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 3:
|
if length == 3:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
|
|
|
@ -6,7 +6,9 @@ class ListCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.list(*args)
|
self.list(*args)
|
||||||
|
|
||||||
def list(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def list(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
for i in main.network.keys():
|
for i in main.network.keys():
|
||||||
|
|
|
@ -5,7 +5,9 @@ class LoadCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.load(*args)
|
self.load(*args)
|
||||||
|
|
||||||
def load(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def load(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 2:
|
if length == 2:
|
||||||
if spl[1] in main.filemap.keys():
|
if spl[1] in main.filemap.keys():
|
||||||
|
|
|
@ -5,7 +5,9 @@ class LoadmodCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.loadmod(*args)
|
self.loadmod(*args)
|
||||||
|
|
||||||
def loadmod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def loadmod(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 2:
|
if length == 2:
|
||||||
rtrn = loadSingle(spl[1])
|
rtrn = loadSingle(spl[1])
|
||||||
|
|
|
@ -2,7 +2,9 @@ class LogoutCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.logout(*args)
|
self.logout(*args)
|
||||||
|
|
||||||
def logout(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def logout(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
obj.authed = False
|
obj.authed = False
|
||||||
success("Logged out")
|
success("Logged out")
|
||||||
|
|
|
@ -6,7 +6,9 @@ class ModCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.mod(*args)
|
self.mod(*args)
|
||||||
|
|
||||||
def mod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def mod(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 4:
|
if length == 4:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
|
@ -20,7 +22,9 @@ class ModCommand:
|
||||||
return
|
return
|
||||||
|
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]))
|
success(
|
||||||
|
"Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1])
|
||||||
|
)
|
||||||
return
|
return
|
||||||
# Find a better way to do this
|
# Find a better way to do this
|
||||||
# elif length == 6:
|
# elif length == 6:
|
||||||
|
|
|
@ -5,7 +5,9 @@ class MsgCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.msg(*args)
|
self.msg(*args)
|
||||||
|
|
||||||
def msg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def msg(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length >= 5:
|
if length >= 5:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
|
@ -20,7 +22,10 @@ class MsgCommand:
|
||||||
if not spl[3] in main.IRCPool[spl[1] + spl[2]].channels:
|
if not spl[3] in main.IRCPool[spl[1] + spl[2]].channels:
|
||||||
info("Bot not on channel: %s" % spl[3])
|
info("Bot not on channel: %s" % spl[3])
|
||||||
main.IRCPool[spl[1] + spl[2]].msg(spl[3], " ".join(spl[4:]))
|
main.IRCPool[spl[1] + spl[2]].msg(spl[3], " ".join(spl[4:]))
|
||||||
success("Sent %s to %s on relay %s on network %s" % (" ".join(spl[4:]), spl[3], spl[2], spl[1]))
|
success(
|
||||||
|
"Sent %s to %s on relay %s on network %s"
|
||||||
|
% (" ".join(spl[4:]), spl[3], spl[2], spl[1])
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
incUsage("msg")
|
incUsage("msg")
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
from string import digits
|
from string import digits
|
||||||
|
|
||||||
from yaml import dump
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from modules.network import Network
|
from modules.network import Network
|
||||||
|
from yaml import dump
|
||||||
|
|
||||||
|
|
||||||
class NetworkCommand:
|
class NetworkCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.network(*args)
|
self.network(*args)
|
||||||
|
|
||||||
def network(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def network(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 7:
|
if length == 7:
|
||||||
if spl[1] == "add":
|
if spl[1] == "add":
|
||||||
|
@ -30,7 +31,9 @@ class NetworkCommand:
|
||||||
failure("Auth must be sasl, ns or none, not %s" % spl[5])
|
failure("Auth must be sasl, ns or none, not %s" % spl[5])
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
main.network[spl[2]] = Network(spl[2], spl[3], int(spl[4]), spl[5].lower(), spl[6].lower())
|
main.network[spl[2]] = Network(
|
||||||
|
spl[2], spl[3], int(spl[4]), spl[5].lower(), spl[6].lower()
|
||||||
|
)
|
||||||
success("Successfully created network: %s" % spl[2])
|
success("Successfully created network: %s" % spl[2])
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
return
|
return
|
||||||
|
|
|
@ -5,7 +5,9 @@ class PartCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.part(*args)
|
self.part(*args)
|
||||||
|
|
||||||
def part(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def part(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 4:
|
if length == 4:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
|
|
|
@ -5,7 +5,9 @@ class PassCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.password(*args)
|
self.password(*args)
|
||||||
|
|
||||||
def password(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def password(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
info("You are already authenticated")
|
info("You are already authenticated")
|
||||||
return
|
return
|
||||||
|
|
|
@ -5,14 +5,19 @@ class PendingCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.pending(*args)
|
self.pending(*args)
|
||||||
|
|
||||||
def pending(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def pending(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
results = []
|
results = []
|
||||||
for i in main.network.keys():
|
for i in main.network.keys():
|
||||||
for x in main.network[i].relays.keys():
|
for x in main.network[i].relays.keys():
|
||||||
if not main.network[i].relays[x]["registered"]:
|
if not main.network[i].relays[x]["registered"]:
|
||||||
results.append("%s: confirm %s %s [code]" % (main.alias[x]["nick"], i, x))
|
results.append(
|
||||||
|
"%s: confirm %s %s [code]"
|
||||||
|
% (main.alias[x]["nick"], i, x)
|
||||||
|
)
|
||||||
info("\n".join(results))
|
info("\n".join(results))
|
||||||
return
|
return
|
||||||
elif length == 2:
|
elif length == 2:
|
||||||
|
@ -22,7 +27,10 @@ class PendingCommand:
|
||||||
results = []
|
results = []
|
||||||
for x in main.network[spl[1]].relays.keys():
|
for x in main.network[spl[1]].relays.keys():
|
||||||
if not main.network[spl[1]].relays[x]["registered"]:
|
if not main.network[spl[1]].relays[x]["registered"]:
|
||||||
results.append("%s: confirm %s %s [code]" % (main.alias[x]["nick"], spl[1], x))
|
results.append(
|
||||||
|
"%s: confirm %s %s [code]"
|
||||||
|
% (main.alias[x]["nick"], spl[1], x)
|
||||||
|
)
|
||||||
info("\n".join(results))
|
info("\n".join(results))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -5,7 +5,9 @@ class RecheckauthCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.recheckauth(*args)
|
self.recheckauth(*args)
|
||||||
|
|
||||||
def recheckauth(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def recheckauth(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
for i in main.IRCPool.keys():
|
for i in main.IRCPool.keys():
|
||||||
|
|
|
@ -6,7 +6,9 @@ class RegCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.reg(*args)
|
self.reg(*args)
|
||||||
|
|
||||||
def reg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def reg(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 2:
|
if length == 2:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
from yaml import dump
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
from yaml import dump
|
||||||
|
|
||||||
|
|
||||||
class RelayCommand:
|
class RelayCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.relay(*args)
|
self.relay(*args)
|
||||||
|
|
||||||
def relay(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def relay(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 3:
|
if length == 3:
|
||||||
if spl[1] == "add":
|
if spl[1] == "add":
|
||||||
if spl[2] in main.network.keys():
|
if spl[2] in main.network.keys():
|
||||||
id, alias = main.network[spl[2]].add_relay()
|
id, alias = main.network[spl[2]].add_relay()
|
||||||
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
|
success(
|
||||||
|
"Successfully created relay %s on network %s with alias %s"
|
||||||
|
% (str(id), spl[2], alias)
|
||||||
|
)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -36,7 +40,10 @@ class RelayCommand:
|
||||||
failure("Must be a number, not %s" % spl[3])
|
failure("Must be a number, not %s" % spl[3])
|
||||||
return
|
return
|
||||||
id, alias = main.network[spl[2]].add_relay(int(spl[3]))
|
id, alias = main.network[spl[2]].add_relay(int(spl[3]))
|
||||||
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
|
success(
|
||||||
|
"Successfully created relay %s on network %s with alias %s"
|
||||||
|
% (str(id), spl[2], alias)
|
||||||
|
)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -53,7 +60,9 @@ class RelayCommand:
|
||||||
failure("No such relay: %s on network %s" % (spl[3], spl[2]))
|
failure("No such relay: %s on network %s" % (spl[3], spl[2]))
|
||||||
return
|
return
|
||||||
main.network[spl[2]].delete_relay(int(spl[3]))
|
main.network[spl[2]].delete_relay(int(spl[3]))
|
||||||
success("Successfully deleted relay %s on network %s" % (spl[3], spl[2]))
|
success(
|
||||||
|
"Successfully deleted relay %s on network %s" % (spl[3], spl[2])
|
||||||
|
)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -5,7 +5,9 @@ class SaveCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.save(*args)
|
self.save(*args)
|
||||||
|
|
||||||
def save(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def save(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 2:
|
if length == 2:
|
||||||
if spl[1] in main.filemap.keys():
|
if spl[1] in main.filemap.keys():
|
||||||
|
|
|
@ -9,7 +9,9 @@ class StatsCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.stats(*args)
|
self.stats(*args)
|
||||||
|
|
||||||
def stats(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def stats(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
stats = []
|
stats = []
|
||||||
|
|
|
@ -5,7 +5,9 @@ class SwhoCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.swho(*args)
|
self.swho(*args)
|
||||||
|
|
||||||
def swho(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def swho(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 2:
|
if length == 2:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from yaml import dump
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
from yaml import dump
|
||||||
|
|
||||||
|
|
||||||
class TokenCommand:
|
class TokenCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.token(*args)
|
self.token(*args)
|
||||||
|
|
||||||
def token(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def token(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 2:
|
if length == 2:
|
||||||
if spl[1] == "list":
|
if spl[1] == "list":
|
||||||
|
|
|
@ -5,7 +5,9 @@ class UsersCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.users(*args)
|
self.users(*args)
|
||||||
|
|
||||||
def users(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def users(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if len(spl) < 2:
|
if len(spl) < 2:
|
||||||
incUsage("users")
|
incUsage("users")
|
||||||
|
|
|
@ -5,7 +5,9 @@ class WhoCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.who(*args)
|
self.who(*args)
|
||||||
|
|
||||||
def who(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def who(
|
||||||
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 2:
|
if length == 2:
|
||||||
result = userinfo.getWho(spl[1])
|
result = userinfo.getWho(spl[1])
|
||||||
|
|
|
@ -3,6 +3,9 @@ from copy import deepcopy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
|
import main
|
||||||
|
from core.relay import sendRelayNotification
|
||||||
|
from modules import chankeep, counters, helpers, monitor, regproc, userinfo
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.internet.defer import Deferred
|
from twisted.internet.defer import Deferred
|
||||||
from twisted.internet.protocol import ReconnectingClientFactory
|
from twisted.internet.protocol import ReconnectingClientFactory
|
||||||
|
@ -13,10 +16,6 @@ from twisted.words.protocols.irc import (
|
||||||
lowDequote,
|
lowDequote,
|
||||||
numeric_to_symbolic,
|
numeric_to_symbolic,
|
||||||
)
|
)
|
||||||
|
|
||||||
import main
|
|
||||||
from core.relay import sendRelayNotification
|
|
||||||
from modules import chankeep, counters, helpers, monitor, regproc, userinfo
|
|
||||||
from utils.dedup import dedup
|
from utils.dedup import dedup
|
||||||
from utils.logging.debug import debug, trace
|
from utils.logging.debug import debug, trace
|
||||||
from utils.logging.log import error, log, warn
|
from utils.logging.log import error, log, warn
|
||||||
|
@ -83,7 +82,9 @@ class IRCBot(IRCClient):
|
||||||
self.listAttempted = False # we asked for a list
|
self.listAttempted = False # we asked for a list
|
||||||
self.listSimple = False # after asking again we got the list, so use the simple
|
self.listSimple = False # after asking again we got the list, so use the simple
|
||||||
# syntax from now on
|
# syntax from now on
|
||||||
self.wantList = False # we want to send a LIST, but not all relays are active yet
|
self.wantList = (
|
||||||
|
False # we want to send a LIST, but not all relays are active yet
|
||||||
|
)
|
||||||
self.chanlimit = 0
|
self.chanlimit = 0
|
||||||
self.prefix = {}
|
self.prefix = {}
|
||||||
self.servername = None
|
self.servername = None
|
||||||
|
@ -115,9 +116,14 @@ class IRCBot(IRCClient):
|
||||||
if i not in self.channels:
|
if i not in self.channels:
|
||||||
if self.net in main.blacklist.keys():
|
if self.net in main.blacklist.keys():
|
||||||
if i in main.blacklist[self.net]:
|
if i in main.blacklist[self.net]:
|
||||||
debug("Not joining blacklisted channel %s on %s - %i" % (i, self.net, self.num))
|
debug(
|
||||||
|
"Not joining blacklisted channel %s on %s - %i"
|
||||||
|
% (i, self.net, self.num)
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
trace(self.net, "-", self.num, ": joining", i, "in", sleeptime, "seconds")
|
trace(
|
||||||
|
self.net, "-", self.num, ": joining", i, "in", sleeptime, "seconds"
|
||||||
|
)
|
||||||
reactor.callLater(sleeptime, self.join, i)
|
reactor.callLater(sleeptime, self.join, i)
|
||||||
sleeptime += increment
|
sleeptime += increment
|
||||||
if sleeptime == 10:
|
if sleeptime == 10:
|
||||||
|
@ -125,13 +131,19 @@ class IRCBot(IRCClient):
|
||||||
increment = 0.7
|
increment = 0.7
|
||||||
increment += 0.1
|
increment += 0.1
|
||||||
else:
|
else:
|
||||||
error("%s - Cannot join channel we are already on: %s - %i" % (i, self.net, self.num))
|
error(
|
||||||
|
"%s - Cannot join channel we are already on: %s - %i"
|
||||||
|
% (i, self.net, self.num)
|
||||||
|
)
|
||||||
|
|
||||||
def checkChannels(self):
|
def checkChannels(self):
|
||||||
if chankeep.allRelaysActive(self.net):
|
if chankeep.allRelaysActive(self.net):
|
||||||
debug(f"checkChannels() all relays active for {self.net}")
|
debug(f"checkChannels() all relays active for {self.net}")
|
||||||
else:
|
else:
|
||||||
debug("checkChannels() skipping channel check as we have inactive relays: %s - %i" % (self.net, self.num))
|
debug(
|
||||||
|
"checkChannels() skipping channel check as we have inactive relays: %s - %i"
|
||||||
|
% (self.net, self.num)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
if self.net in main.TempChan.keys():
|
if self.net in main.TempChan.keys():
|
||||||
if self.num in main.TempChan[self.net].keys():
|
if self.num in main.TempChan[self.net].keys():
|
||||||
|
@ -145,7 +157,9 @@ class IRCBot(IRCClient):
|
||||||
cast["ts"] = str(datetime.now().isoformat())
|
cast["ts"] = str(datetime.now().isoformat())
|
||||||
|
|
||||||
# remove odd stuff
|
# remove odd stuff
|
||||||
for i in list(cast.keys()): # Make a copy of the .keys() as Python 3 cannot handle iterating over
|
for i in list(
|
||||||
|
cast.keys()
|
||||||
|
): # Make a copy of the .keys() as Python 3 cannot handle iterating over
|
||||||
if cast[i] == "": # a dictionary that changes length with each iteration
|
if cast[i] == "": # a dictionary that changes length with each iteration
|
||||||
del cast[i]
|
del cast[i]
|
||||||
# remove server stuff
|
# remove server stuff
|
||||||
|
@ -201,7 +215,9 @@ class IRCBot(IRCClient):
|
||||||
castDup["type"] = "highlight"
|
castDup["type"] = "highlight"
|
||||||
self.event(**castDup)
|
self.event(**castDup)
|
||||||
else:
|
else:
|
||||||
if cast["channel"].lower() == self.nickname.lower() or not cast["channel"].startswith("#"):
|
if cast["channel"].lower() == self.nickname.lower() or not cast[
|
||||||
|
"channel"
|
||||||
|
].startswith("#"):
|
||||||
cast["mtype"] = cast["type"]
|
cast["mtype"] = cast["type"]
|
||||||
cast["type"] = "query"
|
cast["type"] = "query"
|
||||||
# self.event(**castDup)
|
# self.event(**castDup)
|
||||||
|
@ -277,10 +293,33 @@ class IRCBot(IRCClient):
|
||||||
nick, ident, host = parsen(hostmask)
|
nick, ident, host = parsen(hostmask)
|
||||||
# We sent someone a query reply
|
# We sent someone a query reply
|
||||||
if in_query:
|
if in_query:
|
||||||
self.event(type="self", mtype="msg", channel=self.nickname, nick=channel, ident=ident, host=host, msg=msg)
|
self.event(
|
||||||
|
type="self",
|
||||||
|
mtype="msg",
|
||||||
|
channel=self.nickname,
|
||||||
|
nick=channel,
|
||||||
|
ident=ident,
|
||||||
|
host=host,
|
||||||
|
msg=msg,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.event(type="self", mtype="msg", channel=channel, nick=self.nickname, ident=ident, host=host, msg=msg)
|
self.event(
|
||||||
self.event(type="msg", channel=channel, nick=self.nickname, ident=ident, host=host, msg=msg)
|
type="self",
|
||||||
|
mtype="msg",
|
||||||
|
channel=channel,
|
||||||
|
nick=self.nickname,
|
||||||
|
ident=ident,
|
||||||
|
host=host,
|
||||||
|
msg=msg,
|
||||||
|
)
|
||||||
|
self.event(
|
||||||
|
type="msg",
|
||||||
|
channel=channel,
|
||||||
|
nick=self.nickname,
|
||||||
|
ident=ident,
|
||||||
|
host=host,
|
||||||
|
msg=msg,
|
||||||
|
)
|
||||||
self.msg(channel, msg)
|
self.msg(channel, msg)
|
||||||
|
|
||||||
def get(self, var):
|
def get(self, var):
|
||||||
|
@ -309,7 +348,9 @@ class IRCBot(IRCClient):
|
||||||
|
|
||||||
def irc_ERR_PASSWDMISMATCH(self, prefix, params):
|
def irc_ERR_PASSWDMISMATCH(self, prefix, params):
|
||||||
log("%s - %i: password mismatch as %s" % (self.net, self.num, self.username))
|
log("%s - %i: password mismatch as %s" % (self.net, self.num, self.username))
|
||||||
sendAll("%s - %i: password mismatch as %s" % (self.net, self.num, self.username))
|
sendAll(
|
||||||
|
"%s - %i: password mismatch as %s" % (self.net, self.num, self.username)
|
||||||
|
)
|
||||||
|
|
||||||
def _who(self, channel):
|
def _who(self, channel):
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
|
@ -424,12 +465,17 @@ class IRCBot(IRCClient):
|
||||||
debug("Will not send LIST, unauthenticated: %s - %i" % (self.net, self.num))
|
debug("Will not send LIST, unauthenticated: %s - %i" % (self.net, self.num))
|
||||||
return
|
return
|
||||||
if self.listAttempted:
|
if self.listAttempted:
|
||||||
debug("List request dropped, already asked for LIST - %s - %i" % (self.net, self.num))
|
debug(
|
||||||
|
"List request dropped, already asked for LIST - %s - %i"
|
||||||
|
% (self.net, self.num)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.listAttempted = True
|
self.listAttempted = True
|
||||||
if self.listOngoing:
|
if self.listOngoing:
|
||||||
debug("LIST request dropped, already ongoing - %s - %i" % (self.net, self.num))
|
debug(
|
||||||
|
"LIST request dropped, already ongoing - %s - %i" % (self.net, self.num)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if nocheck:
|
if nocheck:
|
||||||
|
@ -454,7 +500,9 @@ class IRCBot(IRCClient):
|
||||||
self._tempList[1].append([channel, users, topic])
|
self._tempList[1].append([channel, users, topic])
|
||||||
|
|
||||||
def irc_RPL_LISTEND(self, prefix, params):
|
def irc_RPL_LISTEND(self, prefix, params):
|
||||||
if not len(self._tempList[0]) > 0: # there are no callbacks, can't do anything there
|
if (
|
||||||
|
not len(self._tempList[0]) > 0
|
||||||
|
): # there are no callbacks, can't do anything there
|
||||||
debug("We didn't ask for this LIST, discarding")
|
debug("We didn't ask for this LIST, discarding")
|
||||||
self._tempList[0].clear()
|
self._tempList[0].clear()
|
||||||
self._tempList[1].clear()
|
self._tempList[1].clear()
|
||||||
|
@ -479,7 +527,10 @@ class IRCBot(IRCClient):
|
||||||
else:
|
else:
|
||||||
if self.listRetried:
|
if self.listRetried:
|
||||||
self.listRetried = False
|
self.listRetried = False
|
||||||
debug("List received after retry - defaulting to simple list syntax: %s - %i" % (self.net, self.num))
|
debug(
|
||||||
|
"List received after retry - defaulting to simple list syntax: %s - %i"
|
||||||
|
% (self.net, self.num)
|
||||||
|
)
|
||||||
self.listSimple = True
|
self.listSimple = True
|
||||||
|
|
||||||
def got_list(self, listinfo):
|
def got_list(self, listinfo):
|
||||||
|
@ -500,9 +551,13 @@ class IRCBot(IRCClient):
|
||||||
if first_relay:
|
if first_relay:
|
||||||
if first_relay.wantList is True:
|
if first_relay.wantList is True:
|
||||||
first_relay.list(nocheck=True)
|
first_relay.list(nocheck=True)
|
||||||
debug(f"recheckList() asking for a list for {self.net} after final relay {self.num} connected")
|
debug(
|
||||||
|
f"recheckList() asking for a list for {self.net} after final relay {self.num} connected"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
debug(f"recheckList() first relay wantList is False for {self.net} ({first_relay.num})")
|
debug(
|
||||||
|
f"recheckList() first relay wantList is False for {self.net} ({first_relay.num})"
|
||||||
|
)
|
||||||
# name = self.net + "1"
|
# name = self.net + "1"
|
||||||
|
|
||||||
# if self.num == 1: # Only one instance should do a list
|
# if self.num == 1: # Only one instance should do a list
|
||||||
|
@ -511,7 +566,9 @@ class IRCBot(IRCClient):
|
||||||
if self.chanlimit:
|
if self.chanlimit:
|
||||||
if allRelays:
|
if allRelays:
|
||||||
self.list()
|
self.list()
|
||||||
debug(f"recheckList() requested a list for {self.net} from {self.num}")
|
debug(
|
||||||
|
f"recheckList() requested a list for {self.net} from {self.num}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
debug(f"recheckList() not all relays active for {self.net}")
|
debug(f"recheckList() not all relays active for {self.net}")
|
||||||
self.wantList = True
|
self.wantList = True
|
||||||
|
@ -525,7 +582,9 @@ class IRCBot(IRCClient):
|
||||||
]: # TODO: add check for register request sent, only send it once
|
]: # TODO: add check for register request sent, only send it once
|
||||||
if main.config["AutoReg"]:
|
if main.config["AutoReg"]:
|
||||||
if not self.authenticated:
|
if not self.authenticated:
|
||||||
self._regAttempt = reactor.callLater(5, regproc.registerAccount, self.net, self.num)
|
self._regAttempt = reactor.callLater(
|
||||||
|
5, regproc.registerAccount, self.net, self.num
|
||||||
|
)
|
||||||
# regproc.registerAccount(self.net, self.num)
|
# regproc.registerAccount(self.net, self.num)
|
||||||
try:
|
try:
|
||||||
self.chanlimit = int(chanlimit)
|
self.chanlimit = int(chanlimit)
|
||||||
|
@ -539,7 +598,9 @@ class IRCBot(IRCClient):
|
||||||
self.chanlimit = net_inst_chanlimit
|
self.chanlimit = net_inst_chanlimit
|
||||||
# warn(f"Chanlimit on {self.net} too high, setting to {self.chanlimit}")
|
# warn(f"Chanlimit on {self.net} too high, setting to {self.chanlimit}")
|
||||||
|
|
||||||
if not regproc.needToRegister(self.net): # if we need to register, only recheck on auth confirmation
|
if not regproc.needToRegister(
|
||||||
|
self.net
|
||||||
|
): # if we need to register, only recheck on auth confirmation
|
||||||
if main.config["ChanKeep"]["Enabled"]:
|
if main.config["ChanKeep"]["Enabled"]:
|
||||||
self.recheckList()
|
self.recheckList()
|
||||||
|
|
||||||
|
@ -642,7 +703,9 @@ class IRCBot(IRCClient):
|
||||||
if reset:
|
if reset:
|
||||||
self._negativePass = None
|
self._negativePass = None
|
||||||
|
|
||||||
debug(f"regPing() {self.net} - {self.num}: _negativePass:{self._negativePass} negativepass:{negativepass}")
|
debug(
|
||||||
|
f"regPing() {self.net} - {self.num}: _negativePass:{self._negativePass} negativepass:{negativepass}"
|
||||||
|
)
|
||||||
if self._negativePass is None:
|
if self._negativePass is None:
|
||||||
# We have failed, the blacklisted message has been found
|
# We have failed, the blacklisted message has been found
|
||||||
if negativepass is False:
|
if negativepass is False:
|
||||||
|
@ -665,7 +728,9 @@ class IRCBot(IRCClient):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
debug(f"regPing() {self.net}: negative registration check - {self.num}")
|
debug(
|
||||||
|
f"regPing() {self.net}: negative registration check - {self.num}"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if sinst["negative"]:
|
if sinst["negative"]:
|
||||||
|
@ -678,14 +743,18 @@ class IRCBot(IRCClient):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self._negativePass = True # if it's disabled, we still want the next block to run
|
self._negativePass = (
|
||||||
|
True # if it's disabled, we still want the next block to run
|
||||||
|
)
|
||||||
|
|
||||||
# Only run if negativepass has completed, or exempted as above
|
# Only run if negativepass has completed, or exempted as above
|
||||||
if self._negativePass:
|
if self._negativePass:
|
||||||
if sinst["check"]:
|
if sinst["check"]:
|
||||||
if sinst["ping"]:
|
if sinst["ping"]:
|
||||||
self.msg(sinst["entity"], sinst["pingmsg"])
|
self.msg(sinst["entity"], sinst["pingmsg"])
|
||||||
debug(f"regPing() {self.net}: sent ping '{sinst['pingmsg']}' to {sinst['entity']} - {self.num}")
|
debug(
|
||||||
|
f"regPing() {self.net}: sent ping '{sinst['pingmsg']}' to {sinst['entity']} - {self.num}"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.authenticated = True
|
self.authenticated = True
|
||||||
|
@ -719,7 +788,11 @@ class IRCBot(IRCClient):
|
||||||
self.channels.append(channel)
|
self.channels.append(channel)
|
||||||
self.names(channel).addCallback(self.got_names)
|
self.names(channel).addCallback(self.got_names)
|
||||||
if main.config["Toggles"]["Who"]:
|
if main.config["Toggles"]["Who"]:
|
||||||
reactor.callLater(main.config["Tweaks"]["Delays"]["WhoDelay"], self.setup_who_loop, channel)
|
reactor.callLater(
|
||||||
|
main.config["Tweaks"]["Delays"]["WhoDelay"],
|
||||||
|
self.setup_who_loop,
|
||||||
|
channel,
|
||||||
|
)
|
||||||
# lc = LoopingCall(self.who, channel)
|
# lc = LoopingCall(self.who, channel)
|
||||||
# self._getWho[channel] = lc
|
# self._getWho[channel] = lc
|
||||||
# intrange = main.config["Tweaks"]["Delays"]["WhoRange"]
|
# intrange = main.config["Tweaks"]["Delays"]["WhoRange"]
|
||||||
|
@ -734,7 +807,9 @@ class IRCBot(IRCClient):
|
||||||
lc = self._getWho[channel]
|
lc = self._getWho[channel]
|
||||||
lc.stop()
|
lc.stop()
|
||||||
del self._getWho[channel]
|
del self._getWho[channel]
|
||||||
userinfo.delChannels(self.net, [channel]) # < we do not need to deduplicate this
|
userinfo.delChannels(
|
||||||
|
self.net, [channel]
|
||||||
|
) # < we do not need to deduplicate this
|
||||||
# log("Can no longer cover %s, removing records" % channel)# as it will only be matched once --
|
# log("Can no longer cover %s, removing records" % channel)# as it will only be matched once --
|
||||||
# other bots have different nicknames so
|
# other bots have different nicknames so
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import logging
|
||||||
from json import dumps
|
from json import dumps
|
||||||
|
|
||||||
import logstash
|
import logstash
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
|
||||||
logger = None
|
logger = None
|
||||||
|
|
|
@ -19,7 +19,9 @@ def parseCommand(addr, authed, data):
|
||||||
incUsage = lambda mode: incorrectUsage(addr, mode) # noqa: E731
|
incUsage = lambda mode: incorrectUsage(addr, mode) # noqa: E731
|
||||||
length = len(spl)
|
length = len(spl)
|
||||||
if spl[0] in main.CommandMap.keys():
|
if spl[0] in main.CommandMap.keys():
|
||||||
main.CommandMap[spl[0]](addr, authed, data, obj, spl, success, failure, info, incUsage, length)
|
main.CommandMap[spl[0]](
|
||||||
|
addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
||||||
|
)
|
||||||
return
|
return
|
||||||
incUsage(None)
|
incUsage(None)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
from json import dumps, loads
|
from json import dumps, loads
|
||||||
|
|
||||||
from twisted.internet.protocol import Factory, Protocol
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
from twisted.internet.protocol import Factory, Protocol
|
||||||
from utils.logging.log import log, warn
|
from utils.logging.log import log, warn
|
||||||
|
|
||||||
validTypes = [
|
validTypes = [
|
||||||
|
@ -118,7 +117,9 @@ class Relay(Protocol):
|
||||||
parsed["hello"] == main.tokens[parsed["key"]]["hello"]
|
parsed["hello"] == main.tokens[parsed["key"]]["hello"]
|
||||||
and main.tokens[parsed["key"]]["usage"] == "relay"
|
and main.tokens[parsed["key"]]["usage"] == "relay"
|
||||||
):
|
):
|
||||||
self.sendMsg({"type": "hello", "hello": main.tokens[parsed["key"]]["counter"]})
|
self.sendMsg(
|
||||||
|
{"type": "hello", "hello": main.tokens[parsed["key"]]["counter"]}
|
||||||
|
)
|
||||||
self.authed = True
|
self.authed = True
|
||||||
else:
|
else:
|
||||||
self.transport.loseConnection()
|
self.transport.loseConnection()
|
||||||
|
@ -133,7 +134,10 @@ class Relay(Protocol):
|
||||||
|
|
||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
self.authed = False
|
self.authed = False
|
||||||
log("Relay connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage()))
|
log(
|
||||||
|
"Relay connection lost from %s:%s -- %s"
|
||||||
|
% (self.addr.host, self.addr.port, reason.getErrorMessage())
|
||||||
|
)
|
||||||
if self.addr in main.relayConnections.keys():
|
if self.addr in main.relayConnections.keys():
|
||||||
del main.relayConnections[self.addr]
|
del main.relayConnections[self.addr]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from twisted.internet.protocol import Factory, Protocol
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from core.parser import parseCommand
|
from core.parser import parseCommand
|
||||||
|
from twisted.internet.protocol import Factory, Protocol
|
||||||
from utils.logging.log import log, warn
|
from utils.logging.log import log, warn
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,7 +33,10 @@ class Server(Protocol):
|
||||||
|
|
||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
self.authed = False
|
self.authed = False
|
||||||
log("Connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage()))
|
log(
|
||||||
|
"Connection lost from %s:%s -- %s"
|
||||||
|
% (self.addr.host, self.addr.port, reason.getErrorMessage())
|
||||||
|
)
|
||||||
if self.addr in main.connections.keys():
|
if self.addr in main.connections.keys():
|
||||||
del main.connections[self.addr]
|
del main.connections[self.addr]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -126,4 +126,6 @@ def initMain():
|
||||||
r = StrictRedis(
|
r = StrictRedis(
|
||||||
unix_socket_path=config["RedisSocket"], db=config["RedisDBEphemeral"] # noqa
|
unix_socket_path=config["RedisSocket"], db=config["RedisDBEphemeral"] # noqa
|
||||||
) # Ephemeral - flushed on quit
|
) # Ephemeral - flushed on quit
|
||||||
g = StrictRedis(unix_socket_path=config["RedisSocket"], db=config["RedisDBPersistent"]) # noqa
|
g = StrictRedis(
|
||||||
|
unix_socket_path=config["RedisSocket"], db=config["RedisDBPersistent"]
|
||||||
|
) # noqa
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
from twisted.internet.threads import deferToThread
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from modules import helpers
|
from modules import helpers
|
||||||
|
from twisted.internet.threads import deferToThread
|
||||||
from utils.logging.debug import debug, trace
|
from utils.logging.debug import debug, trace
|
||||||
from utils.logging.log import error, log, warn
|
from utils.logging.log import error, log, warn
|
||||||
|
|
||||||
|
@ -95,7 +94,11 @@ def getEnabledRelays(net):
|
||||||
:rtype: list of int
|
:rtype: list of int
|
||||||
:return: list of enabled relay numbers
|
:return: list of enabled relay numbers
|
||||||
"""
|
"""
|
||||||
enabledRelays = [x for x in main.network[net].relays.keys() if main.network[net].relays[x]["enabled"]]
|
enabledRelays = [
|
||||||
|
x
|
||||||
|
for x in main.network[net].relays.keys()
|
||||||
|
if main.network[net].relays[x]["enabled"]
|
||||||
|
]
|
||||||
# debug(f"getEnabledRelays() {net}: {enabledRelays}")
|
# debug(f"getEnabledRelays() {net}: {enabledRelays}")
|
||||||
return enabledRelays
|
return enabledRelays
|
||||||
|
|
||||||
|
@ -259,7 +262,9 @@ def emptyChanAllocate(net, flist):
|
||||||
chan_slots_used = getTotalChans(net)
|
chan_slots_used = getTotalChans(net)
|
||||||
max_chans = getSumChanlimit(net) - chan_slots_used
|
max_chans = getSumChanlimit(net) - chan_slots_used
|
||||||
trunc_list = newlist[:max_chans]
|
trunc_list = newlist[:max_chans]
|
||||||
debug(f"emptyChanAllocate() {net}: newlist:{len(newlist)} trunc_list:{len(trunc_list)}")
|
debug(
|
||||||
|
f"emptyChanAllocate() {net}: newlist:{len(newlist)} trunc_list:{len(trunc_list)}"
|
||||||
|
)
|
||||||
|
|
||||||
for i in chanfree.keys():
|
for i in chanfree.keys():
|
||||||
for x in range(chanfree[i]):
|
for x in range(chanfree[i]):
|
||||||
|
@ -359,9 +364,13 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
|
||||||
listinfo = minifyChans(net, listinfo)
|
listinfo = minifyChans(net, listinfo)
|
||||||
if not listinfo:
|
if not listinfo:
|
||||||
return
|
return
|
||||||
if relay <= main.config["ChanKeep"]["SigSwitch"]: # we can cover all of the channels
|
if (
|
||||||
|
relay <= main.config["ChanKeep"]["SigSwitch"]
|
||||||
|
): # we can cover all of the channels
|
||||||
coverAll = True
|
coverAll = True
|
||||||
elif relay > main.config["ChanKeep"]["SigSwitch"]: # we cannot cover all of the channels
|
elif (
|
||||||
|
relay > main.config["ChanKeep"]["SigSwitch"]
|
||||||
|
): # we cannot cover all of the channels
|
||||||
coverAll = False
|
coverAll = False
|
||||||
# if not sigrelay <= main.config["ChanKeep"]["MaxRelay"]:
|
# if not sigrelay <= main.config["ChanKeep"]["MaxRelay"]:
|
||||||
# error("Network %s is too big to cover: %i relays required" % (net, sigrelay))
|
# error("Network %s is too big to cover: %i relays required" % (net, sigrelay))
|
||||||
|
@ -389,7 +398,9 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
|
||||||
flist = [i[0] for i in listinfo_sort]
|
flist = [i[0] for i in listinfo_sort]
|
||||||
|
|
||||||
flist = flist[:max_chans]
|
flist = flist[:max_chans]
|
||||||
debug(f"keepChannels() {net}: joining {len(flist)}/{len(listinfo_sort)} channels")
|
debug(
|
||||||
|
f"keepChannels() {net}: joining {len(flist)}/{len(listinfo_sort)} channels"
|
||||||
|
)
|
||||||
trace(f"keepChannels() {net}: joining:{flist}")
|
trace(f"keepChannels() {net}: joining:{flist}")
|
||||||
populateChans(net, flist)
|
populateChans(net, flist)
|
||||||
else:
|
else:
|
||||||
|
@ -411,8 +422,12 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
|
||||||
siglist = siglist[:max_chans]
|
siglist = siglist[:max_chans]
|
||||||
trace(f"keepChannels() {net}: truncated siglist:{siglist}")
|
trace(f"keepChannels() {net}: truncated siglist:{siglist}")
|
||||||
|
|
||||||
trace(f"keepChannels() {net}: siglist:{siglist} max_chans:{max_chans} len_sig:{len(listinfo_sort)}")
|
trace(
|
||||||
debug(f"keepChannels() {net}: joining {len(siglist)}/{len(listinfo_sort)} channels")
|
f"keepChannels() {net}: siglist:{siglist} max_chans:{max_chans} len_sig:{len(listinfo_sort)}"
|
||||||
|
)
|
||||||
|
debug(
|
||||||
|
f"keepChannels() {net}: joining {len(siglist)}/{len(listinfo_sort)} channels"
|
||||||
|
)
|
||||||
trace(f"keepChannels() {net}: joining:{siglist}")
|
trace(f"keepChannels() {net}: joining:{siglist}")
|
||||||
populateChans(net, siglist)
|
populateChans(net, siglist)
|
||||||
notifyJoin(net)
|
notifyJoin(net)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from twisted.internet.task import LoopingCall
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
from twisted.internet.task import LoopingCall
|
||||||
|
|
||||||
|
|
||||||
def event(name, eventType):
|
def event(name, eventType):
|
||||||
|
|
|
@ -64,7 +64,9 @@ def parsemeta(numName, c):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def event(numName, c): # yes I'm using a short variable because otherwise it goes off the screen
|
def event(
|
||||||
|
numName, c
|
||||||
|
): # yes I'm using a short variable because otherwise it goes off the screen
|
||||||
if dedup(numName, c):
|
if dedup(numName, c):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from twisted.internet import reactor
|
|
||||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from core.bot import IRCBotFactory
|
from core.bot import IRCBotFactory
|
||||||
from modules import alias
|
from modules import alias
|
||||||
from modules.chankeep import nukeNetwork
|
from modules.chankeep import nukeNetwork
|
||||||
from modules.provision import provisionRelay
|
from modules.provision import provisionRelay
|
||||||
from modules.regproc import needToRegister
|
from modules.regproc import needToRegister
|
||||||
|
from twisted.internet import reactor
|
||||||
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||||
from utils.deliver_relay_commands import deliverRelayCommands
|
from utils.deliver_relay_commands import deliverRelayCommands
|
||||||
from utils.get import getRelay
|
from utils.get import getRelay
|
||||||
from utils.logging.log import log
|
from utils.logging.log import log
|
||||||
|
|
|
@ -1,28 +1,37 @@
|
||||||
from twisted.internet import reactor
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
import modules.regproc
|
import modules.regproc
|
||||||
|
from twisted.internet import reactor
|
||||||
from utils.deliver_relay_commands import deliverRelayCommands
|
from utils.deliver_relay_commands import deliverRelayCommands
|
||||||
from utils.logging.log import warn
|
from utils.logging.log import warn
|
||||||
|
|
||||||
|
|
||||||
def provisionUserNetworkData(num, nick, altnick, ident, realname, network, host, port, security):
|
def provisionUserNetworkData(
|
||||||
|
num, nick, altnick, ident, realname, network, host, port, security
|
||||||
|
):
|
||||||
commands = {}
|
commands = {}
|
||||||
stage2commands = {}
|
stage2commands = {}
|
||||||
stage2commands["status"] = []
|
stage2commands["status"] = []
|
||||||
commands["controlpanel"] = []
|
commands["controlpanel"] = []
|
||||||
user = nick.lower()
|
user = nick.lower()
|
||||||
commands["controlpanel"].append("AddUser %s %s" % (user, main.config["Relay"]["Password"]))
|
commands["controlpanel"].append(
|
||||||
|
"AddUser %s %s" % (user, main.config["Relay"]["Password"])
|
||||||
|
)
|
||||||
commands["controlpanel"].append("AddNetwork %s %s" % (user, network))
|
commands["controlpanel"].append("AddNetwork %s %s" % (user, network))
|
||||||
commands["controlpanel"].append("Set Nick %s %s" % (user, nick))
|
commands["controlpanel"].append("Set Nick %s %s" % (user, nick))
|
||||||
commands["controlpanel"].append("Set Altnick %s %s" % (user, altnick))
|
commands["controlpanel"].append("Set Altnick %s %s" % (user, altnick))
|
||||||
commands["controlpanel"].append("Set Ident %s %s" % (user, ident))
|
commands["controlpanel"].append("Set Ident %s %s" % (user, ident))
|
||||||
commands["controlpanel"].append("Set RealName %s %s" % (user, realname))
|
commands["controlpanel"].append("Set RealName %s %s" % (user, realname))
|
||||||
if security == "ssl":
|
if security == "ssl":
|
||||||
commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (user, network)) # Don't judge me
|
commands["controlpanel"].append(
|
||||||
commands["controlpanel"].append("AddServer %s %s %s +%s" % (user, network, host, port))
|
"SetNetwork TrustAllCerts %s %s true" % (user, network)
|
||||||
|
) # Don't judge me
|
||||||
|
commands["controlpanel"].append(
|
||||||
|
"AddServer %s %s %s +%s" % (user, network, host, port)
|
||||||
|
)
|
||||||
elif security == "plain":
|
elif security == "plain":
|
||||||
commands["controlpanel"].append("AddServer %s %s %s %s" % (user, network, host, port))
|
commands["controlpanel"].append(
|
||||||
|
"AddServer %s %s %s %s" % (user, network, host, port)
|
||||||
|
)
|
||||||
if not main.config["ConnectOnCreate"]:
|
if not main.config["ConnectOnCreate"]:
|
||||||
stage2commands["status"].append("Disconnect")
|
stage2commands["status"].append("Disconnect")
|
||||||
if main.config["Toggles"]["CycleChans"]:
|
if main.config["Toggles"]["CycleChans"]:
|
||||||
|
@ -84,7 +93,9 @@ def provisionMultipleRelays(net, relaysNeeded):
|
||||||
if not relaysNeeded:
|
if not relaysNeeded:
|
||||||
return []
|
return []
|
||||||
if not main.config["ChanKeep"]["Provision"]:
|
if not main.config["ChanKeep"]["Provision"]:
|
||||||
warn(f"Asked to create {relaysNeeded} relays for {net}, but provisioning is disabled")
|
warn(
|
||||||
|
f"Asked to create {relaysNeeded} relays for {net}, but provisioning is disabled"
|
||||||
|
)
|
||||||
return []
|
return []
|
||||||
numsProvisioned = []
|
numsProvisioned = []
|
||||||
for i in range(relaysNeeded):
|
for i in range(relaysNeeded):
|
||||||
|
|
|
@ -145,9 +145,13 @@ def enableAuthentication(net, num, jump=True, run_now=False):
|
||||||
return
|
return
|
||||||
# uname = main.alias[num]["nick"] + "/" + net
|
# uname = main.alias[num]["nick"] + "/" + net
|
||||||
password = main.network[net].aliases[num]["password"]
|
password = main.network[net].aliases[num]["password"]
|
||||||
provision.provisionAuthenticationData(num, nick, net, auth, password) # Set up for auth
|
provision.provisionAuthenticationData(
|
||||||
|
num, nick, net, auth, password
|
||||||
|
) # Set up for auth
|
||||||
if jump:
|
if jump:
|
||||||
main.IRCPool[name].msg(main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump")
|
main.IRCPool[name].msg(
|
||||||
|
main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump"
|
||||||
|
)
|
||||||
if run_now:
|
if run_now:
|
||||||
attemptManualAuthentication(net, num)
|
attemptManualAuthentication(net, num)
|
||||||
if selectInst(net)["check"] is False:
|
if selectInst(net)["check"] is False:
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from twisted.internet.threads import deferToThread
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from modules import chankeep
|
from modules import chankeep
|
||||||
|
from twisted.internet.threads import deferToThread
|
||||||
from utils.logging.debug import debug, trace
|
from utils.logging.debug import debug, trace
|
||||||
from utils.logging.log import warn
|
from utils.logging.log import warn
|
||||||
from utils.parsing import parsen
|
from utils.parsing import parsen
|
||||||
|
@ -175,7 +174,9 @@ def delUser(name, channel, nick, user):
|
||||||
p.srem(namespace, nick)
|
p.srem(namespace, nick)
|
||||||
if channels == {channel.encode()}: # can we only see them on this channel?
|
if channels == {channel.encode()}: # can we only see them on this channel?
|
||||||
p.delete(chanspace) # remove channel tracking entry
|
p.delete(chanspace) # remove channel tracking entry
|
||||||
p.hdel("live.prefix." + name + "." + channel, nick) # remove prefix tracking entry
|
p.hdel(
|
||||||
|
"live.prefix." + name + "." + channel, nick
|
||||||
|
) # remove prefix tracking entry
|
||||||
p.hdel(mapspace, nick) # remove nick mapping entry
|
p.hdel(mapspace, nick) # remove nick mapping entry
|
||||||
if user:
|
if user:
|
||||||
p.srem(gnamespace, user) # remove global userinfo entry
|
p.srem(gnamespace, user) # remove global userinfo entry
|
||||||
|
@ -200,7 +201,10 @@ def getUserByNick(name, nick):
|
||||||
if main.r.hexists(mapspace, nick):
|
if main.r.hexists(mapspace, nick):
|
||||||
return main.r.hget(mapspace, nick)
|
return main.r.hget(mapspace, nick)
|
||||||
else:
|
else:
|
||||||
warn("Entry doesn't exist: %s on %s - attempting auxiliary lookup" % (nick, mapspace))
|
warn(
|
||||||
|
"Entry doesn't exist: %s on %s - attempting auxiliary lookup"
|
||||||
|
% (nick, mapspace)
|
||||||
|
)
|
||||||
# return False
|
# return False
|
||||||
# legacy code below - remove when map is reliable
|
# legacy code below - remove when map is reliable
|
||||||
usermatch = main.r.sscan(gnamespace, match=escape(nick) + "!*", count=999999999)
|
usermatch = main.r.sscan(gnamespace, match=escape(nick) + "!*", count=999999999)
|
||||||
|
@ -230,10 +234,18 @@ def renameUser(name, oldnick, olduser, newnick, newuser):
|
||||||
p.sadd("live.who." + name + "." + i, newnick)
|
p.sadd("live.who." + name + "." + i, newnick)
|
||||||
p.hdel(mapspace, oldnick)
|
p.hdel(mapspace, oldnick)
|
||||||
p.hset(mapspace, newnick, newuser)
|
p.hset(mapspace, newnick, newuser)
|
||||||
if main.r.exists("live.prefix." + name + "." + i): # if there's a prefix entry for the channel
|
if main.r.exists(
|
||||||
if main.r.hexists("live.prefix." + name + "." + i, oldnick): # if the old nick is in it
|
"live.prefix." + name + "." + i
|
||||||
mode = main.r.hget("live.prefix." + name + "." + i, oldnick) # retrieve old modes
|
): # if there's a prefix entry for the channel
|
||||||
p.hset("live.prefix." + name + "." + i, newnick, mode) # set old modes to new nickname
|
if main.r.hexists(
|
||||||
|
"live.prefix." + name + "." + i, oldnick
|
||||||
|
): # if the old nick is in it
|
||||||
|
mode = main.r.hget(
|
||||||
|
"live.prefix." + name + "." + i, oldnick
|
||||||
|
) # retrieve old modes
|
||||||
|
p.hset(
|
||||||
|
"live.prefix." + name + "." + i, newnick, mode
|
||||||
|
) # set old modes to new nickname
|
||||||
if main.r.exists(chanspace):
|
if main.r.exists(chanspace):
|
||||||
p.rename(chanspace, newchanspace)
|
p.rename(chanspace, newchanspace)
|
||||||
else:
|
else:
|
||||||
|
@ -299,6 +311,8 @@ def delChannels(net, channels): # we have left a channel
|
||||||
if channel in dupes[net]:
|
if channel in dupes[net]:
|
||||||
if dupes[net][channel] != 0:
|
if dupes[net][channel] != 0:
|
||||||
channels.remove(channel)
|
channels.remove(channel)
|
||||||
debug(f"Not removing channel {channel} as {net} has {dupes[net][channel]} other relays covering it")
|
debug(
|
||||||
|
f"Not removing channel {channel} as {net} has {dupes[net][channel]} other relays covering it"
|
||||||
|
)
|
||||||
deferToThread(_delChannels, net, channels)
|
deferToThread(_delChannels, net, channels)
|
||||||
# d.addCallback(testCallback)
|
# d.addCallback(testCallback)
|
||||||
|
|
|
@ -49,7 +49,9 @@ class TestChanKeep(TestCase):
|
||||||
instances = 1
|
instances = 1
|
||||||
chanlimit = 5
|
chanlimit = 5
|
||||||
max_chans = instances * chanlimit
|
max_chans = instances * chanlimit
|
||||||
listinfo = self.generate_listinfo(ranges=[[1000, 1, 2], [200, 400, 800], [10, 1000, 2000]])
|
listinfo = self.generate_listinfo(
|
||||||
|
ranges=[[1000, 1, 2], [200, 400, 800], [10, 1000, 2000]]
|
||||||
|
)
|
||||||
# listinfo_num = [x[1] for x in listinfo]
|
# listinfo_num = [x[1] for x in listinfo]
|
||||||
|
|
||||||
listlength = len(listinfo)
|
listlength = len(listinfo)
|
||||||
|
|
|
@ -5,18 +5,17 @@ from os import getenv
|
||||||
from signal import SIGINT, signal
|
from signal import SIGINT, signal
|
||||||
from sys import stderr, stdout
|
from sys import stderr, stdout
|
||||||
|
|
||||||
from twisted.internet import reactor
|
|
||||||
|
|
||||||
# Webapp stuff
|
|
||||||
from twisted.internet.protocol import Factory
|
|
||||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
|
||||||
|
|
||||||
import core.logstash
|
import core.logstash
|
||||||
import main
|
import main
|
||||||
import modules.counters
|
import modules.counters
|
||||||
from api.views import API
|
from api.views import API
|
||||||
from core.relay import RelayFactory
|
from core.relay import RelayFactory
|
||||||
from core.server import ServerFactory
|
from core.server import ServerFactory
|
||||||
|
from twisted.internet import reactor
|
||||||
|
|
||||||
|
# Webapp stuff
|
||||||
|
from twisted.internet.protocol import Factory
|
||||||
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||||
from utils.cleanup import handler
|
from utils.cleanup import handler
|
||||||
from utils.loaders.command_loader import loadCommands
|
from utils.loaders.command_loader import loadCommands
|
||||||
from utils.logging.log import log
|
from utils.logging.log import log
|
||||||
|
@ -48,10 +47,14 @@ trues = ("true", "1", "t", True)
|
||||||
# Main listener
|
# Main listener
|
||||||
listener_address = getenv("THRESHOLD_LISTENER_HOST", main.config["Listener"]["Address"])
|
listener_address = getenv("THRESHOLD_LISTENER_HOST", main.config["Listener"]["Address"])
|
||||||
listener_port = int(getenv("THRESHOLD_LISTENER_PORT", main.config["Listener"]["Port"]))
|
listener_port = int(getenv("THRESHOLD_LISTENER_PORT", main.config["Listener"]["Port"]))
|
||||||
listener_ssl = getenv("THRESHOLD_LISTENER_SSL", main.config["Listener"]["UseSSL"]) in trues
|
listener_ssl = (
|
||||||
|
getenv("THRESHOLD_LISTENER_SSL", main.config["Listener"]["UseSSL"]) in trues
|
||||||
|
)
|
||||||
|
|
||||||
# RelayAPI
|
# RelayAPI
|
||||||
relay_enabled = getenv("THRESHOLD_RELAY_ENABLED", main.config["RelayAPI"]["Enabled"]) in trues
|
relay_enabled = (
|
||||||
|
getenv("THRESHOLD_RELAY_ENABLED", main.config["RelayAPI"]["Enabled"]) in trues
|
||||||
|
)
|
||||||
relay_address = getenv("THRESHOLD_RELAY_HOST", main.config["RelayAPI"]["Address"])
|
relay_address = getenv("THRESHOLD_RELAY_HOST", main.config["RelayAPI"]["Address"])
|
||||||
relay_port = int(getenv("THRESHOLD_RELAY_PORT", main.config["RelayAPI"]["Port"]))
|
relay_port = int(getenv("THRESHOLD_RELAY_PORT", main.config["RelayAPI"]["Port"]))
|
||||||
relay_ssl = getenv("THRESHOLD_RELAY_SSL", main.config["RelayAPI"]["UseSSL"]) in trues
|
relay_ssl = getenv("THRESHOLD_RELAY_SSL", main.config["RelayAPI"]["UseSSL"]) in trues
|
||||||
|
@ -102,7 +105,10 @@ if __name__ == "__main__":
|
||||||
),
|
),
|
||||||
interface=relay_address,
|
interface=relay_address,
|
||||||
)
|
)
|
||||||
log("Threshold relay running with SSL on %s:%s" % (relay_address, relay_port))
|
log(
|
||||||
|
"Threshold relay running with SSL on %s:%s"
|
||||||
|
% (relay_address, relay_port)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
reactor.listenTCP(
|
reactor.listenTCP(
|
||||||
relay_port,
|
relay_port,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from twisted.internet import reactor
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
from twisted.internet import reactor
|
||||||
from utils.logging.debug import debug
|
from utils.logging.debug import debug
|
||||||
from utils.logging.log import log
|
from utils.logging.log import log
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,8 @@ from copy import deepcopy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from json import dumps
|
from json import dumps
|
||||||
|
|
||||||
from siphashc import siphash
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
|
from siphashc import siphash
|
||||||
from utils.logging.debug import debug
|
from utils.logging.debug import debug
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,16 +11,24 @@ def dedup(numName, b):
|
||||||
c = deepcopy(b)
|
c = deepcopy(b)
|
||||||
if "ts" in c.keys():
|
if "ts" in c.keys():
|
||||||
del c["ts"]
|
del c["ts"]
|
||||||
c["approxtime"] = str(datetime.utcnow().timestamp())[: main.config["Tweaks"]["DedupPrecision"]]
|
c["approxtime"] = str(datetime.utcnow().timestamp())[
|
||||||
|
: main.config["Tweaks"]["DedupPrecision"]
|
||||||
|
]
|
||||||
castHash = siphash(main.hashKey, dumps(c, sort_keys=True))
|
castHash = siphash(main.hashKey, dumps(c, sort_keys=True))
|
||||||
del c["approxtime"]
|
del c["approxtime"]
|
||||||
isDuplicate = any(castHash in main.lastEvents[x] for x in main.lastEvents.keys() if not x == numName)
|
isDuplicate = any(
|
||||||
|
castHash in main.lastEvents[x]
|
||||||
|
for x in main.lastEvents.keys()
|
||||||
|
if not x == numName
|
||||||
|
)
|
||||||
if isDuplicate:
|
if isDuplicate:
|
||||||
debug("Duplicate: %s" % (c))
|
debug("Duplicate: %s" % (c))
|
||||||
return True
|
return True
|
||||||
if numName in main.lastEvents.keys():
|
if numName in main.lastEvents.keys():
|
||||||
main.lastEvents[numName].insert(0, castHash)
|
main.lastEvents[numName].insert(0, castHash)
|
||||||
main.lastEvents[numName] = main.lastEvents[numName][0 : main.config["Tweaks"]["MaxHash"]] # noqa
|
main.lastEvents[numName] = main.lastEvents[numName][
|
||||||
|
0 : main.config["Tweaks"]["MaxHash"]
|
||||||
|
] # noqa
|
||||||
else:
|
else:
|
||||||
main.lastEvents[numName] = [castHash]
|
main.lastEvents[numName] = [castHash]
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from twisted.internet import reactor
|
|
||||||
from twisted.internet.protocol import ReconnectingClientFactory
|
|
||||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
|
||||||
from twisted.words.protocols.irc import IRCClient
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from core.relay import sendRelayNotification
|
from core.relay import sendRelayNotification
|
||||||
from modules import userinfo
|
from modules import userinfo
|
||||||
|
from twisted.internet import reactor
|
||||||
|
from twisted.internet.protocol import ReconnectingClientFactory
|
||||||
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||||
|
from twisted.words.protocols.irc import IRCClient
|
||||||
from utils.get import getRelay
|
from utils.get import getRelay
|
||||||
from utils.logging.log import error, log
|
from utils.logging.log import error, log
|
||||||
from utils.logging.send import sendAll
|
from utils.logging.send import sendAll
|
||||||
|
@ -157,7 +156,11 @@ class IRCRelayFactory(ReconnectingClientFactory):
|
||||||
def deliverRelayCommands(num, relayCommands, user=None, stage2=None):
|
def deliverRelayCommands(num, relayCommands, user=None, stage2=None):
|
||||||
keyFN = main.certPath + main.config["Key"]
|
keyFN = main.certPath + main.config["Key"]
|
||||||
certFN = main.certPath + main.config["Certificate"]
|
certFN = main.certPath + main.config["Certificate"]
|
||||||
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
|
contextFactory = DefaultOpenSSLContextFactory(
|
||||||
bot = IRCRelayFactory(net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2)
|
keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace")
|
||||||
|
)
|
||||||
|
bot = IRCRelayFactory(
|
||||||
|
net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2
|
||||||
|
)
|
||||||
host, port = getRelay(num)
|
host, port = getRelay(num)
|
||||||
reactor.connectSSL(host, port, bot, contextFactory)
|
reactor.connectSSL(host, port, bot, contextFactory)
|
||||||
|
|
|
@ -13,11 +13,15 @@ def loadCommands(allowDup=False):
|
||||||
# try:
|
# try:
|
||||||
module = __import__("commands.%s" % commandName)
|
module = __import__("commands.%s" % commandName)
|
||||||
if commandName not in CommandMap:
|
if commandName not in CommandMap:
|
||||||
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
CommandMap[commandName] = getattr(
|
||||||
|
getattr(module, commandName), className
|
||||||
|
)
|
||||||
debug("Registered command: %s" % commandName)
|
debug("Registered command: %s" % commandName)
|
||||||
else:
|
else:
|
||||||
if allowDup:
|
if allowDup:
|
||||||
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
CommandMap[commandName] = getattr(
|
||||||
|
getattr(module, commandName), className
|
||||||
|
)
|
||||||
debug("Registered command: %s" % commandName)
|
debug("Registered command: %s" % commandName)
|
||||||
|
|
||||||
error("Duplicate command: %s" % (commandName))
|
error("Duplicate command: %s" % (commandName))
|
||||||
|
|
|
@ -12,7 +12,9 @@ def loadSingle(commandName):
|
||||||
try:
|
try:
|
||||||
if commandName in CommandMap.keys():
|
if commandName in CommandMap.keys():
|
||||||
reload(sys.modules["commands." + commandName])
|
reload(sys.modules["commands." + commandName])
|
||||||
CommandMap[commandName] = getattr(sys.modules["commands." + commandName], className)
|
CommandMap[commandName] = getattr(
|
||||||
|
sys.modules["commands." + commandName], className
|
||||||
|
)
|
||||||
debug("Reloaded command: %s" % commandName)
|
debug("Reloaded command: %s" % commandName)
|
||||||
return "RELOAD"
|
return "RELOAD"
|
||||||
module = __import__("commands.%s" % commandName)
|
module = __import__("commands.%s" % commandName)
|
||||||
|
|
Loading…
Reference in New Issue