From b4a1cbf6701d5b06aed532ad5fabe704589a83ee Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 5 Feb 2024 21:14:52 +0100 Subject: [PATCH] DNS Filter(Profile): Add cmdlet for get DNS Web Filter --- PowerFGT/Public/cmdb/dnsfilter/profile.ps1 | 112 +++++++++++++++++++++ Tests/integration/Connection.Tests.ps1 | 3 + 2 files changed, 115 insertions(+) create mode 100644 PowerFGT/Public/cmdb/dnsfilter/profile.ps1 diff --git a/PowerFGT/Public/cmdb/dnsfilter/profile.ps1 b/PowerFGT/Public/cmdb/dnsfilter/profile.ps1 new file mode 100644 index 000000000..e5c000d29 --- /dev/null +++ b/PowerFGT/Public/cmdb/dnsfilter/profile.ps1 @@ -0,0 +1,112 @@ +# +# Copyright, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# +function Get-FGTDnsfilterProfile { + + <# + .SYNOPSIS + Get list of all Dnsfilter Profile settings + + .DESCRIPTION + Get list of all Dnsfilter Profile (name, sdns, ftgd-dns ...) + + .EXAMPLE + Get-FGTDnsfilterProfile + + Get list of all settings of Dnsfilter Profile + + .EXAMPLE + Get-FGTDnsfilterProfile -name myDnsfilterProfile + + Get Dnsfilter Profile named myDnsfilterProfile + + .EXAMPLE + Get-FGTDnsfilterProfile -name FGT -filter_type contains + + Get Dnsfilter Profile contains with *FGT* + + .EXAMPLE + Get-FGTDnsfilterProfile -meta + + Get list of all settings of Dnsfilter Profile with metadata (q_...) like usage (q_ref) + + .EXAMPLE + Get-FGTDnsfilterProfile -skip + + Get list of all settings of Dnsfilter Profile (but only relevant attributes) + + .EXAMPLE + Get-FGTDnsfilterProfile -vdom vdomX + + Get list of all settings of Dnsfilter Profile on vdomX + #> + + [CmdletBinding(DefaultParameterSetName = "default")] + Param( + [Parameter (Mandatory = $false, Position = 1, ParameterSetName = "name")] + [string]$name, + [Parameter (Mandatory = $false)] + [Parameter (ParameterSetName = "filter")] + [string]$filter_attribute, + [Parameter (Mandatory = $false)] + [Parameter (ParameterSetName = "name")] + [Parameter (ParameterSetName = "filter")] + [ValidateSet('equal', 'contains')] + [string]$filter_type = "equal", + [Parameter (Mandatory = $false)] + [Parameter (ParameterSetName = "filter")] + [psobject]$filter_value, + [Parameter(Mandatory = $false)] + [switch]$meta, + [Parameter(Mandatory = $false)] + [switch]$skip, + [Parameter(Mandatory = $false)] + [String[]]$vdom, + [Parameter(Mandatory = $false)] + [psobject]$connection = $DefaultFGTConnection + ) + + Begin { + } + + Process { + + $uri = 'api/v2/cmdb/dnsfilter/profile' + + $invokeParams = @{ } + if ( $PsBoundParameters.ContainsKey('meta') ) { + $invokeParams.add( 'meta', $meta ) + } + if ( $PsBoundParameters.ContainsKey('skip') ) { + $invokeParams.add( 'skip', $skip ) + } + if ( $PsBoundParameters.ContainsKey('vdom') ) { + $invokeParams.add( 'vdom', $vdom ) + } + + #Filtering + switch ( $PSCmdlet.ParameterSetName ) { + "name" { + $filter_value = $name + $filter_attribute = "name" + } + default { } + } + + #if filter value and filter_attribute, add filter (by default filter_type is equal) + if ( $filter_value -and $filter_attribute ) { + $invokeParams.add( 'filter_value', $filter_value ) + $invokeParams.add( 'filter_attribute', $filter_attribute ) + $invokeParams.add( 'filter_type', $filter_type ) + } + + + $response = Invoke-FGTRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams + $response.results + } + + End { + } +} diff --git a/Tests/integration/Connection.Tests.ps1 b/Tests/integration/Connection.Tests.ps1 index d55aec352..79235c7ed 100644 --- a/Tests/integration/Connection.Tests.ps1 +++ b/Tests/integration/Connection.Tests.ps1 @@ -145,6 +145,9 @@ Describe "Connect to a FortiGate (using multi connection)" { It "Use Multi connection for call Get Antivirus Profile" { { Get-FGTAntivirusProfile -connection $fgt } | Should -Not -Throw } + It "Use Multi connection for call Get DNS Filter Profile" { + { Get-FGTDnsfilterProfile -connection $fgt } | Should -Not -Throw + } It "Use Multi connection for call Get IPS Sensor" { { Get-FGTIpsSensor -connection $fgt } | Should -Not -Throw }