Add support for domain based ACLs
This commit is contained in:
parent
6ee672fe95
commit
cd43529cc8
6 changed files with 31 additions and 15 deletions
|
@ -163,7 +163,7 @@ class TraceController < ApplicationController
|
||||||
trace = Trace.find(params[:id])
|
trace = Trace.find(params[:id])
|
||||||
|
|
||||||
if trace.visible? and (trace.public? or (@user and @user == trace.user))
|
if trace.visible? and (trace.public? or (@user and @user == trace.user))
|
||||||
if Acl.address(request.remote_ip).where(:k => "no_trace_download").exists?
|
if Acl.match(request.remote_ip).where(:k => "no_trace_download").exists?
|
||||||
render :nothing => true, :status => :forbidden
|
render :nothing => true, :status => :forbidden
|
||||||
elsif request.format == Mime::XML
|
elsif request.format == Mime::XML
|
||||||
send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => Mime::XML.to_s, :disposition => 'attachment')
|
send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => Mime::XML.to_s, :disposition => 'attachment')
|
||||||
|
|
|
@ -38,6 +38,8 @@ class UserController < ApplicationController
|
||||||
else
|
else
|
||||||
render :action => 'terms'
|
render :action => 'terms'
|
||||||
end
|
end
|
||||||
|
elsif Acl.match(request.remote_ip, params[:user][:email].split("@").last).where(:k => "no_account_creation").exists?
|
||||||
|
render :action => 'blocked'
|
||||||
else
|
else
|
||||||
session[:referer] = params[:referer]
|
session[:referer] = params[:referer]
|
||||||
|
|
||||||
|
@ -79,9 +81,7 @@ class UserController < ApplicationController
|
||||||
def save
|
def save
|
||||||
@title = t 'user.new.title'
|
@title = t 'user.new.title'
|
||||||
|
|
||||||
if Acl.address(request.remote_ip).where(:k => "no_account_creation").exists?
|
if params[:decline]
|
||||||
render :action => 'new'
|
|
||||||
elsif params[:decline]
|
|
||||||
if @user
|
if @user
|
||||||
@user.terms_seen = true
|
@user.terms_seen = true
|
||||||
|
|
||||||
|
@ -112,6 +112,8 @@ class UserController < ApplicationController
|
||||||
else
|
else
|
||||||
redirect_to :action => :account, :display_name => @user.display_name
|
redirect_to :action => :account, :display_name => @user.display_name
|
||||||
end
|
end
|
||||||
|
elsif Acl.match(request.remote_ip, params[:user][:email].split("@").last).where(:k => "no_account_creation").exists?
|
||||||
|
render :action => 'blocked'
|
||||||
else
|
else
|
||||||
@user = User.new(params[:user])
|
@user = User.new(params[:user])
|
||||||
|
|
||||||
|
@ -269,6 +271,8 @@ class UserController < ApplicationController
|
||||||
:openid_url => params[:openid])
|
:openid_url => params[:openid])
|
||||||
|
|
||||||
flash.now[:notice] = t 'user.new.openid association'
|
flash.now[:notice] = t 'user.new.openid association'
|
||||||
|
elsif Acl.match(request.remote_ip).where(:k => "no_account_creation").exists?
|
||||||
|
render :action => 'blocked'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
class Acl < ActiveRecord::Base
|
class Acl < ActiveRecord::Base
|
||||||
scope :address, lambda { |address| where("address >> ?", address) }
|
def self.match(address, domain = nil)
|
||||||
|
if domain
|
||||||
|
condition = Acl.where("address >> ? OR domain = ?", address, domain)
|
||||||
|
else
|
||||||
|
condition = Acl.where("address >> ?", address)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
5
app/views/user/blocked.html.erb
Normal file
5
app/views/user/blocked.html.erb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<h1><%= t 'user.new.heading' %></h1>
|
||||||
|
|
||||||
|
<p><%= t 'user.new.no_auto_account_create' %></p>
|
||||||
|
|
||||||
|
<p><%= t 'user.new.contact_webmaster' %></p>
|
|
@ -1,13 +1,5 @@
|
||||||
<h1><%= t 'user.new.heading' %></h1>
|
<h1><%= t 'user.new.heading' %></h1>
|
||||||
|
|
||||||
<% if Acl.address(request.remote_ip).where(:k => "no_account_creation").exists? %>
|
|
||||||
|
|
||||||
<p><%= t 'user.new.no_auto_account_create' %></p>
|
|
||||||
|
|
||||||
<p><%= t 'user.new.contact_webmaster' %></p>
|
|
||||||
|
|
||||||
<% else %>
|
|
||||||
|
|
||||||
<p><%= t 'user.new.fill_form' %></p>
|
<p><%= t 'user.new.fill_form' %></p>
|
||||||
|
|
||||||
<%= error_messages_for 'user' %>
|
<%= error_messages_for 'user' %>
|
||||||
|
@ -102,5 +94,3 @@ enableOpenID();
|
||||||
disableOpenID();
|
disableOpenID();
|
||||||
<% end -%>
|
<% end -%>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<% end %>
|
|
||||||
|
|
11
db/migrate/20120208194454_add_domain_to_acl.rb
Normal file
11
db/migrate/20120208194454_add_domain_to_acl.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
class AddDomainToAcl < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
add_column :acls, :domain, :string
|
||||||
|
change_column :acls, :address, :inet, :null => true
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
change_column :acls, :address, :inet, :null => false
|
||||||
|
remove_column :acls, :domain
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue