phantom_proxy 1.2.17 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -12
- data/.rbenv-gemsets +1 -0
- data/.ruby-version +1 -1
- data/Gemfile +2 -3
- data/LICENSE.txt +22 -0
- data/Rakefile +2 -0
- data/bin/phantom_proxy +45 -52
- data/lib/phantom_proxy/helper/http.rb +46 -0
- data/lib/phantom_proxy/helper/jsonizer.rb +46 -0
- data/lib/phantom_proxy/helper/logable.rb +36 -0
- data/lib/phantom_proxy/helper/status_info.rb +42 -0
- data/lib/phantom_proxy/helper/template_renderer.rb +43 -0
- data/lib/phantom_proxy/phantomjs/phantomjs.rb +105 -0
- data/lib/phantom_proxy/proxy/proxy_api.rb +86 -0
- data/lib/phantom_proxy/router/app_router.rb +72 -0
- data/lib/phantom_proxy/scripts/proxy.js +93 -93
- data/lib/phantom_proxy/service.rb +21 -0
- data/lib/phantom_proxy/status/status_api.rb +43 -0
- data/lib/phantom_proxy/version.rb +3 -0
- data/lib/phantom_proxy.rb +95 -12
- data/phantom_proxy.gemspec +27 -26
- data/templates/views/error_page.erb +18 -0
- data/templates/views/status_page.erb +46 -0
- metadata +139 -86
- data/lib/phantom_proxy/config.ru +0 -10
- data/lib/phantom_proxy/install/etc/init.d/phproxy +0 -193
- data/lib/phantom_proxy/install/etc/phantom_proxy/config/example_config +0 -3
- data/lib/phantom_proxy/phantomjs.rb +0 -106
- data/lib/phantom_proxy/phantomjs_control_panel.rb +0 -58
- data/lib/phantom_proxy/phantomjsserver.rb +0 -194
- data/lib/phantom_proxy/web/control_panel.html +0 -44
- data/spec/test +0 -2
- data/tmp/.keep +0 -0
- data/tmp/run +0 -5
@@ -1,194 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'hmac-md5'
|
3
|
-
require 'base64'
|
4
|
-
|
5
|
-
module PhantomJSProxy
|
6
|
-
class Options
|
7
|
-
def initialize(env)
|
8
|
-
@env = env
|
9
|
-
end
|
10
|
-
|
11
|
-
def picture?
|
12
|
-
@env['HTTP_GET_PAGE_AS_IMAGE']||false
|
13
|
-
end
|
14
|
-
|
15
|
-
def loadFrames?
|
16
|
-
@env['HTTP_GET_PAGE_WITH_IFRAMES']||true
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class PhantomJSServer
|
21
|
-
def initialize
|
22
|
-
@control_panel = PhantomJSProxy::PhantomJSControlPanel.new
|
23
|
-
|
24
|
-
#load key
|
25
|
-
@hmac_activated = false
|
26
|
-
@hmac = nil
|
27
|
-
if File.directory?("/tmp/phantom_proxy")
|
28
|
-
if File.exists?("/tmp/phantom_proxy/key")
|
29
|
-
key = File.open("/tmp/phantom_proxy/key", "r").read
|
30
|
-
#puts "HMAC_KEY: #{key}"
|
31
|
-
@hmac_activated = true
|
32
|
-
@hmac = HMAC::MD5.new key
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
attr_accessor :control_panel
|
38
|
-
attr_accessor :hmac
|
39
|
-
attr_accessor :hmac_activated
|
40
|
-
|
41
|
-
def check_for_route(url)
|
42
|
-
if /\.js/i.match(url) and !/\.jsp/i.match(url)
|
43
|
-
return 'text/html'
|
44
|
-
end
|
45
|
-
if /\.css/i.match(url)
|
46
|
-
return 'text/css'
|
47
|
-
end
|
48
|
-
if /\.png/i.match(url) or /\.jpg/i.match(url) or /\.jpeg/i.match(url) or /\.gif/i.match(url)
|
49
|
-
return 'image/*'
|
50
|
-
end
|
51
|
-
if /phantom_proxy_control_panel/.match(url)
|
52
|
-
return 'control_panel'
|
53
|
-
end
|
54
|
-
if /phantomProxy\.get/.match(url)
|
55
|
-
return "base64"
|
56
|
-
end
|
57
|
-
"none"
|
58
|
-
end
|
59
|
-
|
60
|
-
def route(env, type)
|
61
|
-
_req = Net::HTTP::Get.new(env['REQUEST_URI'])
|
62
|
-
|
63
|
-
_req['User-Agent'] = env['HTTP_USER_AGENT']
|
64
|
-
|
65
|
-
_res = Net::HTTP.start(env['HTTP_HOST'], env['SERVER_PORT']) {|http|
|
66
|
-
#http.request(_req)
|
67
|
-
http.get(env['REQUEST_URI'])
|
68
|
-
}
|
69
|
-
|
70
|
-
#env['rack.errors'].write("Response is:"+_res.body+"\n")
|
71
|
-
|
72
|
-
resp = Rack::Response.new([], 200, {'Content-Type' => type}) { |r|
|
73
|
-
r.write(_res.body)
|
74
|
-
}
|
75
|
-
resp.finish
|
76
|
-
end
|
77
|
-
|
78
|
-
def check_request_security req, env
|
79
|
-
if !env['HTTP_HMAC_KEY'] || !env['HTTP_HMAC_TIME']
|
80
|
-
return false
|
81
|
-
end
|
82
|
-
|
83
|
-
client_key = env['HTTP_HMAC_KEY']
|
84
|
-
client_time= Time.parse(env['HTTP_HMAC_TIME'])
|
85
|
-
remote_time= Time.now
|
86
|
-
remote_key = hmac.update(env['REQUEST_URI']+env['HTTP_HMAC_TIME']).hexdigest
|
87
|
-
|
88
|
-
if (client_key != remote_key || (remote_time-client_time).abs > 120)
|
89
|
-
control_panel.add_special_request "@did not pass security check"
|
90
|
-
return false
|
91
|
-
end
|
92
|
-
return true
|
93
|
-
end
|
94
|
-
|
95
|
-
def prepareUrl(env, params, req, https_request, type)
|
96
|
-
if type == "none"
|
97
|
-
url = env['REQUEST_URI']#req.url
|
98
|
-
puts "URL is: #{url}"
|
99
|
-
if https_request
|
100
|
-
url['http'] = 'https' if url['http']
|
101
|
-
url[':443'] = '' if url[':443']
|
102
|
-
end
|
103
|
-
|
104
|
-
if params.length > 0
|
105
|
-
url += '?'+params;
|
106
|
-
end
|
107
|
-
return url
|
108
|
-
end
|
109
|
-
url = Base64.decode64(req.params["address"])
|
110
|
-
env['rack.errors'].write("After Base64 decoding: "+url+"\n")
|
111
|
-
return url
|
112
|
-
end
|
113
|
-
|
114
|
-
def call(env)
|
115
|
-
control_panel.add_request
|
116
|
-
|
117
|
-
req = Rack::Request.new(env)
|
118
|
-
|
119
|
-
request_parameters = env.collect { |k, v| "\t#{k} : #{v}\n" }.join
|
120
|
-
env['rack.errors'].write("The request: "+req.url()+"\nGET: "+request_parameters+"\n")
|
121
|
-
|
122
|
-
if hmac_activated && hmac && !check_request_security(req, env)
|
123
|
-
resp = Rack::Response.new([], 503, {
|
124
|
-
'Content-Type' => 'text/html'
|
125
|
-
}) { |r|
|
126
|
-
r.write("Security ERROR")
|
127
|
-
}
|
128
|
-
return resp.finish
|
129
|
-
end
|
130
|
-
|
131
|
-
https_request = false
|
132
|
-
if /\:443/.match(req.url())
|
133
|
-
https_request = true
|
134
|
-
end
|
135
|
-
|
136
|
-
params = req.params.collect { |k, v| "#{k}=#{v}&" }.join
|
137
|
-
env['rack.errors'].write("Paramas: "+params+"\n")
|
138
|
-
|
139
|
-
#this routes the request to the outgoing server incase its not html that we want to load
|
140
|
-
type = check_for_route(env['REQUEST_URI'])#req.url
|
141
|
-
if type == "control_panel"
|
142
|
-
return control_panel.show()
|
143
|
-
elsif type != "none" and type != "base64"
|
144
|
-
control_panel.add_special_request "@forward_requests"
|
145
|
-
return route(env, type)
|
146
|
-
else
|
147
|
-
#Fetch the Webpage with PhantomJS
|
148
|
-
phJS = PhantomJS.new
|
149
|
-
|
150
|
-
env['rack.errors'].write("Extract the uri\n")
|
151
|
-
|
152
|
-
loadOptions = Options.new(env)
|
153
|
-
|
154
|
-
puts "Options: #{loadOptions.picture?}, #{loadOptions.loadFrames?}"
|
155
|
-
|
156
|
-
url = prepareUrl(env, params, req, https_request, type)
|
157
|
-
|
158
|
-
phJS.getUrl(url, loadOptions.picture?, loadOptions.loadFrames?)
|
159
|
-
|
160
|
-
#Create the response
|
161
|
-
if loadOptions.picture?
|
162
|
-
control_panel.add_special_request "@image_requests"
|
163
|
-
resp = Rack::Response.new([], 200, {
|
164
|
-
'Content-Type' => 'image/png'
|
165
|
-
}) { |r|
|
166
|
-
r.write(phJS.image)
|
167
|
-
}
|
168
|
-
resp.finish
|
169
|
-
elsif phJS.ready != 200
|
170
|
-
if !/favicon\.ico/.match(req.url())
|
171
|
-
env['rack.errors'].write("Request FAILED\n")
|
172
|
-
control_panel.add_special_request "@failed_requests"
|
173
|
-
else
|
174
|
-
control_panel.add_special_request "@favicon_requests"
|
175
|
-
end
|
176
|
-
resp = Rack::Response.new([], phJS.ready > 0 ? phJS.ready : 404 , {
|
177
|
-
'Content-Type' => 'text/html'
|
178
|
-
}) { |r|
|
179
|
-
r.write(phJS.dom)
|
180
|
-
}
|
181
|
-
resp.finish
|
182
|
-
else
|
183
|
-
control_panel.add_special_request "@html_requests"
|
184
|
-
resp = Rack::Response.new([], 200, {
|
185
|
-
'Content-Type' => 'text/html'
|
186
|
-
}) { |r|
|
187
|
-
r.write(phJS.dom)
|
188
|
-
}
|
189
|
-
resp.finish
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
@@ -1,44 +0,0 @@
|
|
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>
|
data/spec/test
DELETED
data/tmp/.keep
DELETED
File without changes
|