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/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2018-01-30 08:17:48 +03:00
|
|
|
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
|
|
|
|
);
|
|
|
|
const gDashboard = Cc["@mozilla.org/network/dashboard;1"].getService(
|
|
|
|
Ci.nsIDashboard
|
|
|
|
);
|
|
|
|
const gDirServ = Cc["@mozilla.org/file/directory_service;1"].getService(
|
|
|
|
Ci.nsIDirectoryServiceProvider
|
|
|
|
);
|
2020-01-07 15:35:17 +03:00
|
|
|
const gNetLinkSvc =
|
|
|
|
Cc["@mozilla.org/network/network-link-service;1"] &&
|
|
|
|
Cc["@mozilla.org/network/network-link-service;1"].getService(
|
|
|
|
Ci.nsINetworkLinkService
|
|
|
|
);
|
2020-09-18 16:04:13 +03:00
|
|
|
const gDNSService = Cc["@mozilla.org/network/dns-service;1"].getService(
|
|
|
|
Ci.nsIDNSService
|
|
|
|
);
|
2016-09-29 22:03:49 +03:00
|
|
|
|
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,
|
2019-08-01 19:06:32 +03:00
|
|
|
networkid: displayNetworkID,
|
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) {
|
|
|
|
let col = document.createElement("td");
|
|
|
|
let content = document.createTextNode(element);
|
|
|
|
col.appendChild(content);
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayHttp(data) {
|
|
|
|
let cont = document.getElementById("http_content");
|
|
|
|
let parent = cont.parentNode;
|
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "http_content");
|
|
|
|
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let i = 0; i < data.connections.length; i++) {
|
2013-08-08 04:15:28 +04: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));
|
2019-11-12 11:27:38 +03:00
|
|
|
row.appendChild(col(data.connections[i].httpVersion));
|
2013-11-20 18:29:01 +04:00
|
|
|
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) {
|
|
|
|
let cont = document.getElementById("sockets_content");
|
|
|
|
let parent = cont.parentNode;
|
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "sockets_content");
|
|
|
|
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let i = 0; i < data.sockets.length; i++) {
|
2013-08-08 04:15:28 +04: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) {
|
2019-10-17 19:15:24 +03:00
|
|
|
let suffixContent = document.getElementById("dns_suffix_content");
|
|
|
|
let suffixParent = suffixContent.parentNode;
|
|
|
|
let suffixes = [];
|
|
|
|
try {
|
|
|
|
suffixes = gNetLinkSvc.dnsSuffixList; // May throw
|
|
|
|
} catch (e) {}
|
|
|
|
let suffix_tbody = document.createElement("tbody");
|
|
|
|
suffix_tbody.id = "dns_suffix_content";
|
|
|
|
for (let suffix of suffixes) {
|
|
|
|
let row = document.createElement("tr");
|
|
|
|
row.appendChild(col(suffix));
|
|
|
|
suffix_tbody.appendChild(row);
|
|
|
|
}
|
|
|
|
suffixParent.replaceChild(suffix_tbody, suffixContent);
|
|
|
|
|
2020-09-18 16:04:13 +03:00
|
|
|
let trr_url_tbody = document.createElement("tbody");
|
|
|
|
trr_url_tbody.id = "dns_trr_url";
|
|
|
|
let trr_url = document.createElement("tr");
|
|
|
|
trr_url.appendChild(col(gDNSService.currentTrrURI));
|
|
|
|
trr_url_tbody.appendChild(trr_url);
|
|
|
|
let prevURL = document.getElementById("dns_trr_url");
|
|
|
|
prevURL.parentNode.replaceChild(trr_url_tbody, prevURL);
|
|
|
|
|
2013-08-08 04:15:28 +04:00
|
|
|
let cont = document.getElementById("dns_content");
|
|
|
|
let parent = cont.parentNode;
|
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "dns_content");
|
|
|
|
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let i = 0; i < data.entries.length; i++) {
|
2013-08-08 04:15:28 +04: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));
|
2018-02-22 11:57:22 +03:00
|
|
|
row.appendChild(col(data.entries[i].trr));
|
2013-08-08 04:15:28 +04:00
|
|
|
let column = document.createElement("td");
|
|
|
|
|
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]));
|
2013-08-08 04:15:28 +04:00
|
|
|
column.appendChild(document.createElement("br"));
|
|
|
|
}
|
|
|
|
|
|
|
|
row.appendChild(column);
|
2013-11-20 18:29:01 +04:00
|
|
|
row.appendChild(col(data.entries[i].expiration));
|
2020-05-20 19:46:26 +03:00
|
|
|
row.appendChild(col(data.entries[i].originAttributesSuffix));
|
2013-08-08 04:15:28 +04:00
|
|
|
new_cont.appendChild(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.replaceChild(new_cont, cont);
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayWebsockets(data) {
|
|
|
|
let cont = document.getElementById("websockets_content");
|
|
|
|
let parent = cont.parentNode;
|
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "websockets_content");
|
|
|
|
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let i = 0; i < data.websockets.length; i++) {
|
2013-08-08 04:15:28 +04: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");
|
2020-01-07 14:15:15 +03:00
|
|
|
let linkType = Ci.nsINetworkLinkService.LINK_TYPE_UNKNOWN;
|
|
|
|
try {
|
|
|
|
linkType = gNetLinkSvc.linkType;
|
|
|
|
} catch (e) {}
|
2018-05-27 03:59:00 +03:00
|
|
|
if (
|
|
|
|
!(
|
|
|
|
linkType == Ci.nsINetworkLinkService.LINK_TYPE_UNKNOWN ||
|
|
|
|
linkType == Ci.nsINetworkLinkService.LINK_TYPE_ETHERNET ||
|
|
|
|
linkType == Ci.nsINetworkLinkService.LINK_TYPE_USB ||
|
|
|
|
linkType == Ci.nsINetworkLinkService.LINK_TYPE_WIFI
|
2019-07-05 12:14:49 +03:00
|
|
|
)
|
2018-05-27 03:59:00 +03:00
|
|
|
) {
|
|
|
|
status = false;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:23:54 +03:00
|
|
|
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"];
|
2019-07-05 12:14:49 +03:00
|
|
|
|
2017-07-05 02:41:00 +03:00
|
|
|
const perfStatFieldNames = ["avgShort", "avgLong", "stddevLong"];
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-08-01 19:06:32 +03:00
|
|
|
function displayNetworkID() {
|
2020-01-07 14:15:15 +03:00
|
|
|
try {
|
|
|
|
let linkIsUp = gNetLinkSvc.isLinkUp;
|
|
|
|
let linkStatusKnown = gNetLinkSvc.linkStatusKnown;
|
|
|
|
let networkID = gNetLinkSvc.networkID;
|
|
|
|
|
|
|
|
document.getElementById("networkid_isUp").innerText = linkIsUp;
|
2020-01-07 15:35:17 +03:00
|
|
|
document.getElementById(
|
|
|
|
"networkid_statusKnown"
|
|
|
|
).innerText = linkStatusKnown;
|
2020-01-07 14:15:15 +03:00
|
|
|
document.getElementById("networkid_id").innerText = networkID;
|
|
|
|
} catch (e) {
|
|
|
|
document.getElementById("networkid_isUp").innerText = "<unknown>";
|
|
|
|
document.getElementById("networkid_statusKnown").innerText = "<unknown>";
|
|
|
|
document.getElementById("networkid_id").innerText = "<unknown>";
|
|
|
|
}
|
2019-08-01 19:06:32 +03:00
|
|
|
}
|
|
|
|
|
2013-08-26 19:27:28 +04:00
|
|
|
function requestAllNetworkingData() {
|
|
|
|
for (let id in gRequestNetworkingData) {
|
|
|
|
requestNetworkingDataForTab(id);
|
2019-07-05 12:14:49 +03:00
|
|
|
}
|
2013-08-26 19:27:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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);
|
2019-07-05 12:14:49 +03:00
|
|
|
}
|
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";
|
2019-07-05 12:14:49 +03:00
|
|
|
}
|
2013-08-08 04:15:28 +04:00
|
|
|
|
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);
|
2019-07-05 12:14:49 +03:00
|
|
|
}
|
2013-08-08 04:15:28 +04:00
|
|
|
});
|
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
|
|
|
|
2020-06-09 16:57:52 +03:00
|
|
|
let clearDNSCache = document.getElementById("clearDNSCache");
|
|
|
|
clearDNSCache.addEventListener("click", function() {
|
2020-09-18 16:04:13 +03:00
|
|
|
gDNSService.clearCache(true);
|
2020-06-09 16:57:52 +03:00
|
|
|
});
|
|
|
|
|
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.
|
2019-09-14 12:39:26 +03:00
|
|
|
if (logPath.length) {
|
2016-09-29 22:03:49 +03:00
|
|
|
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");
|
2019-09-14 12:39:26 +03:00
|
|
|
if (logModules.length) {
|
2016-09-29 22:03:49 +03:00
|
|
|
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) {}
|
|
|
|
|
2019-05-21 09:20:40 +03:00
|
|
|
let children = Services.prefs.getBranch("logging.").getChildList("");
|
2016-09-29 22:03:49 +03:00
|
|
|
|
|
|
|
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.
|
2019-05-21 09:20:40 +03:00
|
|
|
let children = Services.prefs.getBranch("logging.").getChildList("");
|
2016-10-06 18:18:36 +03:00
|
|
|
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 {
|
2020-05-09 14:24:33 +03:00
|
|
|
let lastColon = module.lastIndexOf(":");
|
|
|
|
let key = module.slice(0, lastColon);
|
|
|
|
let value = parseInt(module.slice(lastColon + 1), 10);
|
|
|
|
Services.prefs.setIntPref(`logging.${key}`, value);
|
2016-09-29 22:03:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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;
|
2019-07-05 12:14:49 +03:00
|
|
|
}
|
2013-08-08 04:15:28 +04:00
|
|
|
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) {
|
2020-10-21 03:52:46 +03:00
|
|
|
try {
|
|
|
|
gDashboard.requestDNSLookup(host, displayDNSLookup);
|
|
|
|
} catch (e) {}
|
|
|
|
try {
|
|
|
|
gDashboard.requestDNSHTTPSRRLookup(host, displayHTTPSRRLookup);
|
|
|
|
} catch (e) {}
|
2014-03-05 19:53:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2020-10-21 03:52:46 +03:00
|
|
|
|
|
|
|
function displayHTTPSRRLookup(data) {
|
|
|
|
let cont = document.getElementById("https_rr_content");
|
|
|
|
let parent = cont.parentNode;
|
|
|
|
let new_cont = document.createElement("tbody");
|
|
|
|
new_cont.setAttribute("id", "https_rr_content");
|
|
|
|
|
|
|
|
if (data.answer) {
|
|
|
|
for (let record of data.records) {
|
|
|
|
let row = document.createElement("tr");
|
|
|
|
let alpn = record.alpn ? `alpn="${record.alpn.alpn}" ` : "";
|
|
|
|
let noDefaultAlpn = record.noDefaultAlpn ? "noDefaultAlpn " : "";
|
|
|
|
let port = record.port ? `port="${record.port.port}" ` : "";
|
2020-11-17 13:38:07 +03:00
|
|
|
let echConfig = record.echConfig
|
|
|
|
? `echConfig="${record.echConfig.echConfig}" `
|
2020-10-21 03:52:46 +03:00
|
|
|
: "";
|
2021-01-22 15:59:24 +03:00
|
|
|
let ODoHConfig = record.ODoHConfig
|
|
|
|
? `ODoHConfig="${record.ODoHConfig.ODoHConfig}" `
|
|
|
|
: "";
|
2020-10-21 03:52:46 +03:00
|
|
|
let ipv4hint = "";
|
|
|
|
let ipv6hint = "";
|
|
|
|
if (record.ipv4Hint) {
|
|
|
|
let ipv4Str = "";
|
|
|
|
for (let addr of record.ipv4Hint.address) {
|
|
|
|
ipv4Str += `${addr}, `;
|
|
|
|
}
|
|
|
|
// Remove ", " at the end.
|
|
|
|
ipv4Str = ipv4Str.slice(0, -2);
|
|
|
|
ipv4hint = `ipv4hint="${ipv4Str}" `;
|
|
|
|
}
|
|
|
|
if (record.ipv6Hint) {
|
|
|
|
let ipv6Str = "";
|
|
|
|
for (let addr of record.ipv6Hint.address) {
|
|
|
|
ipv6Str += `${addr}, `;
|
|
|
|
}
|
|
|
|
// Remove ", " at the end.
|
|
|
|
ipv6Str = ipv6Str.slice(0, -2);
|
|
|
|
ipv6hint = `ipv6hint="${ipv6Str}" `;
|
|
|
|
}
|
|
|
|
|
2020-11-17 13:38:07 +03:00
|
|
|
let str = `${record.priority} ${record.targetName} `;
|
2020-10-21 03:52:46 +03:00
|
|
|
str += `(${alpn}${noDefaultAlpn}${port}`;
|
2021-01-22 15:59:24 +03:00
|
|
|
str += `${ipv4hint}${echConfig}${ipv6hint}`;
|
|
|
|
str += `${ODoHConfig})`;
|
2020-10-21 03:52:46 +03:00
|
|
|
row.appendChild(col(str));
|
|
|
|
new_cont.appendChild(row);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
new_cont.appendChild(col(data.error));
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.replaceChild(new_cont, cont);
|
|
|
|
}
|