10 Commits
Author SHA1 Message Date
bj a8b1029ad2 Can provision from the online Rudefox Debian repo 2020-10-20 10:49:38 +02:00
bj 32ee0ffe55 fixed up build-deb.sh 2020-10-20 10:25:31 +02:00
bj f31e9e62d7 fixed build by correcting typo in setup.cfg 2020-10-20 00:42:05 +02:00
bj 05c9ae8d6e Upgraded build system to setup.cfg 2020-10-20 00:27:38 +02:00
bj 64b9698010 Fixed PySocks (lack of) dependency and formatting 2020-10-20 00:20:33 +02:00
bj d9e68d50fe Upgraded setuptools version 2020-10-20 00:08:33 +02:00
bj 1c6da7a091 Added .gitignore for .idea 2020-10-20 00:08:17 +02:00
bj 609ccfbf27 Fixed bash script warnings 2020-10-20 00:07:57 +02:00
bj a78cddfdb1 Fixed broken comment 2020-10-20 00:07:36 +02:00
bj a38b6ee751 Fixed typo 2020-10-20 00:07:24 +02:00
11 changed files with 126 additions and 119 deletions
+1
View File
@@ -6,3 +6,4 @@ venv
/*.egg-info /*.egg-info
*.pyc *.pyc
__pycache__ __pycache__
.idea
+18 -17
View File
@@ -1,33 +1,34 @@
#!/bin/bash #!/bin/bash
TORCH_VERSION=$(git describe --tags --abbrev=0) if [[ -z "${DEB_EMAIL}" ]]; then
PROJECT=torch-agent-$TORCH_VERSION DEB_EMAIL="$1"
if [[ -z "${DEBEMAIL}" ]]; then
DEBEMAIL="$1"
fi fi
if [[ -z "${DEBEMAIL}" ]]; then if [[ -z "${DEB_EMAIL}" ]]; then
echo "E-mail address required for packaging signing with gpg key!" echo "E-mail address required for packaging signing with gpg key!"
echo "Usage: ./build-deb.sh EMAIL" echo "Usage: ./build-deb.sh EMAIL"
exit 1 exit 1
fi fi
TORCH_VERSION=$(git describe --tags --abbrev=0)
PROJECT=torch-agent-$TORCH_VERSION
BUILD_DIR=dist BUILD_DIR=dist
DEB_DIR=$BUILD_DIR/$PROJECT DEB_DIR=$BUILD_DIR/$PROJECT
rm -rf $BUILD_DIR/* rm -rf "${BUILD_DIR:?}"
mkdir -p "$DEB_DIR/src/etc/torch"
cp -r debian "$DEB_DIR/"
cp torch.conf "$DEB_DIR/src/etc/torch/"
pip3 install -r requirements.txt
python3 setup.py sdist python3 setup.py sdist
mkdir -p $DEB_DIR/src/etc/torch cd $BUILD_DIR || exit
cp -r debian $DEB_DIR/ tar -xzmf "$PROJECT.tar.gz"
cp torch.conf $DEB_DIR/src/etc/torch/
cd $BUILD_DIR cd "$PROJECT" || exit
tar -xzmf $PROJECT.tar.gz export USER
USER=$(whoami)
cd $PROJECT dh_make --createorig -e "$DEB_EMAIL" -s -y
export USER=`whoami` dpkg-buildpackage -k"$DEB_EMAIL"
dh_make --createorig -e $DEBEMAIL -s -y
dpkg-buildpackage -k$DEBEMAIL
+4 -2
View File
@@ -64,7 +64,6 @@ Vagrant.configure("2") do |config|
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
# documentation for more information about their specific syntax and use. # documentation for more information about their specific syntax and use.
config.vm.provision "file", source: "torch-agent_0.0.4-1_all.deb", destination: "~/"
config.vm.provision "file", source: "agent-config", destination: "~/torch-conf" config.vm.provision "file", source: "agent-config", destination: "~/torch-conf"
config.vm.provision "shell", inline: <<-SHELL config.vm.provision "shell", inline: <<-SHELL
@@ -72,7 +71,10 @@ Vagrant.configure("2") do |config|
sudo -- sh -c "echo '10.0.2.2 mqtt.example.com' >> /etc/hosts" sudo -- sh -c "echo '10.0.2.2 mqtt.example.com' >> /etc/hosts"
sudo apt update sudo apt update
sudo apt install -y ./torch-agent_0.0.4-1_all.deb wget -qO - https://rudefox.io/repo/gpg | sudo apt-key add
sudo add-apt-repository "deb https://repo.rudefox.io/repository/apt-release focal main"
sudo apt update
sudo apt install -y torch-agent
sudo cp -f torch-conf/* /etc/torch/ sudo cp -f torch-conf/* /etc/torch/
sudo chown -R torch /etc/torch sudo chown -R torch /etc/torch
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
+5
View File
@@ -0,0 +1,5 @@
pip~=20.2.4
setuptools~=50.3.2
stdeb3~=0.9.0.post2
paho-mqtt~=1.5.1
stem>=1.8.0
-5
View File
@@ -1,5 +0,0 @@
wheel>=0.35.1
setuptools>=44.0.0
stem>=1.8.0
paho-mqtt>=1.5.1
PySocks>=1.7.1
+24
View File
@@ -0,0 +1,24 @@
[metadata]
name = torch-agent
version = attr: torch_agent.__version__
author = Benjamin Dweck
author_email = [email protected]
description = TORch: Illuminate the Way to your Node
url = https://git.rudefox.io/bj/torch-agent
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
[options]
packages = find:
install_requires =
paho-mqtt~=1.5.1
setuptools~=50.3.1
pip~=20.2.3
stem
[options.entry_points]
console_scripts = torch-agent=torch_agent.torch_agent:main
[options.packages.find]
exclude=test
+1 -29
View File
@@ -1,32 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import setuptools import setuptools
import torch_agent
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="torch-agent",
version=torch_agent.__version__,
author="B.J. Dweck",
author_email="[email protected]",
description="TORch: Iluminate the Way to your Node",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://git.rudefox.io/bj/torch-agent",
packages=setuptools.find_packages(),
install_requires=[
'stem',
'paho-mqtt>=1.5.1',
'PySocks',
],
entry_points = {
'console_scripts': ['torch-agent=torch_agent.torch_agent:main'],
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
],
python_requires='>=3.6',
)
setuptools.setup()
+4 -1
View File
@@ -6,7 +6,10 @@ ControllerPort = 9051
Port = 22 Port = 22
[mqtt] [mqtt]
BrokerHost = mqtt.example.com # OR example1i3uyrbfoi3fi.onion
BrokerHost = mqtt.example.com
#BrokerHost = example1i3uyrbfoi3fi.onion
BrokerPort = 1883 BrokerPort = 1883
ClientID = my-client ClientID = my-client
Topic = example/topic Topic = example/topic
+39 -38
View File
@@ -1,8 +1,8 @@
from stem.control import Controller from stem.control import Controller
import stem.connection import stem.connection
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from paho.mqtt.client import socks
import ssl import ssl
import socks
import socket import socket
import json import json
import configparser import configparser
@@ -10,6 +10,7 @@ import argparse
from datetime import datetime from datetime import datetime
from os import environ from os import environ
def main(): def main():
parser = argparse.ArgumentParser(description='Broadcast SSH hidden service hostname via MQTT') parser = argparse.ArgumentParser(description='Broadcast SSH hidden service hostname via MQTT')
@@ -18,79 +19,79 @@ def main():
args = parser.parse_args() args = parser.parse_args()
configPath = args.configPath config_path = args.configPath
if "TORCH_CONFIG_DIR" in environ: if "TORCH_CONFIG_DIR" in environ:
configPath = environ.get("TORCH_CONFIG_DIR") config_path = environ.get("TORCH_CONFIG_DIR")
if not configPath.endswith("/"): if not config_path.endswith("/"):
configPath = configPath + "/" config_path = config_path + "/"
print("Using torch configuration path: " + configPath) print("Using torch configuration path: " + config_path)
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(configPath + "torch.conf") config.read(config_path + "torch.conf")
torProxyPort = config['tor'].getint('ProxyPort', fallback = 9050) tor_proxy_port = config['tor'].getint('ProxyPort', fallback=9050)
torControllerPort = config['tor'].getint('ControllerPort', fallback = 9051) tor_controller_port = config['tor'].getint('ControllerPort', fallback=9051)
sshPort = config['ssh'].getint('Port', fallback = 22) ssh_port = config['ssh'].getint('Port', fallback=22)
mqttConfig = config['mqtt'] mqtt_config = config['mqtt']
mqttBrokerHost = mqttConfig.get('BrokerHost', fallback = "localhost") mqtt_broker_host = mqtt_config.get('BrokerHost', fallback="localhost")
mqttBrokerPort = mqttConfig.getint('BrokerPort', fallback = 1883) mqtt_broker_port = mqtt_config.getint('BrokerPort', fallback=1883)
clientID = mqttConfig.get('ClientID', fallback = socket.gethostname()) client_id = mqtt_config.get('ClientID', fallback=socket.gethostname())
mqttTopic = mqttConfig.get('Topic', fallback = "torch/%s/onion_url" % (clientID)) mqtt_topic = mqtt_config.get('Topic', fallback="torch/%s/onion_url" % client_id)
mqttRequireCertificate = mqttConfig.getboolean( mqtt_require_certificate = mqtt_config.getboolean(
'RequireCertificate', 'RequireCertificate',
fallback=False) fallback=False)
mqttCaFile = configPath + mqttConfig.get('CaFile') mqtt_ca_file = config_path + mqtt_config.get('CaFile')
mqttCertFile = configPath + mqttConfig.get('CertFile') mqtt_cert_file = config_path + mqtt_config.get('CertFile')
mqttKeyFile = configPath + mqttConfig.get('KeyFile') mqtt_key_file = config_path + mqtt_config.get('KeyFile')
with Controller.from_port(port = torControllerPort) as controller: with Controller.from_port(port=tor_controller_port) as controller:
protocolInfo = stem.connection.get_protocolinfo(controller) protocol_info = stem.connection.get_protocolinfo(controller)
stem.connection.authenticate_safecookie( stem.connection.authenticate_safecookie(
controller, controller,
protocolInfo.cookie_path) protocol_info.cookie_path)
print("Connected to Tor on port %s" % (torControllerPort)) print("Connected to Tor on port %s" % tor_controller_port)
service = controller.create_ephemeral_hidden_service(sshPort, detached = True) service = controller.create_ephemeral_hidden_service(ssh_port, detached=True)
onionAddress = "%s.onion" % (service.service_id) onion_address = "%s.onion" % service.service_id
print("Created Tor Hidden Service for local port %s at %s" % (sshPort, onionAddress)) print("Created Tor Hidden Service for local port %s at %s" % (ssh_port, onion_address))
payload = { payload = {
'clientId': clientID, 'clientId': client_id,
'timestamp': datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)"), 'timestamp': datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)"),
'onionAddress': onionAddress, 'onionAddress': onion_address,
'sshPort': sshPort 'sshPort': ssh_port
} }
client = mqtt.Client() client = mqtt.Client()
protocol = "mqtt" protocol = "mqtt"
if mqttRequireCertificate: if mqtt_require_certificate:
client.tls_set( client.tls_set(
ca_certs = mqttCaFile, ca_certs=mqtt_ca_file,
certfile = mqttCertFile, certfile=mqtt_cert_file,
keyfile = mqttKeyFile, keyfile=mqtt_key_file,
cert_reqs=ssl.CERT_REQUIRED) cert_reqs=ssl.CERT_REQUIRED)
protocol = "mqtts" protocol = "mqtts"
if mqttBrokerHost.endswith(".onion"): if mqtt_broker_host.endswith(".onion"):
client.proxy_set(proxy_type=socks.SOCKS5, proxy_addr="localhost", proxy_port=torProxyPort) client.proxy_set(proxy_type=socks.SOCKS5, proxy_addr="localhost", proxy_port=tor_proxy_port)
client.tls_insecure_set(True) client.tls_insecure_set(True)
client.connect(mqttBrokerHost, mqttBrokerPort, 60) client.connect(mqtt_broker_host, mqtt_broker_port, 60)
client.publish(mqttTopic, json.dumps(payload)) client.publish(mqtt_topic, json.dumps(payload))
print("Connected to MQTT Broker at %s://%s:%s/%s" % (protocol, mqttBrokerHost, mqttBrokerPort, mqttTopic)) print("Connected to MQTT Broker at %s://%s:%s/%s" % (protocol, mqtt_broker_host, mqtt_broker_port, mqtt_topic))
print("Published payload: " + json.dumps(payload)) print("Published payload: " + json.dumps(payload))
client.disconnect() client.disconnect()