73 lines
1.6 KiB
Python
73 lines
1.6 KiB
Python
from json import load, dump, loads
|
|
from redis import StrictRedis
|
|
from string import digits
|
|
from os import urandom
|
|
|
|
from utils.logging.log import *
|
|
|
|
configPath = "conf/"
|
|
certPath = "cert/"
|
|
|
|
filemap = {
|
|
"config": ["config.json", "configuration"],
|
|
"pool": ["pool.json", "network, alias and relay mappings"],
|
|
"help": ["help.json", "command help"],
|
|
"counters": ["counters.json", "counters file"],
|
|
"monitor": ["monitor.json", "monitoring database"],
|
|
"alias": ["alias.json", "alias details"],
|
|
"relay": ["relay.json", "relay list"],
|
|
"network": ["network.json", "network list"],
|
|
"tokens": ["tokens.json", "authentication tokens"],
|
|
}
|
|
|
|
connections = {}
|
|
relayConnections = {}
|
|
IRCPool = {}
|
|
ReactorPool = {}
|
|
FactoryPool = {}
|
|
|
|
MonitorPool = []
|
|
|
|
CommandMap = {}
|
|
|
|
runningSample = 0
|
|
lastMinuteSample = 0
|
|
|
|
# Generate 16-byte hex key for message checksums
|
|
hashKey = urandom(16)
|
|
lastEvents = {}
|
|
|
|
def nets():
|
|
if not "pool" in globals():
|
|
return
|
|
networks = set()
|
|
for i in pool.keys():
|
|
networks.add("".join([x for x in i if not x in digits]))
|
|
return networks
|
|
|
|
def liveNets():
|
|
networks = set()
|
|
for i in IRCPool.keys():
|
|
networks.add("".join([x for x in i if not x in digits]))
|
|
return networks
|
|
|
|
def saveConf(var):
|
|
with open(configPath+filemap[var][0], "w") as f:
|
|
dump(globals()[var], f, indent=4)
|
|
return
|
|
|
|
def loadConf(var):
|
|
with open(configPath+filemap[var][0], "r") as f:
|
|
globals()[var] = load(f)
|
|
|
|
def initConf():
|
|
for i in filemap.keys():
|
|
loadConf(i)
|
|
|
|
def initMain():
|
|
global r
|
|
initConf()
|
|
r = StrictRedis(unix_socket_path=config["RedisSocket"], db=0)
|
|
|
|
|