From 224bdf16db79d2df393a380899114153b1661c5a Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sun, 5 Jan 2025 02:50:10 -0500 Subject: [PATCH] Update SVSTaskGate.ps1 --- SVSTaskGate.ps1 | 140 +++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/SVSTaskGate.ps1 b/SVSTaskGate.ps1 index 2d8e1bc..548b8c9 100644 --- a/SVSTaskGate.ps1 +++ b/SVSTaskGate.ps1 @@ -687,87 +687,80 @@ function GetHtmlContent { function triggerInstall() { const dropdown = document.getElementById('dattoRmmDropdown'); - const UID = dropdown.options[dropdown.selectedIndex].value; - const Name = dropdown.options[dropdown.selectedIndex].text; + const UID = dropdown.options[dropdown.selectedIndex]?.value || ""; + const Name = dropdown.options[dropdown.selectedIndex]?.text || ""; - const setSVSPowerplan = document.querySelector('input[name="setSVSPowerplan"]'); - const installSVSMSPModule = document.querySelector('input[name="installSVSMSPModule"]'); - const installDattoRMM = document.querySelector('input[name="installDattoRMM"]'); - const installCyberQP = document.querySelector('input[name="installCyberQP"]'); - const installSplashtop = document.querySelector('input[name="installSplashtop"]'); - const installSVSHelpDesk = document.querySelector('input[name="installSVSHelpDesk"]'); - const installSVSWatchtower = document.querySelector('input[name="installSVSWatchtower"]'); - const installThreatLocker = document.querySelector('input[name="installThreatlocker"]'); - const installRocketCyber = document.querySelector('input[name="installRocketCyber"]'); + const setSVSPowerplan = document.querySelector('input[name="setSVSPowerplan"]').checked; + const installCyberQP = document.querySelector('input[name="installCyberQP"]').checked; + const installSplashtop = document.querySelector('input[name="installSplashtop"]').checked; + const installSVSHelpDesk = document.querySelector('input[name="installSVSHelpDesk"]').checked; + const installSVSWatchtower = document.querySelector('input[name="installSVSWatchtower"]').checked; + const installThreatLocker = document.querySelector('input[name="installThreatLocker"]').checked; + const installRocketCyber = document.querySelector('input[name="installRocketCyber"]').checked; + const installDattoRMM = document.querySelector('input[name="installDattoRMM"]').checked; - if (installDattoRMM.checked) { - const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked'); - appendLog("Installing selected site RMM...", "cyan"); + if (installDattoRMM) { + const dattoRMMOptions = Array.from( + document.querySelectorAll('input[name="dattoRMMOption"]:checked') + ).map(option => option.value); - const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value); - - // Predefined PowerShell global variables passed into JavaScript - const ApiUrl = "$global:ApiUrl"; - const ApiKey = "$global:ApiKey"; - const ApiSecretKey = "$global:ApiSecretKey"; - - let installRMMCommand = `Install-DattoRMM -ApiUrl '${ApiUrl}' -ApiKey '${ApiKey}' -ApiSecretKey '${ApiSecretKey}'`; - - - if (checkedValues.includes('inputVar')) { - installRMMCommand += ' -PushSiteVars'; - } - if (checkedValues.includes('rmm')) { - installRMMCommand += ' -InstallRMM'; - } - if (checkedValues.includes('exe')) { - installRMMCommand += ' -SaveCopy'; - } + const payload = { + UID, + Name, + dattoRMMOptions + }; fetch('/installrmm', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ installRMMCommand, UID, Name }) - }); + body: JSON.stringify(payload) + }) + .then(response => response.text()) + .then(data => appendLog(data, "green")) + .catch(error => appendLog(`Error: ${error.message}`, "red")); + + appendLog("Datto RMM installation triggered...", "cyan"); } - if (setSVSPowerplan.checked) { + if (setSVSPowerplan) { fetch('/installSVSPowerplan', { method: 'GET' }); - appendLog("Setting SVS Powerplan", "cyan"); + appendLog("Setting SVS Powerplan...", "cyan"); } - if (installSVSMSPModule.checked) { - fetch('/installSVSMSPModule', { method: 'GET' }); - appendLog("Installing CyberQP", "cyan"); - - } - - if (installCyberQP.checked) { + if (installCyberQP) { fetch('/installCyberQP', { method: 'GET' }); - appendLog("Installing CyberQP", "cyan"); + appendLog("Installing CyberQP...", "cyan"); } - if (installSplashtop.checked) { + + if (installSplashtop) { fetch('/installSplashtop', { method: 'GET' }); - appendLog("Installing Splashtop", "cyan"); + appendLog("Installing Splashtop...", "cyan"); } - if (installSVSHelpDesk.checked) { + + if (installSVSHelpDesk) { fetch('/installSVSHelpDesk', { method: 'GET' }); - appendLog("Installing SVSHelpdesk", "cyan"); + appendLog("Installing SVS HelpDesk...", "cyan"); } - if (installSVSWatchtower.checked) { + + if (installSVSWatchtower) { fetch('/installSVSWatchtower', { method: 'GET' }); - appendLog("Installing SVSWatchtower", "cyan"); + appendLog("Installing SVS Watchtower...", "cyan"); } - if (installThreatLocker.checked) { + + if (installThreatLocker) { fetch('/installThreatLocker', { method: 'GET' }); - appendLog("Installing ThreatLocker", "cyan"); + appendLog("Installing ThreatLocker...", "cyan"); } - if (installRocketCyber.checked) { + + if (installRocketCyber) { fetch('/installRocketCyber', { method: 'GET' }); - appendLog("Installing RocketCyber", "cyan"); + appendLog("Installing RocketCyber...", "cyan"); } } + + + function endSession() { appendLog("Session ended. Closing application...", "yellow"); fetch('/quit', { method: 'GET' }) @@ -868,35 +861,50 @@ try { } } - "/installrmm" { + "/installrmm" { if ($request.HttpMethod -eq "POST") { - $bodyStream = New-Object IO.StreamReader $request.InputStream - $body = $bodyStream.ReadToEnd() - $requestData = ConvertFrom-Json $body + $bodyStream = New-Object IO.StreamReader $request.InputStream + $body = $bodyStream.ReadToEnd() + $requestData = ConvertFrom-Json $body - $installRMMCommand = $requestData.installRMMCommand $UID = $requestData.UID $Name = $requestData.Name + $dattoRMMOptions = $requestData.dattoRMMOptions - # Log the received command - Write-LogHybrid -Message "Received command: $installRMMCommand for UID: $UID, Name: $Name" -Level "Info" + # Start building the Install-DattoRMM command + $installCommand = "Install-DattoRMM -ApiUrl '$ApiUrl' -ApiKey '$ApiKey' -ApiSecretKey '$ApiSecretKey'" + + # Add options based on the received data + if ($dattoRMMOptions -contains "inputVar") { + $installCommand += " -PushSiteVars" + } + if ($dattoRMMOptions -contains "rmm") { + $installCommand += " -InstallRMM" + } + if ($dattoRMMOptions -contains "exe") { + $installCommand += " -SaveCopy" + } + + # Log and execute the command + Write-LogHybrid -Message "Executing DattoRMM install for UID: $UID, Name: $Name with command: $installCommand" -Level "Info" try { - Invoke-Expression $installRMMCommand - $responseString = "RMM install triggered successfully for UID: $UID, Name: $Name." + Invoke-Expression $installCommand + $responseString = "DattoRMM installation triggered successfully for UID: $UID, Name: $Name." } catch { - $responseString = "Error triggering RMM install: $($_.Exception.Message)" + $responseString = "Error triggering DattoRMM installation: $($_.Exception.Message)" } $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString) - $response.ContentType = "text/plain" + $response.ContentType = "text/plain" $response.ContentLength64 = $buffer.Length $response.OutputStream.Write($buffer, 0, $buffer.Length) $response.OutputStream.Close() } } +