diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f7f2311 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +# Normalize line endings for all text files based on content, rather than relying on each +# contributor's local core.autocrlf setting (which is what's been producing the "LF will be +# replaced by CRLF" warnings on every git operation in this repo). +* text=auto + +# PiHoleShell.psd1 is UTF-16LE with a BOM (New-ModuleManifest's default output) - leave it as +# binary from git's line-ending-normalization perspective so it's never rewritten. +PiHoleShell/PiHoleShell.psd1 -text diff --git a/PiHoleShell/PiHoleShell.psd1 b/PiHoleShell/PiHoleShell.psd1 index 431211d..abd6f43 100644 Binary files a/PiHoleShell/PiHoleShell.psd1 and b/PiHoleShell/PiHoleShell.psd1 differ diff --git a/PiHoleShell/PiHoleShell.psm1 b/PiHoleShell/PiHoleShell.psm1 index 72c39c0..136606a 100644 --- a/PiHoleShell/PiHoleShell.psm1 +++ b/PiHoleShell/PiHoleShell.psm1 @@ -18,11 +18,11 @@ Export-ModuleMember -Function @( #Actions 'Update-PiHoleActionsGravity', 'Invoke-PiHoleFlushNetwork', 'Invoke-PiHoleFlushLogs', 'Restart-PiHoleDnsService' ` #Authentication - 'Remove-PiHoleCurrentAuthSession' , 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', 'Get-PiHoleAuthStatus', 'Get-PiHoleAuthTotp', ` + 'Remove-PiHoleCurrentAuthSession' , 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', 'Get-PiHoleAuthStatus', 'Get-PiHoleAuthTotp', 'Get-PiHoleAuthApp', ` #GroupManagement 'Get-PiHoleGroup', 'New-PiHoleGroup', 'Update-PiHoleGroup', 'Remove-PiHoleGroup', ` #DnsControl - 'Get-PiHoleDnsBlockingStatus', 'Set-PiHoleDnsBlocking', ` + 'Get-PiHoleDnsBlockingStatus', 'Set-PiHoleDnsBlocking', 'Add-PiHoleDnsRecord', 'Remove-PiHoleDnsRecord', 'Get-PiHoleDnsRecord', ` #Config 'Get-PiHoleConfig', 'Set-PiHoleConfig', 'Add-PiHoleConfigArrayItem', 'Remove-PiHoleConfigArrayItem', 'Get-PiHoleConfigProperty', ` #Padd diff --git a/PiHoleShell/Public/Actions/Update-PiHoleActionsGravity.ps1 b/PiHoleShell/Public/Actions/Update-PiHoleActionsGravity.ps1 index 3e23c04..8791b6e 100644 --- a/PiHoleShell/Public/Actions/Update-PiHoleActionsGravity.ps1 +++ b/PiHoleShell/Public/Actions/Update-PiHoleActionsGravity.ps1 @@ -61,7 +61,9 @@ Update-PiHoleActionsGravity -PiHoleServer "http://pihole.domain.com:8080" -Passw } catch { - Write-Error -Message $_.Exception.Message + # Surfaces Pi-hole's own message, e.g. "Gravity is already running" for the 409 FTL v6.8+ + # returns while another run is in progress, instead of a bare "409 (Conflict)" + Write-Error -Message (ConvertTo-PiHoleFriendlyErrorMessage -ErrorRecord $_) } finally { diff --git a/PiHoleShell/Public/Authentication/Get-PiHoleAuthApp.ps1 b/PiHoleShell/Public/Authentication/Get-PiHoleAuthApp.ps1 new file mode 100644 index 0000000..f931700 --- /dev/null +++ b/PiHoleShell/Public/Authentication/Get-PiHoleAuthApp.ps1 @@ -0,0 +1,80 @@ +function Get-PiHoleAuthApp { + <# +.SYNOPSIS +Generate a new application password + +.DESCRIPTION +Generates a new application password and its hash. The password is shown only once and cannot be +retrieved later, so store it somewhere safe. + +This only generates the password - it does not activate it, and your current app password keeps +working. To switch to the new one, set the returned Hash as webserver.api.app_pwhash, e.g. with +Set-PiHoleConfig (see the second example). Doing so replaces your current app password and ends +all active sessions. + +.PARAMETER PiHoleServer +The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100" + +.PARAMETER Password +The API Password you generated from your PiHole server + +.PARAMETER IgnoreSsl +Set to $true to skip SSL certificate validation + +.PARAMETER RawOutput +This will dump the response instead of the formatted object + +.EXAMPLE +Get-PiHoleAuthApp -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" + +.EXAMPLE +$App = Get-PiHoleAuthApp -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" +Set-PiHoleConfig -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Settings @{ webserver = @{ api = @{ app_pwhash = $App.Hash } } } + +Generates a new app password and makes it the active one. From then on, use $App.Password. + #> + [CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#get-/auth/app')] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + try { + $Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl + + $Params = @{ + Headers = @{sid = $($Sid) } + Uri = "$($PiHoleServer.OriginalString)/api/auth/app" + Method = "Get" + SkipCertificateCheck = $IgnoreSsl + ContentType = "application/json" + } + + $Response = Invoke-RestMethod @Params + + if ($RawOutput) { + Write-Output $Response + } + else { + $Object = [PSCustomObject]@{ + Password = $Response.app.password + Hash = $Response.app.hash + } + Write-Output $Object + } + } + + catch { + Write-Error -Message (ConvertTo-PiHoleFriendlyErrorMessage -ErrorRecord $_) + } + + finally { + if ($Sid) { + Remove-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Sid $Sid -IgnoreSsl $IgnoreSsl + } + } +} diff --git a/PiHoleShell/Public/DnsControl/Add-PiHoleDnsRecord.ps1 b/PiHoleShell/Public/DnsControl/Add-PiHoleDnsRecord.ps1 new file mode 100644 index 0000000..d69dba1 --- /dev/null +++ b/PiHoleShell/Public/DnsControl/Add-PiHoleDnsRecord.ps1 @@ -0,0 +1,147 @@ +function Add-PiHoleDnsRecord { + <# +.SYNOPSIS +Add a local DNS record + +.DESCRIPTION +Adds a local DNS record to Pi-hole: an A record (IPv4), AAAA record (IPv6), or CNAME record. +This is a DNS-specific convenience wrapper around Add-PiHoleConfigArrayItem, which it calls +internally - using that directly is equivalent, just less discoverable for this specific case. + +.PARAMETER PiHoleServer +The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100" + +.PARAMETER Password +The API Password you generated from your PiHole server + +.PARAMETER Type +The kind of record to add: A (IPv4), AAAA (IPv6), or CNAME + +.PARAMETER Hostname +The hostname to add. For -Type A or AAAA, this is the name that resolves to the given address. +For -Type CNAME, this is the alias being created + +.PARAMETER IPv4Address +The IPv4 address -Hostname should resolve to. Required when -Type is "A" + +.PARAMETER IPv6Address +The IPv6 address -Hostname should resolve to. Required when -Type is "AAAA" + +.PARAMETER Target +The hostname -Hostname should be an alias for. Required when -Type is "CNAME" + +.PARAMETER Ttl +Optional TTL (in seconds) for a CNAME record. Only used when -Type is "CNAME" + +.PARAMETER Restart +Whether to restart FTL immediately if this change requires it. Defaults to $true. Set to +$false to defer the restart, e.g. when adding several records independently rather than all at +once - you'll need to restart FTL manually later for the changes to take effect + +.PARAMETER IgnoreSsl +Set to $true to skip SSL certificate validation + +.PARAMETER RawOutput +This will dump the response instead of the formatted object + +.EXAMPLE +Add-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type A -Hostname "test.local" -IPv4Address "192.168.1.1" + +.EXAMPLE +Add-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type AAAA -Hostname "test.local" -IPv6Address "::1" + +.EXAMPLE +Add-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type CNAME -Hostname "alias.local" -Target "test.local" -Ttl 300 + #> + [CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#put-/config/-element-/-value-')] + [Diagnostics.CodeAnalysis.SuppressMessage("PSUseShouldProcessForStateChangingFunctions", "", Justification = "Thin wrapper - Add-PiHoleConfigArrayItem (called internally) already carries this same suppression")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [Parameter(Mandatory = $true)] + [ValidateSet('A', 'AAAA', 'CNAME')] + [string]$Type, + [Parameter(Mandatory = $true)] + [string]$Hostname, + [string]$IPv4Address, + [string]$IPv6Address, + [string]$Target, + [Nullable[int]]$Ttl, + [Nullable[bool]]$Restart, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + try { + switch ($Type) { + 'A' { + if (-not $IPv4Address) { + throw "-IPv4Address is required when -Type is 'A'" + } + $ParsedAddress = $null + if (-not [System.Net.IPAddress]::TryParse($IPv4Address, [ref]$ParsedAddress) -or $ParsedAddress.AddressFamily -ne [System.Net.Sockets.AddressFamily]::InterNetwork) { + throw "'$IPv4Address' is not a valid IPv4 address" + } + $Element = 'dns/hosts' + $Value = "$IPv4Address $Hostname" + } + 'AAAA' { + if (-not $IPv6Address) { + throw "-IPv6Address is required when -Type is 'AAAA'" + } + $ParsedAddress = $null + if (-not [System.Net.IPAddress]::TryParse($IPv6Address, [ref]$ParsedAddress) -or $ParsedAddress.AddressFamily -ne [System.Net.Sockets.AddressFamily]::InterNetworkV6) { + throw "'$IPv6Address' is not a valid IPv6 address" + } + $Element = 'dns/hosts' + $Value = "$IPv6Address $Hostname" + } + 'CNAME' { + if (-not $Target) { + throw "-Target is required when -Type is 'CNAME'" + } + $Element = 'dns/cnameRecords' + $Value = "$Hostname,$Target" + if ($PSBoundParameters.ContainsKey('Ttl')) { + $Value += ",$Ttl" + } + } + } + + $InnerParams = @{ + PiHoleServer = $PiHoleServer + Password = $Password + Element = $Element + Value = $Value + IgnoreSsl = $IgnoreSsl + RawOutput = $RawOutput + } + if ($PSBoundParameters.ContainsKey('Restart')) { + $InnerParams.Restart = $Restart + } + + $Response = Add-PiHoleConfigArrayItem @InnerParams -ErrorAction Stop + + if ($RawOutput) { + Write-Output $Response + } + else { + $Object = [PSCustomObject]@{ + Type = $Type + Hostname = $Hostname + IPv4Address = $IPv4Address + IPv6Address = $IPv6Address + Target = $Target + Ttl = $Ttl + Status = $Response.Status + } + Write-Output $Object + } + } + + catch { + Write-Error -Message $_.Exception.Message + } +} diff --git a/PiHoleShell/Public/DnsControl/Get-PiHoleDnsRecord.ps1 b/PiHoleShell/Public/DnsControl/Get-PiHoleDnsRecord.ps1 new file mode 100644 index 0000000..0b98a36 --- /dev/null +++ b/PiHoleShell/Public/DnsControl/Get-PiHoleDnsRecord.ps1 @@ -0,0 +1,113 @@ +function Get-PiHoleDnsRecord { + <# +.SYNOPSIS +Get local DNS records + +.DESCRIPTION +Returns Pi-hole's local DNS records (A, AAAA, and CNAME) as a flat list of objects shaped the +same way as Add-PiHoleDnsRecord/Remove-PiHoleDnsRecord, so the result can be piped straight into +Remove-PiHoleDnsRecord. This is a DNS-specific convenience wrapper around Get-PiHoleConfig, +which it calls internally - using that directly (.Dns.Hosts / .Dns.CnameRecords) is equivalent, +just not already split into A/AAAA/CNAME or filterable by -Type/-Hostname. + +.PARAMETER PiHoleServer +The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100" + +.PARAMETER Password +The API Password you generated from your PiHole server + +.PARAMETER Type +Only return records of this kind: A (IPv4), AAAA (IPv6), or CNAME. If omitted, all are returned + +.PARAMETER Hostname +Only return the record(s) for this exact hostname (the alias, for a CNAME). If omitted, every +record is returned + +.PARAMETER IgnoreSsl +Set to $true to skip SSL certificate validation + +.PARAMETER RawOutput +This will dump the response instead of the formatted object + +.EXAMPLE +Get-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" + +.EXAMPLE +Get-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type CNAME + +.EXAMPLE +Get-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Hostname "test.local" | Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" + #> + [CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#get-/config')] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [ValidateSet('A', 'AAAA', 'CNAME')] + [string]$Type, + [string]$Hostname, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + try { + $Config = Get-PiHoleConfig -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl -ErrorAction Stop + + if ($RawOutput) { + $Object = [PSCustomObject]@{ + Hosts = $Config.Dns.Hosts + CnameRecords = $Config.Dns.CnameRecords + } + Write-Output $Object + } + else { + $Records = foreach ($Entry in $Config.Dns.Hosts) { + # Each entry is " " - hostnames never contain spaces, so splitting + # into at most 2 parts on the first space is safe even if an IPv6 address itself + # cannot contain one. + $Parts = $Entry.Split(' ', 2) + $Address = $Parts[0] + $RecordHostname = $Parts[1] + + $ParsedAddress = $null + $IsIPv6 = [System.Net.IPAddress]::TryParse($Address, [ref]$ParsedAddress) -and $ParsedAddress.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetworkV6 + + [PSCustomObject]@{ + Type = if ($IsIPv6) { 'AAAA' } else { 'A' } + Hostname = $RecordHostname + IPv4Address = if ($IsIPv6) { $null } else { $Address } + IPv6Address = if ($IsIPv6) { $Address } else { $null } + Target = $null + Ttl = $null + } + } + + $Records += foreach ($Entry in $Config.Dns.CnameRecords) { + # Each entry is ",[,]" - the TTL segment is optional. + $Parts = $Entry.Split(',') + [PSCustomObject]@{ + Type = 'CNAME' + Hostname = $Parts[0] + IPv4Address = $null + IPv6Address = $null + Target = $Parts[1] + Ttl = if ($Parts.Count -gt 2) { [int]$Parts[2] } else { $null } + } + } + + if ($PSBoundParameters.ContainsKey('Type')) { + $Records = $Records | Where-Object { $_.Type -eq $Type } + } + if ($PSBoundParameters.ContainsKey('Hostname')) { + $Records = $Records | Where-Object { $_.Hostname -eq $Hostname } + } + + Write-Output $Records + } + } + + catch { + Write-Error -Message $_.Exception.Message + } +} diff --git a/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 b/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 new file mode 100644 index 0000000..e031278 --- /dev/null +++ b/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 @@ -0,0 +1,155 @@ +function Remove-PiHoleDnsRecord { + <# +.SYNOPSIS +Remove a local DNS record + +.DESCRIPTION +Removes a local DNS record from Pi-hole: an A record (IPv4), AAAA record (IPv6), or CNAME +record. This is a DNS-specific convenience wrapper around Remove-PiHoleConfigArrayItem, which +it calls internally - using that directly is equivalent, just less discoverable for this +specific case. + +The values given must match the record exactly as it was created (see Get-PiHoleDnsRecord, or +Get-PiHoleConfig under .Dns.Hosts/.Dns.CnameRecords, to check the exact value if removal fails) - +for a CNAME record created with a TTL, -Ttl must be passed here too, with the same value. + +Accepts pipeline input by property name, so it can be chained directly from Get-PiHoleDnsRecord. + +.PARAMETER PiHoleServer +The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100" + +.PARAMETER Password +The API Password you generated from your PiHole server + +.PARAMETER Type +The kind of record to remove: A (IPv4), AAAA (IPv6), or CNAME + +.PARAMETER Hostname +The hostname of the record to remove. For -Type A or AAAA, this is the name that resolves to +the given address. For -Type CNAME, this is the alias being removed + +.PARAMETER IPv4Address +The IPv4 address the record resolves to. Required when -Type is "A" + +.PARAMETER IPv6Address +The IPv6 address the record resolves to. Required when -Type is "AAAA" + +.PARAMETER Target +The hostname the record is an alias for. Required when -Type is "CNAME" + +.PARAMETER Ttl +The TTL (in seconds) the CNAME record was created with, if any. Only used when -Type is +"CNAME" - must match exactly or the removal will not find the record + +.PARAMETER Restart +Whether to restart FTL immediately if this change requires it. Defaults to $true. Set to +$false to defer the restart, e.g. when removing several records independently rather than all +at once - you'll need to restart FTL manually later for the changes to take effect + +.PARAMETER IgnoreSsl +Set to $true to skip SSL certificate validation + +.PARAMETER RawOutput +This will dump the response instead of the formatted object + +.EXAMPLE +Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type A -Hostname "test.local" -IPv4Address "192.168.1.1" + +.EXAMPLE +Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type CNAME -Hostname "alias.local" -Target "test.local" -Ttl 300 + +.EXAMPLE +Get-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Hostname "test.local" | Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" + #> + [CmdletBinding(SupportsShouldProcess = $true, HelpUri = 'https://ftl.pi-hole.net/master/docs/#delete-/config/-element-/-value-')] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [ValidateSet('A', 'AAAA', 'CNAME')] + [string]$Type, + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [string]$Hostname, + [Parameter(ValueFromPipelineByPropertyName = $true)] + [string]$IPv4Address, + [Parameter(ValueFromPipelineByPropertyName = $true)] + [string]$IPv6Address, + [Parameter(ValueFromPipelineByPropertyName = $true)] + [string]$Target, + [Parameter(ValueFromPipelineByPropertyName = $true)] + [Nullable[int]]$Ttl, + [Nullable[bool]]$Restart, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + process { + try { + switch ($Type) { + 'A' { + if (-not $IPv4Address) { + throw "-IPv4Address is required when -Type is 'A'" + } + $Element = 'dns/hosts' + $Value = "$IPv4Address $Hostname" + } + 'AAAA' { + if (-not $IPv6Address) { + throw "-IPv6Address is required when -Type is 'AAAA'" + } + $Element = 'dns/hosts' + $Value = "$IPv6Address $Hostname" + } + 'CNAME' { + if (-not $Target) { + throw "-Target is required when -Type is 'CNAME'" + } + $Element = 'dns/cnameRecords' + $Value = "$Hostname,$Target" + if ($PSBoundParameters.ContainsKey('Ttl')) { + $Value += ",$Ttl" + } + } + } + + if ($PSCmdlet.ShouldProcess("Pi-Hole DNS record '$Value' ($Type)", "Remove DNS record")) { + $InnerParams = @{ + PiHoleServer = $PiHoleServer + Password = $Password + Element = $Element + Value = $Value + IgnoreSsl = $IgnoreSsl + RawOutput = $RawOutput + Confirm = $false + } + if ($PSBoundParameters.ContainsKey('Restart')) { + $InnerParams.Restart = $Restart + } + + $Response = Remove-PiHoleConfigArrayItem @InnerParams -ErrorAction Stop + + if ($RawOutput) { + Write-Output $Response + } + else { + $Object = [PSCustomObject]@{ + Type = $Type + Hostname = $Hostname + IPv4Address = $IPv4Address + IPv6Address = $IPv6Address + Target = $Target + Ttl = $Ttl + Status = $Response.Status + } + Write-Output $Object + } + } + } + + catch { + Write-Error -Message $_.Exception.Message + } + } +} diff --git a/README.md b/README.md index e4dac0d..0fd780d 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,10 @@ See [docs/EXAMPLES.md](docs/EXAMPLES.md) for real, captured output from every fu | Function | Description | |---|---| +| `Add-PiHoleDnsRecord` | Add a local DNS record | | `Get-PiHoleDnsBlockingStatus` | Get Pi-hole's current DNS blocking status | +| `Get-PiHoleDnsRecord` | Get local DNS records | +| `Remove-PiHoleDnsRecord` | Remove a local DNS record | | `Set-PiHoleDnsBlocking` | Enable or disable Pi-hole's DNS blocking | ### Group Management @@ -205,6 +208,7 @@ Session handling is automatic for every command above, but these are available f | Function | Description | |---|---| +| `Get-PiHoleAuthApp` | Generate a new application password | | `Get-PiHoleAuthStatus` | Check if authentication is required | | `Get-PiHoleAuthTotp` | Suggest new TOTP credentials | | `Get-PiHoleCurrentAuthSession` | List of all current sessions | diff --git a/docs/EXAMPLES.md b/docs/EXAMPLES.md index 0602c4e..ff4b693 100644 --- a/docs/EXAMPLES.md +++ b/docs/EXAMPLES.md @@ -86,6 +86,58 @@ Set-PiHoleDnsBlocking -PiHoleServer $PiHoleServer -Password $Password -Blocking _Not captured this run - re-run with -IncludeDisruptive to include a live example._ ``` +### Add-PiHoleDnsRecord + +```powershell +Add-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "piholeshell-docs-dns-example.com" -IPv4Address "192.0.2.2" +``` + +``` + +Type : A +Hostname : piholeshell-docs-dns-example.com +IPv4Address : 192.0.2.2 +IPv6Address : +Target : +Ttl : +Status : Added +``` + +### Get-PiHoleDnsRecord + +_Can be filtered with -Type and/or -Hostname, and piped directly into Remove-PiHoleDnsRecord._ + +```powershell +Get-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password +``` + +``` + +Type : A +Hostname : piholeshell-docs-dns-example.com +IPv4Address : 192.0.2.2 +IPv6Address : +Target : +Ttl : +``` + +### Remove-PiHoleDnsRecord + +```powershell +Remove-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "piholeshell-docs-dns-example.com" -IPv4Address "192.0.2.2" +``` + +``` + +Type : A +Hostname : piholeshell-docs-dns-example.com +IPv4Address : 192.0.2.2 +IPv6Address : +Target : +Ttl : +Status : Removed +``` + ## Group Management ### New-PiHoleGroup @@ -99,9 +151,9 @@ New-PiHoleGroup -PiHoleServer $PiHoleServer -Password $Password -GroupName "PiHo Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : True -Id : 63 -DateAdded : 10/6/2026 10:06:30 PM -DateModified : 10/6/2026 10:06:30 PM +Id : 45 +DateAdded : 10/19/2026 4:33:10 PM +DateModified : 10/19/2026 4:33:10 PM ``` ### Get-PiHoleGroup @@ -143,9 +195,9 @@ DateModified : 9/30/2026 8:48:26 AM Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : True -Id : 63 -DateAdded : 10/6/2026 10:06:30 PM -DateModified : 10/6/2026 10:06:30 PM +Id : 45 +DateAdded : 10/19/2026 4:33:10 PM +DateModified : 10/19/2026 4:33:10 PM ``` ### Update-PiHoleGroup @@ -159,9 +211,9 @@ Update-PiHoleGroup -PiHoleServer $PiHoleServer -Password $Password -GroupName "P Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : False -Id : 63 -DateAdded : 10/6/2026 10:06:30 PM -DateModified : 10/6/2026 10:06:48 PM +Id : 45 +DateAdded : 10/19/2026 4:33:10 PM +DateModified : 10/19/2026 4:33:28 PM ``` ### Remove-PiHoleGroup @@ -190,9 +242,9 @@ Address : https://blocklistproject.github.io/Lists/alt-version/ransomware Comment : Example list Groups : {Default} Enabled : True -Id : 81 -DateAdded : 10/6/2026 10:07:25 PM -DateModified : 10/6/2026 10:07:25 PM +Id : 65 +DateAdded : 10/19/2026 4:34:05 PM +DateModified : 10/19/2026 4:34:05 PM Type : Block DateUpdated : Number : 0 @@ -218,7 +270,7 @@ DateAdded : 7/6/2025 2:20:13 AM DateModified : 7/6/2025 2:20:13 AM Type : block DateUpdated : 7/6/2025 2:20:13 AM -Number : 72234 +Number : 71493 InvalidDomains : 1 AbpEntries : 0 Status : 2 @@ -246,7 +298,7 @@ DateAdded : 7/6/2025 2:20:46 AM DateModified : 7/6/2025 2:20:46 AM Type : block DateUpdated : 7/6/2025 2:20:46 AM -Number : 176582 +Number : 185427 InvalidDomains : 0 AbpEntries : 0 Status : 2 @@ -294,9 +346,9 @@ Address : https://blocklistproject.github.io/Lists/alt-version/ransomware Comment : Example list Groups : {Default} Enabled : False -Id : 81 -DateAdded : 10/6/2026 10:07:25 PM -DateModified : 10/6/2026 10:07:58 PM +Id : 65 +DateAdded : 10/19/2026 4:34:05 PM +DateModified : 10/19/2026 4:34:39 PM Type : Block DateUpdated : Number : 0 @@ -322,8 +374,8 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:13 AM DateModified : 7/6/2025 2:20:13 AM -DateUpdated : 10/2/2026 9:10:24 PM -Number : 72234 +DateUpdated : 10/18/2026 10:04:20 PM +Number : 71493 InvalidDomains : 1 AbpEntries : 0 Status : 2 @@ -337,7 +389,7 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:40 AM DateModified : 7/6/2025 2:20:40 AM -DateUpdated : 7/6/2025 2:25:21 AM +DateUpdated : 10/17/2026 10:41:38 AM Number : 6540 InvalidDomains : 0 AbpEntries : 0 @@ -352,8 +404,8 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:46 AM DateModified : 7/6/2025 2:20:46 AM -DateUpdated : 10/2/2026 9:43:40 AM -Number : 176582 +DateUpdated : 10/19/2026 4:24:30 PM +Number : 185427 InvalidDomains : 0 AbpEntries : 0 Status : 2 @@ -367,7 +419,7 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:59 AM DateModified : 7/6/2025 2:20:59 AM -DateUpdated : 12/27/2025 9:28:21 PM +DateUpdated : 10/17/2026 10:41:52 AM Number : 42531 InvalidDomains : 0 AbpEntries : 0 @@ -382,7 +434,7 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:21:09 AM DateModified : 7/6/2025 2:21:09 AM -DateUpdated : 6/6/2026 11:13:26 PM +DateUpdated : 10/17/2026 10:41:55 AM Number : 2700 InvalidDomains : 0 AbpEntries : 0 @@ -421,9 +473,9 @@ Kind : Exact Comment : Example domain Groups : {Default} Enabled : True -Id : 18 -DateAdded : 10/6/2026 10:08:36 PM -DateModified : 10/6/2026 10:08:36 PM +Id : 1 +DateAdded : 10/19/2026 4:35:17 PM +DateModified : 10/19/2026 4:35:17 PM ``` ### Get-PiHoleDomain @@ -441,9 +493,9 @@ Kind : exact Comment : Example domain Groups : {Default} Enabled : True -Id : 18 -DateAdded : 10/6/2026 10:08:36 PM -DateModified : 10/6/2026 10:08:36 PM +Id : 1 +DateAdded : 10/19/2026 4:35:17 PM +DateModified : 10/19/2026 4:35:17 PM ``` ### Update-PiHoleDomain @@ -461,9 +513,9 @@ Kind : Exact Comment : Example domain Groups : {Default} Enabled : False -Id : 18 -DateAdded : 10/6/2026 10:08:36 PM -DateModified : 10/6/2026 10:09:10 PM +Id : 1 +DateAdded : 10/19/2026 4:35:17 PM +DateModified : 10/19/2026 4:35:51 PM ``` ### Remove-PiHoleDomain @@ -494,9 +546,9 @@ Client : 192.168.99.99 Name : Comment : Example client Groups : {Default} -Id : 20 -DateAdded : 10/6/2026 10:09:40 PM -DateModified : 10/6/2026 10:09:40 PM +Id : 1 +DateAdded : 10/19/2026 4:36:21 PM +DateModified : 10/19/2026 4:36:21 PM ``` ### Get-PiHoleClient @@ -511,9 +563,9 @@ Client : 192.168.99.99 Name : Comment : Example client Groups : {Default} -Id : 20 -DateAdded : 10/6/2026 10:09:40 PM -DateModified : 10/6/2026 10:09:40 PM +Id : 1 +DateAdded : 10/19/2026 4:36:21 PM +DateModified : 10/19/2026 4:36:21 PM ``` ### Get-PiHoleClientSuggestion @@ -524,16 +576,22 @@ Get-PiHoleClientSuggestion -PiHoleServer $PiHoleServer -Password $Password ``` -HwAddr : ip-127.0.0.1 -MacVendor : -LastQuery : 10/6/2026 10:06:14 PM -Addresses : 127.0.0.1 +HwAddr : 00:00:00:00:00:00 +MacVendor : virtual interface +LastQuery : 10/19/2026 4:32:55 PM +Addresses : 127.0.0.1,::1,0.0.0.0 Names : localhost HwAddr : 74:56:3c:bb:f4:0b MacVendor : Giga-Byte Technology Co.,Ltd. -LastQuery : 10/6/2026 10:03:16 PM +LastQuery : 10/18/2026 11:01:25 PM Addresses : 192.168.1.162 +Names : + +HwAddr : b8:27:eb:11:a4:d5 +MacVendor : Raspberry Pi Foundation +LastQuery : 12/31/1969 6:00:00 PM +Addresses : 192.168.1.248,fe80::ba27:ebff:fe11:a4d5 Names : ``` @@ -549,9 +607,9 @@ Client : 192.168.99.99 Name : Comment : Updated comment Groups : {Default} -Id : 20 -DateAdded : 10/6/2026 10:09:40 PM -DateModified : 10/6/2026 10:10:18 PM +Id : 1 +DateAdded : 10/19/2026 4:36:21 PM +DateModified : 10/19/2026 4:37:00 PM ``` ### Remove-PiHoleClient @@ -576,18 +634,18 @@ Get-PiHoleStatsSummary -PiHoleServer $PiHoleServer -Password $Password ``` -Total : 72 -Blocked : 8 -PercentBlocked : 11.1111106872559 -UniqueDomains : 16 -Forwarded : 27 -Cached : 37 +Total : 311 +Blocked : 88 +PercentBlocked : 28.2958202362061 +UniqueDomains : 22 +Forwarded : 37 +Cached : 186 Frequency : 0 -Types : @{A=18; AAAA=17; ANY=0; SRV=0; SOA=0; PTR=37; TXT=0; NAPTR=0; MX=0; DS=0; RRSIG=0; DNSKEY=0; NS=0; SVCB=0; HTTPS=0; OTHER=0} -Status : @{Unknown=0; Gravity=8; Forwarded=27; Cache=37; Regex=0; DenyList=0; ExternalBlockedIp=0; ExternalBlockedNull=0; ExternalBlockedNxra=0; GravityCname=0; RegexCname=0; DenyListCname=0; Retired=0; RetiredDnssec=0; InProgress=0; Dbbusy=0; SpecialDomain=0; CacheStale=0; ExternalBlockedEde15=0} -Replies : @{Unknown=7; Nodata=3; Nxdomain=2; Cname=0; Ip=25; Domain=35; Rrname=0; ServFail=0; Refused=0; Notimp=0; Other=0; Dnssec=0; None=0; Blob=0} +Types : @{A=137; AAAA=137; ANY=0; SRV=0; SOA=0; PTR=37; TXT=0; NAPTR=0; MX=0; DS=0; RRSIG=0; DNSKEY=0; NS=0; SVCB=0; HTTPS=0; OTHER=0} +Status : @{Unknown=0; Gravity=88; Forwarded=37; Cache=154; Regex=0; DenyList=0; ExternalBlockedIp=0; ExternalBlockedNull=0; ExternalBlockedNxra=0; GravityCname=0; RegexCname=0; DenyListCname=0; Retired=0; RetiredDnssec=0; InProgress=0; Dbbusy=0; SpecialDomain=0; CacheStale=32; ExternalBlockedEde15=0} +Replies : @{Unknown=9; Nodata=16; Nxdomain=6; Cname=0; Ip=249; Domain=31; Rrname=0; ServFail=0; Refused=0; Notimp=0; Other=0; Dnssec=0; None=0; Blob=0} Clients : @{Active=2; Total=2} -Gravity : @{DomainsBeingBlocked=526957; LastUpdate=1791140144} +Gravity : @{DomainsBeingBlocked=585338; LastUpdate=1792445332} ``` ### Get-PiHoleStatsRecentBlocked @@ -598,7 +656,7 @@ Get-PiHoleStatsRecentBlocked -PiHoleServer $PiHoleServer -Password $Password ``` -Blocked : googlesyndication.com +Blocked : googleadservices.com ``` ### Get-PiHoleStatsQueryType @@ -610,10 +668,10 @@ Get-PiHoleStatsQueryType -PiHoleServer $PiHoleServer -Password $Password ``` Type : A -Count : 18 +Count : 137 Type : AAAA -Count : 17 +Count : 137 Type : ANY Count : 0 @@ -635,20 +693,20 @@ Get-PiHoleStatsTopDomain -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : 1.0.0.127.in-addr.arpa -Count : 31 +Domain : cloudflare.com +Count : 22 -Domain : bbc.com -Count : 4 +Domain : 1.0.0.127.in-addr.arpa +Count : 21 -Domain : example.com -Count : 4 +Domain : apple.com +Count : 20 -Domain : python.org -Count : 4 +Domain : reddit.com +Count : 20 Domain : wikipedia.org -Count : 4 +Count : 18 _(showing 5 of 10 results)_ ``` @@ -661,13 +719,13 @@ Get-PiHoleStatsTopClient -PiHoleServer $PiHoleServer -Password $Password ``` +IP : 192.168.1.162 +Name : +Count : 274 + IP : 127.0.0.1 Name : localhost Count : 37 - -IP : 192.168.1.162 -Name : -Count : 35 ``` ### Get-PiHoleStatsUpstream @@ -678,9 +736,9 @@ Get-PiHoleStatsUpstream -PiHoleServer $PiHoleServer -Password $Password ``` -TotalQueries : 72 -ForwardedQueries : 27 -Upstreams : {@{Ip=blocklist; Name=blocklist; Port=-1; Count=8; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=37; ResponseTime=0; Variance=0}, @{Ip=8.8.4.4; Name=dns.google; Port=53; Count=23; ResponseTime=0; Variance=0}, @{Ip=8.8.8.8; Name=dns.google; Port=53; Count=4; ResponseTime=0; Variance=0}} +TotalQueries : 311 +ForwardedQueries : 37 +Upstreams : {@{Ip=blocklist; Name=blocklist; Port=-1; Count=88; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=186; ResponseTime=0; Variance=0}, @{Ip=8.8.8.8; Name=; Port=53; Count=32; ResponseTime=0; Variance=0}, @{Ip=8.8.4.4; Name=; Port=53; Count=5; ResponseTime=0; Variance=0}} ``` ### Get-PiHoleStatsQuerySuggestions @@ -691,10 +749,10 @@ Get-PiHoleStatsQuerySuggestions -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : {1.0.0.127.in-addr.arpa, bbc.com, example.com, python.org…} -ClientIp : {127.0.0.1, 192.168.1.162} +Domain : {cloudflare.com, 1.0.0.127.in-addr.arpa, apple.com, reddit.com…} +ClientIp : {192.168.1.162, 127.0.0.1} ClientName : {localhost} -Upstream : {blocklist, cache, 8.8.4.4#53 (dns.google), 8.8.8.8#53 (dns.google)…} +Upstream : {blocklist, cache, 8.8.8.8#53, 8.8.4.4#53…} Type : {A, AAAA, ANY, SRV…} Status : {UNKNOWN, GRAVITY, FORWARDED, CACHE…} Reply : {UNKNOWN, NODATA, NXDOMAIN, CNAME…} @@ -711,10 +769,10 @@ Get-PiHoleStatsDatabaseSummary -PiHoleServer $PiHoleServer -Password $Password ``` -SumQueries : 56 -SumBlocked : 8 -PercentBlocked : 14.2857141494751 -TotalClients : 2 +SumQueries : 10 +SumBlocked : 0 +PercentBlocked : 0 +TotalClients : 1 ``` ### Get-PiHoleStatsDatabaseQueryType @@ -728,7 +786,7 @@ Get-PiHoleStatsDatabaseQueryType -PiHoleServer $PiHoleServer -Password $Password ``` Type : A -Count : 17 +Count : 0 Type : AAAA Count : 0 @@ -740,7 +798,7 @@ Type : SRV Count : 0 Type : SOA -Count : 21 +Count : 0 _(showing 5 of 16 results)_ ``` @@ -756,21 +814,10 @@ Get-PiHoleStatsDatabaseTopDomain -PiHoleServer $PiHoleServer -Password $Password ``` Domain : 1.0.0.127.in-addr.arpa -Count : 15 +Count : 9 -Domain : python.org -Count : 4 - -Domain : bbc.com -Count : 4 - -Domain : wikipedia.org -Count : 4 - -Domain : example.com -Count : 4 - -_(showing 5 of 10 results)_ +Domain : 162.1.168.192.in-addr.arpa +Count : 1 ``` ### Get-PiHoleStatsDatabaseTopClient @@ -783,13 +830,9 @@ Get-PiHoleStatsDatabaseTopClient -PiHoleServer $PiHoleServer -Password $Password ``` -IP : 192.168.1.162 -Name : -Count : 27 - IP : 127.0.0.1 Name : localhost -Count : 21 +Count : 10 ``` ### Get-PiHoleStatsDatabaseUpstream @@ -802,9 +845,9 @@ Get-PiHoleStatsDatabaseUpstream -PiHoleServer $PiHoleServer -Password $Password ``` -TotalQueries : 56 -ForwardedQueries : 27 -Upstreams : {@{Ip=1; Name=; Port=-1; Count=23; ResponseTime=0; Variance=0}, @{Ip=2; Name=; Port=-1; Count=4; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=21; ResponseTime=0; Variance=0}, @{Ip=blocklist; Name=blocklist; Port=-1; Count=8; ResponseTime=0; Variance=0}} +TotalQueries : 10 +ForwardedQueries : 0 +Upstreams : {@{Ip=cache; Name=cache; Port=-1; Count=10; ResponseTime=0; Variance=0}, @{Ip=blocklist; Name=blocklist; Port=-1; Count=0; ResponseTime=0; Variance=0}} ``` ### Get-PiHoleQuery @@ -817,69 +860,69 @@ Get-PiHoleQuery -PiHoleServer $PiHoleServer -Password $Password -Length 5 ``` -Id : 394 -Time : 10/6/2026 10:06:15 PM +Id : 688 +Time : 10/19/2026 4:32:56 PM Type : PTR -Domain : 4.4.8.8.in-addr.arpa +Domain : 1.0.0.127.in-addr.arpa Cname : -Status : FORWARDED +Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0241849422454834} +Reply : @{Type=DOMAIN; Time=0.00135612487792969} ListId : -Upstream : 8.8.8.8#53 +Upstream : Ede : @{Code=-1; Text=} -Id : 393 -Time : 10/6/2026 10:06:15 PM +Id : 687 +Time : 10/19/2026 4:32:56 PM Type : PTR -Domain : 8.8.8.8.in-addr.arpa +Domain : 162.1.168.192.in-addr.arpa Cname : -Status : FORWARDED +Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0249054431915283} +Reply : @{Type=NXDOMAIN; Time=0.0235791206359863} ListId : -Upstream : 8.8.8.8#53 +Upstream : Ede : @{Code=-1; Text=} -Id : 392 -Time : 10/6/2026 10:06:15 PM +Id : 686 +Time : 10/19/2026 4:00:01 PM Type : PTR -Domain : 162.1.168.192.in-addr.arpa +Domain : 1.0.0.127.in-addr.arpa Cname : Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=NXDOMAIN; Time=0.0157008171081543} +Reply : @{Type=DOMAIN; Time=0.000164031982421875} ListId : Upstream : Ede : @{Code=-1; Text=} -Id : 391 -Time : 10/6/2026 10:06:15 PM +Id : 685 +Time : 10/19/2026 3:00:01 PM Type : PTR Domain : 1.0.0.127.in-addr.arpa Cname : Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0260829925537109} +Reply : @{Type=DOMAIN; Time=0.000163078308105469} ListId : Upstream : Ede : @{Code=-1; Text=} -Id : 390 -Time : 10/6/2026 10:03:17 PM +Id : 684 +Time : 10/19/2026 2:00:00 PM Type : PTR -Domain : 4.4.8.8.in-addr.arpa +Domain : 1.0.0.127.in-addr.arpa Cname : -Status : FORWARDED +Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0180368423461914} +Reply : @{Type=DOMAIN; Time=0.000160932540893555} ListId : -Upstream : 8.8.4.4#53 +Upstream : Ede : @{Code=-1; Text=} ``` @@ -992,20 +1035,20 @@ CpuPercent : 0 MemoryPercent : 0 ActiveClients : 2 Blocking : enabled -Cache : @{Size=10000; Inserted=34; Evicted=0} +Cache : @{Size=10000; Inserted=2; Evicted=0} Config : @{DhcpActive=False; DhcpStart=; DhcpEnd=; DhcpIpv6=False; DnsDnssec=False; DnsDomain=lan; DnsNumUpstreams=2; DnsPort=53; DnsrevServerAactive=False; PrivacyLevel=0} -GravitySize : 526957 +GravitySize : 585338 HostModel : Raspberry Pi Zero W Rev 1.1 IFace : @{v4=; v6=} NodeName : dns3.localdomain -Pid : 389 -Queries : @{Total=69; Blocked=8; PercentBlocked=11.5942029953003; QueryFrequency=0} -RecentBlocked : googlesyndication.com +Pid : 392 +Queries : @{Total=309; Blocked=88; PercentBlocked=28.4789638519287; QueryFrequency=0} +RecentBlocked : googleadservices.com Sensors : @{CpuTemp=40.622; HotLimit=60; Unit=C} -System : @{Uptime=384699; Memory=; Procs=70; Cpu=; Ftl=} -TopBlocked : analytics.google.com +System : @{Uptime=169898; Memory=; Procs=73; Cpu=; Ftl=} +TopBlocked : googleadservices.com TopClient : 192.168.1.162 -TopDomain : 1.0.0.127.in-addr.arpa +TopDomain : cloudflare.com Version : @{Core=; Web=; Ftl=; Docker=} ``` @@ -1042,11 +1085,11 @@ Get-PiHoleInfoSystem -PiHoleServer $PiHoleServer -Password $Password ``` -Uptime : 384709 +Uptime : 169908 Memory : @{Ram=; Swap=} -Procs : 70 -Cpu : @{NumProcessors=1; PercentCpu=96.8000030517578; Load=} -Ftl : @{PercentMemory=3.02243185043335; PercentCpu=96.5} +Procs : 72 +Cpu : @{NumProcessors=1; PercentCpu=97.0999984741211; Load=} +Ftl : @{PercentMemory=2.38621687889099; PercentCpu=96.3000030517578} ``` ### Get-PiHoleInfoFtl @@ -1057,16 +1100,16 @@ Get-PiHoleInfoFtl -PiHoleServer $PiHoleServer -Password $Password ``` -Database : @{Gravity=526957; Antigravity=0; Groups=4; Lists=14; Clients=0; Domains=; Regex=} +Database : @{Gravity=585338; Antigravity=0; Groups=4; Lists=14; Clients=0; Domains=; Regex=} PrivacyLevel : 0 QueryFrequency : 0 Clients : @{Total=2; Active=2} -Pid : 389 -Uptime : 528324.275473 -PercentMemory : 3.02243185043335 -PercentCpu : 96.5 +Pid : 392 +Uptime : 62980865.090079 +PercentMemory : 2.38621687889099 +PercentCpu : 96.3000030517578 AllowDestructive : True -Dnsmasq : @{DnsCacheInserted=34; DnsCacheLiveFreed=0; DnsQueriesForwarded=25; DnsAuthAnswered=0; DnsLocalAnswered=15; DnsStaleAnswered=0; DnsUnanswered=0; DnssecMaxCryptoUse=0; DnssecMaxSigFail=0; DnssecMaxWork=0; Bootp=0; Pxe=0; DhcpAck=0; DhcpDecline=0; DhcpDiscover=0; DhcpInform=0; DhcpNak=0; DhcpOffer=0; DhcpRelease=0; DhcpRequest=0; Noanswer=0; LeasesAllocated4=0; LeasesPruned4=0; LeasesAllocated6=0; LeasesPruned6=0; TcpConnections=0; DhcpLeasequery=0; DhcpLeaseUnassigned=0; DhcpLeaseActve=0; DhcpLeaseUnknown=0} +Dnsmasq : @{DnsCacheInserted=2; DnsCacheLiveFreed=0; DnsQueriesForwarded=2; DnsAuthAnswered=0; DnsLocalAnswered=25; DnsStaleAnswered=0; DnsUnanswered=0; DnssecMaxCryptoUse=0; DnssecMaxSigFail=0; DnssecMaxWork=0; Bootp=0; Pxe=0; DhcpAck=0; DhcpDecline=0; DhcpDiscover=0; DhcpInform=0; DhcpNak=0; DhcpOffer=0; DhcpRelease=0; DhcpRequest=0; Noanswer=0; LeasesAllocated4=0; LeasesPruned4=0; LeasesAllocated6=0; LeasesPruned6=0; TcpConnections=0; DhcpLeasequery=0; DhcpLeaseUnassigned=0; DhcpLeaseActve=0; DhcpLeaseUnknown=0} ``` ### Get-PiHoleInfoSensors @@ -1078,7 +1121,7 @@ Get-PiHoleInfoSensors -PiHoleServer $PiHoleServer -Password $Password ``` List : {@{Name=cpu_thermal; Path=hwmon0; Source=devices/virtual/thermal/thermal_zone0; Temps=}, @{Name=rpi_volt; Path=hwmon1; Source=devices/platform/soc/soc:firmware/raspberrypi-hwmon; Temps=}} -CpuTemp : 41.16 +CpuTemp : 40.622 HotLimit : 60 Unit : C ``` @@ -1095,14 +1138,14 @@ Size : 13983744 Type : Regular file Mode : rw-r----- AccessTime : 6/25/2025 12:32:44 AM -ModifiedTime : 10/6/2026 9:56:20 PM -ChangeTime : 10/6/2026 9:56:20 PM +ModifiedTime : 10/19/2026 2:02:00 PM +ChangeTime : 10/19/2026 2:02:00 PM Owner : @{User=; Group=} -Queries : 69 -EarliestTimestamp : 10/5/2026 10:00:00 PM -QueriesDisk : 391 -EarliestTimestampDisk : 10/4/2026 2:31:09 PM -SqliteVersion : 3.53.1 +Queries : 309 +EarliestTimestamp : 10/18/2026 4:30:00 PM +QueriesDisk : 336 +EarliestTimestampDisk : 10/16/2026 11:00:01 PM +SqliteVersion : 3.53.3 ``` ### Get-PiHoleInfoVersion @@ -1168,7 +1211,18 @@ Get-PiHoleInfoMessage -PiHoleServer $PiHoleServer -Password $Password ``` ``` -(no output) + +Id : 1 +Timestamp : 10/18/2026 11:02:08 PM +Type : LOAD +Plain : Long-term load (15min avg) larger than number of processors: 1.0 > 1 +Html : Long-term load (15min avg) larger than number of processors: 1.0 > 1
This may slow down DNS resolution and can cause bottlenecks. + +Id : 2 +Timestamp : 10/19/2026 4:22:33 PM +Type : LIST +Plain : List with ID 53 (https://v.firebog.net/hosts/AdguardDNS.txt) was inaccessible during last gravity run +Html : List with ID 53 (https://v.firebog.net/hosts/AdguardDNS.txt) was inaccessible during last gravity run ``` ### Get-PiHoleInfoMessageCount @@ -1179,7 +1233,7 @@ Get-PiHoleInfoMessageCount -PiHoleServer $PiHoleServer -Password $Password ``` -Count : 0 +Count : 2 ``` ### Remove-PiHoleInfoMessage @@ -1203,9 +1257,9 @@ Get-PiHoleLogWebserver -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/6/2026 9:56:22 PM; Message=Initializing HTTP server on ports "8089,8489s"; Priority=}, @{Timestamp=10/6/2026 10:04:28 PM; Message=ACCESS: 192.168.1.162 - - [07/Oct/2026:03:04:27 +0000] "PATCH /api/config?restart=false HTTP/1.1" 200 4588 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/6/2026 10:04:29 PM; Message=ACCESS: 192.168.1.162 - - [07/Oct/2026:03:04:28 +0000] "DELETE /api/auth HTTP/1.1" 204 558 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/6/2026 10:04:33 PM; Message=ACCESS: 192.168.1.162 - - [07/Oct/2026:03:04:28 +0000] "POST /api/auth HTTP/1.1" 200 808 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}} +Log : {@{Timestamp=10/18/2026 11:02:09 PM; Message=Initializing HTTP server on ports "8089,8489s"; Priority=}, @{Timestamp=10/19/2026 4:30:47 PM; Message=ACCESS: 192.168.1.162 - - [19/Oct/2026:21:30:46 +0000] "PATCH /api/config?restart=false HTTP/1.1" 200 4589 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/19/2026 4:30:47 PM; Message=ACCESS: 192.168.1.162 - - [19/Oct/2026:21:30:46 +0000] "DELETE /api/auth HTTP/1.1" 204 624 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/19/2026 4:30:51 PM; Message=ACCESS: 192.168.1.162 - - [19/Oct/2026:21:30:47 +0000] "POST /api/auth HTTP/1.1" 200 808 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}} NextID : 4 -Pid : 389 +Pid : 392 File : /var/log/pihole/webserver.log ``` @@ -1217,9 +1271,9 @@ Get-PiHoleLogDnsmasq -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/6/2026 9:56:22 PM; Message=started, version pi-hole-v2.93 cachesize 10000; Priority=}, @{Timestamp=10/6/2026 9:56:22 PM; Message=DNS service limited to local subnets; Priority=}, @{Timestamp=10/6/2026 9:56:22 PM; Message=compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth DNSSEC loop-detect inotify dumpfile; Priority=}, @{Timestamp=10/6/2026 9:56:22 PM; Message=using nameserver 8.8.8.8#53; Priority=}…} -NextID : 21 -Pid : 389 +Log : {@{Timestamp=10/18/2026 11:02:09 PM; Message=started, version pi-hole-v2.93+30 cachesize 10000; Priority=}, @{Timestamp=10/18/2026 11:02:09 PM; Message=DNS service limited to local subnets; Priority=}, @{Timestamp=10/18/2026 11:02:09 PM; Message=compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth DNSSEC loop-detect inotify dumpfile; Priority=}, @{Timestamp=10/18/2026 11:02:09 PM; Message=using nameserver 8.8.8.8#53; Priority=}…} +NextID : 27 +Pid : 392 File : /var/log/pihole/pihole.log ``` @@ -1231,9 +1285,9 @@ Get-PiHoleLogFtl -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/6/2026 9:56:21 PM; Message=PID of FTL process: 389; Priority=INFO}, @{Timestamp=10/6/2026 9:56:21 PM; Message=listening on 0.0.0.0 port 53; Priority=INFO}, @{Timestamp=10/6/2026 9:56:21 PM; Message=listening on :: port 53; Priority=INFO}, @{Timestamp=10/6/2026 9:56:21 PM; Message=Database version is 22; Priority=INFO}…} -NextID : 109 -Pid : 389 +Log : {@{Timestamp=10/18/2026 11:02:07 PM; Message=PID of FTL process: 392; Priority=INFO}, @{Timestamp=10/18/2026 11:02:07 PM; Message=listening on 0.0.0.0 port 53; Priority=INFO}, @{Timestamp=10/18/2026 11:02:07 PM; Message=listening on :: port 53; Priority=INFO}, @{Timestamp=10/18/2026 11:02:07 PM; Message=Database version is 22; Priority=INFO}…} +NextID : 180 +Pid : 392 File : /var/log/pihole/FTL.log ``` @@ -1274,31 +1328,31 @@ Get-PiHoleHistory -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/5/2026 10:15:00 PM +Timestamp : 10/18/2026 4:35:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/5/2026 10:25:00 PM +Timestamp : 10/18/2026 4:45:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/5/2026 10:35:00 PM +Timestamp : 10/18/2026 4:55:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/5/2026 10:45:00 PM +Timestamp : 10/18/2026 5:05:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/5/2026 10:55:00 PM +Timestamp : 10/18/2026 5:15:00 PM Total : 0 Cached : 0 Blocked : 0 @@ -1315,20 +1369,20 @@ Get-PiHoleHistoryClient -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/5/2026 10:15:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/18/2026 4:35:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/5/2026 10:25:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/18/2026 4:45:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/5/2026 10:35:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/18/2026 4:55:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/5/2026 10:45:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/18/2026 5:05:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/5/2026 10:55:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/18/2026 5:15:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} _(showing 5 of 145 results)_ ``` @@ -1343,37 +1397,37 @@ Get-PiHoleHistoryDatabase -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/6/2026 3:00:00 PM +Timestamp : 10/19/2026 9:00:00 AM Total : 1 Cached : 1 Blocked : 0 Forwarded : 0 -Timestamp : 10/6/2026 4:00:00 PM +Timestamp : 10/19/2026 10:00:00 AM Total : 1 Cached : 1 Blocked : 0 Forwarded : 0 -Timestamp : 10/6/2026 5:00:00 PM +Timestamp : 10/19/2026 11:00:00 AM Total : 1 Cached : 1 Blocked : 0 Forwarded : 0 -Timestamp : 10/6/2026 6:00:00 PM +Timestamp : 10/19/2026 12:00:00 PM Total : 1 Cached : 1 Blocked : 0 Forwarded : 0 -Timestamp : 10/6/2026 7:00:00 PM +Timestamp : 10/19/2026 1:00:00 PM Total : 1 Cached : 1 Blocked : 0 Forwarded : 0 -_(showing 5 of 10 results)_ +_(showing 5 of 9 results)_ ``` ### Get-PiHoleHistoryDatabaseClient @@ -1386,22 +1440,22 @@ Get-PiHoleHistoryDatabaseClient -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/6/2026 10:00:00 PM -Clients : {@{ClientId=5; Count=1}, @{ClientId=3; Count=1}} +Timestamp : 10/19/2026 4:30:00 PM +Clients : @{ClientId=127.0.0.1; Count=2} -Timestamp : 10/6/2026 9:50:00 PM -Clients : @{ClientId=3; Count=1} +Timestamp : 10/19/2026 4:00:00 PM +Clients : @{ClientId=127.0.0.1; Count=1} -Timestamp : 10/6/2026 9:40:00 PM -Clients : @{ClientId=3; Count=1} +Timestamp : 10/19/2026 3:00:00 PM +Clients : @{ClientId=127.0.0.1; Count=1} -Timestamp : 10/6/2026 9:00:00 PM -Clients : @{ClientId=3; Count=1} +Timestamp : 10/19/2026 2:00:00 PM +Clients : @{ClientId=127.0.0.1; Count=1} -Timestamp : 10/6/2026 8:00:00 PM -Clients : @{ClientId=3; Count=1} +Timestamp : 10/19/2026 1:00:00 PM +Clients : @{ClientId=127.0.0.1; Count=1} -_(showing 5 of 10 results)_ +_(showing 5 of 9 results)_ ``` ### Get-PiHoleNetworkGateway @@ -1497,7 +1551,7 @@ ProtoDown : False Address : 00:00:00:00:00:00 Broadcast : 00:00:00:00:00:00 Stats : @{RxBytes=; TxBytes=; Bits=64} -Addresses : {@{Family=inet; Scope=host; Flags=permanent; Prefixlen=8; Address=127.0.0.1; AddressType=loopback; Local=127.0.0.1; LocalType=loopback; Label=lo; Prefered=4294967295; Valid=4294967295; Cstamp=1790957600.02; Tstamp=1790957600.02}, @{Family=inet6; Scope=host; Flags=permanent; Prefixlen=128; Address=::1; AddressType=loopback; Prefered=4294967295; Valid=4294967295; Cstamp=1790957600.02; Tstamp=1790957600.02}} +Addresses : {@{Family=inet; Scope=host; Flags=permanent; Prefixlen=8; Address=127.0.0.1; AddressType=loopback; Local=127.0.0.1; LocalType=loopback; Label=lo; Prefered=4294967295; Valid=4294967295; Cstamp=1792275601.02; Tstamp=1792275601.02}, @{Family=inet6; Scope=host; Flags=permanent; Prefixlen=128; Address=::1; AddressType=loopback; Prefered=4294967295; Valid=4294967295; Cstamp=1792275601.02; Tstamp=1792275601.02}} Name : wlan0 Speed : @@ -1510,7 +1564,7 @@ Address : b8:27:eb:11:a4:d5 Broadcast : ff:ff:ff:ff:ff:ff PermAddress : b8:27:eb:11:a4:d5 Stats : @{RxBytes=; TxBytes=; Bits=64} -Addresses : {@{Family=inet; Scope=universe; Flags=; Prefixlen=24; Address=192.168.1.248; AddressType=private; Local=192.168.1.248; LocalType=private; Broadcast=192.168.1.255; BroadcastType=private; Label=wlan0; Prefered=62449; Valid=62449; Cstamp=1790957620.44; Tstamp=1791318773.93}, @{Family=inet6; Scope=link; Flags=permanent; Prefixlen=64; Address=fe80::ba27:ebff:fe11:a4d5; AddressType=link-local (LL); Prefered=4294967295; Valid=4294967295; Cstamp=1790957619.8; Tstamp=1790957619.8}} +Addresses : {@{Family=inet; Scope=universe; Flags=; Prefixlen=24; Address=192.168.1.248; AddressType=private; Local=192.168.1.248; LocalType=private; Broadcast=192.168.1.255; BroadcastType=private; Label=wlan0; Prefered=63207; Valid=63207; Cstamp=1792275626.13; Tstamp=1792422734.72}, @{Family=inet6; Scope=link; Flags=permanent; Prefixlen=64; Address=fe80::ba27:ebff:fe11:a4d5; AddressType=link-local (LL); Prefered=4294967295; Valid=4294967295; Cstamp=1792275620.88; Tstamp=1792275620.88}} ``` ### Get-PiHoleNetworkDevice @@ -1523,23 +1577,32 @@ Get-PiHoleNetworkDevice -PiHoleServer $PiHoleServer -Password $Password ``` -Id : 2 -HwAddr : ip-127.0.0.1 +Id : 1 +HwAddr : 00:00:00:00:00:00 Interface : lo -FirstSeen : 10/4/2026 2:31:10 PM -LastQuery : 10/6/2026 10:06:14 PM -NumQueries : 82 -MacVendor : -Ips : @{Ip=127.0.0.1; Name=localhost; LastSeen=10/6/2026 10:12:00 PM; NameUpdated=10/6/2026 10:12:00 PM} +FirstSeen : 10/18/2026 10:04:00 PM +LastQuery : 10/19/2026 4:32:55 PM +NumQueries : 40 +MacVendor : virtual interface +Ips : {@{Ip=127.0.0.1; Name=localhost; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=10/19/2026 4:38:00 PM}, @{Ip=::1; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM}, @{Ip=0.0.0.0; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM}} -Id : 1 +Id : 3 HwAddr : 74:56:3c:bb:f4:0b Interface : wlan0 -FirstSeen : 10/4/2026 2:31:09 PM -LastQuery : 10/6/2026 10:03:16 PM -NumQueries : 318 +FirstSeen : 10/18/2026 10:46:44 PM +LastQuery : 10/18/2026 11:01:25 PM +NumQueries : 276 MacVendor : Giga-Byte Technology Co.,Ltd. -Ips : @{Ip=192.168.1.162; Name=; LastSeen=10/6/2026 10:12:00 PM; NameUpdated=12/31/1969 6:00:00 PM} +Ips : @{Ip=192.168.1.162; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM} + +Id : 2 +HwAddr : b8:27:eb:11:a4:d5 +Interface : wlan0 +FirstSeen : 10/18/2026 10:04:00 PM +LastQuery : 12/31/1969 6:00:00 PM +NumQueries : 0 +MacVendor : Raspberry Pi Foundation +Ips : {@{Ip=192.168.1.248; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM}, @{Ip=fe80::ba27:ebff:fe11:a4d5; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM}} ``` ### Remove-PiHoleNetworkDevice @@ -1592,8 +1655,8 @@ Get-PiHoleAuthStatus -PiHoleServer $PiHoleServer -Password $Password Valid : True Totp : False -Sid : +dfslUHafhrdo0TwRT5nxQ= -Csrf : Em6pqkbJ6cuWxjQw7EtUFw= +Sid : 1egtS0Zh/fgaBQSwCPexMw= +Csrf : 40b4sKeZDafsAQC+j7t1JA= Validity : 1800 Message : correct password ``` @@ -1613,8 +1676,22 @@ Algorithm : SHA1 Digits : 6 Period : 30 Offset : 0 -Secret : EG7DLOTZKTQWIRWBFR2JJLS5Q3BYNUN3 -Codes : {201435, 619358, 736784, 226002…} +Secret : Q5K6L2DLLM65JSATZ7HU7LHC7W677747 +Codes : {619655, 185583, 505198, 995412…} +``` + +### Get-PiHoleAuthApp + +_This only generates a password. It was never activated on the test server, so it is safe to show here._ + +```powershell +Get-PiHoleAuthApp -PiHoleServer $PiHoleServer -Password $Password +``` + +``` + +Password : 4ZafjS7tw7/RgKCph37MY2sM3IlznjNx0+74dQIU1Ns= +Hash : $BALLOON-SHA256$v=1$s=1024,t=32$BjLFnQsBZT7kZrcQJ6KIew==$v0oLwqzLRaScMhqFEUZJj4n3sBKbO2AeIXoHfYVeR+U= ``` ### Get-PiHoleCurrentAuthSession @@ -1626,41 +1703,13 @@ Get-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Password $Password ``` Id : 0 -CurrentSession : False -Valid : True -TlsLogin : True -TlsMixed : False -LoginAt : 10/6/2026 9:44:13 PM -LastActive : 10/6/2026 9:44:17 PM -ValidUntil : 10/6/2026 10:14:17 PM -RemoteAddress : 192.168.1.162 -UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 -XForwardedFor : -App : True -Cli : False - -Id : 1 -CurrentSession : False -Valid : True -TlsLogin : True -TlsMixed : False -LoginAt : 10/6/2026 9:44:59 PM -LastActive : 10/6/2026 9:44:59 PM -ValidUntil : 10/6/2026 10:14:59 PM -RemoteAddress : 192.168.1.162 -UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 -XForwardedFor : -App : True -Cli : False - -Id : 2 CurrentSession : True Valid : True TlsLogin : True TlsMixed : False -LoginAt : 10/6/2026 10:03:33 PM -LastActive : 10/6/2026 10:03:37 PM -ValidUntil : 10/6/2026 10:33:37 PM +LoginAt : 10/19/2026 4:29:51 PM +LastActive : 10/19/2026 4:29:55 PM +ValidUntil : 10/19/2026 4:59:55 PM RemoteAddress : 192.168.1.162 UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 XForwardedFor : @@ -1673,13 +1722,13 @@ Cli : False _Deletes a session by its ID (as shown by Get-PiHoleCurrentAuthSession), not the caller's own session._ ```powershell -Remove-PiHoleAuthSession -PiHoleServer $PiHoleServer -Password $Password -Id 2 +Remove-PiHoleAuthSession -PiHoleServer $PiHoleServer -Password $Password -Id 0 ``` ``` -Id : 2 +Id : 0 Status : Removed ``` diff --git a/tests/Actions/Update-PiHoleActionsGravity.Integration.Tests.ps1 b/tests/Actions/Update-PiHoleActionsGravity.Integration.Tests.ps1 index da81455..c7d440b 100644 --- a/tests/Actions/Update-PiHoleActionsGravity.Integration.Tests.ps1 +++ b/tests/Actions/Update-PiHoleActionsGravity.Integration.Tests.ps1 @@ -41,6 +41,30 @@ Describe 'Update-PiHoleActionsGravity (Integration)' -Tag 'Integration' { $result | Should -Not -BeNullOrEmpty } + It 'reports a clear error when a gravity update is already running' -Skip:(-not $script:ConfigAvailable) { + # FTL v6.8+ refuses a second concurrent run with 409. Start one in the background, give it + # a moment to get going, then try another. + $moduleRoot = (Resolve-Path .\PiHoleShell\PiHoleShell.psm1).Path + $job = Start-ThreadJob -ArgumentList $moduleRoot, $script:PiHoleServer, $script:PiHoleToken, $script:PiHoleIgnoreSsl -ScriptBlock { + param($ModulePath, $Server, $Token, $IgnoreSsl) + Import-Module $ModulePath -Force + Update-PiHoleActionsGravity -PiHoleServer $Server -Password $Token -IgnoreSsl $IgnoreSsl -Confirm:$false + } + try { + Start-Sleep -Seconds 2 + $result = Update-PiHoleActionsGravity -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Confirm:$false -ErrorVariable errOut -ErrorAction SilentlyContinue + Write-Host "Error: [$($errOut[-1])]" + + $result | Should -BeNullOrEmpty + "$($errOut[-1])" | Should -Be 'Gravity is already running' + } + finally { + # Let the background run finish so it doesn't collide with later tests + $job | Wait-Job -Timeout 600 | Receive-Job -ErrorAction SilentlyContinue | Out-Null + $job | Remove-Job -Force + } + } + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { $result = Update-PiHoleActionsGravity -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -Confirm:$false -ErrorVariable errOut -ErrorAction SilentlyContinue Write-Host "Error ($($errOut.Count) entries, showing last): [$($errOut[-1])]" diff --git a/tests/Authentication/Get-PiHoleAuthApp.Integration.Tests.ps1 b/tests/Authentication/Get-PiHoleAuthApp.Integration.Tests.ps1 new file mode 100644 index 0000000..fcba2ed --- /dev/null +++ b/tests/Authentication/Get-PiHoleAuthApp.Integration.Tests.ps1 @@ -0,0 +1,63 @@ +# Requires -Module Pester +# +# Integration tests that call a REAL Pi-hole server. Configure tests/IntegrationConfig.local.ps1 +# (copy it from IntegrationConfig.example.ps1) before running. Tests are skipped automatically +# if that file is missing. +# +# NOTE: these only generate app passwords - they never set the returned hash as +# webserver.api.app_pwhash, so the server's real app password and sessions are left untouched. + +# Config availability must be known at discovery time so the -Skip parameter on each It block +# (evaluated during discovery, before BeforeAll runs) sees the correct value. +$script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1') + +Describe 'Get-PiHoleAuthApp (Integration)' -Tag 'Integration' { + BeforeAll { + Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + + # Recomputed here (not read from the discovery-time $script:ConfigAvailable above) because + # Pester runs discovery and run in separate scopes, so BeforeAll cannot see that value. + $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' + if (Test-Path $configPath) { + . $configPath + $script:PiHoleServer = $PiHoleServer + $script:PiHoleToken = $PiHoleToken + $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl + } + } + + It 'generates a new app password and its hash' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + + $result | Should -Not -BeNullOrEmpty + $result.Password | Should -Not -BeNullOrEmpty + $result.Hash | Should -BeLike '$BALLOON-SHA256$*' + } + + It 'generates a different password each time' -Skip:(-not $script:ConfigAvailable) { + $first = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + $second = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + + $second.Password | Should -Not -Be $first.Password + } + + It 'leaves the current app password working' -Skip:(-not $script:ConfigAvailable) { + Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl | Out-Null + + $status = Get-PiHoleAuthStatus -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + $status.Valid | Should -BeTrue + } + + It 'returns the raw API response when RawOutput is set' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -RawOutput $true + + $result.app.password | Should -Not -BeNullOrEmpty + $result.app.hash | Should -Not -BeNullOrEmpty + } + + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } +} diff --git a/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 new file mode 100644 index 0000000..bcbb31c --- /dev/null +++ b/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 @@ -0,0 +1,97 @@ +# Requires -Module Pester +# +# Integration tests that call a REAL Pi-hole server. Configure tests/IntegrationConfig.local.ps1 +# (copy it from IntegrationConfig.example.ps1) before running. Tests are skipped automatically +# if that file is missing. +# +# NOTE: these tests add/remove fake records using TEST-NET-1/documentation (RFC 5737/3849) +# reserved addresses that will never route anywhere real. They require the app password used +# here to have "app_sudo" enabled in Pi-hole (Settings > All Settings), same as +# Add-PiHoleConfigArrayItem (called internally) - see its .DESCRIPTION. -Restart $false is used +# throughout to avoid the brief FTL restart a real config change otherwise triggers. + +$script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1') + +Describe 'Add-PiHoleDnsRecord (Integration)' -Tag 'Integration' { + BeforeAll { + Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + . (Join-Path $PSScriptRoot 'DnsRecordTestHelpers.ps1') + + $script:AHostname = 'piholeshell-test-a.example.com' + $script:AIPv4 = '192.0.2.201' + $script:AaaaHostname = 'piholeshell-test-aaaa.example.com' + $script:AaaaIPv6 = '2001:db8::201' + $script:CnameHostname = 'piholeshell-test-cname.example.com' + $script:CnameTarget = 'piholeshell-test-a.example.com' + $script:CnameTtl = 300 + + Initialize-DnsRecordTest -Hosts "$script:AIPv4 $script:AHostname", "$script:AaaaIPv6 $script:AaaaHostname" -CnameRecords "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + } + + AfterAll { + Clear-DnsRecordTestData + } + + It 'adds an A record and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Added' + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Contain "$script:AIPv4 $script:AHostname" + + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false | Out-Null + } + + It 'adds an AAAA record and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type AAAA -Hostname $script:AaaaHostname -IPv6Address $script:AaaaIPv6 -Restart $false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Added' + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Contain "$script:AaaaIPv6 $script:AaaaHostname" + + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AaaaIPv6 $script:AaaaHostname" -Restart $false -Confirm:$false | Out-Null + } + + It 'adds a CNAME record with a TTL and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type CNAME -Hostname $script:CnameHostname -Target $script:CnameTarget -Ttl $script:CnameTtl -Restart $false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Added' + + $cnames = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.CnameRecords + $cnames | Should -Contain "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false | Out-Null + } + + It 'errors when -IPv4Address is missing for -Type A' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -Restart $false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } + + It 'errors when -IPv4Address is not a valid IPv4 address' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address '2001:db8::1' -Restart $false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } + + It 'errors when -Target is missing for -Type CNAME' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type CNAME -Hostname $script:CnameHostname -Restart $false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } + + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } +} diff --git a/tests/DnsControl/DnsRecordTestHelpers.ps1 b/tests/DnsControl/DnsRecordTestHelpers.ps1 new file mode 100644 index 0000000..2045727 --- /dev/null +++ b/tests/DnsControl/DnsRecordTestHelpers.ps1 @@ -0,0 +1,51 @@ +# Shared setup/cleanup for the *-PiHoleDnsRecord integration tests. Dot-source this from a +# Describe block's BeforeAll, then call Initialize-DnsRecordTest. + +function Initialize-DnsRecordTest { + # Loads tests/IntegrationConfig.local.ps1 into $script:PiHoleServer/PiHoleToken/PiHoleIgnoreSsl + # and removes any of the given test records a previous failed run left behind. Leaves + # $script:PiHoleServer unset if the config file is missing. + param ( + [string[]]$Hosts = @(), + [string[]]$CnameRecords = @() + ) + + $script:TestRecords = @{ Hosts = $Hosts; CnameRecords = $CnameRecords } + + $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' + if (-not (Test-Path $configPath)) { + return + } + + . $configPath + $script:PiHoleServer = $PiHoleServer + $script:PiHoleToken = $PiHoleToken + $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl + + Clear-DnsRecordTestData +} + +function Clear-DnsRecordTestData { + # Removes the records passed to Initialize-DnsRecordTest without complaining if they aren't + # there, so it's safe to call in AfterAll even after a test already removed them + if (-not $script:PiHoleServer) { + return + } + + $removeParams = @{ + PiHoleServer = $script:PiHoleServer + Password = $script:PiHoleToken + IgnoreSsl = $script:PiHoleIgnoreSsl + Restart = $false + Confirm = $false + ErrorAction = 'SilentlyContinue' + WarningAction = 'SilentlyContinue' + } + + foreach ($value in $script:TestRecords.Hosts) { + Remove-PiHoleConfigArrayItem @removeParams -Element 'dns/hosts' -Value $value | Out-Null + } + foreach ($value in $script:TestRecords.CnameRecords) { + Remove-PiHoleConfigArrayItem @removeParams -Element 'dns/cnameRecords' -Value $value | Out-Null + } +} diff --git a/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 new file mode 100644 index 0000000..d93f18f --- /dev/null +++ b/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 @@ -0,0 +1,95 @@ +# Requires -Module Pester +# +# Integration tests that call a REAL Pi-hole server. Configure tests/IntegrationConfig.local.ps1 +# (copy it from IntegrationConfig.example.ps1) before running. Tests are skipped automatically +# if that file is missing. +# +# NOTE: these tests add/remove fake records using TEST-NET-1/documentation (RFC 5737/3849) +# reserved addresses that will never route anywhere real. -Restart $false is used throughout to +# avoid the brief FTL restart a real config change otherwise triggers. + +$script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1') + +Describe 'Get-PiHoleDnsRecord (Integration)' -Tag 'Integration' { + BeforeAll { + Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + . (Join-Path $PSScriptRoot 'DnsRecordTestHelpers.ps1') + + $script:AHostname = 'piholeshell-test-get-a.example.com' + $script:AIPv4 = '192.0.2.203' + $script:CnameHostname = 'piholeshell-test-get-cname.example.com' + $script:CnameTarget = 'piholeshell-test-get-a.example.com' + $script:CnameTtl = 300 + + Initialize-DnsRecordTest -Hosts "$script:AIPv4 $script:AHostname" -CnameRecords "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + if ($script:PiHoleServer) { + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false | Out-Null + } + } + + AfterAll { + Clear-DnsRecordTestData + } + + It 'returns both the A and CNAME test records, correctly typed' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + $result | Where-Object { $_.Hostname -in @($script:AHostname, $script:CnameHostname) } | Format-Table | Out-String | Write-Host + + $aRecord = $result | Where-Object { $_.Hostname -eq $script:AHostname } + $aRecord | Should -Not -BeNullOrEmpty + $aRecord.Type | Should -Be 'A' + $aRecord.IPv4Address | Should -Be $script:AIPv4 + + $cnameRecord = $result | Where-Object { $_.Hostname -eq $script:CnameHostname } + $cnameRecord | Should -Not -BeNullOrEmpty + $cnameRecord.Type | Should -Be 'CNAME' + $cnameRecord.Target | Should -Be $script:CnameTarget + $cnameRecord.Ttl | Should -Be $script:CnameTtl + } + + It 'filters by -Type' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type CNAME + + $result | Should -Not -BeNullOrEmpty + ($result.Type | Select-Object -Unique) | Should -Be 'CNAME' + $result.Hostname | Should -Contain $script:CnameHostname + } + + It 'filters by -Hostname' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Hostname $script:AHostname + + $result | Should -Not -BeNullOrEmpty + @($result).Count | Should -Be 1 + $result.Type | Should -Be 'A' + } + + It 'returns the raw API response when RawOutput is set' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -RawOutput $true + + $result.PSObject.Properties.Name | Should -Contain 'Hosts' + $result.PSObject.Properties.Name | Should -Contain 'CnameRecords' + $result.Hosts | Should -Contain "$script:AIPv4 $script:AHostname" + } + + It 'can be piped directly into Remove-PiHoleDnsRecord' -Skip:(-not $script:ConfigAvailable) { + $removed = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Hostname $script:AHostname | + Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Restart $false -Confirm:$false + $removed | Format-List | Out-String | Write-Host + + $removed | Should -Not -BeNullOrEmpty + $removed.Status | Should -Be 'Removed' + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Not -Contain "$script:AIPv4 $script:AHostname" + + # Recreate it so AfterAll's cleanup (and other tests, if re-run) have a consistent state + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + } + + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } +} diff --git a/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 new file mode 100644 index 0000000..0a7177a --- /dev/null +++ b/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 @@ -0,0 +1,90 @@ +# Requires -Module Pester +# +# Integration tests that call a REAL Pi-hole server. Configure tests/IntegrationConfig.local.ps1 +# (copy it from IntegrationConfig.example.ps1) before running. Tests are skipped automatically +# if that file is missing. +# +# NOTE: these tests add/remove fake records using TEST-NET-1/documentation (RFC 5737/3849) +# reserved addresses that will never route anywhere real. -Restart $false is used throughout to +# avoid the brief FTL restart a real config change otherwise triggers. + +$script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1') + +Describe 'Remove-PiHoleDnsRecord (Integration)' -Tag 'Integration' { + BeforeAll { + Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + . (Join-Path $PSScriptRoot 'DnsRecordTestHelpers.ps1') + + $script:AHostname = 'piholeshell-test-remove-a.example.com' + $script:AIPv4 = '192.0.2.202' + $script:CnameHostname = 'piholeshell-test-remove-cname.example.com' + $script:CnameTarget = 'piholeshell-test-remove-a.example.com' + $script:CnameTtl = 300 + + Initialize-DnsRecordTest -Hosts "$script:AIPv4 $script:AHostname" -CnameRecords "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + } + + AfterAll { + Clear-DnsRecordTestData + } + + It 'removes an A record and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + + $result = Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false -Confirm:$false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Removed' + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Not -Contain "$script:AIPv4 $script:AHostname" + } + + It 'removes a CNAME record with a matching TTL' -Skip:(-not $script:ConfigAvailable) { + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false | Out-Null + + $result = Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type CNAME -Hostname $script:CnameHostname -Target $script:CnameTarget -Ttl $script:CnameTtl -Restart $false -Confirm:$false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Removed' + + $cnames = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.CnameRecords + $cnames | Should -Not -Contain "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + } + + It 'does not remove anything when -WhatIf is set' -Skip:(-not $script:ConfigAvailable) { + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + + Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false -WhatIf + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Contain "$script:AIPv4 $script:AHostname" + + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false | Out-Null + } + + It 'accepts multiple records piped from Get-PiHoleDnsRecord in a single call' -Skip:(-not $script:ConfigAvailable) { + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false | Out-Null + + $results = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl | + Where-Object { $_.Hostname -in @($script:AHostname, $script:CnameHostname) } | + Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Restart $false -Confirm:$false + $results | Format-Table | Out-String | Write-Host + + @($results).Count | Should -Be 2 + $results.Status | Should -Be @('Removed', 'Removed') + + $config = Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + $config.Dns.Hosts | Should -Not -Contain "$script:AIPv4 $script:AHostname" + $config.Dns.CnameRecords | Should -Not -Contain "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + } + + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { + $result = Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false -Confirm:$false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } +} diff --git a/tools/Update-ExampleOutput.ps1 b/tools/Update-ExampleOutput.ps1 index 35cb802..2632e14 100644 --- a/tools/Update-ExampleOutput.ps1 +++ b/tools/Update-ExampleOutput.ps1 @@ -117,6 +117,11 @@ Add-Example -Category Authentication -FunctionName 'Get-PiHoleAuthTotp' ` -Invocation 'Get-PiHoleAuthTotp -PiHoleServer $PiHoleServer -Password $Password' ` -Result (Get-PiHoleAuthTotp -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl) +Add-Example -Category Authentication -FunctionName 'Get-PiHoleAuthApp' ` + -Invocation 'Get-PiHoleAuthApp -PiHoleServer $PiHoleServer -Password $Password' ` + -Note 'This only generates a password. It was never activated on the test server, so it is safe to show here.' ` + -Result (Get-PiHoleAuthApp -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl) + Add-Example -Category Authentication -FunctionName 'Get-PiHoleCurrentAuthSession' ` -Invocation 'Get-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Password $Password' ` -Result (Get-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl) @@ -193,6 +198,22 @@ if ($appSudoEnabled) { Add-Example -Category Config -FunctionName 'Remove-PiHoleConfigArrayItem' ` -Invocation "Remove-PiHoleConfigArrayItem -PiHoleServer `$PiHoleServer -Password `$Password -Element `"dns/hosts`" -Value `"$docsHostEntry`"" ` -Result (Remove-PiHoleConfigArrayItem -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Element 'dns/hosts' -Value $docsHostEntry -Restart $false -Confirm:$false) + + $docsDnsHostname = 'piholeshell-docs-dns-example.com' + Invoke-Quietly { Remove-PiHoleConfigArrayItem -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Element 'dns/hosts' -Value "192.0.2.2 $docsDnsHostname" -Restart $false -Confirm:$false } + + Add-Example -Category DnsControl -FunctionName 'Add-PiHoleDnsRecord' ` + -Invocation "Add-PiHoleDnsRecord -PiHoleServer `$PiHoleServer -Password `$Password -Type A -Hostname `"$docsDnsHostname`" -IPv4Address `"192.0.2.2`"" ` + -Result (Add-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Type A -Hostname $docsDnsHostname -IPv4Address '192.0.2.2' -Restart $false) + + Add-Example -Category DnsControl -FunctionName 'Get-PiHoleDnsRecord' ` + -Invocation 'Get-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password' ` + -Note 'Can be filtered with -Type and/or -Hostname, and piped directly into Remove-PiHoleDnsRecord.' ` + -Result (Get-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Hostname $docsDnsHostname) + + Add-Example -Category DnsControl -FunctionName 'Remove-PiHoleDnsRecord' ` + -Invocation "Remove-PiHoleDnsRecord -PiHoleServer `$PiHoleServer -Password `$Password -Type A -Hostname `"$docsDnsHostname`" -IPv4Address `"192.0.2.2`"" ` + -Result (Remove-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Type A -Hostname $docsDnsHostname -IPv4Address '192.0.2.2' -Restart $false -Confirm:$false) } else { $appSudoNote = 'Requires "app_sudo" enabled for this app password (Settings > All Settings in your Pi-hole admin UI) - not captured this run since it is disabled here.' @@ -205,6 +226,15 @@ else { Add-Example -Category Config -FunctionName 'Remove-PiHoleConfigArrayItem' ` -Invocation 'Remove-PiHoleConfigArrayItem -PiHoleServer $PiHoleServer -Password $Password -Element "dns/hosts" -Value "192.0.2.1 example.com"' ` -Note $appSudoNote -Skipped + Add-Example -Category DnsControl -FunctionName 'Add-PiHoleDnsRecord' ` + -Invocation 'Add-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "example.com" -IPv4Address "192.0.2.1"' ` + -Note $appSudoNote -Skipped + Add-Example -Category DnsControl -FunctionName 'Get-PiHoleDnsRecord' ` + -Invocation 'Get-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password' ` + -Note $appSudoNote -Skipped + Add-Example -Category DnsControl -FunctionName 'Remove-PiHoleDnsRecord' ` + -Invocation 'Remove-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "example.com" -IPv4Address "192.0.2.1"' ` + -Note $appSudoNote -Skipped } Add-Example -Category Config -FunctionName 'Get-PiHolePadd' `