Update SVSTaskGate.ps1
This commit is contained in:
@@ -699,7 +699,7 @@ function GetHtmlContent {
|
|||||||
appendLog("Installing selected site RMM...", "cyan");
|
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}'`;
|
let installRMMCommand = 'Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey';
|
||||||
|
|
||||||
if (checkedValues.includes('inputVar')) {
|
if (checkedValues.includes('inputVar')) {
|
||||||
installRMMCommand += ' -PushSiteVars';
|
installRMMCommand += ' -PushSiteVars';
|
||||||
@@ -715,19 +715,6 @@ 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");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,24 +855,22 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"/installrmm" {
|
"/installrmm" {
|
||||||
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()
|
||||||
$selectedSite = ConvertFrom-Json $body
|
$selectedSite = ConvertFrom-Json $body
|
||||||
|
|
||||||
# Log received data
|
# Extract parameters
|
||||||
Write-LogHybrid -Message "Received data: $($body)" -Level "Info"
|
$ApiUrl = $selectedSite.ApiUrl
|
||||||
|
$ApiKey = $selectedSite.ApiKey
|
||||||
|
$ApiSecretKey = $selectedSite.ApiSecretKey
|
||||||
|
|
||||||
# Extract values from $selectedSite
|
# Verify required parameters
|
||||||
$installRMMCommand = $selectedSite.installRMMCommand
|
if (-not $ApiUrl -or -not $ApiKey -or -not $ApiSecretKey) {
|
||||||
$UID = $selectedSite.UID
|
$responseString = "Error: Missing required parameters. ApiUrl='$ApiUrl', ApiKey='$ApiKey', ApiSecretKey='$ApiSecretKey'"
|
||||||
$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
|
||||||
@@ -894,31 +879,6 @@ 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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Construct the command
|
# Construct the command
|
||||||
$installCommand = "Install-DattoRMM -ApiUrl '$ApiUrl' -ApiKey '$ApiKey' -ApiSecretKey '$ApiSecretKey'"
|
$installCommand = "Install-DattoRMM -ApiUrl '$ApiUrl' -ApiKey '$ApiKey' -ApiSecretKey '$ApiSecretKey'"
|
||||||
Write-LogHybrid -Message "Executing command: $installCommand" -Level "Info"
|
Write-LogHybrid -Message "Executing command: $installCommand" -Level "Info"
|
||||||
|
|||||||
Reference in New Issue
Block a user