diff --git a/client/favicon.ico b/client/favicon.ico new file mode 100644 index 0000000..2901e0d Binary files /dev/null and b/client/favicon.ico differ diff --git a/client/realtimetraffic.html b/client/realtimetraffic.html index 704dab3..39b1887 100644 --- a/client/realtimetraffic.html +++ b/client/realtimetraffic.html @@ -2,6 +2,7 @@ Realtime traffic monitor + diff --git a/client/scripts/realtimetraffic.js b/client/scripts/realtimetraffic.js index ab660b4..c0f33ee 100644 --- a/client/scripts/realtimetraffic.js +++ b/client/scripts/realtimetraffic.js @@ -1,14 +1,14 @@ (function() { var RealtimeTraffic = function() { - + this.tv = 500; this.last_data = null; this.connection = null; this.initialize(); - + } - + RealtimeTraffic.prototype.initialize = function() { var graph = this.graph = new Rickshaw.Graph( { @@ -21,7 +21,7 @@ timeInterval: this.tv, maxDataPoints: 200, timeBase: new Date().getTime() / 1000 - }) + }) } ); var xAxis = new Rickshaw.Graph.Axis.Time({ @@ -57,13 +57,13 @@ }; RealtimeTraffic.prototype.disconnect = function() { - + if (this.connection) { this.connection.close(); this.connection = this.last_data = null; this.needsReset = true; } - + }; RealtimeTraffic.prototype.connect = function(url, interf) { @@ -71,13 +71,13 @@ var ws_url = url+'?if='+interf; this.disconnect(); - + if (this.needsReset) { $("#chart").empty(); $("#legend").empty(); this.initialize(); } - + var connection; var that = this; @@ -125,7 +125,7 @@ that.last_data = interface_data; } }; - + }; $(document).ready(function() { @@ -148,7 +148,19 @@ $(document).ready(function() { url = localStorage.getItem("org.longsleep.realtimetraffic.defaults.url"); 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) { input_url.val(url); } @@ -169,18 +181,18 @@ $(document).ready(function() { $(realtimetraffic).on("close", function() { control.removeClass("connected"); }); - + button_start.on("click", function() { - + url = $.trim(input_url.val()); interf = $.trim(input_interf.val()); - + if (!url || !interf) { return; } - + realtimetraffic.connect(url, interf); - + if (Modernizr.localstorage) { try { 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); } } - + }); - + button_stop.on("click", function() { - + realtimetraffic.disconnect(); - + }); - + if (params.autostart === "1") { button_start.click(); } diff --git a/trafficserver/trafficserver.py b/trafficserver/trafficserver.py index 37b69a0..7273669 100644 --- a/trafficserver/trafficserver.py +++ b/trafficserver/trafficserver.py @@ -141,7 +141,7 @@ class ClientHandler(tornado.web.RequestHandler): def main(listen="127.0.0.1:8088"): from optparse import OptionParser - + parser = OptionParser() 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") @@ -159,7 +159,7 @@ def main(listen="127.0.0.1:8088"): listen = "%s:%s" % (address, port) application = tornado.web.Application([ - (r'^/ws$', WSHandler), + (r'^/realtimetraffic$', WSHandler), (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'^/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__": status = main() sys.exit(status) - +