Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -data parameter for Add/Set function #234

Merged
merged 9 commits into from
Feb 6, 2024
28 changes: 28 additions & 0 deletions PowerFGT/Public/cmdb/firewall/addressgroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ function Add-FGTFirewallAddressGroup {
Add-FGTFirewallAddressGroup -name MyAddressGroup -member MyAddress1 -comment "My Address Group"

Add Address Group with member MyAddress1 and a comment

.EXAMPLE
$data = @{ "color" = 23 }
PS C:\>Add-FGTFirewallAddressGroup -name MyAddressGroup -member MyAddress1 -comment "My Address Group".0 -data $data

Add Address Group with member MyAddress1, a comment and color (23) via -data parameter
#>

Param(
Expand All @@ -39,6 +45,8 @@ function Add-FGTFirewallAddressGroup {
[string]$comment,
[Parameter (Mandatory = $false)]
[boolean]$visibility,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -93,6 +101,12 @@ function Add-FGTFirewallAddressGroup {
}
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$addrgrp | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

Invoke-FGTRestMethod -method "POST" -body $addrgrp -uri $uri -connection $connection @invokeParams | Out-Null

Get-FGTFirewallAddressGroup -connection $connection @invokeParams -name $name
Expand Down Expand Up @@ -376,6 +390,12 @@ function Set-FGTFirewallAddressGroup {

Change MyFGTAddressGroup to set a new comment and disabled visibility

.EXAMPLE
$data = @{ "color" = 23 }
PS C:\>$MyFGTAddressGroup = Get-FGTFirewallAddressGroup -name MyFGTAddressGroup
PS C:\>$MyFGTAddressGroup | Set-FGTFirewallAddressGroup -data $data

Change MyFGTAddressGroup to set color (23) using -data
#>

[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'medium')]
Expand All @@ -392,6 +412,8 @@ function Set-FGTFirewallAddressGroup {
[string]$comment,
[Parameter (Mandatory = $false)]
[boolean]$visibility,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -448,6 +470,12 @@ function Set-FGTFirewallAddressGroup {
}
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$_addrgrp | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

if ($PSCmdlet.ShouldProcess($addrgrp.name, 'Configure Firewall Address Group')) {
Invoke-FGTRestMethod -method "PUT" -body $_addrgrp -uri $uri -uri_escape $old_name -connection $connection @invokeParams | out-Null

Expand Down
15 changes: 15 additions & 0 deletions PowerFGT/Public/cmdb/firewall/policy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ function Add-FGTFirewallPolicy {
Add-FGTFirewallPolicy -name MyFGTPolicy -srcintf port1 -dstintf port2 -srcaddr all -dstaddr all -policyid 23

Add a MyFGTPolicy with Policy ID equal 23

.EXAMPLE
$data = @{ "logtraffic-start" = "enable" }
Add-FGTFirewallPolicy -name MyFGTPolicy -srcintf port1 -dstintf port2 -srcaddr all -dstaddr all -data $data

Add a MyFGTPolicy with logtraffic-start using -data

#>


Expand Down Expand Up @@ -100,6 +107,8 @@ function Add-FGTFirewallPolicy {
[string[]]$ippool,
[Parameter (Mandatory = $false)]
[switch]$skip,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -233,6 +242,12 @@ function Add-FGTFirewallPolicy {
$policy | add-member -name "poolname" -membertype NoteProperty -Value $ippool_array
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$policy | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

$post = Invoke-FGTRestMethod -method "POST" -body $policy -uri $uri -connection $connection @invokeParams

if ( $PsBoundParameters.ContainsKey('name') ) {
Expand Down
4 changes: 2 additions & 2 deletions PowerFGT/Public/cmdb/firewall/vip.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ function Add-FGTFirewallVip {
.EXAMPLE
Add-FGTFirewallVip -name myVIP4-5000-6000 -type static-nat -extip 192.0.2.1 -mappedip 198.51.100.1 -portforward -extport 5000 -mappedport 6000 -protocol udp

Add VIP objet type static-nat (One to One) with name myVIP3 with external IP 192.0.2.1 and mapped IP 198.51.100.1 with Port Forward and UDP Port 5000 mapped to port 6000
Add VIP objet type static-nat (One to One) with name myVIP4 with external IP 192.0.2.1 and mapped IP 198.51.100.1 with Port Forward and UDP Port 5000 mapped to port 6000

.EXAMPLE
$data = @{ "nat-source-vip" = "enable" ; "color" = "23"}
PS C> Add-FGTFirewallVip -name myVIP5-data -type static-nat -extip 192.0.2.1 -mappedip 198.51.100.1 -data $data

Change dns-mapping-ttl and color settings using -data parameter
Add VIP objet type static-nat (One to One) with name myVIP5 with nat-source-vip and color settings using -data parameter
#>

Param(
Expand Down
28 changes: 28 additions & 0 deletions PowerFGT/Public/cmdb/firewall/vipgroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ function Add-FGTFirewallVipGroup {
Add-FGTFirewallVipGroup -name MyVipGroup -member MyVip1 -comments "My VIP Group" -interface wan1

Add VIP Group with member MyVip1 and a comments, associated to interface wan1

.EXAMPLE
$data = @{ "color" = "23"}
PS C> Add-FGTFirewallVipGroup -name MyVipGroup -member MyVip1 -interface wan1 -data $data

Add VIP Group with member MyVip1 with color 23 (using -data)
#>

Param(
Expand All @@ -40,6 +46,8 @@ function Add-FGTFirewallVipGroup {
[Parameter (Mandatory = $false)]
[ValidateLength(0, 255)]
[string]$comments,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -78,6 +86,12 @@ function Add-FGTFirewallVipGroup {
#TODO: check if interface is valid (and also if members use the same interface...)
$vipgrp | add-member -name "interface" -membertype NoteProperty -Value $interface

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$vipgrp | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

if ( $PsBoundParameters.ContainsKey('comments') ) {
$vipgrp | add-member -name "comments" -membertype NoteProperty -Value $comments
}
Expand Down Expand Up @@ -367,6 +381,12 @@ function Set-FGTFirewallVipGroup {

Change MyFGTVipGroup to set a new comments

.EXAMPLE
$data = @{ "color" = "23" }
PS C:\>$MyFGTVipGroup = Get-FGTFirewallVipGroup -name MyFGTVipGroup
PS C:\>$MyFGTVipGroup | Set-FGTFirewallVipGroup -data $data

Change MyFGTVipGroup to set color (23) with -data parameter
#>

[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'medium')]
Expand All @@ -381,6 +401,8 @@ function Set-FGTFirewallVipGroup {
[Parameter (Mandatory = $false)]
[ValidateLength(0, 255)]
[string]$comments,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -422,6 +444,12 @@ function Set-FGTFirewallVipGroup {
$_vipgrp | add-member -name "comments" -membertype NoteProperty -Value $comments
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$_vipgrp | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

if ($PSCmdlet.ShouldProcess($addrgrp.name, 'Configure Firewall VIP Group')) {
Invoke-FGTRestMethod -method "PUT" -body $_vipgrp -uri $uri -uri_escape $old_name -connection $connection @invokeParams | out-Null

Expand Down
14 changes: 14 additions & 0 deletions PowerFGT/Public/cmdb/router/static.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ function Add-FGTRouterStatic {
Add-FGTRouterStatic -status:$false -dst 198.51.100.0/24 -gateway 192.0.2.254 -device internal1

Add a route with status disabled

.EXAMPLE
$data = @{ "sdwan" = "enable" }
PS C:\>Add-FGTRouterStatic -dst 198.51.100.0/24 -gateway 192.0.2.254 -device internal1 -data $data

Add a route with sdwan enable using -data
#>

[CmdletBinding(DefaultParameterSetName = "default")]
Expand Down Expand Up @@ -222,6 +228,8 @@ function Add-FGTRouterStatic {
[Parameter (Mandatory = $false)]
[switch]$bfd = $false,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter (Mandatory = $false)]
[switch]$skip,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
Expand Down Expand Up @@ -357,6 +365,12 @@ function Add-FGTRouterStatic {
}
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$static | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

$post = Invoke-FGTRestMethod -method "POST" -body $static -uri $uri -connection $connection @invokeParams

#if you don't have seq-num get the number with the POST
Expand Down
28 changes: 28 additions & 0 deletions PowerFGT/Public/cmdb/system/interface.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function Add-FGTSystemInterface {
Add-FGTSystemInterface -name PowerFGT_lo -loopback -mode static -ip 192.0.2.1 -netmask 255.255.255.255 -allowaccess ping

This creates a new interface loopback with IP 192.0.2.1(/32) and allow access to ping

.EXAMPLE
$data = @{ 'sflow-sampler' = "enable" }
Add-FGTSystemInterface -name PowerFGT -interface port10 -vlan_id 10 -data $data

This creates a new interface with sflow-sampler enable using -data parameter
#>

Param(
Expand Down Expand Up @@ -77,6 +83,8 @@ function Add-FGTSystemInterface {
[string]$netmask,
[Parameter (Mandatory = $false)]
[string]$vdom_interface = "root",
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -166,6 +174,12 @@ function Add-FGTSystemInterface {
$_interface | add-member -name "device-identification" -membertype NoteProperty -Value $device_identification
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$_interface | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

$null = Invoke-FGTRestMethod -uri $uri -method 'POST' -body $_interface -connection $connection @invokeParams

Get-FGTSystemInterface -name $name -connection $connection @invokeParams
Expand Down Expand Up @@ -377,6 +391,12 @@ function Set-FGTSystemInterface {
Get-FGTSystemInterface -name PowerFGT | Set-FGTSystemInterface -dhcprelayip $null

This disables DCHP relay and clears the relay ip addresses

.EXAMPLE
$data = @{ "sflow-sampler" = "enable" }
PS C:\>Get-FGTSystemInterface -name PowerFGT | Set-FGTSystemInterface -data $data

Configure sflow-sampler setting using -data parameter on interface PowerFGT
#>

[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'medium')]
Expand Down Expand Up @@ -405,6 +425,8 @@ function Set-FGTSystemInterface {
[string]$status,
[Parameter (Mandatory = $false)]
[string]$device_identification,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -477,6 +499,12 @@ function Set-FGTSystemInterface {
}
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$_interface | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

if ($PSCmdlet.ShouldProcess($interface.name, 'Set interface')) {
$null = Invoke-FGTRestMethod -uri $uri -method 'PUT' -body $_interface -connection $connection @invokeParams
Get-FGTSystemInterface -name $interface.name -connection $connection @invokeParams
Expand Down
16 changes: 16 additions & 0 deletions PowerFGT/Public/cmdb/system/zone.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ function Add-FGTSystemZone {
[string[]]$interfaces,
[Parameter(Mandatory = $false)]
[string]$description,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -193,6 +195,12 @@ function Add-FGTSystemZone {
}
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$zone | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

Invoke-FGTRestMethod -uri 'api/v2/cmdb/system/zone' -method 'POST' -body $zone -connection $connection @invokeParams | Out-Null
Get-FGTSystemZone -name $name -connection $connection @invokeParams

Expand Down Expand Up @@ -246,6 +254,8 @@ function Set-FGTSystemZone {
[string]$description,
[Parameter(Mandatory = $false)]
[string[]]$interfaces,
[Parameter (Mandatory = $false)]
[hashtable]$data,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -301,6 +311,12 @@ function Set-FGTSystemZone {
}
}

if ( $PsBoundParameters.ContainsKey('data') ) {
$data.GetEnumerator() | ForEach-Object {
$zone_body | Add-member -name $_.key -membertype NoteProperty -Value $_.value
}
}

if ($PSCmdlet.ShouldProcess($zone.name, 'Set zone')) {
Invoke-FGTRestMethod -uri "api/v2/cmdb/system/zone" -uri_escape $zone.name -method 'PUT' -body $zone_body -connection $connection @invokeParams | Out-Null
Get-FGTSystemZone -name $name -connection $connection @invokeParams
Expand Down
Loading