From aa6840e0ae82a91b44bae1700365dfd421a5985f Mon Sep 17 00:00:00 2001 From: TheTaylorLee <53202926+TheTaylorLee@users.noreply.github.com> Date: Wed, 3 Apr 2024 13:38:23 -0500 Subject: [PATCH] fix: new-localinpolicy --- modules/AdminToolbox.FortiWizard/Changelog.md | 3 +- .../Private/New-LocalInAddressObject.ps1 | 32 +++++++++++++++++++ .../Public/New-LocalInPolicy.ps1 | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 modules/AdminToolbox.FortiWizard/Private/New-LocalInAddressObject.ps1 diff --git a/modules/AdminToolbox.FortiWizard/Changelog.md b/modules/AdminToolbox.FortiWizard/Changelog.md index 2f73013e..e40bdabe 100644 --- a/modules/AdminToolbox.FortiWizard/Changelog.md +++ b/modules/AdminToolbox.FortiWizard/Changelog.md @@ -177,4 +177,5 @@ * **2.18.42** CI Maintenance Release * **2.18.43** CI Maintenance Release * **2.18.44** CI Maintenance Release -* **2.18.45** CI Maintenance Release \ No newline at end of file +* **2.18.45** CI Maintenance Release +* **2.18.46** Fix new-localinpolicy address objects inserting the cidr twice into address object names \ No newline at end of file diff --git a/modules/AdminToolbox.FortiWizard/Private/New-LocalInAddressObject.ps1 b/modules/AdminToolbox.FortiWizard/Private/New-LocalInAddressObject.ps1 new file mode 100644 index 00000000..210f4a26 --- /dev/null +++ b/modules/AdminToolbox.FortiWizard/Private/New-LocalInAddressObject.ps1 @@ -0,0 +1,32 @@ +#Required By Function +#New-LocalInPolicy + +Function New-LocalInAddressObject { + + [CmdletBinding()] + Param ( + [Parameter(Mandatory = $true)]$AddressName, + [Parameter(Mandatory = $true)] + [ValidateScript( { + if ($_ -match '^[0-9]{1,3}[.]{1}[0-9]{1,3}[.]{1}[0-9]{1,3}[.]{1}[0-9]{1,3}[/]{1}[0-9]{1,2}$') { + $true + } + else { + throw "$_ is an invalid pattern. You must provide a proper CIDR format. ex: 192.168.0.0/24" + } + })] + $CIDR + ) + + $calc = Invoke-PSipcalc $cidr + $IPAddress = ($calc).IP + $SubnetMask = ($calc).SubnetMask + + Write-Output " +config firewall address + edit ""$AddressName"" + set subnet $IPAddress $SubnetMask + set allow-routing enable + next +end" +} \ No newline at end of file diff --git a/modules/AdminToolbox.FortiWizard/Public/New-LocalInPolicy.ps1 b/modules/AdminToolbox.FortiWizard/Public/New-LocalInPolicy.ps1 index 8477013d..5b2d8ba8 100644 --- a/modules/AdminToolbox.FortiWizard/Public/New-LocalInPolicy.ps1 +++ b/modules/AdminToolbox.FortiWizard/Public/New-LocalInPolicy.ps1 @@ -73,7 +73,7 @@ function New-LocalinPolicy { } Foreach ($Address in $Addresses) { - New-AddressObject -AddressName $Address.Name -CIDR $Address.CIDR + New-LocalInAddressObject -AddressName $Address.Name -CIDR $Address.CIDR } #Create Address Objects for the policy