mirror of
https://github.com/freedbygrace/PSOPNSenseAPI.git
synced 2026-07-26 11:58:18 +00:00
Add port forwarding support, improve XML documentation, and add unit tests
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all aliases
|
||||
$aliases = Get-OPNSenseAlias
|
||||
Write-Output "All Aliases:"
|
||||
$aliases | Format-Table -Property Uuid, Name, Type, Content, Description, Enabled
|
||||
|
||||
# Get aliases by type
|
||||
$hostAliases = Get-OPNSenseAlias -Type host
|
||||
Write-Output "Host Aliases:"
|
||||
$hostAliases | Format-Table -Property Uuid, Name, Content, Description
|
||||
|
||||
$networkAliases = Get-OPNSenseAlias -Type network
|
||||
Write-Output "Network Aliases:"
|
||||
$networkAliases | Format-Table -Property Uuid, Name, Content, Description
|
||||
|
||||
$portAliases = Get-OPNSenseAlias -Type port
|
||||
Write-Output "Port Aliases:"
|
||||
$portAliases | Format-Table -Property Uuid, Name, Content, Description
|
||||
|
||||
# Get a specific alias by name
|
||||
$webServersAlias = Get-OPNSenseAlias -Name "WebServers"
|
||||
Write-Output "WebServers Alias:"
|
||||
$webServersAlias | Format-Table -Property Uuid, Name, Type, Content, Description
|
||||
|
||||
# Get a specific alias by UUID
|
||||
$aliasUuid = $aliases[0].Uuid
|
||||
$specificAlias = Get-OPNSenseAlias -Uuid $aliasUuid
|
||||
Write-Output "Specific Alias by UUID:"
|
||||
$specificAlias | Format-List
|
||||
|
||||
# Create a new host alias
|
||||
$webServersUuid = New-OPNSenseAlias -Name "WebServers" -Type host -Content "192.168.1.10,192.168.1.11" -Description "Web Servers" -Apply
|
||||
Write-Output "Created WebServers alias with UUID: $webServersUuid"
|
||||
|
||||
# Create a new network alias
|
||||
$internalNetworksUuid = New-OPNSenseAlias -Name "InternalNetworks" -Type network -Content "192.168.1.0/24,192.168.2.0/24" -Description "Internal Networks" -Apply
|
||||
Write-Output "Created InternalNetworks alias with UUID: $internalNetworksUuid"
|
||||
|
||||
# Create a new port alias
|
||||
$webPortsUuid = New-OPNSenseAlias -Name "WebPorts" -Type port -Content "80,443" -Protocol TCP -Description "Web Ports" -Apply
|
||||
Write-Output "Created WebPorts alias with UUID: $webPortsUuid"
|
||||
|
||||
# Create a new URL alias
|
||||
$blockListUuid = New-OPNSenseAlias -Name "BlockList" -Type url -Content "https://example.com/blocklist.txt" -UpdateFrequency 1 -Description "Block List" -Apply
|
||||
Write-Output "Created BlockList alias with UUID: $blockListUuid"
|
||||
|
||||
# Update an alias's content
|
||||
Set-OPNSenseAlias -Uuid $webServersUuid -Content "192.168.1.10,192.168.1.11,192.168.1.12" -Apply
|
||||
Write-Output "Updated WebServers alias content"
|
||||
|
||||
# Update an alias's description
|
||||
Set-OPNSenseAlias -Uuid $internalNetworksUuid -Description "All Internal Networks" -Apply
|
||||
Write-Output "Updated InternalNetworks alias description"
|
||||
|
||||
# Disable an alias
|
||||
Set-OPNSenseAlias -Uuid $blockListUuid -Disabled -Apply
|
||||
Write-Output "Disabled BlockList alias"
|
||||
|
||||
# Enable an alias
|
||||
Set-OPNSenseAlias -Uuid $blockListUuid -Enabled -Apply
|
||||
Write-Output "Enabled BlockList alias"
|
||||
|
||||
# Enable counters for an alias
|
||||
Set-OPNSenseAlias -Uuid $webServersUuid -EnableCounters -Apply
|
||||
Write-Output "Enabled counters for WebServers alias"
|
||||
|
||||
# Remove an alias
|
||||
Remove-OPNSenseAlias -Uuid $blockListUuid -Force -Apply
|
||||
Write-Output "Removed BlockList alias"
|
||||
|
||||
# Remove aliases by pipeline
|
||||
Get-OPNSenseAlias -Name "WebServers" | Remove-OPNSenseAlias -Force -Apply
|
||||
Write-Output "Removed WebServers alias"
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,22 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get the current connection information
|
||||
Get-OPNSenseConnection
|
||||
|
||||
# Get all firewall rules
|
||||
$rules = Get-OPNSenseFirewallRule
|
||||
$rules | Format-Table -Property Uuid, Description, Protocol, SourceNet, DestinationPort, Action
|
||||
|
||||
# Create a new firewall rule to allow HTTP traffic
|
||||
$ruleId = New-OPNSenseFirewallRule -Description "Allow HTTP" -Protocol TCP -DestinationPort 80 -Action pass
|
||||
Write-Output "Created rule with ID: $ruleId"
|
||||
|
||||
# Apply the changes
|
||||
Apply-OPNSenseFirewallChanges -CancelRollback -Timeout 30
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,29 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all configuration backups
|
||||
$backups = Get-OPNSenseConfigBackup
|
||||
$backups | Format-Table -Property Filename, Description, FileSize, Date, Version
|
||||
|
||||
# Create a new configuration backup
|
||||
$backupFilename = Backup-OPNSenseConfig -Filename "pre-upgrade-backup"
|
||||
Write-Output "Created backup: $backupFilename"
|
||||
|
||||
# Export the configuration to a file
|
||||
$exportPath = "C:\Backups\opnsense-config.xml"
|
||||
Export-OPNSenseConfig -Path $exportPath -Force
|
||||
Write-Output "Exported configuration to: $exportPath"
|
||||
|
||||
# Import a configuration from a file
|
||||
# Note: This will restart the firewall
|
||||
# Import-OPNSenseConfig -Path $exportPath -Confirm
|
||||
|
||||
# Restore a configuration backup
|
||||
# Note: This will restart the firewall
|
||||
# Restore-OPNSenseConfig -Filename $backupFilename -Confirm
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,36 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all cron jobs
|
||||
$cronJobs = Get-OPNSenseCronJob
|
||||
$cronJobs | Format-Table -Property Uuid, Description, Command, Minutes, Hours, Days, Months, Weekdays, Enabled
|
||||
|
||||
# Get a specific cron job
|
||||
$job = Get-OPNSenseCronJob -Uuid $cronJobs[0].Uuid
|
||||
$job
|
||||
|
||||
# Create a new cron job that runs daily at 2:00 AM
|
||||
$dailyBackup = New-OPNSenseCronJob -Description "Daily backup" -Command "/usr/local/bin/backup.sh" -Minutes "0" -Hours "2" -Days "*" -Months "*" -Weekdays "*" -Apply
|
||||
$dailyBackup
|
||||
|
||||
# Create a new cron job that runs weekly on Sunday at 3:00 AM
|
||||
$weeklyCleanup = New-OPNSenseCronJob -Description "Weekly cleanup" -Command "/usr/local/bin/cleanup.sh" -Minutes "0" -Hours "3" -Days "*" -Months "*" -Weekdays "0" -Apply
|
||||
$weeklyCleanup
|
||||
|
||||
# Update a cron job
|
||||
Set-OPNSenseCronJob -Uuid $dailyBackup -Hours "3" -Description "Updated daily backup" -Apply
|
||||
|
||||
# Disable a cron job
|
||||
Disable-OPNSenseCronJob -Uuid $dailyBackup -Apply
|
||||
|
||||
# Enable a cron job
|
||||
Enable-OPNSenseCronJob -Uuid $dailyBackup -Apply
|
||||
|
||||
# Remove a cron job
|
||||
Remove-OPNSenseCronJob -Uuid $weeklyCleanup -Force -Apply
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,41 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all DHCP servers
|
||||
$dhcpServers = Get-OPNSenseDHCPServer
|
||||
$dhcpServers | Format-Table -Property Interface, Enabled, RangeFrom, RangeTo, Gateway
|
||||
|
||||
# Get a specific DHCP server
|
||||
$lanDhcp = Get-OPNSenseDHCPServer -Interface "lan"
|
||||
$lanDhcp
|
||||
|
||||
# Update a DHCP server
|
||||
Set-OPNSenseDHCPServer -Interface "lan" -RangeFrom "192.168.1.100" -RangeTo "192.168.1.200" -Domain "example.local" -DnsServers "8.8.8.8","8.8.4.4" -Apply
|
||||
|
||||
# Get all DHCP leases
|
||||
$dhcpLeases = Get-OPNSenseDHCPLease
|
||||
$dhcpLeases | Format-Table -Property MacAddress, IpAddress, Hostname, State
|
||||
|
||||
# Get active DHCP leases
|
||||
$activeLeases = $dhcpLeases | Where-Object { $_.State -eq "active" }
|
||||
$activeLeases | Format-Table -Property MacAddress, IpAddress, Hostname
|
||||
|
||||
# Get all static mappings for an interface
|
||||
$staticMappings = Get-OPNSenseDHCPStaticMapping -Interface "lan"
|
||||
$staticMappings | Format-Table -Property Uuid, MacAddress, IpAddress, Hostname, Description
|
||||
|
||||
# Create a new static mapping
|
||||
$newMapping = New-OPNSenseDHCPStaticMapping -Interface "lan" -MacAddress "00:11:22:33:44:55" -IpAddress "192.168.1.50" -Hostname "printer" -Description "Office Printer" -Apply
|
||||
$newMapping
|
||||
|
||||
# Update a static mapping
|
||||
Set-OPNSenseDHCPStaticMapping -Interface "lan" -Uuid $newMapping -IpAddress "192.168.1.51" -Description "Updated Printer" -Apply
|
||||
|
||||
# Remove a static mapping
|
||||
Remove-OPNSenseDHCPStaticMapping -Interface "lan" -Uuid $newMapping -Force -Apply
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,27 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get DNS server configuration
|
||||
$dnsConfig = Get-OPNSenseDNSServer
|
||||
Write-Output "DNS Server Configuration:"
|
||||
$dnsConfig
|
||||
|
||||
# Update DNS server configuration
|
||||
Set-OPNSenseDNSServer -Forwarding -Forwarders "8.8.8.8","8.8.4.4" -RegisterDhcp -RegisterDhcpDomain "local" -Apply
|
||||
|
||||
# Get all DNS overrides
|
||||
$overrides = Get-OPNSenseDNSOverride
|
||||
$overrides | Format-Table -Property Uuid, Hostname, Domain, IpAddress, Description
|
||||
|
||||
# Create a new DNS override
|
||||
$overrideId = New-OPNSenseDNSOverride -Hostname "server" -Domain "local" -IpAddress "192.168.1.10" -Description "Internal server" -Apply
|
||||
Write-Output "Created DNS override with ID: $overrideId"
|
||||
|
||||
# Remove a DNS override
|
||||
Remove-OPNSenseDNSOverride -Uuid $overrideId -Apply -Confirm:$false
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,52 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get DNS server configuration
|
||||
$dnsServer = Get-OPNSenseDNSServer
|
||||
Write-Output "DNS Server Configuration:"
|
||||
$dnsServer | Format-List
|
||||
|
||||
# Update DNS server configuration
|
||||
Set-OPNSenseDNSServer -Forwarding -Forwarders "8.8.8.8","8.8.4.4" -Apply
|
||||
Write-Output "DNS Server updated to use Google DNS"
|
||||
|
||||
# Get DNS forwarding configuration
|
||||
$dnsForwarding = Get-OPNSenseDNSForwarding
|
||||
Write-Output "DNS Forwarding Configuration:"
|
||||
$dnsForwarding | Format-List
|
||||
|
||||
# Enable DNS forwarding
|
||||
Set-OPNSenseDNSForwarding -Enabled -DnsServers "1.1.1.1","1.0.0.1" -Apply
|
||||
Write-Output "DNS Forwarding enabled with Cloudflare DNS"
|
||||
|
||||
# Get DNS forwarding hosts
|
||||
$forwardingHosts = Get-OPNSenseDNSForwardingHost
|
||||
Write-Output "DNS Forwarding Hosts:"
|
||||
$forwardingHosts | Format-Table
|
||||
|
||||
# Create a new DNS forwarding host
|
||||
$newHost = New-OPNSenseDNSForwardingHost -Domain "example.com" -Server "192.168.1.10" -Description "Internal DNS Server" -Apply
|
||||
Write-Output "Created new forwarding host with UUID: $newHost"
|
||||
|
||||
# Update a DNS forwarding host
|
||||
Set-OPNSenseDNSForwardingHost -Uuid $newHost -Server "192.168.1.20" -Apply
|
||||
Write-Output "Updated forwarding host server"
|
||||
|
||||
# Remove a DNS forwarding host
|
||||
Remove-OPNSenseDNSForwardingHost -Uuid $newHost -Force -Apply
|
||||
Write-Output "Removed forwarding host"
|
||||
|
||||
# Get system DNS configuration
|
||||
$systemDNS = Get-OPNSenseSystemDNS
|
||||
Write-Output "System DNS Configuration:"
|
||||
$systemDNS | Format-List
|
||||
|
||||
# Update system DNS configuration
|
||||
Set-OPNSenseSystemDNS -Hostname "firewall" -Domain "example.com" -DnsServers "8.8.8.8","8.8.4.4" -Apply
|
||||
Write-Output "Updated system DNS configuration"
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,37 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get firmware status
|
||||
$firmwareStatus = Get-OPNSenseFirmware
|
||||
Write-Output "Firmware Status:"
|
||||
$firmwareStatus
|
||||
|
||||
# Check for updates
|
||||
Get-OPNSenseFirmware -Check
|
||||
|
||||
# Get firmware changelog
|
||||
$changelog = Get-OPNSenseFirmware -Changelog
|
||||
Write-Output "Firmware Changelog:"
|
||||
$changelog
|
||||
|
||||
# Get firmware audit
|
||||
$audit = Get-OPNSenseFirmware -Audit
|
||||
$audit | Format-Table -Property Name, Version, Installed
|
||||
|
||||
# Update firmware (install updates)
|
||||
Update-OPNSenseFirmware -Wait
|
||||
Write-Output "Firmware updated successfully"
|
||||
|
||||
# Upgrade firmware (major version upgrade)
|
||||
# Note: This will restart the firewall
|
||||
# Upgrade-OPNSenseFirmware -Wait -Timeout 1200
|
||||
|
||||
# Restart the firewall
|
||||
Restart-OPNSenseFirewall -Wait -Timeout 300
|
||||
Write-Output "Firewall restarted successfully"
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,59 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all gateways
|
||||
$gateways = Get-OPNSenseGateway
|
||||
Write-Output "Gateways:"
|
||||
$gateways | Format-Table
|
||||
|
||||
# Get gateways with status information
|
||||
$gatewaysWithStatus = Get-OPNSenseGateway -IncludeStatus
|
||||
Write-Output "Gateways with Status:"
|
||||
$gatewaysWithStatus | Format-Table
|
||||
|
||||
# Create a new gateway
|
||||
$newGateway = New-OPNSenseGateway -Name "WAN2_GW" -Interface "opt1" -IpAddress "203.0.113.1" -Description "Secondary WAN" -Apply
|
||||
Write-Output "Created new gateway with UUID: $newGateway"
|
||||
|
||||
# Update a gateway
|
||||
Set-OPNSenseGateway -Uuid $newGateway -MonitorIp "8.8.8.8" -Weight 2 -Apply
|
||||
Write-Output "Updated gateway monitor IP and weight"
|
||||
|
||||
# Make a gateway the default gateway
|
||||
Set-OPNSenseGateway -Uuid $newGateway -Default -Apply
|
||||
Write-Output "Set gateway as default"
|
||||
|
||||
# Get all routes
|
||||
$routes = Get-OPNSenseRoute
|
||||
Write-Output "Routes:"
|
||||
$routes | Format-Table
|
||||
|
||||
# Create a new route
|
||||
$newRoute = New-OPNSenseRoute -Network "192.168.100.0/24" -Gateway "WAN2_GW" -Description "Remote Office" -Apply
|
||||
Write-Output "Created new route with UUID: $newRoute"
|
||||
|
||||
# Update a route
|
||||
Set-OPNSenseRoute -Uuid $newRoute -Gateway "WAN_GW" -Apply
|
||||
Write-Output "Updated route gateway"
|
||||
|
||||
# Disable a route
|
||||
Set-OPNSenseRoute -Uuid $newRoute -Disabled -Apply
|
||||
Write-Output "Disabled route"
|
||||
|
||||
# Enable a route
|
||||
Set-OPNSenseRoute -Uuid $newRoute -Enabled -Apply
|
||||
Write-Output "Enabled route"
|
||||
|
||||
# Remove a route
|
||||
Remove-OPNSenseRoute -Uuid $newRoute -Force -Apply
|
||||
Write-Output "Removed route"
|
||||
|
||||
# Remove a gateway
|
||||
Remove-OPNSenseGateway -Uuid $newGateway -Force -Apply
|
||||
Write-Output "Removed gateway"
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,27 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all interfaces
|
||||
$interfaces = Get-OPNSenseInterface
|
||||
$interfaces | Format-Table -Property Name, Description, IpAddress, SubnetMask, Status
|
||||
|
||||
# Get interface statistics
|
||||
$stats = Get-OPNSenseInterfaceStatistics
|
||||
$stats | Format-Table -Property Name, InPackets, OutPackets, InBytes, OutBytes
|
||||
|
||||
# Update an interface
|
||||
Set-OPNSenseInterface -Name "lan" -Description "Local Area Network" -IpAddress "192.168.1.1" -SubnetMask "24" -Apply
|
||||
|
||||
# Create a new VLAN
|
||||
$vlanId = New-OPNSenseVLAN -Interface "em0" -Tag 10 -Description "Management VLAN"
|
||||
Write-Output "Created VLAN with ID: $vlanId"
|
||||
|
||||
# Get all VLANs
|
||||
$vlans = Get-OPNSenseVLAN
|
||||
$vlans | Format-Table -Property Uuid, Tag, Interface, Description
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,57 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Basic supernetting of two networks
|
||||
$supernet = Invoke-OPNSenseNetworkCalculation -Network "192.168.1.0/24" -Operation Supernet -AdditionalNetworks "192.168.2.0/24"
|
||||
Write-Output "Supernet of 192.168.1.0/24 and 192.168.2.0/24:"
|
||||
$supernet
|
||||
|
||||
# Supernetting of multiple networks
|
||||
$supernet = Invoke-OPNSenseNetworkCalculation -Network "10.0.0.0/24" -Operation Supernet -AdditionalNetworks "10.0.1.0/24","10.0.2.0/24","10.0.3.0/24"
|
||||
Write-Output "Supernet of multiple /24 networks:"
|
||||
$supernet
|
||||
|
||||
# Advanced supernetting with summarization
|
||||
$summarizedNetworks = Invoke-OPNSenseNetworkCalculation -Network "172.16.0.0/24" -Operation SupernetSummarize -AdditionalNetworks "172.16.1.0/24","172.16.2.0/24","172.16.4.0/24","172.16.5.0/24"
|
||||
Write-Output "Summarized networks:"
|
||||
$summarizedNetworks | Format-Table
|
||||
|
||||
# Example of non-contiguous networks being summarized efficiently
|
||||
$summarizedNetworks = Invoke-OPNSenseNetworkCalculation -Network "10.1.0.0/24" -Operation SupernetSummarize -AdditionalNetworks "10.1.1.0/24","10.1.2.0/24","10.2.0.0/24","10.2.1.0/24"
|
||||
Write-Output "Summarized non-contiguous networks:"
|
||||
$summarizedNetworks | Format-Table
|
||||
|
||||
# Example with mixed IPv4 and IPv6 networks
|
||||
$summarizedNetworks = Invoke-OPNSenseNetworkCalculation -Network "192.168.0.0/24" -Operation SupernetSummarize -AdditionalNetworks "192.168.1.0/24","2001:db8::/64","2001:db8:1::/64"
|
||||
Write-Output "Summarized mixed IPv4 and IPv6 networks:"
|
||||
$summarizedNetworks | Format-Table
|
||||
|
||||
# Practical example: Summarizing a large number of networks
|
||||
$networks = @(
|
||||
"10.0.0.0/24"
|
||||
"10.0.1.0/24"
|
||||
"10.0.2.0/24"
|
||||
"10.0.3.0/24"
|
||||
"10.0.4.0/24"
|
||||
"10.0.5.0/24"
|
||||
"10.0.6.0/24"
|
||||
"10.0.7.0/24"
|
||||
"10.1.0.0/24"
|
||||
"10.1.1.0/24"
|
||||
"10.2.0.0/24"
|
||||
"10.2.1.0/24"
|
||||
"172.16.0.0/24"
|
||||
"172.16.1.0/24"
|
||||
"172.16.2.0/24"
|
||||
"172.16.3.0/24"
|
||||
)
|
||||
|
||||
$summarizedNetworks = Invoke-OPNSenseNetworkCalculation -Network $networks[0] -Operation SupernetSummarize -AdditionalNetworks $networks[1..($networks.Length-1)]
|
||||
Write-Output "Summarized large set of networks:"
|
||||
$summarizedNetworks | Format-Table
|
||||
|
||||
# Using the summarized networks for route configuration
|
||||
Write-Output "Example of using summarized networks for route configuration:"
|
||||
foreach ($network in $summarizedNetworks) {
|
||||
Write-Output "New-OPNSenseRoute -Network '$network' -Gateway 'WAN_GW' -Description 'Summarized Route' -Apply"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Network information
|
||||
$networkInfo = Invoke-OPNSenseNetworkCalculation -Network "192.168.1.0/24" -Operation Info
|
||||
Write-Output "Network Information:"
|
||||
$networkInfo | Format-List
|
||||
|
||||
# Subnet a network into smaller networks
|
||||
$subnets = Invoke-OPNSenseNetworkCalculation -Network "10.0.0.0/16" -Operation Subnet -PrefixLength 24
|
||||
Write-Output "First 5 subnets of 10.0.0.0/16 divided into /24 networks:"
|
||||
$subnets | Select-Object -First 5 | Format-Table
|
||||
|
||||
# Subnet a network into a specific number of subnets
|
||||
$subnets = Invoke-OPNSenseNetworkCalculation -Network "172.16.0.0/16" -Operation SubnetByCount -SubnetCount 4
|
||||
Write-Output "172.16.0.0/16 divided into 4 equal subnets:"
|
||||
$subnets | Format-Table
|
||||
|
||||
# Check if an IP address is within a network
|
||||
$contains = Invoke-OPNSenseNetworkCalculation -Network "192.168.1.0/24" -Operation Contains -IPAddress "192.168.1.100"
|
||||
Write-Output "Is 192.168.1.100 within 192.168.1.0/24? $contains"
|
||||
|
||||
# Check if networks overlap
|
||||
$overlaps = Invoke-OPNSenseNetworkCalculation -Network "10.0.0.0/24" -Operation Overlaps -AdditionalNetworks "10.0.0.128/25"
|
||||
Write-Output "Network overlap check:"
|
||||
$overlaps | Format-Table
|
||||
|
||||
# Create a supernet from multiple networks
|
||||
$supernet = Invoke-OPNSenseNetworkCalculation -Network "192.168.1.0/24" -Operation Supernet -AdditionalNetworks "192.168.2.0/24","192.168.3.0/24"
|
||||
Write-Output "Supernet of 192.168.1.0/24, 192.168.2.0/24, and 192.168.3.0/24:"
|
||||
$supernet
|
||||
|
||||
# Convert between CIDR and subnet mask
|
||||
$subnetMask = ConvertTo-OPNSenseNetworkNotation -CIDR 24
|
||||
Write-Output "Subnet mask for /24: $subnetMask"
|
||||
|
||||
$cidr = ConvertTo-OPNSenseNetworkNotation -SubnetMask "255.255.255.0"
|
||||
Write-Output "CIDR for 255.255.255.0: $cidr"
|
||||
|
||||
$ipWithSubnetMask = ConvertTo-OPNSenseNetworkNotation -IPWithCIDR "192.168.1.0/24"
|
||||
Write-Output "IP with subnet mask for 192.168.1.0/24: $ipWithSubnetMask"
|
||||
|
||||
$ipWithCIDR = ConvertTo-OPNSenseNetworkNotation -IPWithSubnetMask "192.168.1.0 255.255.255.0"
|
||||
Write-Output "IP with CIDR for 192.168.1.0 255.255.255.0: $ipWithCIDR"
|
||||
@@ -0,0 +1,29 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all installed plugins
|
||||
$installedPlugins = Get-OPNSensePlugin -Installed
|
||||
$installedPlugins | Format-Table -Property Name, Version, Comment, Enabled
|
||||
|
||||
# Get all available plugins
|
||||
$availablePlugins = Get-OPNSensePlugin -Available
|
||||
$availablePlugins | Format-Table -Property Name, Version, Comment
|
||||
|
||||
# Install a plugin
|
||||
Install-OPNSensePlugin -Name "os-acme-client" -Wait
|
||||
Write-Output "Plugin installed successfully"
|
||||
|
||||
# Enable a plugin
|
||||
Enable-OPNSensePlugin -Name "os-acme-client"
|
||||
|
||||
# Disable a plugin
|
||||
Disable-OPNSensePlugin -Name "os-acme-client"
|
||||
|
||||
# Uninstall a plugin
|
||||
Uninstall-OPNSensePlugin -Name "os-acme-client" -Wait -Confirm:$false
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,212 @@
|
||||
# Port Forwarding Examples
|
||||
|
||||
This document provides examples of using the PSOPNSenseAPI module to manage port forwarding rules on OPNSense firewalls.
|
||||
|
||||
## Basic Port Forwarding
|
||||
|
||||
The following example demonstrates how to create, view, update, and delete port forwarding rules:
|
||||
|
||||
```powershell
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all port forwarding rules
|
||||
$rules = Get-OPNSensePortForwardingRule
|
||||
Write-Output "Current port forwarding rules:"
|
||||
$rules | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Create a new port forwarding rule for HTTP
|
||||
$httpRule = New-OPNSensePortForwardingRule -Interface "WAN" -Protocol "tcp" -DestinationPort "80" -TargetIP "192.168.1.100" -TargetPort "80" -Description "Web Server HTTP"
|
||||
Write-Output "Created HTTP port forwarding rule:"
|
||||
$httpRule | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Create a new port forwarding rule for HTTPS
|
||||
$httpsRule = New-OPNSensePortForwardingRule -Interface "WAN" -Protocol "tcp" -DestinationPort "443" -TargetIP "192.168.1.100" -TargetPort "443" -Description "Web Server HTTPS"
|
||||
Write-Output "Created HTTPS port forwarding rule:"
|
||||
$httpsRule | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Update the HTTP rule to point to a different server
|
||||
$updatedRule = Set-OPNSensePortForwardingRule -Uuid $httpRule.Uuid -TargetIP "192.168.1.200" -Description "Updated Web Server HTTP" -PassThru
|
||||
Write-Output "Updated HTTP port forwarding rule:"
|
||||
$updatedRule | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Get a specific rule by UUID
|
||||
$rule = Get-OPNSensePortForwardingRule -Uuid $httpsRule.Uuid
|
||||
Write-Output "Retrieved HTTPS port forwarding rule:"
|
||||
$rule | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Remove the HTTP rule
|
||||
Remove-OPNSensePortForwardingRule -Uuid $httpRule.Uuid -Force
|
||||
Write-Output "Removed HTTP port forwarding rule"
|
||||
|
||||
# Get all port forwarding rules again to verify changes
|
||||
$rules = Get-OPNSensePortForwardingRule
|
||||
Write-Output "Updated port forwarding rules:"
|
||||
$rules | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
```
|
||||
|
||||
## Advanced Port Forwarding Scenarios
|
||||
|
||||
### Web Server with Multiple Services
|
||||
|
||||
This example shows how to set up port forwarding for a web server with multiple services:
|
||||
|
||||
```powershell
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Define the web server details
|
||||
$webServerIP = "192.168.1.100"
|
||||
$services = @(
|
||||
@{ Name = "HTTP"; Protocol = "tcp"; ExternalPort = "80"; InternalPort = "80" },
|
||||
@{ Name = "HTTPS"; Protocol = "tcp"; ExternalPort = "443"; InternalPort = "443" },
|
||||
@{ Name = "Alternative HTTP"; Protocol = "tcp"; ExternalPort = "8080"; InternalPort = "8080" },
|
||||
@{ Name = "WebSocket"; Protocol = "tcp"; ExternalPort = "9000"; InternalPort = "9000" }
|
||||
)
|
||||
|
||||
# Create port forwarding rules for each service
|
||||
foreach ($service in $services) {
|
||||
New-OPNSensePortForwardingRule -Interface "WAN" `
|
||||
-Protocol $service.Protocol `
|
||||
-DestinationPort $service.ExternalPort `
|
||||
-TargetIP $webServerIP `
|
||||
-TargetPort $service.InternalPort `
|
||||
-Description "Web Server - $($service.Name)" `
|
||||
-Force
|
||||
}
|
||||
|
||||
# Verify the rules were created
|
||||
Get-OPNSensePortForwardingRule | Where-Object { $_.TargetIP -eq $webServerIP } |
|
||||
Format-Table -Property Description, Protocol, DestinationPort, TargetPort
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
```
|
||||
|
||||
### Game Server Port Forwarding
|
||||
|
||||
This example demonstrates how to set up port forwarding for a game server with multiple ports:
|
||||
|
||||
```powershell
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Define the game server details
|
||||
$gameServerIP = "192.168.1.150"
|
||||
$gameServerPorts = @(
|
||||
@{ Name = "Game Server - Main"; Protocol = "tcp/udp"; Ports = "27015" },
|
||||
@{ Name = "Game Server - Query"; Protocol = "udp"; Ports = "27016" },
|
||||
@{ Name = "Game Server - RCON"; Protocol = "tcp"; Ports = "27017" },
|
||||
@{ Name = "Game Server - Voice"; Protocol = "udp"; Ports = "9987-9989" }
|
||||
)
|
||||
|
||||
# Create port forwarding rules for the game server
|
||||
foreach ($port in $gameServerPorts) {
|
||||
New-OPNSensePortForwardingRule -Interface "WAN" `
|
||||
-Protocol $port.Protocol `
|
||||
-DestinationPort $port.Ports `
|
||||
-TargetIP $gameServerIP `
|
||||
-TargetPort $port.Ports `
|
||||
-Description $port.Name `
|
||||
-Force
|
||||
}
|
||||
|
||||
# Verify the rules were created
|
||||
Get-OPNSensePortForwardingRule | Where-Object { $_.TargetIP -eq $gameServerIP } |
|
||||
Format-Table -Property Description, Protocol, DestinationPort, TargetPort
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
```
|
||||
|
||||
### Remote Access Services
|
||||
|
||||
This example shows how to set up port forwarding for remote access services:
|
||||
|
||||
```powershell
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Define remote access services
|
||||
$remoteServices = @(
|
||||
@{ Name = "RDP - Admin Server"; TargetIP = "192.168.1.200"; ExternalPort = "33389"; InternalPort = "3389"; Protocol = "tcp" },
|
||||
@{ Name = "SSH - Dev Server"; TargetIP = "192.168.1.201"; ExternalPort = "2222"; InternalPort = "22"; Protocol = "tcp" },
|
||||
@{ Name = "VNC - Support"; TargetIP = "192.168.1.202"; ExternalPort = "5900"; InternalPort = "5900"; Protocol = "tcp" }
|
||||
)
|
||||
|
||||
# Create port forwarding rules for remote access
|
||||
foreach ($service in $remoteServices) {
|
||||
New-OPNSensePortForwardingRule -Interface "WAN" `
|
||||
-Protocol $service.Protocol `
|
||||
-DestinationPort $service.ExternalPort `
|
||||
-TargetIP $service.TargetIP `
|
||||
-TargetPort $service.InternalPort `
|
||||
-Description $service.Name `
|
||||
-Log ` # Enable logging for security
|
||||
-Force
|
||||
}
|
||||
|
||||
# Verify the rules were created
|
||||
Get-OPNSensePortForwardingRule | Where-Object { $_.Description -like "* - *" } |
|
||||
Format-Table -Property Description, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
```
|
||||
|
||||
### Bulk Management of Port Forwarding Rules
|
||||
|
||||
This example demonstrates how to perform bulk operations on port forwarding rules:
|
||||
|
||||
```powershell
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all port forwarding rules
|
||||
$rules = Get-OPNSensePortForwardingRule
|
||||
|
||||
# Disable all rules with "Temporary" in the description
|
||||
$rules | Where-Object { $_.Description -like "*Temporary*" } | ForEach-Object {
|
||||
Set-OPNSensePortForwardingRule -Uuid $_.Uuid -Enabled:$false -Force
|
||||
Write-Output "Disabled rule: $($_.Description)"
|
||||
}
|
||||
|
||||
# Update all rules pointing to a decommissioned server
|
||||
$oldServerIP = "192.168.1.100"
|
||||
$newServerIP = "192.168.1.150"
|
||||
|
||||
$rules | Where-Object { $_.TargetIP -eq $oldServerIP } | ForEach-Object {
|
||||
Set-OPNSensePortForwardingRule -Uuid $_.Uuid -TargetIP $newServerIP -Description "$($_.Description) (Migrated)" -Force
|
||||
Write-Output "Updated rule: $($_.Description) to point to $newServerIP"
|
||||
}
|
||||
|
||||
# Delete all rules with "Obsolete" in the description
|
||||
$rules | Where-Object { $_.Description -like "*Obsolete*" } | ForEach-Object {
|
||||
Remove-OPNSensePortForwardingRule -Uuid $_.Uuid -Force
|
||||
Write-Output "Removed rule: $($_.Description)"
|
||||
}
|
||||
|
||||
# Verify changes
|
||||
$updatedRules = Get-OPNSensePortForwardingRule
|
||||
Write-Output "Rules after bulk operations:"
|
||||
$updatedRules | Format-Table -Property Uuid, Description, Enabled, TargetIP, DestinationPort, TargetPort
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- Port forwarding rules are applied immediately after creation, update, or deletion.
|
||||
- When creating or updating rules, consider security implications and only forward necessary ports.
|
||||
- Use the `FilterRuleAssociation` parameter to automatically create associated firewall rules.
|
||||
- NAT reflection allows internal clients to access forwarded services using the external IP address.
|
||||
- For security-sensitive rules, enable logging with the `-Log` parameter.
|
||||
- Always use strong authentication and encryption for remote access services.
|
||||
- Consider using non-standard external ports for common services to reduce automated scanning attempts.
|
||||
@@ -0,0 +1,42 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all port forwarding rules
|
||||
$rules = Get-OPNSensePortForwardingRule
|
||||
Write-Output "Current port forwarding rules:"
|
||||
$rules | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Create a new port forwarding rule for HTTP
|
||||
$httpRule = New-OPNSensePortForwardingRule -Interface "WAN" -Protocol "tcp" -DestinationPort "80" -TargetIP "192.168.1.100" -TargetPort "80" -Description "Web Server HTTP"
|
||||
Write-Output "Created HTTP port forwarding rule:"
|
||||
$httpRule | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Create a new port forwarding rule for HTTPS
|
||||
$httpsRule = New-OPNSensePortForwardingRule -Interface "WAN" -Protocol "tcp" -DestinationPort "443" -TargetIP "192.168.1.100" -TargetPort "443" -Description "Web Server HTTPS"
|
||||
Write-Output "Created HTTPS port forwarding rule:"
|
||||
$httpsRule | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Update the HTTP rule to point to a different server
|
||||
$updatedRule = Set-OPNSensePortForwardingRule -Uuid $httpRule.Uuid -TargetIP "192.168.1.200" -Description "Updated Web Server HTTP" -PassThru
|
||||
Write-Output "Updated HTTP port forwarding rule:"
|
||||
$updatedRule | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Get a specific rule by UUID
|
||||
$rule = Get-OPNSensePortForwardingRule -Uuid $httpsRule.Uuid
|
||||
Write-Output "Retrieved HTTPS port forwarding rule:"
|
||||
$rule | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Remove the HTTP rule
|
||||
Remove-OPNSensePortForwardingRule -Uuid $httpRule.Uuid -Force
|
||||
Write-Output "Removed HTTP port forwarding rule"
|
||||
|
||||
# Get all port forwarding rules again to verify changes
|
||||
$rules = Get-OPNSensePortForwardingRule
|
||||
Write-Output "Updated port forwarding rules:"
|
||||
$rules | Format-Table -Property Uuid, Description, Interface, Protocol, DestinationPort, TargetIP, TargetPort
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,31 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get available interfaces
|
||||
$interfaces = Get-OPNSenseInterface
|
||||
$interfaces | Format-Table -Property Name, Description, Status
|
||||
|
||||
# Create VLANs for subnets with sequential VLAN IDs
|
||||
$result1 = New-OPNSenseSubnetVLANs -ParentInterface "em0" -Network "192.168.0.0/24" -SubnetMaskBits 27 -StartingVlanId 10 -VlanIdIncrement 1
|
||||
Write-Output "Created VLANs with sequential IDs:"
|
||||
$result1.VLANs | Format-Table -Property VlanId, Subnet, Gateway, Status
|
||||
|
||||
# Create VLANs for subnets with VLAN IDs in multiples of 10
|
||||
$result2 = New-OPNSenseSubnetVLANs -ParentInterface "em1" -Network "10.0.0.0/16" -SubnetMaskBits 24 -StartingVlanId 100 -VlanIdIncrement 10
|
||||
Write-Output "Created VLANs with IDs in multiples of 10:"
|
||||
$result2.VLANs | Format-Table -Property VlanId, Subnet, Gateway, Status
|
||||
|
||||
# Create VLANs for subnets with DHCP enabled
|
||||
$result3 = New-OPNSenseSubnetVLANs -ParentInterface "em2" -Network "172.16.0.0/20" -SubnetMaskBits 24 -StartingVlanId 200 -VlanIdIncrement 1 -EnableDHCP -DescriptionPrefix "VLAN-DHCP"
|
||||
Write-Output "Created VLANs with DHCP enabled:"
|
||||
$result3.VLANs | Format-Table -Property VlanId, Subnet, Gateway, Status
|
||||
|
||||
# Get all VLANs
|
||||
$vlans = Get-OPNSenseVLAN
|
||||
$vlans | Format-Table -Property Uuid, Tag, Interface, Description
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,45 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get Tailscale status
|
||||
$status = Get-OPNSenseTailscaleStatus
|
||||
Write-Output "Tailscale Status:"
|
||||
$status
|
||||
|
||||
# Get detailed Tailscale status with interfaces and settings
|
||||
$detailedStatus = Get-OPNSenseTailscaleStatus -IncludeInterfaces -IncludeSettings
|
||||
Write-Output "Tailscale Interfaces:"
|
||||
$detailedStatus.Interfaces
|
||||
|
||||
# Enable Tailscale with default settings (will install plugin if not present)
|
||||
Enable-OPNSenseTailscale -Force
|
||||
|
||||
# Enable Tailscale with custom settings
|
||||
Enable-OPNSenseTailscale -AcceptDns -AcceptRoutes -Hostname "opnsense-firewall" -Force
|
||||
|
||||
# Enable Tailscale with subnet route advertising
|
||||
Enable-OPNSenseTailscale -AdvertiseRoutes -SubnetRoutes "192.168.1.0/24","10.0.0.0/8" -Force
|
||||
|
||||
# Connect to Tailscale network with an auth key
|
||||
# You can generate an auth key at https://login.tailscale.com/admin/settings/keys
|
||||
Connect-OPNSenseTailscale -AuthKey "tskey-auth-abcdef123456" -InstallIfMissing -EnableIfDisabled -StartIfStopped -Force
|
||||
|
||||
# Connect to Tailscale and advertise subnet routes
|
||||
Connect-OPNSenseTailscale -AuthKey "tskey-auth-abcdef123456" -SubnetRoutes "192.168.1.0/24","10.0.0.0/8" -AdvertiseRoutes -Force
|
||||
|
||||
# Get Tailscale status after connecting
|
||||
$connectedStatus = Get-OPNSenseTailscaleStatus -IncludeInterfaces
|
||||
Write-Output "Tailscale Connected Status:"
|
||||
$connectedStatus
|
||||
|
||||
# Disconnect from Tailscale network
|
||||
Disconnect-OPNSenseTailscale -Force
|
||||
|
||||
# Disable Tailscale and stop the service
|
||||
Disable-OPNSenseTailscale -Stop -Force
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -0,0 +1,28 @@
|
||||
# Import the module
|
||||
Import-Module PSOPNSenseAPI
|
||||
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Get all users
|
||||
$users = Get-OPNSenseUser
|
||||
$users | Format-Table -Property Uuid, Username, FullName, Email, Disabled
|
||||
|
||||
# Create a new user
|
||||
$userId = New-OPNSenseUser -Username "john" -Password "P@ssw0rd" -FullName "John Doe" -Email "john@example.com" -Groups "admins"
|
||||
Write-Output "Created user with ID: $userId"
|
||||
|
||||
# Update a user
|
||||
Set-OPNSenseUser -Uuid $userId -Email "john.doe@example.com" -FullName "John A. Doe"
|
||||
|
||||
# Disable a user
|
||||
Set-OPNSenseUser -Uuid $userId -Disabled
|
||||
|
||||
# Enable a user
|
||||
Set-OPNSenseUser -Uuid $userId -Enabled
|
||||
|
||||
# Remove a user
|
||||
Remove-OPNSenseUser -Uuid $userId -Confirm:$false
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
Reference in New Issue
Block a user