Add registrar nameserver replacement UI

#661
This commit is contained in:
Artur Beljajev 2018-02-26 10:30:46 +02:00
parent 18010c6a2e
commit 2db401fd98
11 changed files with 197 additions and 11 deletions

View file

@ -2,7 +2,7 @@ module Repp
class NameserversV1 < Grape::API
version 'v1', using: :path
resource :nameservers do
resource 'registrar/nameservers' do
put '/' do
params do
requires :data, type: Hash do

View file

@ -0,0 +1,59 @@
class Registrar
class RegistrarNameserversController < DeppController
def edit
authorize! :manage, :repp
end
def update
authorize! :manage, :repp
ipv4 = params[:ipv4].split("\r\n")
ipv6 = params[:ipv6].split("\r\n")
uri = URI.parse("#{ENV['repp_url']}registrar/nameservers")
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
request.body = { data: { type: 'nameserver', id: params[:old_hostname],
attributes: { hostname: params[:new_hostname],
ipv4: ipv4,
ipv6: ipv6 } } }.to_json
request.basic_auth(current_user.username, current_user.password)
if Rails.env.test?
response = Net::HTTP.start(uri.hostname, uri.port,
use_ssl: (uri.scheme == 'https'),
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
http.request(request)
end
elsif Rails.env.development?
client_cert = File.read(ENV['cert_path'])
client_key = File.read(ENV['key_path'])
response = Net::HTTP.start(uri.hostname, uri.port,
use_ssl: (uri.scheme == 'https'),
verify_mode: OpenSSL::SSL::VERIFY_NONE,
cert: OpenSSL::X509::Certificate.new(client_cert),
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
http.request(request)
end
else
client_cert = File.read(ENV['cert_path'])
client_key = File.read(ENV['key_path'])
response = Net::HTTP.start(uri.hostname, uri.port,
use_ssl: (uri.scheme == 'https'),
cert: OpenSSL::X509::Certificate.new(client_cert),
key: OpenSSL::PKey::RSA.new(client_key)) do |http|
http.request(request)
end
end
parsed_response = JSON.parse(response.body, symbolize_names: true)
if response.code == '200'
flash[:notice] = t '.replaced'
redirect_to registrar_domains_url
else
@api_errors = parsed_response[:errors]
render :edit
end
end
end
end

View file

@ -1,12 +1,14 @@
<div class="page-header">
<div class="row">
<div class="col-sm-9">
<div class="col-sm-7">
<h1><%= t '.header' %></h1>
</div>
<div class="col-sm-3 text-right">
<div class="col-sm-5 text-right">
<%= link_to t('.new_btn'), new_registrar_domain_path, class: 'btn btn-primary' %>
<%= link_to t('.transfer_btn'), new_registrar_domain_transfer_path, class: 'btn btn-default' %>
<%= link_to t('.replace_nameserver_btn'), registrar_edit_registrar_nameserver_path,
class: 'btn btn-default' %>
</div>
</div>
</div>

View file

@ -0,0 +1,50 @@
<%= form_tag registrar_update_registrar_nameserver_path, method: :put, class: 'form-horizontal' do %>
<div class="form-group">
<div class="col-md-2 control-label">
<%= label_tag :old_hostname, nil %>
</div>
<div class="col-md-5">
<%= text_field_tag :old_hostname, nil, autofocus: true, required: true,
class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-2 control-label">
<%= label_tag :new_hostname, nil %>
</div>
<div class="col-md-5">
<%= text_field_tag :new_hostname, nil, required: true, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-2 control-label">
<%= label_tag :ipv4, nil %>
</div>
<div class="col-md-3">
<%= text_area_tag :ipv4, nil, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-2 control-label">
<%= label_tag :ipv6, nil %>
</div>
<div class="col-md-3">
<%= text_area_tag :ipv6, nil, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-md-5 col-md-offset-2 text-right">
<button class="btn btn-warning">
<%= t '.replace_btn' %>
</button>
</div>
</div>
<% end %>

View file

@ -0,0 +1,11 @@
<ol class="breadcrumb">
<li><%= link_to t('registrar.domains.index.header'), registrar_domains_path %></li>
</ol>
<div class="page-header">
<h1><%= t '.header' %></h1>
</div>
<%= render 'registrar/domain_transfers/form/api_errors' %>
<%= render 'form' %>