tor fixes

This commit is contained in:
j 2024-06-09 14:46:28 +01:00
parent 8a5d8072ca
commit fd34ba305c

View file

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