File: firewall.rb

package info (click to toggle)
ruby-specinfra 2.89.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,412 kB
  • sloc: ruby: 10,338; sh: 4; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 1,301 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Specinfra::Command::Windows::Base::Firewall < Specinfra::Command::Windows::Base
  class << self
    def check_exists(displayName)
      cmd = "(Get-NetFirewallRule -DisplayName '#{displayName}') -ne $null"
      create_command cmd
    end

    def check_is_enabled(displayName)
      cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | where {$_.Enabled -eq 'True'}) -ne $null"
      create_command cmd
    end

    def check_has_action(displayName, action)
      cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | where {$_.Action -eq '#{action}'}) -ne $null"
      create_command cmd
    end

    def check_has_protocol(displayName, protocol)
      cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | Get-NetFirewallPortFilter | where {$_.Protocol -eq '#{protocol}'}) -ne $null"
      create_command cmd
    end

    def check_has_localport(displayName, localport)
      cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | Get-NetFirewallPortFilter | where {$_.LocalPort -eq '#{localport}'}) -ne $null"
      create_command cmd
    end

    def check_has_direction(displayName, direction)
      cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | where {$_.Direction -eq '#{direction}'}) -ne $null"
      create_command cmd
    end
  end
end