2017-11-19 14:46:42 +00:00
|
|
|
#!/usr/bin/env python
|
2022-07-21 12:40:01 +00:00
|
|
|
from twisted.internet import reactor
|
|
|
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
2019-09-28 18:46:10 +00:00
|
|
|
import sys
|
2022-07-21 12:40:01 +00:00
|
|
|
from signal import signal, SIGINT
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
# from twisted.python import log
|
|
|
|
# from sys import stdout
|
|
|
|
# log.startLogging(stdout)
|
2022-07-21 12:40:01 +00:00
|
|
|
from sys import stdout, stderr # Import again because we want to override
|
|
|
|
from codecs import getwriter # fix printing odd shit to the terminal
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2022-07-21 12:40:05 +00:00
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
import main
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-09-28 18:46:10 +00:00
|
|
|
from utils.cleanup import handler
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2022-07-21 12:40:05 +00:00
|
|
|
|
|
|
|
from utils.logging.log import log
|
|
|
|
from utils.loaders.command_loader import loadCommands
|
|
|
|
from core.server import ServerFactory
|
|
|
|
from core.relay import RelayFactory
|
|
|
|
import modules.counters
|
|
|
|
import core.logstash
|
|
|
|
|
|
|
|
main.initMain()
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
if "--debug" in sys.argv: # yes really
|
2019-08-15 20:20:49 +00:00
|
|
|
main.config["Debug"] = True
|
2020-10-31 00:10:33 +00:00
|
|
|
if "--trace" in sys.argv:
|
|
|
|
main.config["Trace"] = True
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-01-26 18:58:21 +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
|
2019-01-26 18:58:21 +00:00
|
|
|
|
2017-11-19 14:46:42 +00:00
|
|
|
if __name__ == "__main__":
|
2018-03-04 13:26:53 +00:00
|
|
|
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"])
|
|
|
|
)
|
2017-11-19 14:46:42 +00:00
|
|
|
else:
|
2022-07-21 12:39:41 +00:00
|
|
|
reactor.listenTCP(
|
|
|
|
main.config["Listener"]["Port"],
|
|
|
|
listener,
|
|
|
|
interface=main.config["Listener"]["Address"],
|
|
|
|
)
|
2022-07-21 12:40:01 +00:00
|
|
|
log("Threshold running on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]))
|
2019-08-25 20:29:11 +00:00
|
|
|
if main.config["RelayAPI"]["Enabled"]:
|
2019-03-18 21:01:28 +00:00
|
|
|
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"])
|
|
|
|
)
|
2019-03-18 21:01:28 +00:00
|
|
|
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"])
|
|
|
|
)
|
2019-08-11 20:58:14 +00:00
|
|
|
for net in main.network.keys():
|
|
|
|
main.network[net].start_bots()
|
2019-07-28 14:07:46 +00:00
|
|
|
modules.counters.setupCounterLoop()
|
2017-11-19 14:46:42 +00:00
|
|
|
reactor.run()
|