From 74f7f46eb7f4057b7c7d1cb164c5b3ed63728d17 Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Fri, 27 Jun 2025 16:52:37 -0500 Subject: [PATCH 1/3] added more functions --- PiHoleShell/Public/FTLInformation.ps1 | 60 +++++++++++++++++++++++ PiHoleShell/Public/Teleporter.ps1 | 68 +++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 PiHoleShell/Public/Teleporter.ps1 diff --git a/PiHoleShell/Public/FTLInformation.ps1 b/PiHoleShell/Public/FTLInformation.ps1 index 98beadf..2f22165 100644 --- a/PiHoleShell/Public/FTLInformation.ps1 +++ b/PiHoleShell/Public/FTLInformation.ps1 @@ -127,6 +127,66 @@ This API hook returns a collection of host infos. break } + finally { + if ($Sid) { + Remove-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Sid $Sid -IgnoreSsl $IgnoreSsl + } + } +} + +function Get-PiHoleLogWebserver { + <# +.SYNOPSIS +Get info about logs for webserver + + #> + #Work In Progress + [CmdletBinding()] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [int]$NextID, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + try { + $Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl + + if ($NextID) { + $Uri = "$($PiHoleServer.OriginalString)/api/logs/webserver?nextId=$NextId" + + } + else { + $Uri = "$($PiHoleServer.OriginalString)/api/logs/webserver" + } + + $Params = @{ + Headers = @{sid = $($Sid) } + Uri = $Uri + Method = "Get" + SkipCertificateCheck = $IgnoreSsl + ContentType = "application/json" + } + + $Response = Invoke-RestMethod @Params + + if ($RawOutput) { + Write-Output $Response + } + + else { + $ObjectFinal = @() + } + } + + catch { + Write-Error -Message $_.Exception.Message + break + } + finally { if ($Sid) { Remove-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Sid $Sid -IgnoreSsl $IgnoreSsl diff --git a/PiHoleShell/Public/Teleporter.ps1 b/PiHoleShell/Public/Teleporter.ps1 new file mode 100644 index 0000000..8c8d88b --- /dev/null +++ b/PiHoleShell/Public/Teleporter.ps1 @@ -0,0 +1,68 @@ +function Get-PiHoleTeleporter { + <# +.SYNOPSIS +Get info about logs for webserver + + #> + #Work In Progress + [CmdletBinding()] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [Parameter(Mandatory = $true)] + [System.IO.DirectoryInfo]$FolderPath, + [Parameter(Mandatory = $true)] + [string]$FileName, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + try { + $Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl + + if (!(Test-Path -Path $FolderPath)) { + throw "$FolderPath does not exist!" + } + $OutFile = "$FolderPath\$FileName.tar.gz" + if (Test-Path -Path $OutFile) { + throw "$OutFile already exists!" + } + + $Params = @{ + Headers = @{sid = $($Sid) } + Uri = "$($PiHoleServer.OriginalString)/api/teleporter" + Method = "Get" + SkipCertificateCheck = $IgnoreSsl + ContentType = "application/json" + } + + $Response = Invoke-RestMethod @Params -OutFile $OutFile + + if ($RawOutput) { + Write-Output $Response + } + + else { + $ObjectFinal = @() + $Object = [PSCustomObject]@{ + Backup = "Completed" + FilePath = $OutFile + } + $ObjectFinal += $Object + Write-Output $ObjectFinal + } + } + + catch { + Write-Error -Message $_.Exception.Message + break + } + + finally { + if ($Sid) { + Remove-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Sid $Sid -IgnoreSsl $IgnoreSsl + } + } +} \ No newline at end of file From eecac04f783ae75c26f5c0feaa8202ae40151cdd Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Fri, 27 Jun 2025 17:05:37 -0500 Subject: [PATCH 2/3] debugging --- PiHoleShell/Public/FTLInformation.ps1 | 2 +- PiHoleShell/Public/Teleporter.ps1 | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PiHoleShell/Public/FTLInformation.ps1 b/PiHoleShell/Public/FTLInformation.ps1 index 2f22165..ad14d80 100644 --- a/PiHoleShell/Public/FTLInformation.ps1 +++ b/PiHoleShell/Public/FTLInformation.ps1 @@ -178,7 +178,7 @@ Get info about logs for webserver } else { - $ObjectFinal = @() + #$ObjectFinal = @() } } diff --git a/PiHoleShell/Public/Teleporter.ps1 b/PiHoleShell/Public/Teleporter.ps1 index 8c8d88b..b21f602 100644 --- a/PiHoleShell/Public/Teleporter.ps1 +++ b/PiHoleShell/Public/Teleporter.ps1 @@ -25,7 +25,8 @@ Get info about logs for webserver if (!(Test-Path -Path $FolderPath)) { throw "$FolderPath does not exist!" } - $OutFile = "$FolderPath\$FileName.tar.gz" + $FileName = "$FileName.tar.gz" + $OutFile = "$FolderPath\$FileName" if (Test-Path -Path $OutFile) { throw "$OutFile already exists!" } @@ -47,8 +48,10 @@ Get info about logs for webserver else { $ObjectFinal = @() $Object = [PSCustomObject]@{ - Backup = "Completed" - FilePath = $OutFile + FileName = $FileName + FilePath = $OutFile + RootFolder = $FolderPath + FileSizeKB = [math]::Ceiling((Get-Item $OutFile).Length / 1KB) } $ObjectFinal += $Object Write-Output $ObjectFinal From 3ac7ce899f1b67d4fd7f05855586ae568be9f64f Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Fri, 27 Jun 2025 17:08:54 -0500 Subject: [PATCH 3/3] debugging --- PiHoleShell/Public/Teleporter.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PiHoleShell/Public/Teleporter.ps1 b/PiHoleShell/Public/Teleporter.ps1 index b21f602..4da0524 100644 --- a/PiHoleShell/Public/Teleporter.ps1 +++ b/PiHoleShell/Public/Teleporter.ps1 @@ -1,4 +1,4 @@ -function Get-PiHoleTeleporter { +function Get-PiHoleTeleporterDownload { <# .SYNOPSIS Get info about logs for webserver