Update SVSTaskGate.ps1

This commit is contained in:
2025-01-05 00:48:55 -05:00
parent b1ff4bb9fb
commit c20ea4eb4b

View File

@@ -697,35 +697,44 @@ function GetHtmlContent {
if (installDattoRMM.checked) { if (installDattoRMM.checked) {
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked'); const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
appendLog("Installing selected site RMM...", "cyan");
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}`;
if (checkedValues.includes('inputVar')) { // Ensure required variables are set
installRMMCommand += ' -PushSiteVars'; if (!ApiUrl || !ApiKey || !ApiSecretKey) {
} appendLog("Error: Missing API credentials. Please configure them before proceeding.", "red");
if (checkedValues.includes('rmm')) { return;
installRMMCommand += ' -InstallRMM';
}
if (checkedValues.includes('exe')) {
installRMMCommand += ' -SaveCopy';
} }
// Now send this command in the JSON payload // Build payload
const payload = { const payload = {
installRMMCommand, ApiUrl: ApiUrl, // Replace with actual variable holding the API URL
UID, ApiKey: ApiKey, // Replace with actual variable holding the API Key
Name ApiSecretKey: ApiSecretKey, // Replace with actual variable holding the API Secret Key
UID: UID, // Replace with actual UID value
Name: Name, // Replace with actual Name value
PushSiteVars: checkedValues.includes('inputVar'),
InstallRMM: checkedValues.includes('rmm'),
SaveCopy: checkedValues.includes('exe')
}; };
// Send POST request
fetch('/installrmm', { fetch('/installrmm', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload) body: JSON.stringify(payload)
}); })
.then(response => {
if (!response.ok) {
appendLog("Error: Failed to trigger RMM installation.", "red");
throw new Error("Failed to trigger RMM installation");
}
return response.text();
})
.then(data => appendLog(`Success: ${data}`, "green"))
.catch(error => appendLog(`Error: ${error.message}`, "red"));
} }
if (setSVSPowerplan.checked) { if (setSVSPowerplan.checked) {
fetch('/installSVSPowerplan', { method: 'GET' }); fetch('/installSVSPowerplan', { method: 'GET' });
appendLog("Setting SVS Powerplan", "cyan"); appendLog("Setting SVS Powerplan", "cyan");
@@ -865,47 +874,67 @@ try {
} }
"/installrmm" { "/installrmm" {
if ($request.HttpMethod -eq "GET") { if ($request.HttpMethod -eq "POST") {
$bodyStream = New-Object IO.StreamReader $request.InputStream # Read and parse the incoming JSON request
$body = $bodyStream.ReadToEnd() $bodyStream = New-Object IO.StreamReader $request.InputStream
$selectedSite = ConvertFrom-Json $body $body = $bodyStream.ReadToEnd()
# Extract parameters
$ApiUrl = $selectedSite.ApiUrl
$ApiKey = $selectedSite.ApiKey
$ApiSecretKey = $selectedSite.ApiSecretKey
# Log parsed data for debugging
Write-LogHybrid -Message "Raw request body: $body" -Level "Info" Write-LogHybrid -Message "Raw request body: $body" -Level "Info"
Write-LogHybrid -Message "Parsed parameters: ApiUrl='$ApiUrl', ApiKey='$ApiKey', ApiSecretKey='$ApiSecretKey'" -Level "Info"
# Verify required parameters
if (-not $ApiUrl -or -not $ApiKey -or -not $ApiSecretKey) {
$responseString = "Error: Missing required parameters. ApiUrl='$ApiUrl', ApiKey='$ApiKey', ApiSecretKey='$ApiSecretKey'"
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
$response.ContentType = "text/plain"
$response.ContentLength64 = $buffer.Length
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close()
return
}
# Construct the command
$installCommand = "Install-DattoRMM -ApiUrl '$ApiUrl' -ApiKey '$ApiKey' -ApiSecretKey '$ApiSecretKey'"
Write-LogHybrid -Message "Executing command: $installCommand" -Level "Info"
try { try {
Invoke-Expression $installCommand $requestData = $body | ConvertFrom-Json
$responseString = "RMM install triggered successfully."
# Extract parameters
$ApiUrl = $requestData.ApiUrl
$ApiKey = $requestData.ApiKey
$ApiSecretKey = $requestData.ApiSecretKey
$UID = $requestData.UID
$Name = $requestData.Name
$PushSiteVars = $requestData.PushSiteVars
$InstallRMM = $requestData.InstallRMM
$SaveCopy = $requestData.SaveCopy
Write-LogHybrid -Message "Parsed parameters: ApiUrl='$ApiUrl', ApiKey='$ApiKey', ApiSecretKey='$ApiSecretKey', UID='$UID', Name='$Name'" -Level "Info"
# Validate required parameters
if (-not $ApiUrl -or -not $ApiKey -or -not $ApiSecretKey -or -not $UID -or -not $Name) {
$responseString = "Error: Missing required parameters."
Write-LogHybrid -Message $responseString -Level "Error"
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
$response.ContentType = "text/plain"
$response.ContentLength64 = $buffer.Length
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close()
return
}
# Dynamically construct the command
$installCommand = "Install-DattoRMM -ApiUrl '$ApiUrl' -ApiKey '$ApiKey' -ApiSecretKey '$ApiSecretKey'"
if ($PushSiteVars) { $installCommand += " -PushSiteVars" }
if ($InstallRMM) { $installCommand += " -InstallRMM" }
if ($SaveCopy) { $installCommand += " -SaveCopy" }
Write-LogHybrid -Message "Executing command: $installCommand" -Level "Info"
try {
Invoke-Expression $installCommand
$responseString = "RMM install triggered successfully for UID: $UID, Name: $Name."
$response.StatusCode = 200
}
catch {
$responseString = "Error triggering RMM install: $($_.Exception.Message)"
$response.StatusCode = 500
}
} }
catch { catch {
$responseString = "Error triggering RMM install: $($_.Exception.Message)" $responseString = "Error parsing request JSON: $($_.Exception.Message)"
Write-LogHybrid -Message $responseString -Level "Error"
$response.StatusCode = 400
} }
# Send the response
$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
$response.OutputStream.Write($buffer, 0, $buffer.Length) $response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.OutputStream.Close() $response.OutputStream.Close()
@@ -914,6 +943,7 @@ try {
"/setSVSPowerplan" { "/setSVSPowerplan" {
if ($request.HttpMethod -eq "GET") { if ($request.HttpMethod -eq "GET") {
Set-SVSPowerPlan Set-SVSPowerPlan