Separate out into different directories and reshuffle configuration directives

This commit is contained in:
2018-01-17 19:02:41 +00:00
parent 12b6fe2acb
commit a7599dddfe
4 changed files with 82 additions and 26 deletions

View File

@@ -22,6 +22,9 @@ IRCPool = {}
MonitorPool = []
configPath = "conf/"
certPath = "cert/"
filemap = {
"config": ["config.json", "configuration"],
"keyconf": ["keyword.json", "keyword lists"],
@@ -314,20 +317,6 @@ class BaseFactory(Factory):
return
class Helper(object):
def getConfig(self):
with open("config.json", "r") as f:
config = load(f)
if set(["Port", "BindAddress", "UseSSL", "UsePassword"]).issubset(set(config.keys())):
if config["UseSSL"] == True:
if not set(["ListenerKey", "ListenerCertificate"]).issubset(set(config.keys())):
error("SSL is on but certificate or key is not defined")
if config["UsePassword"] == True:
if not "Password" in config.keys():
error("Password authentication is on but password is not defined")
return config
else:
error("Mandatory values missing from config")
def setWho(self, network, newObjects):
global wholist
network = "".join([x for x in network if not x in numbers])
@@ -360,12 +349,12 @@ class Helper(object):
return result
def save(self, var):
with open(filemap[var][0], "w") as f:
with open(configPath+filemap[var][0], "w") as f:
dump(globals()[var], f, indent=4)
return
def load(self, var):
with open(filemap[var][0], "r") as f:
with open(configPath+filemap[var][0], "r") as f:
globals()[var] = load(f)
def incorrectUsage(self, addr, mode):
@@ -437,7 +426,7 @@ class Helper(object):
helper.sendMaster("MATCH %s %s (U:%s T:%s): (%s/%s) %s" % (actType, name, toSend[1], toSend[2], user, channel, toSend[0]))
def addBot(self, name):
global IRCPool
global IRCPool, certPath
instance = pool[name]
log("Started bot %s to %s:%s protocol %s nickname %s" % (name, instance["host"], instance["port"], instance["protocol"], instance["nickname"]))
if instance["protocol"] == "plain":
@@ -454,7 +443,9 @@ class Helper(object):
d = connectProtocol(point, bot)
return
elif instance["protocol"] == "ssl":
contextFactory = DefaultOpenSSLContextFactory(instance["key"].encode("utf-8", "replace"), instance["certificate"].encode("utf-8", "replace"))
keyFN = certPath+instance["key"]
certFN = certPath+instance["certificate"]
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
if instance["bind"] == None:
point = SSL4ClientEndpoint(reactor, instance["host"], int(instance["port"]), contextFactory, timeout=int(instance["timeout"]))
bot = IRCBot(name)
@@ -542,9 +533,9 @@ class Helper(object):
return
elif cmd == "dist":
if config["DistEnabled"]:
rtrn = run(["./dist.sh"], shell=True, stdout=PIPE)
if config["SendDistOutput"]:
if config["Dist"]["Enabled"]:
rtrn = run([config["Dist"]["File"]], shell=True, stdout=PIPE)
if config["Dist"]["SendOutput"]:
info("Exit code: %s -- Stdout: %s" % (rtrn.returncode, rtrn.stdout))
else:
info("Exit code: %s" % rtrn.returncode)
@@ -1135,11 +1126,11 @@ if __name__ == "__main__":
helper.addBot(i)
listener = BaseFactory()
if config["UseSSL"] == True:
reactor.listenSSL(config["Port"], listener, DefaultOpenSSLContextFactory(config["ListenerKey"], config["ListenerCertificate"]), interface=config["BindAddress"])
log("Threshold running with SSL on %s:%s" % (config["BindAddress"], config["Port"]))
if config["Listener"]["UseSSL"] == True:
reactor.listenSSL(config["Listener"]["Port"], listener, DefaultOpenSSLContextFactory(certPath+config["Listener"]["Key"], certPath+config["Listener"]["Certificate"]), interface=config["Listener"]["Address"])
log("Threshold running with SSL on %s:%s" % (config["Listener"]["Address"], config["Listener"]["Port"]))
else:
reactor.listenTCP(config["Port"], listener, interface=config["BindAddress"])
log("Threshold running on %s:%s" % (config["BindAddress"], config["Port"]))
reactor.listenTCP(config["Listener"]["Port"], listener, interface=config["Listener"]["Address"])
log("Threshold running on %s:%s" % (config["Listener"]["Address"], config["Listener"]["Port"]))
reactor.run()