Skip to content
Merged
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
Binary file modified PiHoleShell/PiHoleShell.psd1
Binary file not shown.
45 changes: 1 addition & 44 deletions PiHoleShell/Private/Misc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,4 @@ function Convert-LocalTimeToPiHoleUnixTime {

$ObjectFinal = $Object
Write-Output $ObjectFinal
}

# function Test-HttpPrefixForPiHole {
# param (
# [Parameter(Mandatory)]
# [string]$Url
# )

# Write-Output ($Url -match '^https?://')
# }

# function Test-PiHoleServerAccess {
# param (
# [Parameter(Mandatory)]
# [string]$Url,
# [bool]$IgnoreSsl = $false
# )

# if (Test-HttpPrefixForPiHole -Url $Url) {
# $RawOutput = Invoke-WebRequest -Uri "$Url/admin/login" -Method Head -TimeoutSec 5 -ErrorAction Stop -SkipCertificateCheck
# }
# }

# function Convert-EnabledBoolToString {
# param (
# [bool]$Bool
# )

# switch ($Bool) {
# $false {
# $Enabled = "false"
# }
# $true {
# $Enabled = "true"
# }
# }

# $Object = [PSCustomObject]@{
# Bool = $Enabled
# }

# Write-Output $Object

# }
}
30 changes: 22 additions & 8 deletions PiHoleShell/Public/Authentication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function Request-PiHoleAuth {
}

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

Write-Output $Response.session.sid
}
Expand All @@ -39,14 +40,22 @@ The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "h
.PARAMETER Password
The API Password you generated from your PiHole v6 server

.PARAMETER IgnoreSsl
Ignore SSL when interacting with the PiHole API

.PARAMETER RawOutput
This will dump the response instead of the formatted object

.EXAMPLE
Get-PiHoleCurrentAuthSession -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
#>
[CmdletBinding()]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
[string]$PiHoleServer,
$Password,
[Parameter(Mandatory = $true)]
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[bool]$IgnoreSsl = $false,
[bool]$RawOutput = $false
)
Expand All @@ -55,7 +64,7 @@ Get-PiHoleCurrentAuthSession -PiHoleServer "http://pihole.domain.com:8080" -Pass

$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/auth/sessions"
Uri = "$($PiHoleServer.OriginalString)/api/auth/sessions"
Method = "Get"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down Expand Up @@ -117,7 +126,7 @@ function Remove-PiHoleCurrentAuthSession {
)
$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/auth"
Uri = "$($PiHoleServer.OriginalString)/api/auth"
Method = "Delete"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand All @@ -143,23 +152,28 @@ The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "h
.PARAMETER Password
The API Password you generated from your PiHole server

.PARAMETER IgnoreSsl
Ignore SSL when interacting with the PiHole API

.EXAMPLE
Get-PiHoleCurrentAuthSession -PiHoleServer "http://pihole.domain.com:8080" -Password "fjdsjfldsjfkldjslafjskdl"
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change state')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
$PiHoleServer,
$Password,
$IgnoreSsl,
[Parameter(Mandatory = $true)]
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[bool]$IgnoreSsl = $false,
[int]$Id
)

