Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PiHoleShell/PiHoleShell.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ foreach ($File in $PrivateFunctions) {

Export-ModuleMember -Function @(
#Actions.ps1
'Update-PiHoleActionsGravity', 'Invoke-PiHoleFlushLog' `
'Update-PiHoleActionsGravity', 'Invoke-PiHoleFlushLog', 'Clear-PiHoleLog' `
#Authentication.ps1
'Remove-PiHoleCurrentAuthSession' , 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', `
#GroupManagement.ps1
Expand Down
72 changes: 70 additions & 2 deletions PiHoleShell/Public/Actions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,75 @@ https://TODO
}
}

function Invoke-PiHoleFlushLog {
function Invoke-PiHoleFlushNetwork {
<#
.SYNOPSIS
https://dns3.local:8489/api/docs/#post-/action/flush/network

.DESCRIPTION
Flushes the Pi-hole network table, clearing all known network devices.

.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
Invoke-PiHoleFlushNetwork -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Flushes PiHole network table')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
$PiHoleServer,
$Password,
[bool]$IgnoreSsl = $false,
[bool]$RawOutput = $false
)

try {
$Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl

$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/action/flush/network"
Method = "Post"
ContentType = "application/json"
SkipCertificateCheck = $IgnoreSsl
}

$Response = Invoke-RestMethod @Params

if ($RawOutput) {
Write-Output $Response
}
else {
$Object = [PSCustomObject]@{
Status = "Flushed"
}
Write-Output $Object
}
}

catch {
Write-Error -Message $_.Exception.Message
}

finally {
if ($Sid) {
Remove-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Sid $Sid -IgnoreSsl $IgnoreSsl
}
}
}

function Clear-PiHoleLog {
<#
.SYNOPSIS
https://dns1.local:8489/api/docs/#post-/action/flush/logs
Expand All @@ -77,7 +145,7 @@ Set to $true to skip SSL certificate validation
This will dump the response instead of the formatted object

.EXAMPLE
Invoke-PiHoleFlushLogs -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
Clear-PiHoleLog -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Flushes PiHole logs')]
Expand Down