Update StackMonkey.ps1
This commit is contained in:
137
StackMonkey.ps1
137
StackMonkey.ps1
@@ -418,65 +418,52 @@ function Handle-InstallSVSHelpDesk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Handle-InstallDattoRMM {
|
function Handle-InstallDattoRMM {
|
||||||
param($Context)
|
param($Context)
|
||||||
|
$req = $Context.Request
|
||||||
|
$resp = $Context.Response
|
||||||
|
|
||||||
$request = $Context.Request
|
if ($req.HttpMethod -ne 'POST') {
|
||||||
$response = $Context.Response
|
$resp.StatusCode = 405; $resp.ContentType = 'text/plain'
|
||||||
|
$resp.OutputStream.Write([Text.Encoding]::UTF8.GetBytes('Use POST'),0,7)
|
||||||
|
$resp.OutputStream.Close(); return
|
||||||
|
}
|
||||||
|
|
||||||
if ($request.HttpMethod -ne "POST") {
|
# parse JSON body
|
||||||
$response.StatusCode = 405
|
$body = (New-Object IO.StreamReader $req.InputStream).ReadToEnd()
|
||||||
$response.ContentType = "text/plain"
|
$data = $body | ConvertFrom-Json
|
||||||
$response.OutputStream.Write(
|
$checked = $data.checkedValues
|
||||||
[Text.Encoding]::UTF8.GetBytes("Method not allowed. Use POST."),
|
$uid = $data.UID
|
||||||
0, 29
|
$name = $data.Name
|
||||||
)
|
|
||||||
$response.OutputStream.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$body = (New-Object IO.StreamReader $request.InputStream).ReadToEnd()
|
Install-DattoRMM `
|
||||||
$requestData = $body | ConvertFrom-Json
|
-ApiUrl $Global:ApiUrl `
|
||||||
$checked = $requestData.checkedValues
|
-ApiKey $Global:ApiKey `
|
||||||
$UID = $requestData.UID
|
-ApiSecretKey $Global:ApiSecretKey `
|
||||||
$Name = $requestData.Name
|
-SiteUID $uid `
|
||||||
|
-SiteName $name `
|
||||||
|
-PushSiteVars:($checked -contains 'inputVar') `
|
||||||
|
-InstallRMM: ($checked -contains 'rmm') `
|
||||||
|
-SaveCopy: ($checked -contains 'exe')
|
||||||
|
|
||||||
if (-not $checked -or -not $UID -or -not $Name) {
|
Write-LogHybrid "RMM install triggered for $name" "Success" "DattoRMM"
|
||||||
throw "Missing required parameters"
|
$resp.StatusCode = 200
|
||||||
}
|
$responseString = "Triggered DattoRMM for $name"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-LogHybrid "Error in Install-DattoRMM: $_" "Error" "DattoRMM"
|
||||||
|
$resp.StatusCode = 500
|
||||||
|
$responseString = "ERROR: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
|
||||||
# Build the command
|
$b = [Text.Encoding]::UTF8.GetBytes($responseString)
|
||||||
$cmd = "Install-DattoRMM -ApiUrl '$ApiUrl' -ApiKey '$ApiKey' -ApiSecretKey '$ApiSecretKey' -SiteName '$Name' -SiteUID '$UID'"
|
$resp.ContentType = 'text/plain'
|
||||||
if ($checked -contains 'inputVar') { $cmd += " -PushSiteVars" }
|
$resp.ContentLength64 = $b.Length
|
||||||
if ($checked -contains 'rmm') { $cmd += " -InstallRMM" }
|
$resp.OutputStream.Write($b,0,$b.Length)
|
||||||
if ($checked -contains 'exe') { $cmd += " -SaveCopy" }
|
$resp.OutputStream.Close()
|
||||||
|
|
||||||
# Invoke and respond
|
|
||||||
try {
|
|
||||||
Invoke-Expression $cmd
|
|
||||||
Write-LogHybrid "RMM install triggered for $Name" "Success" "DattoRMM"
|
|
||||||
$response.StatusCode = 200
|
|
||||||
$responseString = "RMM installation triggered successfully for $Name."
|
|
||||||
} catch {
|
|
||||||
Write-LogHybrid "Error triggering RMM install: $_" "Error" "DattoRMM"
|
|
||||||
$response.StatusCode = 500
|
|
||||||
$responseString = "Error triggering RMM install: $_"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Write-LogHybrid "Bad request to /installDattoRMM: $_" "Error" "DattoRMM"
|
|
||||||
$response.StatusCode = 400
|
|
||||||
$responseString = "Error: $($_.Exception.Message)"
|
|
||||||
}
|
|
||||||
|
|
||||||
# write the response
|
|
||||||
$bytes = [Text.Encoding]::UTF8.GetBytes($responseString)
|
|
||||||
$response.ContentType = "text/plain"
|
|
||||||
$response.ContentLength64 = $bytes.Length
|
|
||||||
$response.OutputStream.Write($bytes, 0, $bytes.Length)
|
|
||||||
$response.OutputStream.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Off-boarding handlers
|
# Off-boarding handlers
|
||||||
function Handle-UninstallCyberQP {
|
function Handle-UninstallCyberQP {
|
||||||
param($Context)
|
param($Context)
|
||||||
@@ -856,40 +843,34 @@ $style = @'
|
|||||||
const cb = document.getElementById(t.id);
|
const cb = document.getElementById(t.id);
|
||||||
if (!cb || !cb.checked) continue;
|
if (!cb || !cb.checked) continue;
|
||||||
|
|
||||||
// special-case DattoRMM: POST JSON with sub-options + site info
|
// special case: DattoRMM is POST
|
||||||
if (t.id === 'installDattoRMM') {
|
if (t.id === 'installDattoRMM') {
|
||||||
const checkedValues = Array.from(
|
const sub = Array.from(
|
||||||
document.querySelectorAll('.sub-option-installDattoRMM')
|
document.querySelectorAll('.sub-option-installDattoRMM:checked')
|
||||||
)
|
).map(x=>x.value);
|
||||||
.filter(sub => sub.checked)
|
|
||||||
.map(sub => sub.value);
|
|
||||||
|
|
||||||
const dropdown = document.getElementById('dattoDropdown');
|
const dropdown = document.getElementById('dattoDropdown');
|
||||||
const UID = dropdown.value;
|
const uid = dropdown.value;
|
||||||
const Name = dropdown.options[dropdown.selectedIndex].text;
|
const name = dropdown.selectedOptions[0].text;
|
||||||
|
|
||||||
try {
|
await fetch('/installDattoRMM', {
|
||||||
await fetch('/installDattoRMM', {
|
method: 'POST',
|
||||||
method: 'POST',
|
headers: { 'Content-Type': 'application/json' },
|
||||||
headers: { 'Content-Type': 'application/json' },
|
body: JSON.stringify({
|
||||||
body: JSON.stringify({ checkedValues, UID, Name })
|
checkedValues: sub,
|
||||||
});
|
UID: uid,
|
||||||
} catch (e) {
|
Name: name
|
||||||
console.error(`Error running ${t.label}:`, e);
|
})
|
||||||
}
|
});
|
||||||
|
}
|
||||||
} else {
|
else {
|
||||||
// everything else remains a simple GET
|
// your existing GET for everyone else
|
||||||
try {
|
await fetch(t.handler, { method: 'GET' });
|
||||||
await fetch(t.handler, { method: 'GET' });
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`Error running ${t.label}:`, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// Shutdown Handler
|
// Shutdown Handler
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user