pfSense configuration backup

This page summarizes the projects mentioned and recommended in the original post on /r/PowerShell

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • pfSense_API

    Automate your pfSense management

  • <# .Synopsis Get pfSense configuration .DESCRIPTION Get a copy of pfsense configuration XML file. .EXAMPLE $splat = @{ Uri = 'https://30.20.10.0:54321' Username = 'admin' Password = 'pfsense' } $session = Connect-PfSense @splat Get-PfSenseConfig -Session $session .EXAMPLE # You can pipe both commands to save you some typing $splat = @{ Uri = 'https://30.20.10.0:54321' Username = 'admin' Password = 'pfsense' } Connect-PfSense @splat | Get-PfSenseConfig .EXAMPLE # If you want to save the file with filename supplied by pfSense $splat = @{ Uri = 'https://30.20.10.0:54321' Username = 'admin' Password = 'pfsense' } Connect-PfSense @splat -SkipCertificateCheck | Get-PfSenseConfig -Object | % { $_.config | Set-Content $_.filename } .INPUTS Session object from Connect-PfSense .OUTPUTS String .NOTES Based on the work of Chris, https://github.com/masters274/pfSense_API MIT license. Author: poshftw, 2022 #> function Get-PfSenseConfig { [CmdletBinding()] [Alias()] [OutputType([string])] Param ( # Session object from Connect-PfSense [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] $Session, # Output as an object @{FileName, Config} [switch]$Object ) $wrUri = '{0}/diag_backup.php' -f $Session.Uri $webRequestSplat = @{ ErrorAction = 'Stop' } if ($Session.SkipCertificateCheck) { $webRequestSplat.Add('SkipCertificateCheck', $true) } try { $request = Invoke-WebRequest -Uri $wruri -Method Get -WebSession $Session.Session @webRequestSplat $Body = @{ __csrf_magic = $request.InputFields[0].Value donotbackuprrd = 'yes' download = 'Download configuration as XML' } $request = Invoke-WebRequest -Uri $wrUri -Method Post -Body $Body -WebSession $Session.Session @webRequestSplat # check received data if ($request.Headers['Content-Type'] -match 'application/octet-stream') { # pfsense supplies filename by itself # but dear Redmond, why do we need those ugly join hacks? $null = $request.Headers['Content-Disposition'] -join '' -match 'filename=(?.+\.xml)' $filename = $Matches['filename'] #convert from bytes $Encoder = [System.Text.Encoding]::ASCII $Config = $Encoder.GetString($request.Content) if ($Object) { [PSCustomObject][ordered]@{ Filename = $filename Config = $Config } } else{ $Config } } elseif ($request.Headers['Content-Type'] -match 'html') { $thisErrorMessage = ("Operation failed, probably wrong credentials: {0}" -f $Error[0]) } else { $thisErrorMessage = ("Unknown error has occured: {0}" -f $Error[0]) } } catch { $Error[0] Write-Error -Message $thisErrorMessage } }

  • platform-compat

    Discontinued Roslyn analyzer that finds usages of APIs that will throw PlatformNotSupportedException on certain platforms.

  • And if you really want to be secure you need to something better than a SecureString: https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.md

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts