mirror of
https://github.com/internetee/registry.git
synced 2025-07-04 10:13:34 +02:00
Add IP protection for REPP
This commit is contained in:
parent
8321f894d5
commit
abf47b1e08
6 changed files with 39 additions and 6 deletions
|
@ -8,6 +8,10 @@ module Repp
|
|||
end
|
||||
|
||||
before do
|
||||
unless Rails.env.development?
|
||||
error! 'IP is not whitelisted', 401 unless @current_user.registrar.repp_ip_white?(request.ip)
|
||||
end
|
||||
|
||||
next if Rails.env.test? || Rails.env.development?
|
||||
message = 'Certificate mismatch! Cert common name should be:'
|
||||
request_name = env['HTTP_SSL_CLIENT_S_DN_CN']
|
||||
|
@ -18,6 +22,7 @@ module Repp
|
|||
else
|
||||
error! "#{message} #{@current_user.username}", 401 if @current_user.username != request_name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
helpers do
|
||||
|
|
|
@ -146,4 +146,20 @@ class Registrar < ActiveRecord::Base
|
|||
def code=(code)
|
||||
self[:code] = code.gsub(/[ :]/, '').upcase if new_record? && code.present?
|
||||
end
|
||||
|
||||
def repp_ip_white?(ip)
|
||||
white_ips.repp.pluck(:ipv4, :ipv6).flatten.include?(ip) || global_ip_white?(ip)
|
||||
end
|
||||
|
||||
def epp_ip_white?(ip)
|
||||
white_ips.epp.pluck(:ipv4, :ipv6).flatten.include?(ip) || global_ip_white?(ip)
|
||||
end
|
||||
|
||||
def registrar_ip_white?(ip)
|
||||
white_ips.registrar.pluck(:ipv4, :ipv6).flatten.include?(ip) || global_ip_white?(ip)
|
||||
end
|
||||
|
||||
def global_ip_white?(ip)
|
||||
white_ips.global.pluck(:ipv4, :ipv6).flatten.include?(ip)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,9 +13,15 @@ class WhiteIp < ActiveRecord::Base
|
|||
errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present))
|
||||
end
|
||||
|
||||
INTERFACE_EPP = 'epp'
|
||||
INTERFACE_REPP = 'repp'
|
||||
INTERFACE_REGISTRAR = 'registrar'
|
||||
EPP = 'epp'
|
||||
REPP = 'repp'
|
||||
REGISTRAR = 'registrar'
|
||||
GLOBAL = 'global'
|
||||
|
||||
INTERFACES = [INTERFACE_EPP, INTERFACE_REPP, INTERFACE_REGISTRAR]
|
||||
INTERFACES = [GLOBAL, EPP, REPP, REGISTRAR]
|
||||
|
||||
scope :epp, -> { where(interface: EPP) }
|
||||
scope :repp, -> { where(interface: REPP) }
|
||||
scope :registrar, -> { where(interface: REGISTRAR) }
|
||||
scope :global, -> { where(interface: GLOBAL) }
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
.col-md-4.control-label
|
||||
= f.label :interface
|
||||
.col-md-7
|
||||
= f.select :interface, [[t(:choose), '']] + WhiteIp::INTERFACES.map {|x| [x.upcase, x]}, {}, class: 'form-control selectize', placeholder: t(:choose)
|
||||
= f.select :interface, WhiteIp::INTERFACES.map {|x| [x.upcase, x]}, {}, class: 'form-control selectize'
|
||||
%hr
|
||||
.row
|
||||
.col-md-8.text-right
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue