phantom_proxy 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -33,5 +33,12 @@ Point your browser's proxy to http://localhost:8080 for testting.
|
|
33
33
|
|
34
34
|
You can use the Net::HTTP lib to fetch page or use the phantom_client
|
35
35
|
(see: https://github.com/experteer/phantom_client).
|
36
|
+
|
37
|
+
Monitoring(1.1.0):
|
38
|
+
The phantom_proxy comes with a usage monitor.
|
39
|
+
You can see the current proxy status by pointing your browser to
|
40
|
+
phantom_proxy_control_panel
|
41
|
+
if you have set the proxy or just to the address and port the proxy is running at
|
42
|
+
address:port/phantom_proxy_control_panel
|
36
43
|
|
37
44
|
== TODO
|
data/lib/phantom_proxy.rb
CHANGED
@@ -3,8 +3,10 @@ require 'rubygems'
|
|
3
3
|
module PhantomJSProxy
|
4
4
|
ROOT = File.expand_path(File.dirname(__FILE__))
|
5
5
|
SCRIPT = ROOT+"/phantom_proxy/scripts/proxy.js"
|
6
|
+
CONTROL_PANEL = ROOT+"/phantom_proxy/web/control_panel.html"
|
6
7
|
PHANTOMJS_BIN = ROOT+'/../bin/phantomjs'
|
7
8
|
end
|
8
9
|
|
9
10
|
require PhantomJSProxy::ROOT+'/phantom_proxy/phantomjs.rb'
|
10
|
-
require PhantomJSProxy::ROOT+'/phantom_proxy/phantomjsserver.rb'
|
11
|
+
require PhantomJSProxy::ROOT+'/phantom_proxy/phantomjsserver.rb'
|
12
|
+
require PhantomJSProxy::ROOT+'/phantom_proxy/phantomjs_control_panel.rb'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module PhantomJSProxy
|
2
|
+
class PhantomJSControlPanel
|
3
|
+
def initialize
|
4
|
+
@start_time = Time.new
|
5
|
+
@total_requests = 0
|
6
|
+
@special_requests = Hash.new
|
7
|
+
@special_requests.default = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :start_time
|
11
|
+
|
12
|
+
attr_accessor :total_requests
|
13
|
+
attr_accessor :route_requests
|
14
|
+
attr_accessor :html_requests
|
15
|
+
attr_accessor :picture_requests
|
16
|
+
attr_accessor :special_requests
|
17
|
+
|
18
|
+
def show
|
19
|
+
add_special_request "@control_requests"
|
20
|
+
|
21
|
+
resp = Rack::Response.new([], 200, {
|
22
|
+
'Content-Type' => 'text/html'
|
23
|
+
}) { |r|
|
24
|
+
r.write(load_html)
|
25
|
+
}
|
26
|
+
resp.finish
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_request
|
30
|
+
@total_requests = @total_requests+1
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_special_request type
|
34
|
+
@special_requests[type] = @special_requests[type]+1
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def load_html
|
39
|
+
insert_value IO.read(CONTROL_PANEL)
|
40
|
+
end
|
41
|
+
|
42
|
+
def insert_value html
|
43
|
+
info_data = ""
|
44
|
+
info_data << create_entry("Running since", start_time.ctime)
|
45
|
+
info_data << create_entry("Total requests", total_requests.to_s)
|
46
|
+
special_requests.each { |key, value|
|
47
|
+
info_data << create_entry(key, special_requests[key].to_s)
|
48
|
+
}
|
49
|
+
html["@control_panel_data"] = info_data
|
50
|
+
|
51
|
+
html
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_entry name, value
|
55
|
+
"<div class='name'>#{name}:</div><div class='value' id='#{name}'>#{value}</div><div class='divider'></div>"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -3,7 +3,10 @@ require 'net/http'
|
|
3
3
|
module PhantomJSProxy
|
4
4
|
class PhantomJSServer
|
5
5
|
def initialize()
|
6
|
+
@control_panel = PhantomJSProxy::PhantomJSControlPanel.new
|
6
7
|
end
|
8
|
+
|
9
|
+
attr_accessor :control_panel
|
7
10
|
|
8
11
|
def check_for_route(url)
|
9
12
|
if /\.js/i.match(url)
|
@@ -15,6 +18,9 @@ module PhantomJSProxy
|
|
15
18
|
if /\.png/i.match(url) or /\.jpg/i.match(url) or /\.jpeg/i.match(url) or /\.gif/i.match(url)
|
16
19
|
return 'image/*';
|
17
20
|
end
|
21
|
+
if /phantom_proxy_control_panel/.match(url)
|
22
|
+
return 'control_panel'
|
23
|
+
end
|
18
24
|
"none"
|
19
25
|
end
|
20
26
|
|
@@ -37,6 +43,8 @@ module PhantomJSProxy
|
|
37
43
|
end
|
38
44
|
|
39
45
|
def call(env)
|
46
|
+
control_panel.add_request
|
47
|
+
|
40
48
|
req = Rack::Request.new(env)
|
41
49
|
|
42
50
|
haha = env.collect { |k, v| "#{k} : #{v}\n" }.join
|
@@ -47,58 +55,68 @@ module PhantomJSProxy
|
|
47
55
|
|
48
56
|
#this routes the request to the outgoing server incase its not html that we want to load
|
49
57
|
type = check_for_route(env['REQUEST_URI'])
|
50
|
-
if type
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
if type == "control_panel"
|
59
|
+
return control_panel.show()
|
60
|
+
elsif type != "none"
|
61
|
+
control_panel.add_special_request "@forward_requests"
|
62
|
+
return route(env, type)
|
63
|
+
else
|
64
|
+
#Fetch the Webpage with PhantomJS
|
65
|
+
phJS = PhantomJS.new
|
66
|
+
|
67
|
+
env['rack.errors'].write("Extract the uri\n")
|
68
|
+
|
69
|
+
if defined? env['HTTP_GET_PAGE_AS_IMAGE']
|
70
|
+
picture = env['HTTP_GET_PAGE_AS_IMAGE']
|
71
|
+
else
|
72
|
+
picture = true
|
73
|
+
end
|
74
|
+
|
75
|
+
if defined? env['HTTP_GET_PAGE_WITH_IFRAMES']
|
76
|
+
loadFrames = env['HTTP_GET_PAGE_WITH_IFRAMES']
|
77
|
+
else
|
78
|
+
loadFrames = false
|
79
|
+
end
|
80
|
+
|
81
|
+
url = env['REQUEST_URI'];
|
82
|
+
if params.length > 0
|
83
|
+
url += '?'+params;
|
84
|
+
end
|
85
|
+
|
86
|
+
phJS.getUrl(url, picture, loadFrames)
|
87
|
+
|
88
|
+
#Create the response
|
89
|
+
if !phJS.ready
|
90
|
+
if !/favicon\.ico/.match(req.url())
|
91
|
+
env['rack.errors'].write("Request FAILED\n")
|
92
|
+
control_panel.add_special_request "@failed_requests"
|
93
|
+
else
|
94
|
+
control_panel.add_special_request "@favicon_requests"
|
95
|
+
end
|
96
|
+
resp = Rack::Response.new([], 503, {
|
97
|
+
'Content-Type' => 'text/html'
|
98
|
+
}) { |r|
|
99
|
+
r.write(phJS.dom)
|
100
|
+
}
|
101
|
+
resp.finish
|
102
|
+
elsif picture
|
103
|
+
control_panel.add_special_request "@image_requests"
|
104
|
+
resp = Rack::Response.new([], 200, {
|
105
|
+
'Content-Type' => 'image/png'
|
106
|
+
}) { |r|
|
107
|
+
r.write(phJS.image)
|
108
|
+
}
|
109
|
+
resp.finish
|
110
|
+
else
|
111
|
+
control_panel.add_special_request "@html_requests"
|
112
|
+
resp = Rack::Response.new([], 200, {
|
113
|
+
'Content-Type' => 'text/html'
|
114
|
+
}) { |r|
|
115
|
+
r.write(phJS.dom)
|
116
|
+
}
|
117
|
+
resp.finish
|
118
|
+
end
|
64
119
|
end
|
65
|
-
|
66
|
-
if defined? env['HTTP_GET_PAGE_WITH_IFRAMES']
|
67
|
-
loadFrames = env['HTTP_GET_PAGE_WITH_IFRAMES']
|
68
|
-
else
|
69
|
-
loadFrames = false
|
70
|
-
end
|
71
|
-
|
72
|
-
url = env['REQUEST_URI'];
|
73
|
-
if params.length > 0
|
74
|
-
url += '?'+params;
|
75
|
-
end
|
76
|
-
|
77
|
-
phJS.getUrl(url, picture, loadFrames)
|
78
|
-
|
79
|
-
#Create the response
|
80
|
-
if !phJS.ready
|
81
|
-
resp = Rack::Response.new([], 503, {
|
82
|
-
'Content-Type' => 'text/html'
|
83
|
-
}) { |r|
|
84
|
-
r.write(phJS.dom)
|
85
|
-
}
|
86
|
-
resp.finish
|
87
|
-
elsif picture
|
88
|
-
resp = Rack::Response.new([], 200, {
|
89
|
-
'Content-Type' => 'image/png'
|
90
|
-
}) { |r|
|
91
|
-
r.write(phJS.image)
|
92
|
-
}
|
93
|
-
resp.finish
|
94
|
-
else
|
95
|
-
resp = Rack::Response.new([], 200, {
|
96
|
-
'Content-Type' => 'text/html'
|
97
|
-
}) { |r|
|
98
|
-
r.write(phJS.dom)
|
99
|
-
}
|
100
|
-
resp.finish
|
101
|
-
end
|
102
120
|
end
|
103
121
|
end
|
104
122
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Phantom Proxy Control</title>
|
4
|
+
<style>
|
5
|
+
h1 {
|
6
|
+
text-align: center;
|
7
|
+
}
|
8
|
+
h4 {
|
9
|
+
text-align: center;
|
10
|
+
position: relative;
|
11
|
+
top: -20px;
|
12
|
+
}
|
13
|
+
.infobox {
|
14
|
+
width: 800px;
|
15
|
+
margin-left: auto;
|
16
|
+
margin-right: auto;
|
17
|
+
}
|
18
|
+
.name {
|
19
|
+
float: left;
|
20
|
+
}
|
21
|
+
.value {
|
22
|
+
float: right;
|
23
|
+
margin-bottom: 10px;
|
24
|
+
}
|
25
|
+
.divider {
|
26
|
+
background-color: black;
|
27
|
+
height: 1px;
|
28
|
+
width: 700px;
|
29
|
+
margin-bottom: 10px;
|
30
|
+
margin-left: auto;
|
31
|
+
margin-right: auto;
|
32
|
+
clear: left;
|
33
|
+
clear: right;
|
34
|
+
}
|
35
|
+
</style>
|
36
|
+
</head>
|
37
|
+
<body>
|
38
|
+
<h1>Phantom Proxy</h1>
|
39
|
+
<h4>Control Panel</h4>
|
40
|
+
<div class="infobox" id="infobox">
|
41
|
+
@control_panel_data
|
42
|
+
</div>
|
43
|
+
</body>
|
44
|
+
</html>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantom_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
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
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|
@@ -36,10 +36,12 @@ extensions: []
|
|
36
36
|
extra_rdoc_files: []
|
37
37
|
files:
|
38
38
|
- lib/phantom_proxy/phantomjsserver.rb
|
39
|
+
- lib/phantom_proxy/phantomjs_control_panel.rb
|
39
40
|
- lib/phantom_proxy/phantomjs.rb
|
40
41
|
- lib/phantom_proxy.rb
|
41
42
|
- lib/phantom_proxy/scripts/proxy.js
|
42
43
|
- lib/phantom_proxy/config.ru
|
44
|
+
- lib/phantom_proxy/web/control_panel.html
|
43
45
|
- bin/phantom_proxy
|
44
46
|
- bin/phantomjs
|
45
47
|
- README.rdoc
|