diff --git a/Posh-ACME/Plugins/WebSelfHost.ps1 b/Posh-ACME/Plugins/WebSelfHost.ps1 index 5101e5e0..052f7e9d 100644 --- a/Posh-ACME/Plugins/WebSelfHost.ps1 +++ b/Posh-ACME/Plugins/WebSelfHost.ps1 @@ -11,6 +11,7 @@ function Add-HttpChallenge { [string]$Body, [string]$WSHPort, [int]$WSHTimeout = 120, + [int]$WSHDelayAfterStart = 0, [Parameter(ValueFromRemainingArguments)] $ExtraParams ) @@ -51,6 +52,9 @@ function Add-HttpChallenge { .PARAMETER WSHTimeout The number of seconds to leave the server running for before automatically stopping. + .PARAMETER WSHDelayAfterStart + The number of seconds to sleep after starting the HTTP listener job. + .PARAMETER ExtraParams This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports. @@ -72,6 +76,7 @@ function Remove-HttpChallenge { [string]$Body, [string]$WSHPort, [int]$WSHTimeout = 120, + [int]$WSHDelayAfterStart = 0, [Parameter(ValueFromRemainingArguments)] $ExtraParams ) @@ -110,6 +115,9 @@ function Remove-HttpChallenge { .PARAMETER WSHTimeout The number of seconds to leave the server running for before automatically stopping. + .PARAMETER WSHDelayAfterStart + The number of seconds to sleep after starting the HTTP listener job. + .PARAMETER ExtraParams This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports. @@ -125,6 +133,7 @@ function Save-HttpChallenge { param( [string]$WSHPort, [int]$WSHTimeout = 120, + [int]$WSHDelayAfterStart = 0, [Parameter(ValueFromRemainingArguments)] $ExtraParams ) @@ -142,6 +151,10 @@ function Save-HttpChallenge { $portSuffix = if ($WSHPort) { ":$WSHPort" } else { [string]::Empty } $prefix = 'http://+{0}/.well-known/acme-challenge/' -f $portSuffix + # add the delay value to the timeout value so the user effectively gets the full + # timeout value. + $WSHTimeout += $WSHDelayAfterStart + Write-Debug "Starting listener job with prefix $prefix" $script:WSHListenerJob = Start-Job -ScriptBlock { param( @@ -249,6 +262,10 @@ function Save-HttpChallenge { } -ArgumentList $prefix,$script:WSHResponses,$WSHTimeout + if ($WSHDelayAfterStart -gt 0) { + Start-Sleep -Seconds $WSHDelayAfterStart + } + } else { # STOP Write-Debug "Found existing listener job, time to stop" @@ -283,6 +300,9 @@ function Save-HttpChallenge { .PARAMETER WSHTimeout The number of seconds to leave the server running for before automatically stopping. + .PARAMETER WSHDelayAfterStart + The number of seconds to sleep after starting the HTTP listener job. + .PARAMETER ExtraParams This parameter can be ignored and is only used to prevent errors when splatting with more parameters than this function supports. diff --git a/docs/Plugins/WebSelfHost.md b/docs/Plugins/WebSelfHost.md index 7b7b6b0a..177a756d 100644 --- a/docs/Plugins/WebSelfHost.md +++ b/docs/Plugins/WebSelfHost.md @@ -32,6 +32,8 @@ Regardless of the underlying OS, you need to make sure the listener won't confli No plugin args are required if you will be using the default port 80 and 120 second timeout. Otherwise, you may use `WSHPort` and `WSHTimeout` respectively. +There is also a `WSHDelayAfterStart` arg that can be used to add a delay between when the listener starts and when the plugin returns control to the module to validate the challenges. This can be useful if it seems like the listener isn't starting up fast enough to answer the challenge requests. + ### Default functionality ```powershell