summaryrefslogtreecommitdiffstats
path: root/web/gui/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/gui/main.js')
-rw-r--r--web/gui/main.js100
1 files changed, 34 insertions, 66 deletions
diff --git a/web/gui/main.js b/web/gui/main.js
index 0635b07a7..5bf11e5f7 100644
--- a/web/gui/main.js
+++ b/web/gui/main.js
@@ -499,10 +499,26 @@ function toggleAgentItem(e, guid) {
// When you stream metrics from netdata to netdata, the recieving netdata now
// has multiple host databases. It's own, and multiple mirrored. Mirrored databases
// can be accessed with <http://localhost:19999/host/NAME/>
+const OLD_DASHBOARD_SUFFIX = "old"
+let isOldSuffix = true
+try {
+ const currentScriptMainJs = document.currentScript;
+ const mainJsSrc = currentScriptMainJs.getAttribute("src")
+ isOldSuffix = mainJsSrc.startsWith("../main.js")
+} catch {
+ console.warn("current script not detecting, assuming the dashboard is running with /old suffix")
+}
+
+function transformWithOldSuffix(url) {
+ return isOldSuffix ? `../${url}` : url
+}
+
function renderStreamedHosts(options) {
let html = `<div class="info-item">Databases streamed to this agent</div>`;
- var base = document.location.origin.toString() + document.location.pathname.toString();
+ var base = document.location.origin.toString() +
+ document.location.pathname.toString()
+ .replace(isOldSuffix ? `/${OLD_DASHBOARD_SUFFIX}` : "", "");
if (base.endsWith("/host/" + options.hostname + "/")) {
base = base.substring(0, base.length - ("/host/" + options.hostname + "/").toString().length);
}
@@ -536,10 +552,10 @@ function renderStreamedHosts(options) {
displayedDatabases = true;
if (hostname === master) {
- url = `${base}/`;
+ url = isOldSuffix ? `${base}/${OLD_DASHBOARD_SUFFIX}/` : `${base}/`;
icon = 'home';
} else {
- url = `${base}/host/${hostname}/`;
+ url = isOldSuffix ? `${base}/host/${hostname}/${OLD_DASHBOARD_SUFFIX}/` : `${base}/host/${hostname}/`;
icon = 'window-restore';
}
@@ -707,10 +723,9 @@ function clearMyNetdataMenu() {
}
function errorMyNetdataMenu() {
- setMyNetdataMenu(`<div class="agent-item" style="white-space: nowrap">
+ setMyNetdataMenu(`<div class="agent-item" style="padding: 0 8px">
<i class="fas fa-exclamation-triangle" style="color: red"></i>
- Cannot load known netdata agents from netdata.cloud!
- <div></div>
+ Cannot load known Netdata agents from Netdata Cloud! Please make sure you have the latest version of Netdata.
</div>`);
}
@@ -791,11 +806,6 @@ function renderMyNetdataMenu(machinesArray) {
if (!isSignedIn()) {
html += (
`<div class="agent-item">
- <i class="fas fa-tv"></i>
- <a onClick="openAuthenticatedUrl('console.html');" target="_blank">Nodes<sup class="beta"> beta</sup></a>
- <div></div>
- </div>
- <div class="agent-item">
<i class="fas fa-cog""></i>
<a href="#" onclick="switchRegistryModalHandler(); return false;">Switch Identity</a>
<div></div>
@@ -965,7 +975,7 @@ function gotoServerModalHandler(guid) {
if (!isSignedIn()) {
// When the registry is enabled, if the user's known URLs are not working
- // we consult the registry to get additional URLs.
+ // we consult the registry to get additional URLs.
setTimeout(function () {
if (gotoServerStop === false) {
document.getElementById('gotoServerResponse').innerHTML = '<b>Added all the known URLs for this machine.</b>';
@@ -1805,8 +1815,8 @@ function renderPage(menus, data) {
const isMemoryModeDbEngine = data.memory_mode === "dbengine";
- sidebar += '<li class="" style="padding-top:15px;"><a href="https://github.com/netdata/netdata/blob/master/docs/Add-more-charts-to-netdata.md#add-more-charts-to-netdata" target="_blank"><i class="fas fa-plus"></i> add more charts</a></li>';
- sidebar += '<li class=""><a href="https://github.com/netdata/netdata/tree/master/health#Health-monitoring" target="_blank"><i class="fas fa-plus"></i> add more alarms</a></li>';
+ sidebar += '<li class="" style="padding-top:15px;"><a href="https://docs.netdata.cloud/collectors/quickstart/" target="_blank"><i class="fas fa-plus"></i> Add more charts</a></li>';
+ sidebar += '<li class=""><a href="https://docs.netdata.cloud/health/quickstart/" target="_blank"><i class="fas fa-plus"></i> Add more alarms</a></li>';
sidebar += '<li class="" style="margin:20px;color:#666;"><small>Every ' +
((data.update_every === 1) ? 'second' : data.update_every.toString() + ' seconds') + ', ' +
'Netdata collects <strong>' + data.dimensions_count.toLocaleString() + '</strong> metrics on ' +
@@ -1818,7 +1828,7 @@ function renderPage(menus, data) {
if (!isMemoryModeDbEngine) {
sidebar += '<br />&nbsp;<br />Get more history by ' +
- '<a href="https://docs.netdata.cloud/docs/configuration-guide/#increase-the-metrics-retention-period" target=_blank>configuring Netdata\'s <strong>history</strong></a> or using the <a href="https://docs.netdata.cloud/database/engine/" target=_blank>DB engine.</a>'
+ '<a href="https://docs.netdata.cloud/docs/configuration-guide/#increase-the-metrics-retention-period" target=_blank>configuring Netdata\'s <strong>history</strong></a> or using the <a href="https://docs.netdata.cloud/database/engine/" target=_blank>DB engine.</a>';
}
sidebar += '<br/>&nbsp;<br/><strong>netdata</strong><br/>' + data.version.toString() + '</small></li>';
@@ -1933,7 +1943,7 @@ function renderChartsAndMenu(data) {
function loadJs(url, callback) {
$.ajax({
- url: url,
+ url: url.startsWith("http") ? url : transformWithOldSuffix(url),
cache: true,
dataType: "script",
xhrFields: { withCredentials: true } // required for the cookie
@@ -1980,7 +1990,7 @@ function loadBootstrapSlider(callback) {
if (bootstrapSliderLoaded === false) {
bootstrapSliderLoaded = true;
loadJs('lib/bootstrap-slider-10.0.0.min.js', function () {
- NETDATA._loadCSS('css/bootstrap-slider-10.0.0.min.css');
+ NETDATA._loadCSS(transformWithOldSuffix("css/bootstrap-slider-10.0.0.min.css"));
callback();
});
} else {
@@ -4806,11 +4816,7 @@ function signInDidClick(e) {
}
function shouldShowSignInBanner() {
- if (isSignedIn()) {
- return false;
- }
-
- return localStorage.getItem("signInBannerClosed") != "true";
+ return false;
}
function closeSignInBanner() {
@@ -4894,43 +4900,6 @@ function signOut() {
cloudSSOSignOut();
}
-function renderAccountUI() {
- if (!NETDATA.registry.isCloudEnabled) {
- return
- }
-
- const container = document.getElementById("account-menu-container");
- if (isSignedIn()) {
- container.removeAttribute("title");
- container.removeAttribute("data-original-title");
- container.removeAttribute("data-placement");
- container.innerHTML = (
- `<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span id="amc-account-name"></span> <strong class="caret"></strong></a>
- <ul id="cloud-menu" class="dropdown-menu scrollable-menu inpagemenu" role="menu">
- <li>
- <a onclick="openAuthenticatedUrl('console.html');" target="_blank" class="btn">
- <i class="fas fa-tv"></i>&nbsp;&nbsp;<span class="hidden-sm hidden-md">Nodes<sup class="beta"> beta</sup></span>
- </a>
- </li>
- <li>
- <a href="#" class="btn" onclick="signOutDidClick(event); return false">
- <i class="fas fa-sign-out-alt"></i>&nbsp;&nbsp;<span class="hidden-sm hidden-md">Sign Out</span>
- </a>
- </li>
- </ul>`
- )
- document.getElementById("amc-account-name").textContent = cloudAccountName; // Anti-XSS
- } else {
- container.setAttribute("data-original-title", "sign in");
- container.setAttribute("data-placement", "bottom");
- container.innerHTML = (
- `<a href="#" class="btn sign-in-btn theme-${netdataTheme}" onclick="signInDidClick(event); return false">
- <i class="fas fa-sign-in-alt"></i>&nbsp;<span class="hidden-sm hidden-md">Sign In</span>
- </a>`
- )
- }
-}
-
function handleMessage(e) {
switch (e.data.type) {
case "sign-in":
@@ -4956,13 +4925,13 @@ function handleSignInMessage(e) {
netdataRegistryCallback(registryAgents);
if (e.data.redirectURI && !window.location.href.includes(e.data.redirectURI)) {
- window.location.replace(e.data.redirectURI);
+ // lgtm false-positive - redirectURI does not come from user input, but from iframe callback
+ window.location.replace(e.data.redirectURI); // lgtm[js/client-side-unvalidated-url-redirection]
}
}
function handleSignOutMessage(e) {
clearCloudVariables();
- renderAccountUI();
renderMyNetdataMenu(registryAgents);
}
@@ -5116,7 +5085,6 @@ function initCloud() {
}
touchAgent();
- renderAccountUI();
}
// This callback is called after NETDATA.registry is initialized.
@@ -5128,7 +5096,7 @@ function netdataRegistryCallback(machinesArray) {
registryAgents = machinesArray;
if (isSignedIn()) {
- // We call getCloudAccountAgents() here because it requires that
+ // We call getCloudAccountAgents() here because it requires that
// NETDATA.registry is initialized.
clearMyNetdataMenu();
getCloudAccountAgents().then((agents) => {
@@ -5154,8 +5122,8 @@ function netdataRegistryCallback(machinesArray) {
}
};
-// If we know the cloudBaseURL and agentID from local storage render (eagerly)
-// the account ui before receiving the definitive response from the web server.
+// If we know the cloudBaseURL and agentID from local storage render (eagerly)
+// the account ui before receiving the definitive response from the web server.
// This improves the perceived performance.
function tryFastInitCloud() {
const baseURL = localStorage.getItem("cloud.baseURL");
@@ -5183,5 +5151,5 @@ if (document.readyState === "complete") {
if (document.readyState === "complete") {
initializeApp();
}
- })
+ });
}