From c415b548c5ec11df41518f98b2f0324e63936b71 Mon Sep 17 00:00:00 2001 From: BJ Dweck Date: Mon, 5 Oct 2020 16:36:04 +0200 Subject: [PATCH] Added --config-dir parameter and timestamp in payload --- torch-pub.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/torch-pub.py b/torch-pub.py index 6420447..9bd7888 100644 --- a/torch-pub.py +++ b/torch-pub.py @@ -6,15 +6,29 @@ import socks import socket import json import configparser +import argparse +from datetime import datetime -configPath = "/etc/torch/" +parser = argparse.ArgumentParser(description='Broadcast SSH hidden service hostname via MQTT') + +parser.add_argument('--config-dir', nargs='?', dest='configPath', default='/etc/torch', + help='configuration directory (default: /etc/torch)') + +args = parser.parse_args() + +configPath = args.configPath + +if not configPath.endswith("/"): + configPath = configPath + "/" config = configparser.ConfigParser() config.read(configPath + "torch.conf") torProxyPort = config['tor'].getint('ProxyPort', fallback = 9050) torControllerPort = config['tor'].getint('ControllerPort', fallback = 9051) + sshPort = config['ssh'].getint('Port', fallback = 22) + mqttConfig = config['mqtt'] mqttBrokerHost = mqttConfig.get('BrokerHost', fallback = "localhost") mqttBrokerPort = mqttConfig.getint('BrokerPort', fallback = 1883) @@ -43,7 +57,12 @@ with Controller.from_port(port = torControllerPort) as controller: onionAddress = "%s.onion" % (service.service_id) -payload = { 'clientId': clientID, 'onionAddress': onionAddress } +payload = { + 'clientId': clientID, + 'timestamp': datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)"), + 'onionAddress': onionAddress, + 'sshPort': sshPort + } client = mqtt.Client()