def to_s
template = File.read(self.template_file)
if template =~ /\$(SRC|DEST)/
lines = template.split("\n")
if !ipv4? and lines.any?{|l| l =~ /^[^#]*iptables /}
warn "Disabling IPv4 rules for non-IPv4 addresses in #{self.name}" if $VERBOSE
lines = lines.collect{|l| l =~ /^[^#]*iptables / ? "# "+l : l }
end
if !ipv6? and lines.any?{|l| l =~ /^[^#]*ip6tables /}
warn "Disabling IPv6 rules for non-IPv6 addresses in #{self.name}" if $VERBOSE
lines = lines.collect{|l| l =~ /^[^#]*ip6tables / ? "# "+l : l }
end
lines = lines.collect do |l|
next if l =~ /^#/
l = l.gsub("$SRC",src).gsub("$DEST",dst)
while l =~ /^[^#]*(\$[A-Z]+)/
warn "Bad variable #{$1} in #{self.template_file} -- removing!"
l = l.gsub($1,"")
end
l
end
return lines.join("\n")
else
begin
return ERB.new(template,0,'%>').result(binding)
rescue NoMethodError,ArgumentError,SyntaxError => err
warn "Caught error in #{template_file}: #{err.to_s}"
raise err
end
end
end