Sha256: 41c6488cb4bea4f30ec507125017c9953b1487d83ebce69c3d17367b0c3adf9a

Contents?: true

Size: 750 Bytes

Versions: 6

Compression:

Stored size: 750 Bytes

Contents

module Shutter
  module IPTables
    class EyePee
      def initialize( path, state )
        @state = state
        file = File.open("#{path}/ip.#{state.to_s}", "r")
        @content = file.read
      end

      def to_s
        @content
      end

      def to_ipt
        @rules = ""
        @content.each_line do |ip|
          ip_clean = ip.strip
          if ip_clean =~ /^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}(\/[0-9]{0,2})*$/
            @rules += send(:"#{@state.to_s}_ipt", ip_clean)
          end
        end
        @rules
      end

      def allow_ipt(ip)
        "-A AllowIP -m state --state NEW -s #{ip} -j Allowed\n"
      end

      def deny_ipt(ip)
        "-A Bastards -s #{ip} -j DropBastards\n"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shutter-0.0.7 lib/shutter/iptables/eyepee.rb
shutter-0.0.6 lib/shutter/iptables/eyepee.rb
shutter-0.0.5 lib/shutter/iptables/eyepee.rb
shutter-0.0.4 lib/shutter/iptables/eyepee.rb
shutter-0.0.3 lib/shutter/iptables/eyepee.rb
shutter-0.0.2 lib/shutter/iptables/eyepee.rb