In Linux, create HS dir in /tmp/onionshare/* (#185), and also connect to Tor control port more robustly

This commit is contained in:
Micah Lee 2015-05-19 13:34:36 -07:00
parent c0f049bcff
commit 210448d6c9
2 changed files with 22 additions and 5 deletions

View file

@ -40,5 +40,7 @@
"gui_starting_server1": "Starting Tor hidden service...", "gui_starting_server1": "Starting Tor hidden service...",
"gui_starting_server2": "Crunching files...", "gui_starting_server2": "Crunching files...",
"gui_starting_server3": "Waiting for Tor hidden service...", "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"
} }

View file

@ -21,7 +21,6 @@ import os, sys, subprocess, time, argparse, inspect, shutil, socket, threading,
import socks import socks
from stem.control import Controller from stem.control import Controller
from stem import SocketError
import strings, helpers, web import strings, helpers, web
@ -34,6 +33,10 @@ class TailsError(Exception):
pass pass
class HSDirError(Exception):
pass
def hsdic2list(dic): def hsdic2list(dic):
"""Convert what we get from get_conf_map to what we need for set_options""" """Convert what we get from get_conf_map to what we need for set_options"""
return [ return [
@ -131,7 +134,17 @@ class OnionShare(object):
gid = grp.getgrnam("debian-tor").gr_gid gid = grp.getgrnam("debian-tor").gr_gid
os.chown(self.hidserv_dir, uid, gid) os.chown(self.hidserv_dir, uid, gid)
else: 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) self.cleanup_filenames.append(self.hidserv_dir)
# connect to the tor controlport # connect to the tor controlport
@ -140,12 +153,12 @@ class OnionShare(object):
for tor_control_port in tor_control_ports: for tor_control_port in tor_control_ports:
try: try:
self.controller = Controller.from_port(port=tor_control_port) self.controller = Controller.from_port(port=tor_control_port)
self.controller.authenticate()
break break
except SocketError: except:
pass pass
if not self.controller: if not self.controller:
raise NoTor(strings._("cant_connect_ctrlport").format(tor_control_ports)) raise NoTor(strings._("cant_connect_ctrlport").format(tor_control_ports))
self.controller.authenticate()
# set up hidden service # set up hidden service
if helpers.get_platform() == 'Windows': if helpers.get_platform() == 'Windows':
@ -301,6 +314,8 @@ def main(cwd=None):
sys.exit(e.args[0]) sys.exit(e.args[0])
except TailsError as e: except TailsError as e:
sys.exit(e.args[0]) sys.exit(e.args[0])
except HSDirError as e:
sys.exit(e.args[0])
# prepare files to share # prepare files to share
print strings._("preparing_files") print strings._("preparing_files")