try {
$Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl
$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/auth/session/$Id"
Uri = "$($PiHoleServer.OriginalString)/api/auth/session/$Id"
Method = "Delete"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down
8 changes: 5 additions & 3 deletions PiHoleShell/Public/Config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ https://TODO
[CmdletBinding()]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
$PiHoleServer,
$Password,
[Parameter(Mandatory = $true)]
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[bool]$IgnoreSsl = $false,
[bool]$RawOutput = $false
)
try {
$Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl
$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/config"
Uri = "$($PiHoleServer.OriginalString)/api/config"
Method = "Get"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down
22 changes: 13 additions & 9 deletions PiHoleShell/Public/DnsControl.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
function Get-PiHoleDnsBlockingStatus {
<#
.SYNOPSIS
https://ftl.pi-hole.net/development-v6/docs/#get-/dns/blocking
Get current blocking status

.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
Ignore SSL when interacting with the PiHole API

.PARAMETER RawOutput
This will dump the response instead of the formatted object

Expand All @@ -18,7 +21,7 @@ Get-PiHoleDnsBlockingStatus -PiHoleServer "http://pihole.domain.com:8080" -Passw
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
[Parameter(Mandatory = $true)]
[string]$PiHoleServer,
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[bool]$IgnoreSsl = $false,
Expand All @@ -29,7 +32,7 @@ Get-PiHoleDnsBlockingStatus -PiHoleServer "http://pihole.domain.com:8080" -Passw

$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/dns/blocking"
Uri = "$($PiHoleServer.OriginalString)/api/dns/blocking"
Method = "Get"
ContentType = "application/json"
SkipCertificateCheck = $IgnoreSsl
Expand Down Expand Up @@ -94,7 +97,7 @@ Set-PiHoleDnsBlocking -PiHoleServer "http://pihole.domain.com:8080" -Password "f
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
[Parameter(Mandatory = $true)]
[string]$PiHoleServer,
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[ValidateSet("True", "False")]
Expand All @@ -111,13 +114,14 @@ Set-PiHoleDnsBlocking -PiHoleServer "http://pihole.domain.com:8080" -Password "f

$Body = "{`"blocking`":$Blocking,`"timer`":$TimeInSeconds}"
$Params = @{
Headers = @{sid = $($Sid)
Headers = @{sid = $($Sid)
Accept = "application/json"
}
Uri = "$PiHoleServer/api/dns/blocking"
Method = "Post"
ContentType = "application/json"
Body = $Body
Uri = "$($PiHoleServer.OriginalString)/api/dns/blocking"
Method = "Post"
ContentType = "application/json"
Body = $Body
SkipCertificateCheck = $IgnoreSsl
}

$Response = Invoke-RestMethod @Params
Expand Down
12 changes: 6 additions & 6 deletions PiHoleShell/Public/GroupManagement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ https://TODO
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
[Parameter(Mandatory = $true)]
[string]$PiHoleServer,
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[Parameter(Mandatory = $true)]
Expand Down Expand Up @@ -125,7 +125,7 @@ https://TODO

$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/groups"
Uri = "$($PiHoleServer.OriginalString)/api/groups"
Method = "Post"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down Expand Up @@ -176,7 +176,7 @@ https://TODO
[Diagnostics.CodeAnalysis.SuppressMessage("PSUseShouldProcessForStateChangingFunctions", "", Justification = "Ignoring for now")]
param (
[Parameter(Mandatory = $true)]
[string]$PiHoleServer,
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[Parameter(Mandatory = $true)]
Expand Down Expand Up @@ -229,7 +229,7 @@ https://TODO

$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/groups/$GroupName"
Uri = "$($PiHoleServer.OriginalString)/api/groups/$GroupName"
Method = "Put"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down Expand Up @@ -282,7 +282,7 @@ https://TODO
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
[Parameter(Mandatory = $true)]
[string]$PiHoleServer,
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[Parameter(Mandatory = $true)]
Expand All @@ -300,7 +300,7 @@ https://TODO

$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/groups/$GroupName"
Uri = "$($PiHoleServer.OriginalString)/api/groups/$GroupName"
Method = "Delete"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down
18 changes: 9 additions & 9 deletions PiHoleShell/Public/Metrics.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Get-PiHoleStatsRecentBlocked -PiHoleServer "http://pihole.domain.com:8080" -Pass
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
[Parameter(Mandatory = $true)]
[string]$PiHoleServer,
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[int]$MaxResult = 1,
Expand All @@ -35,7 +35,7 @@ Get-PiHoleStatsRecentBlocked -PiHoleServer "http://pihole.domain.com:8080" -Pass
Write-Verbose -Message "MaxResults - $MaxResult"
$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/stats/recent_blocked?count=$MaxResult"
Uri = "$($PiHoleServer.OriginalString)/api/stats/recent_blocked?count=$MaxResult"
Method = "Get"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down Expand Up @@ -81,7 +81,7 @@ https://TODOFINDNEWAPILINK
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
[Parameter(Mandatory = $true)]
[string]$PiHoleServer,
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[bool]$IgnoreSsl = $false,
Expand All @@ -92,7 +92,7 @@ https://TODOFINDNEWAPILINK
Write-Verbose -Message "MaxResults - $MaxResult"
$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/stats/query_types"
Uri = "$($PiHoleServer.OriginalString)/api/stats/query_types"
Method = "Get"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down Expand Up @@ -136,7 +136,7 @@ https://TODOFINDNEWAPILINK
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
[Parameter(Mandatory = $true)]
[string]$PiHoleServer,
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[int]$MaxResult = 10,
Expand All @@ -162,7 +162,7 @@ https://TODOFINDNEWAPILINK

$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/stats/top_domains?blocked=$Blocked&count=$MaxResult"
Uri = "$($PiHoleServer.OriginalString)/api/stats/top_domains?blocked=$Blocked&count=$MaxResult"
Method = "Get"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down Expand Up @@ -191,7 +191,7 @@ The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "h
.PARAMETER Password
The API Password you generated from your PiHole server

.PARAMETER IgnoreSsl

This will dump the response instead of the formatted object

.PARAMETER RawOutput
Expand All @@ -204,7 +204,7 @@ Get-PiHoleStatsSummary -PiHoleServer "http://pihole.domain.com:8080" -Password "
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")]
param (
[Parameter(Mandatory = $true)]
[string]$PiHoleServer,
[System.URI]$PiHoleServer,
[Parameter(Mandatory = $true)]
[string]$Password,
[bool]$IgnoreSsl = $false,
Expand All @@ -215,7 +215,7 @@ Get-PiHoleStatsSummary -PiHoleServer "http://pihole.domain.com:8080" -Password "

$Params = @{
Headers = @{sid = $($Sid) }
Uri = "$PiHoleServer/api/stats/summary"
Uri = "$($PiHoleServer.OriginalString)/api/stats/summary"
Method = "Get"
SkipCertificateCheck = $IgnoreSsl
ContentType = "application/json"
Expand Down
Loading