summaryrefslogtreecommitdiffstats
path: root/src/web/gui/v2/registry-access.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:18 +0000
commit5da14042f70711ea5cf66e034699730335462f66 (patch)
tree0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/web/gui/v2/registry-access.html
parentReleasing debian version 1.44.3-2. (diff)
downloadnetdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz
netdata-5da14042f70711ea5cf66e034699730335462f66.zip
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/web/gui/v2/registry-access.html')
-rw-r--r--src/web/gui/v2/registry-access.html73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/web/gui/v2/registry-access.html b/src/web/gui/v2/registry-access.html
new file mode 100644
index 000000000..75a403034
--- /dev/null
+++ b/src/web/gui/v2/registry-access.html
@@ -0,0 +1,73 @@
+<!doctype html><html><head><title>Netdata Registry</title><meta name="application-name" content="netdata"/><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/><meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,minimum-scale=1"/><meta name="apple-mobile-web-app-capable" content="yes"/><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/></head><body><script>var getBasename = function() {
+ var pathRegex = /\/(v2\/)?registry-access.html?.*/
+ return window.location.origin + window.location.pathname.replace(pathRegex, "")
+ }
+
+ function doRegistryAccess(parentHelloData, originUrl) {
+ const helloPromise = !parentHelloData
+ ? fetch(originUrl + "/api/v1/registry?action=hello", { cache: "no-cache", credentials: "include" })
+ .then(function(response) { return response.json() })
+ : Promise.resolve(parentHelloData)
+
+ helloPromise.then(function(helloData) {
+ var retries = 3
+ var nodes = helloData.nodes || []
+
+ var doAccess = function(mg, nm, token) {
+ fetch(helloData.registry + '/api/v1/registry?action=access&machine=' + (mg || helloData.machine_guid) + '&name=' + encodeURIComponent(nm || helloData.hostname) + '&url=' + encodeURIComponent(originUrl) + '&agent=' + (helloData.agent ? helloData.agent.machine_guid : ""), { cache: "no-cache", credentials: "include", headers: { ["X-Netdata-Auth"]: 'Bearer ' + (token || localStorage.getItem("registry-netdata-token")) } })
+ .then(function(response) { return response.json() })
+ .then(function(data) {
+ var token = data.person_guid
+
+ if (data.status === "redirect" && retries > 0) {
+ retries = retries - 1
+ doAccess(helloData.machine_guid, helloData.hostname, token)
+ }
+
+ if (data.status === "ok") {
+ localStorage.setItem("registry-netdata-token", token)
+
+ let node = nodes.pop()
+
+ if (!!node) {
+ setTimeout(function () {
+ doAccess(node.machine_guid, node.hostname, token)
+ }, 1000)
+ }
+ }
+ window.parent.postMessage(data, "*");
+ })
+ }
+ doAccess(helloData.machine_guid, helloData.hostname)
+ }).catch(() => {})
+ }
+
+ try {
+ var searchParams = new URLSearchParams(location.search)
+ urlHelloData = searchParams.get("x")
+ var parentHelloData = JSON.parse(atob(urlHelloData))
+ doRegistryAccess(parentHelloData, searchParams.get("originUrl"))
+ } catch(e) {
+ // do nothing
+ }
+
+ function isValidHttpUrl(string) {
+ var url;
+
+ try {
+ return true
+ } catch (_) {
+ return false;
+ }
+ }
+
+ window.addEventListener('message', function(event) {
+ var isNetdataMessage = Array.isArray(event.data) ? event.data.length === 3 ? event.data[0] === "netdata-registry" : isValidHttpUrl(event.data[0]) : false
+
+ if (!isNetdataMessage) return
+
+ var originUrl = Array.isArray(event.data) ? event.data.length === 3 ? event.data[1] : event.data[0] : event.data
+ var parentHelloData = Array.isArray(event.data) ? event.data.length === 3 ? event.data[2] : event.data[1] : null
+
+ doRegistryAccess(parentHelloData, originUrl)
+ });</script></body></html> \ No newline at end of file