Skip to content

Instantly share code, notes, and snippets.

@marcusschiesser
Last active February 25, 2022 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusschiesser/905b1daeb32a1c56e9d7e8b4bedc5015 to your computer and use it in GitHub Desktop.
Save marcusschiesser/905b1daeb32a1c56e9d7e8b4bedc5015 to your computer and use it in GitHub Desktop.
Custom Login Page in Splunk
<!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>
@marcusschiesser
Copy link
Author

marcusschiesser commented Feb 23, 2022

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 the settings stanza in the web.conf:

login_content = <script>window.location.replace('/static/login.html?cval='+__splunkd_partials__['/services/session'].entry[0].content.cval)</script>

This JS snippet automatically redirects every login attempt to this static HTML page and injects the necessary cval value for authentication.

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