(function() { /* * We display untrusted stuff in html context... reject anything * that has HTML stuff in it */ function san(s) { if (s.search("<") !== -1) return "invalid string"; return s; } function humanize(s) { var i = parseInt(s, 10); if (i >= (1024 * 1024 * 1024)) return (i / (1024 * 1024 * 1024)).toFixed(3) + "Gi"; if (i >= (1024 * 1024)) return (i / (1024 * 1024)).toFixed(3) + "Mi"; if (i > 1024) return (i / 1024).toFixed(3) + "Ki"; return s; } function get_appropriate_ws_url() { var pcol; var u = document.URL; /* * We open the websocket encrypted if this page came on an * https:// url itself, otherwise unencrypted */ if (u.substring(0, 5) === "https") { pcol = "wss://"; u = u.substr(8); } else { pcol = "ws://"; if (u.substring(0, 4) === "http") u = u.substr(7); } u = u.split("/"); /* + "/xxx" bit is for IE10 workaround */ return pcol + u[0] + "/xxx"; } var socket_status, jso, s; function ws_open_server_status() { socket_status = new WebSocket(get_appropriate_ws_url(), "lws-server-status"); try { socket_status.onopen = function() { document.getElementById("title").innerHTML = "Server Status (Active)"; lws_gray_out(false); }; socket_status.onmessage =function got_packet(msg) { var u, ci, n; //document.getElementById("json").innerHTML = "
"+msg.data+"
"; if (msg.data.length < 100) return; jso = JSON.parse(msg.data); u = parseInt(san(jso.i.uptime), 10); if (parseInt(jso.i.contexts[0].deprecated, 10) === 0) s = "
"; else s = ""; for (ci = 0; ci < jso.i.contexts.length; ci++) { if (parseInt(jso.i.contexts[ci].deprecated, 10) === 0) s += ""; } // context s = s + "
"; s += "Server" + "Server Version: " + san(jso.i.version) + "
" + "Host Uptime: " + ((u / (24 * 3600)) | 0) + "d " + (((u % (24 * 3600)) / 3600) | 0) + "h " + (((u % 3600) / 60) | 0) + "m"; if (jso.i.l1) s = s + ", Host Load: " + san(jso.i.l1) + " "; if (jso.i.l2) s = s + san(jso.i.l2) + " "; if (jso.i.l3) s = s + san(jso.i.l3); if (jso.i.l1) s =s + ""; if (jso.i.statm) { var sm = jso.i.statm.split(" "); s += ", Virt stack + heap Usage: " + humanize(parseInt(sm[5], 10) * 4096) + "B"; } s += ", lws heap usage: " + humanize(jso.i.heap) + "B"; for (n = 0; n < jso.files.length; n++) { s += "
" + san(jso.files[n].path) + ":
" + san(jso.files[n].val); } s += "
" + "Active Context"; else s += "
" + "Deprecated Context " + ci + ""; u = parseInt(san(jso.i.contexts[ci].context_uptime), 10); s += "Server Uptime: " + ((u / (24 * 3600)) | 0) + "d " + (((u % (24 * 3600)) / 3600) | 0) + "h " + (((u % 3600) / 60) | 0) + "m"; s = s + "
" + "Listening wsi: " + san(jso.i.contexts[ci].listen_wsi) + ", " + "Current wsi alive: " + (parseInt(san(jso.i.contexts[ci].wsi_alive), 10) - parseInt(san(jso.i.contexts[ci].listen_wsi), 10)) + "
" + "Total Rx: " + humanize(san(jso.i.contexts[ci].rx)) +"B, " + "Total Tx: " + humanize(san(jso.i.contexts[ci].tx)) +"B
" + "CONNECTIONS: HTTP/1.x: " + san(jso.i.contexts[ci].h1_conn) +", " + "Websocket: " + san(jso.i.contexts[ci].ws_upg) +", " + "H2 upgrade: " + san(jso.i.contexts[ci].h2_upg) +", " + "H2 ALPN: " + san(jso.i.contexts[ci].h2_alpn) +", " + "Rejected: " + san(jso.i.contexts[ci].rejected) +"
" + "TRANSACTIONS: HTTP/1.x: " + san(jso.i.contexts[ci].h1_trans) + ", " + "H2: " + san(jso.i.contexts[ci].h2_trans) +", " + "Total H2 substreams: " + san(jso.i.contexts[ci].h2_subs) +"
" + "CGI: alive: " + san(jso.i.contexts[ci].cgi_alive) + ", " + "spawned: " + san(jso.i.contexts[ci].cgi_spawned) + ""; for (n = 0; n < jso.i.contexts[ci].pt.length; n++) { if (parseInt(jso.i.contexts[ci].deprecated, 10) === 0) s += ""; } for (n = 0; n < jso.i.contexts[ci].vhosts.length; n++) { if (parseInt(jso.i.contexts[ci].deprecated, 10) === 0) s += ""; } s += "
  service thread " + (n + 1); else s += "
  service thread " + (n + 1); s += "" + "fds: " + san(jso.i.contexts[ci].pt[n].fds_count) + " / " + san(jso.i.contexts[ci].pt_fd_max) + ", "; s = s + "ah pool: " + san(jso.i.contexts[ci].pt[n].ah_pool_inuse) + " / " + san(jso.i.contexts[ci].ah_pool_max) + ", " + "ah waiting list: " + san(jso.i.contexts[ci].pt[n].ah_wait_list); s = s + "
  vhost " + (n + 1); else s += "
  vhost " + (n + 1); s += ""; if (jso.i.contexts[ci].vhosts[n].use_ssl === "1") s = s + "https://"; else s = s + "http://"; s = s + san(jso.i.contexts[ci].vhosts[n].name) + ":" + san(jso.i.contexts[ci].vhosts[n].port) + ""; if (jso.i.contexts[ci].vhosts[n].sts === "1") s = s + " (STS)"; s = s +"
" + "Total Rx: " + humanize(san(jso.i.contexts[ci].vhosts[n].rx)) +"B, " + "Total Tx: " + humanize(san(jso.i.contexts[ci].vhosts[n].tx)) +"B
" + "CONNECTIONS: HTTP/1.x: " + san(jso.i.contexts[ci].vhosts[n].h1_conn) +", " + "Websocket: " + san(jso.i.contexts[ci].vhosts[n].ws_upg) +", " + "H2 upgrade: " + san(jso.i.contexts[ci].vhosts[n].h2_upg) +", " + "H2 ALPN: " + san(jso.i.contexts[ci].vhosts[n].h2_alpn) +", " + "Rejected: " + san(jso.i.contexts[ci].vhosts[n].rejected) +"
" + "TRANSACTIONS: HTTP/1.x: " + san(jso.i.contexts[ci].vhosts[n].h1_trans) + ", " + "H2: " + san(jso.i.contexts[ci].vhosts[n].h2_trans) +", " + "Total H2 substreams: " + san(jso.i.contexts[ci].vhosts[n].h2_subs) +"
"; if (jso.i.contexts[ci].vhosts[n].mounts) { s = s + ""; var m; for (m = 0; m < jso.i.contexts[ci].vhosts[n].mounts.length; m++) { s = s + ""; } s = s + "
MountpointOriginCache Policy
"; s = s + "" + san(jso.i.contexts[ci].vhosts[n].mounts[m].mountpoint) + "" + san(jso.i.contexts[ci].vhosts[n].mounts[m].origin) + ""; if (parseInt(san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_max_age), 10)) s = s + "max-age: " + san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_max_age) + ", reuse: " + san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_reuse) + ", reval: " + san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_revalidate) + ", inter: " + san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_intermediaries); s = s + "
"; } s = s + "
"; document.getElementById("conninfo").innerHTML = s; }; socket_status.onclose = function(){ document.getElementById("title").innerHTML = "Server Status (Disconnected)"; lws_gray_out(true,{"zindex":"499"}); }; } catch(exception) { alert("

Error" + exception); } } /* stuff that has to be delayed until all the page assets are loaded */ window.addEventListener("load", function() { lws_gray_out(true,{"zindex":"499"}); ws_open_server_status(); }, false); }());