Sha256: eb1fce5c62c496169deaada34dee28a21b70337c0375359dd88354a12bcd59d1

Contents?: true

Size: 1.56 KB

Versions: 46

Compression:

Stored size: 1.56 KB

Contents

#
# iplookup.rb: included TDiary::Filter::IplookupFilter class
#
#
# Copyright (c) 2008 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
# Distributed under the GPL2
#

require 'resolv'

module TDiary
   module Filter
      class IplookupFilter < Filter
         def iplookup_init
            if @conf.options.include?('iplookup.ip.list')
               @iplookup_ip_list = @conf.options['iplookup.ip.list']
            else
               @iplookup_ip_list = "bsb.spamlookup.net\nopm.blitzed.org\n" +
                                   "niku.2ch.net\ndnsbl.spam-champuru.livedoor.com"
            end
         end

         def black_ip?( address )
            chance = 2
            ip = address.gsub(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/, '\4.\3.\2.\1')
            @iplookup_ip_list.split(/\n+/).each do |dnsbl|
               begin
                  address = Resolv.getaddress( "#{ip}.#{dnsbl}" )
                  return true
                  rescue Resolv::ResolvTimeout
                     if chance > 0
                        chance -= 1
                        retry
                     end
                  rescue Resolv::ResolvError
                  rescue Exception
               end
            end
            return false
         end

         def comment_filter( diary, comment )
            iplookup_init
            return false if black_ip?( @cgi.remote_addr )
            return true
         end

         def referer_filter( referer )
            iplookup_init
            return false if black_ip?( @cgi.remote_addr )
            return true
         end
      end
   end
end

Version data entries

46 entries across 40 versions & 2 rubygems

Version Path
tdiary-contrib-5.3.0 filter/iplookup.rb
tdiary-contrib-5.2.4 filter/iplookup.rb
tdiary-contrib-5.2.3 filter/iplookup.rb
tdiary-contrib-5.2.2 filter/iplookup.rb
tdiary-contrib-5.2.1 filter/iplookup.rb
tdiary-contrib-5.2.0 filter/iplookup.rb
tdiary-contrib-5.1.7 filter/iplookup.rb
tdiary-contrib-5.1.6 filter/iplookup.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/filter/iplookup.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/bundler/gems/tdiary-contrib-d1e41204db13/filter/iplookup.rb
tdiary-contrib-5.1.5 filter/iplookup.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/filter/iplookup.rb
tdiary-contrib-5.1.4 filter/iplookup.rb
tdiary-contrib-5.1.3 filter/iplookup.rb
tdiary-contrib-5.1.2 filter/iplookup.rb
tdiary-contrib-5.1.1 filter/iplookup.rb
tdiary-contrib-5.1.0 filter/iplookup.rb
tdiary-contrib-5.0.13 filter/iplookup.rb
tdiary-contrib-5.0.12 filter/iplookup.rb
tdiary-contrib-5.0.11 filter/iplookup.rb