Reverts all executed rules that this handler knows about.
# File lib/packetthief/impl/pf_divert.rb, line 83 def revert return if @active_rules == nil or @active_rules.empty? args = %W{pfctl -a packetthief -F rules} unless system(*args) raise "Command #{args.inspect} exited with error code #{$?.inspect}" end # end @active_rules = [] end
Executes a rule and holds onto it for later removal.
# File lib/packetthief/impl/pf_divert.rb, line 64 def run(rule) @active_rules ||= [] # args = ['pfctl', 'add', 'set', '30'] # TODO: make the rule number customizable args = ['echo'] @active_rules << rule args << @active_rules.map { |r| r.to_pf_command.join(" ") }.join("\n") args = args + %w{| pfctl -a packetthief -f -} # run the command unless system(*args) raise "Command #{args.inspect} exited with error code #{$?.inspect}" end end