mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 09:21:43 +02:00
Merge branch 'master' into registry-927
This commit is contained in:
commit
2636fe2525
40 changed files with 313 additions and 105 deletions
|
@ -29,7 +29,7 @@ module Repp
|
|||
# example: curl -u registrar1:password localhost:3000/repp/v1/domains/1/transfer_info -H "Auth-Code: authinfopw1"
|
||||
get '/:id/transfer_info', requirements: { id: /.*/ } do
|
||||
ident = params[:id]
|
||||
domain = ident =~ /\A[0-9]+\z/ ? Domain.find_by(id: ident) : Domain.find_by_idn(ident)
|
||||
domain = ident.match?(/\A[0-9]+\z/) ? Domain.find_by(id: ident) : Domain.find_by_idn(ident)
|
||||
|
||||
error! I18n.t('errors.messages.epp_domain_not_found'), 404 unless domain
|
||||
error! I18n.t('errors.messages.epp_authorization_error'), 401 unless domain.transfer_code.eql? request.headers['Auth-Code']
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Admin
|
||||
class DomainsController < BaseController
|
||||
load_and_authorize_resource
|
||||
before_action :set_domain, only: [:show, :edit, :update, :zonefile]
|
||||
before_action :set_domain, only: %i[show edit update keep]
|
||||
authorize_resource
|
||||
helper_method :force_delete_templates
|
||||
|
||||
def index
|
||||
|
@ -33,7 +33,8 @@ module Admin
|
|||
end
|
||||
|
||||
def show
|
||||
@domain.valid?
|
||||
# Validation is needed to warn users
|
||||
@domain.validate
|
||||
end
|
||||
|
||||
def edit
|
||||
|
@ -60,6 +61,11 @@ module Admin
|
|||
@versions = @domain.versions
|
||||
end
|
||||
|
||||
def keep
|
||||
@domain.keep
|
||||
redirect_to edit_admin_domain_url(@domain), notice: t('.kept')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_domain
|
||||
|
|
|
@ -145,7 +145,9 @@ class EppController < ApplicationController
|
|||
# VALIDATION
|
||||
def latin_only
|
||||
return true if params['frame'].blank?
|
||||
return true if params['frame'].match(/\A[\p{Latin}\p{Z}\p{P}\p{S}\p{Cc}\p{Cf}\w_\'\+\-\.\(\)\/]*\Z/i)
|
||||
if params['frame'].match?(/\A[\p{Latin}\p{Z}\p{P}\p{S}\p{Cc}\p{Cf}\w_\'\+\-\.\(\)\/]*\Z/i)
|
||||
return true
|
||||
end
|
||||
|
||||
epp_errors << {
|
||||
msg: 'Parameter value policy error. Allowed only Latin characters.',
|
||||
|
|
|
@ -87,14 +87,14 @@ class Certificate < ActiveRecord::Base
|
|||
-extensions usr_cert -notext -md sha256 \
|
||||
-in #{csr_file.path} -out #{crt_file.path} -key '#{ENV['ca_key_password']}' -batch")
|
||||
|
||||
if err.match(/Data Base Updated/)
|
||||
if err.match?(/Data Base Updated/)
|
||||
crt_file.rewind
|
||||
self.crt = crt_file.read
|
||||
self.md5 = OpenSSL::Digest::MD5.new(parsed_crt.to_der).to_s
|
||||
save!
|
||||
else
|
||||
logger.error('FAILED TO CREATE CLIENT CERTIFICATE')
|
||||
if err.match(/TXT_DB error number 2/)
|
||||
if err.match?(/TXT_DB error number 2/)
|
||||
errors.add(:base, I18n.t('failed_to_create_crt_csr_already_signed'))
|
||||
logger.error('CSR ALREADY SIGNED')
|
||||
else
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
module Concerns::Domain::Deletable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
alias_attribute :delete_time, :delete_at
|
||||
private
|
||||
|
||||
def delete_later
|
||||
deletion_time = Time.zone.at(rand(deletion_time_span))
|
||||
DomainDeleteJob.enqueue(id, run_at: deletion_time, priority: 1)
|
||||
logger.info "Domain #{name} is scheduled to be deleted around #{deletion_time}"
|
||||
end
|
||||
|
||||
def discard
|
||||
statuses << DomainStatus::DELETE_CANDIDATE
|
||||
save
|
||||
def do_not_delete_later
|
||||
# Que job can be manually deleted in admin area UI
|
||||
QueJob.find_by("args->>0 = '#{id}'", job_class: DomainDeleteJob.name)&.destroy
|
||||
end
|
||||
|
||||
def discarded?
|
||||
statuses.include?(DomainStatus::DELETE_CANDIDATE)
|
||||
def deletion_time_span
|
||||
range_params = [Time.zone.now.to_i, deletion_deadline.to_i].sort
|
||||
Range.new(*range_params)
|
||||
end
|
||||
end
|
||||
|
||||
def deletion_deadline
|
||||
delete_at + 24.hours
|
||||
end
|
||||
end
|
40
app/models/concerns/domain/discardable.rb
Normal file
40
app/models/concerns/domain/discardable.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Concerns::Domain::Discardable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def discard_domains
|
||||
domains = where('delete_at < ? AND ? != ALL(coalesce(statuses, array[]::varchar[])) AND' \
|
||||
' ? != ALL(COALESCE(statuses, array[]::varchar[]))',
|
||||
Time.zone.now,
|
||||
DomainStatus::SERVER_DELETE_PROHIBITED,
|
||||
DomainStatus::DELETE_CANDIDATE)
|
||||
|
||||
domains.each do |domain|
|
||||
domain.discard
|
||||
yield domain if block_given?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def discard
|
||||
raise 'Domain is already discarded' if discarded?
|
||||
|
||||
statuses << DomainStatus::DELETE_CANDIDATE
|
||||
transaction do
|
||||
save(validate: false)
|
||||
delete_later
|
||||
end
|
||||
end
|
||||
|
||||
def keep
|
||||
statuses.delete(DomainStatus::DELETE_CANDIDATE)
|
||||
transaction do
|
||||
save(validate: false)
|
||||
do_not_delete_later
|
||||
end
|
||||
end
|
||||
|
||||
def discarded?
|
||||
statuses.include?(DomainStatus::DELETE_CANDIDATE)
|
||||
end
|
||||
end
|
|
@ -4,6 +4,7 @@ class Domain < ActiveRecord::Base
|
|||
include Concerns::Domain::Expirable
|
||||
include Concerns::Domain::Activatable
|
||||
include Concerns::Domain::ForceDelete
|
||||
include Concerns::Domain::Discardable
|
||||
include Concerns::Domain::Deletable
|
||||
include Concerns::Domain::Transferable
|
||||
include Concerns::Domain::RegistryLockable
|
||||
|
@ -250,13 +251,6 @@ class Domain < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
def delete_candidateable?
|
||||
return false if delete_at > Time.zone.now
|
||||
return false if statuses.include?(DomainStatus::DELETE_CANDIDATE)
|
||||
return false if statuses.include?(DomainStatus::SERVER_DELETE_PROHIBITED)
|
||||
true
|
||||
end
|
||||
|
||||
def renewable?
|
||||
if Setting.days_to_renew_domain_before_expire != 0
|
||||
# if you can renew domain at days_to_renew before domain expiration
|
||||
|
@ -614,10 +608,6 @@ class Domain < ActiveRecord::Base
|
|||
where("#{attribute_alias(:outzone_time)} < ?", Time.zone.now)
|
||||
end
|
||||
|
||||
def self.delete_candidates
|
||||
where("#{attribute_alias(:delete_time)} < ?", Time.zone.now)
|
||||
end
|
||||
|
||||
def self.uses_zone?(zone)
|
||||
exists?(["name ILIKE ?", "%.#{zone.origin}"])
|
||||
end
|
||||
|
|
|
@ -84,22 +84,6 @@ class DomainCron
|
|||
|
||||
c = 0
|
||||
|
||||
domains = Domain.delete_candidates
|
||||
|
||||
domains.each do |domain|
|
||||
next unless domain.delete_candidateable?
|
||||
|
||||
domain.statuses << DomainStatus::DELETE_CANDIDATE
|
||||
|
||||
# If domain successfully saved, add it to delete schedule
|
||||
if domain.save(validate: false)
|
||||
::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||
DomainDeleteJob.enqueue(domain.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now)
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.destroy_delete_candidates: job added by deleteCandidate status ##{domain.id} (#{domain.name})\n" unless Rails.env.test?
|
||||
c += 1
|
||||
end
|
||||
end
|
||||
|
||||
Domain.where('force_delete_at <= ?', Time.zone.now.end_of_day.utc).each do |x|
|
||||
DomainDeleteJob.enqueue(x.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now)
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.destroy_delete_candidates: job added by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
||||
|
|
|
@ -153,13 +153,11 @@ class DomainStatus < ActiveRecord::Base
|
|||
[
|
||||
['Hold', SERVER_HOLD],
|
||||
['ManualInzone', SERVER_MANUAL_INZONE],
|
||||
# [''],
|
||||
['RenewProhibited', SERVER_RENEW_PROHIBITED],
|
||||
['TransferProhibited', SERVER_TRANSFER_PROHIBITED],
|
||||
['RegistrantChangeProhibited', SERVER_REGISTRANT_CHANGE_PROHIBITED],
|
||||
['AdminChangeProhibited', SERVER_ADMIN_CHANGE_PROHIBITED],
|
||||
['TechChangeProhibited', SERVER_TECH_CHANGE_PROHIBITED],
|
||||
# [''],
|
||||
['UpdateProhibited', SERVER_UPDATE_PROHIBITED],
|
||||
['DeleteProhibited', SERVER_DELETE_PROHIBITED]
|
||||
]
|
||||
|
@ -171,11 +169,11 @@ class DomainStatus < ActiveRecord::Base
|
|||
INACTIVE,
|
||||
FORCE_DELETE,
|
||||
PENDING_CREATE,
|
||||
#PENDING_DELETE,
|
||||
PENDING_RENEW,
|
||||
PENDING_TRANSFER,
|
||||
PENDING_UPDATE,
|
||||
PENDING_DELETE_CONFIRMATION
|
||||
PENDING_DELETE_CONFIRMATION,
|
||||
DELETE_CANDIDATE,
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -100,18 +100,18 @@ class Nameserver < ActiveRecord::Base
|
|||
|
||||
def check_puny_symbols
|
||||
regexp = /(\A|\.)..--/
|
||||
errors.add(:hostname, :invalid) if hostname =~ regexp
|
||||
errors.add(:hostname, :invalid) if hostname.match?(regexp)
|
||||
end
|
||||
|
||||
def validate_ipv4_format
|
||||
ipv4.to_a.each do |ip|
|
||||
errors.add(:ipv4, :invalid) unless ip =~ IPV4_REGEXP
|
||||
errors.add(:ipv4, :invalid) unless ip.match?(IPV4_REGEXP)
|
||||
end
|
||||
end
|
||||
|
||||
def validate_ipv6_format
|
||||
ipv6.to_a.each do |ip|
|
||||
errors.add(:ipv6, :invalid) unless ip =~ IPV6_REGEXP
|
||||
errors.add(:ipv6, :invalid) unless ip.match?(IPV6_REGEXP)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
4
app/models/que_job.rb
Normal file
4
app/models/que_job.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
# To be able to remove existing jobs
|
||||
class QueJob < ActiveRecord::Base
|
||||
self.primary_key = 'job_id'
|
||||
end
|
|
@ -35,7 +35,7 @@ class DomainPresenter
|
|||
end
|
||||
|
||||
def delete_date
|
||||
view.l(domain.delete_time, format: :date) if domain.delete_time
|
||||
view.l(domain.delete_at, format: :date) if domain.delete_at
|
||||
end
|
||||
|
||||
def force_delete_date
|
||||
|
@ -73,6 +73,15 @@ class DomainPresenter
|
|||
class: 'dropdown-item')
|
||||
end
|
||||
|
||||
def keep_btn
|
||||
return unless domain.discarded?
|
||||
|
||||
view.link_to view.t('admin.domains.edit.keep_btn'), view.keep_admin_domain_path(@domain),
|
||||
method: :patch,
|
||||
data: { confirm: view.t('admin.domains.edit.keep_btn_confirm') },
|
||||
class: 'btn btn-default'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def schedule_force_delete_btn
|
||||
|
|
|
@ -10,7 +10,8 @@ class Contact::Ident::RegNoValidator < ActiveModel::EachValidator
|
|||
|
||||
return unless format
|
||||
|
||||
record.errors.add(attribute, :invalid_reg_no, country: record.country) unless value =~ format
|
||||
return if value.match?(format)
|
||||
record.errors.add(attribute, :invalid_reg_no, country: record.country)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -22,7 +22,7 @@ class DomainNameValidator < ActiveModel::EachValidator
|
|||
# it's punycode
|
||||
if value[2] == '-' && value[3] == '-'
|
||||
regexp = /\Axn--[a-zA-Z0-9-]{0,59}\.#{general_domains}\z/
|
||||
return false unless value =~ regexp
|
||||
return false unless value.match?(regexp)
|
||||
value = SimpleIDN.to_unicode(value).mb_chars.downcase.strip
|
||||
end
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<ul class="dropdown-menu">
|
||||
<li><%= domain.force_delete_toggle_btn %></li>
|
||||
<li><%= domain.remove_registry_lock_btn %></li>
|
||||
<li><%= domain.keep_btn %></li>
|
||||
<div class="divider"></div>
|
||||
<li><%= link_to t('.add_new_status_btn'), '#', class: 'js-add-status' %></li>
|
||||
</ul>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue