Merge branch 'master' of github.com:micahflee/onionshare

This commit is contained in:
Micah Lee 2014-06-27 18:18:50 -04:00
commit 91abbca21e
3 changed files with 48 additions and 17 deletions

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64
from random import randint
from functools import wraps
@ -152,12 +153,12 @@ def is_root():
def tails_open_port(port):
if get_platform() == 'Tails':
print strings["punching_a_hole"]
print translated("punching_a_hole")
subprocess.call(['/sbin/iptables', '-I', 'OUTPUT', '-o', 'lo', '-p', 'tcp', '--dport', str(port), '-j', 'ACCEPT'])
def tails_close_port(port):
if get_platform() == 'Tails':
print strings["closing_hole"]
print translated("closing_hole")
subprocess.call(['/sbin/iptables', '-I', 'OUTPUT', '-o', 'lo', '-p', 'tcp', '--dport', str(port), '-j', 'REJECT'])
def load_strings(default="en"):
@ -177,6 +178,9 @@ def load_strings(default="en"):
strings[key] = translated[lang][key]
return strings
def translated(k):
return strings[k].encode("utf-8")
def file_crunching(filename):
# calculate filehash, file size
BLOCKSIZE = 65536
@ -219,7 +223,7 @@ def start_hidden_service(port):
except SocketError:
pass
if not controller:
raise NoTor(strings["cant_connect_ctrlport"].format(controlports))
raise NoTor(translated("cant_connect_ctrlport").format(controlports))
controller.authenticate()
# set up hidden service
@ -239,7 +243,7 @@ def main():
# check for root in Tails
if get_platform() == 'Tails' and not is_root():
sys.exit(strings["tails_requires_root"])
sys.exit(translated("tails_requires_root"))
# parse arguments
parser = argparse.ArgumentParser()
@ -255,7 +259,7 @@ def main():
stay_open = args.stay_open
if not (filename and os.path.isfile(filename)):
sys.exit(strings["not_a_file"].format(filename))
sys.exit(translated("not_a_file").format(filename))
filename = os.path.abspath(filename)
port = choose_port()
@ -263,24 +267,24 @@ def main():
if not local_only:
# try starting hidden service
print strings["connecting_ctrlport"].format(port)
print translated("connecting_ctrlport").format(port)
try:
onion_host = start_hidden_service(port)
except NoTor as e:
sys.exit(e.args[0])
# startup
print strings["calculating_sha1"]
print translated("calculating_sha1")
filehash, filesize = file_crunching(filename)
set_file_info(filename, filehash, filesize)
tails_open_port(port)
print '\n' + strings["give_this_url"]
print '\n' + translated("give_this_url")
if local_only:
print 'http://{0}/{1}'.format(local_host, slug)
else:
print 'http://{0}/{1}'.format(onion_host, slug)
print ''
print strings["ctrlc_to_stop"]
print translated("ctrlc_to_stop")
# start the web server
app.run(port=port)

View File

@ -3,7 +3,7 @@
"closing_hole": "Closing hole in firewall.",
"calculating_sha1": "Calculating SHA1 checksum.",
"connecting_ctrlport": "Connecting to Tor control port to set up hidden service on port {0}.",
"cant_connect_ctrlport": "Cannot connect to Tor control port on ports {0}. Is Tor running?",
"cant_connect_ctrlport": "Cannot connect to Tor control port on port {0}. Is Tor running?",
"give_this_url": "Give this URL to the person you're sending the file to:",
"ctrlc_to_stop": "Press Ctrl-C to stop server",
"not_a_file": "{0} is not a file.",
@ -28,7 +28,16 @@
"ctrlc_to_stop": "Trykk Ctrl+C for å stoppe serveren.",
"not_a_file": "{0} er ikke en fil.",
"filesize": "Filstørrelse",
"sha1_checksum": "SHA1 sjekksum"
"sha1_checksum": "SHA1 sjekksum",
"copied_url": "Kopierte URL-en til utklippstavlen",
"download_page_loaded": "Nedlastingsside lastet",
"download_started": "Nedlasting startet",
"download_finished": "Nedlasting fullført",
"other_page_loaded": "En annen side har blitt lastet",
"tails_requires_root": "OnionShare kan må kjøres som administrator i Tails",
"close_on_finish": "Lukk automatisk",
"close_countdown": "Lukker om {0} sekunder",
"choose_file": "Velg en fil å dele"
}, "es": {
"punching_a_hole": "Abriendo un agujero en el cortafuegos.",
"closing_hole": "Cerrando el agujero en el cortafuegos.",
@ -39,8 +48,17 @@
"ctrlc_to_stop": "Pulse Ctrl-C para detener servidor",
"not_a_file": "{0} no es un archivo.",
"filesize": "Tamaño del archivo",
"sha1_checksum": "Suma de verificación SHA1"
}, "fr": {
"sha1_checksum": "Suma de verificación SHA1",
"copied_url": "Copiar URL en el portapapeles",
"download_page_loaded": "Descargar página cargada.",
"download_started": "Descarga comenzó",
"download_finished": "Descarga terminado",
"other_page_loaded": "Otra página se ha cargado",
"tails_requires_root": "Debe ejecutar OnionShare como root en Tails",
"close_on_finish": "Cerrar automáticamente.",
"close_countdown": "Cierre en {0} segundos...",
"choose_file": "Elija un archivo para compartir"
}, "fr": {
"punching_a_hole": "Poinçonnage d'un trou dans le pare-feu.",
"closing_hole": "Trou de clôture dans le pare-feu.",
"calculating_sha1": "Calculer un hachage SHA-1.",
@ -61,7 +79,16 @@
"ctrlc_to_stop": "Premi Ctrl-C per fermare il server",
"not_a_file": "{0} non è un file.",
"filesize": "Grandezza del file",
"sha1_checksum": "firma SHA1"
"sha1_checksum": "Firma SHA1",
"copied_url": "URL copiato negli appunti",
"download_page_loaded": "Pagina di download caricata",
"download_started": "Download iniziato",
"download_finished": "Download finito",
"other_page_loaded": "Un altra pagina é stata caricata",
"tails_requires_root": "Con Tails devi avviare OnionShare come utente root",
"close_on_finish": "Chiudi automaticamente",
"close_countdown": "Chiusura in {0} secondi...",
"choose_file": "Scegli un file da condividere"
}, "nl": {
"punching_a_hole": "Een doorgang aan het maken in de firewall.",
"closing_hole": "Doorgang in de firewall sluiten.",

View File

@ -13,7 +13,7 @@ try:
except ImportError:
sys.path.append(os.path.abspath(onionshare_gui_dir+"/.."))
import onionshare
from onionshare import translated
import webapp
window_icon = None
@ -61,7 +61,7 @@ def select_file(strings, filename=None):
if onionshare.get_platform() == 'Tails':
args['directory'] = '/home/amnesia'
filename = QFileDialog.getOpenFileName(caption=strings['choose_file'], options=QFileDialog.ReadOnly, **args)
filename = QFileDialog.getOpenFileName(caption=translated('choose_file'), options=QFileDialog.ReadOnly, **args)
if not filename:
return False, False
@ -69,7 +69,7 @@ def select_file(strings, filename=None):
# validate filename
if not os.path.isfile(filename):
alert(strings["not_a_file"].format(filename), QMessageBox.Warning)
alert(translated("not_a_file").format(filename), QMessageBox.Warning)
return False, False
filename = os.path.abspath(filename)