diff --git a/SVSTaskGate.ps1 b/SVSTaskGate.ps1 index f4ffffa..fc44b03 100644 --- a/SVSTaskGate.ps1 +++ b/SVSTaskGate.ps1 @@ -303,7 +303,7 @@ function Install-SVSMSP { Perform-ToolkitInstallation } - # Install-SVSMSP -InstallToolkit + Install-SVSMSP -InstallToolkit # ---------------------------------------------------------------------------------- @@ -344,6 +344,8 @@ function Get-N8nWebhookData { $global:ApiSecretKey = $data.ApiSecretKey + + return $data } catch { Write-Host "Error making the GET request:" -ForegroundColor Red @@ -686,18 +688,13 @@ function GetHtmlContent { const installThreatLocker = document.querySelector('input[name="installThreatlocker"]'); const installRocketCyber = document.querySelector('input[name="installRocketCyber"]'); - if (installDattoRMM.checked) { - // Get the checked options for Datto RMM + if (installDattoRMM.checked) { 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'; } @@ -708,51 +705,13 @@ 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": 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"); + body: JSON.stringify({ installRMMCommand, UID, Name }) }); } - - .then(response => response.text()) - .then(data => { - console.log('RMM Installation Request Sent:', data); // Log confirmation in browser console - appendLog("Installation request sent to backend.", "green"); - }) - .catch(error => { - console.error('Error:', error); - appendLog("Error sending installation request to backend: " + error.message, "red"); - }); - - } - if (document.querySelector('input[name="setSVSPowerplan"]').checked) { fetch('/installSVSPowerplan', { method: 'GET' }); appendLog("Setting SVS Powerplan", "cyan"); @@ -884,50 +843,14 @@ try { } } - "/installrmm" { + "/installrmm" { if ($request.HttpMethod -eq "POST") { $bodyStream = New-Object IO.StreamReader $request.InputStream $body = $bodyStream.ReadToEnd() + $selectedSite = ConvertFrom-Json $body + Invoke-Expression $selectedSite.installRMMCommand - # Ensure the request body is not empty - if (-not $body) { - Write-LogHybrid -Message "Request body is empty. Aborting..." -Level "Error" - return - } - - # Log raw request body - Write-LogHybrid -Message "Raw request body: $body" -Level "Info" - - try { - $selectedSite = ConvertFrom-Json $body - Write-LogHybrid -Message "Parsed request body: $($selectedSite | ConvertTo-Json -Depth 10)" -Level "Info" - } - catch { - Write-LogHybrid -Message "Error parsing JSON: $($_.Exception.Message)" -Level "Error" - return - } - - # Validate required fields - if (-not $selectedSite.installRMMCommand -or -not $selectedSite.UID -or -not $selectedSite.Name) { - Write-LogHybrid -Message "Missing required fields in JSON payload. Aborting..." -Level "Error" - return - } - - # Log the received request - Write-LogHybrid -Message "Received RMM installation request for site $($selectedSite.Name) ($($selectedSite.UID))." -Level "Info" - - # Execute the installation command - try { - $output = Invoke-Expression $selectedSite.installRMMCommand - Write-LogHybrid -Message "Command output: $output" -Level "Info" - Write-LogHybrid -Message "Installation for site $($selectedSite.Name) ($($selectedSite.UID)) completed successfully." -Level "Success" - } - catch { - Write-LogHybrid -Message "Error during installation for site $($selectedSite.Name): $($_.Exception.Message)" -Level "Error" - } - - # Send response - $responseString = "RMM installation triggered for site $($selectedSite.Name)." + $responseString = "RMM install triggered." $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString) $response.ContentType = "text/plain" $response.ContentLength64 = $buffer.Length @@ -936,8 +859,6 @@ try { } } - - "/setSVSPowerplan" { if ($request.HttpMethod -eq "GET") { Set-SVSPowerPlan