mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
In Linux, create HS dir in /tmp/onionshare/* (#185), and also connect to Tor control port more robustly
This commit is contained in:
parent
c0f049bcff
commit
210448d6c9
@ -40,5 +40,7 @@
|
||||
"gui_starting_server1": "Starting Tor hidden service...",
|
||||
"gui_starting_server2": "Crunching files...",
|
||||
"gui_starting_server3": "Waiting for Tor hidden service...",
|
||||
"gui_please_wait": "Please wait..."
|
||||
"gui_please_wait": "Please wait...",
|
||||
"error_hs_dir_cannot_create": "Cannot create hidden service dir {0:s}",
|
||||
"error_hs_dir_not_writable": "Hidden service dir {0:s} is not writable"
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import os, sys, subprocess, time, argparse, inspect, shutil, socket, threading,
|
||||
import socks
|
||||
|
||||
from stem.control import Controller
|
||||
from stem import SocketError
|
||||
|
||||
import strings, helpers, web
|
||||
|
||||
@ -34,6 +33,10 @@ class TailsError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class HSDirError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def hsdic2list(dic):
|
||||
"""Convert what we get from get_conf_map to what we need for set_options"""
|
||||
return [
|
||||
@ -131,7 +134,17 @@ class OnionShare(object):
|
||||
gid = grp.getgrnam("debian-tor").gr_gid
|
||||
os.chown(self.hidserv_dir, uid, gid)
|
||||
else:
|
||||
self.hidserv_dir = tempfile.mkdtemp()
|
||||
# in non-Tails linux, onionshare will create HS dir in /tmp/onionshare/*
|
||||
path = '/tmp/onionshare'
|
||||
try:
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path, 0700)
|
||||
except:
|
||||
raise HSDirError(strings._("error_hs_dir_cannot_create").format(path))
|
||||
if not os.access(path, os.W_OK):
|
||||
raise HSDirError(strings._("error_hs_dir_not_writable").format(path))
|
||||
|
||||
self.hidserv_dir = tempfile.mkdtemp(dir=path)
|
||||
self.cleanup_filenames.append(self.hidserv_dir)
|
||||
|
||||
# connect to the tor controlport
|
||||
@ -140,12 +153,12 @@ class OnionShare(object):
|
||||
for tor_control_port in tor_control_ports:
|
||||
try:
|
||||
self.controller = Controller.from_port(port=tor_control_port)
|
||||
self.controller.authenticate()
|
||||
break
|
||||
except SocketError:
|
||||
except:
|
||||
pass
|
||||
if not self.controller:
|
||||
raise NoTor(strings._("cant_connect_ctrlport").format(tor_control_ports))
|
||||
self.controller.authenticate()
|
||||
|
||||
# set up hidden service
|
||||
if helpers.get_platform() == 'Windows':
|
||||
@ -301,6 +314,8 @@ def main(cwd=None):
|
||||
sys.exit(e.args[0])
|
||||
except TailsError as e:
|
||||
sys.exit(e.args[0])
|
||||
except HSDirError as e:
|
||||
sys.exit(e.args[0])
|
||||
|
||||
# prepare files to share
|
||||
print strings._("preparing_files")
|
||||
|
Loading…
Reference in New Issue
Block a user