diff --git a/install-ubuntu2004.sh b/install-ubuntu2004.sh index cf41d9b..2685302 100755 --- a/install-ubuntu2004.sh +++ b/install-ubuntu2004.sh @@ -2,7 +2,7 @@ apt update apt install -y tor python3-pip -sudo -H pip3 install stem paho-mqtt +sudo -H pip3 install stem paho-mqtt PySocks sed -i '/^#ControlPort 9051/s/^#//' /etc/tor/torrc sed -i '/^#CookieAuthentication 1/s/^#//' /etc/tor/torrc diff --git a/torch-pub.py b/torch-pub.py index b3db69e..b46c894 100644 --- a/torch-pub.py +++ b/torch-pub.py @@ -2,6 +2,7 @@ from stem.control import Controller import stem.connection import paho.mqtt.client as mqtt import ssl +import socks import configparser configPath = "/etc/torch/" @@ -9,6 +10,7 @@ configPath = "/etc/torch/" 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'] @@ -47,6 +49,10 @@ if mqttRequireCertificate: keyfile = mqttKeyFile, cert_reqs=ssl.CERT_REQUIRED) +if mqttBrokerHost.endswith(".onion"): + client.proxy_set(proxy_type=socks.SOCKS5, proxy_addr="localhost", proxy_port=torProxyPort) + client.tls_insecure_set(True) + client.connect(mqttBrokerHost, mqttBrokerPort, 60) client.publish(mqttTopic, onionAddress) client.disconnect()