diff --git a/PiHoleShell/Public/FTLInformation.ps1 b/PiHoleShell/Public/FTLInformation.ps1 index 98beadf..ad14d80 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..4da0524 --- /dev/null +++ b/PiHoleShell/Public/Teleporter.ps1 @@ -0,0 +1,71 @@ +function Get-PiHoleTeleporterDownload { + <# +.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!" + } + $FileName = "$FileName.tar.gz" + $OutFile = "$FolderPath\$FileName" + 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]@{ + FileName = $FileName + FilePath = $OutFile + RootFolder = $FolderPath + FileSizeKB = [math]::Ceiling((Get-Item $OutFile).Length / 1KB) + } + $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