phantom_client 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -15,11 +15,14 @@ Usage example:
15
15
  require 'phantom_client'
16
16
 
17
17
  client = PhantomJSProxy::PhantomJSClient.new([{:addr => "127.0.0.1", :port => 5000}])
18
- dom = client.get("http://foo.de/", {:imageOnly => false, :withIframes => true})
18
+ dom = client.get("http://foo.de/", {:imageOnly => false, :withIframes => true}, "hmac_key")
19
19
 
20
20
  or in the bash
21
21
 
22
- phantom_client http://foo.de/ [proxy_ip:port []]
22
+ phantom_client http://foo.de/ [proxy_ip:port []] [-hmac key]
23
+
24
+ == Features
25
+ Supports an security algorithm which if activated on the server has to supplied by the client otherwise the request is denied
23
26
 
24
27
  == TODO
25
28
  * nicer API
data/bin/phantom_client CHANGED
@@ -5,21 +5,25 @@ require 'phantom_client'
5
5
 
6
6
  url = nil
7
7
  proxy_list = []
8
-
8
+ last_arg = nil
9
+ hmac_key = nil
9
10
  ARGV.each{ |arg|
10
11
  if url == nil
11
12
  url = arg
13
+ elsif /-hmac/.match(last_arg)
14
+ hmac_key = arg
12
15
  else
13
16
  newE = {}
14
17
  newE[:addr] = arg.split(':')[0]
15
18
  newE[:port] = arg.split(':')[1]
16
19
  proxy_list.push newE
17
20
  end
21
+ last_arg = arg
18
22
  }
19
23
 
20
24
  if url == nil
21
25
  return
22
26
  end
23
27
 
24
- client = PhantomJSProxy::PhantomJSClient.new(proxy_list)
25
- puts client.get(url, {:imageOnly => false, :withIframes => true})
28
+ client = PhantomJSProxy::PhantomJSClient.new(proxy_list, PhantomJSProxy::PhantomJSClientConnection.new, hmac_key)
29
+ puts client.get_body(url, {:imageOnly => false, :withIframes => true})
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'uri'
3
+ require 'hmac-md5'
3
4
 
4
5
  module PhantomJSProxy
5
6
  class DummyResponse
@@ -12,10 +13,15 @@ module PhantomJSProxy
12
13
  attr_accessor :proxy_port
13
14
  attr_accessor :proxy_list
14
15
  attr_accessor :connection
16
+ attr_accessor :hmac
17
+ attr_accessor :hmac_activated
15
18
 
16
- def initialize(addr_list=[], con = PhantomJSClientConnection.new)
19
+ def initialize(addr_list=[], con = PhantomJSClientConnection.new, key=nil)
17
20
  @proxy_list = addr_list
18
21
  @connection = con
22
+ @hmac_activated = key ? true : false
23
+ @hmac = HMAC::MD5.new key
24
+ puts "Using #{key} as HMAC key"
19
25
  end
20
26
 
21
27
  def get_body(addr, options=nil)
@@ -39,6 +45,13 @@ module PhantomJSProxy
39
45
  req['Get-Page-With-IFrames'] = options['withIframes']
40
46
  puts "Do fetch iframes"
41
47
  end
48
+
49
+ if hmac_activated
50
+ t = Time.now
51
+ req['Hmac-Key'] = hmac.update(addr+t.to_s).hexdigest
52
+ req['Hmac-Time'] = t
53
+ puts "Encode: #{addr} to #{req['Hmac-Key']}"
54
+ end
42
55
  #::Proxy(@proxy_addr, @proxy_port)
43
56
 
44
57
  #element = get_proxy()
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phantom_client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Sudmann
@@ -15,10 +15,25 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-19 00:00:00 +02:00
18
+ date: 2012-05-02 00:00:00 +02:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: ruby-hmac
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 0
32
+ - 4
33
+ - 0
34
+ version: 0.4.0
35
+ type: :runtime
36
+ version_requirements: *id001
22
37
  description: This is a phantomjs Proxy client
23
38
  email: suddani@googlemail.com
24
39
  executables: