2017-01-16 00:24:56 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class ProxyController < ApplicationController
|
2020-03-19 09:39:51 +00:00
|
|
|
prepend_before_action { authentication_check && authorize! }
|
2017-01-16 00:24:56 +00:00
|
|
|
|
|
|
|
# POST /api/v1/proxy
|
|
|
|
def test
|
|
|
|
url = 'http://zammad.org'
|
|
|
|
options = params
|
2021-03-03 09:54:59 +00:00
|
|
|
.permit(:proxy, :proxy_username, :proxy_password, :proxy_no)
|
|
|
|
.to_h
|
2017-01-16 00:24:56 +00:00
|
|
|
options[:open_timeout] = 12
|
|
|
|
options[:read_timeout] = 24
|
|
|
|
begin
|
|
|
|
result = UserAgent.get(
|
|
|
|
url,
|
|
|
|
{},
|
|
|
|
options,
|
|
|
|
)
|
|
|
|
rescue => e
|
|
|
|
render json: {
|
2018-12-19 17:31:51 +00:00
|
|
|
result: 'failed',
|
2017-01-16 00:24:56 +00:00
|
|
|
message: e.inspect
|
|
|
|
}
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if result.success?
|
|
|
|
render json: {
|
|
|
|
result: 'success'
|
|
|
|
}
|
|
|
|
return
|
|
|
|
end
|
|
|
|
render json: {
|
2018-12-19 17:31:51 +00:00
|
|
|
result: 'failed',
|
2017-01-16 00:24:56 +00:00
|
|
|
message: result.body || result.error || result.code
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|