diff --git a/PiHoleShell/PiHoleShell.psm1 b/PiHoleShell/PiHoleShell.psm1 index 3d038d9..0f1e1d5 100644 --- a/PiHoleShell/PiHoleShell.psm1 +++ b/PiHoleShell/PiHoleShell.psm1 @@ -16,7 +16,7 @@ foreach ($File in $PrivateFunctions) { Export-ModuleMember -Function @( #Actions.ps1 - 'Update-PiHoleActionsGravity' ` + 'Update-PiHoleActionsGravity', 'Invoke-PiHoleFlushLog' ` #Authentication.ps1 'Remove-PiHoleCurrentAuthSession' , 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', ` #GroupManagement.ps1 diff --git a/PiHoleShell/Public/Actions.ps1 b/PiHoleShell/Public/Actions.ps1 index 7788c9a..a45ddd8 100644 --- a/PiHoleShell/Public/Actions.ps1 +++ b/PiHoleShell/Public/Actions.ps1 @@ -54,4 +54,72 @@ https://TODO Remove-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Sid $Sid -IgnoreSsl $IgnoreSsl } } -} \ No newline at end of file +} + +function Invoke-PiHoleFlushLog { + <# +.SYNOPSIS +https://dns1.local:8489/api/docs/#post-/action/flush/logs + +.DESCRIPTION +Flushes the Pi-hole log file (/var/log/pihole/pihole.log). + +.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-PiHoleFlushLogs -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl" + #> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Flushes PiHole logs')] + [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/logs" + 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 + } + } +} diff --git a/functions/actions/Actions.ps1 b/functions/actions/Actions.ps1 deleted file mode 100644 index 16f74f8..0000000 --- a/functions/actions/Actions.ps1 +++ /dev/null @@ -1,69 +0,0 @@ -function Invoke-PiHoleFlushLogs { - <# -.SYNOPSIS -https://dns1.local:8489/api/docs/#post-/action/flush/logs - -.DESCRIPTION -Flushes the Pi-hole log file (/var/log/pihole/pihole.log). - -.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-PiHoleFlushLogs -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl" - #> - [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Flushes PiHole logs')] - [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/logs" - 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 - } - } -} - -Export-ModuleMember -Function Invoke-PiHoleFlushLogs