|
|
@ -1,6 +1,20 @@
|
|
|
|
#Requires -Modules powershell-yaml
|
|
|
|
#Requires -Modules powershell-yaml
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Start-IptablesProcess {
|
|
|
|
|
|
|
|
param (
|
|
|
|
|
|
|
|
[array]$ArgumentList
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$splat = @{
|
|
|
|
|
|
|
|
FilePath = 'iptables'
|
|
|
|
|
|
|
|
ArgumentList = $ArgumentList
|
|
|
|
|
|
|
|
Wait = $true
|
|
|
|
|
|
|
|
PassThru = $true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Start-Process @splat
|
|
|
|
|
|
|
|
}
|
|
|
|
function Test-IptablesChain {
|
|
|
|
function Test-IptablesChain {
|
|
|
|
param (
|
|
|
|
param (
|
|
|
|
[string]$Chain,
|
|
|
|
[string]$Chain,
|
|
|
@ -41,14 +55,7 @@ function Test-IptablesRule {
|
|
|
|
$Chain
|
|
|
|
$Chain
|
|
|
|
)+$Rule
|
|
|
|
)+$Rule
|
|
|
|
|
|
|
|
|
|
|
|
$check_splat = @{
|
|
|
|
$check = Start-IptablesProcess -ArgumentList $argument_list
|
|
|
|
FilePath = 'iptables'
|
|
|
|
|
|
|
|
ArgumentList = $argument_list
|
|
|
|
|
|
|
|
Wait = $true
|
|
|
|
|
|
|
|
PassThru = $true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$check = Start-Process @check_splat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Write-Output ($check.ExitCode -eq 0)
|
|
|
|
Write-Output ($check.ExitCode -eq 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -66,16 +73,11 @@ function Add-IptablesRule {
|
|
|
|
$Chain
|
|
|
|
$Chain
|
|
|
|
)+$Rule
|
|
|
|
)+$Rule
|
|
|
|
|
|
|
|
|
|
|
|
$add_splat = @{
|
|
|
|
|
|
|
|
FilePath = 'iptables'
|
|
|
|
|
|
|
|
ArgumentList = $argument_list
|
|
|
|
|
|
|
|
Wait = $true
|
|
|
|
|
|
|
|
PassThru = $true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(-not (Test-IptablesRule -Chain $Chain -Rule $Rule)) {
|
|
|
|
if(-not (Test-IptablesRule -Chain $Chain -Rule $Rule)) {
|
|
|
|
$add = Start-Process @add_splat
|
|
|
|
$add = Start-IptablesProcess -ArgumentList $argument_list
|
|
|
|
if(0 -ne $add.ExitCode) {
|
|
|
|
if(0 -eq $add.ExitCode) {
|
|
|
|
|
|
|
|
Write-Output $true
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Write-Error 'Adding iptables rule failed'
|
|
|
|
Write-Error 'Adding iptables rule failed'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|