Class: IPTables::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/iptables/expansions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, info) ⇒ Service

Returns a new instance of Service.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/iptables/expansions.rb', line 66

def initialize(name, info)
  @name = name
  @info = info
  @children = []

  case info
  when Array
    self.handle_array()
  when Hash
    self.handle_hash()
  when Integer
    self.handle_integer()
  when String
    self.handle_string()
  else
    raise "don't know how to handle info: #{info.inspect}"
  end
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



65
66
67
# File 'lib/iptables/expansions.rb', line 65

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



65
66
67
# File 'lib/iptables/expansions.rb', line 65

def name
  @name
end

Instance Method Details

#add_child(rule_hash) ⇒ Object



85
86
87
# File 'lib/iptables/expansions.rb', line 85

def add_child(rule_hash)
  @children.push(rule_hash)
end

#handle_arrayObject



89
90
91
92
93
94
95
# File 'lib/iptables/expansions.rb', line 89

def handle_array()
  self.add_child( { 'comment' => "_ #{@name}" } )
  raise 'empty @info' if @info.empty?
  @info.each{ |service_info_hash|
    self.add_child(service_info_hash)
  }
end

#handle_hashObject



97
98
99
100
101
# File 'lib/iptables/expansions.rb', line 97

def handle_hash()
  raise 'empty @info' if @info.empty?
  @info['service_name'] = @name
  self.add_child( @info )
end

#handle_integerObject



103
104
105
106
107
108
109
# File 'lib/iptables/expansions.rb', line 103

def handle_integer()
  self.add_child( { 'comment' => "_ Port #{@info} - #{@name}" } )
  self.add_child({ 
    'raw' =>
    "-p tcp -m tcp --sport 1024:65535 --dport #{@info} -m state --state NEW,ESTABLISHED -j ACCEPT"
  })
end

#handle_stringObject



111
112
113
114
# File 'lib/iptables/expansions.rb', line 111

def handle_string()
  self.add_child( { 'comment' => "_ #{@name}" } )
  self.add_child( {'raw' => @info} )
end