Skip to content

Commit 424f99d

Browse files
authored
Merge pull request #75 from mikemadeja/develop
develop --> main
2 parents 3d30096 + 14d6021 commit 424f99d

35 files changed

Lines changed: 1763 additions & 1673 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
notes.txt

PiHoleShell/PiHoleShell.psm1

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ if ($PSVersionTable.PSEdition -ne 'Core') {
33
}
44

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

99
foreach ($File in $PublicFunctions) {
1010
. $File.FullName
@@ -15,22 +15,22 @@ foreach ($File in $PrivateFunctions) {
1515
}
1616

1717
Export-ModuleMember -Function @(
18-
#Actions.ps1
19-
'Update-PiHoleActionsGravity', 'Invoke-PiHoleFlushNetwork' `
20-
#Authentication.ps1
18+
#Actions
19+
'Update-PiHoleActionsGravity', 'Invoke-PiHoleFlushNetwork', 'Restart-PiHoleDnsService' `
20+
#Authentication
2121
'Remove-PiHoleCurrentAuthSession' , 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', `
22-
#GroupManagement.ps1
22+
#GroupManagement
2323
'Get-PiHoleGroup', 'New-PiHoleGroup', 'Update-PiHoleGroup', 'Remove-PiHoleGroup', `
24-
#DnsControl.ps1
24+
#DnsControl
2525
'Get-PiHoleDnsBlockingStatus', 'Set-PiHoleDnsBlocking', `
26-
#Config.ps1
27-
'Get-PiHoleConfig', 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', `
28-
#Padd.ps1
26+
#Config
27+
'Get-PiHoleConfig', `
28+
#Padd
2929
'Get-PiHolePadd', `
30-
#Metrics.ps1
30+
#Metrics
3131
'Get-PiHoleStatsRecentBlocked', 'Get-PiHoleStatsQueryType', 'Get-PiHoleStatsTopDomain', 'Get-PiHoleStatsSummary', 'Get-PiHoleStatsTopClient' `
32-
#ListManagement.ps1
32+
#ListManagement
3333
'Get-PiHoleList', 'Search-PiHoleListDomain', 'Add-PiHoleList', 'Remove-PiHoleList', `
34-
#FTLInformation.ps1
34+
#FTLInformation
3535
'Get-PiHoleInfoMessage', 'Get-PiHoleInfoHost'
3636
)

PiHoleShell/Public/Actions.ps1

Lines changed: 0 additions & 193 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function Invoke-PiHoleFlushNetwork {
2+
<#
3+
.SYNOPSIS
4+
Flushes the network table. This includes removing both all known devices and their associated addresses.
5+
6+
.DESCRIPTION
7+
Flushes the Pi-hole log file (/var/log/pihole/pihole.log).
8+
9+
.PARAMETER PiHoleServer
10+
The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100"
11+
12+
.PARAMETER Password
13+
The API Password you generated from your PiHole server
14+
15+
.PARAMETER IgnoreSsl
16+
Set to $true to skip SSL certificate validation
17+
18+
.PARAMETER RawOutput
19+
This will dump the response instead of the formatted object
20+
21+
.EXAMPLE
22+
Invoke-PiHoleFlushNetwork -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
23+
#>
24+
[CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#post-/action/flush/network')]
25+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Flushes PiHole logs')]
26+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
27+
param (
28+
$PiHoleServer,
29+
$Password,
30+
[bool]$IgnoreSsl = $false,
31+
[bool]$RawOutput = $false
32+
)
33+
34+
try {
35+
$Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl
36+
37+
$Params = @{
38+
Headers = @{sid = $($Sid) }
39+
Uri = "$PiHoleServer/api/action/flush/logs"
40+
Method = "Post"
41+
ContentType = "application/json"
42+
SkipCertificateCheck = $IgnoreSsl
43+
}
44+
45+
$Response = Invoke-RestMethod @Params
46+
47+
if ($RawOutput) {
48+
Write-Output $Response
49+
}
50+
else {
51+
$Object = [PSCustomObject]@{
52+
Status = "Flushed"
53+
}
54+
Write-Output $Object
55+
}
56+
}
57+
58+
catch {
59+
Write-Error -Message $_.Exception.Message
60+
}
61+
62+
finally {
63+
if ($Sid) {
64+
Remove-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Sid $Sid -IgnoreSsl $IgnoreSsl
65+
}
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function Restart-PiHoleDnsService {
2+
<#
3+
.SYNOPSIS
4+
Restarts the pihole-FTL service
5+
6+
.DESCRIPTION
7+
Restarts the Pi-hole DNS resolver (FTL).
8+
9+
.PARAMETER PiHoleServer
10+
The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100"
11+
12+
.PARAMETER Password
13+
The API Password you generated from your PiHole server
14+
15+
.PARAMETER IgnoreSsl
16+
Set to $true to skip SSL certificate validation
17+
18+
.PARAMETER RawOutput
19+
This will dump the response instead of the formatted object
20+
21+
.EXAMPLE
22+
Invoke-PiHoleRestartDns -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
23+
#>
24+
[CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#post-/action/restartdns')]
25+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Restarts PiHole DNS')]
26+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
27+
param (
28+
$PiHoleServer,
29+
$Password,
30+
[bool]$IgnoreSsl = $false,
31+
[bool]$RawOutput = $false
32+
)
33+
34+
try {
35+
$Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl
36+
37+
$Params = @{
38+
Headers = @{sid = $($Sid) }
39+
Uri = "$PiHoleServer/api/action/restartdns"
40+
Method = "Post"
41+
ContentType = "application/json"
42+
SkipCertificateCheck = $IgnoreSsl
43+
}
44+
45+
$Response = Invoke-RestMethod @Params
46+
47+
if ($RawOutput) {
48+
Write-Output $Response
49+
}
50+
else {
51+
$Object = [PSCustomObject]@{
52+
Status = "Restarted"
53+
}
54+
Write-Output $Object
55+
}
56+
}
57+
58+
catch {
59+
Write-Error -Message $_.Exception.Message
60+
}
61+
62+
finally {
63+
if ($Sid) {
64+
Remove-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Sid $Sid -IgnoreSsl $IgnoreSsl
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)