Update StackMonkey.ps1
This commit is contained in:
@@ -117,6 +117,41 @@ $Port = 8082
|
|||||||
# Configurable endpoints
|
# Configurable endpoints
|
||||||
$Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit'
|
$Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit'
|
||||||
|
|
||||||
|
#region Get-DattoApiCredentials
|
||||||
|
function Get-DattoApiCredentials {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[string]$Password
|
||||||
|
)
|
||||||
|
$headers = @{ "SVSMSPKit" = $Password }
|
||||||
|
try {
|
||||||
|
$resp = Invoke-RestMethod -Uri $Global:DattoWebhookUrl `
|
||||||
|
-Headers $headers `
|
||||||
|
-Method GET
|
||||||
|
return @{
|
||||||
|
ApiUrl = $resp.ApiUrl
|
||||||
|
ApiKey = $resp.ApiKey
|
||||||
|
ApiSecretKey = $resp.ApiSecretKey
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-LogHybrid "Failed to fetch API credentials: $($_.Exception.Message)" Error DattoAuth
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
switch ($PSCmdlet.ParameterSetName) {
|
||||||
|
'Toolkit' {
|
||||||
|
Write-LogHelper "Toolkit-only mode" Info Startup
|
||||||
|
Install-SVSMSP -InstallToolkit
|
||||||
|
return
|
||||||
|
}
|
||||||
|
'Datto' {
|
||||||
|
Write-LogHelper "Headless DattoRMM deploy (via n8n)" Info Startup
|
||||||
switch ($PSCmdlet.ParameterSetName) {
|
switch ($PSCmdlet.ParameterSetName) {
|
||||||
'Toolkit' {
|
'Toolkit' {
|
||||||
Write-LogHelper "Toolkit-only mode" Info Startup
|
Write-LogHelper "Toolkit-only mode" Info Startup
|
||||||
@@ -126,10 +161,43 @@ $Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit'
|
|||||||
'Datto' {
|
'Datto' {
|
||||||
Write-LogHelper "Headless DattoRMM deploy (via n8n)" Info Startup
|
Write-LogHelper "Headless DattoRMM deploy (via n8n)" Info Startup
|
||||||
|
|
||||||
# need to get the info from N8N, so run the try command from line 415 to line 424
|
# ────────────────────────────────────────────
|
||||||
# line 415 - 424 would get th url key and secret from n8n
|
# 1) Fetch URL, Key & Secret from n8n webhook
|
||||||
|
# (this is your lines 415–424)
|
||||||
|
# ────────────────────────────────────────────
|
||||||
|
try {
|
||||||
|
$creds = Get-DattoApiCredentials -Password $N8nPassword
|
||||||
|
if (-not $creds) {
|
||||||
|
throw "Failed to retrieve Datto API credentials from n8n"
|
||||||
|
}
|
||||||
|
# overwrite the parameters with what we just fetched
|
||||||
|
$DattoApiUrl = $creds.ApiUrl
|
||||||
|
$DattoApiKey = $creds.ApiKey
|
||||||
|
$DattoApiSecretKey = $creds.ApiSecretKey
|
||||||
|
|
||||||
# need to run the external cmdlet "install-dattoRMM with all variables from ParameterSetName='Datto'"
|
Write-LogHelper "Fetched Datto API credentials from n8n" Success DattoAuth
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-LogHelper "N8N credential fetch error: $($_.Exception.Message)" Error DattoAuth
|
||||||
|
throw
|
||||||
|
}
|
||||||
|
|
||||||
|
# ────────────────────────────────────────────
|
||||||
|
# 2) Invoke the existing Install-DattoRMM cmdlet
|
||||||
|
# ────────────────────────────────────────────
|
||||||
|
Install-DattoRMM `
|
||||||
|
-ApiUrl $DattoApiUrl `
|
||||||
|
-ApiKey $DattoApiKey `
|
||||||
|
-ApiSecretKey $DattoApiSecretKey `
|
||||||
|
-SiteUID $SiteUID `
|
||||||
|
-SiteName $SiteName `
|
||||||
|
-PushSiteVars:$PushSiteVars `
|
||||||
|
-InstallRMM:$InstallRMM `
|
||||||
|
-SaveCopy:$SaveCopy
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -400,6 +468,20 @@ function Handle-FetchSites {
|
|||||||
|
|
||||||
# 2) Fetch your Datto API creds from the webhook
|
# 2) Fetch your Datto API creds from the webhook
|
||||||
Write-LogHybrid "Calling webhook for Datto credentials…" "Info" "FetchSites"
|
Write-LogHybrid "Calling webhook for Datto credentials…" "Info" "FetchSites"
|
||||||
|
<#
|
||||||
|
$creds = Get-DattoApiCredentials -Password $N8nPassword
|
||||||
|
if (-not $creds) {
|
||||||
|
Write-LogHelper "Failed to retrieve Datto API credentials from n8n" Error DattoAuth
|
||||||
|
throw
|
||||||
|
}
|
||||||
|
|
||||||
|
# now exactly the same values are populated:
|
||||||
|
$Global:ApiUrl = $creds.ApiUrl
|
||||||
|
$Global:ApiKey = $creds.ApiKey
|
||||||
|
$Global:ApiSecretKey = $creds.ApiSecretKey
|
||||||
|
Write-LogHelper "Fetched Datto API credentials from n8n" Success DattoAuth
|
||||||
|
#> #could replace the following 15 lines
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$hdr = @{ "SVSMSPKit" = $pw }
|
$hdr = @{ "SVSMSPKit" = $pw }
|
||||||
$resp = Invoke-RestMethod -Uri $Global:DattoWebhookUrl -Headers $hdr -Method GET
|
$resp = Invoke-RestMethod -Uri $Global:DattoWebhookUrl -Headers $hdr -Method GET
|
||||||
|
|||||||
Reference in New Issue
Block a user