From dedbaa8bc7f5d2cdc9415eb65be0b8033f9236e4 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sun, 29 Jun 2025 04:33:18 -0400 Subject: [PATCH] Update StackMonkey.ps1 --- StackMonkey.ps1 | 806 ++++++++++++++++++++++++------------------------ 1 file changed, 403 insertions(+), 403 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index cc331d8..6450328 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -856,419 +856,419 @@ function Invoke-ScriptMonkey { # # 1) Inline your full original CSS here # - $style = @' - +'@ + +$script = @' + +// ======================================================================= +// Fetch Sites Handler +// ======================================================================= +async function fetchSites() { + const pwd = document.getElementById("Password").value; + if (!pwd) { + alert("Please enter the password."); + return; + } - '@ + const dropdown = document.getElementById("dattoDropdown"); + dropdown.innerHTML = ''; + + try { + const resp = await fetch("/getpw", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ password: pwd }) + }); + + if (!resp.ok) throw("HTTP " + resp.status); + + const sites = await resp.json(); + dropdown.innerHTML = ''; // clear the loading message + + sites.forEach(site => { + const option = document.createElement("option"); + option.value = site.UID; + option.textContent = site.Name; + dropdown.appendChild(option); + }); + + document.getElementById("dattoRmmContainer").style.display = "block"; + } + catch (e) { + console.error(e); + dropdown.innerHTML = ''; + alert("Failed to fetch sites. Check password and try again."); + } +} + + + + + + + async function triggerInstall() { + // disable the button so you can't double-click while work is in flight + const runBtn = document.querySelector('.run-button'); + runBtn.disabled = true; + + try { + for (const t of tasks) { + const cb = document.getElementById(t.id); + if (!cb || !cb.checked) continue; + + if (t.id === 'installDattoRMM') { + const sub = Array.from( + document.querySelectorAll('.sub-option-installDattoRMM:checked') + ).map(x => x.value); + const dropdown = document.getElementById('dattoDropdown'); + const uid = dropdown.value; + const name = dropdown.selectedOptions[0].text; + + await fetch('/installDattoRMM', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + checkedValues: sub, + UID: uid, + Name: name + }) + }); + } else { + await fetch(t.handler, { method: 'GET' }); + } + } + } catch (e) { + console.error('Error during triggerInstall:', e); + } finally { + // always re-enable, even if an error occurred + runBtn.disabled = false; + } + } + + + + + // ======================================================================= + // Shutdown Handler + // ======================================================================= + function endSession() { + fetch("/quit", { method: "GET" }) + .finally(() => window.close()); + } + + // ======================================================================= + // Sub-Options Auto-Toggle for Tasks + // ======================================================================= + + + document.addEventListener('DOMContentLoaded', function () { + // Auto-handle visibility and checking for tasks with sub-options + const tasksWithSubOptions = document.querySelectorAll('[id$="OptionsContainer"]'); + + tasksWithSubOptions.forEach(container => { + const taskId = container.id.replace('OptionsContainer', ''); + const masterCheckbox = document.getElementById(taskId); + + if (!masterCheckbox) return; + + function updateVisibility() { + const checked = masterCheckbox.checked; + container.style.display = checked ? 'block' : 'none'; + container.querySelectorAll('input[type="checkbox"]').forEach(cb => cb.checked = checked); + + // Show/hide Password and RMM only if it's installDattoRMM + if (taskId === 'installDattoRMM') { + const pwdBox = document.getElementById('PasswordContainer'); + const rmmBox = document.getElementById('dattoRmmContainer'); + if (pwdBox) pwdBox.style.display = checked ? 'block' : 'none'; + if (rmmBox) rmmBox.style.display = checked ? 'block' : 'none'; + } + } + + masterCheckbox.addEventListener('change', updateVisibility); + updateVisibility(); // call once on load + }); + }); + +// =========================================== +// ─ rotating tagline ─────────────────────────────── +// =========================================== + +document.addEventListener('DOMContentLoaded', () => { + const taglines = [ + "Fast deployments, no monkey business.", + "Bananas for better builds.", + "Deploy without flinging code.", + "Tame your stack. Unleash the monkey.", + "Monkey see, monkey deploy.", + "Deploy smarter -- with a monkey on your team.", + "Don't pass the monkey -- let it deploy.", + "No more monkeying around. Stack handled.", + "Own your stack. But let the monkey do the work.", + "Why throw code when the monkey's got it?", + "Deployments so easy, a monkey could do it. Ours does.", + "Monkey in the stack, not on your back." + ]; + + const el = document.getElementById("tagline"); + let idx = Math.floor(Math.random() * taglines.length); + el.textContent = taglines[idx]; + + setInterval(() => { + idx = (idx + 1) % taglines.length; + el.textContent = taglines[idx]; + }, 10_000); +}); + +// when the browser window is closed (X), notify the server to quit +window.addEventListener('beforeunload', () => { + // keepalive: true ensures the request is sent even as the page unloads + fetch('/quit', { method: 'GET', keepalive: true }); +}); + + + +'@ # # 3) The HTML skeleton with placeholders