class Construqt::Flavour::Ubuntu::EtcNetworkIptables::Section::Block

Public Class Methods

new(section) click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 82
def initialize(section)
  @section = section
  @rows = []
end

Public Instance Methods

commit() click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 130
def commit
  #puts @rows.inspect
  tables = @rows.inject({}) do |r, row|
    r[row.get_table] ||= {}
    r[row.get_table][row.get_chain] ||= []
    r[row.get_table][row.get_chain] << row
    r
  end

  return "" if tables.empty?
  ret = ["*#{@section.name}"]
  ret += tables.keys.sort.map do |k|
    v = tables[k]
    if k.empty?
      v.keys.map{|o| ":#{o} ACCEPT [0:0]" }
    else
      ":#{k} - [0:0]"
    end
  end

  tables.keys.sort.each do |k,v|
    v = tables[k]
    v.keys.sort.each do |chain|
      rows = v[chain]
      table = !k.empty? ? "-A #{k}" : "-A #{chain}"
      rows.each do |row|
        ret << "#{table} #{row.get_row}"
      end
    end
  end

  ret << "COMMIT"
  ret << ""
  ret.join("\n")
end
forward() click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 118
def forward
  table("", 'FORWARD')
end
input() click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 126
def input
  table("", 'INPUT')
end
output() click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 122
def output
  table("", 'OUTPUT')
end
postrouting() click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 114
def postrouting
  table("", 'POSTROUTING')
end
prerouting() click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 110
def prerouting
  table("", 'PREROUTING')
end
table(table, chain = nil) click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 106
def table(table, chain = nil)
  RowFactory.new.rows(@rows).table(table).chain(chain)
end