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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
notes.txt
26 changes: 13 additions & 13 deletions PiHoleShell/PiHoleShell.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ if ($PSVersionTable.PSEdition -ne 'Core') {
}

# Get all .ps1 files in the 'Public' directory and dot-source them
$PublicFunctions = Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') -Filter '*.ps1' -File
$PrivateFunctions = Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') -Filter '*.ps1' -File
$PublicFunctions = Get-ChildItem -Verbose -Path (Join-Path $PSScriptRoot 'Public') -Filter '*.ps1' -File -Recurse
$PrivateFunctions = Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') -Filter '*.ps1' -File -Recurse

foreach ($File in $PublicFunctions) {
. $File.FullName
Expand All @@ -15,22 +15,22 @@ foreach ($File in $PrivateFunctions) {
}

Export-ModuleMember -Function @(
#Actions.ps1
'Update-PiHoleActionsGravity', 'Invoke-PiHoleFlushNetwork' `
#Authentication.ps1
#Actions
'Update-PiHoleActionsGravity', 'Invoke-PiHoleFlushNetwork', 'Restart-PiHoleDnsService' `
#Authentication
'Remove-PiHoleCurrentAuthSession' , 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', `
#GroupManagement.ps1
#GroupManagement
'Get-PiHoleGroup', 'New-PiHoleGroup', 'Update-PiHoleGroup', 'Remove-PiHoleGroup', `
#DnsControl.ps1
#DnsControl
'Get-PiHoleDnsBlockingStatus', 'Set-PiHoleDnsBlocking', `
#Config.ps1
'Get-PiHoleConfig', 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', `
#Padd.ps1
#Config
'Get-PiHoleConfig', `
#Padd
'Get-PiHolePadd', `
#Metrics.ps1
#Metrics
'Get-PiHoleStatsRecentBlocked', 'Get-PiHoleStatsQueryType', 'Get-PiHoleStatsTopDomain', 'Get-PiHoleStatsSummary', 'Get-PiHoleStatsTopClient' `
#ListManagement.ps1
#ListManagement
'Get-PiHoleList', 'Search-PiHoleListDomain', 'Add-PiHoleList', 'Remove-PiHoleList', `
#FTLInformation.ps1
#FTLInformation
'Get-PiHoleInfoMessage', 'Get-PiHoleInfoHost'
)
193 changes: 0 additions & 193 deletions PiHoleShell/Public/Actions.ps1

This file was deleted.

67 changes: 67 additions & 0 deletions PiHoleShell/Public/Actions/Invoke-PiHoleFlushNetwork.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function Invoke-PiHoleFlushNetwork {
<#
.SYNOPSIS
Flushes the network table. This includes removing both all known devices and their associated addresses.

.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-PiHoleFlushNetwork -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
#>
[CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#post-/action/flush/network')]
[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
}
}
}
67 changes: 67 additions & 0 deletions PiHoleShell/Public/Actions/Restart-PiHoleDnsService.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function Restart-PiHoleDnsService {
<#
.SYNOPSIS
Restarts the pihole-FTL service

.DESCRIPTION
Restarts the Pi-hole DNS resolver (FTL).

.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-PiHoleRestartDns -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
#>
[CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#post-/action/restartdns')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Restarts PiHole DNS')]
[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/restartdns"
Method = "Post"
ContentType = "application/json"
SkipCertificateCheck = $IgnoreSsl
}

$Response = Invoke-RestMethod @Params

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

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

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