Class: Tablomat::IPTablesBase::Rule
- Inherits:
-
Object
- Object
- Tablomat::IPTablesBase::Rule
- Defined in:
- lib/tablomat/iptables/rule.rb
Overview
IPTables are made of Rules
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#method ⇒ Object
Returns the value of attribute method.
-
#owned ⇒ Object
Returns the value of attribute owned.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #activate(override = false) ⇒ Object
- #apply_create ⇒ Object
- #apply_delete ⇒ Object
- #deactivate(override = false) ⇒ Object
-
#initialize(chain, description, owned = true) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(chain, description, owned = true) ⇒ Rule
Returns a new instance of Rule.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tablomat/iptables/rule.rb', line 10 def initialize(chain, description, owned = true) @system = chain.table.system @chain = chain @description = description @items = {} @owned = owned @active = false @method = 'APPEND' @position = 0 activate if @chain.active end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
7 8 9 |
# File 'lib/tablomat/iptables/rule.rb', line 7 def active @active end |
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
8 9 10 |
# File 'lib/tablomat/iptables/rule.rb', line 8 def chain @chain end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'lib/tablomat/iptables/rule.rb', line 8 def description @description end |
#method ⇒ Object
Returns the value of attribute method.
7 8 9 |
# File 'lib/tablomat/iptables/rule.rb', line 7 def method @method end |
#owned ⇒ Object
Returns the value of attribute owned.
7 8 9 |
# File 'lib/tablomat/iptables/rule.rb', line 7 def owned @owned end |
#position ⇒ Object
Returns the value of attribute position.
7 8 9 |
# File 'lib/tablomat/iptables/rule.rb', line 7 def position @position end |
Instance Method Details
#activate(override = false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tablomat/iptables/rule.rb', line 22 def activate(override = false) return unless @owned || override return if @active @active = true return if override @chain.activate unless @chain.active apply_create end |
#apply_create ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tablomat/iptables/rule.rb', line 43 def apply_create return unless @owned method = if @method == 'APPEND' "-A #{@chain.name}" else "-I #{@chain.name} #{@position}" end command = "#{@system.iptables_bin} -t #{@chain.table.name} #{method} #{@description}" @system.exec command end |
#apply_delete ⇒ Object
55 56 57 58 59 60 |
# File 'lib/tablomat/iptables/rule.rb', line 55 def apply_delete return unless @owned command = "#{@system.iptables_bin} -t #{@chain.table.name} -D #{@chain.name} #{@description}" @system.exec command end |
#deactivate(override = false) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/tablomat/iptables/rule.rb', line 33 def deactivate(override = false) return unless @owned || override return unless @active self.active = false return if override apply_delete end |