Skip to content

Feature/ip cidr conversion#103

Merged
alagoutte merged 8 commits into
AsBuiltReport:devfrom
msoukhomlinov:feature/ip-cidr-conversion
Jan 14, 2025
Merged

Feature/ip cidr conversion#103
alagoutte merged 8 commits into
AsBuiltReport:devfrom
msoukhomlinov:feature/ip-cidr-conversion

Conversation

@msoukhomlinov

Copy link
Copy Markdown
Contributor

Add CIDR Notation Support for IP Addresses and Subnets

Overview

This PR adds the ability to display IP addresses and subnet masks in CIDR notation throughout the report. The feature is configurable through a new option in the JSON configuration file.

New Configuration Option

{
    "Report": {
        "InfoLevel": {
            "UseCIDRNotation": false
        }
    }
}

New Functions

Added new private functions in Src/Private/Convert-AbrFgtSubnetToCIDR.ps1:

  • Convert-AbrFgtSubnetToCIDR: Converts IP/subnet pairs to CIDR notation
  • Convert-AbrFgtSubnetMaskToCIDR: Helper function for subnet mask conversion

Modified Files

Get-AbrFgtFirewall.ps1

  • Added CIDR conversion for firewall address objects (type: "ipmask")

Get-AbrFgtRoute.ps1

  • Added CIDR conversion for:
    • Route Monitor section (ip_mask)
    • Static Route destinations
    • Policy Based Route source/destination subnets

Get-AbrFgtSystem.ps1

  • Added CIDR conversion for:
    • Interface primary IP addresses
    • Interface secondary IP addresses
    • Interface remote IP addresses
    • Administrator trusted hosts

Get-AbrFgtVPNIPsec.ps1

  • Added CIDR conversion for Phase 2 configurations:
    • Source subnets
    • Destination subnets

Feature Behavior

When UseCIDRNotation = true

  • Converts space-separated IP/subnet pairs to CIDR notation
    • Example: "192.168.1.0 255.255.255.0" → "192.168.1.0/24"
  • Preserves existing CIDR notation
  • Single IP addresses get /32 suffix

When UseCIDRNotation = false

  • Maintains original FortiGate format
  • Some fields use forward slashes instead of spaces for consistency

Error Handling

  • Invalid IP addresses or subnet masks are returned unchanged
  • Includes error messages for troubleshooting
  • Maintains existing functionality when conversion fails

Testing

  • Tested with various IP/subnet combinations
  • Verified behavior with configuration enabled/disabled
  • Confirmed error handling for invalid inputs
  • Checked formatting consistency across all sections

- Add UseCIDRNotation configuration option

- Add Convert-AbrFgtSubnetToCIDR function for IP/subnet conversion

- Implement CIDR conversion in firewall, route, system, and VPN IPsec sections

- Add error handling and maintain backward compatibility
@msoukhomlinov
msoukhomlinov marked this pull request as draft January 13, 2025 09:37
@msoukhomlinov
msoukhomlinov marked this pull request as ready for review January 13, 2025 09:41

@alagoutte alagoutte left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor change and it will be good !

add good idea also for Options

Thanks !

Comment thread Src/Private/Convert-AbrFgtSubnetToCIDR.ps1
Comment thread Src/Private/Get-AbrFgtRoute.ps1 Outdated
Comment thread Src/Private/Get-AbrFgtSystem.ps1 Outdated
Comment thread h origin dev Outdated
Comment thread Src/Private/Get-AbrFgtVPNIPsec.ps1 Outdated
Comment thread AsBuiltReport.Fortinet.FortiGate.json
@msoukhomlinov

Copy link
Copy Markdown
Contributor Author

Done

@alagoutte
alagoutte merged commit 3ec229c into AsBuiltReport:dev Jan 14, 2025
@alagoutte

Copy link
Copy Markdown
Collaborator

Merged, Thanks max!

@msoukhomlinov

Copy link
Copy Markdown
Contributor Author

@alagoutte , on a slightly different topic, would you happen to know owner of PScribo? If so, would you be able to see if he could take a look at this pull request for me?
iainbrighton/PScribo#130

This is the enhanced table function I earlier tried to add to this module but then decided that its better to reside higher up stream.
I am waiting on its approval to then incorporate further enhancements to this module (items which are commented out at the moment).

@alagoutte

Copy link
Copy Markdown
Collaborator

No but i will see what it is possible !

@alagoutte

Copy link
Copy Markdown
Collaborator

Hi Mark,

look there is some issue when i try... (i need look why)

May be also enable the feature by default ?

alagoutte pushed a commit that referenced this pull request Jun 27, 2025
* Add CIDR notation support for IP addresses and subnets

- Add UseCIDRNotation configuration option

- Add Convert-AbrFgtSubnetToCIDR function for IP/subnet conversion

- Implement CIDR conversion in firewall, route, system, and VPN IPsec sections

- Add error handling and maintain backward compatibility

* Add OutputType attributes to Convert-AbrFgtSubnetToCIDR functions

* Add UseCIDRNotation option and convert CIDR notation checks to PowerShell 5.1 compatible one-liners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants