Last active
February 25, 2022 03:53
-
-
Save marcusschiesser/905b1daeb32a1c56e9d7e8b4bedc5015 to your computer and use it in GitHub Desktop.
Custom Login Page in Splunk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<form method="post" id="loginForm"> | |
<div> | |
<input type="text" name="username" placeholder="Username" /> | |
</div> | |
<div> | |
<input type="password" name="password" placeholder="Password" /> | |
</div> | |
<div> | |
<input type="hidden" name="cval" /> | |
</div> | |
<input type="submit" value="Sign In" /> | |
</form> | |
<script> | |
const APP_NAME = 'search'; | |
var form = document.getElementById('loginForm'); | |
form.elements.cval.value = new URLSearchParams(window.location.search).get("cval"); | |
var paths = window.location.pathname.split('/'); | |
var locale = paths.length > 1 ? paths[1] : "en-US"; | |
form.addEventListener("submit", function (e) { | |
e.preventDefault(); | |
var form_data = `username=${encodeURIComponent(form.elements.username.value)}&password=${encodeURIComponent(form.elements.password.value)}&cval=${encodeURIComponent(form.elements.cval.value)}`; | |
fetch(`/${locale}/account/login`, { | |
method: "POST", | |
body: form_data, | |
}).then(function (response) { | |
if (response.status === 200) { | |
window.location.replace( | |
`/${locale}/app/${APP_NAME}` | |
); | |
} else if (response.status === 401) { | |
console.log('Incorrect login - check username and password'); | |
} else { | |
throw new Error( | |
"Unhandled status code: " + | |
response.status | |
); | |
} | |
}).catch(function (error) { | |
console.error(error); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This static login page can be used to customize the login experience for Splunk (Tested with Enterprise 8.2.3).
To activate it, you have to copy this file to
$SPLUNK_HOME/share/splunk/search_mrsparkle/exposed/login.html
(it will be served by Splunk Web as a static file) and add the following entry to thesettings
stanza in theweb.conf
:This JS snippet automatically redirects every login attempt to this static HTML page and injects the necessary
cval
value for authentication.