mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Merge branch 'joshuathayer-plugin-changes'
This commit is contained in:
commit
e9900fc5e9
@ -61,6 +61,9 @@
|
|||||||
top:1px;
|
top:1px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<meta name="onionshare-filename" content="{{ filename }}">
|
||||||
|
<meta name="onionshare-filesize" content="{{ filesize }}">
|
||||||
|
<meta name="onionshare-filehash" content="{{ filehash }}">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p><a class="button" href='/{{ slug }}/download'>{{ filename }} ▼</a></p>
|
<p><a class="button" href='/{{ slug }}/download'>{{ filename }} ▼</a></p>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import os, sys, subprocess, time, hashlib, platform, json, locale, socket
|
import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse
|
||||||
from random import randint
|
from random import randint
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@ -40,9 +40,6 @@ def set_file_info(new_filename, new_filehash, new_filesize):
|
|||||||
@app.route("/{0}".format(slug))
|
@app.route("/{0}".format(slug))
|
||||||
def index():
|
def index():
|
||||||
global filename, filesize, filehash, slug, strings
|
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(),
|
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)
|
slug=slug, filename=os.path.basename(filename), filehash=filehash, filesize=filesize, strings=strings)
|
||||||
|
|
||||||
@ -118,13 +115,16 @@ def start_hidden_service(port):
|
|||||||
# connect to the tor controlport
|
# connect to the tor controlport
|
||||||
controlports = [9051, 9151]
|
controlports = [9051, 9151]
|
||||||
controller = False
|
controller = False
|
||||||
|
|
||||||
for controlport in controlports:
|
for controlport in controlports:
|
||||||
try:
|
try:
|
||||||
controller = Controller.from_port(port=controlport)
|
controller = Controller.from_port(port=controlport)
|
||||||
except SocketError:
|
except SocketError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not controller:
|
if not controller:
|
||||||
raise NoTor(strings["cant_connect_ctrlport"].format(controlports))
|
raise NoTor(strings["cant_connect_ctrlport"].format(controlports))
|
||||||
|
|
||||||
controller.authenticate()
|
controller.authenticate()
|
||||||
|
|
||||||
# set up hidden service
|
# set up hidden service
|
||||||
@ -132,28 +132,35 @@ def start_hidden_service(port):
|
|||||||
('HiddenServiceDir', get_hidden_service_dir(port)),
|
('HiddenServiceDir', get_hidden_service_dir(port)),
|
||||||
('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
|
return onion_host
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
load_strings()
|
load_strings()
|
||||||
|
|
||||||
# try starting hidden service
|
parser = argparse.ArgumentParser()
|
||||||
port = choose_port()
|
parser.add_argument('--local-only', action='store_true', dest='local_only', help='Do not attempt to use tor: for development only')
|
||||||
print strings["connecting_ctrlport"].format(port)
|
parser.add_argument('filename', nargs=1)
|
||||||
try:
|
args = parser.parse_args()
|
||||||
onion_host = start_hidden_service(port)
|
|
||||||
except NoTor as e:
|
|
||||||
sys.exit(e.args[0])
|
|
||||||
|
|
||||||
# select file to share
|
filename = os.path.abspath(args.filename[0])
|
||||||
if len(sys.argv) != 2:
|
local_only = args.local_only
|
||||||
sys.exit('Usage: {0} [filename]'.format(sys.argv[0]));
|
|
||||||
filename = sys.argv[1]
|
if not (filename and os.path.isfile(filename)):
|
||||||
if not os.path.isfile(filename):
|
|
||||||
sys.exit(strings["not_a_file"].format(filename))
|
sys.exit(strings["not_a_file"].format(filename))
|
||||||
else:
|
filename = os.path.abspath(filename)
|
||||||
filename = os.path.abspath(filename)
|
|
||||||
|
port = choose_port()
|
||||||
|
local_host = "127.0.0.1:{0}".format(port)
|
||||||
|
|
||||||
|
if not local_only:
|
||||||
|
# try starting hidden service
|
||||||
|
print strings["connecting_ctrlport"].format(port)
|
||||||
|
try:
|
||||||
|
onion_host = start_hidden_service(port)
|
||||||
|
except NoTor as e:
|
||||||
|
sys.exit(e.args[0])
|
||||||
|
|
||||||
# startup
|
# startup
|
||||||
print strings["calculating_sha1"]
|
print strings["calculating_sha1"]
|
||||||
@ -161,7 +168,10 @@ def main():
|
|||||||
set_file_info(filename, filehash, filesize)
|
set_file_info(filename, filehash, filesize)
|
||||||
tails_open_port(port)
|
tails_open_port(port)
|
||||||
print '\n' + strings["give_this_url"]
|
print '\n' + strings["give_this_url"]
|
||||||
print 'http://{0}/{1}'.format(onion_host, slug)
|
if local_only:
|
||||||
|
print 'http://{0}/{1}'.format(local_host, slug)
|
||||||
|
else:
|
||||||
|
print 'http://{0}/{1}'.format(onion_host, slug)
|
||||||
print ''
|
print ''
|
||||||
print strings["ctrlc_to_stop"]
|
print strings["ctrlc_to_stop"]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user