app/controllers/lookup_controller.rb in local_pac-0.9.0 vs app/controllers/lookup_controller.rb in local_pac-0.10.0
- old
+ new
@@ -1,19 +1,22 @@
module LocalPac
module App
class LookupController < ApplicationController
-
helpers Sinatra::Param
get '/' do
redirect to('/proxy.pac')
end
get '/:name' do
- file = local_storage.find(params[:name].to_s)
- fail Sinatra::NotFound, name: params[:name].to_s if file.nil?
+ param :name, String, required: true
+ name = translation_table.rewrite(env['REMOTE_ADDR'], params[:name])
+
+ file = local_storage.find(name)
+ fail Sinatra::NotFound, name: name if file.nil?
+
@client_ip = IPAddr.new(remote_addr).to_s
@time = Time.now.strftime "%Y-%m-%d %H:%M:%S"
haml :lookup, layout: :application
end
@@ -24,14 +27,15 @@
param :client_ip, String
param :time, String
parse_env = {}
- @file = local_storage.find(params[:name])
+ name = translation_table.rewrite(env['REMOTE_ADDR'], params[:name])
+ @file = local_storage.find(name)
@uri = Addressable::URI.heuristic_parse(params[:url])
- fail Sinatra::NotFound, name: params[:name].to_s if @file.nil?
+ fail Sinatra::NotFound, name: name if @file.nil?
fail Exceptions::GivenUrlInvalid, JSON.dump(url: params[:url]) if @uri.host.blank?
begin
parse_env[:time] = @time = Time.parse(params[:time]).to_s unless params[:time].blank?
rescue ArgumentError
@@ -48,10 +52,10 @@
parser = LocalPac::ProxyPac::PacParser.new(file: @file, environment: parse_env)
begin
@result = parser.find(@uri)
rescue Exceptions::PacFileInvalid
- raise Exceptions::PacFileInvalid, name: params[:name]
+ raise Exceptions::PacFileInvalid, name: name
end
haml :lookup_result, layout: :application
end