2017-11-19 14:46:42 +00:00
|
|
|
#!/usr/bin/env python
|
2019-09-28 18:46:10 +00:00
|
|
|
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
|
2022-07-21 12:40:11 +00:00
|
|
|
|
|
|
|
# Webapp stuff
|
|
|
|
from twisted.internet.protocol import Factory
|
2022-07-21 12:40:09 +00:00
|
|
|
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
|
2018-03-14 20:13:40 +00:00
|
|
|
import main
|
2022-07-21 12:40:09 +00:00
|
|
|
import modules.counters
|
2022-07-21 12:40:11 +00:00
|
|
|
from api.views import API
|
2022-07-21 12:40:09 +00:00
|
|
|
from core.relay import RelayFactory
|
|
|
|
from core.server import ServerFactory
|
2019-09-28 18:46:10 +00:00
|
|
|
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-28 18:38:37 +00:00
|
|
|
from os import getenv
|
2022-07-21 12:40:05 +00:00
|
|
|
|
2022-07-21 12:40:11 +00:00
|
|
|
Factory.noisy = False
|
|
|
|
|
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
|
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
|
|
|
|
2022-07-28 18:38:37 +00:00
|
|
|
# Main listener
|
|
|
|
listener_address = getenv("THRESHOLD_LISTENER_HOST") or main.config["Listener"]["Address"]
|
|
|
|
listener_port = int(getenv("THRESHOLD_LISTENER_PORT")) or main.config["Listener"]["Port"]
|
|
|
|
listener_ssl = int(getenv("THRESHOLD_LISTENER_SSL")) or main.config["Listener"]["UseSSL"]
|
|
|
|
|
|
|
|
# RelayAPI
|
|
|
|
relay_enabled = int(getenv("THRESHOLD_RELAY_ENABLED")) or main.config["Relay"]["Enabled"]
|
|
|
|
relay_address = getenv("THRESHOLD_RELAY_HOST") or main.config["RelayAPI"]["Address"]
|
|
|
|
relay_port = int(getenv("THRESHOLD_RELAY_PORT")) or main.config["RelayAPI"]["Port"]
|
|
|
|
relay_ssl = int(getenv("THRESHOLD_RELAY_SSL")) or main.config["RelayAPI"]["UseSSL"]
|
|
|
|
|
|
|
|
# Web API
|
|
|
|
api_enabled = int(getenv("THRESHOLD_API_ENABLED")) or main.config["API"]["Enabled"]
|
|
|
|
api_address = getenv("THRESHOLD_API_HOST") or main.config["API"]["Address"]
|
|
|
|
api_port = int(getenv("THRESHOLD_API_PORT")) or main.config["API"]["Port"]
|
|
|
|
|
2017-11-19 14:46:42 +00:00
|
|
|
if __name__ == "__main__":
|
2018-03-04 13:26:53 +00:00
|
|
|
listener = ServerFactory()
|
2022-07-28 18:38:37 +00:00
|
|
|
if listener_ssl 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"],
|
|
|
|
),
|
2022-07-28 18:38:37 +00:00
|
|
|
interface=listener_address,
|
2022-07-21 12:39:41 +00:00
|
|
|
)
|
2022-07-21 12:40:03 +00:00
|
|
|
log(
|
|
|
|
"Threshold running with SSL on %s:%s"
|
2022-07-28 18:38:37 +00:00
|
|
|
% (listener_address, listener_port)
|
2022-07-21 12:40:03 +00:00
|
|
|
)
|
2017-11-19 14:46:42 +00:00
|
|
|
else:
|
2022-07-21 12:39:41 +00:00
|
|
|
reactor.listenTCP(
|
2022-07-28 18:38:37 +00:00
|
|
|
listener_port,
|
2022-07-21 12:39:41 +00:00
|
|
|
listener,
|
2022-07-28 18:38:37 +00:00
|
|
|
interface=listener_address,
|
2022-07-21 12:39:41 +00:00
|
|
|
)
|
2022-07-28 18:38:37 +00:00
|
|
|
log("Threshold running on %s:%s" % (listener_address, listener_port))
|
|
|
|
if relay_enabled:
|
2019-03-18 21:01:28 +00:00
|
|
|
relay = RelayFactory()
|
2022-07-28 18:38:37 +00:00
|
|
|
if relay_ssl is True:
|
2022-07-21 12:39:41 +00:00
|
|
|
reactor.listenSSL(
|
2022-07-28 18:38:37 +00:00
|
|
|
relay_port,
|
2022-07-21 12:39:41 +00:00
|
|
|
relay,
|
|
|
|
DefaultOpenSSLContextFactory(
|
|
|
|
main.certPath + main.config["Key"],
|
|
|
|
main.certPath + main.config["Certificate"],
|
|
|
|
),
|
2022-07-28 18:38:37 +00:00
|
|
|
interface=relay_address,
|
2022-07-21 12:39:41 +00:00
|
|
|
)
|
|
|
|
log(
|
|
|
|
"Threshold relay running with SSL on %s:%s"
|
2022-07-28 18:38:37 +00:00
|
|
|
% (relay_address, relay_port)
|
2022-07-21 12:39:41 +00:00
|
|
|
)
|
2019-03-18 21:01:28 +00:00
|
|
|
else:
|
2022-07-21 12:39:41 +00:00
|
|
|
reactor.listenTCP(
|
2022-07-28 18:38:37 +00:00
|
|
|
relay_port,
|
2022-07-21 12:39:41 +00:00
|
|
|
relay,
|
2022-07-28 18:38:37 +00:00
|
|
|
interface=relay_address,
|
2022-07-21 12:39:41 +00:00
|
|
|
)
|
2022-07-21 12:40:03 +00:00
|
|
|
log(
|
|
|
|
"Threshold relay running on %s:%s"
|
2022-07-28 18:38:37 +00:00
|
|
|
% (relay_address, relay_port)
|
2022-07-21 12:40:03 +00:00
|
|
|
)
|
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()
|
2022-07-28 18:38:37 +00:00
|
|
|
if api_enabled:
|
2022-07-21 12:40:11 +00:00
|
|
|
api = API()
|
2022-07-28 18:38:37 +00:00
|
|
|
api.app.run(api_address, api_port)
|
2022-07-21 12:40:11 +00:00
|
|
|
else:
|
|
|
|
reactor.run()
|