rearranged onionshare_gui files, made it work better with packaging

This commit is contained in:
Micah Lee 2014-05-29 22:53:35 -04:00
parent 33cd3ba0ea
commit 3deab0dc40
9 changed files with 40 additions and 20 deletions

View File

@ -2,3 +2,4 @@ include LICENSE
include README.md
include onionshare/*.html
include onionshare/strings.json
include onionshare_gui/html/*

View File

@ -77,21 +77,8 @@ def load_strings(default="en"):
if lang in translated:
strings = translated[lang]
def main():
global filename, filehash, filesize
load_strings()
# validate filename
if len(sys.argv) != 2:
sys.exit('Usage: {0} [filename]'.format(sys.argv[0]));
filename = sys.argv[1]
if not os.path.isfile(filename):
sys.exit(strings["not_a_file"].format(filename))
else:
filename = os.path.abspath(filename)
def file_crunching(filename):
# calculate filehash, file size
print strings["calculating_sha1"]
BLOCKSIZE = 65536
hasher = hashlib.sha1()
with open(filename, 'rb') as f:
@ -101,15 +88,18 @@ def main():
buf = f.read(BLOCKSIZE)
filehash = hasher.hexdigest()
filesize = os.path.getsize(filename)
return filehash, filesize
def choose_port():
# let the OS choose a port
tmpsock = socket.socket()
tmpsock.bind(("127.0.0.1", 0))
port = tmpsock.getsockname()[1]
tmpsock.close()
return port
def start_hidden_service(port):
# connect to the tor controlport
print strings["connecting_ctrlport"].format(port)
controlports = [9051, 9151]
controller = False
for controlport in controlports:
@ -127,6 +117,27 @@ def main():
('HiddenServicePort', '80 127.0.0.1:{0}'.format(port))
])
onion_host = get_hidden_service_hostname(port)
return onion_host
def main():
global filename, filehash, filesize
load_strings()
# validate filename
if len(sys.argv) != 2:
sys.exit('Usage: {0} [filename]'.format(sys.argv[0]));
filename = sys.argv[1]
if not os.path.isfile(filename):
sys.exit(strings["not_a_file"].format(filename))
else:
filename = os.path.abspath(filename)
print strings["calculating_sha1"]
filehash, filesize = file_crunching(filename)
port = choose_port()
print strings["connecting_ctrlport"].format(port)
onion_host = start_hidden_service(port)
# punch a hole in the firewall
tails_open_port(port)

View File

@ -1 +1 @@
from gui import *
from onionshare_gui import *

View File

@ -6,7 +6,7 @@
<body>
<h1><span class="skull">&#9760;</span> <span id="basename">...</span></h1>
<div id="url-wrapper">
<div id="url-header">Give this URL to the person you're sending the file to:</div>
<div id="give-this-url">Give this URL to the person you're sending the file to:</div>
<div id="url"></div>
</div>
<div id="output">...</div>

View File

@ -7,3 +7,7 @@ function set_basename(basename) {
$('#basename').html(basename);
}
function set_strings(strings) {
strings = JSON.parse(strings)
$('#give-this-url').html(strings['give_this_url'])
}

View File

@ -25,7 +25,7 @@ h1 .skull {
background-color: #ffffff;
display: none;
}
#url-header {
#give-this-url {
font-size: 14px;
margin-bottom: 10px;
font-family: sans-serif;

View File

@ -14,6 +14,9 @@ def main():
if not filename:
return
# initialize onionshare
onionshare.load_strings()
# open the window, launching webkit browser
webgui.start_gtk_thread()
browser, web_recv, web_send = webgui.sync_gtk_msg(webgui.launch_window)(
@ -23,6 +26,7 @@ def main():
# send the browser initial data
time.sleep(0.1)
web_send("set_basename('{0}')".format(basename))
web_send("set_strings('{0}')".format(json.dumps(onionshare.strings)))
# main loop
last_second = time.time()

View File

@ -75,7 +75,7 @@ def launch_window(title='OnionShare', quit_function=None, echo=True):
def callback_wrapper(widget, frame, title): callback(title)
browser.connect('title-changed', callback_wrapper)
browser.open('file://'+os.getcwd()+'/index.html')
browser.open('file://'+os.path.abspath(os.path.dirname(__file__))+'/html/index.html')
def web_recv():
if message_queue.empty():