mirror of
https://github.com/longsleep/realtimetraffic.git
synced 2024-12-22 13:32:18 +01:00
added favicon
compute default url
This commit is contained in:
parent
24033fc3ee
commit
37c0263b51
4 changed files with 36 additions and 23 deletions
BIN
client/favicon.ico
Normal file
BIN
client/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 198 B |
|
@ -2,6 +2,7 @@
|
||||||
<html class="no-js">
|
<html class="no-js">
|
||||||
<head>
|
<head>
|
||||||
<title>Realtime traffic monitor</title>
|
<title>Realtime traffic monitor</title>
|
||||||
|
<link href="favicon.ico" rel="icon" type="image/x-icon"/>
|
||||||
<link type="text/css" rel="stylesheet" href="css/base.css">
|
<link type="text/css" rel="stylesheet" href="css/base.css">
|
||||||
<link type="text/css" rel="stylesheet" href="css/graph.css">
|
<link type="text/css" rel="stylesheet" href="css/graph.css">
|
||||||
<link type="text/css" rel="stylesheet" href="css/legend.css">
|
<link type="text/css" rel="stylesheet" href="css/legend.css">
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var RealtimeTraffic = function() {
|
var RealtimeTraffic = function() {
|
||||||
|
|
||||||
this.tv = 500;
|
this.tv = 500;
|
||||||
this.last_data = null;
|
this.last_data = null;
|
||||||
this.connection = null;
|
this.connection = null;
|
||||||
this.initialize();
|
this.initialize();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RealtimeTraffic.prototype.initialize = function() {
|
RealtimeTraffic.prototype.initialize = function() {
|
||||||
|
|
||||||
var graph = this.graph = new Rickshaw.Graph( {
|
var graph = this.graph = new Rickshaw.Graph( {
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
timeInterval: this.tv,
|
timeInterval: this.tv,
|
||||||
maxDataPoints: 200,
|
maxDataPoints: 200,
|
||||||
timeBase: new Date().getTime() / 1000
|
timeBase: new Date().getTime() / 1000
|
||||||
})
|
})
|
||||||
} );
|
} );
|
||||||
|
|
||||||
var xAxis = new Rickshaw.Graph.Axis.Time({
|
var xAxis = new Rickshaw.Graph.Axis.Time({
|
||||||
|
@ -57,13 +57,13 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
RealtimeTraffic.prototype.disconnect = function() {
|
RealtimeTraffic.prototype.disconnect = function() {
|
||||||
|
|
||||||
if (this.connection) {
|
if (this.connection) {
|
||||||
this.connection.close();
|
this.connection.close();
|
||||||
this.connection = this.last_data = null;
|
this.connection = this.last_data = null;
|
||||||
this.needsReset = true;
|
this.needsReset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
RealtimeTraffic.prototype.connect = function(url, interf) {
|
RealtimeTraffic.prototype.connect = function(url, interf) {
|
||||||
|
@ -71,13 +71,13 @@
|
||||||
var ws_url = url+'?if='+interf;
|
var ws_url = url+'?if='+interf;
|
||||||
|
|
||||||
this.disconnect();
|
this.disconnect();
|
||||||
|
|
||||||
if (this.needsReset) {
|
if (this.needsReset) {
|
||||||
$("#chart").empty();
|
$("#chart").empty();
|
||||||
$("#legend").empty();
|
$("#legend").empty();
|
||||||
this.initialize();
|
this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
var connection;
|
var connection;
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
that.last_data = interface_data;
|
that.last_data = interface_data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
@ -148,7 +148,19 @@ $(document).ready(function() {
|
||||||
url = localStorage.getItem("org.longsleep.realtimetraffic.defaults.url");
|
url = localStorage.getItem("org.longsleep.realtimetraffic.defaults.url");
|
||||||
interf = localStorage.getItem("org.longsleep.realtimetraffic.defaults.interf");
|
interf = localStorage.getItem("org.longsleep.realtimetraffic.defaults.interf");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// compute default URL based on current URL.
|
||||||
|
if (!url) {
|
||||||
|
if (/^((http|https):\/\/)/i.test(window.location.href)) {
|
||||||
|
if (/^(https:\/\/)/i.test(window.location.href)) {
|
||||||
|
url = "wss://"+window.location.host+"/realtimetraffic";
|
||||||
|
} else {
|
||||||
|
url = "ws://"+window.location.host+"/realtimetraffic";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
input_url.val(url);
|
input_url.val(url);
|
||||||
}
|
}
|
||||||
|
@ -169,18 +181,18 @@ $(document).ready(function() {
|
||||||
$(realtimetraffic).on("close", function() {
|
$(realtimetraffic).on("close", function() {
|
||||||
control.removeClass("connected");
|
control.removeClass("connected");
|
||||||
});
|
});
|
||||||
|
|
||||||
button_start.on("click", function() {
|
button_start.on("click", function() {
|
||||||
|
|
||||||
url = $.trim(input_url.val());
|
url = $.trim(input_url.val());
|
||||||
interf = $.trim(input_interf.val());
|
interf = $.trim(input_interf.val());
|
||||||
|
|
||||||
if (!url || !interf) {
|
if (!url || !interf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
realtimetraffic.connect(url, interf);
|
realtimetraffic.connect(url, interf);
|
||||||
|
|
||||||
if (Modernizr.localstorage) {
|
if (Modernizr.localstorage) {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem("org.longsleep.realtimetraffic.defaults.url", url);
|
localStorage.setItem("org.longsleep.realtimetraffic.defaults.url", url);
|
||||||
|
@ -189,15 +201,15 @@ $(document).ready(function() {
|
||||||
console.warn("Failed to store settings into localStorage with error " + e);
|
console.warn("Failed to store settings into localStorage with error " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
button_stop.on("click", function() {
|
button_stop.on("click", function() {
|
||||||
|
|
||||||
realtimetraffic.disconnect();
|
realtimetraffic.disconnect();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (params.autostart === "1") {
|
if (params.autostart === "1") {
|
||||||
button_start.click();
|
button_start.click();
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ class ClientHandler(tornado.web.RequestHandler):
|
||||||
def main(listen="127.0.0.1:8088"):
|
def main(listen="127.0.0.1:8088"):
|
||||||
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
parser.add_option("-l", "--listen", dest="listen", help="listen address (default: [%s])" % listen, default=listen)
|
parser.add_option("-l", "--listen", dest="listen", help="listen address (default: [%s])" % listen, default=listen)
|
||||||
parser.add_option("--ssl_keyfile", dest="ssl_keyfile", help="SSL key file", metavar="FILE")
|
parser.add_option("--ssl_keyfile", dest="ssl_keyfile", help="SSL key file", metavar="FILE")
|
||||||
|
@ -159,7 +159,7 @@ def main(listen="127.0.0.1:8088"):
|
||||||
listen = "%s:%s" % (address, port)
|
listen = "%s:%s" % (address, port)
|
||||||
|
|
||||||
application = tornado.web.Application([
|
application = tornado.web.Application([
|
||||||
(r'^/ws$', WSHandler),
|
(r'^/realtimetraffic$', WSHandler),
|
||||||
(r'^/css/(.*)$', tornado.web.StaticFileHandler, {'path': os.path.join(CLIENT_ROOT, 'css')}),
|
(r'^/css/(.*)$', tornado.web.StaticFileHandler, {'path': os.path.join(CLIENT_ROOT, 'css')}),
|
||||||
(r'^/scripts/(.*)$', tornado.web.StaticFileHandler, {'path': os.path.join(CLIENT_ROOT, 'scripts')}),
|
(r'^/scripts/(.*)$', tornado.web.StaticFileHandler, {'path': os.path.join(CLIENT_ROOT, 'scripts')}),
|
||||||
(r'^/img/(.*)$', tornado.web.StaticFileHandler, {'path': os.path.join(CLIENT_ROOT, 'img')}),
|
(r'^/img/(.*)$', tornado.web.StaticFileHandler, {'path': os.path.join(CLIENT_ROOT, 'img')}),
|
||||||
|
@ -194,5 +194,5 @@ def main(listen="127.0.0.1:8088"):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
status = main()
|
status = main()
|
||||||
sys.exit(status)
|
sys.exit(status)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue