mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
started web server in separate thread. organized file info, so it can be set from both cli and gui.
This commit is contained in:
parent
837533e9c6
commit
4868a9155b
@ -26,12 +26,20 @@ strings = {}
|
||||
# generate an unguessable string
|
||||
slug = os.urandom(16).encode('hex')
|
||||
|
||||
# file information
|
||||
filename = filehash = filesize = ''
|
||||
# information about the file
|
||||
filename = filesize = filehash = None
|
||||
def set_file_info(new_filename, new_filesize, new_filehash):
|
||||
global filename, filesize, filehash
|
||||
filename = new_filename
|
||||
filesize = new_filesize
|
||||
filehash = new_filehash
|
||||
|
||||
@app.route("/{0}".format(slug))
|
||||
def index():
|
||||
global filename, filesize, filehash, slug, strings
|
||||
print 'filename: {0}'.format(filename)
|
||||
print 'filehash: {0}'.format(filehash)
|
||||
print 'filesize: {0}'.format(filesize)
|
||||
return render_template_string(open('{0}/index.html'.format(os.path.dirname(__file__))).read(),
|
||||
slug=slug, filename=os.path.basename(filename), filehash=filehash, filesize=filesize, strings=strings)
|
||||
|
||||
@ -125,7 +133,6 @@ def start_hidden_service(port):
|
||||
return onion_host
|
||||
|
||||
def main():
|
||||
global filename, filehash, filesize
|
||||
load_strings()
|
||||
|
||||
# try starting hidden service
|
||||
@ -148,6 +155,7 @@ def main():
|
||||
# startup
|
||||
print strings["calculating_sha1"]
|
||||
filehash, filesize = file_crunching(filename)
|
||||
set_file_info(filename, filehash, filesize)
|
||||
tails_open_port(port)
|
||||
print '\n' + strings["give_this_url"]
|
||||
print 'http://{0}/{1}'.format(onion_host, slug)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import onionshare, webgui
|
||||
import os, sys, time, json, gtk
|
||||
import os, sys, time, json, gtk, thread
|
||||
|
||||
class Global(object):
|
||||
quit = False
|
||||
@ -75,14 +75,14 @@ def main():
|
||||
web_send("init('{0}', {1});".format(basename, json.dumps(strings)))
|
||||
web_send("update('{0}')".format(strings['calculating_sha1']))
|
||||
filehash, filesize = onionshare.file_crunching(filename)
|
||||
onionshare.set_file_info(filename, filehash, filesize)
|
||||
onionshare.tails_open_port(port)
|
||||
url = 'http://{0}/{1}'.format(onion_host, onionshare.slug)
|
||||
web_send("update('{0}')".format('Secret URL is {0}'.format(url)))
|
||||
web_send("set_url('{0}')".format(url));
|
||||
|
||||
# start the web server
|
||||
# todo: start this in another thread, and send output using web_send
|
||||
#onionshare.app.run(port=port)
|
||||
web_thread = thread.start_new_thread(onionshare.app.run, (), {"port": port})
|
||||
|
||||
# main loop
|
||||
last_second = time.time()
|
||||
|
Loading…
Reference in New Issue
Block a user