Sha256: 3e3581ba3b27a3d33bdf3d4a3408b35d8fda43442a8eda624b18125f28509e62

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

module RailsConnector

  class PdfExternalController < ApplicationController
    skip_before_filter :verify_authenticity_token
    before_filter :validate_inputs

    def index
      send_file(
        FopOnRails.generate_pdf(
          params[:xml_url],
          params[:xsl_url],
          params[:tidy]
        ),
        :filename => "#{params[:filename] || 'output'}.pdf",
        :type => 'application/pdf'
      )
    end

    private

    def validate_inputs
      validate_input('xml', params['xml_url'])
      validate_input('xsl', params['xsl_url'])
      validate_hosts
    end

    def validate_input(type, url)
      unless url and valid_url?(url)
        raise "Invalid #{type} input URL: #{url || 'empty'}"
      end
    end

    def valid_url?(url)
      begin
        URI.parse(url)
      rescue URI::InvalidURIError
        return false
      end
      true
    end

    def validate_hosts
      xml_host, xsl_host = URI.parse(params['xml_url']).host, URI.parse(params['xsl_url']).host
      bad_host = [xml_host, xsl_host].detect do |host|
        !Configuration::PdfGenerator.host_allowed?(host)
      end
      if bad_host
        render(
          :status => 403,
          :text => I18n.t(:"rails_connector.controllers.pdf_external.host_not_allowed", :host => bad_host)
        )
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
infopark_rails_connector-6.8.0.515.34928522 app/controllers/rails_connector/pdf_external_controller.rb
infopark_rails_connector-6.8.0.498.46559598 app/controllers/rails_connector/pdf_external_controller.rb
infopark_rails_connector-6.8.0.480.261594408 app/controllers/rails_connector/pdf_external_controller.rb
infopark_rails_connector-6.8.0.444.171626367 app/controllers/rails_connector/pdf_external_controller.rb
infopark_rails_connector-6.8.0.406.131718077 app/controllers/rails_connector/pdf_external_controller.rb
infopark_rails_connector-6.8.0.356.19698103 app/controllers/rails_connector/pdf_external_controller.rb
infopark_rails_connector-6.8.0.348.160665197 app/controllers/rails_connector/pdf_external_controller.rb
infopark_rails_connector-6.8.0.328.4a753fc app/controllers/rails_connector/pdf_external_controller.rb
infopark_rails_connector-6.8.0.322.c003f11 app/controllers/rails_connector/pdf_external_controller.rb