Update SVSTaskGate.ps1

This commit is contained in:
2025-01-04 00:20:41 -05:00
parent 1f56bc8ce9
commit e082255a67

View File

@@ -303,7 +303,7 @@ function Install-SVSMSP {
Perform-ToolkitInstallation Perform-ToolkitInstallation
} }
# Install-SVSMSP -InstallToolkit Install-SVSMSP -InstallToolkit
# ---------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------
@@ -344,6 +344,8 @@ function Get-N8nWebhookData {
$global:ApiSecretKey = $data.ApiSecretKey $global:ApiSecretKey = $data.ApiSecretKey
return $data
} }
catch { catch {
Write-Host "Error making the GET request:" -ForegroundColor Red Write-Host "Error making the GET request:" -ForegroundColor Red
@@ -687,17 +689,12 @@ function GetHtmlContent {
const installRocketCyber = document.querySelector('input[name="installRocketCyber"]'); 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'); const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
appendLog("Installing selected site RMM...", "cyan"); appendLog("Installing selected site RMM...", "cyan");
// Map the selected checkboxes to their values
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value); 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')) { if (checkedValues.includes('inputVar')) {
installRMMCommand += ' -PushSiteVars'; installRMMCommand += ' -PushSiteVars';
} }
@@ -708,51 +705,13 @@ function GetHtmlContent {
installRMMCommand += ' -SaveCopy'; 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', { fetch('/installrmm', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify({ installRMMCommand, UID, Name })
"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
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) { if (document.querySelector('input[name="setSVSPowerplan"]').checked) {
fetch('/installSVSPowerplan', { method: 'GET' }); fetch('/installSVSPowerplan', { method: 'GET' });
appendLog("Setting SVS Powerplan", "cyan"); appendLog("Setting SVS Powerplan", "cyan");
@@ -888,46 +847,10 @@ try {
if ($request.HttpMethod -eq "POST") { if ($request.HttpMethod -eq "POST") {
$bodyStream = New-Object IO.StreamReader $request.InputStream $bodyStream = New-Object IO.StreamReader $request.InputStream
$body = $bodyStream.ReadToEnd() $body = $bodyStream.ReadToEnd()
# 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 $selectedSite = ConvertFrom-Json $body
Write-LogHybrid -Message "Parsed request body: $($selectedSite | ConvertTo-Json -Depth 10)" -Level "Info" Invoke-Expression $selectedSite.installRMMCommand
}
catch {
Write-LogHybrid -Message "Error parsing JSON: $($_.Exception.Message)" -Level "Error"
return
}
# Validate required fields $responseString = "RMM install triggered."
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)."
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString) $buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
$response.ContentType = "text/plain" $response.ContentType = "text/plain"
$response.ContentLength64 = $buffer.Length $response.ContentLength64 = $buffer.Length
@@ -936,8 +859,6 @@ try {
} }
} }
"/setSVSPowerplan" { "/setSVSPowerplan" {
if ($request.HttpMethod -eq "GET") { if ($request.HttpMethod -eq "GET") {
Set-SVSPowerPlan Set-SVSPowerPlan