From 1f56bc8ce97bedb8a56bd0b639d786d0b9954ed7 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sat, 4 Jan 2025 00:15:47 -0500 Subject: [PATCH] Update SVSTaskGate.ps1 --- SVSTaskGate.ps1 | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/SVSTaskGate.ps1 b/SVSTaskGate.ps1 index d590e8b..f4ffffa 100644 --- a/SVSTaskGate.ps1 +++ b/SVSTaskGate.ps1 @@ -686,13 +686,18 @@ function GetHtmlContent { const installThreatLocker = document.querySelector('input[name="installThreatlocker"]'); const installRocketCyber = document.querySelector('input[name="installRocketCyber"]'); - if (installDattoRMM.checked) { + if (installDattoRMM.checked) { + // Get the checked options for Datto RMM const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked'); appendLog("Installing selected site RMM...", "cyan"); + // Map the selected checkboxes to their values const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value); - let installRMMCommand = 'Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey'; + // Build the base command + let installRMMCommand = `Install-DattoRMM ${ApiUrl} -ApiKey ${ApiKey} -ApiSecretKey ${ApiSecretKey}`; + + // Append optional flags based on user selection if (checkedValues.includes('inputVar')) { installRMMCommand += ' -PushSiteVars'; } @@ -703,18 +708,39 @@ function GetHtmlContent { installRMMCommand += ' -SaveCopy'; } + // Log the full command for debugging purposes + console.log("Generated command:", installRMMCommand); + + // Send the command and site details to the backend fetch('/installrmm', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - installRMMCommand, "Install-DattoRMM http://proget.svstools.ca:8083/nuget/SVS_Repo/ -ApiKey TMM2F65NR81TR2N2MOUQI5KGC0TELPO -ApikeysecretKey PRB1NSQJ14ISDB00C49LRO2GR3J33RN5" - UID, "9f90bdc8-38fe-4cc6-af6d-c014569b96e3" - Name, "Sytech" - ApiUrl, "http://proget.svstools.ca:8083/nuget/SVS_Repo/" - ApiKey, "TMM2F65NR81TR2N2MOUQI5KGC0TELPO" - ApiSecretKey "PRB1NSQJ14ISDB00C49LRO2GR3J33RN5" + "installRMMCommand": installRMMCommand, + "UID": UID, + "Name": Name, + "ApiUrl": ApiUrl, + "ApiKey": ApiKey, + "ApiSecretKey": ApiSecretKey }) }) + .then(response => { + if (!response.ok) { + throw new Error(`Server responded with status ${response.status}`); + } + return response.text(); + }) + .then(data => { + console.log('RMM Installation Request Sent:', data); // Log success in console + appendLog("Installation request sent to backend successfully.", "green"); + }) + .catch(error => { + console.error('Error:', error); + appendLog(`Error sending installation request to backend: ${error.message}`, "red"); + }); + } + + .then(response => response.text()) .then(data => { console.log('RMM Installation Request Sent:', data); // Log confirmation in browser console