proxied 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58e69adf50671eb77dac5aab9fbe23f3704243a1f21678082bfb4d92cd1204a9
4
- data.tar.gz: c10c1245e7fde08ab30b82e109e3c5d977dd0dc80332f48f37910d5c9b30bb23
3
+ metadata.gz: 259fa06faa16224529c74da60047158116d019a7017972887cd9c91228f854b4
4
+ data.tar.gz: a9a83e6416cc5db560e4b3d90129eabc7e0c55aeea4150bba155f482957091bb
5
5
  SHA512:
6
- metadata.gz: de4a55cac54cf4906ad7ff46cc774d2ca0eec7e416227a5e8f091c8faead140741fe5f5defd9a3f7d5ac963430281aca48992953a1e88252f92a3cecf5de885d
7
- data.tar.gz: 412e1cf5216ffd43e7b48c916331a5798ef139eab8372f7a917298728eb50935d08830b7ffb8abf9929877bed5101b2e65d84bbe6851ccbd93f0cc74c7c30ddf
6
+ metadata.gz: 764f5d70013bf48d88064cf6bd90d5c29759f75b6672f26e4d443f3bebc7e49e18f71d4bd1dbd7628cfcbd3c9bd178027a2327d3f68732cf96b09a2be8234537
7
+ data.tar.gz: 1a79de19edcfb1bdef83ff8d110489ab43501732dbb04c38f6a312e382f69fbc63142c6a60fc1de9e081628952c5a3984bfd55e8e4373dbf4e99e0c0f5ec28c2
@@ -20,16 +20,16 @@ module ActiveRecord
20
20
  end
21
21
 
22
22
  def inject_proxied_content
23
- content = model_contents
23
+ content = model_contents
24
24
 
25
- class_path = if namespaced?
25
+ class_path = if namespaced?
26
26
  class_name.to_s.split("::")
27
27
  else
28
28
  [class_name]
29
29
  end
30
30
 
31
- indent_depth = class_path.size - 1
32
- content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
31
+ indent_depth = class_path.size - 1
32
+ content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
33
33
 
34
34
  inject_into_class(model_path, class_path.last, content) if model_exists?
35
35
  end
@@ -40,8 +40,8 @@ module ActiveRecord
40
40
  RUBY
41
41
  end
42
42
 
43
- def rails5?
44
- Rails.version.start_with? '5'
43
+ def should_version_migration?
44
+ !(Rails.version.to_s =~ /^(5|6)/i).nil?
45
45
  end
46
46
 
47
47
  def postgresql?
@@ -49,20 +49,21 @@ RUBY
49
49
  config && config['adapter'] == 'postgresql'
50
50
  end
51
51
 
52
- def migration_version
53
- if rails5?
54
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
55
- end
56
- end
52
+ def migration_version
53
+ if should_version_migration?
54
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
55
+ end
56
+ end
57
57
 
58
- def primary_key_type
59
- primary_key_string if rails5?
60
- end
58
+ def primary_key_type
59
+ primary_key_string if should_version_migration?
60
+ end
61
61
 
62
- def primary_key_string
63
- key_string = options[:primary_key_type]
64
- ", id: :#{key_string}" if key_string
65
- end
62
+ def primary_key_string
63
+ key_string = options[:primary_key_type]
64
+ ", id: :#{key_string}" if key_string
65
+ end
66
+
66
67
  end
67
68
  end
68
69
  end
@@ -4,6 +4,7 @@ class ProxiedCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migra
4
4
  def change
5
5
  create_table :<%= table_name %><%= primary_key_type %> do |t|
6
6
  t.string :host, null: false, index: true
7
+ t.string :ip_address, null: false, index: true
7
8
  t.integer :port, null: false, index: true
8
9
  t.string :username
9
10
  t.string :password
@@ -22,6 +22,7 @@ module Mongoid
22
22
 
23
23
  # Fields
24
24
  field :host, type: String
25
+ field :ip_address, type: String
25
26
  field :port, type: Integer
26
27
 
27
28
  field :username, type: String
@@ -5,4 +5,17 @@
5
5
  config.maximum_failed_attempts = 10
6
6
 
7
7
  config.job_queue = :proxies
8
+
9
+ config.http_test = {
10
+ url: "http://ipinfo.io/ip",
11
+ evaluate: -> (proxy, response) { response.to_s.strip.eql?(proxy.ip_address.strip) },
12
+ timeout: 10,
13
+ }
14
+
15
+ config.socks_test = {
16
+ hostname: "whois.verisign-grs.com",
17
+ port: 43,
18
+ query: "=google.com",
19
+ timeout: 10
20
+ }
8
21
  end
@@ -67,11 +67,11 @@ module Proxied
67
67
  return valid_proxy
68
68
  end
69
69
 
70
- def check_http_proxy(proxy, test_url: ::Proxied.configuration.http_test[:url], timeout: ::Proxied.configuration.http_test[:timeout], update: true)
70
+ def check_http_proxy(proxy, test_url: ::Proxied.configuration.http_test[:url], evaluate: ::Proxied.configuration.http_test[:evaluate], timeout: ::Proxied.configuration.http_test[:timeout], update: true)
71
71
  ::Proxied::Logger.log "#{Time.now}: Fetching #{::Proxied.configuration.http_test[:url]} with proxy #{proxy.proxy_address}."
72
72
 
73
73
  response = request(test_url, proxy, options: {timeout: timeout})
74
- valid_proxy = response.to_s.strip.eql?(proxy.host.strip)
74
+ valid_proxy = evaluate.call(proxy, response)
75
75
 
76
76
  update_proxy(proxy, valid_proxy) if update
77
77
 
@@ -21,6 +21,7 @@ module Proxied
21
21
 
22
22
  self.http_test = {
23
23
  url: "http://ipinfo.io/ip",
24
+ evaluate: -> (proxy, response) { response.to_s.strip.eql?(proxy.ip_address.strip) },
24
25
  timeout: 10,
25
26
  }
26
27
 
@@ -16,12 +16,17 @@ module Proxied
16
16
 
17
17
  def self.import(proxies)
18
18
  proxies.each do |proxy_item|
19
+ host = proxy_item[:host]&.to_s&.strip&.downcase
20
+ port = proxy_item[:port]&.to_s&.strip&.to_i
21
+ ip_address = proxy_item.fetch(:ip_address, host)&.to_s&.strip&.downcase
22
+
19
23
  query = {
20
- host: proxy_item[:host]&.to_s&.strip,
21
- port: proxy_item[:port]&.to_s&.strip&.to_i
24
+ host: host,
25
+ port: port
22
26
  }
23
27
 
24
28
  parsed = {
29
+ ip_address: ip_address,
25
30
  protocol: proxy_item.fetch(:protocol, "http")&.to_s&.strip&.downcase,
26
31
  proxy_type: proxy_item.fetch(:type, :private)&.to_s&.strip,
27
32
  category: proxy_item.fetch(:category, nil)&.to_s&.strip&.downcase,
@@ -1,3 +1,3 @@
1
1
  module Proxied
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxied
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-02 00:00:00.000000000 Z
11
+ date: 2019-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday