Restrict admin area to IPs

27 vistas
Ir al primer mensaje no leído

Thorsten Kohpeiß

no leída,
23 oct 2014, 3:53:33 a.m.23/10/14
para alche...@googlegroups.com
Hi,

how can I restrict the access to the admin area based on IP addresses?

Thanx.

Regards Thorsten

Thomas von Deyen

no leída,
23 oct 2014, 4:21:28 a.m.23/10/14
para alche...@googlegroups.com

Thorsten Kohpeiß

no leída,
23 oct 2014, 5:06:32 a.m.23/10/14
para alche...@googlegroups.com
Forgot to mention: its hosted at heroku.

Regards Thorsten

Thomas von Deyen

no leída,
23 oct 2014, 5:33:39 a.m.23/10/14
para alche...@googlegroups.com
Ok, then you need to patch the Alchemy::Admin::BaseController

Caution, Pseudo Code ;)

# config/initializers/secure_alchemy_backend.rb
Alchemy::Admin::BaseController.class_eval do
before_action {
if request.ip != '1.2.3.4'
return && redirect_to(root_url, message: 'You are not allowed to access this url')
end
}
end

Maybe you need `request.remote_ip`, don't know.

best

t
> --
> You received this message because you are subscribed to the Google Groups "Alchemy CMS" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to alchemy-cms...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Thorsten Kohpeiß

no leída,
23 oct 2014, 6:57:14 a.m.23/10/14
para alche...@googlegroups.com
Hi Thomas,

cool - this worked for me:

# lib/whitelist_constraint.rb
class WhitelistConstraint
  def initialize
    @ips = %w(127.0.0.* 192.168.0.*)
  end

  def matches?(request)
    @ips.select { |x| /#{x}/.match request.remote_ip }.length > 0
  end
end

# config/initializers/secure_alchemy_backend.rb
Alchemy::Admin::BaseController.class_eval do
before_action {
    whitelist = WhitelistConstraint.new
redirect_to(root_url, message: 'You are not allowed to access this url') unless whitelist.matches?(request)
}
end

Regards, 
Thorsten

Am Donnerstag, 23. Oktober 2014 09:53:33 UTC+2 schrieb Thorsten Kohpeiß:

Thomas von Deyen

no leída,
23 oct 2014, 8:40:51 a.m.23/10/14
para alche...@googlegroups.com
Wow, this is actually very PORO style \o/
nice

Toby Johnson

no leída,
20 feb 2015, 4:16:06 p.m.20/2/15
para alche...@googlegroups.com
It seems like you could now accomplish this a bit more simply using the new `Alchemy.current_user_method` config setting instead, correct?

I'm planning to do something similar, where I don't want some logged-in users to even be able to view the admin area. So in that method, when Alchemy tries to get the current user, I'll redirect to root if it's not a user I want seeing that section.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos