Class: IPTables::Service
- Inherits:
-
Object
- Object
- IPTables::Service
- Defined in:
- lib/iptables/expansions.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_child(rule_hash) ⇒ Object
- #handle_array ⇒ Object
- #handle_hash ⇒ Object
- #handle_integer ⇒ Object
- #handle_string ⇒ Object
-
#initialize(name, info) ⇒ Service
constructor
A new instance of Service.
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
#children ⇒ Object (readonly)
Returns the value of attribute children.
65 66 67 |
# File 'lib/iptables/expansions.rb', line 65 def children @children end |
#name ⇒ Object (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_array ⇒ Object
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_hash ⇒ Object
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_integer ⇒ Object
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_string ⇒ Object
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 |