Update SVSTaskGate.ps1
This commit is contained in:
128
SVSTaskGate.ps1
128
SVSTaskGate.ps1
@@ -697,44 +697,28 @@ function GetHtmlContent {
|
|||||||
|
|
||||||
if (installDattoRMM.checked) {
|
if (installDattoRMM.checked) {
|
||||||
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
|
const DattoRMMCheckbox = document.querySelectorAll('input[name="dattoRMMOption"]:checked');
|
||||||
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
|
appendLog("Installing selected site RMM...", "cyan");
|
||||||
|
|
||||||
// Ensure required variables are set
|
const checkedValues = Array.from(DattoRMMCheckbox).map(c => c.value);
|
||||||
if (!ApiUrl || !ApiKey || !ApiSecretKey) {
|
let installRMMCommand = 'Install-DattoRMM -ApiUrl $ApiUrl -ApiKey $ApiKey -ApiSecretKey $ApiSecretKey';
|
||||||
appendLog("Error: Missing API credentials. Please configure them before proceeding.", "red");
|
|
||||||
return;
|
if (checkedValues.includes('inputVar')) {
|
||||||
|
installRMMCommand += ' -PushSiteVars';
|
||||||
|
}
|
||||||
|
if (checkedValues.includes('rmm')) {
|
||||||
|
installRMMCommand += ' -InstallRMM';
|
||||||
|
}
|
||||||
|
if (checkedValues.includes('exe')) {
|
||||||
|
installRMMCommand += ' -SaveCopy';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build payload
|
|
||||||
const payload = {
|
|
||||||
ApiUrl: $data.ApiURL, // Replace with actual variable holding the API URL
|
|
||||||
ApiKey: $data.ApiKey, // Replace with actual variable holding the API Key
|
|
||||||
ApiSecretKey: $data/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({ installRMMCommand, UID, Name })
|
||||||
})
|
});
|
||||||
.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");
|
||||||
@@ -846,7 +830,6 @@ try {
|
|||||||
$response.OutputStream.Close()
|
$response.OutputStream.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
"/getn8npw" {
|
"/getn8npw" {
|
||||||
if ($request.HttpMethod -eq "POST") {
|
if ($request.HttpMethod -eq "POST") {
|
||||||
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
||||||
@@ -874,67 +857,43 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
"/installrmm" {
|
|
||||||
|
"/installrmm" {
|
||||||
if ($request.HttpMethod -eq "POST") {
|
if ($request.HttpMethod -eq "POST") {
|
||||||
# Read and parse the incoming JSON request
|
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
||||||
$bodyStream = New-Object IO.StreamReader $request.InputStream
|
$body = $bodyStream.ReadToEnd()
|
||||||
$body = $bodyStream.ReadToEnd()
|
$selectedSite = ConvertFrom-Json $body
|
||||||
Write-LogHybrid -Message "Raw request body: $body" -Level "Info"
|
|
||||||
|
# Extract parameters
|
||||||
|
$ApiUrl = $selectedSite.ApiUrl
|
||||||
|
$ApiKey = $selectedSite.ApiKey
|
||||||
|
$ApiSecretKey = $selectedSite.ApiSecretKey
|
||||||
|
|
||||||
|
# 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 {
|
||||||
$requestData = $body | ConvertFrom-Json
|
Invoke-Expression $installCommand
|
||||||
|
$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 parsing request JSON: $($_.Exception.Message)"
|
$responseString = "Error triggering RMM install: $($_.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()
|
||||||
@@ -943,7 +902,6 @@ try {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"/setSVSPowerplan" {
|
"/setSVSPowerplan" {
|
||||||
if ($request.HttpMethod -eq "GET") {
|
if ($request.HttpMethod -eq "GET") {
|
||||||
Set-SVSPowerPlan
|
Set-SVSPowerPlan
|
||||||
|
|||||||
Reference in New Issue
Block a user