mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 02:39:37 +02:00
Registrar refactor
This commit is contained in:
parent
6573d81b94
commit
ec4c06bb06
95 changed files with 564 additions and 539 deletions
|
@ -1,38 +0,0 @@
|
|||
module Depp
|
||||
# class ApplicationController < ::ApplicationController
|
||||
class ApplicationController < ActionController::Base
|
||||
include CurrentUserHelper
|
||||
include Depp::ApplicationHelper
|
||||
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
helper_method :depp_current_user
|
||||
|
||||
rescue_from(Errno::ECONNRESET, Errno::ECONNREFUSED) do |_exception|
|
||||
redirect_to login_url, alert: t(:no_connection_to_registry)
|
||||
end
|
||||
|
||||
before_action :authenticate_user
|
||||
def authenticate_user
|
||||
redirect_to main_app.login_url and return unless depp_current_user
|
||||
end
|
||||
|
||||
def depp_current_user
|
||||
return nil unless current_user
|
||||
@depp_current_user ||= Depp::User.new(
|
||||
tag: current_user.username,
|
||||
password: current_user.password
|
||||
)
|
||||
end
|
||||
|
||||
def response_ok?
|
||||
@data.css('result').each do |x|
|
||||
success_codes = %(1000, 1300, 1301)
|
||||
return false unless success_codes.include?(x['code'])
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,84 +0,0 @@
|
|||
module Depp
|
||||
class ContactsController < ApplicationController
|
||||
before_action :init_epp_contact
|
||||
|
||||
def index
|
||||
limit, offset = pagination_details
|
||||
|
||||
res = depp_current_user.repp_request('contacts', { details: true, limit: limit, offset: offset })
|
||||
flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }]
|
||||
@response = res.parsed_body.with_indifferent_access if res.code == '200'
|
||||
@contacts = @response ? @response[:contacts] : []
|
||||
|
||||
@paginatable_array = Kaminari.paginate_array(
|
||||
[], total_count: @response[:total_number_of_records]
|
||||
).page(params[:page]).per(limit)
|
||||
end
|
||||
|
||||
def new
|
||||
@contact = Depp::Contact.new
|
||||
end
|
||||
|
||||
def show
|
||||
@contact = Depp::Contact.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def edit
|
||||
@contact = Depp::Contact.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
@contact = Depp::Contact.new(params[:contact])
|
||||
|
||||
if @contact.save
|
||||
redirect_to contact_url(@contact.id)
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@contact = Depp::Contact.new(params[:contact])
|
||||
|
||||
if @contact.update_attributes(params[:contact])
|
||||
redirect_to contact_url(@contact.id)
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
@contact = Depp::Contact.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def destroy
|
||||
@contact = Depp::Contact.new(params[:contact])
|
||||
|
||||
if @contact.delete
|
||||
redirect_to contacts_url, notice: t(:destroyed)
|
||||
else
|
||||
render 'delete'
|
||||
end
|
||||
end
|
||||
|
||||
def check
|
||||
@ids = params[:contacts]
|
||||
# if @ids
|
||||
# @contacts = []
|
||||
# @ids.split(',').each do |id|
|
||||
# @contacts << id.strip
|
||||
# end
|
||||
# end
|
||||
return unless @ids
|
||||
|
||||
@data = @contact.check(@ids)
|
||||
@contacts = Depp::Contact.construct_check_hash_from_data(@data)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_epp_contact
|
||||
Depp::Contact.user = depp_current_user
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,107 +0,0 @@
|
|||
module Depp
|
||||
class DomainsController < ApplicationController
|
||||
before_action :init_domain, except: :new
|
||||
|
||||
def index
|
||||
limit, offset = pagination_details
|
||||
|
||||
res = depp_current_user.repp_request('domains', { details: true, limit: limit, offset: offset })
|
||||
flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }]
|
||||
@response = res.parsed_body.with_indifferent_access if res.code == '200'
|
||||
@contacts = @response ? @response[:contacts] : []
|
||||
|
||||
@paginatable_array = Kaminari.paginate_array(
|
||||
[], total_count: @response[:total_number_of_records]
|
||||
).page(params[:page]).per(limit)
|
||||
end
|
||||
|
||||
def info
|
||||
@data = @domain.info(params[:domain_name]) if params[:domain_name]
|
||||
if response_ok?
|
||||
render 'info'
|
||||
else
|
||||
flash[:alert] = t('domain_not_found')
|
||||
redirect_to domains_path and return
|
||||
end
|
||||
end
|
||||
|
||||
def check
|
||||
if params[:domain_name]
|
||||
@data = @domain.check(params[:domain_name])
|
||||
render 'check_index' and return unless response_ok?
|
||||
else
|
||||
render 'check_index'
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@domain_params = Depp::Domain.default_params
|
||||
end
|
||||
|
||||
def create
|
||||
@domain_params = params[:domain]
|
||||
@data = @domain.create(@domain_params)
|
||||
|
||||
if response_ok?
|
||||
redirect_to info_domains_path(domain_name: @domain_params[:name])
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@data = @domain.info(params[:domain_name])
|
||||
@domain_params = Depp::Domain.construct_params_from_server_data(@data)
|
||||
end
|
||||
|
||||
def update
|
||||
@domain_params = params[:domain]
|
||||
@data = @domain.update(@domain_params)
|
||||
|
||||
if response_ok?
|
||||
redirect_to info_domains_path(domain_name: @domain_params[:name])
|
||||
else
|
||||
params[:domain_name] = @domain_params[:name]
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def delete; end
|
||||
|
||||
def destroy
|
||||
@data = @domain.delete(params[:domain])
|
||||
@results = @data.css('result')
|
||||
if response_ok?
|
||||
params[:domain_name] = nil
|
||||
render 'info_index'
|
||||
else
|
||||
params[:domain_name] = params[:domain][:name]
|
||||
render 'delete'
|
||||
end
|
||||
end
|
||||
|
||||
def renew
|
||||
if params[:domain_name] && params[:cur_exp_date]
|
||||
@data = @domain.renew(params)
|
||||
render 'renew_index' and return unless response_ok?
|
||||
else
|
||||
render 'renew_index'
|
||||
end
|
||||
end
|
||||
|
||||
def transfer
|
||||
if params[:domain_name]
|
||||
@data = @domain.transfer(params)
|
||||
render 'transfer_index' and return unless response_ok?
|
||||
else
|
||||
render 'transfer_index'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_domain
|
||||
@domain = Depp::Domain.new(current_user: depp_current_user)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
module Depp
|
||||
class KeyrelaysController < ApplicationController
|
||||
def show; end
|
||||
|
||||
def create
|
||||
keyrelay = Depp::Keyrelay.new(current_user: depp_current_user)
|
||||
@data = keyrelay.keyrelay(params)
|
||||
|
||||
if response_ok?
|
||||
flash[:epp_results] = [{ 'code' => '1000', 'msg' => 'Command completed successfully' }]
|
||||
redirect_to keyrelay_path
|
||||
else
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,50 +0,0 @@
|
|||
module Depp
|
||||
class PollsController < ApplicationController
|
||||
before_action :init_epp_xml
|
||||
|
||||
def show
|
||||
@data = depp_current_user.request(@ex.poll)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@data = depp_current_user.request(@ex.poll(poll: {
|
||||
value: '', attrs: { op: 'ack', msgID: params[:id] }
|
||||
}))
|
||||
|
||||
@results = @data.css('result')
|
||||
|
||||
@data = depp_current_user.request(@ex.poll)
|
||||
render 'show'
|
||||
end
|
||||
|
||||
def confirm_keyrelay
|
||||
domain_params = params[:domain]
|
||||
@data = @domain.confirm_keyrelay(domain_params)
|
||||
|
||||
if response_ok?
|
||||
redirect_to info_domains_path(domain_name: domain_params[:name])
|
||||
else
|
||||
@results = @data.css('result')
|
||||
@data = depp_current_user.request(@ex.poll)
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
def confirm_transfer
|
||||
domain_params = params[:domain]
|
||||
@data = @domain.confirm_transfer(domain_params)
|
||||
|
||||
@results = @data.css('result')
|
||||
@data = depp_current_user.request(@ex.poll)
|
||||
|
||||
render 'show'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_epp_xml
|
||||
@ex = EppXml::Session.new(cl_trid_prefix: depp_current_user.tag)
|
||||
@domain = Depp::Domain.new(current_user: depp_current_user)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,23 +0,0 @@
|
|||
module Depp
|
||||
class XmlConsolesController < ApplicationController
|
||||
def show; end
|
||||
|
||||
def create
|
||||
begin
|
||||
@result = depp_current_user.server.request(params[:payload])
|
||||
rescue
|
||||
@result = 'CONNECTION ERROR - Is the EPP server running?'
|
||||
end
|
||||
render :show
|
||||
end
|
||||
|
||||
def load_xml
|
||||
# binding.pry
|
||||
cl_trid = "#{depp_current_user.tag}-#{Time.now.to_i}"
|
||||
xml_dir_path = Depp::Engine.root + 'app/views/depp/xml_consoles/epp_requests'
|
||||
xml = File.read("#{xml_dir_path}/#{params[:obj]}/#{params[:epp_action]}.xml")
|
||||
xml.gsub!('<clTRID>ABC-12345</clTRID>', "<clTRID>#{cl_trid}</clTRID>")
|
||||
render text: xml
|
||||
end
|
||||
end
|
||||
end
|
76
app/controllers/registrar/contacts_controller.rb
Normal file
76
app/controllers/registrar/contacts_controller.rb
Normal file
|
@ -0,0 +1,76 @@
|
|||
class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
||||
before_action :init_epp_contact
|
||||
|
||||
def index
|
||||
authorize! :view, Depp::Contact
|
||||
limit, offset = pagination_details
|
||||
|
||||
res = depp_current_user.repp_request('contacts', { details: true, limit: limit, offset: offset })
|
||||
flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }]
|
||||
@response = res.parsed_body.with_indifferent_access if res.code == '200'
|
||||
@contacts = @response ? @response[:contacts] : []
|
||||
|
||||
@paginatable_array = Kaminari.paginate_array(
|
||||
[], total_count: @response[:total_number_of_records]
|
||||
).page(params[:page]).per(limit)
|
||||
end
|
||||
|
||||
def new
|
||||
authorize! :create, Depp::Contact
|
||||
@contact = Depp::Contact.new
|
||||
end
|
||||
|
||||
def show
|
||||
authorize! :view, Depp::Contact
|
||||
@contact = Depp::Contact.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def edit
|
||||
authorize! :edit, Depp::Contact
|
||||
@contact = Depp::Contact.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
authorize! :create, Depp::Contact
|
||||
@contact = Depp::Contact.new(params[:contact])
|
||||
|
||||
if @contact.save
|
||||
redirect_to registrar_contact_url(@contact.id)
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
authorize! :edit, Depp::Contact
|
||||
@contact = Depp::Contact.new(params[:contact])
|
||||
|
||||
if @contact.update_attributes(params[:contact])
|
||||
redirect_to registrar_contact_url(@contact.id)
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
authorize! :delete, Depp::Contact
|
||||
@contact = Depp::Contact.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize! :delete, Depp::Contact
|
||||
@contact = Depp::Contact.new(params[:contact])
|
||||
|
||||
if @contact.delete
|
||||
redirect_to registrar_contacts_url, notice: t(:destroyed)
|
||||
else
|
||||
render 'delete'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_epp_contact
|
||||
Depp::Contact.user = depp_current_user
|
||||
end
|
||||
end
|
35
app/controllers/registrar/depp_controller.rb
Normal file
35
app/controllers/registrar/depp_controller.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
class Registrar::DeppController < RegistrarController # EPP controller
|
||||
include CurrentUserHelper
|
||||
include Depp::ApplicationHelper
|
||||
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
helper_method :depp_current_user
|
||||
|
||||
rescue_from(Errno::ECONNRESET, Errno::ECONNREFUSED) do |_exception|
|
||||
redirect_to registrar_login_url, alert: t(:no_connection_to_registry)
|
||||
end
|
||||
|
||||
before_action :authenticate_user
|
||||
def authenticate_user
|
||||
redirect_to registrar_login_url and return unless depp_current_user
|
||||
end
|
||||
|
||||
def depp_current_user
|
||||
return nil unless current_user
|
||||
@depp_current_user ||= Depp::User.new(
|
||||
tag: current_user.username,
|
||||
password: current_user.password
|
||||
)
|
||||
end
|
||||
|
||||
def response_ok?
|
||||
@data.css('result').each do |x|
|
||||
success_codes = %(1000, 1300, 1301)
|
||||
return false unless success_codes.include?(x['code'])
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
117
app/controllers/registrar/domains_controller.rb
Normal file
117
app/controllers/registrar/domains_controller.rb
Normal file
|
@ -0,0 +1,117 @@
|
|||
class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
||||
before_action :init_domain, except: :new
|
||||
|
||||
def index
|
||||
authorize! :view, Depp::Domain
|
||||
limit, offset = pagination_details
|
||||
|
||||
res = depp_current_user.repp_request('domains', { details: true, limit: limit, offset: offset })
|
||||
flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }]
|
||||
@response = res.parsed_body.with_indifferent_access if res.code == '200'
|
||||
@contacts = @response ? @response[:contacts] : []
|
||||
|
||||
@paginatable_array = Kaminari.paginate_array(
|
||||
[], total_count: @response[:total_number_of_records]
|
||||
).page(params[:page]).per(limit)
|
||||
end
|
||||
|
||||
def info
|
||||
authorize! :view, Depp::Domain
|
||||
@data = @domain.info(params[:domain_name]) if params[:domain_name]
|
||||
if response_ok?
|
||||
render 'info'
|
||||
else
|
||||
flash[:alert] = t('domain_not_found')
|
||||
redirect_to domains_path and return
|
||||
end
|
||||
end
|
||||
|
||||
def check
|
||||
authorize! :view, Depp::Domain
|
||||
if params[:domain_name]
|
||||
@data = @domain.check(params[:domain_name])
|
||||
render 'check_index' and return unless response_ok?
|
||||
else
|
||||
render 'check_index'
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
authorize! :create, Depp::Domain
|
||||
@domain_params = Depp::Domain.default_params
|
||||
end
|
||||
|
||||
def create
|
||||
authorize! :create, Depp::Domain
|
||||
@domain_params = params[:domain]
|
||||
@data = @domain.create(@domain_params)
|
||||
|
||||
if response_ok?
|
||||
redirect_to info_domains_path(domain_name: @domain_params[:name])
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
authorize! :update, Depp::Domain
|
||||
@data = @domain.info(params[:domain_name])
|
||||
@domain_params = Depp::Domain.construct_params_from_server_data(@data)
|
||||
end
|
||||
|
||||
def update
|
||||
authorize! :update, Depp::Domain
|
||||
@domain_params = params[:domain]
|
||||
@data = @domain.update(@domain_params)
|
||||
|
||||
if response_ok?
|
||||
redirect_to info_domains_path(domain_name: @domain_params[:name])
|
||||
else
|
||||
params[:domain_name] = @domain_params[:name]
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
authorize! :delete, Depp::Domain
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize! :delete, Depp::Domain
|
||||
@data = @domain.delete(params[:domain])
|
||||
@results = @data.css('result')
|
||||
if response_ok?
|
||||
params[:domain_name] = nil
|
||||
render 'info_index'
|
||||
else
|
||||
params[:domain_name] = params[:domain][:name]
|
||||
render 'delete'
|
||||
end
|
||||
end
|
||||
|
||||
def renew
|
||||
authorize! :renew, Depp::Domain
|
||||
if params[:domain_name] && params[:cur_exp_date]
|
||||
@data = @domain.renew(params)
|
||||
render 'renew_index' and return unless response_ok?
|
||||
else
|
||||
render 'renew_index'
|
||||
end
|
||||
end
|
||||
|
||||
def transfer
|
||||
authorize! :transfer, Depp::Domain
|
||||
if params[:domain_name]
|
||||
@data = @domain.transfer(params)
|
||||
render 'transfer_index' and return unless response_ok?
|
||||
else
|
||||
render 'transfer_index'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_domain
|
||||
@domain = Depp::Domain.new(current_user: depp_current_user)
|
||||
end
|
||||
end
|
18
app/controllers/registrar/keyrelays_controller.rb
Normal file
18
app/controllers/registrar/keyrelays_controller.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
class Registrar::KeyrelaysController < Registrar::DeppController # EPP controller
|
||||
def show
|
||||
authorize! :view, Depp::Keyrelay
|
||||
end
|
||||
|
||||
def create
|
||||
authorize! :create, Depp::Keyrelay
|
||||
keyrelay = Depp::Keyrelay.new(current_user: depp_current_user)
|
||||
@data = keyrelay.keyrelay(params)
|
||||
|
||||
if response_ok?
|
||||
flash[:epp_results] = [{ 'code' => '1000', 'msg' => 'Command completed successfully' }]
|
||||
redirect_to keyrelay_path
|
||||
else
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
end
|
52
app/controllers/registrar/polls_controller.rb
Normal file
52
app/controllers/registrar/polls_controller.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
class Registrar::PollsController < Registrar::DeppController # EPP controller
|
||||
before_action :init_epp_xml
|
||||
|
||||
def show
|
||||
authorize! :view, :registrar_dashboard
|
||||
@data = depp_current_user.request(@ex.poll)
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize! :delete, :registrar_poll
|
||||
@data = depp_current_user.request(@ex.poll(poll: {
|
||||
value: '', attrs: { op: 'ack', msgID: params[:id] }
|
||||
}))
|
||||
|
||||
@results = @data.css('result')
|
||||
|
||||
@data = depp_current_user.request(@ex.poll)
|
||||
render 'show'
|
||||
end
|
||||
|
||||
def confirm_keyrelay
|
||||
authorize! :confirm, :keyrelay
|
||||
domain_params = params[:domain]
|
||||
@data = @domain.confirm_keyrelay(domain_params)
|
||||
|
||||
if response_ok?
|
||||
redirect_to info_domains_path(domain_name: domain_params[:name])
|
||||
else
|
||||
@results = @data.css('result')
|
||||
@data = depp_current_user.request(@ex.poll)
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
def confirm_transfer
|
||||
authorize! :confirm, :transfer
|
||||
domain_params = params[:domain]
|
||||
@data = @domain.confirm_transfer(domain_params)
|
||||
|
||||
@results = @data.css('result')
|
||||
@data = depp_current_user.request(@ex.poll)
|
||||
|
||||
render 'show'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_epp_xml
|
||||
@ex = EppXml::Session.new(cl_trid_prefix: depp_current_user.tag)
|
||||
@domain = Depp::Domain.new(current_user: depp_current_user)
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
class Registrar::SessionsController < SessionsController
|
||||
layout 'depp/application'
|
||||
class Registrar::SessionsController < ::SessionsController
|
||||
layout 'registrar/application'
|
||||
|
||||
def create
|
||||
@user = ApiUser.first if params[:user1]
|
||||
|
|
24
app/controllers/registrar/xml_consoles_controller.rb
Normal file
24
app/controllers/registrar/xml_consoles_controller.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class Registrar::XmlConsolesController < Registrar::DeppController # EPP controller
|
||||
def show
|
||||
authorize! :view, :registrar_xml_console
|
||||
end
|
||||
|
||||
def create
|
||||
authorize! :create, :registrar_xml_console
|
||||
begin
|
||||
@result = depp_current_user.server.request(params[:payload])
|
||||
rescue
|
||||
@result = 'CONNECTION ERROR - Is the EPP server running?'
|
||||
end
|
||||
render :show
|
||||
end
|
||||
|
||||
def load_xml
|
||||
# binding.pry
|
||||
cl_trid = "#{depp_current_user.tag}-#{Time.now.to_i}"
|
||||
xml_dir_path = Depp::Engine.root + 'app/views/depp/xml_consoles/epp_requests'
|
||||
xml = File.read("#{xml_dir_path}/#{params[:obj]}/#{params[:epp_action]}.xml")
|
||||
xml.gsub!('<clTRID>ABC-12345</clTRID>', "<clTRID>#{cl_trid}</clTRID>")
|
||||
render text: xml
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
class RegistrarController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
layout 'depp/application'
|
||||
layout 'registrar/application'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue