diff --git a/.travis.yml b/.travis.yml index 73e6e71a..5854d61e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,6 @@ python: - "3.6.4" # install dependencies install: - - sudo apt install gnupg + - sudo apt install gnupg tor - pip install -r requirements.txt script: ./test.sh diff --git a/onionr/core.py b/onionr/core.py index 653bd855..819ef0af 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -20,7 +20,7 @@ import sqlite3, os, time, math, gnupg, base64, tarfile, getpass, simplecrypt from Crypto.Cipher import AES from Crypto import Random - +import netcontroller class Core: def __init__(self): @@ -155,4 +155,4 @@ class Core: generate and return an HMAC key ''' key = base64.b64encode(os.urandom(32)) - return key + return key \ No newline at end of file diff --git a/onionr/netcontroller.py b/onionr/netcontroller.py index ada757e8..5fbfba4e 100644 --- a/onionr/netcontroller.py +++ b/onionr/netcontroller.py @@ -17,21 +17,35 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import subprocess +import subprocess, os class NetController: '''NetController This class handles hidden service setup on Tor and I2P ''' - def __init__(self, hsPort, socksPort): + def __init__(self, hsPort): self.torConfigLocation = 'data/torrc' self.readyState = False + self.socksPort = socksPort + self.hsPort = hsPort + if os.path.exists(self.torConfigLocation): + torrc = open(self.torConfigLocation, 'r') + if not self.hsPort in torrc.read(): + os.remove(self.torConfigLocation) return def generateTorrc(self): - torrcData = '''SOCKSPORT - + if os.path.exists(self.torConfigLocation): + os.remove(self.torConfigLocation) + torrcData = '''SOCKSPORT ''' + self.socksPort + ''' +HiddenServiceData data/hs/ +HiddenServicePort 80 127.0.0.1:''' + self.hsPort + ''' ''' + torrc = open(self.torConfigLocation, 'w') + torrc.write(torrcData) + torrc.close() return def startTor(self): + if not os.path.exists(self.torConfigLocation): + self.generateTorrc() subprocess.Popen(['tor', '-f ' + self.torConfigLocation]) return \ No newline at end of file diff --git a/onionr/onionr.py b/onionr/onionr.py index bb6cf823..749c85e9 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -24,6 +24,7 @@ import sys, os, configparser, base64, random, getpass, shutil, subprocess, reque import gui, api, colors, core from onionrutils import OnionrUtils from colors import Colors +from netcontroller import NetController class Onionr: def __init__(self): @@ -118,6 +119,10 @@ class Onionr: ''' Start the Onionr communication daemon ''' if not os.environ.get("WERKZEUG_RUN_MAIN") == "true": + net = NetController(self.config['PORT']) + print('Tor is starting...') + net.startTor(self.config['CLIENT']['PORT']) + time.sleep(5) subprocess.Popen(["./communicator.py", "run"]) print('Started communicator') api.API(self.config, self.debug)