mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 19:48:28 +02:00
Check IP in registrar
This commit is contained in:
parent
19e133ec6a
commit
940355a417
4 changed files with 33 additions and 2 deletions
|
@ -5,6 +5,8 @@ class Registrar::SessionsController < ::SessionsController
|
|||
false
|
||||
end
|
||||
|
||||
before_action :check_ip
|
||||
|
||||
def login
|
||||
@depp_user = Depp::User.new
|
||||
end
|
||||
|
@ -139,4 +141,11 @@ class Registrar::SessionsController < ::SessionsController
|
|||
return User.new unless idc
|
||||
ApiUser.find_by(identity_code: idc) || User.new
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_ip
|
||||
return if WhiteIp.registrar_ip_white?(request.ip)
|
||||
render text: t('ip_is_not_whitelisted') and return
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class RegistrarController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :authenticate_user!, :check_ip
|
||||
# before_action :check_ip
|
||||
layout 'registrar/application'
|
||||
|
||||
include Registrar::ApplicationHelper
|
||||
|
@ -9,6 +10,14 @@ class RegistrarController < ApplicationController
|
|||
false
|
||||
end
|
||||
|
||||
def check_ip
|
||||
return unless current_user
|
||||
return if current_user.registrar.registrar_ip_white?(request.ip)
|
||||
flash[:alert] = t('ip_is_not_whitelisted')
|
||||
sign_out(current_user)
|
||||
redirect_to registrar_login_path and return
|
||||
end
|
||||
|
||||
helper_method :head_title_sufix
|
||||
def head_title_sufix
|
||||
t(:registrar_head_title_sufix)
|
||||
|
|
|
@ -84,7 +84,7 @@ module Depp
|
|||
res = server.send_request(xml)
|
||||
|
||||
if Nokogiri::XML(res).css('result').first['code'] != '1000'
|
||||
errors.add(:base, :authorization_error)
|
||||
errors.add(:base, Nokogiri::XML(res).css('result').text)
|
||||
end
|
||||
|
||||
server.close_connection
|
||||
|
|
|
@ -24,4 +24,17 @@ class WhiteIp < ActiveRecord::Base
|
|||
scope :repp, -> { where(interface: REPP) }
|
||||
scope :registrar, -> { where(interface: REGISTRAR) }
|
||||
scope :global, -> { where(interface: GLOBAL) }
|
||||
|
||||
class << self
|
||||
def registrar_ip_white?(ip)
|
||||
at = WhiteIp.arel_table
|
||||
WhiteIp.where(
|
||||
at[:interface].eq(REGISTRAR).or(
|
||||
at[:interface].eq(GLOBAL)
|
||||
).and(
|
||||
at[:ipv4].eq(ip)
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue