121 lines
3.6 KiB
JavaScript
121 lines
3.6 KiB
JavaScript
#include utility.js
|
|
#include xhr.js
|
|
#include elems/sidelist.jsx
|
|
|
|
const MakaiWHOIS = () => {
|
|
let locked = false;
|
|
const input = $q('.js-whois-input');
|
|
const submit = $q('.js-whois-submit');
|
|
const result = $q('.js-whois-body');
|
|
const tabs = $q('.js-whois-tabs');
|
|
|
|
const historic = [];
|
|
const history = (() => {
|
|
const element = $q('.js-whois-sidelist');
|
|
if(element instanceof Element)
|
|
return new MakaiSideListElement(element);
|
|
})();
|
|
|
|
const lock = () => {
|
|
if(locked)
|
|
return false;
|
|
|
|
document.body.classList.add('whois-locked');
|
|
input.disabled = true;
|
|
locked = true;
|
|
return true;
|
|
}
|
|
|
|
const unlock = () => {
|
|
if(!locked)
|
|
return false;
|
|
|
|
document.body.classList.remove('whois-locked');
|
|
input.disabled = false;
|
|
locked = false;
|
|
return true;
|
|
}
|
|
|
|
const lookup = target => {
|
|
if(!lock())
|
|
return;
|
|
|
|
$x.post('/tools/whois/lookup', {}, { _csrfp: $csrfp.get(), target: target }).then(output => {
|
|
let headers = output.headers();
|
|
if(headers.has('x-csrfp'))
|
|
$csrfp.set(headers.get('x-csrfp'));
|
|
|
|
let resp = output.json();
|
|
if(resp.error)
|
|
alert(resp.text);
|
|
|
|
let count = 0;
|
|
|
|
$rc(tabs);
|
|
|
|
if(resp.result && Array.isArray(resp.result.responses) && resp.result.responses.length > 0) {
|
|
if(!historic.includes(resp.result.target)) {
|
|
historic.push(resp.result.target);
|
|
history.prependItem(resp.result.target, '←', `#${resp.result.target}`);
|
|
}
|
|
|
|
for(const response of resp.result.responses) {
|
|
const tab = $e({tag: 'a'});
|
|
const tabHeader = $e();
|
|
const tabServer = $e();
|
|
|
|
tab.href = 'javascript:;';
|
|
tab.className = 'whois-result-tab';
|
|
if(count === 0) tab.className += ' whois-result-tab-active';
|
|
|
|
tab.onclick = () => {
|
|
const active = $q('.whois-result-tab-active');
|
|
if(active) active.classList.remove('whois-result-tab-active');
|
|
tab.classList.add('whois-result-tab-active');
|
|
result.textContent = response.lines.join("\r\n").trim();
|
|
};
|
|
|
|
tabHeader.className = 'whois-result-tab-header';
|
|
tabHeader.textContent = count === 0 ? 'Result' : ('Hop #' + (resp.result.responses.length - count).toString());
|
|
|
|
tabServer.className = 'whois-result-tab-server';
|
|
tabServer.textContent = response.server;
|
|
|
|
tab.appendChild(tabHeader);
|
|
tab.appendChild(tabServer);
|
|
tabs.appendChild(tab);
|
|
|
|
++count;
|
|
}
|
|
}
|
|
|
|
if(tabs.firstChild)
|
|
tabs.firstChild.click();
|
|
|
|
unlock();
|
|
});
|
|
}
|
|
|
|
const readHash = () => {
|
|
if(location.hash.length < 2) {
|
|
result.textContent = 'Enter a domain or IP address!';
|
|
return;
|
|
}
|
|
|
|
const target = decodeURIComponent(location.hash.substring(1));
|
|
if(input.value !== target)
|
|
input.value = target;
|
|
lookup(target);
|
|
};
|
|
|
|
window.addEventListener('hashchange', ev => {
|
|
readHash();
|
|
}, false);
|
|
|
|
submit.addEventListener('click', ev => {
|
|
ev.preventDefault();
|
|
location.hash = encodeURIComponent(input.value);
|
|
});
|
|
|
|
readHash();
|
|
};
|