Skip to content

Instantly share code, notes, and snippets.

@mdunham
Created March 10, 2018 15:54
Show Gist options
  • Save mdunham/f8f88629879e536a86e5ac8f4747d1ee to your computer and use it in GitHub Desktop.
Save mdunham/f8f88629879e536a86e5ac8f4747d1ee to your computer and use it in GitHub Desktop.
Quick 200/404/500 http status checker for WHM
var urlList = [], xmlhttp = [null, null];
[].map.call(document.querySelectorAll('#listaccts tr'), function(e){
var
domain = e.querySelector(':scope a[title^="Browse to the"]'),
username = e.querySelector(':scope > td:nth-child(5)'),
account = [];
if (username) account.push(username.innerText);
if (domain) account.push(domain.getAttribute('href'));
urlList.push(account);
});
console.log(urlList);
loadUrl(urlList.pop());
function loadUrl(account) {
delete xmlhttp[1];
delete xmlhttp[0];
xmlhttp[0] = new XMLHttpRequest()
xmlhttp[1] = new XMLHttpRequest();
var url0 = account.domain, url1 = 'http://162.214.2.64/~' + account.username;
xmlhttp[0].onreadystatechange = function() {
var status = (xmlhttp[0].readyState === XMLHttpRequest.DONE) ? xmlhttp[0].status : '...';
console.log('%c ' + xmlhttp.readyState + ' - ' + status + ' - ' + url0 + ' - ', 'color: ' + (status == 200) ? 'green' : (status == 500 || status == 404) ? 'red' : '#333' );
};
xmlhttp[1].onreadystatechange = function() {
var status = (xmlhttp[1].readyState === XMLHttpRequest.DONE) ? xmlhttp[1].status : '...';
console.log('%c ' + xmlhttp.readyState + ' - ' + status + ' - ' + url1 + ' - ', 'color: ' + (status == 200) ? 'green' : (status == 500 || status == 404) ? 'red' : '#333' );
};
console.log('Loading URLs - ', account);
xmlhttp[0].open("GET", account[0], true);
xmlhttp[0].send();
xmlhttp[1].open("GET", account[1], true);
xmlhttp[1].send();
setTimeout(function(){
if (xmlhttp[0].readyState !== 4 || xmlhttp[1].readyState !== 4) {
console.log('%c Timeout reached! - D: ' + xmlhttp[0].readyState + ' U: ' + xmlhttp[1].readyState, 'color: red')
}
if (urlList.length) loadUrl(urlList.pop());
}, 1234);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment