proxy_controller.rb 843 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class ProxyController < ApplicationController
  3. prepend_before_action { authentication_check && authorize! }
  4. # POST /api/v1/proxy
  5. def test
  6. url = 'http://zammad.org'
  7. options = params
  8. .permit(:proxy, :proxy_username, :proxy_password, :proxy_no)
  9. .to_h
  10. options[:open_timeout] = 12
  11. options[:read_timeout] = 24
  12. begin
  13. result = UserAgent.get(
  14. url,
  15. {},
  16. options,
  17. )
  18. rescue => e
  19. render json: {
  20. result: 'failed',
  21. message: e.inspect
  22. }
  23. return
  24. end
  25. if result.success?
  26. render json: {
  27. result: 'success'
  28. }
  29. return
  30. end
  31. render json: {
  32. result: 'failed',
  33. message: result.body || result.error || result.code
  34. }
  35. end
  36. end