diff --git a/conf/example.json b/conf/example.json new file mode 100644 index 0000000..c4e6afe --- /dev/null +++ b/conf/example.json @@ -0,0 +1,40 @@ +{ + "Listener": { + "Port": 13867, + "Address": "127.0.0.1", + "UseSSL": true, + "Key": "key.pem", + "Certificate": "cert.pem" + }, + "UsePassword": true, + "ConnectOnCreate": false, + "HighlightNotifications": true, + "Dist": { + "Enabled": true, + "SendOutput": false, + "File": "conf/dist.sh" + }, + "Password": "s", + "Default": { + "host": null, + "port": null, + "protocol": null, + "bind": null, + "timeout": 30, + "nickname": null, + "username": null, + "realname": null, + "userinfo": null, + "finger": null, + "version": null, + "source": null, + "autojoin": [], + "authtype": null, + "password": null, + "authentity": "NickServ", + "key": "key.pem", + "certificate": "cert.pem", + "enabled": true + }, + "Master": [null, null] +} diff --git a/conf/help.json b/conf/help.json new file mode 100644 index 0000000..b17ae32 --- /dev/null +++ b/conf/help.json @@ -0,0 +1,19 @@ +{ + "pass": "pass ", + "logout": "logout", + "add": "add [
] [] [] []", + "del": "del ", + "mod": "mod [] []", + "default": "default [] []", + "get": "get ", + "key": "key [] [] [] []", + "who": "who ", + "join": "join []", + "enable": "enable ", + "disable": "disable ", + "list": "list", + "stats": "stats", + "save": "save ", + "load": "load ", + "dist": "dist" +} diff --git a/conf/keyword.json b/conf/keyword.json new file mode 100644 index 0000000..cc4da5b --- /dev/null +++ b/conf/keyword.json @@ -0,0 +1,6 @@ +{ + "Keywords": [ + "kek" + ], + "KeywordsExcept": {} +} \ No newline at end of file diff --git a/threshold b/threshold index 9f7650c..c38d8fb 100755 --- a/threshold +++ b/threshold @@ -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()