mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
rearranged onionshare_gui files, made it work better with packaging
This commit is contained in:
parent
33cd3ba0ea
commit
3deab0dc40
@ -2,3 +2,4 @@ include LICENSE
|
||||
include README.md
|
||||
include onionshare/*.html
|
||||
include onionshare/strings.json
|
||||
include onionshare_gui/html/*
|
||||
|
@ -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)
|
||||
|
@ -1 +1 @@
|
||||
from gui import *
|
||||
from onionshare_gui import *
|
||||
|
@ -6,7 +6,7 @@
|
||||
<body>
|
||||
<h1><span class="skull">☠</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>
|
@ -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'])
|
||||
}
|
@ -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;
|
@ -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()
|
||||
@ -39,7 +43,7 @@ def main():
|
||||
|
||||
# check msg for messages from the browser
|
||||
# use web_send() to send javascript to the browser
|
||||
|
||||
|
||||
if not again:
|
||||
time.sleep(0.1)
|
||||
|
||||
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user