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

Issue#138 #140

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/AdminToolbox.FortiWizard/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@
* **2.17.23** CI Maintenance Release
* **2.17.24** CI Maintenance Release
* **2.17.25** CI Maintenance Release
* **2.17.26** CI Maintenance Release
* **2.17.26** CI Maintenance Release
* **2.18.00** Modify New-AddressObject to accept an array. Issue [#138](https://github.com/TheTaylorLee/AdminToolbox/issues/138)
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#Required by functions
#New-P2PTunnel
#New-P2PTunnelNAT
#New-DialUPTunnelDynamic
#New-DialUPTunnelStatic

<#
.Description
Create a New Address Object

.Parameter AddressName
Specify a Unique name for the Address Object

.Parameter CIDR
Specify a CIDR address. ex: 192.168.0.0/24

.Example
$Params = @{
AddressName = "ComanyLan_192.168.0.1/26"
CIDR = "192.168.0.1/26"
}
New-AddressObjectTunnel @params

.Example
New-SSHSession -computername 192.168.0.1
$Params = @{
AddressName = "ComanyLan_192.168.0.1/26"
CIDR = "192.168.0.1/26"
}
$command = New-AddressObjectTunnel @params
$result = Invoke-SSHCommand -Command $command -SessionId 0
$result.output

This example generates an SSH session and invokes the output of this function against that session.

.Example
New-SSHSession -computername 192.168.0.1
New-SSHSession -computername 192.168.1.1
$Params = @{
AddressName = "ComanyLan_192.168.0.1/26"
CIDR = "192.168.0.1/26"
}
$command = New-AddressObjectTunnel @params
$sessions = Get-SSHSession
foreach ($session in $sessions) {
Write-Output "Invoking Command against $session.host"
$result = Invoke-SSHCommand -Command $command -SessionId $session.sessionID
$result.output
}

This example generates multiple SSH sessions and invokes the output of this function against all active sessions.


.Link
https://github.com/TheTaylorLee/AdminToolbox/tree/master/docs
#>

Function New-AddressObjectTunnel {

[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"
}
30 changes: 15 additions & 15 deletions modules/AdminToolbox.FortiWizard/Public/New-AddressObject.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
#Required by functions
#New-P2PTunnel
#New-P2PTunnelNAT
#New-DialUPTunnelDynamic
#New-DialUPTunnelStatic

<#
.Description
Create a New Address Object
Create New Address Objects

.Parameter AddressName
Specify a Unique name for the Address Object
Specify a prefix for the Address Object/s. This will prefix the CIDR address as a name for the addresses.

.Parameter CIDR
Specify a CIDR address. ex: 192.168.0.0/24
Specify a CIDR address or addresses. ex: 192.168.0.0/24 or 192.168.0.0/24, 10.10.10.5/32

.Example
$Params = @{
AddressName = "ComanyLan_192.168.0.1/26"
CIDR = "192.168.0.1/26"
AddressName = "ComanyLan"
CIDR = "192.168.0.1/26", "10.10.0.0/24"
}
New-AddressObject @params

Create Multiple Address Objects.

.Example
New-SSHSession -computername 192.168.0.1
$Params = @{
AddressName = "ComanyLan_192.168.0.1/26"
AddressName = "ComanyLan"
CIDR = "192.168.0.1/26"
}
$command = New-AddressObject @params
Expand All @@ -37,7 +33,7 @@
New-SSHSession -computername 192.168.0.1
New-SSHSession -computername 192.168.1.1
$Params = @{
AddressName = "ComanyLan_192.168.0.1/26"
AddressName = "ComanyLan"
CIDR = "192.168.0.1/26"
}
$command = New-AddressObject @params
Expand Down Expand Up @@ -69,18 +65,22 @@ Function New-AddressObject {
throw "$_ is an invalid pattern. You must provide a proper CIDR format. ex: 192.168.0.0/24"
}
})]
[String[]]
$CIDR
)

$calc = Invoke-PSipcalc $cidr
foreach ($sub in $Cidr) {
$calc = Invoke-PSipcalc $sub
$IPAddress = ($calc).IP
$SubnetMask = ($calc).SubnetMask
$name = $AddressName + "_" + $sub

Write-Output "
config firewall address
edit ""$AddressName""
edit ""$name""
set subnet $IPAddress $SubnetMask
set allow-routing enable
next
end"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Function New-DialUPTunnelBehindNAT {
}

$ConfLocalAddressObjects = Foreach ($AddressObject in $script:LocalAddressObjects) {
New-AddressObject -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
New-AddressObjectTunnel -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
}

#Create Remote Address Objects
Expand All @@ -234,7 +234,7 @@ Function New-DialUPTunnelBehindNAT {
}

$ConfRemoteAddressObjects = Foreach ($AddressObject in $script:RemoteAddressObjects) {
New-AddressObject -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
New-AddressObjectTunnel -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
}

#Create Local Address Group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Function New-DialUPTunnelRemoteNAT {
}

$ConfLocalAddressObjects = Foreach ($AddressObject in $script:LocalAddressObjects) {
New-AddressObject -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
New-AddressObjectTunnel -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
}

#Create Remote Address Objects
Expand All @@ -225,7 +225,7 @@ Function New-DialUPTunnelRemoteNAT {
}

$ConfRemoteAddressObjects = Foreach ($AddressObject in $script:RemoteAddressObjects) {
New-AddressObject -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
New-AddressObjectTunnel -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
}

#Create Local Address Group
Expand Down
4 changes: 2 additions & 2 deletions modules/AdminToolbox.FortiWizard/Public/New-P2PTunnel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Function New-P2PTunnel {
}

$ConfLocalAddressObjects = Foreach ($AddressObject in $script:LocalAddressObjects) {
New-AddressObject -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
New-AddressObjectTunnel -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
}

#Create Remote Address Objects
Expand All @@ -232,7 +232,7 @@ Function New-P2PTunnel {
}

$ConfRemoteAddressObjects = Foreach ($AddressObject in $script:RemoteAddressObjects) {
New-AddressObject -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
New-AddressObjectTunnel -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
}

#Create Local Address Group
Expand Down
6 changes: 3 additions & 3 deletions modules/AdminToolbox.FortiWizard/Public/New-P2PTunnelNAT.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Function New-P2PTunnelNAT {
}

$ConfLocalAddressObjects = Foreach ($AddressObject in $script:LocalAddressObjects) {
New-AddressObject -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
New-AddressObjectTunnel -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
}

#Create Remote Address Objects
Expand All @@ -278,7 +278,7 @@ Function New-P2PTunnelNAT {
}

$ConfRemoteAddressObjects = Foreach ($AddressObject in $script:RemoteAddressObjects) {
New-AddressObject -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
New-AddressObjectTunnel -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
}

#Create NAT Address Objects
Expand All @@ -291,7 +291,7 @@ Function New-P2PTunnelNAT {
}

$ConfNATAddressObjects = Foreach ($AddressObject in $script:NATAddressObjects) {
New-AddressObject -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
New-AddressObjectTunnel -AddressName $AddressObject.Name -CIDR $AddressObject.CIDR
}

#Create Local Address Group
Expand Down