Skip to content

Commit 65aee53

Browse files
authored
Merge pull request #53 from mikemadeja/feat/more-updates
Feat/more updates
2 parents 2147347 + 4dd701f commit 65aee53

8 files changed

Lines changed: 110 additions & 79 deletions

File tree

PiHoleShell/PiHoleShell.psd1

520 Bytes
Binary file not shown.

PiHoleShell/Private/Misc.ps1

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,47 +45,4 @@ function Convert-LocalTimeToPiHoleUnixTime {
4545

4646
$ObjectFinal = $Object
4747
Write-Output $ObjectFinal
48-
}
49-
50-
# function Test-HttpPrefixForPiHole {
51-
# param (
52-
# [Parameter(Mandatory)]
53-
# [string]$Url
54-
# )
55-
56-
# Write-Output ($Url -match '^https?://')
57-
# }
58-
59-
# function Test-PiHoleServerAccess {
60-
# param (
61-
# [Parameter(Mandatory)]
62-
# [string]$Url,
63-
# [bool]$IgnoreSsl = $false
64-
# )
65-
66-
# if (Test-HttpPrefixForPiHole -Url $Url) {
67-
# $RawOutput = Invoke-WebRequest -Uri "$Url/admin/login" -Method Head -TimeoutSec 5 -ErrorAction Stop -SkipCertificateCheck
68-
# }
69-
# }
70-
71-
# function Convert-EnabledBoolToString {
72-
# param (
73-
# [bool]$Bool
74-
# )
75-
76-
# switch ($Bool) {
77-
# $false {
78-
# $Enabled = "false"
79-
# }
80-
# $true {
81-
# $Enabled = "true"
82-
# }
83-
# }
84-
85-
# $Object = [PSCustomObject]@{
86-
# Bool = $Enabled
87-
# }
88-
89-
# Write-Output $Object
90-
91-
# }
48+
}

PiHoleShell/Public/Authentication.ps1

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function Request-PiHoleAuth {
1818
}
1919

2020
$Response = Invoke-RestMethod @Params -Verbose: $false
21+
Write-Verbose -Message "Request-PiHoleAuth Successful!"
2122

2223
Write-Output $Response.session.sid
2324
}
@@ -39,14 +40,22 @@ The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "h
3940
.PARAMETER Password
4041
The API Password you generated from your PiHole v6 server
4142
43+
.PARAMETER IgnoreSsl
44+
Ignore SSL when interacting with the PiHole API
45+
46+
.PARAMETER RawOutput
47+
This will dump the response instead of the formatted object
48+
4249
.EXAMPLE
4350
Get-PiHoleCurrentAuthSession -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
4451
#>
4552
[CmdletBinding()]
4653
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
4754
param (
48-
[string]$PiHoleServer,
49-
$Password,
55+
[Parameter(Mandatory = $true)]
56+
[System.URI]$PiHoleServer,
57+
[Parameter(Mandatory = $true)]
58+
[string]$Password,
5059
[bool]$IgnoreSsl = $false,
5160
[bool]$RawOutput = $false
5261
)
@@ -55,7 +64,7 @@ Get-PiHoleCurrentAuthSession -PiHoleServer "http://pihole.domain.com:8080" -Pass
5564

