work on net controller

This commit is contained in:
Kevin Froman 2018-01-19 03:16:38 -06:00
parent 388752c079
commit 9d91e77ec5
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
4 changed files with 26 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -17,21 +17,35 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
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

View File

@ -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)