Moved files to subdirectory

This commit is contained in:
2022-09-06 12:50:09 +01:00
parent 2c3d83fe9a
commit bd9f9378cf
83 changed files with 0 additions and 0 deletions

View File

23
legacy/commands/admall.py Normal file
View File

@@ -0,0 +1,23 @@
import main
from utils.deliver_relay_commands import deliverRelayCommands
class AdmallCommand:
def __init__(self, *args):
self.admall(*args)
def admall(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length > 2:
for i in main.network.keys():
for x in main.network[i].relays.keys():
num = main.network[i].relays[x]["id"]
commands = {spl[1]: [" ".join(spl[2:])]}
success("Sending commands to relay %s" % (num))
deliverRelayCommands(num, commands)
return
else:
incUsage("admall")
return
else:
incUsage(None)

54
legacy/commands/alias.py Normal file
View File

@@ -0,0 +1,54 @@
from yaml import dump
import main
from modules import alias
class AliasCommand:
def __init__(self, *args):
self.alias(*args)
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
info(dump(main.alias))
return
elif length == 3:
if spl[1] == "add":
if not spl[2].isdigit():
failure("Must be a number, not %s" % spl[2])
return
num = int(spl[2])
for i in range(num):
if len(main.alias.keys()) == 0:
nextNum = 1
else:
nextNum = max(main.alias.keys()) + 1
main.alias[nextNum] = alias.generate_alias()
success("Generated new alias: %i" % nextNum)
main.saveConf("alias")
return
elif spl[1] == "del":
if not spl[2].isdigit():
failure("Must be a number, not %s" % spl[2])
return
num = int(spl[2])
if num not in main.alias.keys():
failure("No such alias: %i" % num)
return
failed = False
for i in main.network.keys():
if num in main.network[i].aliases.keys():
failure("Alias in use by %s" % i)
failed = True
if failed:
return
del main.alias[num]
success("Removed alias: %i" % num)
main.saveConf("alias")
return
else:
incUsage("alias")
return
else:
incUsage(None)

25
legacy/commands/all.py Normal file
View File

@@ -0,0 +1,25 @@
import main
from utils.deliver_relay_commands import deliverRelayCommands
class AllCommand:
def __init__(self, *args):
self.all(*args)
def all(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length > 2:
for i in main.network.keys():
for x in main.network[i].relays.keys():
num = main.network[i].relays[x]["id"]
net = main.network[i].relays[x]["net"]
alias = main.alias[x]["nick"]
commands = {spl[1]: [" ".join(spl[2:])]}
success("Sending commands to relay %s as user %s" % (num, alias + "/" + net))
deliverRelayCommands(num, commands, user=alias + "/" + net)
return
else:
incUsage("all")
return
else:
incUsage(None)

43
legacy/commands/allc.py Normal file
View File

@@ -0,0 +1,43 @@
import main
from utils.deliver_relay_commands import deliverRelayCommands
class AllcCommand:
def __init__(self, *args):
self.allc(*args)
def allc(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length > 4:
targets = []
if spl[1] == "network":
for i in main.network.keys():
for x in main.network[i].relays.keys():
if main.network[i].relays[x]["net"] == spl[2]:
targets.append((i, x))
elif spl[1] == "alias":
for i in main.network.keys():
[
targets.append((i, x))
for x in main.alias.keys()
if main.alias[x]["nick"] == spl[2] and x in main.network[i].aliases.keys()
]
else:
incUsage("allc")
return
if len(targets) == 0:
failure("No matches found: %s" % spl[2])
return
for i in targets:
net = i[0]
num = i[1]
alias = main.alias[num]["nick"]
commands = {spl[3]: [" ".join(spl[4:])]}
success("Sending commands to relay %i as user %s" % (num, alias + "/" + net))
deliverRelayCommands(num, commands, user=alias + "/" + net)
return
else:
incUsage("allc")
return
else:
incUsage(None)

View File

@@ -0,0 +1,37 @@
import main
class AuthcheckCommand:
def __init__(self, *args):
self.authcheck(*args)
def authcheck(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
results = []
for i in main.IRCPool.keys():
num = main.IRCPool[i].num
net = main.IRCPool[i].net
if not main.IRCPool[i].authenticated:
results.append("%s - %s: %s" % (net, num, main.alias[num]["nick"]))
info("\n".join(results))
return
elif length == 2:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
results = []
for i in main.IRCPool.keys():
num = main.IRCPool[i].num
net = main.IRCPool[i].net
if not net == spl[1]:
continue
if not main.IRCPool[i].authenticated:
results.append("%s - %s: %s" % (net, num, main.alias[num]["nick"]))
info("\n".join(results))
return
else:
incUsage("authcheck")
return
else:
incUsage(None)

39
legacy/commands/auto.py Normal file
View File

@@ -0,0 +1,39 @@
import main
from modules import provision
class AutoCommand:
def __init__(self, *args):
self.auto(*args)
def auto(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
for i in main.network.keys():
if 1 in main.network[i].relays.keys():
info("Skipping %s - first relay exists" % i)
else:
num, alias = main.network[i].add_relay(1)
success("Successfully created first relay on network %s with alias %s" % (i, alias))
provision.provisionRelay(num, i)
success("Started provisioning network %s on first relay for alias %s" % (i, alias))
main.saveConf("network")
return
elif length == 2:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
if 1 in main.network[spl[1]].relays.keys():
failure("First relay exists on %s" % spl[1])
return
num, alias = main.network[spl[1]].add_relay(1)
success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias))
provision.provisionRelay(num, spl[1])
success("Started provisioning network %s on relay %s for alias %s" % (spl[1], num, alias))
main.saveConf("network")
return
else:
incUsage("auto")
return
else:
incUsage(None)

View File

@@ -0,0 +1,43 @@
from yaml import dump
import main
class BlacklistCommand:
def __init__(self, *args):
self.blacklist(*args)
def blacklist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
info(dump(main.blacklist))
return
elif length == 4:
if spl[1] == "add":
if spl[2] in main.blacklist.keys():
main.blacklist[spl[2]].append(spl[3])
else:
main.blacklist[spl[2]] = [spl[3]]
success("Blacklisted %s on %s" % (spl[3], spl[2]))
main.saveConf("blacklist")
return
elif spl[1] == "del":
if spl[2] in main.blacklist.keys():
if spl[3] in main.blacklist[spl[2]]:
main.blacklist[spl[2]].remove(spl[3])
if len(main.blacklist[spl[2]]) == 0:
del main.blacklist[spl[2]]
else:
failure("Not in list: %s" % spl[3])
return
else:
failure("No such entry: %s" % spl[2])
return
success("Removed blacklist %s on %s" % (spl[3], spl[2]))
main.saveConf("blacklist")
return
else:
incUsage("blacklist")
return
else:
incUsage(None)

25
legacy/commands/chans.py Normal file
View File

@@ -0,0 +1,25 @@
import modules.userinfo as userinfo
class ChansCommand:
def __init__(self, *args):
self.chans(*args)
def chans(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if len(spl) < 2:
incUsage("chans")
return
result = userinfo.getChans(spl[1:])
rtrn = ""
for i in result.keys():
rtrn += "Matches from: %s" % i
rtrn += "\n"
for x in result[i]:
rtrn += x
rtrn += "\n"
rtrn += "\n"
info(rtrn)
return
else:
incUsage(None)

22
legacy/commands/cmd.py Normal file
View File

@@ -0,0 +1,22 @@
from utils.deliver_relay_commands import deliverRelayCommands
class CmdCommand:
def __init__(self, *args):
self.cmd(*args)
def cmd(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length > 4:
if not spl[1].isdigit():
failure("Must be a number, not %s" % spl[1])
return
commands = {spl[3]: [" ".join(spl[4:])]}
success("Sending commands to relay %s as user %s" % (spl[2], spl[3]))
deliverRelayCommands(int(spl[1]), commands, user=spl[2])
return
else:
incUsage("cmd")
return
else:
incUsage(None)

View File

@@ -0,0 +1,28 @@
import main
from modules import regproc
class ConfirmCommand:
def __init__(self, *args):
self.confirm(*args)
def confirm(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 4:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
if not spl[2].isdigit():
failure("Must be a number, not %s" % spl[2])
return
if not int(spl[2]) in main.network[spl[1]].relays.keys():
failure("No such relay on %s: %s" % (spl[1], spl[2]))
return
regproc.confirmAccount(spl[1], int(spl[2]), spl[3])
success("Requested confirmation on %s - %s with token %s" % (spl[1], spl[2], spl[3]))
return
else:
incUsage("confirm")
return
else:
incUsage(None)

25
legacy/commands/dedup.py Normal file
View File

@@ -0,0 +1,25 @@
from json import dumps
import main
from modules import chankeep
class DedupCommand:
def __init__(self, *args):
self.dedup(*args)
def dedup(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
dupes = chankeep.getDuplicateChannels()
chankeep.partChannels(dupes)
info(dumps(dupes))
return
elif length == 2:
if spl[1] not in main.network.keys():
failure("No such network: %s" % spl[1])
return
dupes = chankeep.getDuplicateChannels(spl[1])
chankeep.partChannels(dupes)
info(dumps(dupes))
return

View File

@@ -0,0 +1,46 @@
import main
from utils.deliver_relay_commands import deliverRelayCommands
class DisableCommand:
def __init__(self, *args):
self.disable(*args)
def disable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 3:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
if not spl[2].isdigit():
failure("Must be a number, not %s" % spl[2])
return
relayNum = int(spl[2])
name = spl[1] + spl[2]
if not spl[1] in main.IRCPool.keys():
info("Note - instance not running, proceeding anyway")
if relayNum not in main.network[spl[1]].relays.keys():
failure("No such relay: %s in network %s" % (spl[2], spl[1]))
return
main.network[spl[1]].relays[relayNum]["enabled"] = False
user = main.alias[relayNum]["nick"]
network = spl[1]
# relay = main.network[spl[1]].relays[relayNum]
commands = {"status": ["Disconnect"]}
deliverRelayCommands(relayNum, commands, user=user + "/" + network)
main.saveConf("network")
if name in main.ReactorPool.keys():
if name in main.FactoryPool.keys():
main.FactoryPool[name].stopTrying()
main.ReactorPool[name].disconnect()
if name in main.IRCPool.keys():
del main.IRCPool[name]
del main.ReactorPool[name]
del main.FactoryPool[name]
success("Successfully disabled bot %s on network %s" % (spl[2], spl[1]))
return
else:
incUsage("disable")
return
else:
incUsage(None)

22
legacy/commands/dist.py Normal file
View File

@@ -0,0 +1,22 @@
from subprocess import PIPE, run
import main
class DistCommand:
def __init__(self, *args):
self.dist(*args)
def dist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if main.config["Dist"]["Enabled"]:
rtrn = run([main.config["Dist"]["File"]], shell=True, stdout=PIPE)
if main.config["Dist"]["SendOutput"]:
info("Exit code: %s -- Stdout: %s" % (rtrn.returncode, rtrn.stdout))
else:
info("Exit code: %s" % rtrn.returncode)
else:
failure("The dist command is not enabled")
return
else:
incUsage(None)

93
legacy/commands/email.py Normal file
View File

@@ -0,0 +1,93 @@
from yaml import dump
import main
class EmailCommand:
def __init__(self, *args):
self.email(*args)
def email(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 4:
if spl[1] == "add":
if spl[2].isdigit():
num = int(spl[2])
if num not in main.alias.keys():
failure("No such alias: %i" % num)
return
if not spl[3] in main.alias[num]["emails"]:
main.alias[num]["emails"].append(spl[3])
main.saveConf("alias")
success("Successfully added email %s to alias %i" % (spl[3], num))
return
else:
failure("Email already exists in alias %i: %s" % (num, spl[3]))
return
else:
failure("Must be a number, not %s" % spl[2])
if spl[2] == "domain":
domain = spl[3]
if "@" in domain:
failure("Not a domain: %s" % domain)
return
if domain not in main.irc["_"]["domains"]:
main.irc["_"]["domains"].append(domain)
success("Successfully added domain %s to default config" % domain)
main.saveConf("irc")
else:
failure("Domain already exists in default config: %s" % domain)
return
elif spl[1] == "del":
if not spl[2].isdigit():
# failure("Must be a number, not %s" % spl[2])
if spl[2] == "domain":
domain = spl[3]
if domain in main.irc["_"]["domains"]:
main.irc["_"]["domains"].remove(domain)
success("Successfully removed domain %s to default config" % domain)
main.saveConf("irc")
else:
failure("Domain does not exist in default config: %s" % domain)
return
elif spl[1] == "del":
if num not in main.alias.keys():
failure("No such alias: %i" % num)
return
if spl[3] in main.alias[num]["emails"]:
main.alias[num]["emails"].remove(spl[3])
main.saveConf("alias")
success("Successfully removed email %s from alias %i" % (spl[3], num))
return
else:
failure("Email does not exist in alias %i: %s" % (spl[3], num))
return
elif length == 2:
if spl[1] == "list":
info(dump(main.alias))
return
else:
incUsage("email")
return
elif length == 3:
if spl[1] == "list":
if spl[2] == "domain":
filtered = {
f"{k}:{k2}": v2 for k, v in main.irc.items() for k2, v2 in v.items() if k2 == "domains"
}
info(dump(filtered))
return
else:
incUsage("email")
return
else:
incUsage("email")
return
else:
incUsage("email")
return
else:
incUsage(None)

38
legacy/commands/enable.py Normal file
View File

@@ -0,0 +1,38 @@
import main
from utils.deliver_relay_commands import deliverRelayCommands
class EnableCommand:
def __init__(self, *args):
self.enable(*args)
def enable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 3:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
if not spl[2].isdigit():
failure("Must be a number, not %s" % spl[2])
return
if not int(spl[2]) in main.network[spl[1]].relays.keys():
failure("No such relay on %s: %s" % (spl[2], spl[1]))
return
main.network[spl[1]].relays[int(spl[2])]["enabled"] = True
user = main.alias[int(spl[2])]["nick"]
network = spl[1]
commands = {"status": ["Connect"]}
deliverRelayCommands(int(spl[2]), commands, user=user + "/" + network)
main.saveConf("network")
if not spl[1] + spl[2] in main.IRCPool.keys():
main.network[spl[1]].start_bot(int(spl[2]))
else:
pass
success("Successfully enabled bot %s on network %s" % (spl[2], spl[1]))
return
else:
incUsage("enable")
return
else:
incUsage(None)

19
legacy/commands/exec.py Normal file
View File

@@ -0,0 +1,19 @@
class ExecCommand:
def __init__(self, *args):
self.exec(*args)
def exec(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length > 1:
try:
rtrn = exec(" ".join(spl[1:]))
except Exception as err:
failure(str(err))
return
info(str(rtrn))
return
else:
incUsage("exec")
return
else:
incUsage(None)

33
legacy/commands/getstr.py Normal file
View File

@@ -0,0 +1,33 @@
import main
from utils.get import getRelay
class GetstrCommand:
def __init__(self, *args):
self.getstr(*args)
def getstr(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 3:
net = spl[1]
num = spl[2]
if net not in main.network.keys():
failure("Network does not exist: %s" % net)
return
if not num.isdigit():
failure("Must be a number, not %s" % num)
return
num = int(num)
alias = main.alias[num]["nick"].lower()
host, port = getRelay(num)
password = main.config["Relay"]["Password"]
connstr = f"/connect -ssl {host} {port}"
authstr = f"/quote PASS {alias}/{net}:{password}"
obj.send(connstr)
obj.send(authstr)
else:
incUsage("getstr")
return
else:
incUsage(None)

16
legacy/commands/help.py Normal file
View File

@@ -0,0 +1,16 @@
import main
class HelpCommand:
def __init__(self, *args):
self.help(*args)
def help(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
helpMap = []
for i in main.help.keys():
helpMap.append("%s: %s" % (i, main.help[i]))
info("\n".join(helpMap))
return
else:
incUsage(None)

48
legacy/commands/join.py Normal file
View File

@@ -0,0 +1,48 @@
import main
import modules.chankeep
class JoinCommand:
def __init__(self, *args):
self.join(*args)
def join(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 3:
if not spl[1] in main.network.keys():
failure("Network does not exist: %s" % spl[1])
return
modules.chankeep.joinSingle(spl[1], spl[2])
success("Joined %s" % spl[2])
elif length == 4:
if not spl[1] in main.network.keys():
failure("Network does not exist: %s" % spl[1])
return
if not int(spl[2]) in main.network[spl[1]].relays.keys():
failure("Relay %s does not exist on network %s" % (spl[2], spl[1]))
return
if not spl[1] + spl[2] in main.IRCPool.keys():
failure("Name has no instance: %s" % spl[1])
return
main.IRCPool[spl[1] + spl[2]].join(spl[3])
success("Joined %s" % spl[3])
return
elif length == 5:
if not spl[1] in main.network.keys():
failure("Network does not exist: %s" % spl[1])
return
if not int(spl[2]) in main.network[spl[1]].relays.keys():
failure("Relay % does not exist on network %", (spl[2], spl[1]))
return
if not spl[1] + spl[2] in main.IRCPool.keys():
failure("Name has no instance: %s" % spl[1])
return
main.IRCPool[spl[1] + spl[2]].join(spl[3], spl[4])
success("Joined %s with key %s" % (spl[3], spl[4]))
return
else:
incUsage("join")
return
else:
incUsage(None)

36
legacy/commands/list.py Normal file
View File

@@ -0,0 +1,36 @@
import main
from modules import helpers
class ListCommand:
def __init__(self, *args):
self.list(*args)
def list(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
for i in main.network.keys():
first_relay = helpers.get_first_relay(i)
####
if not first_relay:
info("Network has no first instance: %s" % i)
continue
first_relay.list()
success(f"Requested list with instance {first_relay.num} of {i}")
return
elif length == 2:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
first_relay = helpers.get_first_relay(spl[1])
if not first_relay:
failure("Could not get first instance")
return
first_relay.list()
success(f"Requested list with instance {first_relay.num} of {spl[1]}")
return
else:
incUsage("list")
return
else:
incUsage(None)

30
legacy/commands/load.py Normal file
View File

@@ -0,0 +1,30 @@
import main
class LoadCommand:
def __init__(self, *args):
self.load(*args)
def load(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
if spl[1] in main.filemap.keys():
main.loadConf(spl[1])
success("Loaded %s from %s" % (spl[1], main.filemap[spl[1]][0]))
return
elif spl[1] == "all":
for i in main.filemap.keys():
main.loadConf(i)
success("Loaded %s from %s" % (i, main.filemap[i][0]))
return
elif spl[1] == "list":
info(", ".join(main.filemap.keys()))
return
else:
incUsage("load")
return
else:
incUsage("load")
return
else:
incUsage(None)

View File

@@ -0,0 +1,26 @@
from utils.loaders.single_loader import loadSingle
class LoadmodCommand:
def __init__(self, *args):
self.loadmod(*args)
def loadmod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
rtrn = loadSingle(spl[1])
if rtrn is True:
success("Loaded module: %s" % spl[1])
return
elif rtrn == "RELOAD":
success("Reloaded module: %s" % spl[1])
return
else:
failure("Error loading module %s: %s" % (spl[1], rtrn))
return
else:
incUsage("loadmod")
return
else:
incUsage(None)
return

11
legacy/commands/logout.py Normal file
View File

@@ -0,0 +1,11 @@
class LogoutCommand:
def __init__(self, *args):
self.logout(*args)
def logout(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
obj.authed = False
success("Logged out")
return
else:
incUsage(None)

48
legacy/commands/mod.py Normal file
View File

@@ -0,0 +1,48 @@
import main
class ModCommand:
# This could be greatly improved, but not really important right now
def __init__(self, *args):
self.mod(*args)
def mod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 4:
if not spl[1] in main.network.keys():
failure("Network does not exist: %s" % spl[1])
return
try:
setattr(main.network[spl[1]], spl[2], spl[3])
except Exception as e:
failure(f"Something went wrong: {e}")
return
main.saveConf("network")
success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]))
return
# Find a better way to do this
# elif length == 6:
# if not spl[1] in main.network.keys():
# failure("Network does not exist: %s" % spl[1])
# return
# if not spl[3].isdigit():
# failure("Must be a number, not %s" % spl[3])
# return
# if not int(spl[3]) in main.network[spl[1]].relays.keys():
# failure("Relay/alias does not exist: %s" % spl[3])
# return
# try:
# x = getattr(main.network[spl[1]], spl[2])
# x[spl[3]] = spl[4]
# except Exception as err:
# failure("Error: %s" % err)
# return
else:
incUsage("mod")
return
else:
incUsage(None)

29
legacy/commands/msg.py Normal file
View File

@@ -0,0 +1,29 @@
import main
class MsgCommand:
def __init__(self, *args):
self.msg(*args)
def msg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length >= 5:
if not spl[1] in main.network.keys():
failure("Network does not exist: %s" % spl[1])
return
if not int(spl[2]) in main.network[spl[1]].relays.keys():
failure("Relay %s does not exist on network %s" % (spl[2], spl[1]))
return
if not spl[1] + spl[2] in main.IRCPool.keys():
failure("Name has no instance: %s" % spl[1])
return
if not spl[3] in main.IRCPool[spl[1] + spl[2]].channels:
info("Bot not on channel: %s" % spl[3])
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]))
return
else:
incUsage("msg")
return
else:
incUsage(None)

View File

@@ -0,0 +1,66 @@
from string import digits
from yaml import dump
import main
from modules.network import Network
class NetworkCommand:
def __init__(self, *args):
self.network(*args)
def network(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 7:
if spl[1] == "add":
if spl[2] in main.network.keys():
failure("Network already exists: %s" % spl[2])
return
if not spl[4].isdigit():
failure("Port must be an integer, not %s" % spl[4])
return
if not spl[5].lower() in ["ssl", "plain"]:
failure("Security must be ssl or plain, not %s" % spl[5])
return
if set(spl[2]).intersection(set(digits)):
failure("Network name cannot contain numbers")
return
if not spl[6].lower() in ["sasl", "ns", "none"]:
failure("Auth must be sasl, ns or none, not %s" % spl[5])
return
else:
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])
main.saveConf("network")
return
else:
incUsage("network")
return
elif length == 3:
if spl[1] == "del":
if spl[2] in main.network.keys():
main.network[spl[2]].seppuku() # ;(
del main.network[spl[2]]
success("Successfully removed network: %s" % spl[2])
main.saveConf("network")
return
else:
failure("No such network: %s" % spl[2])
return
else:
incUsage("network")
return
elif length == 2:
if spl[1] == "list":
info(dump(main.network))
return
else:
incUsage("network")
return
else:
incUsage("network")
return
else:
incUsage(None)

27
legacy/commands/part.py Normal file
View File

@@ -0,0 +1,27 @@
import main
class PartCommand:
def __init__(self, *args):
self.part(*args)
def part(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 4:
if not spl[1] in main.network.keys():
failure("Network does not exist: %s" % spl[1])
return
if not int(spl[2]) in main.network[spl[1]].relays.keys():
failure("Relay % does not exist on network %", (spl[2], spl[1]))
return
if not spl[1] + spl[2] in main.IRCPool.keys():
failure("Name has no instance: %s" % spl[1] + spl[2])
return
main.IRCPool[spl[1] + spl[2]].part(spl[3])
success("Left %s" % spl[3])
return
else:
incUsage("part")
return
else:
incUsage(None)

23
legacy/commands/pass.py Normal file
View File

@@ -0,0 +1,23 @@
import main
class PassCommand:
def __init__(self, *args):
self.password(*args)
def password(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
info("You are already authenticated")
return
else:
if length == 2:
if spl[1] == main.config["Password"]:
success("Authenticated successfully")
obj.authed = True
return
else:
failure("Password incorrect")
obj.transport.loseConnection()
return
else:
incUsage("pass")

View File

@@ -0,0 +1,32 @@
import main
class PendingCommand:
def __init__(self, *args):
self.pending(*args)
def pending(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
results = []
for i in main.network.keys():
for x in main.network[i].relays.keys():
if not main.network[i].relays[x]["registered"]:
results.append("%s: confirm %s %s [code]" % (main.alias[x]["nick"], i, x))
info("\n".join(results))
return
elif length == 2:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
results = []
for x in main.network[spl[1]].relays.keys():
if not main.network[spl[1]].relays[x]["registered"]:
results.append("%s: confirm %s %s [code]" % (main.alias[x]["nick"], spl[1], x))
info("\n".join(results))
return
else:
incUsage("pending")
return
else:
incUsage(None)

View File

@@ -0,0 +1,34 @@
import main
class RecheckauthCommand:
def __init__(self, *args):
self.recheckauth(*args)
def recheckauth(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
for i in main.IRCPool.keys():
net = main.IRCPool[i].net
main.IRCPool[i].authenticated = False
main.IRCPool[i].regPing()
success("Successfully reset authentication status")
return
elif length == 2:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
for i in main.IRCPool.keys():
# num = main.IRCPool[i].num
net = main.IRCPool[i].net
if not net == spl[1]:
continue
main.IRCPool[i].authenticated = False
main.IRCPool[i].regPing()
success("Successfully reset authentication status on %s" % spl[1])
return
else:
incUsage("recheckauth")
return
else:
incUsage(None)

36
legacy/commands/reg.py Normal file
View File

@@ -0,0 +1,36 @@
import main
from modules import regproc
class RegCommand:
def __init__(self, *args):
self.reg(*args)
def reg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
for i in main.network[spl[1]].relays.keys():
regproc.registerAccount(spl[1], i)
success("Requested registration for all relays on %s" % spl[1])
return
elif length == 3:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
if not spl[2].isdigit():
failure("Must be a number, not %s" % spl[2])
return
if not int(spl[2]) in main.network[spl[1]].relays.keys():
failure("No such relay on %s: %s" % (spl[2], spl[1]))
return
regproc.registerAccount(spl[1], int(spl[2]))
success("Requested registration on %s - %s" % (spl[1], spl[2]))
return
else:
incUsage("reg")
return
else:
incUsage(None)

66
legacy/commands/relay.py Normal file
View File

@@ -0,0 +1,66 @@
from yaml import dump
import main
class RelayCommand:
def __init__(self, *args):
self.relay(*args)
def relay(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 3:
if spl[1] == "add":
if spl[2] in main.network.keys():
id, alias = main.network[spl[2]].add_relay()
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
main.saveConf("network")
return
else:
failure("No such network: %s" % spl[2])
return
elif spl[1] == "list":
if spl[2] not in main.network.keys():
failure("No such network: %s" % spl[2])
return
info(dump(main.network[spl[2]].relays))
return
else:
incUsage("relay")
return
elif length == 4:
if spl[1] == "add":
if spl[2] in main.network.keys():
if not spl[3].isdigit():
failure("Must be a number, not %s" % spl[3])
return
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))
main.saveConf("network")
return
else:
failure("No such network: %s" % spl[2])
return
elif spl[1] == "del":
if not spl[2] in main.network.keys():
failure("No such network: %s" % spl[2])
return
if not spl[3].isdigit():
failure("Must be a number, not %s" % spl[3])
return
if not int(spl[3]) in main.network[spl[2]].relays.keys():
failure("No such relay: %s on network %s" % (spl[3], spl[2]))
return
main.network[spl[2]].delete_relay(int(spl[3]))
success("Successfully deleted relay %s on network %s" % (spl[3], spl[2]))
main.saveConf("network")
return
else:
incUsage("relay")
return
else:
incUsage("relay")
return
else:
incUsage(None)

29
legacy/commands/save.py Normal file
View File

@@ -0,0 +1,29 @@
import main
class SaveCommand:
def __init__(self, *args):
self.save(*args)
def save(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
if spl[1] in main.filemap.keys():
main.saveConf(spl[1])
success("Saved %s to %s" % (spl[1], main.filemap[spl[1]][0]))
return
elif spl[1] == "all":
for i in main.filemap.keys():
main.saveConf(i)
success("Saved %s to %s" % (i, main.filemap[i][0]))
return
elif spl[1] == "list":
info(", ".join(main.filemap.keys()))
else:
incUsage("save")
return
else:
incUsage("save")
return
else:
incUsage(None)

69
legacy/commands/stats.py Normal file
View File

@@ -0,0 +1,69 @@
from string import digits
import main
import modules.counters as count
import modules.userinfo as userinfo
class StatsCommand:
def __init__(self, *args):
self.stats(*args)
def stats(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 1:
stats = []
numChannels = 0
numWhoEntries = 0
for i in main.IRCPool.keys():
numChannels += len(main.IRCPool[i].channels)
numWhoEntries += userinfo.getNumTotalWhoEntries()
stats.append("Registered servers:")
stats.append(" Unique: %s" % len(main.network.keys()))
stats.append("Online servers:")
stats.append(" Total: %s" % len(main.IRCPool.keys()))
stats.append(" Unique: %s" % len(main.liveNets()))
stats.append("Channels: %s" % numChannels)
stats.append("User records: %s" % numWhoEntries)
stats.append("Events/min: %s" % main.lastMinuteSample)
counterEvents = count.getEvents()
if counterEvents is None:
stats.append("No counters records")
else:
stats.append("Counters:")
for i in counterEvents.keys():
stats.append(" %s: %s" % (i, counterEvents[i]))
info("\n".join(stats))
return
elif length == 2:
stats = []
numChannels = 0
numWhoEntries = 0
found = False
numNodes = 0
for i in main.IRCPool.keys():
if "".join([x for x in i if x not in digits]) == spl[1]:
numChannels += len(main.IRCPool[i].channels)
found = True
numNodes += 1
if not found:
failure("Name does not exist: %s" % spl[1])
numWhoEntries += userinfo.getNumWhoEntries(spl[1])
stats.append("Channels: %s" % numChannels)
stats.append("User records: %s" % numWhoEntries)
stats.append("Endpoints: %s" % numNodes)
counterEvents = count.getEvents(spl[1])
if counterEvents is None:
stats.append("No counters records")
else:
stats.append("Counters:")
for i in counterEvents.keys():
stats.append(" %s: %s" % (i, counterEvents[i]))
info("\n".join(stats))
return
else:
incUsage("stats")
else:
incUsage(None)

44
legacy/commands/swho.py Normal file
View File

@@ -0,0 +1,44 @@
import main
class SwhoCommand:
def __init__(self, *args):
self.swho(*args)
def swho(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
if not spl[1] in main.network.keys():
failure("Network does not exist: %s" % spl[1])
return
for i in main.IRCPool.keys():
if spl[1] == main.IRCPool[i].net:
for x in main.IRCPool[i].channels:
main.IRCPool[i].who(x)
success("Sent WHO to all channels on all networks for %s" % spl[1])
return
elif length == 3:
if not spl[1] in main.network.keys():
failure("Network does not exist: %s" % spl[1])
return
matches = []
# This loop gets all networks where the core network matches spl[1]
# where there is also a currently joined channel matching spl[2]
for i in main.IRCPool.keys():
if spl[1] == main.IRCPool[i].net:
for x in main.IRCPool[i].channels:
if x == spl[2]:
main.IRCPool[i].who(x)
matches.append(i)
if matches == []:
failure("No matches found for channel %s" % spl[2])
return
success("Sent WHO to %s on: %s" % (spl[2], ", ".join(matches)))
return
else:
incUsage("swho")
return
else:
incUsage(None)

60
legacy/commands/token.py Normal file
View File

@@ -0,0 +1,60 @@
from uuid import uuid4
from yaml import dump
import main
class TokenCommand:
def __init__(self, *args):
self.token(*args)
def token(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
if spl[1] == "list":
info(dump(main.tokens))
return
else:
incUsage("token")
return
elif length == 3:
if spl[1] == "del":
if spl[2] in main.tokens.keys():
del main.tokens[spl[2]]
main.saveConf("tokens")
success("Successfully removed token: %s" % spl[2])
return
else:
failure("No such token")
return
else:
incUsage("token")
return
elif length == 4:
if spl[1] == "add":
if not spl[2] in main.tokens.keys():
if spl[3] in ["relay", "api"]: # more to come!
main.tokens[spl[2]] = {
"hello": str(uuid4()),
"usage": spl[3],
"counter": str(uuid4()),
}
main.saveConf("tokens")
success("Successfully created token %s:" % spl[2])
info(dump(main.tokens[spl[2]]))
return
else:
incUsage("token")
return
else:
failure("Token already exists: %s" % spl[2])
return
else:
incUsage("token")
return
else:
incUsage("token")
return
else:
incUsage(None)

25
legacy/commands/users.py Normal file
View File

@@ -0,0 +1,25 @@
import modules.userinfo as userinfo
class UsersCommand:
def __init__(self, *args):
self.users(*args)
def users(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if len(spl) < 2:
incUsage("users")
return
result = userinfo.getUsers(spl[1:])
rtrn = ""
for i in result.keys():
rtrn += "Matches from: %s" % i
rtrn += "\n"
for x in result[i]:
rtrn += x
rtrn += "\n"
rtrn += "\n"
info(rtrn)
return
else:
incUsage(None)

26
legacy/commands/who.py Normal file
View File

@@ -0,0 +1,26 @@
import modules.userinfo as userinfo
class WhoCommand:
def __init__(self, *args):
self.who(*args)
def who(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 2:
result = userinfo.getWho(spl[1])
rtrn = ""
for i in result.keys():
rtrn += "Matches from: %s" % i
rtrn += "\n"
for x in result[i]:
rtrn += x
rtrn += "\n"
rtrn += "\n"
info(rtrn)
return
else:
incUsage("who")
return
else:
incUsage(None)