From cff7f6e4a5ec7c22859c6be972a31ad2b7fcd528 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sun, 22 Jun 2025 23:59:34 -0400 Subject: [PATCH] Update StackMonkey.ps1 --- StackMonkey.ps1 | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index 6b2ad23..82d369d 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -62,6 +62,14 @@ #> + +# Listening port for HTTP UI +$Port = 8082 + +# Configurable endpoints +$Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit' + + function Invoke-ScriptMonkey { #region ScriptMonkey run silently Entrypoint [CmdletBinding(DefaultParameterSetName='UI')] @@ -72,6 +80,10 @@ function Invoke-ScriptMonkey { [switch]$SilentInstall, # ───────────────────────────────────────────────────────── + [Parameter(Mandatory,ParameterSetName='Datto')] + [string] $N8nPassword, + + <# replaced by n8n # Datto headless mode [Parameter(Mandatory,ParameterSetName='Datto')] #[ValidateNotNullOrEmpty()] @@ -84,6 +96,7 @@ function Invoke-ScriptMonkey { [Parameter(Mandatory,ParameterSetName='Datto')] #[ValidateNotNullOrEmpty()] [string] $DattoApiSecretKey, + #> [Parameter(Mandatory,ParameterSetName='Datto')] #[ValidateNotNullOrEmpty()] @@ -110,11 +123,19 @@ function Invoke-ScriptMonkey { return } 'Datto' { - Write-LogHelper "Headless DattoRMM deploy" Info Startup + Write-LogHelper "Headless DattoRMM deploy (via n8n)" Info Startup + + # 1) fetch creds from n8n + $creds = Get-DattoApiCredentials -Password $N8nPassword + if (-not $creds) { + throw "Failed to retrieve Datto API credentials from n8n" + } + + # 2) pass them straight into the helper Install-DattoRMM-Helper ` - -ApiUrl $DattoApiUrl ` - -ApiKey $DattoApiKey ` - -ApiSecretKey $DattoApiSecretKey ` + -ApiUrl $creds.ApiUrl ` + -ApiKey $creds.ApiKey ` + -ApiSecretKey $creds.ApiSecretKey ` -SiteUID $SiteUID ` -SiteName $SiteName ` -PushSiteVars:$PushSiteVars ` @@ -140,11 +161,6 @@ function Invoke-ScriptMonkey { #region Config & Task Definitions -# Listening port for HTTP UI -$Port = 8082 - -# Configurable endpoints -$Global:DattoWebhookUrl = 'https://automate.svstools.ca/webhook/svsmspkit' # Define every task once here: @@ -279,10 +295,9 @@ function Respond-JSON { #region Get-DattoApiCreds function Get-DattoApiCredentials { param ([string]$Password) - $url = "https://automate.svstools.ca/webhook/svsmspkit" $headers = @{ "SVSMSPKit" = $Password } try { - $response = Invoke-RestMethod -Uri $url -Headers $headers -Method GET + $response = Invoke-RestMethod -Uri $Global:DattoWebhookUrl -Headers $headers -Method GET return @{ ApiUrl = $response.ApiUrl ApiKey = $response.ApiKey