Skip to content

Instantly share code, notes, and snippets.

@aashutoshrathi
Last active January 16, 2023 19:02
Show Gist options
  • Save aashutoshrathi/fc5e830e40f38bacf0c786ed13be0dac to your computer and use it in GitHub Desktop.
Save aashutoshrathi/fc5e830e40f38bacf0c786ed13be0dac to your computer and use it in GitHub Desktop.
Adds or updates your current IP to NAL Whitelisting for Mongo
const sleep = (milliseconds) => {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
};
const YOUR_ENTRY_NAME = "Aashutosh";
// Go to NAL Page
if (window.location.hash !== "#/security/network/accessList") {
window.location.hash = "#/security/network/accessList";
await sleep(1000);
}
const clickOnAddCurrentIP = async () => {
const addCurrentButton = document.querySelector(
"button[name='addCurrentIpAddress']"
);
if (addCurrentButton) {
addCurrentButton.click();
await sleep(1000);
}
};
const clickOnSaveButton = async () => {
const submitButton = document.querySelector(
"button.button-is-primary[name='confirm']"
);
if (!submitButton) return;
submitButton.click();
};
const addNewEntry = async () => {
const allSectionControls = document.querySelector(
".section-controls-is-end-justified"
).children;
for (const e of allSectionControls) {
if (e.innerText === " ADD IP ADDRESS") {
e.click();
break;
}
}
await sleep(1000);
await clickOnAddCurrentIP();
// Add Comment as entry name
document.querySelector('[name="comment"]').value = YOUR_ENTRY_NAME;
// save
await clickOnSaveButton();
};
const updateIpAddress = async () => {
await sleep(2000);
await clickOnAddCurrentIP();
await clickOnSaveButton();
};
// find existing entry
const namedEntries = document.querySelectorAll(".plain-table-cell");
let found = false;
for (const e of namedEntries) {
if (e.innerText === YOUR_ENTRY_NAME) {
const targetElement = e.nextElementSibling.nextElementSibling;
targetElement.querySelector(".js-edit-entry").click();
found = true;
break;
}
}
if (!found) {
await addNewEntry();
} else {
await updateIpAddress();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment