summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2015-05-19 13:34:36 -0700
committerMicah Lee <micah@micahflee.com>2015-05-19 13:34:36 -0700
commit210448d6c9eea513bcefc009d07e4e0e4c3c8580 (patch)
tree20be803403844a76ddcfa04e617a84858e292b11
parentc0f049bcff2f7c4b51357ab48baa7856ee9f4de2 (diff)
downloadonionshare-210448d6c9eea513bcefc009d07e4e0e4c3c8580.tar.gz
onionshare-210448d6c9eea513bcefc009d07e4e0e4c3c8580.zip
In Linux, create HS dir in /tmp/onionshare/* (#185), and also connect to Tor control port more robustly
-rw-r--r--locale/en.json4
-rw-r--r--onionshare/onionshare.py23
2 files changed, 22 insertions, 5 deletions
diff --git a/locale/en.json b/locale/en.json
index 4a3faee8..e918b427 100644
--- a/locale/en.json
+++ b/locale/en.json
@@ -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"
}
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
index 54f3b27e..e08b1a61 100644
--- a/onionshare/onionshare.py
+++ b/onionshare/onionshare.py
@@ -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")