Added support for tor / onion broker hostname
This commit is contained in:
parent
de6ac8a1ff
commit
d58745ca2e
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
apt update
|
apt update
|
||||||
apt install -y tor python3-pip
|
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 '/^#ControlPort 9051/s/^#//' /etc/tor/torrc
|
||||||
sed -i '/^#CookieAuthentication 1/s/^#//' /etc/tor/torrc
|
sed -i '/^#CookieAuthentication 1/s/^#//' /etc/tor/torrc
|
||||||
|
|
|
@ -2,6 +2,7 @@ from stem.control import Controller
|
||||||
import stem.connection
|
import stem.connection
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import ssl
|
import ssl
|
||||||
|
import socks
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
configPath = "/etc/torch/"
|
configPath = "/etc/torch/"
|
||||||
|
@ -9,6 +10,7 @@ configPath = "/etc/torch/"
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(configPath + "torch.conf")
|
config.read(configPath + "torch.conf")
|
||||||
|
|
||||||
|
torProxyPort = config['tor'].getint('ProxyPort', fallback = 9050)
|
||||||
torControllerPort = config['tor'].getint('ControllerPort', fallback = 9051)
|
torControllerPort = config['tor'].getint('ControllerPort', fallback = 9051)
|
||||||
sshPort = config['ssh'].getint('Port', fallback = 22)
|
sshPort = config['ssh'].getint('Port', fallback = 22)
|
||||||
mqttConfig = config['mqtt']
|
mqttConfig = config['mqtt']
|
||||||
|
@ -47,6 +49,10 @@ if mqttRequireCertificate:
|
||||||
keyfile = mqttKeyFile,
|
keyfile = mqttKeyFile,
|
||||||
cert_reqs=ssl.CERT_REQUIRED)
|
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.connect(mqttBrokerHost, mqttBrokerPort, 60)
|
||||||
client.publish(mqttTopic, onionAddress)
|
client.publish(mqttTopic, onionAddress)
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user