Add src/handlers.datto.ps1
This commit is contained in:
53
src/handlers.datto.ps1
Normal file
53
src/handlers.datto.ps1
Normal file
@@ -0,0 +1,53 @@
|
||||
function Invoke-FetchSites {
|
||||
param($Context)
|
||||
|
||||
try {
|
||||
$raw = (New-Object IO.StreamReader $Context.Request.InputStream).ReadToEnd()
|
||||
$pw = (ConvertFrom-Json $raw).password
|
||||
|
||||
$Global:WebhookPassword = [string]$pw
|
||||
|
||||
$sites = Install-DattoRMM `
|
||||
-UseWebhook `
|
||||
-WebhookPassword $pw `
|
||||
-FetchSites
|
||||
|
||||
Send-JSON $Context $sites
|
||||
}
|
||||
catch {
|
||||
Write-LogHybrid "Invoke-FetchSites error: $($_.Exception.Message)" Error DattoRMM -LogToEvent
|
||||
$Context.Response.StatusCode = 500
|
||||
Send-Text $Context "Internal server error fetching sites."
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-InstallDattoRMM {
|
||||
param($Context)
|
||||
|
||||
try {
|
||||
if ($Context.Request.HttpMethod -ne 'POST') {
|
||||
$Context.Response.StatusCode = 405
|
||||
Send-Text $Context 'Use POST'
|
||||
return
|
||||
}
|
||||
|
||||
$body = (New-Object IO.StreamReader $Context.Request.InputStream).ReadToEnd()
|
||||
$data = ConvertFrom-Json $body
|
||||
|
||||
Install-DattoRMM `
|
||||
-UseWebhook `
|
||||
-WebhookPassword $Global:WebhookPassword `
|
||||
-SiteUID $data.UID `
|
||||
-SiteName $data.Name `
|
||||
-PushSiteVars:($data.checkedValues -contains 'inputVar') `
|
||||
-InstallRMM: ($data.checkedValues -contains 'rmm') `
|
||||
-SaveCopy: ($data.checkedValues -contains 'exe')
|
||||
|
||||
Send-Text $Context "Triggered DattoRMM for $($data.Name)"
|
||||
}
|
||||
catch {
|
||||
Write-LogHybrid "Invoke-InstallDattoRMM error: $($_.Exception.Message)" Error DattoRMM -LogToEvent
|
||||
$Context.Response.StatusCode = 500
|
||||
Send-Text $Context "Internal server error during DattoRMM install."
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user