proxied 0.2.0 → 0.2.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/lib/generators/active_record/proxied_generator.rb +19 -18
- data/lib/generators/active_record/templates/migration.rb +1 -0
- data/lib/generators/mongoid/proxied_generator.rb +1 -0
- data/lib/generators/templates/proxied.rb +13 -0
- data/lib/proxied/checker.rb +2 -2
- data/lib/proxied/configuration.rb +1 -0
- data/lib/proxied/importer.rb +7 -2
- data/lib/proxied/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 259fa06faa16224529c74da60047158116d019a7017972887cd9c91228f854b4
|
4
|
+
data.tar.gz: a9a83e6416cc5db560e4b3d90129eabc7e0c55aeea4150bba155f482957091bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
23
|
+
content = model_contents
|
24
24
|
|
25
|
-
class_path
|
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
|
32
|
-
content
|
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
|
44
|
-
Rails.version.
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
def migration_version
|
53
|
+
if should_version_migration?
|
54
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
55
|
+
end
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
def primary_key_type
|
59
|
+
primary_key_string if should_version_migration?
|
60
|
+
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
@@ -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
|
data/lib/proxied/checker.rb
CHANGED
@@ -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 =
|
74
|
+
valid_proxy = evaluate.call(proxy, response)
|
75
75
|
|
76
76
|
update_proxy(proxy, valid_proxy) if update
|
77
77
|
|
data/lib/proxied/importer.rb
CHANGED
@@ -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:
|
21
|
-
port:
|
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,
|
data/lib/proxied/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2019-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|