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