hidemyass 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -31,8 +31,8 @@ Or install it yourself as:
31
31
  response
32
32
  => #<Net::HTTPOK 200 OK readbody=true>
33
33
 
34
- This method defaults to return on HTTPSuccess (2xx)
35
- If you want more control to follow redirections or whatever, you can retrieve the proxies list and connect manually
34
+ This method will try successive proxies until one returns HTTPSuccess (2xx).
35
+ If you want more control (e.g. to follow redirections), you can retrieve the proxies list and connect manually
36
36
 
37
37
  HideMyAss.proxies.each do |proxy|
38
38
  response = Net::HTTP::Proxy(proxy[:host], proxy[:port]).start(@uri.host, @uri.port) do |http|
@@ -58,15 +58,14 @@ or simply run:
58
58
 
59
59
  ## Roadmap
60
60
 
61
- * Improve the quality of returned proxies: currently I'm using the custom search url, but it seems to expire every n-days
62
- * Get proxies from other pages
61
+ * Get proxies from all pages
63
62
  * Improve tests suite
64
63
  * Clean code and refactor
65
64
 
66
65
  ## Contributing
67
66
 
68
67
  1. Fork it
69
- 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`), and make sure to include specs
70
69
  3. Commit your changes (`git commit -am 'Added some feature'`)
71
70
  4. Push to the branch (`git push origin my-new-feature`)
72
71
  5. Create new Pull Request
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "hidemyass"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = HideMyAss::VERSION
17
-
18
- gem.add_dependency "nokogiri", "~> 1.5.5"
19
- gem.add_development_dependency "rspec", "~> 2.12.0"
17
+
18
+ gem.add_dependency "nokogiri", "~> 1.5.6"
19
+ gem.add_development_dependency "rspec", "~> 2.13.0"
20
20
  end
@@ -15,53 +15,74 @@ module HideMyAss
15
15
  ENDPOINT = "http://hidemyass.com/proxy-list/".freeze
16
16
 
17
17
  LOG_PREFIX = '** [hidemyass] '
18
-
19
- HTTP_ERRORS = [Timeout::Error,
20
- Errno::EINVAL,
21
- Errno::ECONNRESET,
22
- Errno::ECONNREFUSED,
23
- Errno::ETIMEDOUT,
24
- EOFError,
25
- Net::HTTPBadResponse,
26
- Net::HTTPHeaderSyntaxError,
27
- Net::ProtocolError]
28
-
29
- def self.options
30
- @options ||= {
31
- :log => true,
32
- :local => false,
33
- :clear_cache => false
34
- }
35
- end
36
18
 
19
+ HTTP_ERRORS = [
20
+ Timeout::Error,
21
+ Errno::EINVAL,
22
+ Errno::ECONNRESET,
23
+ Errno::ECONNREFUSED,
24
+ Errno::ETIMEDOUT,
25
+ EOFError,
26
+ Net::HTTPBadResponse,
27
+ Net::HTTPHeaderSyntaxError,
28
+ Net::ProtocolError
29
+ ]
30
+
31
+ def self.options
32
+ @options ||= {
33
+ :log => true,
34
+ :local => false,
35
+ :clear_cache => false
36
+ }
37
+ end
38
+
39
+ # Clears cached proxies.
40
+ def self.clear_cache
41
+ @proxies = nil
42
+ end
43
+
44
+ # Returns HMA proxies.
37
45
  def self.proxies
38
46
  clear_cache if options[:clear_cache]
39
47
 
40
- unless @proxies
48
+ @proxies ||= begin
41
49
  html = get_hma_body
42
- end
43
50
 
44
- @proxies ||= html.xpath('//table[@id="listtable"]/tr').collect do |node|
45
- ip = HideMyAss::IP.new(node.at_xpath('td[2]/span'))
46
- next unless ip.valid?
47
- {
48
- host: ip.address,
49
- port: node.at_xpath('td[3]').content.strip
50
- }
51
+ html.xpath('//table[@id="listtable"]/tr').collect do |node|
52
+ ip = HideMyAss::IP.new(node.at_xpath('td[2]/span'))
53
+ next unless ip.valid?
54
+ {
55
+ host: ip.address,
56
+ port: node.at_xpath('td[3]').content.strip
57
+ }
58
+ end
51
59
  end
52
60
  end
53
-
54
- def self.clear_cache
55
- @proxies = nil
56
- end
57
61
 
58
- private
62
+ # Sets form data to support custom searches.
63
+ def self.form_data=(data)
64
+ @form_data = data if data
65
+ end
59
66
 
60
- def self.get_hma_body
61
- data = {
62
- "c[]" => ["United States"],
67
+ # Set form data for HMA search
68
+ #
69
+ # c[] - Countries
70
+ # p - Port. Defaults to all ports.
71
+ # pr[] - Protocol. 0..2 = HTTP, HTTPS, socks4/5
72
+ # a[] - Anonymity level. 0..4 = None, Low, Medium, High, High +KA
73
+ # sp[] - Speed. 0..2 = Slow, Medium, Fast.
74
+ # ct[] - Connection time. 0..2 = Slow, Medium, Fast
75
+ # s - Sort. 0..3 = Response time, Connection time, Country A-Z.
76
+ # o - Order. 0, 1 = DESC, ASC.
77
+ # pp - Per Page. 0..3 = 10, 25, 50, 100.
78
+ # sortBy - Sort by. Defaults to date.
79
+ #
80
+ # Returns form data hash.
81
+ def self.form_data
82
+ @form_data ||= {
83
+ "c[]" => ["Brazil", "Mexico", "United States"],
63
84
  "p" => nil,
64
- "pr[]" => [0,1,2],
85
+ "pr[]" => [0,1],
65
86
  "a[]" => [0,1,2,3],
66
87
  "sp[]" => [2,3],
67
88
  "ct[]" => [2,3],
@@ -70,8 +91,13 @@ module HideMyAss
70
91
  "pp" => 2,
71
92
  "sortBy" => "date"
72
93
  }
94
+ end
95
+
96
+ private
73
97
 
74
- res = Net::HTTP.post_form(URI(ENDPOINT), data)
98
+ # Returns HMA body as a Nokogiri HTML Document.
99
+ def self.get_hma_body
100
+ res = Net::HTTP.post_form(URI(ENDPOINT), form_data)
75
101
 
76
102
  body = case res
77
103
  when Net::HTTPSuccess then
@@ -1,13 +1,19 @@
1
+ # TODO: Hijack HTTP calls automatically
2
+
1
3
  module HideMyAss
2
4
  module HTTP
5
+
3
6
  def HTTP.start(address, *arg, &block)
4
7
  HideMyAss.log 'Connecting to ' + address + ' through:'
5
8
  response = nil
6
-
9
+
7
10
  if HideMyAss.options[:local]
8
11
  begin
9
12
  HideMyAss.log 'localhost...'
10
13
  response = Net::HTTP.start(address, *arg, &block)
14
+
15
+ HideMyAss.log response.class.to_s
16
+
11
17
  if response.class.ancestors.include?(Net::HTTPSuccess)
12
18
  return response
13
19
  end
@@ -15,12 +21,15 @@ module HideMyAss
15
21
  HideMyAss.log error
16
22
  end
17
23
  end
18
-
24
+
19
25
  HideMyAss.proxies.each do |proxy|
20
26
  begin
21
27
  HideMyAss.log proxy[:host] + ':' + proxy[:port]
22
- response = Net::HTTP::Proxy(proxy[:host], proxy[:port]).start(address, *arg, &block)
28
+ response = Net::HTTP::Proxy(proxy[:host],
29
+ proxy[:port]).start(address, *arg, &block)
30
+
23
31
  HideMyAss.log response.class.to_s
32
+
24
33
  if response.class.ancestors.include?(Net::HTTPSuccess)
25
34
  return response
26
35
  end
@@ -1,19 +1,33 @@
1
+ # HideMyAss masks real IPs with CSS classes
2
+ # in order to prevent crawlers from grabbing them.
3
+ #
4
+ # Here we emulate what our browser does
5
+ # so we can get the real IP addresses.
6
+
1
7
  module HideMyAss
2
8
  class IP
3
-
4
9
  attr_accessor :decoys, :address
5
-
10
+
6
11
  VALID_TAGS = %w(span div text).freeze
7
-
12
+
8
13
  def initialize(encoded_address)
9
- @decoys = encoded_address.css("style").text.split("\n").select {|style| style =~ /none/}
14
+ # Select decoy CSS classes: those which result in a hidden element
15
+ @decoys = encoded_address.css("style").text.split("\n").
16
+ select {|style| style =~ /none/}
17
+
18
+ # Find enclosing IP elements
10
19
  elements = encoded_address.children
20
+
21
+ # Process elements and get rid of those with decoy classes
11
22
  decode(elements)
23
+
24
+ # Finally grab enclosing elements content, which is the real IP
12
25
  @address = elements.map(&:content).join
13
-
14
26
  self
15
27
  end
16
-
28
+
29
+ # Receives an array of elements
30
+ # and removes those that are invisible.
17
31
  def decode(elements)
18
32
  elements.each do |element|
19
33
  if !VALID_TAGS.include?(element.name) || (element["style"] && element["style"] =~ /none/)
@@ -23,14 +37,15 @@ module HideMyAss
23
37
  end
24
38
  end
25
39
  end
26
-
40
+
41
+ # Make sure the IP has a valid format.
27
42
  def valid?
28
43
  address.split(".").reject(&:empty?).size == 4
29
44
  end
30
-
45
+
31
46
  def inspect
32
47
  "#<#{self.class}> @address=#{address}>"
33
48
  end
34
-
49
+
35
50
  end # IP
36
51
  end # HideMyAss
@@ -1,3 +1,3 @@
1
1
  module HideMyAss
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hidemyass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-30 00:00:00.000000000 Z
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.5.5
21
+ version: 1.5.6
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.5.5
29
+ version: 1.5.6
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 2.12.0
37
+ version: 2.13.0
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.12.0
45
+ version: 2.13.0
46
46
  description: Hide My Ass! fetches and connects to proxies at www.hidemyass.com
47
47
  email:
48
48
  - javier@tractical.com