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