5665
$Params = @{
5766
Headers = @{sid = $($Sid) }
58-
Uri = "$PiHoleServer/api/auth/sessions"
67+
Uri = "$($PiHoleServer.OriginalString)/api/auth/sessions"
5968
Method = "Get"
6069
SkipCertificateCheck = $IgnoreSsl
6170
ContentType = "application/json"
@@ -117,7 +126,7 @@ function Remove-PiHoleCurrentAuthSession {
117126
)
118127
$Params = @{
119128
Headers = @{sid = $($Sid) }
120-
Uri = "$PiHoleServer/api/auth"
129+
Uri = "$($PiHoleServer.OriginalString)/api/auth"
121130
Method = "Delete"
122131
SkipCertificateCheck = $IgnoreSsl
123132
ContentType = "application/json"
@@ -143,23 +152,28 @@ The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "h
143152
.PARAMETER Password
144153
The API Password you generated from your PiHole server
145154
155+
.PARAMETER IgnoreSsl
156+
Ignore SSL when interacting with the PiHole API
157+
146158
.EXAMPLE
147159
Get-PiHoleCurrentAuthSession -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
148160
#>
149161
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change state')]
150162
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
151163
param (
152-
$PiHoleServer,
153-
$Password,
154-
$IgnoreSsl,
164+
[Parameter(Mandatory = $true)]
165+
[System.URI]$PiHoleServer,
166+
[Parameter(Mandatory = $true)]
167+
[string]$Password,
168+
[bool]$IgnoreSsl = $false,
155169
[int]$Id
156170
)
157171

158172
try {
159173
$Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl
160174
$Params = @{
161175
Headers = @{sid = $($Sid) }
162-
Uri = "$PiHoleServer/api/auth/session/$Id"
176+
Uri = "$($PiHoleServer.OriginalString)/api/auth/session/$Id"
163177
Method = "Delete"
164178
SkipCertificateCheck = $IgnoreSsl
165179
ContentType = "application/json"

PiHoleShell/Public/Config.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ https://TODO
88
[CmdletBinding()]
99
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
1010
param (
11-
$PiHoleServer,
12-
$Password,
11+
[Parameter(Mandatory = $true)]
12+
[System.URI]$PiHoleServer,
13+
[Parameter(Mandatory = $true)]
14+
[string]$Password,
1315
[bool]$IgnoreSsl = $false,
1416
[bool]$RawOutput = $false
1517
)
1618
try {
1719
$Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl
1820
$Params = @{
1921
Headers = @{sid = $($Sid) }
20-
Uri = "$PiHoleServer/api/config"
22+
Uri = "$($PiHoleServer.OriginalString)/api/config"
2123
Method = "Get"
2224
SkipCertificateCheck = $IgnoreSsl
2325
ContentType = "application/json"

PiHoleShell/Public/DnsControl.ps1

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
function Get-PiHoleDnsBlockingStatus {
22
<#
33
.SYNOPSIS
4-
https://ftl.pi-hole.net/development-v6/docs/#get-/dns/blocking
4+
Get current blocking status
55
66
.PARAMETER PiHoleServer
77
The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100"
88
99
.PARAMETER Password
1010
The API Password you generated from your PiHole server
1111
12+
.PARAMETER IgnoreSsl
13+
Ignore SSL when interacting with the PiHole API
14+
1215
.PARAMETER RawOutput
1316
This will dump the response instead of the formatted object
1417
@@ -18,7 +21,7 @@ Get-PiHoleDnsBlockingStatus -PiHoleServer "http://pihole.domain.com:8080" -Passw
1821
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
1922
param (
2023
[Parameter(Mandatory = $true)]
21-
[string]$PiHoleServer,
24+
[System.URI]$PiHoleServer,
2225
[Parameter(Mandatory = $true)]
2326
[string]$Password,
2427
[bool]$IgnoreSsl = $false,
@@ -29,7 +32,7 @@ Get-PiHoleDnsBlockingStatus -PiHoleServer "http://pihole.domain.com:8080" -Passw
2932

3033
$Params = @{
3134
Headers = @{sid = $($Sid) }
32-
Uri = "$PiHoleServer/api/dns/blocking"
35+
Uri = "$($PiHoleServer.OriginalString)/api/dns/blocking"
3336
Method = "Get"
3437
ContentType = "application/json"
3538
SkipCertificateCheck = $IgnoreSsl
@@ -94,7 +97,7 @@ Set-PiHoleDnsBlocking -PiHoleServer "http://pihole.domain.com:8080" -Password "f
9497
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
9598
param (
9699
[Parameter(Mandatory = $true)]
97-
[string]$PiHoleServer,
100+
[System.URI]$PiHoleServer,
98101
[Parameter(Mandatory = $true)]
99102
[string]$Password,
100103
[ValidateSet("True", "False")]
@@ -111,13 +114,14 @@ Set-PiHoleDnsBlocking -PiHoleServer "http://pihole.domain.com:8080" -Password "f
111114

112115
$Body = "{`"blocking`":$Blocking,`"timer`":$TimeInSeconds}"
113116
$Params = @{
114-
Headers = @{sid = $($Sid)
117+
Headers = @{sid = $($Sid)
115118
Accept = "application/json"
116119
}
117-
Uri = "$PiHoleServer/api/dns/blocking"
118-
Method = "Post"
119-
ContentType = "application/json"
120-
Body = $Body
120+
Uri = "$($PiHoleServer.OriginalString)/api/dns/blocking"
121+
Method = "Post"
122+
ContentType = "application/json"
123+
Body = $Body
124+
SkipCertificateCheck = $IgnoreSsl
121125
}
122126

123127
$Response = Invoke-RestMethod @Params

PiHoleShell/Public/GroupManagement.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ https://TODO
9696
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
9797
param (
9898
[Parameter(Mandatory = $true)]
99-
[string]$PiHoleServer,
99+
[System.URI]$PiHoleServer,
100100
[Parameter(Mandatory = $true)]
101101
[string]$Password,
102102
[Parameter(Mandatory = $true)]
@@ -125,7 +125,7 @@ https://TODO
125125

126126
$Params = @{
127127
Headers = @{sid = $($Sid) }
128-
Uri = "$PiHoleServer/api/groups"
128+
Uri = "$($PiHoleServer.OriginalString)/api/groups"
129129
Method = "Post"
130130
SkipCertificateCheck = $IgnoreSsl
131131
ContentType = "application/json"
@@ -176,7 +176,7 @@ https://TODO
176176
[Diagnostics.CodeAnalysis.SuppressMessage("PSUseShouldProcessForStateChangingFunctions", "", Justification = "Ignoring for now")]
177177
param (
178178
[Parameter(Mandatory = $true)]
179-
[string]$PiHoleServer,
179+
[System.URI]$PiHoleServer,
180180
[Parameter(Mandatory = $true)]
181181
[string]$Password,
182182
[Parameter(Mandatory = $true)]
@@ -229,7 +229,7 @@ https://TODO
229229

230230
$Params = @{
231231
Headers = @{sid = $($Sid) }
232-
Uri = "$PiHoleServer/api/groups/$GroupName"
232+
Uri = "$($PiHoleServer.OriginalString)/api/groups/$GroupName"
233233
Method = "Put"
234234
SkipCertificateCheck = $IgnoreSsl
235235
ContentType = "application/json"
@@ -282,7 +282,7 @@ https://TODO
282282
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
283283
param (
284284
[Parameter(Mandatory = $true)]
285-
[string]$PiHoleServer,
285+
[System.URI]$PiHoleServer,
286286
[Parameter(Mandatory = $true)]
287287
[string]$Password,
288288
[Parameter(Mandatory = $true)]
@@ -300,7 +300,7 @@ https://TODO
300300

301301
$Params = @{
302302
Headers = @{sid = $($Sid) }
303-
Uri = "$PiHoleServer/api/groups/$GroupName"
303+
Uri = "$($PiHoleServer.OriginalString)/api/groups/$GroupName"
304304
Method = "Delete"
305305
SkipCertificateCheck = $IgnoreSsl
306306
ContentType = "application/json"

PiHoleShell/Public/Metrics.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Get-PiHoleStatsRecentBlocked -PiHoleServer "http://pihole.domain.com:8080" -Pass
2323
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
2424
param (
2525
[Parameter(Mandatory = $true)]
26-
[string]$PiHoleServer,
26+
[System.URI]$PiHoleServer,
2727
[Parameter(Mandatory = $true)]
2828
[string]$Password,
2929
[int]$MaxResult = 1,
@@ -35,7 +35,7 @@ Get-PiHoleStatsRecentBlocked -PiHoleServer "http://pihole.domain.com:8080" -Pass
3535
Write-Verbose -Message "MaxResults - $MaxResult"
3636
$Params = @{
3737
Headers = @{sid = $($Sid) }
38-
Uri = "$PiHoleServer/api/stats/recent_blocked?count=$MaxResult"
38+
Uri = "$($PiHoleServer.OriginalString)/api/stats/recent_blocked?count=$MaxResult"
3939
Method = "Get"
4040
SkipCertificateCheck = $IgnoreSsl
4141
ContentType = "application/json"
@@ -81,7 +81,7 @@ https://TODOFINDNEWAPILINK
8181
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
8282
param (
8383
[Parameter(Mandatory = $true)]
84-
[string]$PiHoleServer,
84+
[System.URI]$PiHoleServer,
8585
[Parameter(Mandatory = $true)]
8686
[string]$Password,
8787
[bool]$IgnoreSsl = $false,
@@ -92,7 +92,7 @@ https://TODOFINDNEWAPILINK
9292
Write-Verbose -Message "MaxResults - $MaxResult"
9393
$Params = @{
9494
Headers = @{sid = $($Sid) }
95-
Uri = "$PiHoleServer/api/stats/query_types"
95+
Uri = "$($PiHoleServer.OriginalString)/api/stats/query_types"
9696
Method = "Get"
9797
SkipCertificateCheck = $IgnoreSsl
9898
ContentType = "application/json"
@@ -136,7 +136,7 @@ https://TODOFINDNEWAPILINK
136136
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
137137
param (
138138
[Parameter(Mandatory = $true)]
139-
[string]$PiHoleServer,
139+
[System.URI]$PiHoleServer,
140140
[Parameter(Mandatory = $true)]
141141
[string]$Password,
142142
[int]$MaxResult = 10,
@@ -162,7 +162,7 @@ https://TODOFINDNEWAPILINK
162162

163163
$Params = @{
164164
Headers = @{sid = $($Sid) }
165-
Uri = "$PiHoleServer/api/stats/top_domains?blocked=$Blocked&count=$MaxResult"
165+
Uri = "$($PiHoleServer.OriginalString)/api/stats/top_domains?blocked=$Blocked&count=$MaxResult"
166166
Method = "Get"
167167
SkipCertificateCheck = $IgnoreSsl
168168
ContentType = "application/json"
@@ -191,7 +191,7 @@ The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "h
191191
.PARAMETER Password
192192
The API Password you generated from your PiHole server
193193
194-
.PARAMETER IgnoreSsl
194+
195195
This will dump the response instead of the formatted object
196196
197197
.PARAMETER RawOutput
@@ -204,7 +204,7 @@ Get-PiHoleStatsSummary -PiHoleServer "http://pihole.domain.com:8080" -Password "
204204
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
205205
param (
206206
[Parameter(Mandatory = $true)]
207-
[string]$PiHoleServer,
207+
[System.URI]$PiHoleServer,
208208
[Parameter(Mandatory = $true)]
209209
[string]$Password,
210210
[bool]$IgnoreSsl = $false,
@@ -215,7 +215,7 @@ Get-PiHoleStatsSummary -PiHoleServer "http://pihole.domain.com:8080" -Password "
215215

216216
$Params = @{
217217
Headers = @{sid = $($Sid) }
218-
Uri = "$PiHoleServer/api/stats/summary"
218+
Uri = "$($PiHoleServer.OriginalString)/api/stats/summary"
219219
Method = "Get"
220220
SkipCertificateCheck = $IgnoreSsl
221221
ContentType = "application/json"

0 commit comments

Comments
 (0)