Skip to content

Commit

Permalink
Merge pull request #14 from nwesterhausen/html-tweaks
Browse files Browse the repository at this point in the history
domain card info
  • Loading branch information
nwesterhausen authored Sep 30, 2020
2 parents 85dda1c + 1436b33 commit 12911aa
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ module.exports = {
SCK_UPDATE_DOMAIN: "50",
SCK_DELETE_DOMAIN: "51",
SCK_LOADED_DOMAINS: "102",
SCK_LOADED_WHOIS: "103",
SCK_WHOIS_CACHE_MISS: "104",
};
44 changes: 44 additions & 0 deletions lib/sockets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require("fs").promises;
const path = require("path");

const yamler = require("./yamler");
const constants = require("./constants");
Expand All @@ -14,6 +15,46 @@ function logSocketTraffic(socket, message) {
);
}

/**
*
* @param {Socket} socket
* @param {object} domainInfo
*/
function sendCachedWHOISData(socket, domainInfo) {
const allDomains = [];
domainInfo.domains.map((domain) => {
allDomains.push(domain.fqdn);
});
fs.readdir(yamler.WHOIS_DIR_PATH)
.then((whoisFiles) => {
for (let i = 0; i < allDomains.length; i++) {
if (whoisFiles.indexOf(`${allDomains[i]}.yaml`) == -1) {
logSocketTraffic(socket, `No cached WHOIS for ${allDomains[i]}`);
socket.emit(constants.SCK_WHOIS_CACHE_MISS, allDomains[i]);
}
}
const sendWhoisPromises = [];
for (let i = 0; i < whoisFiles.length; i++) {
sendWhoisPromises.push(
fs
.readFile(path.join(yamler.WHOIS_DIR_PATH, whoisFiles[i]))
.then(yamler.parseObjectFromYaml)
.then((whoisObj) => {
logSocketTraffic(
socket,
`Sent WHOIS for ${whoisObj.domain_name}`
);
socket.emit(constants.SCK_LOADED_WHOIS, whoisObj);
})
);
}
return Promise.all(sendWhoisPromises);
})
.catch((error) => {
throw error;
});
}

/**
* Function which handles socket communication
* @param {Socket} socket
Expand All @@ -37,6 +78,7 @@ function socketHandler(socket) {
.then((domainInfo) => {
socket.emit(constants.SCK_LOADED_DOMAINS, domainInfo);
logSocketTraffic(socket, "sent domains");
sendCachedWHOISData(socket, domainInfo);
})
.catch((reason) => {
throw reason;
Expand Down Expand Up @@ -75,6 +117,7 @@ function socketHandler(socket) {
.then((domainInfo) => {
socket.emit(constants.SCK_LOADED_DOMAINS, domainInfo);
logSocketTraffic(socket, "sent domain update.");
sendCachedWHOISData(socket, domainInfo);
})
.catch((error) => {
throw error;
Expand All @@ -99,6 +142,7 @@ function socketHandler(socket) {
.then((domainInfo) => {
socket.emit(constants.SCK_LOADED_DOMAINS, domainInfo);
logSocketTraffic(socket, "sent domain update");
sendCachedWHOISData(socket, domainInfo);
})
.catch((error) => {
throw error;
Expand Down
2 changes: 1 addition & 1 deletion web/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ footer p {
height: 20em;
}

#config {
.tab-pane {
margin-bottom: 15%;
}
52 changes: 50 additions & 2 deletions web/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const SCK_DELETE_DOMAIN = "51";
const SCK_UPDATE_CONFIG = "52";
const SCK_SERVER_RESTART = "10";
const SCK_LOADED_DOMAINS = "102";
const SCK_LOADED_WHOIS = "103";
const SCK_WHOIS_CACHE_MISS = "104";

// eslint-disable-next-line no-undef
const socket = io();
Expand Down Expand Up @@ -55,6 +57,19 @@ socket.on(SCK_LOADED_DOMAINS, function (data) {
updateDomainDashboardInformation(data);
updateDomainConfigurationFeedback(data);
});
socket.on(SCK_LOADED_WHOIS, function (data) {
updateMessageGui(`WHOIS data recieved for ${data.domain_name}`, data);
updateDomainCard(data);
});
socket.on(SCK_WHOIS_CACHE_MISS, function (data) {
updateMessageGui(`WHOIS cache miss for ${data}`);
document
.querySelector(`#${getCardIdTagFromDomain(data)} .card-header`)
.classList.add("bg-warning");
document.querySelector(
`#${getCardIdTagFromDomain(data)} .card-body`
).innerHTML = `<p>No WHOIS cache for ${data}</p>`;
});

document
.querySelector("#modalDomainBtnCommit")
Expand Down Expand Up @@ -314,15 +329,18 @@ function updateMessageGui(message, extraData) {
function createDomainCard(domainObj) {
const card = document.createElement("div");
card.classList.add("card", "mb-2");
card.id = `card-${domainObj.fqdn}`;
card.id = getCardIdTagFromDomain(domainObj.fqdn);

const header = document.createElement("div");
header.classList.add("card-header");
header.innerText = domainObj.fqdn;

const body = document.createElement("div");
body.classList.add("card-body");
body.innerHTML = "<p>Here's some sample inner text.</p>";
body.innerHTML =
'<div class="spinner-border text-secondary" role="status">' +
'<span class="sr-only">Loading...</span></div>' +
'<span class="ml-2">Waiting for WHOIS update from server</span>';

card.appendChild(header);
card.appendChild(body);
Expand Down Expand Up @@ -367,3 +385,33 @@ function updateConfig() {
socket.emit(SCK_UPDATE_CONFIG, configObj);
updateMessageGui("Sent server config update.", configObj);
}

/**
*
* @param {object} whoisdata
*/
function updateDomainCard(whoisdata) {
const cardid = getCardIdTagFromDomain(whoisdata.domain_name);
document.querySelector(`#${cardid} .card-body`).innerHTML = `<table><tbody>
<tr><td>Registrar</td><td>${whoisdata.registrar.name}</td></tr>
<tr><td>Registered On</td><td>${whoisdata.created_date}</td></tr>
<tr><td>Expiration</td><td>${
whoisdata.registrar.registration_expiration
}</td></tr>
<tr><td>Name Servers</td><td>${JSON.stringify(
whoisdata.name_server
)}</td></tr>
<tr><td>WHOIS query time</td><td>${
whoisdata.whois_db_update_time
}</td></tr>
</tbody></table>`;
document.querySelector(`#${cardid} .card-header`).classList.add("bg-success");
}

/**
* @param {string} fqdn
* @return {string} domain card idtag
*/
function getCardIdTagFromDomain(fqdn) {
return `card-${fqdn.replace(/\./g, "-")}`;
}

0 comments on commit 12911aa

Please sign in to comment.