-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.fix.rb
More file actions
29 lines (28 loc) · 835 Bytes
/
app.fix.rb
File metadata and controls
29 lines (28 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'roda'
require 'uri'
require 'net/http'
class App < Roda
route do |r|
r.get 'local' do
addr = r.ip # safer than parsing HTTP headers
addr = "http://#{addr}"
parsed_addr = URI.parse(addr)
if parsed_addr.host == '127.0.0.1'
safe_addr = parsed_addr.dup # always use the same method to process the data that was used in the security check
safe_addr.path = '/login'
data = {user: 'admin', pass: 'AJMMbzLckY37'}
begin
Net::HTTP.post_form(safe_addr, data)
rescue Errno::ECONNREFUSED => e
puts e.message
ensure
response.status = 200
response.write 'Service proceeded'
end
else
response.status = 403
response.write "Not authorized from your address: #{addr}"
end
end
end
end