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 README.md
|
||||||
include onionshare/*.html
|
include onionshare/*.html
|
||||||
include onionshare/strings.json
|
include onionshare/strings.json
|
||||||
|
include onionshare_gui/html/*
|
||||||
|
@ -77,21 +77,8 @@ def load_strings(default="en"):
|
|||||||
if lang in translated:
|
if lang in translated:
|
||||||
strings = translated[lang]
|
strings = translated[lang]
|
||||||
|
|
||||||
def main():
|
def file_crunching(filename):
|
||||||
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)
|
|
||||||
|
|
||||||
# calculate filehash, file size
|
# calculate filehash, file size
|
||||||
print strings["calculating_sha1"]
|
|
||||||
BLOCKSIZE = 65536
|
BLOCKSIZE = 65536
|
||||||
hasher = hashlib.sha1()
|
hasher = hashlib.sha1()
|
||||||
with open(filename, 'rb') as f:
|
with open(filename, 'rb') as f:
|
||||||
@ -101,15 +88,18 @@ def main():
|
|||||||
buf = f.read(BLOCKSIZE)
|
buf = f.read(BLOCKSIZE)
|
||||||
filehash = hasher.hexdigest()
|
filehash = hasher.hexdigest()
|
||||||
filesize = os.path.getsize(filename)
|
filesize = os.path.getsize(filename)
|
||||||
|
return filehash, filesize
|
||||||
|
|
||||||
|
def choose_port():
|
||||||
# let the OS choose a port
|
# let the OS choose a port
|
||||||
tmpsock = socket.socket()
|
tmpsock = socket.socket()
|
||||||
tmpsock.bind(("127.0.0.1", 0))
|
tmpsock.bind(("127.0.0.1", 0))
|
||||||
port = tmpsock.getsockname()[1]
|
port = tmpsock.getsockname()[1]
|
||||||
tmpsock.close()
|
tmpsock.close()
|
||||||
|
return port
|
||||||
|
|
||||||
|
def start_hidden_service(port):
|
||||||
# connect to the tor controlport
|
# connect to the tor controlport
|
||||||
print strings["connecting_ctrlport"].format(port)
|
|
||||||
controlports = [9051, 9151]
|
controlports = [9051, 9151]
|
||||||
controller = False
|
controller = False
|
||||||
for controlport in controlports:
|
for controlport in controlports:
|
||||||
@ -127,6 +117,27 @@ def main():
|
|||||||
('HiddenServicePort', '80 127.0.0.1:{0}'.format(port))
|
('HiddenServicePort', '80 127.0.0.1:{0}'.format(port))
|
||||||
])
|
])
|
||||||
onion_host = get_hidden_service_hostname(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
|
# punch a hole in the firewall
|
||||||
tails_open_port(port)
|
tails_open_port(port)
|
||||||
|
@ -1 +1 @@
|
|||||||
from gui import *
|
from onionshare_gui import *
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1><span class="skull">☠</span> <span id="basename">...</span></h1>
|
<h1><span class="skull">☠</span> <span id="basename">...</span></h1>
|
||||||
<div id="url-wrapper">
|
<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 id="url"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="output">...</div>
|
<div id="output">...</div>
|
@ -7,3 +7,7 @@ function set_basename(basename) {
|
|||||||
$('#basename').html(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;
|
background-color: #ffffff;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
#url-header {
|
#give-this-url {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
@ -14,6 +14,9 @@ def main():
|
|||||||
if not filename:
|
if not filename:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# initialize onionshare
|
||||||
|
onionshare.load_strings()
|
||||||
|
|
||||||
# open the window, launching webkit browser
|
# open the window, launching webkit browser
|
||||||
webgui.start_gtk_thread()
|
webgui.start_gtk_thread()
|
||||||
browser, web_recv, web_send = webgui.sync_gtk_msg(webgui.launch_window)(
|
browser, web_recv, web_send = webgui.sync_gtk_msg(webgui.launch_window)(
|
||||||
@ -23,6 +26,7 @@ def main():
|
|||||||
# send the browser initial data
|
# send the browser initial data
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
web_send("set_basename('{0}')".format(basename))
|
web_send("set_basename('{0}')".format(basename))
|
||||||
|
web_send("set_strings('{0}')".format(json.dumps(onionshare.strings)))
|
||||||
|
|
||||||
# main loop
|
# main loop
|
||||||
last_second = time.time()
|
last_second = time.time()
|
||||||
@ -39,7 +43,7 @@ def main():
|
|||||||
|
|
||||||
# check msg for messages from the browser
|
# check msg for messages from the browser
|
||||||
# use web_send() to send javascript to the browser
|
# use web_send() to send javascript to the browser
|
||||||
|
|
||||||
if not again:
|
if not again:
|
||||||
time.sleep(0.1)
|
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)
|
def callback_wrapper(widget, frame, title): callback(title)
|
||||||
browser.connect('title-changed', callback_wrapper)
|
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():
|
def web_recv():
|
||||||
if message_queue.empty():
|
if message_queue.empty():
|
||||||
|
Loading…
Reference in New Issue
Block a user