mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-26 01:11:27 -05:00
displays web logs in GUI now. fixes #33
This commit is contained in:
parent
67ea5b5c2c
commit
927282a432
@ -1,4 +1,4 @@
|
|||||||
import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse
|
import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue
|
||||||
from random import randint
|
from random import randint
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@ -37,21 +37,37 @@ def set_file_info(new_filename, new_filehash, new_filesize):
|
|||||||
filehash = new_filehash
|
filehash = new_filehash
|
||||||
filesize = new_filesize
|
filesize = new_filesize
|
||||||
|
|
||||||
|
REQUEST_LOAD = 0
|
||||||
|
REQUEST_DOWNLOAD = 1
|
||||||
|
REQUEST_OTHER = 2
|
||||||
|
request_q = Queue.Queue()
|
||||||
|
|
||||||
|
def add_request(type):
|
||||||
|
global request_q
|
||||||
|
request_q.put({
|
||||||
|
'type': type,
|
||||||
|
'path': request.path
|
||||||
|
})
|
||||||
|
|
||||||
@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, REQUEST_LOAD
|
||||||
|
add_request(REQUEST_LOAD)
|
||||||
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)
|
||||||
|
|
||||||
@app.route("/{0}/download".format(slug))
|
@app.route("/{0}/download".format(slug))
|
||||||
def download():
|
def download():
|
||||||
global filename
|
global filename, request_q, REQUEST_DOWNLOAD
|
||||||
|
add_request(REQUEST_DOWNLOAD)
|
||||||
dirname = os.path.dirname(filename)
|
dirname = os.path.dirname(filename)
|
||||||
basename = os.path.basename(filename)
|
basename = os.path.basename(filename)
|
||||||
return send_from_directory(dirname, basename, as_attachment=True)
|
return send_from_directory(dirname, basename, as_attachment=True)
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
|
global REQUEST_OTHER
|
||||||
|
add_request(REQUEST_OTHER)
|
||||||
return render_template_string(open('{0}/404.html'.format(os.path.dirname(__file__))).read())
|
return render_template_string(open('{0}/404.html'.format(os.path.dirname(__file__))).read())
|
||||||
|
|
||||||
def get_hidden_service_dir(port):
|
def get_hidden_service_dir(port):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
$(function(){
|
$(function(){
|
||||||
onionshare = {}
|
var onionshare = {}
|
||||||
|
|
||||||
function update($msg) {
|
function update($msg) {
|
||||||
var $line = $('<p></p>').append($msg);
|
var $line = $('<p></p>').append($msg);
|
||||||
@ -17,12 +17,36 @@ $(function(){
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/copy_url',
|
url: '/copy_url',
|
||||||
success: function(data, textStatus, jqXHR){
|
success: function(data, textStatus, jqXHR){
|
||||||
update('Copied secret URL to clipboard.');
|
update('Copied secret URL to clipboard');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$('#copy-button').click(copy_to_clipboard);
|
$('#copy-button').click(copy_to_clipboard);
|
||||||
|
|
||||||
|
var REQUEST_LOAD = 0;
|
||||||
|
var REQUEST_DOWNLOAD = 1;
|
||||||
|
var REQUEST_OTHER = 2;
|
||||||
|
function check_for_requests() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/check_for_requests',
|
||||||
|
success: function(data, textStatus, jqXHR){
|
||||||
|
if(data != '') {
|
||||||
|
var r = JSON.parse(data);
|
||||||
|
if(r.type == REQUEST_LOAD) {
|
||||||
|
update($('<span>').addClass('weblog').html('Download page loaded'));
|
||||||
|
} else if(r.type == REQUEST_DOWNLOAD) {
|
||||||
|
update($('<span>').addClass('weblog').html('Download started'));
|
||||||
|
} else {
|
||||||
|
if(r.path != '/favicon.ico')
|
||||||
|
update($('<span>').addClass('weblog-error').html('Other page has been loaded: {0}'.replace('{0}', r.path)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(check_for_requests, 1000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// start onionshare
|
// start onionshare
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/start_onionshare',
|
url: '/start_onionshare',
|
||||||
@ -39,6 +63,8 @@ $(function(){
|
|||||||
copy_to_clipboard();
|
copy_to_clipboard();
|
||||||
$('#copy-button').show();
|
$('#copy-button').show();
|
||||||
|
|
||||||
|
setTimeout(check_for_requests, 1000);
|
||||||
|
|
||||||
$('#loading').hide();
|
$('#loading').hide();
|
||||||
$('#content').show();
|
$('#content').show();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ h1 {
|
|||||||
|
|
||||||
p {
|
p {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0 0 .3em 0;
|
margin: 0 0 .5em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#output {
|
#output {
|
||||||
@ -31,6 +31,16 @@ p {
|
|||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#output .weblog {
|
||||||
|
color: #009900;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
#output .weblog-error {
|
||||||
|
color: #990000;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
-moz-box-shadow:inset 0px 1px 0px 0px #f29c93;
|
-moz-box-shadow:inset 0px 1px 0px 0px #f29c93;
|
||||||
-webkit-box-shadow:inset 0px 1px 0px 0px #f29c93;
|
-webkit-box-shadow:inset 0px 1px 0px 0px #f29c93;
|
||||||
@ -77,14 +87,6 @@ p {
|
|||||||
bottom: 10px;
|
bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loader {
|
|
||||||
width: 21px;
|
|
||||||
height: 20px;
|
|
||||||
background-image: url('loader.gif');
|
|
||||||
background-position: top left;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
}
|
|
||||||
|
|
||||||
#loading {
|
#loading {
|
||||||
width: 550px;
|
width: 550px;
|
||||||
height: 300px;
|
height: 300px;
|
||||||
|
@ -44,3 +44,12 @@ def copy_url():
|
|||||||
clipboard.set_text(url)
|
clipboard.set_text(url)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
@app.route("/check_for_requests")
|
||||||
|
def check_for_requests():
|
||||||
|
global onionshare
|
||||||
|
try:
|
||||||
|
r = onionshare.request_q.get(False)
|
||||||
|
return json.dumps(r)
|
||||||
|
except onionshare.Queue.Empty:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user