robots_txt_controller.rb 819 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class RobotsTxtController < ApplicationController
  3. helper_method :custom_address_uri, :custom_path?, :custom_domain_path?
  4. def index
  5. render layout: false, content_type: 'text/plain'
  6. end
  7. private
  8. def knowledge_base
  9. @knowledge_base ||= KnowledgeBase.active.first
  10. end
  11. def custom_address_uri
  12. @custom_address_uri ||= knowledge_base&.custom_address_uri
  13. end
  14. def custom_address_host
  15. custom_address_uri&.host
  16. end
  17. def custom_path?
  18. custom_address_uri && custom_address_host.blank?
  19. end
  20. def custom_domain_path?
  21. return false if custom_address_uri.blank?
  22. given_fqdn = request.headers.env['SERVER_NAME']&.downcase
  23. kb_fqdn = custom_address_host&.downcase
  24. given_fqdn == kb_fqdn
  25. end
  26. end