mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04: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 functools import wraps
|
||||
|
||||
@ -37,21 +37,37 @@ def set_file_info(new_filename, new_filehash, new_filesize):
|
||||
filehash = new_filehash
|
||||
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))
|
||||
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(),
|
||||
slug=slug, filename=os.path.basename(filename), filehash=filehash, filesize=filesize, strings=strings)
|
||||
|
||||
@app.route("/{0}/download".format(slug))
|
||||
def download():
|
||||
global filename
|
||||
global filename, request_q, REQUEST_DOWNLOAD
|
||||
add_request(REQUEST_DOWNLOAD)
|
||||
dirname = os.path.dirname(filename)
|
||||
basename = os.path.basename(filename)
|
||||
return send_from_directory(dirname, basename, as_attachment=True)
|
||||
|
||||
@app.errorhandler(404)
|
||||
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())
|
||||
|
||||
def get_hidden_service_dir(port):
|
||||
|
@ -1,5 +1,5 @@
|
||||
$(function(){
|
||||
onionshare = {}
|
||||
var onionshare = {}
|
||||
|
||||
function update($msg) {
|
||||
var $line = $('<p></p>').append($msg);
|
||||
@ -17,12 +17,36 @@ $(function(){
|
||||
$.ajax({
|
||||
url: '/copy_url',
|
||||
success: function(data, textStatus, jqXHR){
|
||||
update('Copied secret URL to clipboard.');
|
||||
update('Copied secret URL 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
|
||||
$.ajax({
|
||||
url: '/start_onionshare',
|
||||
@ -39,6 +63,8 @@ $(function(){
|
||||
copy_to_clipboard();
|
||||
$('#copy-button').show();
|
||||
|
||||
setTimeout(check_for_requests, 1000);
|
||||
|
||||
$('#loading').hide();
|
||||
$('#content').show();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ h1 {
|
||||
|
||||
p {
|
||||
padding: 0;
|
||||
margin: 0 0 .3em 0;
|
||||
margin: 0 0 .5em 0;
|
||||
}
|
||||
|
||||
#output {
|
||||
@ -31,6 +31,16 @@ p {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
#output .weblog {
|
||||
color: #009900;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#output .weblog-error {
|
||||
color: #990000;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.button {
|
||||
-moz-box-shadow:inset 0px 1px 0px 0px #f29c93;
|
||||
-webkit-box-shadow:inset 0px 1px 0px 0px #f29c93;
|
||||
@ -77,14 +87,6 @@ p {
|
||||
bottom: 10px;
|
||||
}
|
||||
|
||||
.loader {
|
||||
width: 21px;
|
||||
height: 20px;
|
||||
background-image: url('loader.gif');
|
||||
background-position: top left;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
#loading {
|
||||
width: 550px;
|
||||
height: 300px;
|
||||
|
@ -44,3 +44,12 @@ def copy_url():
|
||||
clipboard.set_text(url)
|
||||
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…
Reference in New Issue
Block a user