2020-07-29 11:19:20 +02:00
|
|
|
require 'net/http'
|
|
|
|
|
|
|
|
class LinksController < ApplicationController
|
|
|
|
def show
|
|
|
|
link = Link.find(params[:id])
|
|
|
|
url = link.url
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
return deny_access if link.workgroup && !current_user.role_admin? && !link.workgroup.member?(current_user)
|
2020-07-29 11:19:20 +02:00
|
|
|
|
|
|
|
if link.indirect
|
|
|
|
uri = URI.parse url
|
|
|
|
request = Net::HTTP::Get.new uri
|
|
|
|
request['Authorization'] = link.authorization if link.authorization
|
|
|
|
result = Net::HTTP.start uri.host, uri.port, use_ssl: uri.scheme == 'https' do |http|
|
|
|
|
http.request request
|
|
|
|
end
|
|
|
|
|
|
|
|
url = result.header['Location']
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
return redirect_to root_url, alert: t('.indirect_no_location') unless url
|
2020-07-29 11:19:20 +02:00
|
|
|
end
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
redirect_to url, status: :found
|
2020-07-29 11:19:20 +02:00
|
|
|
end
|
|
|
|
end
|