def initialize(filename)
@logfile = nil
@ports = nil
@patterns = []
@filename = filename
File.readlines(filename).each do |line|
line = line.strip.chomp
next if line.empty? or line =~ /^#/
if line =~ /^file\s*=\s*(.*)/ and @logfile.nil?
@logfile = $1
elsif line =~ /^ports\s*=\s*(.*)/ and @ports.nil?
@ports = $1.split(/[^a-z0-9]+/i)
else
line = line.gsub("__IP__","(?:::ffff:)?([0-9a-fA-F:\.]+(?:/[0-9]+)?)")
unless line =~ /^\^/ or line =~ /\$$/
line += "$"
end
@patterns << Regexp.new(line)
end
end
if @ports.nil? or @ports.empty?
puts "No ports set in #{filename} -- assuming 'all'." if $VERBOSE
@ports = %w(all)
end
end