Update SVSTaskGate.ps1
This commit is contained in:
@@ -715,7 +715,19 @@ function GetHtmlContent {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ installRMMCommand, UID, Name })
|
body: JSON.stringify({ installRMMCommand, UID, Name })
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
appendLog(`Error: ${response.statusText}`, "red");
|
||||||
|
throw new Error(`Server responded with status ${response.status}`);
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
appendLog(`Response: ${data}`, "green");
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
appendLog(`Fetch error: ${error.message}`, "red");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -862,14 +874,18 @@ try {
|
|||||||
$body = $bodyStream.ReadToEnd()
|
$body = $bodyStream.ReadToEnd()
|
||||||
$selectedSite = ConvertFrom-Json $body
|
$selectedSite = ConvertFrom-Json $body
|
||||||
|
|
||||||
# Extract parameters
|
# Log received data
|
||||||
$ApiUrl = $selectedSite.ApiUrl
|
Write-LogHybrid -Message "Received data: $($body)" -Level "Info"
|
||||||
$ApiKey = $selectedSite.ApiKey
|
|
||||||
$ApiSecretKey = $selectedSite.ApiSecretKey
|
|
||||||
|
|
||||||
# Verify required parameters
|
# Extract values from $selectedSite
|
||||||
if (-not $ApiUrl -or -not $ApiKey -or -not $ApiSecretKey) {
|
$installRMMCommand = $selectedSite.installRMMCommand
|
||||||
$responseString = "Error: Missing required parameters. ApiUrl='$ApiUrl', ApiKey='$ApiKey', ApiSecretKey='$ApiSecretKey'"
|
$UID = $selectedSite.UID
|
||||||
|
$Name = $selectedSite.Name
|
||||||
|
|
||||||
|
# Validate required fields
|
||||||
|
if (-not $installRMMCommand) {
|
||||||
|
$responseString = "Error: Missing 'installRMMCommand' in the request payload."
|
||||||
|
Write-LogHybrid -Message $responseString -Level "Error"
|
||||||
$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
|
||||||
@@ -878,11 +894,35 @@ try {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Write-LogHybrid -Message "Executing command: $installRMMCommand" -Level "Info"
|
||||||
|
Write-LogHybrid -Message "Site UID: $UID, Name: $Name" -Level "Info"
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Execute the command
|
||||||
|
Invoke-Expression $installRMMCommand
|
||||||
|
$responseString = "RMM install triggered successfully for site: $Name (UID: $UID)."
|
||||||
|
Write-LogHybrid -Message $responseString -Level "Success"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$responseString = "Error executing RMM install: $($_.Exception.Message)"
|
||||||
|
Write-LogHybrid -Message $responseString -Level "Error"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Send the response back to the client
|
||||||
|
$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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"/setSVSPowerplan" {
|
"/setSVSPowerplan" {
|
||||||
if ($request.HttpMethod -eq "GET") {
|
if ($request.HttpMethod -eq "GET") {
|
||||||
Set-SVSPowerPlan
|
Set-SVSPowerPlan
|
||||||
|
|||||||
Reference in New Issue
Block a user