2013-08-08 04:15:28 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
"use strict";
|
2013-08-08 04:15:28 +04:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const FileUtils = ChromeUtils.import("resource://gre/modules/FileUtils.jsm").FileUtils;
|
2016-09-29 22:03:49 +03:00
|
|
|
const gEnv = Cc["@mozilla.org/process/environment;1"]
|
|
|
|
.getService(Ci.nsIEnvironment);
|
2017-01-17 18:48:17 +03:00
|
|
|
const gDashboard = Cc["@mozilla.org/network/dashboard;1"]
|
2016-09-29 22:03:49 +03:00
|
|
|
.getService(Ci.nsIDashboard);
|
|
|
|
const gDirServ = Cc["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Ci.nsIDirectoryServiceProvider);
|
|
|
|
|
2013-08-26 19:27:28 +04:00
|
|
|
const gRequestNetworkingData = {
|
|
|
|
"http": gDashboard.requestHttpConnections,
|
|
|
|
"sockets": gDashboard.requestSockets,
|
|
|
|
"dns": gDashboard.requestDNSInfo,
|
2017-05-10 20:23:54 +03:00
|
|
|
"websockets": gDashboard.requestWebsocketConnections,
|
2017-07-05 02:41:00 +03:00
|
|
|
"dnslookuptool": () => {},
|
|
|
|
"logging": () => {},
|
2017-05-10 20:23:54 +03:00
|
|
|
"rcwn": gDashboard.requestRcwnStats,
|
2013-08-26 19:27:28 +04:00
|
|
|
};
|
|
|
|
const gDashboardCallbacks = {
|
|
|
|
"http": displayHttp,
|
|
|
|
"sockets": displaySockets,
|
|
|
|
"dns": displayDns,
|
2017-05-10 20:23:54 +03:00
|
|
|
"websockets": displayWebsockets,
|
|
|
|
"rcwn": displayRcwnStats,
|
2013-08-26 19:27:28 +04:00
|
|
|
};
|
2013-08-08 04:15:28 +04:00
|
|
|
|
|
|
|
const REFRESH_INTERVAL_MS = 3000;
|
|
|
|
|
|
|
|
function col(element) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let col = document.createElement("td");
|
2013-08-08 04:15:28 +04:00
|
|
|
let content = document.createTextNode(element);
|
|
|
|
col.appendChild(content);
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayHttp(data) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let cont = document.getElementById("http_content");
|
2013-08-08 04:15:28 +04:00
|
|
|
let parent = cont.parentNode;
|
2017-01-17 18:48:17 +03:00
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "http_content");
|
2013-08-08 04:15:28 +04:00
|
|
|
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let i = 0; i < data.connections.length; i++) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let row = document.createElement("tr");
|
2013-11-20 18:29:01 +04:00
|
|
|
row.appendChild(col(data.connections[i].host));
|
|
|
|
row.appendChild(col(data.connections[i].port));
|
|
|
|
row.appendChild(col(data.connections[i].spdy));
|
|
|
|
row.appendChild(col(data.connections[i].ssl));
|
|
|
|
row.appendChild(col(data.connections[i].active.length));
|
|
|
|
row.appendChild(col(data.connections[i].idle.length));
|
2013-08-08 04:15:28 +04:00
|
|
|
new_cont.appendChild(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.replaceChild(new_cont, cont);
|
|
|
|
}
|
|
|
|
|
|
|
|
function displaySockets(data) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let cont = document.getElementById("sockets_content");
|
2013-08-08 04:15:28 +04:00
|
|
|
let parent = cont.parentNode;
|
2017-01-17 18:48:17 +03:00
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "sockets_content");
|
2013-08-08 04:15:28 +04:00
|
|
|
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let i = 0; i < data.sockets.length; i++) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let row = document.createElement("tr");
|
2013-11-20 18:29:01 +04:00
|
|
|
row.appendChild(col(data.sockets[i].host));
|
|
|
|
row.appendChild(col(data.sockets[i].port));
|
|
|
|
row.appendChild(col(data.sockets[i].tcp));
|
|
|
|
row.appendChild(col(data.sockets[i].active));
|
|
|
|
row.appendChild(col(data.sockets[i].sent));
|
|
|
|
row.appendChild(col(data.sockets[i].received));
|
2013-08-08 04:15:28 +04:00
|
|
|
new_cont.appendChild(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.replaceChild(new_cont, cont);
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayDns(data) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let cont = document.getElementById("dns_content");
|
2013-08-08 04:15:28 +04:00
|
|
|
let parent = cont.parentNode;
|
2017-01-17 18:48:17 +03:00
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "dns_content");
|
2013-08-08 04:15:28 +04:00
|
|
|
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let i = 0; i < data.entries.length; i++) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let row = document.createElement("tr");
|
2013-11-20 18:29:01 +04:00
|
|
|
row.appendChild(col(data.entries[i].hostname));
|
|
|
|
row.appendChild(col(data.entries[i].family));
|
2017-01-17 18:48:17 +03:00
|
|
|
let column = document.createElement("td");
|
2013-08-08 04:15:28 +04:00
|
|
|
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let j = 0; j < data.entries[i].hostaddr.length; j++) {
|
|
|
|
column.appendChild(document.createTextNode(data.entries[i].hostaddr[j]));
|
2017-01-17 18:48:17 +03:00
|
|
|
column.appendChild(document.createElement("br"));
|
2013-08-08 04:15:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
row.appendChild(column);
|
2013-11-20 18:29:01 +04:00
|
|
|
row.appendChild(col(data.entries[i].expiration));
|
2013-08-08 04:15:28 +04:00
|
|
|
new_cont.appendChild(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.replaceChild(new_cont, cont);
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayWebsockets(data) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let cont = document.getElementById("websockets_content");
|
2013-08-08 04:15:28 +04:00
|
|
|
let parent = cont.parentNode;
|
2017-01-17 18:48:17 +03:00
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "websockets_content");
|
2013-08-08 04:15:28 +04:00
|
|
|
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let i = 0; i < data.websockets.length; i++) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let row = document.createElement("tr");
|
2013-11-20 18:29:01 +04:00
|
|
|
row.appendChild(col(data.websockets[i].hostport));
|
|
|
|
row.appendChild(col(data.websockets[i].encrypted));
|
|
|
|
row.appendChild(col(data.websockets[i].msgsent));
|
|
|
|
row.appendChild(col(data.websockets[i].msgreceived));
|
|
|
|
row.appendChild(col(data.websockets[i].sentsize));
|
|
|
|
row.appendChild(col(data.websockets[i].receivedsize));
|
2013-08-08 04:15:28 +04:00
|
|
|
new_cont.appendChild(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.replaceChild(new_cont, cont);
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:23:54 +03:00
|
|
|
function displayRcwnStats(data) {
|
|
|
|
let status = Services.prefs.getBoolPref("network.http.rcwn.enabled");
|
|
|
|
let cacheWon = data.rcwnCacheWonCount;
|
|
|
|
let netWon = data.rcwnNetWonCount;
|
|
|
|
let total = data.totalNetworkRequests;
|
2017-07-05 02:41:00 +03:00
|
|
|
let cacheSlow = data.cacheSlowCount;
|
|
|
|
let cacheNotSlow = data.cacheNotSlowCount;
|
2017-05-10 20:23:54 +03:00
|
|
|
|
|
|
|
document.getElementById("rcwn_status").innerText = status;
|
|
|
|
document.getElementById("total_req_count").innerText = total;
|
|
|
|
document.getElementById("rcwn_cache_won_count").innerText = cacheWon;
|
|
|
|
document.getElementById("rcwn_cache_net_count").innerText = netWon;
|
2017-07-05 02:41:00 +03:00
|
|
|
document.getElementById("rcwn_cache_slow").innerText = cacheSlow;
|
|
|
|
document.getElementById("rcwn_cache_not_slow").innerText = cacheNotSlow;
|
|
|
|
|
|
|
|
// Keep in sync with CachePerfStats::EDataType in CacheFileUtils.h
|
|
|
|
const perfStatTypes = [
|
|
|
|
"open",
|
|
|
|
"read",
|
|
|
|
"write",
|
|
|
|
"entryopen",
|
|
|
|
];
|
|
|
|
|
|
|
|
const perfStatFieldNames = [
|
|
|
|
"avgShort",
|
|
|
|
"avgLong",
|
|
|
|
"stddevLong",
|
2017-10-15 21:50:30 +03:00
|
|
|
];
|
2017-07-05 02:41:00 +03:00
|
|
|
|
|
|
|
for (let typeIndex in perfStatTypes) {
|
|
|
|
for (let statFieldIndex in perfStatFieldNames) {
|
|
|
|
document.getElementById("rcwn_perfstats_" + perfStatTypes[typeIndex] + "_"
|
|
|
|
+ perfStatFieldNames[statFieldIndex]).innerText =
|
|
|
|
data.perfStats[typeIndex][perfStatFieldNames[statFieldIndex]];
|
|
|
|
}
|
|
|
|
}
|
2017-05-10 20:23:54 +03:00
|
|
|
}
|
|
|
|
|
2013-08-26 19:27:28 +04:00
|
|
|
function requestAllNetworkingData() {
|
|
|
|
for (let id in gRequestNetworkingData)
|
|
|
|
requestNetworkingDataForTab(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function requestNetworkingDataForTab(id) {
|
|
|
|
gRequestNetworkingData[id](gDashboardCallbacks[id]);
|
2013-08-08 04:15:28 +04:00
|
|
|
}
|
|
|
|
|
2017-07-12 16:03:18 +03:00
|
|
|
let gInited = false;
|
2013-08-08 04:15:28 +04:00
|
|
|
function init() {
|
2017-07-12 16:03:18 +03:00
|
|
|
if (gInited) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gInited = true;
|
2013-08-08 04:15:28 +04:00
|
|
|
gDashboard.enableLogging = true;
|
2016-09-29 22:03:49 +03:00
|
|
|
if (Services.prefs.getBoolPref("network.warnOnAboutNetworking")) {
|
2013-08-08 04:15:28 +04:00
|
|
|
let div = document.getElementById("warning_message");
|
|
|
|
div.classList.add("active");
|
2014-03-27 01:35:04 +04:00
|
|
|
div.hidden = false;
|
2013-08-08 04:15:28 +04:00
|
|
|
document.getElementById("confpref").addEventListener("click", confirm);
|
|
|
|
}
|
|
|
|
|
2013-08-26 19:27:28 +04:00
|
|
|
requestAllNetworkingData();
|
2013-08-08 04:15:28 +04:00
|
|
|
|
2014-03-13 17:47:12 +04:00
|
|
|
let autoRefresh = document.getElementById("autorefcheck");
|
|
|
|
if (autoRefresh.checked)
|
|
|
|
setAutoRefreshInterval(autoRefresh);
|
2013-08-26 19:27:28 +04:00
|
|
|
|
2014-03-13 17:47:12 +04:00
|
|
|
autoRefresh.addEventListener("click", function() {
|
2013-08-08 04:15:28 +04:00
|
|
|
let refrButton = document.getElementById("refreshButton");
|
|
|
|
if (this.checked) {
|
2013-08-26 19:27:28 +04:00
|
|
|
setAutoRefreshInterval(this);
|
2013-08-08 04:15:28 +04:00
|
|
|
refrButton.disabled = "disabled";
|
|
|
|
} else {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
refrButton.disabled = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let refr = document.getElementById("refreshButton");
|
2013-08-26 19:27:28 +04:00
|
|
|
refr.addEventListener("click", requestAllNetworkingData);
|
2013-08-08 04:15:28 +04:00
|
|
|
if (document.getElementById("autorefcheck").checked)
|
|
|
|
refr.disabled = "disabled";
|
|
|
|
|
2014-03-27 01:35:04 +04:00
|
|
|
// Event delegation on #categories element
|
|
|
|
let menu = document.getElementById("categories");
|
2013-08-08 04:15:28 +04:00
|
|
|
menu.addEventListener("click", function click(e) {
|
2013-08-19 17:43:44 +04:00
|
|
|
if (e.target && e.target.parentNode == menu)
|
2013-08-08 04:15:28 +04:00
|
|
|
show(e.target);
|
|
|
|
});
|
2014-03-05 19:53:14 +04:00
|
|
|
|
|
|
|
let dnsLookupButton = document.getElementById("dnsLookupButton");
|
|
|
|
dnsLookupButton.addEventListener("click", function() {
|
|
|
|
doLookup();
|
|
|
|
});
|
2016-09-29 22:03:49 +03:00
|
|
|
|
|
|
|
let setLogButton = document.getElementById("set-log-file-button");
|
|
|
|
setLogButton.addEventListener("click", setLogFile);
|
|
|
|
|
|
|
|
let setModulesButton = document.getElementById("set-log-modules-button");
|
|
|
|
setModulesButton.addEventListener("click", setLogModules);
|
|
|
|
|
2016-10-06 18:18:36 +03:00
|
|
|
let startLoggingButton = document.getElementById("start-logging-button");
|
|
|
|
startLoggingButton.addEventListener("click", startLogging);
|
|
|
|
|
|
|
|
let stopLoggingButton = document.getElementById("stop-logging-button");
|
|
|
|
stopLoggingButton.addEventListener("click", stopLogging);
|
|
|
|
|
2016-09-29 22:03:49 +03:00
|
|
|
try {
|
2016-12-31 05:47:25 +03:00
|
|
|
let file = gDirServ.getFile("TmpD", {});
|
2016-09-29 22:03:49 +03:00
|
|
|
file.append("log.txt");
|
|
|
|
document.getElementById("log-file").value = file.path;
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the value of the log file.
|
|
|
|
updateLogFile();
|
|
|
|
|
|
|
|
// Update the active log modules
|
|
|
|
updateLogModules();
|
2016-10-06 18:18:36 +03:00
|
|
|
|
|
|
|
// If we can't set the file and the modules at runtime,
|
|
|
|
// the start and stop buttons wouldn't really do anything.
|
|
|
|
if (setLogButton.disabled && setModulesButton.disabled) {
|
|
|
|
startLoggingButton.disabled = true;
|
|
|
|
stopLoggingButton.disabled = true;
|
|
|
|
}
|
2017-07-06 15:17:57 +03:00
|
|
|
|
|
|
|
if (location.hash) {
|
|
|
|
let sectionButton = document.getElementById("category-" + location.hash.substring(1));
|
|
|
|
if (sectionButton) {
|
|
|
|
sectionButton.click();
|
|
|
|
}
|
|
|
|
}
|
2016-09-29 22:03:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateLogFile() {
|
|
|
|
let logPath = "";
|
|
|
|
|
|
|
|
// Try to get the environment variable for the log file
|
|
|
|
logPath = gEnv.get("MOZ_LOG_FILE") || gEnv.get("NSPR_LOG_FILE");
|
|
|
|
let currentLogFile = document.getElementById("current-log-file");
|
|
|
|
let setLogFileButton = document.getElementById("set-log-file-button");
|
|
|
|
|
|
|
|
// If the log file was set from an env var, we disable the ability to set it
|
|
|
|
// at runtime.
|
|
|
|
if (logPath.length > 0) {
|
|
|
|
currentLogFile.innerText = logPath;
|
|
|
|
setLogFileButton.disabled = true;
|
|
|
|
} else {
|
|
|
|
// There may be a value set by a pref.
|
|
|
|
currentLogFile.innerText = gDashboard.getLogPath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateLogModules() {
|
|
|
|
// Try to get the environment variable for the log file
|
|
|
|
let logModules = gEnv.get("MOZ_LOG") ||
|
|
|
|
gEnv.get("MOZ_LOG_MODULES") ||
|
|
|
|
gEnv.get("NSPR_LOG_MODULES");
|
|
|
|
let currentLogModules = document.getElementById("current-log-modules");
|
|
|
|
let setLogModulesButton = document.getElementById("set-log-modules-button");
|
|
|
|
if (logModules.length > 0) {
|
|
|
|
currentLogModules.innerText = logModules;
|
|
|
|
// If the log modules are set by an environment variable at startup, do not
|
|
|
|
// allow changing them throught a pref. It would be difficult to figure out
|
|
|
|
// which ones are enabled and which ones are not. The user probably knows
|
|
|
|
// what he they are doing.
|
|
|
|
setLogModulesButton.disabled = true;
|
|
|
|
} else {
|
|
|
|
let activeLogModules = [];
|
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("logging.config.add_timestamp")) {
|
|
|
|
activeLogModules.push("timestamp");
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("logging.config.sync")) {
|
|
|
|
activeLogModules.push("sync");
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
let children = Services.prefs.getBranch("logging.").getChildList("", {});
|
|
|
|
|
|
|
|
for (let pref of children) {
|
|
|
|
if (pref.startsWith("config.")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let value = Services.prefs.getIntPref(`logging.${pref}`);
|
|
|
|
activeLogModules.push(`${pref}:${value}`);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentLogModules.innerText = activeLogModules.join(",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setLogFile() {
|
2016-10-06 18:18:36 +03:00
|
|
|
let setLogButton = document.getElementById("set-log-file-button");
|
|
|
|
if (setLogButton.disabled) {
|
|
|
|
// There's no point trying since it wouldn't work anyway.
|
|
|
|
return;
|
|
|
|
}
|
2016-09-29 22:03:49 +03:00
|
|
|
let logFile = document.getElementById("log-file").value.trim();
|
|
|
|
Services.prefs.setCharPref("logging.config.LOG_FILE", logFile);
|
|
|
|
updateLogFile();
|
|
|
|
}
|
|
|
|
|
2016-10-06 18:18:36 +03:00
|
|
|
function clearLogModules() {
|
|
|
|
// Turn off all the modules.
|
|
|
|
let children = Services.prefs.getBranch("logging.").getChildList("", {});
|
|
|
|
for (let pref of children) {
|
|
|
|
if (!pref.startsWith("config.")) {
|
|
|
|
Services.prefs.clearUserPref(`logging.${pref}`);
|
2016-09-29 22:03:49 +03:00
|
|
|
}
|
2016-10-06 18:18:36 +03:00
|
|
|
}
|
|
|
|
Services.prefs.clearUserPref("logging.config.add_timestamp");
|
|
|
|
Services.prefs.clearUserPref("logging.config.sync");
|
|
|
|
updateLogModules();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setLogModules() {
|
|
|
|
let setLogModulesButton = document.getElementById("set-log-modules-button");
|
|
|
|
if (setLogModulesButton.disabled) {
|
|
|
|
// The modules were set via env var, so we shouldn't try to change them.
|
2016-09-29 22:03:49 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-06 18:18:36 +03:00
|
|
|
let modules = document.getElementById("log-modules").value.trim();
|
|
|
|
|
|
|
|
// Clear previously set log modules.
|
|
|
|
clearLogModules();
|
|
|
|
|
2016-09-29 22:03:49 +03:00
|
|
|
let logModules = modules.split(",");
|
|
|
|
for (let module of logModules) {
|
|
|
|
if (module == "timestamp") {
|
2016-10-06 18:18:36 +03:00
|
|
|
Services.prefs.setBoolPref("logging.config.add_timestamp", true);
|
2016-09-29 22:03:49 +03:00
|
|
|
} else if (module == "rotate") {
|
|
|
|
// XXX: rotate is not yet supported.
|
|
|
|
} else if (module == "append") {
|
|
|
|
// XXX: append is not yet supported.
|
|
|
|
} else if (module == "sync") {
|
2016-10-06 18:18:36 +03:00
|
|
|
Services.prefs.setBoolPref("logging.config.sync", true);
|
2016-09-29 22:03:49 +03:00
|
|
|
} else {
|
|
|
|
let [key, value] = module.split(":");
|
|
|
|
Services.prefs.setIntPref(`logging.${key}`, parseInt(value, 10));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateLogModules();
|
2013-08-08 04:15:28 +04:00
|
|
|
}
|
|
|
|
|
2016-10-06 18:18:36 +03:00
|
|
|
function startLogging() {
|
|
|
|
setLogFile();
|
|
|
|
setLogModules();
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopLogging() {
|
|
|
|
clearLogModules();
|
|
|
|
// clear the log file as well
|
|
|
|
Services.prefs.clearUserPref("logging.config.LOG_FILE");
|
|
|
|
updateLogFile();
|
|
|
|
}
|
|
|
|
|
2016-11-12 02:22:34 +03:00
|
|
|
function confirm() {
|
2013-08-08 04:15:28 +04:00
|
|
|
let div = document.getElementById("warning_message");
|
|
|
|
div.classList.remove("active");
|
2014-03-27 01:35:04 +04:00
|
|
|
div.hidden = true;
|
2013-08-08 04:15:28 +04:00
|
|
|
let warnBox = document.getElementById("warncheck");
|
2016-09-29 22:03:49 +03:00
|
|
|
Services.prefs.setBoolPref("network.warnOnAboutNetworking", warnBox.checked);
|
2013-08-08 04:15:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function show(button) {
|
|
|
|
let current_tab = document.querySelector(".active");
|
2017-07-06 15:17:57 +03:00
|
|
|
let category = button.getAttribute("id").substring("category-".length);
|
|
|
|
let content = document.getElementById(category);
|
2013-08-08 04:15:28 +04:00
|
|
|
if (current_tab == content)
|
|
|
|
return;
|
|
|
|
current_tab.classList.remove("active");
|
2014-03-27 01:35:04 +04:00
|
|
|
current_tab.hidden = true;
|
2013-08-08 04:15:28 +04:00
|
|
|
content.classList.add("active");
|
2014-03-27 01:35:04 +04:00
|
|
|
content.hidden = false;
|
2013-08-08 04:15:28 +04:00
|
|
|
|
2014-03-27 01:35:04 +04:00
|
|
|
let current_button = document.querySelector("[selected=true]");
|
|
|
|
current_button.removeAttribute("selected");
|
|
|
|
button.setAttribute("selected", "true");
|
2013-08-26 19:27:28 +04:00
|
|
|
|
|
|
|
let autoRefresh = document.getElementById("autorefcheck");
|
|
|
|
if (autoRefresh.checked) {
|
|
|
|
clearInterval(autoRefresh.interval);
|
|
|
|
setAutoRefreshInterval(autoRefresh);
|
|
|
|
}
|
2014-03-27 01:35:04 +04:00
|
|
|
|
|
|
|
let title = document.getElementById("sectionTitle");
|
|
|
|
title.textContent = button.children[0].textContent;
|
2017-07-06 15:17:57 +03:00
|
|
|
location.hash = category;
|
2013-08-26 19:27:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setAutoRefreshInterval(checkBox) {
|
|
|
|
let active_tab = document.querySelector(".active");
|
|
|
|
checkBox.interval = setInterval(function() {
|
|
|
|
requestNetworkingDataForTab(active_tab.id);
|
|
|
|
}, REFRESH_INTERVAL_MS);
|
2013-08-08 04:15:28 +04:00
|
|
|
}
|
|
|
|
|
2017-07-12 16:03:18 +03:00
|
|
|
// We use the pageshow event instead of onload. This is needed because sometimes
|
|
|
|
// the page is loaded via session-restore/bfcache. In such cases we need to call
|
|
|
|
// init() to keep the page behaviour consistent with the ticked checkboxes.
|
|
|
|
// Mostly the issue is with the autorefresh checkbox.
|
|
|
|
window.addEventListener("pageshow", function() {
|
2013-08-08 04:15:28 +04:00
|
|
|
init();
|
2017-07-12 16:03:18 +03:00
|
|
|
});
|
2014-03-05 19:53:14 +04:00
|
|
|
|
|
|
|
function doLookup() {
|
|
|
|
let host = document.getElementById("host").value;
|
|
|
|
if (host) {
|
|
|
|
gDashboard.requestDNSLookup(host, displayDNSLookup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayDNSLookup(data) {
|
|
|
|
let cont = document.getElementById("dnslookuptool_content");
|
|
|
|
let parent = cont.parentNode;
|
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "dnslookuptool_content");
|
|
|
|
|
|
|
|
if (data.answer) {
|
|
|
|
for (let address of data.address) {
|
|
|
|
let row = document.createElement("tr");
|
|
|
|
row.appendChild(col(address));
|
|
|
|
new_cont.appendChild(row);
|
|
|
|
}
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
2014-03-05 19:53:14 +04:00
|
|
|
new_cont.appendChild(col(data.error));
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.replaceChild(new_cont, cont);
|
|
|
|
}
|