added tor control and stem
This commit is contained in:
parent
cf37823fd7
commit
67be0bebc2
@ -18,7 +18,8 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import subprocess, os, random, sys, logger, time, signal, config
|
import subprocess, os, random, sys, logger, time, signal, config, base64
|
||||||
|
from stem.control import Controller
|
||||||
from onionrblockapi import Block
|
from onionrblockapi import Block
|
||||||
|
|
||||||
class NetController:
|
class NetController:
|
||||||
@ -33,6 +34,14 @@ class NetController:
|
|||||||
self.hsPort = hsPort
|
self.hsPort = hsPort
|
||||||
self._torInstnace = ''
|
self._torInstnace = ''
|
||||||
self.myID = ''
|
self.myID = ''
|
||||||
|
|
||||||
|
if os.path.exists('./tor'):
|
||||||
|
self.torBinary = './tor'
|
||||||
|
elif os.path.exists('/usr/bin/tor'):
|
||||||
|
self.torBinary = '/usr/bin/tor'
|
||||||
|
else:
|
||||||
|
self.torBinary = 'tor'
|
||||||
|
|
||||||
config.reload()
|
config.reload()
|
||||||
'''
|
'''
|
||||||
if os.path.exists(self.torConfigLocation):
|
if os.path.exists(self.torConfigLocation):
|
||||||
@ -52,13 +61,27 @@ class NetController:
|
|||||||
if config.get('tor.v3onions'):
|
if config.get('tor.v3onions'):
|
||||||
hsVer = 'HiddenServiceVersion 3'
|
hsVer = 'HiddenServiceVersion 3'
|
||||||
logger.info('Using v3 onions :)')
|
logger.info('Using v3 onions :)')
|
||||||
|
|
||||||
if os.path.exists(self.torConfigLocation):
|
if os.path.exists(self.torConfigLocation):
|
||||||
os.remove(self.torConfigLocation)
|
os.remove(self.torConfigLocation)
|
||||||
|
|
||||||
|
# Set the Tor control password. Meant to make it harder to manipulate our Tor instance
|
||||||
|
plaintext = base64.b64encode(os.urandom(50)).decode()
|
||||||
|
config.set('tor.controlpassword', plaintext, savefile=True)
|
||||||
|
|
||||||
|
hashedPassword = subprocess.Popen([self.torBinary, '--hash-password', plaintext], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
for line in iter(hashedPassword.stdout.readline, b''):
|
||||||
|
password = line.decode()
|
||||||
|
break
|
||||||
|
|
||||||
torrcData = '''SocksPort ''' + str(self.socksPort) + '''
|
torrcData = '''SocksPort ''' + str(self.socksPort) + '''
|
||||||
HiddenServiceDir data/hs/
|
HiddenServiceDir data/hs/
|
||||||
\n''' + hsVer + '''\n
|
\n''' + hsVer + '''\n
|
||||||
HiddenServicePort 80 127.0.0.1:''' + str(self.hsPort) + '''
|
HiddenServicePort 80 127.0.0.1:''' + str(self.hsPort) + '''
|
||||||
DataDirectory data/tordata/
|
DataDirectory data/tordata/
|
||||||
|
CookieAuthentication 1
|
||||||
|
ControlPort 9051
|
||||||
|
HashedControlPassword ''' + str(password) + '''
|
||||||
'''
|
'''
|
||||||
torrc = open(self.torConfigLocation, 'w')
|
torrc = open(self.torConfigLocation, 'w')
|
||||||
torrc.write(torrcData)
|
torrc.write(torrcData)
|
||||||
@ -74,20 +97,20 @@ DataDirectory data/tordata/
|
|||||||
self.generateTorrc()
|
self.generateTorrc()
|
||||||
|
|
||||||
if os.path.exists('./tor'):
|
if os.path.exists('./tor'):
|
||||||
torBinary = './tor'
|
self.torBinary = './tor'
|
||||||
elif os.path.exists('/usr/bin/tor'):
|
elif os.path.exists('/usr/bin/tor'):
|
||||||
torBinary = '/usr/bin/tor'
|
self.torBinary = '/usr/bin/tor'
|
||||||
else:
|
else:
|
||||||
torBinary = 'tor'
|
self.torBinary = 'tor'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tor = subprocess.Popen([torBinary, '-f', self.torConfigLocation], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
tor = subprocess.Popen([self.torBinary, '-f', self.torConfigLocation], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.fatal("Tor was not found in your path or the Onionr directory. Please install Tor and try again.")
|
logger.fatal("Tor was not found in your path or the Onionr directory. Please install Tor and try again.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
# Test Tor Version
|
# Test Tor Version
|
||||||
torVersion = subprocess.Popen([torBinary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
torVersion = subprocess.Popen([self.torBinary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
for line in iter(torVersion.stdout.readline, b''):
|
for line in iter(torVersion.stdout.readline, b''):
|
||||||
if 'Tor 0.2.' in line.decode():
|
if 'Tor 0.2.' in line.decode():
|
||||||
logger.warn("Running 0.2.x Tor series, no support for v3 onion peers")
|
logger.warn("Running 0.2.x Tor series, no support for v3 onion peers")
|
||||||
|
@ -46,6 +46,7 @@ class OnionrCLIUI:
|
|||||||
showMenu = True
|
showMenu = True
|
||||||
isOnline = "No"
|
isOnline = "No"
|
||||||
firstRun = True
|
firstRun = True
|
||||||
|
choice = ''
|
||||||
|
|
||||||
if self.myCore._utils.localCommand('ping') == 'pong':
|
if self.myCore._utils.localCommand('ping') == 'pong':
|
||||||
firstRun = False
|
firstRun = False
|
||||||
|
@ -7,3 +7,4 @@ defusedxml==0.5.0
|
|||||||
simple_crypt==4.1.7
|
simple_crypt==4.1.7
|
||||||
Flask==1.0.2
|
Flask==1.0.2
|
||||||
PySocks==1.6.8
|
PySocks==1.6.8
|
||||||
|
stem==1.6.0
|
||||||
|
Loading…
Reference in New Issue
Block a user