rack-tor-tag 0.0.8 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -7
- data/VERSION +1 -1
- data/lib/rack/tor_tag.rb +26 -10
- data/rack-tor-tag.gemspec +3 -3
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 027ae09603e859442444675a51ceecb2ec6818d8
         | 
| 4 | 
            +
              data.tar.gz: 901771003822ee99803fa46d2abb6a9f23ceed26
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c6ceb3d63d987ba465055f7e74c74b011ad970e5b4b9df33a800d92db5ea5d1e671c9e13d86f2930306fad9b913f9d73dcc773353673fdb5e09b8addeb531847
         | 
| 7 | 
            +
              data.tar.gz: 17f69f2a315d5b2ff02e9660521c5ffe2defe07e2b0f75120f8a3628f83db77732c87034c256b9cb565365b5f5145619857ed2e80b6df202cb0097e10106d761
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            GEM
         | 
| 2 2 | 
             
              remote: http://rubygems.org/
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                addressable (2.3. | 
| 4 | 
            +
                addressable (2.3.6)
         | 
| 5 5 | 
             
                builder (3.2.2)
         | 
| 6 | 
            -
                cucumber (1.3. | 
| 6 | 
            +
                cucumber (1.3.13)
         | 
| 7 7 | 
             
                  builder (>= 2.1.2)
         | 
| 8 8 | 
             
                  diff-lcs (>= 1.1.3)
         | 
| 9 9 | 
             
                  gherkin (~> 2.12)
         | 
| 10 10 | 
             
                  multi_json (>= 1.7.5, < 2.0)
         | 
| 11 | 
            -
                  multi_test (>= 0. | 
| 11 | 
            +
                  multi_test (>= 0.1.1)
         | 
| 12 12 | 
             
                descendants_tracker (0.0.3)
         | 
| 13 13 | 
             
                diff-lcs (1.2.5)
         | 
| 14 14 | 
             
                docile (1.1.3)
         | 
| @@ -39,9 +39,9 @@ GEM | |
| 39 39 | 
             
                json (1.8.1)
         | 
| 40 40 | 
             
                jwt (0.1.11)
         | 
| 41 41 | 
             
                  multi_json (>= 1.5)
         | 
| 42 | 
            -
                mini_portile (0.5. | 
| 43 | 
            -
                multi_json (1.9. | 
| 44 | 
            -
                multi_test (0. | 
| 42 | 
            +
                mini_portile (0.5.3)
         | 
| 43 | 
            +
                multi_json (1.9.2)
         | 
| 44 | 
            +
                multi_test (0.1.1)
         | 
| 45 45 | 
             
                multi_xml (0.5.5)
         | 
| 46 46 | 
             
                multipart-post (2.0.0)
         | 
| 47 47 | 
             
                nokogiri (1.6.1)
         | 
| @@ -53,7 +53,7 @@ GEM | |
| 53 53 | 
             
                  multi_xml (~> 0.5)
         | 
| 54 54 | 
             
                  rack (~> 1.2)
         | 
| 55 55 | 
             
                rack (1.5.2)
         | 
| 56 | 
            -
                rake (10. | 
| 56 | 
            +
                rake (10.2.0)
         | 
| 57 57 | 
             
                rdoc (4.1.1)
         | 
| 58 58 | 
             
                  json (~> 1.4)
         | 
| 59 59 | 
             
                rspec (2.14.1)
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.1.1
         | 
    
        data/lib/rack/tor_tag.rb
    CHANGED
    
    | @@ -1,6 +1,9 @@ | |
| 1 1 | 
             
            require 'rack'
         | 
| 2 2 | 
             
            require 'resolv'
         | 
| 3 3 |  | 
| 4 | 
            +
            # Not in rbx. See https://github.com/rubinius/rubinius/issues/2303
         | 
| 5 | 
            +
            RESOLV_WORKS = Socket.methods.include?(:ip_address_list)
         | 
| 6 | 
            +
             | 
| 4 7 | 
             
            module Rack
         | 
| 5 8 | 
             
              class TorTag
         | 
| 6 9 | 
             
                DEFAULT_PARAMS = {
         | 
| @@ -14,6 +17,8 @@ module Rack | |
| 14 17 | 
             
                def initialize(app, params = {})
         | 
| 15 18 | 
             
                  @app = app
         | 
| 16 19 | 
             
                  @params = DEFAULT_PARAMS.merge(params)
         | 
| 20 | 
            +
                  puts "rack-tor-tag initialized: #{app} - #{params}"
         | 
| 21 | 
            +
                  # raise ArgumentError, "Must pass :host_ips" unless RESOLV_WORKS
         | 
| 17 22 | 
             
                end
         | 
| 18 23 |  | 
| 19 24 | 
             
                def call(env)
         | 
| @@ -44,18 +49,29 @@ module Rack | |
| 44 49 | 
             
                def is_tor? ip, env
         | 
| 45 50 | 
             
                  # We're a hidden service! Of course it's Tor.
         | 
| 46 51 | 
             
                  return true if env['HTTP_HOST'] =~ /\.onion\z/
         | 
| 47 | 
            -
                  return false if ( | 
| 52 | 
            +
                  return false if (['localhost','127.0.0.1'].include? ip) or (['localhost','127.0.0.1'].include? env['HTTP_HOST'])
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  host_ips = @params[:host_ips]
         | 
| 48 55 |  | 
| 49 | 
            -
                   | 
| 50 | 
            -
                    env['HTTP_HOST'] ? env['HTTP_HOST'].sub(/:.*/,'') : env['SERVER_NAME']) | 
| 51 | 
            -
             | 
| 56 | 
            +
                  if RESOLV_WORKS
         | 
| 57 | 
            +
                    addrs = (env['HTTP_HOST'] ? env['HTTP_HOST'].sub(/:.*/,'') : env['SERVER_NAME'])
         | 
| 58 | 
            +
                    host_ips ||= Resolv.getaddresses(addrs).select{
         | 
| 59 | 
            +
                      |i| i[Resolv::IPv4::Regex] # DNEL only works with IPv4
         | 
| 60 | 
            +
                    }
         | 
| 61 | 
            +
                  else
         | 
| 62 | 
            +
                    raise ArgumentError, "Socket.ip_address_list is missing, so you must pass :host_ips" unless host_ips
         | 
| 63 | 
            +
                  end
         | 
| 52 64 |  | 
| 53 65 | 
             
                  host_ips.each do |host_ip|
         | 
| 54 | 
            -
                    tor_hostname = [reverse_ip_octets(ip), @params[:host_port] || env['SERVER_PORT'], reverse_ip_octets(host_ip), @params[:dnsel]].join('.')
         | 
| 55 | 
            -
                     | 
| 56 | 
            -
                       | 
| 57 | 
            -
             | 
| 58 | 
            -
                       | 
| 66 | 
            +
                    tor_hostname = [reverse_ip_octets(ip), @params[:host_port] || env['SERVER_PORT'].to_i, reverse_ip_octets(host_ip), @params[:dnsel]].join('.')
         | 
| 67 | 
            +
                    if RESOLV_WORKS
         | 
| 68 | 
            +
                      begin
         | 
| 69 | 
            +
                        return true if (Resolv.getaddress(tor_hostname) == '127.0.0.2')
         | 
| 70 | 
            +
                      rescue Resolv::ResolvError => e
         | 
| 71 | 
            +
                        false # It's supposed to not get a response if it's not a tor host
         | 
| 72 | 
            +
                      end
         | 
| 73 | 
            +
                    else # try what we can...
         | 
| 74 | 
            +
                      return true if (`dig A +short #{tor_hostname}`.to_s.strip == '127.0.0.2')
         | 
| 59 75 | 
             
                    end
         | 
| 60 76 | 
             
                  end
         | 
| 61 77 | 
             
                  false
         | 
| @@ -65,7 +81,7 @@ module Rack | |
| 65 81 | 
             
                end
         | 
| 66 82 |  | 
| 67 83 | 
             
                def reverse_ip_octets(ip)
         | 
| 68 | 
            -
                  ip.to_s.split('.').reverse.join('.')
         | 
| 84 | 
            +
                  ip.to_s.split('.').map(&:to_i).reverse.join('.')
         | 
| 69 85 | 
             
                end
         | 
| 70 86 | 
             
              end
         | 
| 71 87 | 
             
            end
         | 
    
        data/rack-tor-tag.gemspec
    CHANGED
    
    | @@ -2,16 +2,16 @@ | |
| 2 2 | 
             
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 3 | 
             
            # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
         | 
| 4 4 | 
             
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            -
            # stub: rack-tor-tag 0. | 
| 5 | 
            +
            # stub: rack-tor-tag 0.1.1 ruby lib
         | 
| 6 6 |  | 
| 7 7 | 
             
            Gem::Specification.new do |s|
         | 
| 8 8 | 
             
              s.name = "rack-tor-tag"
         | 
| 9 | 
            -
              s.version = "0. | 
| 9 | 
            +
              s.version = "0.1.1"
         | 
| 10 10 |  | 
| 11 11 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 12 12 | 
             
              s.require_paths = ["lib"]
         | 
| 13 13 | 
             
              s.authors = ["Sai"]
         | 
| 14 | 
            -
              s.date = "2014-03- | 
| 14 | 
            +
              s.date = "2014-03-25"
         | 
| 15 15 | 
             
              s.description = "Mark Tor users using rack, for filtering / throttling / etc"
         | 
| 16 16 | 
             
              s.email = "github@saizai.com"
         | 
| 17 17 | 
             
              s.extra_rdoc_files = [
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rack-tor-tag
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sai
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-03- | 
| 11 | 
            +
            date: 2014-03-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rspec
         |