Note that there are some explanatory texts on larger screens.

plurals
  1. PORails routes and authentication?
    primarykey
    data
    text
    <p>I am working on a simple Intranet application, although there are some users, there is no requirement for the general staff to login. They should be able to visit the Intranet from any computer and access what they need without logging in.</p> <p>A number of our users are remote and they should be able to interact in the same way.</p> <p>What I am trying to achieve is the following; a list of IPs &amp; subnets that go straight to the root URL without logging in (admins can still login). Any visitor not on the list of whitelisted IPs &amp; subnets should see the static access denied page. On that page should be a login link. Once logged in they can interact with the Intranet just as they can if they are in our whitelisted subnet. Once they log out they see the access denied page again.</p> <p>I have the following code in my application controller:</p> <pre><code>class ApplicationController &lt; ActionController::Base before_filter :protect protect_from_forgery private def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] rescue ActiveRecord::RecordNotFound end helper_method :current_user def authorized? not current_user.nil? end def authorize redirect_to login_url, alert: "Not authorized" unless authorized? end def authorize_admin redirect_to login_url, alert: "Not authorized" unless authorized? &amp;&amp; current_user.admin? end def protect @ips = ['127.0.0.1','123.123.123.12','192.168.5.0/24'] allowed = false bremote_ip = 0 request.remote_ip.split('.').each { |x| bremote_ip = (bremote_ip &lt;&lt; 8) + x.to_i } @ips.each do |ipstring| ip, mask = ipstring.split '/' mask = mask ? mask.to_i : 32 bip = 0 ip.split('.').each { |x| bip = (bip &lt;&lt; 8) + x.to_i } bmask = ((1 &lt;&lt; mask) - 1) &lt;&lt; (32 - mask) if bip &amp; bmask == bremote_ip &amp; bmask allowed = true break end end if not allowed render :template =&gt; "static/protect", :layout =&gt; "static" return end end end </code></pre> <p>Any pointers on how to achieve this would be appreciated. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload