tor fixes
This commit is contained in:
parent
8a5d8072ca
commit
fd34ba305c
1 changed files with 34 additions and 18 deletions
40
oml/tor.py
40
oml/tor.py
|
@ -26,6 +26,7 @@ logger = logging.getLogger(__name__)
|
||||||
class TorDaemon(Thread):
|
class TorDaemon(Thread):
|
||||||
installing = False
|
installing = False
|
||||||
running = True
|
running = True
|
||||||
|
ended = False
|
||||||
p = None
|
p = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -106,6 +107,8 @@ DirReqStatistics 0
|
||||||
logger.debug(line)
|
logger.debug(line)
|
||||||
self.p.communicate()
|
self.p.communicate()
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
self.ended = True
|
||||||
|
self.running = False
|
||||||
self.p = None
|
self.p = None
|
||||||
|
|
||||||
def kill(self):
|
def kill(self):
|
||||||
|
@ -143,6 +146,10 @@ class Tor(object):
|
||||||
logger.debug("Start tor")
|
logger.debug("Start tor")
|
||||||
self.daemon = TorDaemon()
|
self.daemon = TorDaemon()
|
||||||
return self.connect()
|
return self.connect()
|
||||||
|
elif self.daemon.ended:
|
||||||
|
logger.debug("Try starting tor again")
|
||||||
|
self.daemon = TorDaemon()
|
||||||
|
return self.connect()
|
||||||
if not self.daemon.installing:
|
if not self.daemon.installing:
|
||||||
logger.debug("Failed to connect to tor")
|
logger.debug("Failed to connect to tor")
|
||||||
return False
|
return False
|
||||||
|
@ -262,31 +269,34 @@ def torbrowser_url(sys_platform=None):
|
||||||
data = read_url(base_url, timeout=3*24*60*60).decode()
|
data = read_url(base_url, timeout=3*24*60*60).decode()
|
||||||
versions = []
|
versions = []
|
||||||
for r in (
|
for r in (
|
||||||
re.compile('href="(\d\.\d\.\d/)"'),
|
re.compile('href="(\d+\.\d+\.\d+/)"'),
|
||||||
re.compile('href="(\d\.\d/)"'),
|
re.compile('href="(\d+\.\d+/)"'),
|
||||||
):
|
):
|
||||||
versions += r.findall(data)
|
versions += r.findall(data)
|
||||||
|
if not versions:
|
||||||
|
return None
|
||||||
current = sorted(versions)[-1]
|
current = sorted(versions)[-1]
|
||||||
url = base_url + current
|
url = base_url + current
|
||||||
language = '.*?en'
|
|
||||||
if sys_platform.startswith('linux'):
|
if sys_platform.startswith('linux'):
|
||||||
if platform.architecture()[0] == '64bit':
|
if platform.architecture()[0] == '64bit':
|
||||||
osname = 'linux64'
|
osname = 'linux-x86_64'
|
||||||
else:
|
else:
|
||||||
osname = 'linux32'
|
osname = 'linux-x86_32'
|
||||||
ext = 'xz'
|
ext = 'xz'
|
||||||
elif sys_platform == 'darwin':
|
elif sys_platform == 'darwin':
|
||||||
osname = 'osx64'
|
osname = 'macos'
|
||||||
ext = 'dmg'
|
ext = 'dmg'
|
||||||
elif sys_platform == 'win32':
|
elif sys_platform == 'win32':
|
||||||
language = ''
|
osname = 'windows-x86_64-portable'
|
||||||
osname = ''
|
ext = 'exe'
|
||||||
ext = 'zip'
|
|
||||||
else:
|
else:
|
||||||
logger.debug('no way to get torbrowser url for %s', sys.platform)
|
logger.debug('no way to get torbrowser url for %s', sys.platform)
|
||||||
return None
|
return None
|
||||||
r = re.compile('href="(.*?{osname}{language}.*?{ext})"'.format(osname=osname,language=language,ext=ext))
|
data = read_url(url).decode()
|
||||||
torbrowser = sorted(r.findall(read_url(url).decode()))[-1]
|
r = re.compile('href="(.*?{osname}.*?{ext})"'.format(osname=osname, ext=ext)).findall(data)
|
||||||
|
if not r:
|
||||||
|
r = re.compile('href="(.*?{ext})"'.format(ext=ext)).findall(data)
|
||||||
|
torbrowser = sorted(r)[-1]
|
||||||
url += torbrowser
|
url += torbrowser
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
@ -303,7 +313,10 @@ def get_tor():
|
||||||
paths = [
|
paths = [
|
||||||
os.path.join(settings.base_dir, '..', 'platform_win32', 'tor', 'tor.exe')
|
os.path.join(settings.base_dir, '..', 'platform_win32', 'tor', 'tor.exe')
|
||||||
]
|
]
|
||||||
exe = os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'tor.exe')
|
for exe in (
|
||||||
|
os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'tor.exe'),
|
||||||
|
os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'Tor', 'tor.exe'),
|
||||||
|
):
|
||||||
for prefix in (
|
for prefix in (
|
||||||
os.path.join(os.path.expanduser('~'), 'Desktop'),
|
os.path.join(os.path.expanduser('~'), 'Desktop'),
|
||||||
os.path.join('C:', 'Program Files'),
|
os.path.join('C:', 'Program Files'),
|
||||||
|
@ -334,6 +347,9 @@ def get_tor():
|
||||||
path = os.path.join(base, 'TorBrowser', 'Tor', 'tor')
|
path = os.path.join(base, '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
|
||||||
|
path = os.path.join(base, 'TorBrowser', 'Tor', 'Tor', 'tor')
|
||||||
|
if os.path.isfile(path) and os.access(path, os.X_OK):
|
||||||
|
return path
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
local_tor = os.path.normpath(os.path.join(settings.base_dir, '..',
|
local_tor = os.path.normpath(os.path.join(settings.base_dir, '..',
|
||||||
|
|
Loading…
Reference in a new issue