Compare commits
No commits in common. "05c9ae8d6ef0ddfd1016f686735d9b013436e629" and "f3677ad45e2fc7a8c4a35a0ab62e6ba9c5b72d99" have entirely different histories.
05c9ae8d6e
...
f3677ad45e
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,4 +6,3 @@ venv
|
|||
/*.egg-info
|
||||
*.pyc
|
||||
__pycache__
|
||||
.idea
|
34
build-deb.sh
34
build-deb.sh
|
@ -1,35 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ -z "${DEB_EMAIL}" ]]; then
|
||||
DEB_EMAIL="$1"
|
||||
TORCH_VERSION=$(git describe --tags --abbrev=0)
|
||||
PROJECT=torch-agent-$TORCH_VERSION
|
||||
|
||||
if [[ -z "${DEBEMAIL}" ]]; then
|
||||
DEBEMAIL="$1"
|
||||
fi
|
||||
|
||||
if [[ -z "${DEB_EMAIL}" ]]; then
|
||||
if [[ -z "${DEBEMAIL}" ]]; then
|
||||
echo "E-mail address required for packaging signing with gpg key!"
|
||||
echo "Usage: ./build-deb.sh EMAIL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TORCH_VERSION=$(git describe --tags --abbrev=0)
|
||||
PROJECT=torch-agent-$TORCH_VERSION
|
||||
|
||||
BUILD_DIR=dist
|
||||
DEB_DIR=$BUILD_DIR/$PROJECT
|
||||
|
||||
rm -rf "${BUILD_DIR:?}/"*
|
||||
rm -rf $BUILD_DIR/*
|
||||
|
||||
pip3 install -r requirements.txt
|
||||
python3 setup.py sdist
|
||||
|
||||
mkdir -p "$DEB_DIR/src/etc/torch"
|
||||
cp -r debian "$DEB_DIR/"
|
||||
cp torch.conf "$DEB_DIR/src/etc/torch/"
|
||||
mkdir -p $DEB_DIR/src/etc/torch
|
||||
cp -r debian $DEB_DIR/
|
||||
cp torch.conf $DEB_DIR/src/etc/torch/
|
||||
|
||||
cd $BUILD_DIR || exit
|
||||
tar -xzmf "$PROJECT.tar.gz"
|
||||
cd $BUILD_DIR
|
||||
tar -xzmf $PROJECT.tar.gz
|
||||
|
||||
cd "$PROJECT" || exit
|
||||
export USER
|
||||
USER=$(whoami)
|
||||
dh_make --createorig -e "$DEB_EMAIL" -s -y
|
||||
dpkg-buildpackage -k"$DEB_EMAIL"
|
||||
cd $PROJECT
|
||||
export USER=`whoami`
|
||||
dh_make --createorig -e $DEBEMAIL -s -y
|
||||
dpkg-buildpackage -k$DEBEMAIL
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[build-system]
|
||||
requires = ["setuptools", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
|
@ -1,5 +0,0 @@
|
|||
pip~=20.2.4
|
||||
setuptools~=50.3.2
|
||||
stdeb3~=0.9.0.post2
|
||||
paho-mqtt~=1.5.1
|
||||
stem>=1.8.0
|
5
requires.txt
Normal file
5
requires.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
wheel>=0.35.1
|
||||
setuptools>=44.0.0
|
||||
stem>=1.8.0
|
||||
paho-mqtt>=1.5.1
|
||||
PySocks>=1.7.1
|
24
setup.cfg
24
setup.cfg
|
@ -1,24 +0,0 @@
|
|||
[metadata]
|
||||
name = torch-agent
|
||||
version = attrib: torch_agent.__version__
|
||||
author = Benjamin Dweck
|
||||
author_email = bjdweck@gmail.com
|
||||
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
|
30
setup.py
30
setup.py
|
@ -1,4 +1,32 @@
|
|||
#!/usr/bin/env python3
|
||||
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="bjdweck@gmail.com",
|
||||
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()
|
||||
|
|
|
@ -6,10 +6,7 @@ ControllerPort = 9051
|
|||
Port = 22
|
||||
|
||||
[mqtt]
|
||||
|
||||
BrokerHost = mqtt.example.com
|
||||
#BrokerHost = example1i3uyrbfoi3fi.onion
|
||||
|
||||
BrokerHost = mqtt.example.com # OR example1i3uyrbfoi3fi.onion
|
||||
BrokerPort = 1883
|
||||
ClientID = my-client
|
||||
Topic = example/topic
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from stem.control import Controller
|
||||
import stem.connection
|
||||
import paho.mqtt.client as mqtt
|
||||
from paho.mqtt.client import socks
|
||||
import ssl
|
||||
import socks
|
||||
import socket
|
||||
import json
|
||||
import configparser
|
||||
|
@ -10,7 +10,6 @@ import argparse
|
|||
from datetime import datetime
|
||||
from os import environ
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Broadcast SSH hidden service hostname via MQTT')
|
||||
|
||||
|
@ -19,79 +18,79 @@ def main():
|
|||
|
||||
args = parser.parse_args()
|
||||
|
||||
config_path = args.configPath
|
||||
configPath = args.configPath
|
||||
|
||||
if "TORCH_CONFIG_DIR" in environ:
|
||||
config_path = environ.get("TORCH_CONFIG_DIR")
|
||||
configPath = environ.get("TORCH_CONFIG_DIR")
|
||||
|
||||
if not config_path.endswith("/"):
|
||||
config_path = config_path + "/"
|
||||
if not configPath.endswith("/"):
|
||||
configPath = configPath + "/"
|
||||
|
||||
print("Using torch configuration path: " + config_path)
|
||||
print("Using torch configuration path: " + configPath)
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_path + "torch.conf")
|
||||
config.read(configPath + "torch.conf")
|
||||
|
||||
tor_proxy_port = config['tor'].getint('ProxyPort', fallback=9050)
|
||||
tor_controller_port = config['tor'].getint('ControllerPort', fallback=9051)
|
||||
torProxyPort = config['tor'].getint('ProxyPort', fallback = 9050)
|
||||
torControllerPort = config['tor'].getint('ControllerPort', fallback = 9051)
|
||||
|
||||
ssh_port = config['ssh'].getint('Port', fallback=22)
|
||||
sshPort = config['ssh'].getint('Port', fallback = 22)
|
||||
|
||||
mqtt_config = config['mqtt']
|
||||
mqtt_broker_host = mqtt_config.get('BrokerHost', fallback="localhost")
|
||||
mqtt_broker_port = mqtt_config.getint('BrokerPort', fallback=1883)
|
||||
client_id = mqtt_config.get('ClientID', fallback=socket.gethostname())
|
||||
mqtt_topic = mqtt_config.get('Topic', fallback="torch/%s/onion_url" % client_id)
|
||||
mqttConfig = config['mqtt']
|
||||
mqttBrokerHost = mqttConfig.get('BrokerHost', fallback = "localhost")
|
||||
mqttBrokerPort = mqttConfig.getint('BrokerPort', fallback = 1883)
|
||||
clientID = mqttConfig.get('ClientID', fallback = socket.gethostname())
|
||||
mqttTopic = mqttConfig.get('Topic', fallback = "torch/%s/onion_url" % (clientID))
|
||||
|
||||
mqtt_require_certificate = mqtt_config.getboolean(
|
||||
mqttRequireCertificate = mqttConfig.getboolean(
|
||||
'RequireCertificate',
|
||||
fallback=False)
|
||||
fallback = False)
|
||||
|
||||
mqtt_ca_file = config_path + mqtt_config.get('CaFile')
|
||||
mqtt_cert_file = config_path + mqtt_config.get('CertFile')
|
||||
mqtt_key_file = config_path + mqtt_config.get('KeyFile')
|
||||
mqttCaFile = configPath + mqttConfig.get('CaFile')
|
||||
mqttCertFile = configPath + mqttConfig.get('CertFile')
|
||||
mqttKeyFile = configPath + mqttConfig.get('KeyFile')
|
||||
|
||||
with Controller.from_port(port=tor_controller_port) as controller:
|
||||
with Controller.from_port(port = torControllerPort) as controller:
|
||||
|
||||
protocol_info = stem.connection.get_protocolinfo(controller)
|
||||
protocolInfo = stem.connection.get_protocolinfo(controller)
|
||||
|
||||
stem.connection.authenticate_safecookie(
|
||||
controller,
|
||||
protocol_info.cookie_path)
|
||||
protocolInfo.cookie_path)
|
||||
|
||||
print("Connected to Tor on port %s" % tor_controller_port)
|
||||
print("Connected to Tor on port %s" % (torControllerPort))
|
||||
|
||||
service = controller.create_ephemeral_hidden_service(ssh_port, detached=True)
|
||||
service = controller.create_ephemeral_hidden_service(sshPort, detached = True)
|
||||
|
||||
onion_address = "%s.onion" % service.service_id
|
||||
onionAddress = "%s.onion" % (service.service_id)
|
||||
|
||||
print("Created Tor Hidden Service for local port %s at %s" % (ssh_port, onion_address))
|
||||
print("Created Tor Hidden Service for local port %s at %s" % (sshPort, onionAddress))
|
||||
|
||||
payload = {
|
||||
'clientId': client_id,
|
||||
'clientId': clientID,
|
||||
'timestamp': datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)"),
|
||||
'onionAddress': onion_address,
|
||||
'sshPort': ssh_port
|
||||
'onionAddress': onionAddress,
|
||||
'sshPort': sshPort
|
||||
}
|
||||
|
||||
client = mqtt.Client()
|
||||
protocol = "mqtt"
|
||||
|
||||
if mqtt_require_certificate:
|
||||
if mqttRequireCertificate:
|
||||
client.tls_set(
|
||||
ca_certs=mqtt_ca_file,
|
||||
certfile=mqtt_cert_file,
|
||||
keyfile=mqtt_key_file,
|
||||
ca_certs = mqttCaFile,
|
||||
certfile = mqttCertFile,
|
||||
keyfile = mqttKeyFile,
|
||||
cert_reqs=ssl.CERT_REQUIRED)
|
||||
protocol = "mqtts"
|
||||
|
||||
if mqtt_broker_host.endswith(".onion"):
|
||||
client.proxy_set(proxy_type=socks.SOCKS5, proxy_addr="localhost", proxy_port=tor_proxy_port)
|
||||
if mqttBrokerHost.endswith(".onion"):
|
||||
client.proxy_set(proxy_type=socks.SOCKS5, proxy_addr="localhost", proxy_port=torProxyPort)
|
||||
client.tls_insecure_set(True)
|
||||
|
||||
client.connect(mqtt_broker_host, mqtt_broker_port, 60)
|
||||
client.publish(mqtt_topic, json.dumps(payload))
|
||||
print("Connected to MQTT Broker at %s://%s:%s/%s" % (protocol, mqtt_broker_host, mqtt_broker_port, mqtt_topic))
|
||||
client.connect(mqttBrokerHost, mqttBrokerPort, 60)
|
||||
client.publish(mqttTopic, json.dumps(payload))
|
||||
print("Connected to MQTT Broker at %s://%s:%s/%s" % (protocol, mqttBrokerHost, mqttBrokerPort, mqttTopic))
|
||||
print("Published payload: " + json.dumps(payload))
|
||||
|
||||
client.disconnect()
|
||||
|
|
Loading…
Reference in New Issue
Block a user