diff --git a/app/controllers/api/v1/contact_controller.rb b/app/controllers/api/v1/contact_controller.rb index 419c20d6..3b24ba73 100644 --- a/app/controllers/api/v1/contact_controller.rb +++ b/app/controllers/api/v1/contact_controller.rb @@ -83,9 +83,13 @@ module Api head :precondition_required if site.nil? end - # Comprueba que el mensaje vino fue enviado desde el sitio + # Comprueba que el mensaje fue enviado desde el sitio o uno + # de los sitios permitidos. + # + # XXX: Este header se puede falsificar de todas formas pero al + # menos es una trampa. def site_is_origin? - return if origin.to_s.start_with? site.url(slash: false) + return if site.urls(slash: false).any? { |u| origin.to_s.start_with? u } head :precondition_required end diff --git a/app/models/site.rb b/app/models/site.rb index bdba0f73..eb47398d 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -83,13 +83,34 @@ class Site < ApplicationRecord # @param slash Boolean Agregar / al final o no # @return String La URL con o sin / al final def url(slash: true) - if slash - 'https://' + hostname + '/' - else - 'https://' + hostname + 'https://' + hostname + (slash ? '/' : '') + end + + # Obtiene los dominios alternativos + # + # @return Array + def alternative_hostnames + deploys.where(type: 'DeployAlternativeDomain').map(&:hostname).map do |h| + h.end_with?('.') ? h[0..-2] : h + '.' + Site.domain end end + # Obtiene todas las URLs alternativas para este sitio + # + # @return Array + def alternative_urls(slash: true) + alternative_hostnames.map do |h| + 'https://' + h + (slash ? '/' : '') + end + end + + # Todas las URLs posibles para este sitio + # + # @return Array + def urls(slash: true) + alternative_urls << url(slash: slash) + end + def invitade?(usuarie) !invitades.where(id: usuarie).empty? end @@ -113,15 +134,6 @@ class Site < ApplicationRecord File.join(Site.site_path, name_was) end - def cover - "/covers/#{name}.png" - end - - # Define si el sitio tiene un glosario - def glossary? - config.fetch('glossary', false) - end - # Obtiene la lista de traducciones actuales # # Siempre tiene que tener algo porque las traducciones están