Rework data structures, storing all front-end network data in Network objects
parent
f6657cb905
commit
e5adcfef4c
@ -1,15 +1,13 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
*.pem
|
*.pem
|
||||||
|
*.swp
|
||||||
__pycache__/
|
__pycache__/
|
||||||
conf/config.json
|
conf/config.json
|
||||||
conf/pool.json
|
|
||||||
conf/wholist.json
|
conf/wholist.json
|
||||||
conf/counters.json
|
conf/counters.json
|
||||||
conf/masterbuf.json
|
conf/masterbuf.json
|
||||||
conf/monitor.json
|
conf/monitor.json
|
||||||
conf/alias.json
|
|
||||||
conf/relay.json
|
|
||||||
conf/network.json
|
|
||||||
conf/tokens.json
|
conf/tokens.json
|
||||||
|
conf/network.dat
|
||||||
conf/dist.sh
|
conf/dist.sh
|
||||||
env/
|
env/
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
import main
|
|
||||||
from yaml import dump
|
|
||||||
import modules.alias as 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 == 8:
|
|
||||||
if spl[1] == "add":
|
|
||||||
if spl[2] in main.alias.keys():
|
|
||||||
failure("Alias already exists: %s" % spl[2])
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
main.alias[spl[2]] = {"nick": spl[3],
|
|
||||||
"altnick": spl[4],
|
|
||||||
"ident": spl[5],
|
|
||||||
"realname": spl[6],
|
|
||||||
"password": spl[7]}
|
|
||||||
success("Successfully created alias: %s" % spl[2])
|
|
||||||
main.saveConf("alias")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
incUsage("alias")
|
|
||||||
return
|
|
||||||
|
|
||||||
elif length == 3:
|
|
||||||
if spl[1] == "del":
|
|
||||||
if spl[2] in main.alias.keys():
|
|
||||||
del main.alias[spl[2]]
|
|
||||||
success("Successfully removed alias: %s" % spl[2])
|
|
||||||
main.saveConf("alias")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
failure("No such alias: %s" % spl[2])
|
|
||||||
return
|
|
||||||
elif spl[1] == "add" and spl[2] == "auto":
|
|
||||||
newalias = alias.generate_alias()
|
|
||||||
while newalias["nick"] in main.alias.keys():
|
|
||||||
newalias = alias.generate_alias()
|
|
||||||
main.alias[newalias["nick"]] = newalias
|
|
||||||
success("Successfully created alias: %s" % newalias["nick"])
|
|
||||||
main.saveConf("alias")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
incUsage("alias")
|
|
||||||
return
|
|
||||||
elif length == 2:
|
|
||||||
if spl[1] == "list":
|
|
||||||
info(dump(main.alias))
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
incUsage("alias")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
incUsage("alias")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
incUsage(None)
|
|
@ -1,13 +0,0 @@
|
|||||||
import main
|
|
||||||
from yaml import dump
|
|
||||||
|
|
||||||
class ListCommand:
|
|
||||||
def __init__(self, *args):
|
|
||||||
self.list(*args)
|
|
||||||
|
|
||||||
def list(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
|
||||||
if authed:
|
|
||||||
info(dump(main.pool))
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
incUsage(None)
|
|
@ -1 +0,0 @@
|
|||||||
{}
|
|
@ -1 +0,0 @@
|
|||||||
{}
|
|
@ -1 +0,0 @@
|
|||||||
{}
|
|
@ -1 +0,0 @@
|
|||||||
{}
|
|
@ -1,29 +1,27 @@
|
|||||||
{
|
{
|
||||||
"pass": "pass <password>",
|
"pass": "pass <password>",
|
||||||
"logout": "logout",
|
"logout": "logout",
|
||||||
"del": "del <name>",
|
"del": "del <network> <relay>",
|
||||||
"mod": "mod <name> [<key>] [<value>]",
|
"mod": "mod <network> <variable> <value>",
|
||||||
"get": "get <name> <variable>",
|
"get": "get <name>",
|
||||||
"key": "key <master|list|add|del|except|unexcept|listexcept|monitor> [<name>] [<target>] [<key...>] [<on|off>]",
|
"key": "key <master|list|add|del|except|unexcept|listexcept|monitor> [<name>] [<target>] [<key...>] [<on|off>]",
|
||||||
"who": "who <query>",
|
"who": "who <query>",
|
||||||
"join": "join <name> <channel> [<key>]",
|
"join": "join <network> <relay> <channel> [<key>]",
|
||||||
"part": "part <name> <channel>",
|
"part": "part <network> <relay> <channel>",
|
||||||
"enable": "enable <name>",
|
"enable": "enable <network> <id>",
|
||||||
"disable": "disable <name>",
|
"disable": "disable <network> <id>",
|
||||||
"list": "list",
|
|
||||||
"stats": "stats [<name>]",
|
"stats": "stats [<name>]",
|
||||||
"save": "save <(file)|list|all>",
|
"save": "save <(file)|list|all>",
|
||||||
"load": "load <(file)|list|all>",
|
"load": "load <(file)|list|all>",
|
||||||
"dist": "dist",
|
"dist": "dist",
|
||||||
"loadmod": "loadmod <module>",
|
"loadmod": "loadmod <module>",
|
||||||
"msg": "msg <name> <target> <message...>",
|
"msg": "msg <network> <relay> <target> <message...>",
|
||||||
"mon": "mon -h",
|
"mon": "mon -h",
|
||||||
"chans": "chans <nick> [<nick> ...]",
|
"chans": "chans <nick> [<nick> ...]",
|
||||||
"users": "users <channel> [<channel> ...]",
|
"users": "users <channel> [<channel> ...]",
|
||||||
"alias": "alias <add|del|list> [<alias> <nickname> <altnick> <ident> <realname> <password> OR auto]",
|
"relay": "relay <add|del|list> [<network> <host> <port> <user> <password> | <network> <id> | <network>]",
|
||||||
"relay": "relay <add|del|list> [<relay> <host> <port> <user> <password>]",
|
|
||||||
"network": "network <add|del|list> [<name> <address> <port> <ssl|plain> <sasl|ns|none>]",
|
"network": "network <add|del|list> [<name> <address> <port> <ssl|plain> <sasl|ns|none>]",
|
||||||
"provision": "provision <relay> <alias> [<network>]",
|
"provision": "provision <relay> <alias> [<network>]",
|
||||||
"cmd": "cmd <relay> <user> <entity> <text ...>",
|
"cmd": "cmd <network> <relay> <user> <entity> <text ...>",
|
||||||
"token": "token <add|del|list> [<key>] [<relay>]"
|
"token": "token <add|del|list> [<key>] [<relay>]"
|
||||||
}
|
}
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
from twisted.internet import reactor
|
|
||||||
from core.bot import IRCBot, IRCBotFactory
|
|
||||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
|
||||||
import main
|
|
||||||
from utils.logging.log import *
|
|
||||||
|
|
||||||
def startBot(name):
|
|
||||||
inst = main.pool[name]
|
|
||||||
relay, alias, network = inst["relay"], inst["alias"], inst["network"]
|
|
||||||
host = main.relay[relay]["host"]
|
|
||||||
port = int(main.relay[relay]["port"])
|
|
||||||
|
|
||||||
log("Started bot %s to %s network %s" % (name, relay, network))
|
|
||||||
|
|
||||||
keyFN = main.certPath+main.config["Key"]
|
|
||||||
certFN = main.certPath+main.config["Certificate"]
|
|
||||||
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"),
|
|
||||||
certFN.encode("utf-8", "replace"))
|
|
||||||
bot = IRCBotFactory(name)
|
|
||||||
rct = reactor.connectSSL(host,
|
|
||||||
port,
|
|
||||||
bot, contextFactory)
|
|
||||||
|
|
||||||
main.ReactorPool[name] = rct
|
|
||||||
main.FactoryPool[name] = bot
|
|
||||||
return
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
|||||||
|
import json
|
||||||
|
import modules.alias as alias
|
||||||
|
from twisted.internet import reactor
|
||||||
|
from core.bot import IRCBot, IRCBotFactory
|
||||||
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||||
|
import main
|
||||||
|
from utils.logging.log import *
|
||||||
|
|
||||||
|
class Network:
|
||||||
|
def __init__(self, name, host, port, security, auth):
|
||||||
|
self.name = name
|
||||||
|
self.host = host
|
||||||
|
self.port = port
|
||||||
|
self.security = security
|
||||||
|
self.auth = auth
|
||||||
|
|
||||||
|
self.last = 0
|
||||||
|
self.relays = {}
|
||||||
|
self.aliases = {}
|
||||||
|
|
||||||
|
def add_relay(self, host, port, user, password):
|
||||||
|
self.last += 1
|
||||||
|
self.relays[self.last] = {
|
||||||
|
"host": host,
|
||||||
|
"port": port,
|
||||||
|
"user": user,
|
||||||
|
"password": password,
|
||||||
|
"enabled": False,
|
||||||
|
"net": self.name,
|
||||||
|
"id": self.last
|
||||||
|
}
|
||||||
|
self.aliases[self.last] = alias.generate_alias()
|
||||||
|
return self.last, self.aliases[self.last]["nick"]
|
||||||
|
|
||||||
|
def delete_relay(self, id):
|
||||||
|
del self.relays[id]
|
||||||
|
del self.aliases[id]
|
||||||
|
|
||||||
|
def start_bot(self, relay):
|
||||||
|
# a single name is given to relays in the backend
|
||||||
|
# e.g. freenode1 for the first relay on freenode network
|
||||||
|
name = self.name + relay
|
||||||
|
keyFN = main.certPath+main.config["Key"]
|
||||||
|
certFN = main.certPath+main.config["Certificate"]
|
||||||
|
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
|
||||||
|
bot = IRCBotFactory(name)
|
||||||
|
rct = reactor.connectSSL(k, port, bot, contextFactory)
|
||||||
|
|
||||||
|
main.ReactorPool[name] = rct
|
||||||
|
main.FactoryPool[name] = bot
|
||||||
|
|
||||||
|
log("Started bot on relay %s on %s", (relay, self.host))
|
||||||
|
|
||||||
|
def start_bots(self):
|
||||||
|
for relay in self.relays:
|
||||||
|
if relay["enabled"]:
|
||||||
|
start_bot(relay)
|
Loading…
Reference in New Issue