Skip to content

Commit

Permalink
Add WSHDelayAfterStart param to WebSelfHold plugin (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbolger committed Oct 11, 2023
1 parent a997eaa commit e616344
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Posh-ACME/Plugins/WebSelfHost.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function Add-HttpChallenge {
[string]$Body,
[string]$WSHPort,
[int]$WSHTimeout = 120,
[int]$WSHDelayAfterStart = 0,
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)
Expand Down Expand Up @@ -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.
Expand All @@ -72,6 +76,7 @@ function Remove-HttpChallenge {
[string]$Body,
[string]$WSHPort,
[int]$WSHTimeout = 120,
[int]$WSHDelayAfterStart = 0,
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)
Expand Down Expand Up @@ -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.
Expand All @@ -125,6 +133,7 @@ function Save-HttpChallenge {
param(
[string]$WSHPort,
[int]$WSHTimeout = 120,
[int]$WSHDelayAfterStart = 0,
[Parameter(ValueFromRemainingArguments)]
$ExtraParams
)
Expand All @@ -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(
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions docs/Plugins/WebSelfHost.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e616344

Please sign in to comment.