monolith/threshold

88 lines
2.9 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python
import sys
2022-07-21 12:40:09 +00:00
from codecs import getwriter
from signal import SIGINT, signal
from sys import stderr, stdout
2022-07-21 12:39:41 +00:00
2022-07-21 12:40:09 +00:00
from twisted.internet import reactor
from twisted.internet.ssl import DefaultOpenSSLContextFactory
2022-07-21 12:40:05 +00:00
2022-07-21 12:40:09 +00:00
import core.logstash
import main
2022-07-21 12:40:09 +00:00
import modules.counters
from core.relay import RelayFactory
from core.server import ServerFactory
from utils.cleanup import handler
2022-07-21 12:40:05 +00:00
from utils.loaders.command_loader import loadCommands
2022-07-21 12:40:09 +00:00
from utils.logging.log import log
2022-07-21 12:40:05 +00:00
main.initMain()
2022-07-21 12:39:41 +00:00
if "--debug" in sys.argv: # yes really
main.config["Debug"] = True
if "--trace" in sys.argv:
main.config["Trace"] = True
2022-07-21 12:39:41 +00:00
loadCommands()
2022-07-21 12:40:05 +00:00
2022-07-21 12:39:41 +00:00
2021-06-06 10:16:04 +00:00
core.logstash.init_logstash()
2022-07-21 12:40:05 +00:00
signal(SIGINT, handler) # Handle Ctrl-C and run the cleanup routine
stdout = getwriter("utf8")(stdout) # this is a generic fix but we all know
stderr = getwriter("utf8")(stderr) # it's just for the retards on Rizon using
# unicode quit messages for no reason
if __name__ == "__main__":
listener = ServerFactory()
2022-07-21 12:40:05 +00:00
if main.config["Listener"]["UseSSL"] is True:
2022-07-21 12:39:41 +00:00
reactor.listenSSL(
main.config["Listener"]["Port"],
listener,
DefaultOpenSSLContextFactory(
main.certPath + main.config["Key"],
main.certPath + main.config["Certificate"],
),
interface=main.config["Listener"]["Address"],
)
2022-07-21 12:40:03 +00:00
log(
"Threshold running with SSL on %s:%s"
% (main.config["Listener"]["Address"], main.config["Listener"]["Port"])
)
else:
2022-07-21 12:39:41 +00:00
reactor.listenTCP(
main.config["Listener"]["Port"],
listener,
interface=main.config["Listener"]["Address"],
)
log("Threshold running on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]))
if main.config["RelayAPI"]["Enabled"]:
relay = RelayFactory()
2022-07-21 12:40:05 +00:00
if main.config["RelayAPI"]["UseSSL"] is True:
2022-07-21 12:39:41 +00:00
reactor.listenSSL(
main.config["RelayAPI"]["Port"],
relay,
DefaultOpenSSLContextFactory(
main.certPath + main.config["Key"],
main.certPath + main.config["Certificate"],
),
interface=main.config["RelayAPI"]["Address"],
)
log(
"Threshold relay running with SSL on %s:%s"
% (main.config["RelayAPI"]["Address"], main.config["RelayAPI"]["Port"])
)
else:
2022-07-21 12:39:41 +00:00
reactor.listenTCP(
main.config["RelayAPI"]["Port"],
relay,
interface=main.config["RelayAPI"]["Address"],
)
2022-07-21 12:40:03 +00:00
log(
"Threshold relay running on %s:%s"
% (main.config["RelayAPI"]["Address"], main.config["RelayAPI"]["Port"])
)
for net in main.network.keys():
main.network[net].start_bots()
modules.counters.setupCounterLoop()
reactor.run()