Skip to content

Instantly share code, notes, and snippets.

@cwest-consultch
Last active March 2, 2021 13:21
Show Gist options
  • Save cwest-consultch/e798e0477fc932c1636bfab62e003b4d to your computer and use it in GitHub Desktop.
Save cwest-consultch/e798e0477fc932c1636bfab62e003b4d to your computer and use it in GitHub Desktop.
(function() {
const IS_LEGACY = +grafanaBootData.settings.buildInfo.version.split('.')[0] <= 6;
const user = prompt('Enter the username:', get(window, 'grafanaBootData.user.login', ''));
const pass = prompt(`Enter the password for "${user}":`);
const redirect = location.pathname + location.search;
const t = IS_LEGACY
? {
user,
pass,
logout: /^YES$/i.test(prompt('If a previous user is logged in, should he be logged out? (Yes/No)', 'Yes')),
redirect
}
: { u: user, p: pass, r: redirect };
const url = `${location.origin}/public/views/auto-login.html?t=${btoa(JSON.stringify(t))}`;
document.body.innerHTML = `
Here is the AutoLogin URL:<br />
<a href="${url}" target="_blank">${url}</a><br />
<br />
<button onclick="location.reload()" type="button" class="btn btn-primary">Go Back To AIR</button>
`;
document.body.style.cssText = 'font-family:monospace;white-space:pre-wrap;word-wrap:break-word;padding:1em;';
function get(root, path, opt_default) {
let result = path.split('.').reduce(function(result, key) {
return result == undefined ? result : result[key]
}, root);
return result === undefined ? opt_default : result;
}
})();
@cwest-consultch
Copy link
Author

Here is the YourJS Bookmarklet Creator that can be used to turn this into a bookmarklet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment