Last active
September 26, 2016 15:56
-
-
Save LukeMurphey/9af92aafb5c5caba04982f4ebaa9fed7 to your computer and use it in GitHub Desktop.
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
| // ==UserScript== | |
| // @name Splunk AutoLogin | |
| // @namespace http://127.0.0.1:8000/en-US/account/login* | |
| // @description Automatically logs into Splunk | |
| // @include http://127.0.0.1:8000/en-US/account/login* | |
| // @include https://127.0.0.1:8000/en-US/account/login* | |
| // @include */en-US/account/login* | |
| // ==/UserScript== | |
| function splunkLogin(){ | |
| // Stop if the login page is not active | |
| if(document.hidden){ | |
| setTimeout(splunkLogin, 1000); | |
| return; | |
| } | |
| if ( document.getElementById('tplerror') != null && document.getElementById('tplerror').innerHTML == "Invalid username or password."){ | |
| return; | |
| } | |
| if( document.getElementsByClassName("spl-pwd-reset-description").length > 0 ){ | |
| return; | |
| } | |
| var login = false; | |
| if( $('body').modal != undefined ){ | |
| d = '<div id="loginModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' + | |
| '<div class="modal-header">' + | |
| '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' + | |
| '<h3 id="myModalLabel">Automatic Login</h3>' + | |
| '</div>' + | |
| '<div class="modal-body">' + | |
| '<p>Would you like to login automatically with the default admin account?</p>' + | |
| '</div>' + | |
| '<div class="modal-footer">' + | |
| '<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>' + | |
| '<button id="login" class="btn btn-primary">Login</button>' + | |
| '</div>' + | |
| '</div>'; | |
| $('body').append(d); | |
| $('#loginModal').modal(); | |
| } | |
| else{ | |
| login = confirm("Would you like to login automatically with the default admin account?"); | |
| } | |
| if( login ) { | |
| if( false && typeof $ !== 'undefined'){ | |
| // For Splunk 6 | |
| var username = [97, 100, 109, 105, 110]; | |
| var password = [99, 104, 97, 110, 103, 109, 101]; | |
| // Enter username | |
| for( var c = 0; c < username.length; c++){ | |
| var e = $.Event("keydown", { keyCode: username[c]}); | |
| $('#username').trigger(e); | |
| } | |
| // Enter password | |
| for( c = 0; c < password.length; c++){ | |
| var e = $.Event("keydown", { keyCode: password[c]}); | |
| $('#password').trigger(e); | |
| } | |
| } | |
| else{ | |
| // For Splunk 5 | |
| for( var c=0; c < document.forms[0].elements.length; c++){ | |
| if( document.forms[0].elements[c].name == "username"){ | |
| document.forms[0].elements[c].value = "admin"; | |
| } | |
| else if( document.forms[0].elements[c].name == "password"){ | |
| document.forms[0].elements[c].value = "changeme"; | |
| } | |
| } | |
| $('.loginForm').trigger('submit'); | |
| document.forms[0].submit(); | |
| } | |
| } | |
| } | |
| // Determines if the view is hidden or not. | |
| (function() { | |
| var hidden = "hidden"; | |
| // Standards: | |
| if (hidden in document) | |
| document.addEventListener("visibilitychange", onchange); | |
| else if ((hidden = "mozHidden") in document) | |
| document.addEventListener("mozvisibilitychange", onchange); | |
| else if ((hidden = "webkitHidden") in document) | |
| document.addEventListener("webkitvisibilitychange", onchange); | |
| else if ((hidden = "msHidden") in document) | |
| document.addEventListener("msvisibilitychange", onchange); | |
| // IE 9 and lower: | |
| else if ("onfocusin" in document) | |
| document.onfocusin = document.onfocusout = onchange; | |
| // All others: | |
| else | |
| window.onpageshow = window.onpagehide = window.onfocus = window.onblur = onchange; | |
| function onchange (evt) { | |
| var v = "visible", h = "hidden", | |
| evtMap = { | |
| focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h | |
| }; | |
| evt = evt || window.event; | |
| if (evt.type in evtMap) | |
| document.body.className = evtMap[evt.type]; | |
| else | |
| document.body.className = this[hidden] ? "hidden" : "visible"; | |
| } | |
| // set the initial state (but only if browser supports the Page Visibility API) | |
| if( document[hidden] !== undefined ) | |
| onchange({type: document[hidden] ? "blur" : "focus"}); | |
| })(); | |
| //Give the page a second to load | |
| setTimeout(splunkLogin, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment