From 4ada660ddd1425286bbbf7a1a36a606c29d9e6b4 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Wed, 14 Jan 2026 02:11:46 -0500 Subject: [PATCH] Add src/handlers.datto.ps1 --- src/handlers.datto.ps1 | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/handlers.datto.ps1 diff --git a/src/handlers.datto.ps1 b/src/handlers.datto.ps1 new file mode 100644 index 0000000..36075fd --- /dev/null +++ b/src/handlers.datto.ps1 @@ -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." + } +}