use tor from platform package
This commit is contained in:
parent
04a1c6b951
commit
0e44e319c4
1 changed files with 32 additions and 15 deletions
47
oml/tor.py
47
oml/tor.py
|
@ -74,14 +74,16 @@ DirReqStatistics 0
|
||||||
self.installing = False
|
self.installing = False
|
||||||
tor = get_tor()
|
tor = get_tor()
|
||||||
if tor:
|
if tor:
|
||||||
if 'TorBrowser' in tor and sys.platform.startswith('linux'):
|
if sys.platform.startswith('linux') and (
|
||||||
|
'TorBrowser' in tor or tor.startswith(os.path.dirname(settings.base_dir))
|
||||||
|
):
|
||||||
env = {
|
env = {
|
||||||
'LD_LIBRARY_PATH': os.path.dirname(tor)
|
'LD_LIBRARY_PATH': os.path.dirname(tor)
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
env = None
|
env = None
|
||||||
cmd = [tor, '--defaults-torrc', defaults, '-f', torrc, 'DataDirectory', tor_data]
|
cmd = [tor, '--defaults-torrc', defaults, '-f', torrc, 'DataDirectory', tor_data]
|
||||||
cmd += self.geoip(tor)
|
cmd += get_geoip(tor)
|
||||||
cwd = os.path.dirname(tor)
|
cwd = os.path.dirname(tor)
|
||||||
while self.running:
|
while self.running:
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
|
@ -99,17 +101,6 @@ DirReqStatistics 0
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
self.p = None
|
self.p = None
|
||||||
|
|
||||||
def geoip(self, tor):
|
|
||||||
geo = []
|
|
||||||
tordir = os.path.dirname(os.path.dirname(tor))
|
|
||||||
gepipfile = os.path.join(tordir, 'Data', 'Tor', 'geoip')
|
|
||||||
gepipv6file = os.path.join(tordir, 'Data', 'Tor', 'geoip6')
|
|
||||||
if os.path.exists(gepipfile):
|
|
||||||
geo += ['GeoIPFile', gepipfile]
|
|
||||||
if os.path.exists(gepipv6file):
|
|
||||||
geo += ['GeoIPv6File', gepipv6file]
|
|
||||||
return geo
|
|
||||||
|
|
||||||
def kill(self):
|
def kill(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
if self.p:
|
if self.p:
|
||||||
|
@ -281,13 +272,16 @@ def torbrowser_url(sys_platform=None):
|
||||||
def get_tor():
|
def get_tor():
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
for path in (
|
for path in (
|
||||||
|
os.path.join(settings.base_dir, '..', 'platform_darwin64', 'tor', 'tor'),
|
||||||
'/Applications/TorBrowser.app/TorBrowser/Tor/tor',
|
'/Applications/TorBrowser.app/TorBrowser/Tor/tor',
|
||||||
os.path.join(settings.base_dir, '..', 'tor', 'TorBrowser.app', 'TorBrowser', 'Tor', 'tor')
|
os.path.join(settings.base_dir, '..', 'tor', 'TorBrowser.app', 'TorBrowser', 'Tor', 'tor')
|
||||||
):
|
):
|
||||||
if os.path.isfile(path) and os.access(path, os.X_OK):
|
if os.path.isfile(path) and os.access(path, os.X_OK):
|
||||||
return path
|
return path
|
||||||
elif sys.platform == 'win32':
|
elif sys.platform == 'win32':
|
||||||
paths = []
|
paths = [
|
||||||
|
os.path.join(settings.base_dir, '..', 'platform_win32', 'tor', 'tor.exe')
|
||||||
|
]
|
||||||
exe = os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'tor.exe')
|
exe = os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'tor.exe')
|
||||||
for prefix in (
|
for prefix in (
|
||||||
os.path.join(os.path.expanduser('~'), 'Desktop'),
|
os.path.join(os.path.expanduser('~'), 'Desktop'),
|
||||||
|
@ -299,7 +293,14 @@ def get_tor():
|
||||||
paths.append(os.path.join(settings.base_dir, '..', 'tor', 'Tor', 'tor.exe'))
|
paths.append(os.path.join(settings.base_dir, '..', 'tor', 'Tor', 'tor.exe'))
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if os.path.isfile(path) and os.access(path, os.X_OK):
|
if os.path.isfile(path) and os.access(path, os.X_OK):
|
||||||
return path
|
return os.path.normpath(path)
|
||||||
|
elif sys.platform.startswith('linux'):
|
||||||
|
for path in (
|
||||||
|
os.path.join(settings.base_dir, '..', 'platform_linux64', 'tor', 'tor'),
|
||||||
|
os.path.join(settings.base_dir, '..', 'platform_linux32', 'tor', 'tor'),
|
||||||
|
):
|
||||||
|
if os.path.isfile(path) and os.access(path, os.X_OK):
|
||||||
|
return os.path.normpath(path)
|
||||||
start = os.path.expanduser('~/.local/share/applications/start-tor-browser.desktop')
|
start = os.path.expanduser('~/.local/share/applications/start-tor-browser.desktop')
|
||||||
if os.path.exists(start):
|
if os.path.exists(start):
|
||||||
with open(start) as fd:
|
with open(start) as fd:
|
||||||
|
@ -318,6 +319,22 @@ def get_tor():
|
||||||
return local_tor
|
return local_tor
|
||||||
return distutils.spawn.find_executable('tor')
|
return distutils.spawn.find_executable('tor')
|
||||||
|
|
||||||
|
def get_geoip(tor):
|
||||||
|
geo = []
|
||||||
|
for tordir in (
|
||||||
|
os.path.normpath(os.path.join(settings.base_dir, '..', 'platform', 'tor')),
|
||||||
|
os.path.join(os.path.dirname(os.path.dirname(tor)), 'Data', 'Tor')
|
||||||
|
):
|
||||||
|
gepipfile = os.path.join(tordir, 'geoip')
|
||||||
|
gepipv6file = os.path.join(tordir, 'geoip6')
|
||||||
|
if os.path.exists(gepipfile):
|
||||||
|
geo += ['GeoIPFile', gepipfile]
|
||||||
|
if os.path.exists(gepipv6file):
|
||||||
|
geo += ['GeoIPv6File', gepipv6file]
|
||||||
|
if geo:
|
||||||
|
break
|
||||||
|
return geo
|
||||||
|
|
||||||
def install_tor():
|
def install_tor():
|
||||||
import tarfile
|
import tarfile
|
||||||
import update
|
import update
|
||||||
|
|
Loading…
Reference in a new issue