|
|
@ -20,9 +20,6 @@
|
|
|
|
# WANT_JSON
|
|
|
|
# WANT_JSON
|
|
|
|
# POWERSHELL_COMMON
|
|
|
|
# POWERSHELL_COMMON
|
|
|
|
|
|
|
|
|
|
|
|
# temporarily disable strictmode, for this module only
|
|
|
|
|
|
|
|
Set-StrictMode -Off
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getFirewallRule ($fwsettings) {
|
|
|
|
function getFirewallRule ($fwsettings) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
@ -205,80 +202,54 @@ $fwsettings=@{}
|
|
|
|
# Variabelise the arguments
|
|
|
|
# Variabelise the arguments
|
|
|
|
$params=Parse-Args $args;
|
|
|
|
$params=Parse-Args $args;
|
|
|
|
|
|
|
|
|
|
|
|
$enable=Get-Attr $params "enable" $null;
|
|
|
|
$name = Get-AnsibleParam -obj $params -name "name" -failifempty $true
|
|
|
|
$state=Get-Attr $params "state" "present";
|
|
|
|
$direction = Get-AnsibleParam -obj $params -name "direction" -failifempty $true -validateSet "in","out"
|
|
|
|
$name=Get-Attr $params "name" "";
|
|
|
|
$action = Get-AnsibleParam -obj $params -name "action" -failifempty $true -validateSet "allow","block","bypass"
|
|
|
|
$direction=Get-Attr $params "direction" "";
|
|
|
|
$program = Get-AnsibleParam -obj $params -name "program"
|
|
|
|
$force=Get-Attr $params "force" $false;
|
|
|
|
$service = Get-AnsibleParam -obj $params -name "service" -default "any"
|
|
|
|
$action=Get-Attr $params "action" "";
|
|
|
|
$description = Get-AnsibleParam -obj $params -name "description"
|
|
|
|
|
|
|
|
$enable = ConvertTo-Bool (Get-AnsibleParam -obj $params -name "enable" -default "true")
|
|
|
|
|
|
|
|
$winprofile = Get-AnsibleParam -obj $params -name "profile" -default "any"
|
|
|
|
|
|
|
|
$localip = Get-AnsibleParam -obj $params -name "localip" -default "any"
|
|
|
|
|
|
|
|
$remoteip = Get-AnsibleParam -obj $params -name "remoteip" -default "any"
|
|
|
|
|
|
|
|
$localport = Get-AnsibleParam -obj $params -name "localport" -default "any"
|
|
|
|
|
|
|
|
$remoteport = Get-AnsibleParam -obj $params -name "remoteport" -default "any"
|
|
|
|
|
|
|
|
$protocol = Get-AnsibleParam -obj $params -name "protocol" -default "any"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$state = Get-AnsibleParam -obj $params -name "state" -failifempty $true -validateSet "present","absent"
|
|
|
|
|
|
|
|
$force = ConvertTo-Bool (Get-AnsibleParam -obj $params -name "force" -default "false")
|
|
|
|
|
|
|
|
|
|
|
|
$misArg = ''
|
|
|
|
|
|
|
|
# Check the arguments
|
|
|
|
# Check the arguments
|
|
|
|
if ($enable -ne $null) {
|
|
|
|
If ($enable -eq $true) {
|
|
|
|
$enable=ConvertTo-Bool $enable;
|
|
|
|
|
|
|
|
if ($enable -eq $true) {
|
|
|
|
|
|
|
|
$fwsettings.Add("Enabled", "yes");
|
|
|
|
$fwsettings.Add("Enabled", "yes");
|
|
|
|
} elseif ($enable -eq $false) {
|
|
|
|
} Else {
|
|
|
|
$fwsettings.Add("Enabled", "no");
|
|
|
|
$fwsettings.Add("Enabled", "no");
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$misArg+="enable";
|
|
|
|
|
|
|
|
$msg+=@("for the enable parameter only yes and no is allowed");
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (($state -ne "present") -And ($state -ne "absent")){
|
|
|
|
|
|
|
|
$misArg+="state";
|
|
|
|
|
|
|
|
$msg+=@("for the state parameter only present and absent is allowed");
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if ($name -eq ""){
|
|
|
|
|
|
|
|
$misArg+="Name";
|
|
|
|
|
|
|
|
$msg+=@("name is a required argument");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$fwsettings.Add("Rule Name", $name)
|
|
|
|
$fwsettings.Add("Rule Name", $name)
|
|
|
|
#$fwsettings.Add("displayname", $name)
|
|
|
|
#$fwsettings.Add("displayname", $name)
|
|
|
|
};
|
|
|
|
|
|
|
|
if ((($direction.ToLower() -ne "In") -And ($direction.ToLower() -ne "Out")) -And ($state -eq "present")){
|
|
|
|
$state = $state.ToString().ToLower()
|
|
|
|
$misArg+="Direction";
|
|
|
|
If ($state -eq "present")){
|
|
|
|
$msg+=@("for the Direction parameter only the values 'In' and 'Out' are allowed");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$fwsettings.Add("Direction", $direction)
|
|
|
|
$fwsettings.Add("Direction", $direction)
|
|
|
|
};
|
|
|
|
|
|
|
|
if ((($action.ToLower() -ne "allow") -And ($action.ToLower() -ne "block")) -And ($state -eq "present")){
|
|
|
|
|
|
|
|
$misArg+="Action";
|
|
|
|
|
|
|
|
$msg+=@("for the Action parameter only the values 'allow' and 'block' are allowed");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$fwsettings.Add("Action", $action)
|
|
|
|
$fwsettings.Add("Action", $action)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
$args=@(
|
|
|
|
|
|
|
|
"Description",
|
|
|
|
|
|
|
|
"LocalIP",
|
|
|
|
|
|
|
|
"RemoteIP",
|
|
|
|
|
|
|
|
"LocalPort",
|
|
|
|
|
|
|
|
"RemotePort",
|
|
|
|
|
|
|
|
"Program",
|
|
|
|
|
|
|
|
"Service",
|
|
|
|
|
|
|
|
"Protocol"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($arg in $args){
|
|
|
|
If ($description) {
|
|
|
|
New-Variable -Name $arg -Value $(Get-Attr $params $arg "");
|
|
|
|
$fwsettings.Add("Description", $description);
|
|
|
|
if ((Get-Variable -Name $arg -ValueOnly) -ne ""){
|
|
|
|
}
|
|
|
|
$fwsettings.Add($arg, $(Get-Variable -Name $arg -ValueOnly));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$winprofile=Get-Attr $params "profile" "current";
|
|
|
|
If ($program) {
|
|
|
|
$fwsettings.Add("Profiles", $winprofile)
|
|
|
|
$fwsettings.Add("Program", $program);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($misArg){
|
|
|
|
$fwsettings.Add("LocalIP", $localip);
|
|
|
|
$result=New-Object psobject @{
|
|
|
|
$fwsettings.Add("RemoteIP", $remoteip);
|
|
|
|
changed=$false
|
|
|
|
$fwsettings.Add("LocalPort", $localport);
|
|
|
|
failed=$true
|
|
|
|
$fwsettings.Add("RemotePort", $remoteport);
|
|
|
|
msg=$msg
|
|
|
|
$fwsettings.Add("Service", $service);
|
|
|
|
};
|
|
|
|
$fwsettings.Add("Protocol", $protocol);
|
|
|
|
Exit-Json($result);
|
|
|
|
$fwsettings.Add("Profiles", $winprofile)
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$output=@()
|
|
|
|
$output=@()
|
|
|
|
$capture=getFirewallRule ($fwsettings);
|
|
|
|
$capture=getFirewallRule ($fwsettings);
|
|
|
@ -299,7 +270,7 @@ if ($capture.failed -eq $true) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch ($state.ToLower()){
|
|
|
|
switch ($state){
|
|
|
|
"present" {
|
|
|
|
"present" {
|
|
|
|
if ($capture.exists -eq $false) {
|
|
|
|
if ($capture.exists -eq $false) {
|
|
|
|
$capture=createFireWallRule($fwsettings);
|
|
|
|
$capture=createFireWallRule($fwsettings);
|
|
|
|