Revert "Reformat project"

This reverts commit 64e3e1160aa76d191740342ab3edc68807f890fb.
master
Mark Veidemanis 2 years ago
parent 760e43b59a
commit 3229d9b806

@ -1,21 +1,13 @@
repos: repos:
- repo: https://github.com/psf/black - repo: https://github.com/ambv/black
rev: 22.6.0 rev: 22.3.0
hooks: hooks:
- id: black - id: black
exclude: ^core/migrations args:
- repo: https://github.com/PyCQA/isort - --line-length=120
rev: 5.10.1 - repo: https://gitlab.com/pycqa/flake8
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1 rev: 4.0.1
hooks: hooks:
- id: flake8 - id: flake8
args: [--max-line-length=88] args:
exclude: ^core/migrations - "--max-line-length=120"
- repo: https://github.com/thibaudcolas/curlylint
rev: v0.13.1
hooks:
- id: curlylint
files: \.(html|sls)$

@ -6,9 +6,7 @@ class AdmallCommand:
def __init__(self, *args): def __init__(self, *args):
self.admall(*args) self.admall(*args)
def admall( def admall(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,6 +1,5 @@
from yaml import dump
import main import main
from yaml import dump
from modules import alias from modules import alias
@ -8,9 +7,7 @@ class AliasCommand:
def __init__(self, *args): def __init__(self, *args):
self.alias(*args) self.alias(*args)
def alias( def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,9 +6,7 @@ class AllCommand:
def __init__(self, *args): def __init__(self, *args):
self.all(*args) self.all(*args)
def all( def all(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():
@ -17,10 +15,7 @@ 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( success("Sending commands to relay %s as user %s" % (num, alias + "/" + net))
"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,9 +6,7 @@ class AllcCommand:
def __init__(self, *args): def __init__(self, *args):
self.allc(*args) self.allc(*args)
def allc( def allc(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
):
if authed: if authed:
if length > 4: if length > 4:
targets = [] targets = []
@ -22,8 +20,7 @@ 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] if main.alias[x]["nick"] == spl[2] and x in main.network[i].aliases.keys()
and x in main.network[i].aliases.keys()
] ]
else: else:
incUsage("allc") incUsage("allc")
@ -36,10 +33,7 @@ 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( success("Sending commands to relay %i as user %s" % (num, alias + "/" + net))
"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,9 +5,7 @@ class AuthcheckCommand:
def __init__(self, *args): def __init__(self, *args):
self.authcheck(*args) self.authcheck(*args)
def authcheck( def authcheck(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
):
if authed: if authed:
if length == 1: if length == 1:
results = [] results = []
@ -15,9 +13,7 @@ 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( results.append("%s - %s: %s" % (net, num, main.alias[num]["nick"]))
"%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:
@ -31,9 +27,7 @@ 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( results.append("%s - %s: %s" % (net, num, main.alias[num]["nick"]))
"%s - %s: %s" % (net, num, main.alias[num]["nick"])
)
info("\n".join(results)) info("\n".join(results))
return return
else: else:

@ -6,9 +6,7 @@ class AutoCommand:
def __init__(self, *args): def __init__(self, *args):
self.auto(*args) self.auto(*args)
def auto( def auto(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():
@ -16,15 +14,9 @@ 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( success("Successfully created first relay on network %s with alias %s" % (i, alias))
"Successfully created first relay on network %s with alias %s"
% (i, alias)
)
provision.provisionRelay(num, i) provision.provisionRelay(num, i)
success( success("Started provisioning network %s on first relay for alias %s" % (i, alias))
"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:
@ -35,15 +27,9 @@ 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( success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias))
"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( success("Started provisioning network %s on relay %s for alias %s" % (spl[1], num, alias))
"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,15 +1,12 @@
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( def blacklist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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))

@ -6,9 +6,7 @@ class ChansCommand:
def __init__(self, *args): def __init__(self, *args):
self.chans(*args) self.chans(*args)
def chans( def chans(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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")

@ -6,9 +6,7 @@ class CmdCommand:
def __init__(self, *args): def __init__(self, *args):
self.cmd(*args) self.cmd(*args)
def cmd( def cmd(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,9 +6,7 @@ class ConfirmCommand:
def __init__(self, *args): def __init__(self, *args):
self.confirm(*args) self.confirm(*args)
def confirm( def confirm(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():
@ -21,10 +19,7 @@ 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( success("Requested confirmation on %s - %s with token %s" % (spl[1], spl[2], spl[3]))
"Requested confirmation on %s - %s with token %s"
% (spl[1], spl[2], spl[3])
)
return return
else: else:
incUsage("confirm") incUsage("confirm")

@ -6,9 +6,7 @@ class DisableCommand:
def __init__(self, *args): def __init__(self, *args):
self.disable(*args) self.disable(*args)
def disable( def disable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():

@ -1,15 +1,12 @@
from subprocess import PIPE, run
import main import main
from subprocess import run, PIPE
class DistCommand: class DistCommand:
def __init__(self, *args): def __init__(self, *args):
self.dist(*args) self.dist(*args)
def dist( def dist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,15 +1,12 @@
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( def email(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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":
@ -22,16 +19,10 @@ class EmailCommand:
return return
if not domain in main.irc["_"]["domains"]: if not domain in main.irc["_"]["domains"]:
main.irc["_"]["domains"].append(domain) main.irc["_"]["domains"].append(domain)
success( success("Successfully added domain %s to default config" % domain)
"Successfully added domain %s to default config"
% domain
)
main.saveConf("irc") main.saveConf("irc")
else: else:
failure( failure("Domain already exists in default config: %s" % domain)
"Domain already exists in default config: %s"
% domain
)
return return
elif spl[1] == "del": elif spl[1] == "del":
if not spl[2].isdigit(): if not spl[2].isdigit():
@ -41,16 +32,10 @@ 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( success("Successfully removed domain %s to default config" % domain)
"Successfully removed domain %s to default config"
% domain
)
main.saveConf("irc") main.saveConf("irc")
else: else:
failure( failure("Domain does not exist in default config: %s" % domain)
"Domain does not exist in default config: %s"
% domain
)
return return
else: else:
@ -62,15 +47,10 @@ 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( success("Successfully added email %s to alias %i" % (spl[3], num))
"Successfully added email %s to alias %i"
% (spl[3], num)
)
return return
else: else:
failure( failure("Email already exists in alias %i: %s" % (num, spl[3]))
"Email already exists in alias %i: %s" % (num, spl[3])
)
return return
elif spl[1] == "del": elif spl[1] == "del":
if not num in main.alias.keys(): if not num in main.alias.keys():
@ -79,15 +59,10 @@ 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( success("Successfully removed email %s from alias %i" % (spl[3], num))
"Successfully removed email %s from alias %i"
% (spl[3], num)
)
return return
else: else:
failure( failure("Email does not exist in alias %i: %s" % (spl[3], num))
"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":
@ -99,12 +74,7 @@ class EmailCommand:
elif length == 3: elif length == 3:
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
else: else:

@ -6,9 +6,7 @@ class EnableCommand:
def __init__(self, *args): def __init__(self, *args):
self.enable(*args) self.enable(*args)
def enable( def enable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():

@ -5,9 +5,7 @@ class ExecCommand:
def __init__(self, *args): def __init__(self, *args):
self.exec(*args) self.exec(*args)
def exec( def exec(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
):
if authed: if authed:
if length > 1: if length > 1:
try: try:

@ -5,9 +5,7 @@ class HelpCommand:
def __init__(self, *args): def __init__(self, *args):
self.help(*args) self.help(*args)
def help( def help(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,9 +6,7 @@ class JoinCommand:
def __init__(self, *args): def __init__(self, *args):
self.join(*args) self.join(*args)
def join( def join(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():

@ -5,9 +5,7 @@ class ListCommand:
def __init__(self, *args): def __init__(self, *args):
self.list(*args) self.list(*args)
def list( def list(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,9 +5,7 @@ class LoadCommand:
def __init__(self, *args): def __init__(self, *args):
self.load(*args) self.load(*args)
def load( def load(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():

@ -6,9 +6,7 @@ class LoadmodCommand:
def __init__(self, *args): def __init__(self, *args):
self.loadmod(*args) self.loadmod(*args)
def loadmod( def loadmod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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])

@ -5,9 +5,7 @@ class LogoutCommand:
def __init__(self, *args): def __init__(self, *args):
self.logout(*args) self.logout(*args)
def logout( def logout(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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")

@ -1,6 +1,5 @@
from yaml import dump
import main import main
from yaml import dump
class ModCommand: class ModCommand:
@ -8,9 +7,7 @@ class ModCommand:
def __init__(self, *args): def __init__(self, *args):
self.mod(*args) self.mod(*args)
def mod( def mod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():
@ -24,9 +21,7 @@ class ModCommand:
return return
main.saveConf("network") main.saveConf("network")
success( success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]))
"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,9 +5,7 @@ class MsgCommand:
def __init__(self, *args): def __init__(self, *args):
self.msg(*args) self.msg(*args)
def msg( def msg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():
@ -22,10 +20,7 @@ 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( success("Sent %s to %s on relay %s on network %s" % (" ".join(spl[4:]), spl[3], spl[2], spl[1]))
"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,18 +1,14 @@
from string import digits
from yaml import dump
import main import main
from yaml import dump
from modules.network import Network from modules.network import Network
from string import digits
class NetworkCommand: class NetworkCommand:
def __init__(self, *args): def __init__(self, *args):
self.network(*args) self.network(*args)
def network( def network(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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":
@ -32,9 +28,7 @@ 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( main.network[spl[2]] = Network(spl[2], spl[3], int(spl[4]), spl[5].lower(), spl[6].lower())
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,9 +5,7 @@ class PartCommand:
def __init__(self, *args): def __init__(self, *args):
self.part(*args) self.part(*args)
def part( def part(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,9 +5,7 @@ class PassCommand:
def __init__(self, *args): def __init__(self, *args):
self.password(*args) self.password(*args)
def password( def password(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,19 +5,14 @@ class PendingCommand:
def __init__(self, *args): def __init__(self, *args):
self.pending(*args) self.pending(*args)
def pending( def pending(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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( results.append("%s: confirm %s %s [code]" % (main.alias[x]["nick"], i, x))
"%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:
@ -27,10 +22,7 @@ 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( results.append("%s: confirm %s %s [code]" % (main.alias[x]["nick"], spl[1], x))
"%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,9 +5,7 @@ class RecheckauthCommand:
def __init__(self, *args): def __init__(self, *args):
self.recheckauth(*args) self.recheckauth(*args)
def recheckauth( def recheckauth(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
):
if authed: if authed:
if length == 1: if length == 1:
results = [] results = []

@ -6,9 +6,7 @@ class RegCommand:
def __init__(self, *args): def __init__(self, *args):
self.reg(*args) self.reg(*args)
def reg( def reg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,24 +1,18 @@
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( def relay(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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( success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
"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:
@ -41,10 +35,7 @@ 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( success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
"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:
@ -61,9 +52,7 @@ 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( success("Successfully deleted relay %s on network %s" % (spl[3], spl[2]))
"Successfully deleted relay %s on network %s" % (spl[3], spl[2])
)
main.saveConf("network") main.saveConf("network")
return return
else: else:

@ -5,9 +5,7 @@ class SaveCommand:
def __init__(self, *args): def __init__(self, *args):
self.save(*args) self.save(*args)
def save( def save(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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():

@ -1,17 +1,14 @@
from string import digits
import main import main
import modules.counters as count import modules.counters as count
import modules.userinfo as userinfo import modules.userinfo as userinfo
from string import digits
class StatsCommand: class StatsCommand:
def __init__(self, *args): def __init__(self, *args):
self.stats(*args) self.stats(*args)
def stats( def stats(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
):
if authed: if authed:
if length == 1: if length == 1:
stats = [] stats = []

@ -5,9 +5,7 @@ class SwhoCommand:
def __init__(self, *args): def __init__(self, *args):
self.swho(*args) self.swho(*args)
def swho( def swho(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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,17 +1,13 @@
from uuid import uuid4
from yaml import dump
import main import main
from yaml import dump
from uuid import uuid4
class TokenCommand: class TokenCommand:
def __init__(self, *args): def __init__(self, *args):
self.token(*args) self.token(*args)
def token( def token(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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":

@ -6,9 +6,7 @@ class UsersCommand:
def __init__(self, *args): def __init__(self, *args):
self.users(*args) self.users(*args)
def users( def users(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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")

@ -6,9 +6,7 @@ class WhoCommand:
def __init__(self, *args): def __init__(self, *args):
self.who(*args) self.who(*args)
def who( def who(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
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])

@ -1,38 +1,45 @@
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.words.protocols.irc import IRCClient
from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall
from twisted.internet import reactor, task
from twisted.words.protocols.irc import (
symbolic_to_numeric,
numeric_to_symbolic,
lowDequote,
IRCBadMessage,
)
import sys import sys
from string import digits
from random import randint
from copy import deepcopy from copy import deepcopy
from datetime import datetime from datetime import datetime
from random import randint
from string import digits
from twisted.internet import reactor, task from modules import userinfo
from twisted.internet.defer import Deferred from modules import counters
from twisted.internet.protocol import ReconnectingClientFactory from modules import monitor
from twisted.internet.ssl import DefaultOpenSSLContextFactory from modules import chankeep
from twisted.internet.task import LoopingCall from modules import regproc
from twisted.words.protocols.irc import (IRCBadMessage, IRCClient, lowDequote,
numeric_to_symbolic,
symbolic_to_numeric)
import main
from core.relay import sendRelayNotification from core.relay import sendRelayNotification
from modules import chankeep, counters, monitor, regproc, userinfo
from utils.dedup import dedup from utils.dedup import dedup
from utils.get import getRelay from utils.get import getRelay
from utils.logging.debug import *
import main
from utils.logging.log import * from utils.logging.log import *
from utils.logging.debug import *
from utils.logging.send import * from utils.logging.send import *
from utils.parsing import parsen from utils.parsing import parsen
from twisted.internet.ssl import DefaultOpenSSLContextFactory
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( contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace") bot = IRCBotFactory(net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2)
)
bot = IRCBotFactory(
net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2
)
host, port = getRelay(num) host, port = getRelay(num)
rct = reactor.connectSSL(host, port, bot, contextFactory) rct = reactor.connectSSL(host, port, bot, contextFactory)
@ -158,9 +165,7 @@ 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 = ( self.wantList = False # we want to send a LIST, but not all relays are active yet
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
@ -192,14 +197,9 @@ class IRCBot(IRCClient):
if not i in self.channels: if not i 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( debug("Not joining blacklisted channel %s on %s - %i" % (i, self.net, self.num))
"Not joining blacklisted channel %s on %s - %i"
% (i, self.net, self.num)
)
continue continue
debug( debug(self.net, "-", self.num, ": joining", i, "in", sleeptime, "seconds")
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:
@ -207,17 +207,11 @@ class IRCBot(IRCClient):
increment = 0.7 increment = 0.7
increment += 0.1 increment += 0.1
else: else:
error( error("%s - Cannot join channel we are already on: %s - %i" % (i, self.net, self.num))
"%s - Cannot join channel we are already on: %s - %i"
% (i, self.net, self.num)
)
def checkChannels(self): def checkChannels(self):
if not chankeep.allRelaysActive(self.net): if not chankeep.allRelaysActive(self.net):
debug( debug("Skipping channel check as we have inactive relays: %s - %i" % (self.net, self.num))
"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():
@ -231,9 +225,7 @@ 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( for i in list(cast.keys()): # Make a copy of the .keys() as Python 3 cannot handle iterating over
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
@ -367,9 +359,7 @@ 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( sendAll("%s - %i: password mismatch as %s" % (self.net, self.num, self.username))
"%s - %i: password mismatch as %s" % (self.net, self.num, self.username)
)
def _who(self, channel): def _who(self, channel):
d = Deferred() d = Deferred()
@ -484,17 +474,12 @@ 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( debug("List request dropped, already asked for LIST - %s - %i" % (self.net, self.num))
"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( debug("LIST request dropped, already ongoing - %s - %i" % (self.net, self.num))
"LIST request dropped, already ongoing - %s - %i" % (self.net, self.num)
)
return return
else: else:
if nocheck: if nocheck:
@ -519,9 +504,7 @@ 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 ( if not len(self._tempList[0]) > 0: # there are no callbacks, can't do anything there
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()
@ -546,10 +529,7 @@ class IRCBot(IRCClient):
else: else:
if self.listRetried: if self.listRetried:
self.listRetried = False self.listRetried = False
debug( debug("List received after retry - defaulting to simple list syntax: %s - %i" % (self.net, self.num))
"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):
@ -563,10 +543,7 @@ class IRCBot(IRCClient):
name = self.net + "1" name = self.net + "1"
if main.IRCPool[name].wantList == True: if main.IRCPool[name].wantList == True:
main.IRCPool[name].list(nocheck=True) main.IRCPool[name].list(nocheck=True)
debug( debug("Asking for a list for %s after final relay %i connected" % (self.net, self.num))
"Asking for a list for %s after final relay %i connected"
% (self.net, self.num)
)
if self.num == 1: # Only one instance should do a list if self.num == 1: # Only one instance should do a list
if self.chanlimit: if self.chanlimit:
if allRelays: if allRelays:
@ -583,9 +560,7 @@ 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( self._regAttempt = reactor.callLater(5, regproc.registerAccount, self.net, self.num)
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)
@ -593,9 +568,7 @@ class IRCBot(IRCClient):
warn("Invalid chanlimit: %s" % i) warn("Invalid chanlimit: %s" % i)
if self.chanlimit == 0: if self.chanlimit == 0:
self.chanlimit = 200 # don't take the piss if it's not limited self.chanlimit = 200 # don't take the piss if it's not limited
if not regproc.needToRegister( if not regproc.needToRegister(self.net): # if we need to register, only recheck on auth confirmation
self.net
): # if we need to register, only recheck on auth confirmation
self.recheckList() self.recheckList()
def seed_prefix(self, prefix): def seed_prefix(self, prefix):
@ -696,9 +669,7 @@ class IRCBot(IRCClient):
if negativepass == True: if negativepass == True:
if self._negativePass == None: if self._negativePass == None:
self._negativePass = True self._negativePass = True
debug( debug("Positive registration check - %s - %i" % (self.net, self.num))
"Positive registration check - %s - %i" % (self.net, self.num)
)
if sinst["ping"]: if sinst["ping"]:
debug("Sending ping - %s - %i" % (self.net, self.num)) debug("Sending ping - %s - %i" % (self.net, self.num))
self.msg(sinst["entity"], sinst["pingmsg"]) self.msg(sinst["entity"], sinst["pingmsg"])
@ -754,9 +725,7 @@ 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( userinfo.delChannels(self.net, [channel]) # < we do not need to deduplicate this
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

@ -1,8 +1,7 @@
import logging
from json import dumps, loads
import logstash import logstash
import logging
from json import dumps, loads
import main import main
from utils.logging.log import * from utils.logging.log import *

@ -24,9 +24,7 @@ def parseCommand(addr, authed, data):
failure("No text was sent") failure("No text was sent")
return return
if spl[0] in main.CommandMap.keys(): if spl[0] in main.CommandMap.keys():
main.CommandMap[spl[0]]( main.CommandMap[spl[0]](addr, authed, data, obj, spl, success, failure, info, incUsage, length)
addr, authed, data, obj, spl, success, failure, info, incUsage, length
)
return return
incUsage(None) incUsage(None)
return return

@ -1,7 +1,6 @@
from copy import deepcopy from twisted.internet.protocol import Protocol, Factory, ClientFactory
from json import dumps, loads from json import dumps, loads
from copy import deepcopy
from twisted.internet.protocol import ClientFactory, Factory, Protocol
import main import main
from utils.logging.log import * from utils.logging.log import *
@ -115,13 +114,8 @@ class Relay(Protocol):
def handleHello(self, parsed): def handleHello(self, parsed):
if parsed["key"] in main.tokens.keys(): if parsed["key"] in main.tokens.keys():
if ( if parsed["hello"] == main.tokens[parsed["key"]]["hello"] and main.tokens[parsed["key"]]["usage"] == "relay":
parsed["hello"] == main.tokens[parsed["key"]]["hello"] self.sendMsg({"type": "hello", "hello": main.tokens[parsed["key"]]["counter"]})
and main.tokens[parsed["key"]]["usage"] == "relay"
):
self.sendMsg(
{"type": "hello", "hello": main.tokens[parsed["key"]]["counter"]}
)
self.authed = True self.authed = True
else: else:
self.transport.loseConnection() self.transport.loseConnection()
@ -136,10 +130,7 @@ class Relay(Protocol):
def connectionLost(self, reason): def connectionLost(self, reason):
self.authed = False self.authed = False
log( log("Relay connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage()))
"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,9 +1,9 @@
from twisted.internet.protocol import ClientFactory, Factory, Protocol from twisted.internet.protocol import Protocol, Factory, ClientFactory
import main import main
from core.parser import parseCommand
from utils.logging.log import * from utils.logging.log import *
from core.parser import parseCommand
class Server(Protocol): class Server(Protocol):
def __init__(self, addr): def __init__(self, addr):
@ -34,10 +34,7 @@ class Server(Protocol):
def connectionLost(self, reason): def connectionLost(self, reason):
self.authed = False self.authed = False
log( log("Connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage()))
"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:

@ -1,9 +1,8 @@
import json import json
import pickle import pickle
from os import urandom
from string import digits
from redis import StrictRedis from redis import StrictRedis
from string import digits
from os import urandom
from utils.logging.log import * from utils.logging.log import *
@ -107,9 +106,5 @@ def initConf():
def initMain(): def initMain():
global r, g global r, g
initConf() initConf()
r = StrictRedis( r = StrictRedis(unix_socket_path=config["RedisSocket"], db=config["RedisDBEphemeral"]) # Ephemeral - flushed on quit
unix_socket_path=config["RedisSocket"], db=config["RedisDBEphemeral"] g = StrictRedis(unix_socket_path=config["RedisSocket"], db=config["RedisDBPersistent"]) # Persistent
) # Ephemeral - flushed on quit
g = StrictRedis(
unix_socket_path=config["RedisSocket"], db=config["RedisDBPersistent"]
) # Persistent

@ -1,8 +1,7 @@
import main
import random import random
import re import re
import main
def generate_password(): def generate_password():
return "".join([chr(random.randint(0, 74) + 48) for i in range(32)]) return "".join([chr(random.randint(0, 74) + 48) for i in range(32)])

@ -1,12 +1,10 @@
import main
from utils.logging.log import *
from utils.logging.debug import *
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 modules.provision import modules.provision
from utils.logging.debug import * from twisted.internet.threads import deferToThread
from utils.logging.log import *
def allRelaysActive(net): def allRelaysActive(net):
@ -48,10 +46,7 @@ def emptyChanAllocate(net, flist, relay, new):
if toalloc > sum(chanfree[0].values()): if toalloc > sum(chanfree[0].values()):
correction = round(toalloc - sum(chanfree[0].values()) / chanfree[1]) correction = round(toalloc - sum(chanfree[0].values()) / chanfree[1])
# print("correction", correction) # print("correction", correction)
warn( warn("Ran out of channel spaces, provisioning additional %i relays for %s" % (correction, net))
"Ran out of channel spaces, provisioning additional %i relays for %s"
% (correction, net)
)
# newNums = modules.provision.provisionMultipleRelays(net, correction) # newNums = modules.provision.provisionMultipleRelays(net, correction)
return False return False
for i in chanfree[0].keys(): for i in chanfree[0].keys():
@ -104,18 +99,12 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
listinfo = minifyChans(net, listinfo) listinfo = minifyChans(net, listinfo)
if not listinfo: if not listinfo:
return return
if ( if relay <= main.config["ChanKeep"]["SigSwitch"]: # we can cover all of the channels
relay <= main.config["ChanKeep"]["SigSwitch"]
): # we can cover all of the channels
coverAll = True coverAll = True
elif ( elif relay > main.config["ChanKeep"]["SigSwitch"]: # we cannot cover all of the channels
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( error("Network %s is too big to cover: %i relays required" % (net, sigrelay))
"Network %s is too big to cover: %i relays required" % (net, sigrelay)
)
return return
if coverAll: if coverAll:
needed = relay - len(main.network[net].relays.keys()) needed = relay - len(main.network[net].relays.keys())

@ -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):

@ -2,9 +2,10 @@ from copy import deepcopy
from json import dumps from json import dumps
import main import main
from core.logstash import sendLogstashNotification
from core.relay import sendRelayNotification from core.relay import sendRelayNotification
from modules import regproc, userinfo from core.logstash import sendLogstashNotification
from modules import userinfo
from modules import regproc
from utils.dedup import dedup from utils.dedup import dedup
order = [ order = [
@ -67,9 +68,7 @@ def parsemeta(numName, c):
) )
def event( def event(numName, c): # yes I'm using a short variable because otherwise it goes off the screen
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,15 +1,14 @@
import json
from twisted.internet import reactor
from twisted.internet.ssl import DefaultOpenSSLContextFactory from twisted.internet.ssl import DefaultOpenSSLContextFactory
import json
import main
from core.bot import IRCBot, IRCBotFactory
from modules import alias from modules import alias
from modules.chankeep import nukeNetwork from modules.chankeep import nukeNetwork
from modules.regproc import needToRegister from modules.regproc import needToRegister
from utils.get import getRelay from twisted.internet import reactor
from core.bot import IRCBot, IRCBotFactory
import main
from utils.logging.log import * from utils.logging.log import *
from utils.get import getRelay
class Network: class Network:
@ -78,9 +77,7 @@ class Network:
# e.g. freenode1 for the first relay on freenode network # e.g. freenode1 for the first relay on freenode network
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( contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace")
)
bot = IRCBotFactory(self.net, num) bot = IRCBotFactory(self.net, num)
# host, port = self.relays[num]["host"], self.relays[num]["port"] # host, port = self.relays[num]["host"], self.relays[num]["port"]
host, port = getRelay(num) host, port = getRelay(num)

@ -1,25 +1,11 @@
from twisted.internet import reactor
import main import main
import modules.regproc
from core.bot import deliverRelayCommands from core.bot import deliverRelayCommands
from utils.logging.log import * from utils.logging.log import *
from twisted.internet import reactor
import modules.regproc
def provisionUserNetworkData( def provisionUserNetworkData(num, nick, altnick, ident, realname, emails, network, host, port, security, auth, password):
num,
nick,
altnick,
ident,
realname,
emails,
network,
host,
port,
security,
auth,
password,
):
print("nick", nick) print("nick", nick)
print("altnick", altnick) print("altnick", altnick)
print("emails", emails) print("emails", emails)
@ -30,25 +16,17 @@ def provisionUserNetworkData(
stage2commands["status"] = [] stage2commands["status"] = []
commands["controlpanel"] = [] commands["controlpanel"] = []
user = nick.lower() user = nick.lower()
commands["controlpanel"].append( commands["controlpanel"].append("AddUser %s %s" % (user, main.config["Relay"]["Password"]))
"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( commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (user, network)) # Don't judge me
"SetNetwork TrustAllCerts %s %s true" % (user, network) commands["controlpanel"].append("AddServer %s %s %s +%s" % (user, network, host, port))
) # 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( commands["controlpanel"].append("AddServer %s %s %s %s" % (user, network, host, port))
"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"]:

@ -1,11 +1,9 @@
from copy import deepcopy
from random import choice
import main import main
from modules import provision from modules import provision
from utils.logging.debug import *
from utils.logging.log import * from utils.logging.log import *
from utils.logging.debug import *
from copy import deepcopy
from random import choice
def needToRegister(net): def needToRegister(net):
# Check if the network does not support authentication # Check if the network does not support authentication
@ -53,7 +51,7 @@ def substitute(net, num, token=None):
nickname = alias["nick"] nickname = alias["nick"]
username = nickname + "/" + net username = nickname + "/" + net
password = main.network[net].aliases[num]["password"] password = main.network[net].aliases[num]["password"]
# inst["email"] = inst["email"].replace("{nickname}", nickname) #inst["email"] = inst["email"].replace("{nickname}", nickname)
for i in inst.keys(): for i in inst.keys():
if not isinstance(inst[i], str): if not isinstance(inst[i], str):
continue continue
@ -114,12 +112,8 @@ def enableAuthentication(net, num):
auth = obj.auth auth = obj.auth
password = obj.aliases[num]["password"] password = obj.aliases[num]["password"]
uname = main.alias[num]["nick"] + "/" + net uname = main.alias[num]["nick"] + "/" + net
provision.provisionAuthenticationData( provision.provisionAuthenticationData(num, nick, net, security, auth, password) # Set up for auth
num, nick, net, security, auth, password main.IRCPool[net + str(num)].msg(main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump")
) # Set up for auth
main.IRCPool[net + str(num)].msg(
main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump"
)
if selectInst(net)["check"] == False: if selectInst(net)["check"] == False:
confirmRegistration(net, num) confirmRegistration(net, num)
@ -135,14 +129,10 @@ def registerTest(c):
if not main.IRCPool[name]._negativePass == True: if not main.IRCPool[name]._negativePass == True:
if c["type"] == "query" and c["nick"] == sinst["entity"]: if c["type"] == "query" and c["nick"] == sinst["entity"]:
if sinst["checknegativemsg"] in c["msg"]: if sinst["checknegativemsg"] in c["msg"]:
confirmRegistration( confirmRegistration(c["net"], c["num"], negativepass=False) # Not passed negative check, report back
c["net"], c["num"], negativepass=False
) # Not passed negative check, report back
return return
if sinst["checkendnegative"] in c["msg"]: if sinst["checkendnegative"] in c["msg"]:
confirmRegistration( confirmRegistration(c["net"], c["num"], negativepass=True) # Passed the negative check, report back
c["net"], c["num"], negativepass=True
) # Passed the negative check, report back
return return
if sinst["ping"]: if sinst["ping"]:
if sinst["checkmsg2"] in c["msg"] and c["nick"] == sinst["entity"]: if sinst["checkmsg2"] in c["msg"] and c["nick"] == sinst["entity"]:

@ -1,10 +1,9 @@
from string import digits
from twisted.internet.threads import deferToThread from twisted.internet.threads import deferToThread
from string import digits
import main import main
from utils.logging.debug import debug, trace
from utils.logging.log import * from utils.logging.log import *
from utils.logging.debug import debug, trace
from utils.parsing import parsen from utils.parsing import parsen
@ -146,9 +145,7 @@ 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( p.hdel("live.prefix." + name + "." + channel, nick) # remove prefix tracking entry
"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
@ -173,10 +170,7 @@ 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( warn("Entry doesn't exist: %s on %s - attempting auxiliary lookup" % (nick, mapspace))
"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)
@ -206,18 +200,10 @@ 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( if main.r.exists("live.prefix." + name + "." + i): # if there's a prefix entry for the channel
"live.prefix." + name + "." + i if main.r.hexists("live.prefix." + name + "." + i, oldnick): # if the old nick is in it
): # if there's a prefix entry for the channel mode = main.r.hget("live.prefix." + name + "." + i, oldnick) # retrieve old modes
if main.r.hexists( p.hset("live.prefix." + name + "." + i, newnick, mode) # set old modes to new nickname
"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:

@ -1,14 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
from twisted.internet import reactor
from twisted.internet.ssl import DefaultOpenSSLContextFactory
import sys import sys
from codecs import getwriter # fix printing odd shit to the terminal from signal import signal, SIGINT
from signal import SIGINT, signal
# from twisted.python import log # from twisted.python import log
# from sys import stdout # from sys import stdout
# log.startLogging(stdout) # log.startLogging(stdout)
from sys import stderr, stdout # Import again because we want to override from sys import stdout, stderr # Import again because we want to override
from codecs import getwriter # fix printing odd shit to the terminal
from twisted.internet import reactor
from twisted.internet.ssl import DefaultOpenSSLContextFactory
stdout = getwriter("utf8")(stdout) # this is a generic fix but we all know stdout = getwriter("utf8")(stdout) # this is a generic fix but we all know
stderr = getwriter("utf8")(stderr) # it's just for the retards on Rizon using stderr = getwriter("utf8")(stderr) # it's just for the retards on Rizon using
@ -23,11 +23,11 @@ if "--debug" in sys.argv: # yes really
main.config["Debug"] = True main.config["Debug"] = True
if "--trace" in sys.argv: if "--trace" in sys.argv:
main.config["Trace"] = True main.config["Trace"] = True
import modules.counters
from core.relay import Relay, RelayFactory
from core.server import Server, ServerFactory
from utils.loaders.command_loader import loadCommands
from utils.logging.log import * from utils.logging.log import *
from utils.loaders.command_loader import loadCommands
from core.server import Server, ServerFactory
from core.relay import Relay, RelayFactory
import modules.counters
loadCommands() loadCommands()
import core.logstash import core.logstash
@ -46,20 +46,14 @@ if __name__ == "__main__":
), ),
interface=main.config["Listener"]["Address"], interface=main.config["Listener"]["Address"],
) )
log( log("Threshold running with SSL on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]))
"Threshold running with SSL on %s:%s"
% (main.config["Listener"]["Address"], main.config["Listener"]["Port"])
)
else: else:
reactor.listenTCP( reactor.listenTCP(
main.config["Listener"]["Port"], main.config["Listener"]["Port"],
listener, listener,
interface=main.config["Listener"]["Address"], interface=main.config["Listener"]["Address"],
) )
log( log("Threshold running on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]))
"Threshold running on %s:%s"
% (main.config["Listener"]["Address"], main.config["Listener"]["Port"])
)
if main.config["RelayAPI"]["Enabled"]: if main.config["RelayAPI"]["Enabled"]:
relay = RelayFactory() relay = RelayFactory()
if main.config["RelayAPI"]["UseSSL"] == True: if main.config["RelayAPI"]["UseSSL"] == True:
@ -82,10 +76,7 @@ if __name__ == "__main__":
relay, relay,
interface=main.config["RelayAPI"]["Address"], interface=main.config["RelayAPI"]["Address"],
) )
log( log("Threshold relay running on %s:%s" % (main.config["RelayAPI"]["Address"], main.config["RelayAPI"]["Port"]))
"Threshold relay running on %s:%s"
% (main.config["RelayAPI"]["Address"], main.config["RelayAPI"]["Port"])
)
for net in main.network.keys(): for net in main.network.keys():
main.network[net].start_bots() main.network[net].start_bots()
modules.counters.setupCounterLoop() modules.counters.setupCounterLoop()

@ -1,10 +1,8 @@
import sys
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 * from utils.logging.log import *
import sys
def handler(sig, frame): def handler(sig, frame):

@ -1,9 +1,7 @@
from copy import deepcopy
from datetime import datetime from datetime import datetime
from json import dumps
from csiphash import siphash24 from csiphash import siphash24
from copy import deepcopy
from json import dumps
import main import main
from utils.logging.debug import debug from utils.logging.debug import debug
@ -12,24 +10,16 @@ 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())[ c["approxtime"] = str(datetime.utcnow().timestamp())[: main.config["Tweaks"]["DedupPrecision"]]
: main.config["Tweaks"]["DedupPrecision"]
]
castHash = siphash24(main.hashKey, dumps(c, sort_keys=True).encode("utf-8")) castHash = siphash24(main.hashKey, dumps(c, sort_keys=True).encode("utf-8"))
del c["approxtime"] del c["approxtime"]
isDuplicate = any( isDuplicate = any(castHash in main.lastEvents[x] for x in main.lastEvents.keys() if not x == numName)
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][ main.lastEvents[numName] = main.lastEvents[numName][0 : main.config["Tweaks"]["MaxHash"]]
0 : main.config["Tweaks"]["MaxHash"]
]
else: else:
main.lastEvents[numName] = [castHash] main.lastEvents[numName] = [castHash]
return False return False

@ -1,9 +1,10 @@
from os import listdir from os import listdir
import commands
from main import CommandMap
from utils.logging.debug import debug from utils.logging.debug import debug
from utils.logging.log import * from utils.logging.log import *
import commands
from main import CommandMap
def loadCommands(allowDup=False): def loadCommands(allowDup=False):
@ -14,15 +15,11 @@ def loadCommands(allowDup=False):
try: try:
module = __import__("commands.%s" % commandName) module = __import__("commands.%s" % commandName)
if not commandName in CommandMap: if not commandName in CommandMap:
CommandMap[commandName] = getattr( CommandMap[commandName] = getattr(getattr(module, commandName), className)
getattr(module, commandName), className
)
debug("Registered command: %s" % commandName) debug("Registered command: %s" % commandName)
else: else:
if allowDup: if allowDup:
CommandMap[commandName] = getattr( CommandMap[commandName] = getattr(getattr(module, commandName), className)
getattr(module, commandName), className
)
debug("Registered command: %s" % commandName) debug("Registered command: %s" % commandName)
error("Duplicate command: %s" % (commandName)) error("Duplicate command: %s" % (commandName))

@ -1,11 +1,12 @@
import sys
from importlib import reload
from os import listdir from os import listdir
from importlib import reload
import sys
import commands
from main import CommandMap
from utils.logging.debug import debug from utils.logging.debug import debug
from utils.logging.log import * from utils.logging.log import *
import commands
from main import CommandMap
def loadSingle(commandName): def loadSingle(commandName):
@ -14,9 +15,7 @@ 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( CommandMap[commandName] = getattr(sys.modules["commands." + commandName], className)
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)

@ -1,6 +1,5 @@
import main import main
# we need a seperate module to log.py, as log.py is imported by main.py, and we need to access main # we need a seperate module to log.py, as log.py is imported by main.py, and we need to access main
# to read the setting # to read the setting
def debug(*data): def debug(*data):

Loading…
Cancel
Save