Sha256: 38642adb4d86b8b9858b840af7a782499764b39387e8a0578791ef15310669fa

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# ApplicationController just checks every incoming request according to the remote IP address.
#
# The request is sent to DocumentsController only if the IP is included in the white list.
# Otherwise, it returns "Access denied" 403.

class ApplicationController < ActionController::Base
  session :disabled => true
  before_filter :should_only_be_available_for_white_list_IPs, :except=> :access_denied

  # Returns 403 status in case of an unknown remote IP address
  def access_denied
    render :text=>"Access denied", :status => 403
  end

  # Redirects to documents_url in case route hasn't been recognised
  def unknown_request
    flash[:warning]="Unknown URL"
    redirect_to documents_url
  end

  private

  # Tries to match remote IP address with the white list defined in config/custom/white_list_ip.yml
  # Redirects to :access_denied if the remote IP is not white listed.
  def should_only_be_available_for_white_list_IPs
    unless request.remote_ip =~ Picolena::WhiteListIPs
      redirect_to :controller => 'application', :action=>'access_denied'
      return false
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
picolena-0.1.6 lib/picolena/templates/app/controllers/application.rb
picolena-0.1.7 lib/picolena/templates/app/controllers/application.rb
picolena-0.1.8 lib/picolena/templates/app/controllers/application.rb
picolena-0.2.0 lib/picolena/templates/app/controllers/application.rb
picolena-0.2.2 lib/picolena/templates/app/controllers/application.rb