mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 02:39:37 +02:00
Merge remote-tracking branch 'origin/master' into 110687814-update_values
# Conflicts: # app/models/epp/domain.rb
This commit is contained in:
commit
ae3467a8b1
304 changed files with 3676 additions and 426401 deletions
|
@ -16,7 +16,7 @@ class Ability
|
|||
@user.roles.each { |role| send(role) } if @user.roles
|
||||
when 'ApiUser'
|
||||
@user.roles.each { |role| send(role) } if @user.roles
|
||||
when 'RegistrantUser'
|
||||
when 'RegistrantUser'
|
||||
static_registrant
|
||||
end
|
||||
|
||||
|
@ -117,9 +117,11 @@ class Ability
|
|||
end
|
||||
|
||||
def static_registrant
|
||||
customer_service
|
||||
can :manage, :registrant_domains
|
||||
can :manage, :registrant_whois
|
||||
can :manage, Depp::Domain
|
||||
can :manage, Domain
|
||||
end
|
||||
|
||||
def user
|
||||
|
|
|
@ -6,6 +6,8 @@ class AccountActivity < ActiveRecord::Base
|
|||
belongs_to :bank_transaction
|
||||
belongs_to :invoice
|
||||
|
||||
attr_accessor :registrar
|
||||
|
||||
CREATE = 'create'
|
||||
RENEW = 'renew'
|
||||
ADD_CREDIT = 'add_credit'
|
||||
|
@ -22,12 +24,13 @@ class AccountActivity < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def to_csv
|
||||
attributes = %w(description activity_type created_at sum)
|
||||
attributes = %w(registrar description activity_type created_at sum)
|
||||
|
||||
CSV.generate(headers: true) do |csv|
|
||||
csv << %w(description activity_type receipt_date sum)
|
||||
csv << %w(registrar description activity_type receipt_date sum)
|
||||
|
||||
all.each do |x| # rubocop:disable Rails/FindEach
|
||||
x.registrar = Registrar.find(x.account_id).try(:code)
|
||||
csv << attributes.map { |attr| x.send(attr) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ class BankTransaction < ActiveRecord::Base
|
|||
include Versions
|
||||
belongs_to :bank_statement
|
||||
has_one :account_activity
|
||||
has_many :directo_records, as: :item, class_name: 'Directo'# Deprecated
|
||||
|
||||
scope :unbinded, lambda {
|
||||
where('id NOT IN (SELECT bank_transaction_id FROM account_activities where bank_transaction_id IS NOT NULL)')
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
class BlockedDomain < ActiveRecord::Base
|
||||
include Versions
|
||||
before_save :generate_data
|
||||
before_destroy :remove_data
|
||||
before_save :generate_data
|
||||
after_destroy :remove_data
|
||||
|
||||
validates :name, domain_name: true, uniqueness: true
|
||||
|
||||
|
||||
class << self
|
||||
|
@ -21,19 +23,14 @@ class BlockedDomain < ActiveRecord::Base
|
|||
def generate_data
|
||||
return if Domain.where(name: name).any?
|
||||
|
||||
@json = generate_json
|
||||
@body = generate_body
|
||||
update_whois_server
|
||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||
wr.json = @json = generate_json # we need @json to bind to class
|
||||
wr.body = generate_body
|
||||
wr.save
|
||||
end
|
||||
|
||||
alias_method :update_whois_record, :generate_data
|
||||
|
||||
def update_whois_server
|
||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||
wr.body = @body
|
||||
wr.json = @json
|
||||
wr.save
|
||||
end
|
||||
|
||||
def generate_body
|
||||
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
||||
|
@ -48,8 +45,6 @@ class BlockedDomain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def remove_data
|
||||
return if Domain.where(name: name).any?
|
||||
|
||||
Whois::Record.where(name: name).delete_all
|
||||
UpdateWhoisRecordJob.enqueue name, 'blocked'
|
||||
end
|
||||
end
|
||||
|
|
83
app/models/business_registry_cache.rb
Normal file
83
app/models/business_registry_cache.rb
Normal file
|
@ -0,0 +1,83 @@
|
|||
|
||||
=begin
|
||||
The portal for registrants has to offer an overview of the domains the user is related to directly or through an organisation.
|
||||
Personal relation is defined by matching the personal identification code associated with a domain and the one acquired on
|
||||
authentication using electronic ID. Association through a business organisation requires a query to business registry.
|
||||
|
||||
* when user logs in the personal identification code is sent to business registry (using XML service)
|
||||
* business registry returns the list of business registry codes the user is a board member of
|
||||
* the list is cached for two days (configurable)
|
||||
* during that time no new queries are made to business registry for that personal identification code
|
||||
and the cached organisation code listing is used
|
||||
* user sees the listing of domains that are associated with him/her directly or through registered organisation
|
||||
* UI of the portal displays the list of organisation codes and names used to fetch additional domains for the user
|
||||
(currently by clicking on a username in top right corner of the screen).
|
||||
Also time and date of the query to the business registry is displayed with the list of organisations.
|
||||
* if the query to the business registry fails for any reason the list of
|
||||
domains associated directly with the user is still displayed with an error message indicating a problem
|
||||
with receiving current list business entities. Outdated list of organisations cannot be used.
|
||||
=end
|
||||
|
||||
class BusinessRegistryCache < ActiveRecord::Base
|
||||
|
||||
# 1. load domains by business
|
||||
# 2. load domains by person
|
||||
def associated_contacts
|
||||
contact_ids = Contact.where(ident_type: 'org', ident: associated_businesses, ident_country_code: 'EE').pluck(:id)
|
||||
contact_ids += Contact.where(ident_type: 'priv', ident: ident, ident_country_code: ident_country_code).pluck(:id)
|
||||
contact_ids
|
||||
end
|
||||
|
||||
def associated_domain_ids
|
||||
domain_ids = []
|
||||
|
||||
contact_ids = associated_contacts
|
||||
|
||||
unless contact_ids.blank?
|
||||
domain_ids = DomainContact.distinct.where(contact_id: contact_ids).pluck(:domain_id)
|
||||
end
|
||||
|
||||
domain_ids
|
||||
end
|
||||
|
||||
def associated_domains
|
||||
Domain.includes(:registrar, :registrant).where(id: associated_domain_ids)
|
||||
end
|
||||
|
||||
class << self
|
||||
def fetch_associated_domains(ident_code, ident_cc)
|
||||
fetch_by_ident_and_cc(ident_code, ident_cc).associated_domains
|
||||
end
|
||||
|
||||
def fetch_by_ident_and_cc(ident_code, ident_cc)
|
||||
cache = BusinessRegistryCache.where(ident: ident_code, ident_country_code: ident_cc).first_or_initialize
|
||||
msg_start = "[Ariregister] #{ident_cc}-#{ident_code}:"
|
||||
|
||||
# fetch new data if cache is expired
|
||||
if cache.retrieved_on && cache.retrieved_on > (Time.zone.now - Setting.days_to_keep_business_registry_cache.days)
|
||||
Rails.logger.info("#{msg_start} Info loaded from cache")
|
||||
return cache
|
||||
end
|
||||
|
||||
cache.attributes = business_registry.associated_businesses(ident_code, ident_cc)
|
||||
Rails.logger.info("#{msg_start} Info loaded from server")
|
||||
|
||||
cache.save
|
||||
cache
|
||||
end
|
||||
|
||||
def business_registry
|
||||
Soap::Arireg.new
|
||||
end
|
||||
|
||||
def purge
|
||||
STDOUT << "#{Time.zone.now.utc} - Starting Purge of old BusinessRegistry data from cache\n" unless Rails.env.test?
|
||||
purged = 0
|
||||
BusinessRegistryCache.where('retrieved_on < ?',
|
||||
Time.zone.now < Setting.days_to_keep_business_registry_cache.days).each do |br|
|
||||
br.destroy and purged += 1
|
||||
end
|
||||
STDOUT << "#{Time.zone.now.utc} - Finished purging #{purged} old BusinessRegistry cache items\n" unless Rails.env.test?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,6 +12,10 @@ class Contact < ActiveRecord::Base
|
|||
# TODO: remove later
|
||||
has_many :depricated_statuses, class_name: 'DepricatedContactStatus', dependent: :destroy
|
||||
|
||||
has_paper_trail class_name: "ContactVersion", meta: { children: :children_log }
|
||||
|
||||
attr_accessor :legal_document_id
|
||||
|
||||
accepts_nested_attributes_for :legal_documents
|
||||
|
||||
validates :name, :phone, :email, :ident, :ident_type,
|
||||
|
@ -32,6 +36,7 @@ class Contact < ActiveRecord::Base
|
|||
validate :val_ident_valid_format?
|
||||
validate :uniq_statuses?
|
||||
validate :validate_html
|
||||
validate :val_country_code
|
||||
|
||||
after_initialize do
|
||||
self.statuses = [] if statuses.nil?
|
||||
|
@ -39,7 +44,7 @@ class Contact < ActiveRecord::Base
|
|||
self.ident_updated_at = Time.zone.now if new_record? && ident_updated_at.blank?
|
||||
end
|
||||
|
||||
before_validation :set_ident_country_code
|
||||
before_validation :to_upcase_country_code
|
||||
before_validation :prefix_code
|
||||
before_create :generate_auth_info
|
||||
|
||||
|
@ -330,22 +335,36 @@ class Contact < ActiveRecord::Base
|
|||
# TODO: refactor, it should not allow to destroy with normal destroy,
|
||||
# no need separate method
|
||||
# should use only in transaction
|
||||
def destroy_and_clean
|
||||
def destroy_and_clean frame
|
||||
if domains_present?
|
||||
errors.add(:domains, :exist)
|
||||
return false
|
||||
end
|
||||
|
||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
||||
|
||||
if legal_document_data
|
||||
|
||||
doc = LegalDocument.create(
|
||||
documentable_type: Contact,
|
||||
document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body]
|
||||
)
|
||||
self.legal_documents = [doc]
|
||||
self.legal_document_id = doc.id
|
||||
self.save
|
||||
end
|
||||
destroy
|
||||
end
|
||||
|
||||
def set_ident_country_code
|
||||
return true unless ident_country_code_changed? && ident_country_code.present?
|
||||
code = Country.new(ident_country_code)
|
||||
if code
|
||||
self.ident_country_code = code.alpha2
|
||||
else
|
||||
errors.add(:ident, :invalid_country_code)
|
||||
end
|
||||
def to_upcase_country_code
|
||||
self.ident_country_code = ident_country_code.upcase if ident_country_code
|
||||
self.country_code = country_code.upcase if country_code
|
||||
end
|
||||
|
||||
def val_country_code
|
||||
errors.add(:ident, :invalid_country_code) unless Country.new(ident_country_code)
|
||||
errors.add(:ident, :invalid_country_code) unless Country.new(country_code)
|
||||
end
|
||||
|
||||
def related_domain_descriptions
|
||||
|
@ -415,7 +434,10 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
|
||||
# fetch domains
|
||||
domains = Domain.where("domains.id IN (#{filter_sql})").includes(:registrar).page(page).per(per)
|
||||
domains = Domain.where("domains.id IN (#{filter_sql})")
|
||||
domains = domains.where("domains.id" => params[:leave_domains]) if params[:leave_domains]
|
||||
domains = domains.includes(:registrar).page(page).per(per)
|
||||
|
||||
if sorts.first == "registrar_name".freeze
|
||||
# using small rails hack to generate outer join
|
||||
domains = domains.includes(:registrar).where.not(registrars: {id: nil}).order("registrars.name #{order} NULLS LAST")
|
||||
|
@ -434,6 +456,30 @@ class Contact < ActiveRecord::Base
|
|||
domains
|
||||
end
|
||||
|
||||
def all_registrant_domains(page: nil, per: nil, params: {}, registrant: nil)
|
||||
|
||||
if registrant
|
||||
sorts = params.fetch(:sort, {}).first || []
|
||||
sort = Domain.column_names.include?(sorts.first) ? sorts.first : "valid_to"
|
||||
order = {"asc"=>"desc", "desc"=>"asc"}[sorts.second] || "desc"
|
||||
|
||||
domain_ids = DomainContact.distinct.where(contact_id: registrant.id).pluck(:domain_id)
|
||||
|
||||
domains = Domain.where(id: domain_ids).includes(:registrar).page(page).per(per)
|
||||
if sorts.first == "registrar_name".freeze
|
||||
domains = domains.includes(:registrar).where.not(registrars: {id: nil}).order("registrars.name #{order} NULLS LAST")
|
||||
else
|
||||
domains = domains.order("#{sort} #{order} NULLS LAST")
|
||||
end
|
||||
|
||||
domain_c = Hash.new([])
|
||||
registrant_domains.where(id: domains.map(&:id)).each{|d| domain_c[d.id] |= ["Registrant".freeze] }
|
||||
DomainContact.where(contact_id: id, domain_id: domains.map(&:id)).each{|d| domain_c[d.domain_id] |= [d.type] }
|
||||
domains.each{|d| d.roles = domain_c[d.id].uniq}
|
||||
domains
|
||||
end
|
||||
end
|
||||
|
||||
def set_linked
|
||||
statuses << LINKED if statuses.detect { |s| s == LINKED }.blank?
|
||||
end
|
||||
|
@ -498,8 +544,15 @@ class Contact < ActiveRecord::Base
|
|||
]).present?
|
||||
end
|
||||
|
||||
def update_related_whois_records
|
||||
related_domain_descriptions.each{ |x, y| WhoisRecord.find_by(name: x).try(:save) }
|
||||
end
|
||||
def update_related_whois_records
|
||||
names = related_domain_descriptions.keys
|
||||
UpdateWhoisRecordJob.enqueue(names, :domain) if names.present?
|
||||
end
|
||||
|
||||
def children_log
|
||||
log = HashWithIndifferentAccess.new
|
||||
log[:legal_documents]= [legal_document_id]
|
||||
log
|
||||
end
|
||||
|
||||
end
|
||||
|
|
24
app/models/counter.rb
Normal file
24
app/models/counter.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class Counter
|
||||
def initialize value = 0
|
||||
@value = value
|
||||
end
|
||||
attr_accessor :value
|
||||
def method_missing *args, &blk
|
||||
@value.send(*args, &blk)
|
||||
end
|
||||
def to_s
|
||||
@value.to_s
|
||||
end
|
||||
|
||||
def now
|
||||
@value
|
||||
end
|
||||
|
||||
# pre-increment ".+" when x not present
|
||||
def next(x = 1)
|
||||
@value += x
|
||||
end
|
||||
def prev(x = 1)
|
||||
@value -= x
|
||||
end
|
||||
end
|
|
@ -1,15 +1,25 @@
|
|||
class Directo < ActiveRecord::Base
|
||||
DOMAIN_TO_PRODUCT = {"ee" => "01EE", "com.ee" => "02COM", "pri.ee" => "03PRI", "fie.ee"=>"04FIE", "med.ee" => "05MED"}.freeze
|
||||
belongs_to :item, polymorphic: true
|
||||
|
||||
def self.send_receipts
|
||||
new_trans = Invoice.where(invoice_type: "DEB", in_directo: false).where.not(cancelled_at: nil)
|
||||
new_trans = Invoice.where(invoice_type: "DEB", in_directo: false).where(cancelled_at: nil)
|
||||
total = new_trans.count
|
||||
counter = 0
|
||||
Rails.logger.info("[DIRECTO] Will try to send #{total} invoices")
|
||||
|
||||
new_trans.find_in_batches(batch_size: 10).each do |group|
|
||||
mappers = {} # need them as no direct connection between invoice
|
||||
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
||||
xml.invoices {
|
||||
group.each do |invoice|
|
||||
next if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil?
|
||||
# next if invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.sum_cache
|
||||
|
||||
if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? ||
|
||||
invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.sum_cache
|
||||
Rails.logger.info("[DIRECTO] Invoice #{invoice.number} has been skipped")
|
||||
next
|
||||
end
|
||||
counter += 1
|
||||
|
||||
num = invoice.number
|
||||
mappers[num] = invoice
|
||||
|
@ -36,14 +46,134 @@ class Directo < ActiveRecord::Base
|
|||
response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false).to_s
|
||||
dump_result_to_db(mappers, response)
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Directo receipts sending finished. #{counter} of #{total} are sent\n"
|
||||
end
|
||||
|
||||
def self.dump_result_to_db mappers, xml
|
||||
Nokogiri::XML(xml).css("Result").each do |res|
|
||||
obj = mappers[res.attributes["docid"].value.to_i]
|
||||
obj.directo_records.create!(response: res.as_json.to_h)
|
||||
obj.directo_records.create!(response: res.as_json.to_h, invoice_number: obj.number)
|
||||
obj.update_columns(in_directo: true)
|
||||
Rails.logger.info("[DIRECTO] Invoice #{res.attributes["docid"].value} was pushed and return is #{res.as_json.to_h.inspect}")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.send_monthly_invoices(debug: false)
|
||||
@debug = debug
|
||||
I18n.locale = :et
|
||||
month = Time.now - 1.month
|
||||
invoices_until = month.end_of_month
|
||||
date_format = "%Y-%m-%d"
|
||||
invoice_counter= Counter.new
|
||||
|
||||
min_directo = Setting.directo_monthly_number_min.presence.try(:to_i)
|
||||
max_directo = Setting.directo_monthly_number_max.presence.try(:to_i)
|
||||
last_directo = [Setting.directo_monthly_number_last.presence.try(:to_i), min_directo].compact.max || 0
|
||||
if max_directo && max_directo <= last_directo
|
||||
raise "Directo counter is out of period (max allowed number is smaller than last counter number)"
|
||||
end
|
||||
|
||||
directo_next = last_directo
|
||||
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
||||
unless registrar.cash_account
|
||||
Rails.logger.info("[DIRECTO] Monthly invoice for registrar #{registrar.id} has been skipped as it doesn't has cash_account")
|
||||
next
|
||||
end
|
||||
counter = Counter.new(1)
|
||||
items = {}
|
||||
registrar_activities = AccountActivity.where(account_id: registrar.account_ids).where("created_at BETWEEN ? AND ?",month.beginning_of_month, month.end_of_month)
|
||||
|
||||
# adding domains items
|
||||
registrar_activities.where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]).each do |activity|
|
||||
pricelist = load_activity_pricelist(activity)
|
||||
unless pricelist
|
||||
Rails.logger.error("[DIRECTO] Skipping activity #{activity.id} as pricelist not found")
|
||||
next
|
||||
end
|
||||
|
||||
pricelist.years_amount.times do |i|
|
||||
year = i+1
|
||||
hash = {
|
||||
"ProductID" => DOMAIN_TO_PRODUCT[pricelist.category],
|
||||
"Unit" => "tk",
|
||||
"ProductName" => ".#{pricelist.category} registreerimine: #{pricelist.years_amount} aasta",
|
||||
"UnitPriceWoVAT" => pricelist.price_decimal/pricelist.years_amount
|
||||
}
|
||||
hash["StartDate"] = (activity.created_at + (year-1).year).end_of_month.strftime(date_format) if year > 1
|
||||
hash["EndDate"] = (activity.created_at + (year-1).year + 1).end_of_month.strftime(date_format) if year > 1
|
||||
|
||||
if items.has_key?(hash)
|
||||
items[hash]["Quantity"] += 1
|
||||
else
|
||||
items[hash] = {"RN"=>counter.next, "RR" => counter.now - i, "Quantity"=> 1}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#adding prepaiments
|
||||
if items.any?
|
||||
total = 0
|
||||
items.each{ |key, val| total += val["Quantity"] * key["UnitPriceWoVAT"] }
|
||||
hash = {"ProductID" => Setting.directo_receipt_product_name, "Unit" => "tk", "ProductName" => "Domeenide ettemaks", "UnitPriceWoVAT"=>total}
|
||||
items[hash] = {"RN"=>counter.next, "RR" => counter.now, "Quantity"=> -1}
|
||||
end
|
||||
|
||||
# generating XML
|
||||
if items.any?
|
||||
directo_next += 1
|
||||
invoice_counter.next
|
||||
|
||||
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
||||
xml.invoices{
|
||||
xml.invoice("Number" =>directo_next,
|
||||
"InvoiceDate" =>invoices_until.strftime(date_format),
|
||||
"PaymentTerm" =>Setting.directo_receipt_payment_term,
|
||||
"CustomerCode"=>registrar.directo_handle,
|
||||
"Language" =>"",
|
||||
"Currency" =>registrar_activities.first.currency,
|
||||
"SalesAgent" =>Setting.directo_sales_agent){
|
||||
xml.line("RN" => 1, "RR"=>1, "ProductName"=> "Domeenide registreerimine - #{I18n.l(invoices_until, format: "%B %Y").titleize}")
|
||||
items.each do |line, val|
|
||||
xml.line(val.merge(line))
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
data = builder.to_xml.gsub("\n",'')
|
||||
response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false).to_s
|
||||
if @debug
|
||||
STDOUT << "#{Time.zone.now.utc} - Directo xml had to be sent #{data}\n"
|
||||
else
|
||||
Setting.directo_monthly_number_last = directo_next
|
||||
Nokogiri::XML(response).css("Result").each do |res|
|
||||
Directo.create!(request: data, response: res.as_json.to_h, invoice_number: directo_next)
|
||||
Rails.logger.info("[DIRECTO] Invoice #{res.attributes["docid"].value} was pushed and return is #{res.as_json.to_h.inspect}")
|
||||
end
|
||||
end
|
||||
else
|
||||
Rails.logger.info("[DIRECTO] Registrar #{registrar.id} has nothing to be sent to Directo")
|
||||
end
|
||||
|
||||
end
|
||||
STDOUT << "#{Time.zone.now.utc} - Directo invoices sending finished. #{invoice_counter.now} are sent\n"
|
||||
end
|
||||
|
||||
|
||||
def self.load_activity_pricelist activity
|
||||
@pricelists ||= {}
|
||||
return @pricelists[activity.log_pricelist_id] if @pricelists.has_key?(activity.log_pricelist_id)
|
||||
|
||||
pricelist = Pricelist.find_by(id: activity.log_pricelist_id) || PricelistVersion.find_by(item_id: activity.log_pricelist_id).try(:reify)
|
||||
unless pricelist
|
||||
@pricelists[activity.log_pricelist_id] = nil
|
||||
Rails.logger.info("[DIRECTO] AccountActivity #{activity.id} cannot be sent as pricelist wasn't found #{activity.log_pricelist_id}")
|
||||
return
|
||||
end
|
||||
|
||||
@pricelists[activity.log_pricelist_id] = pricelist.version_at(activity.created_at) || pricelist
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
attr_accessor :roles
|
||||
|
||||
attr_accessor :legal_document_id
|
||||
|
||||
# TODO: whois requests ip whitelist for full info for own domains and partial info for other domains
|
||||
# TODO: most inputs should be trimmed before validatation, probably some global logic?
|
||||
|
||||
|
@ -43,7 +45,7 @@ class Domain < ActiveRecord::Base
|
|||
has_many :dnskeys, dependent: :destroy
|
||||
|
||||
has_many :keyrelays
|
||||
has_one :whois_record, dependent: :destroy
|
||||
has_one :whois_record # destroyment will be done in after_commit
|
||||
|
||||
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
||||
|
||||
|
@ -87,14 +89,11 @@ class Domain < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
after_save :update_whois_record
|
||||
after_commit :update_whois_record
|
||||
|
||||
after_create :update_reserved_domains
|
||||
def update_reserved_domains
|
||||
return unless in_reserved_list?
|
||||
rd = ReservedDomain.by_domain(name).first
|
||||
rd.password = SecureRandom.hex
|
||||
rd.save
|
||||
ReservedDomain.new_password_for(name) if in_reserved_list?
|
||||
end
|
||||
|
||||
validates :name_dirty, domain_name: true, uniqueness: true
|
||||
|
@ -203,6 +202,31 @@ class Domain < ActiveRecord::Base
|
|||
statuses.include? DomainStatus::SERVER_TECH_CHANGE_PROHIBITED
|
||||
end
|
||||
|
||||
def self.clean_expired_pendings
|
||||
ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__)
|
||||
DomainCron.send(__method__)
|
||||
end
|
||||
|
||||
def self.start_expire_period
|
||||
ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__)
|
||||
DomainCron.send(__method__)
|
||||
end
|
||||
|
||||
def self.start_redemption_grace_period
|
||||
ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__)
|
||||
DomainCron.send(__method__)
|
||||
end
|
||||
|
||||
def self.start_delete_period
|
||||
ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__)
|
||||
DomainCron.send(__method__)
|
||||
end
|
||||
|
||||
def self.destroy_delete_candidates
|
||||
ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__)
|
||||
DomainCron.send(__method__)
|
||||
end
|
||||
|
||||
class << self
|
||||
def convert_period_to_time(period, unit)
|
||||
return (period.to_i / 365).years if unit == 'd'
|
||||
|
@ -220,122 +244,6 @@ class Domain < ActiveRecord::Base
|
|||
{ admin_contacts: :registrar }
|
||||
)
|
||||
end
|
||||
|
||||
# rubocop: disable Metrics/AbcSize
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
def clean_expired_pendings
|
||||
STDOUT << "#{Time.zone.now.utc} - Clean expired domain pendings\n" unless Rails.env.test?
|
||||
|
||||
expire_at = Setting.expire_pending_confirmation.hours.ago
|
||||
count = 0
|
||||
expired_pending_domains = Domain.where('registrant_verification_asked_at <= ?', expire_at)
|
||||
expired_pending_domains.each do |domain|
|
||||
unless domain.pending_update? || domain.pending_delete? || domain.pending_delete_confirmation?
|
||||
msg = "#{Time.zone.now.utc} - ISSUE: DOMAIN #{domain.id}: #{domain.name} IS IN EXPIRED PENDING LIST, " \
|
||||
"but no pendingDelete/pendingUpdate state present!\n"
|
||||
STDOUT << msg unless Rails.env.test?
|
||||
next
|
||||
end
|
||||
count += 1
|
||||
if domain.pending_update?
|
||||
domain.send_mail :pending_update_expired_notification_for_new_registrant
|
||||
end
|
||||
if domain.pending_delete? || domain.pending_delete_confirmation?
|
||||
DomainMailer.pending_delete_expired_notification(domain.id, true).deliver
|
||||
end
|
||||
domain.clean_pendings_lowlevel
|
||||
unless Rails.env.test?
|
||||
STDOUT << "#{Time.zone.now.utc} Domain.clean_expired_pendings: ##{domain.id} (#{domain.name})\n"
|
||||
end
|
||||
end
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} domain pendings\n" unless Rails.env.test?
|
||||
count
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
|
||||
# rubocop: disable Metrics/LineLength
|
||||
def start_expire_period
|
||||
STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test?
|
||||
|
||||
domains = Domain.where('valid_to <= ?', Time.zone.now)
|
||||
domains.each do |domain|
|
||||
next unless domain.expirable?
|
||||
domain.set_graceful_expired
|
||||
DomainMailer.expiration_reminder(domain.id).deliver_in(Setting.expiration_reminder_mail.to_i.days)
|
||||
STDOUT << "#{Time.zone.now.utc} Domain.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test?
|
||||
domain.save(validate: false)
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully expired #{domains.count} domains\n" unless Rails.env.test?
|
||||
end
|
||||
|
||||
def start_redemption_grace_period
|
||||
STDOUT << "#{Time.zone.now.utc} - Setting server_hold to domains\n" unless Rails.env.test?
|
||||
|
||||
d = Domain.where('outzone_at <= ?', Time.zone.now)
|
||||
d.each do |domain|
|
||||
next unless domain.server_holdable?
|
||||
domain.statuses << DomainStatus::SERVER_HOLD
|
||||
STDOUT << "#{Time.zone.now.utc} Domain.start_redemption_grace_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test?
|
||||
domain.save(validate: false)
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{d.count} domains\n" unless Rails.env.test?
|
||||
end
|
||||
|
||||
def start_delete_period
|
||||
STDOUT << "#{Time.zone.now.utc} - Setting delete_candidate to domains\n" unless Rails.env.test?
|
||||
|
||||
d = Domain.where('delete_at <= ?', Time.zone.now)
|
||||
d.each do |domain|
|
||||
next unless domain.delete_candidateable?
|
||||
domain.statuses << DomainStatus::DELETE_CANDIDATE
|
||||
STDOUT << "#{Time.zone.now.utc} Domain.start_delete_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test?
|
||||
domain.save(validate: false)
|
||||
end
|
||||
|
||||
return if Rails.env.test?
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully set delete_candidate to #{d.count} domains\n"
|
||||
end
|
||||
|
||||
# rubocop:disable Rails/FindEach
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def destroy_delete_candidates
|
||||
STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test?
|
||||
|
||||
c = 0
|
||||
Domain.where("statuses @> '{deleteCandidate}'::varchar[]").each do |x|
|
||||
WhoisRecord.where(domain_id: x.id).destroy_all
|
||||
destroy_with_message x
|
||||
STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by deleteCandidate ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
||||
|
||||
c += 1
|
||||
end
|
||||
|
||||
Domain.where('force_delete_at <= ?', Time.zone.now).each do |x|
|
||||
WhoisRecord.where(domain_id: x.id).destroy_all
|
||||
destroy_with_message x
|
||||
STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
||||
c += 1
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test?
|
||||
end
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
# rubocop:enable Rails/FindEach
|
||||
# rubocop: enable Metrics/LineLength
|
||||
def destroy_with_message(domain)
|
||||
domain.destroy
|
||||
bye_bye = domain.versions.last
|
||||
domain.registrar.messages.create!(
|
||||
body: "#{I18n.t(:domain_deleted)}: #{domain.name}",
|
||||
attached_obj_id: bye_bye.id,
|
||||
attached_obj_type: bye_bye.class.to_s # DomainVersion
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def name=(value)
|
||||
|
@ -370,7 +278,7 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def in_reserved_list?
|
||||
ReservedDomain.pw_for(name).present?
|
||||
@in_reserved_list ||= ReservedDomain.by_domain(name).any?
|
||||
end
|
||||
|
||||
def pending_transfer
|
||||
|
@ -439,7 +347,8 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
|
||||
# state change shouln't be
|
||||
# state changes may be done low-level - no validation
|
||||
# in this metod we still save PaperTrail log.
|
||||
def clean_pendings_lowlevel
|
||||
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||
statuses.delete(DomainStatus::PENDING_UPDATE)
|
||||
|
@ -448,13 +357,23 @@ class Domain < ActiveRecord::Base
|
|||
status_notes[DomainStatus::PENDING_UPDATE] = ''
|
||||
status_notes[DomainStatus::PENDING_DELETE] = ''
|
||||
|
||||
update_columns(
|
||||
hash = {
|
||||
registrant_verification_token: nil,
|
||||
registrant_verification_asked_at: nil,
|
||||
pending_json: {},
|
||||
status_notes: status_notes,
|
||||
statuses: statuses.presence || [DomainStatus::OK]
|
||||
)
|
||||
statuses: statuses.presence || [DomainStatus::OK],
|
||||
# need this column in order to update PaperTrail version properly
|
||||
updated_at: Time.now.utc
|
||||
}
|
||||
|
||||
# PaperTrail
|
||||
self.attributes = hash
|
||||
record_update
|
||||
clear_version_instance!
|
||||
reset_transaction_id
|
||||
|
||||
update_columns(hash)
|
||||
end
|
||||
|
||||
def pending_update!
|
||||
|
@ -478,6 +397,7 @@ class Domain < ActiveRecord::Base
|
|||
self.registrant_verification_token = token
|
||||
self.registrant_verification_asked_at = asked_at
|
||||
set_pending_update
|
||||
touch_always_version
|
||||
pending_json['new_registrant_id'] = new_registrant_id
|
||||
pending_json['new_registrant_email'] = new_registrant_email
|
||||
pending_json['new_registrant_name'] = new_registrant_name
|
||||
|
@ -543,19 +463,14 @@ class Domain < ActiveRecord::Base
|
|||
period_i ||= period
|
||||
unit ||= period_unit
|
||||
|
||||
# TODO: test if name.scan(/\.(.+)\z/).first.first is faster
|
||||
zone = name.split('.').drop(1).join('.')
|
||||
|
||||
p = period_i / 365 if unit == 'd'
|
||||
p = period_i / 12 if unit == 'm'
|
||||
p = period_i if unit == 'y'
|
||||
|
||||
if p > 1
|
||||
p = "#{p}years"
|
||||
else
|
||||
p = "#{p}year"
|
||||
end
|
||||
|
||||
Pricelist.pricelist_for(zone, operation, p)
|
||||
Pricelist.pricelist_for(zone, operation, "#{p}year".pluralize(p))
|
||||
end
|
||||
|
||||
### VALIDATIONS ###
|
||||
|
@ -592,7 +507,7 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
def name_in_wire_format
|
||||
res = ''
|
||||
parts = name.split('.')
|
||||
parts = name_puny.split('.')
|
||||
parts.each do |x|
|
||||
res += format('%02X', x.length) # length of label in hex
|
||||
res += x.each_byte.map { |b| format('%02X', b) }.join # label
|
||||
|
@ -728,8 +643,12 @@ class Domain < ActiveRecord::Base
|
|||
case s
|
||||
when DomainStatus::PENDING_DELETE
|
||||
self.delete_at = nil
|
||||
# Handle any other special remove cases?
|
||||
# when DomainStatus::FORCE_DELETE unset_force_delete
|
||||
when DomainStatus::SERVER_MANUAL_INZONE # removal causes server hold to set
|
||||
self.outzone_at = Time.zone.now if self.force_delete_at.present?
|
||||
when DomainStatus::DomainStatus::EXPIRED # removal causes server hold to set
|
||||
self.outzone_at = self.valid_to + 15.day
|
||||
when DomainStatus::DomainStatus::SERVER_HOLD # removal causes server hold to set
|
||||
self.outzone_at = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -820,13 +739,14 @@ class Domain < ActiveRecord::Base
|
|||
log[:admin_contacts] = admin_contact_ids
|
||||
log[:tech_contacts] = tech_contact_ids
|
||||
log[:nameservers] = nameserver_ids
|
||||
log[:legal_documents]= [legal_document_id]
|
||||
log[:registrant] = [registrant_id]
|
||||
log[:domain_statuses] = domain_status_ids
|
||||
log
|
||||
end
|
||||
|
||||
def update_whois_record
|
||||
whois_record.blank? ? create_whois_record : whois_record.save
|
||||
UpdateWhoisRecordJob.enqueue name, 'domain'
|
||||
end
|
||||
|
||||
def status_notes_array=(notes)
|
||||
|
@ -841,5 +761,19 @@ class Domain < ActiveRecord::Base
|
|||
DomainMailer.send(action, DomainMailModel.new(self).send(action)).deliver
|
||||
end
|
||||
|
||||
|
||||
def self.to_csv
|
||||
CSV.generate do |csv|
|
||||
csv << column_names
|
||||
all.each do |domain|
|
||||
csv << domain.attributes.values_at(*column_names)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.pdf(html)
|
||||
kit = PDFKit.new(html)
|
||||
kit.to_pdf
|
||||
end
|
||||
end
|
||||
# rubocop: enable Metrics/ClassLength
|
||||
|
|
132
app/models/domain_cron.rb
Normal file
132
app/models/domain_cron.rb
Normal file
|
@ -0,0 +1,132 @@
|
|||
class DomainCron
|
||||
|
||||
def self.clean_expired_pendings
|
||||
STDOUT << "#{Time.zone.now.utc} - Clean expired domain pendings\n" unless Rails.env.test?
|
||||
|
||||
expire_at = Setting.expire_pending_confirmation.hours.ago
|
||||
count = 0
|
||||
expired_pending_domains = Domain.where('registrant_verification_asked_at <= ?', expire_at)
|
||||
expired_pending_domains.each do |domain|
|
||||
unless domain.pending_update? || domain.pending_delete? || domain.pending_delete_confirmation?
|
||||
msg = "#{Time.zone.now.utc} - ISSUE: DOMAIN #{domain.id}: #{domain.name} IS IN EXPIRED PENDING LIST, " \
|
||||
"but no pendingDelete/pendingUpdate state present!\n"
|
||||
STDOUT << msg unless Rails.env.test?
|
||||
next
|
||||
end
|
||||
count += 1
|
||||
if domain.pending_update?
|
||||
DomainMailer.pending_update_expired_notification_for_new_registrant(domain.id).deliver
|
||||
end
|
||||
if domain.pending_delete? || domain.pending_delete_confirmation?
|
||||
DomainMailer.pending_delete_expired_notification(domain.id, true).deliver
|
||||
end
|
||||
domain.clean_pendings_lowlevel
|
||||
unless Rails.env.test?
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.clean_expired_pendings: ##{domain.id} (#{domain.name})\n"
|
||||
end
|
||||
UpdateWhoisRecordJob.enqueue domain.name, 'domain'
|
||||
end
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} domain pendings\n" unless Rails.env.test?
|
||||
count
|
||||
end
|
||||
|
||||
def self.start_expire_period
|
||||
STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test?
|
||||
|
||||
domains = Domain.where('valid_to <= ?', Time.zone.now)
|
||||
marked = 0
|
||||
real = 0
|
||||
domains.each do |domain|
|
||||
next unless domain.expirable?
|
||||
real += 1
|
||||
domain.set_graceful_expired
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test?
|
||||
domain.save(validate: false) and marked += 1
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully expired #{marked} of #{real} domains\n" unless Rails.env.test?
|
||||
end
|
||||
|
||||
def self.start_redemption_grace_period
|
||||
STDOUT << "#{Time.zone.now.utc} - Setting server_hold to domains\n" unless Rails.env.test?
|
||||
|
||||
d = Domain.where('outzone_at <= ?', Time.zone.now)
|
||||
marked = 0
|
||||
real = 0
|
||||
d.each do |domain|
|
||||
next unless domain.server_holdable?
|
||||
real += 1
|
||||
domain.statuses << DomainStatus::SERVER_HOLD
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.start_redemption_grace_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test?
|
||||
domain.save(validate: false) and marked += 1
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{marked} of #{real} domains\n" unless Rails.env.test?
|
||||
marked
|
||||
end
|
||||
|
||||
#doing nothing, deprecated
|
||||
|
||||
def self.start_delete_period
|
||||
# begin
|
||||
# STDOUT << "#{Time.zone.now.utc} - Setting delete_candidate to domains\n" unless Rails.env.test?
|
||||
#
|
||||
# d = Domain.where('delete_at <= ?', Time.zone.now)
|
||||
# marked = 0
|
||||
# real = 0
|
||||
# d.each do |domain|
|
||||
# next unless domain.delete_candidateable?
|
||||
# real += 1
|
||||
# domain.statuses << DomainStatus::DELETE_CANDIDATE
|
||||
# STDOUT << "#{Time.zone.now.utc} DomainCron.start_delete_period: ##{domain.id} (#{domain.name})\n" unless Rails.env.test?
|
||||
# ::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||
# domain.save(validate: false) and marked += 1
|
||||
# end
|
||||
# ensure # the operator should see what was accomplished
|
||||
# STDOUT << "#{Time.zone.now.utc} - Finished setting delete_candidate - #{marked} out of #{real} successfully set\n" unless Rails.env.test?
|
||||
# end
|
||||
# marked
|
||||
end
|
||||
|
||||
def self.destroy_delete_candidates
|
||||
STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test?
|
||||
|
||||
c = 0
|
||||
|
||||
Domain.where('delete_at <= ?', Time.zone.now).each do |x|
|
||||
next unless x.delete_candidateable?
|
||||
|
||||
x.statuses << DomainStatus::DELETE_CANDIDATE
|
||||
|
||||
# If domain successfully saved, add it to delete schedule
|
||||
if x.save(validate: false)
|
||||
::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||
DomainDeleteJob.enqueue(x.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now)
|
||||
STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: job added by deleteCandidate status ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
||||
c += 1
|
||||
end
|
||||
end
|
||||
|
||||
Domain.where('force_delete_at <= ?', Time.zone.now).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?
|
||||
c += 1
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Job destroy added for #{c} domains\n" unless Rails.env.test?
|
||||
end
|
||||
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
# rubocop:enable Rails/FindEach
|
||||
# rubocop: enable Metrics/LineLength
|
||||
def self.destroy_with_message(domain)
|
||||
domain.destroy
|
||||
bye_bye = domain.versions.last
|
||||
domain.registrar.messages.create!(
|
||||
body: "#{I18n.t(:domain_deleted)}: #{domain.name}",
|
||||
attached_obj_id: bye_bye.id,
|
||||
attached_obj_type: bye_bye.class.to_s # DomainVersion
|
||||
)
|
||||
end
|
||||
|
||||
end
|
|
@ -37,10 +37,7 @@ class Epp::Contact < Contact
|
|||
at[:country_code] = f.css('postalInfo addr cc').text if f.css('postalInfo addr cc').present?
|
||||
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
|
||||
|
||||
legal_frame = f.css('legalDocument').first
|
||||
if legal_frame.present?
|
||||
at[:legal_documents_attributes] = legal_document_attrs(legal_frame)
|
||||
end
|
||||
|
||||
at.merge!(ident_attrs(f.css('ident').first)) if new_record
|
||||
at
|
||||
end
|
||||
|
@ -104,6 +101,7 @@ class Epp::Contact < Contact
|
|||
|
||||
res
|
||||
end
|
||||
|
||||
end
|
||||
delegate :ident_attr_valid?, to: :class
|
||||
|
||||
|
@ -152,8 +150,14 @@ class Epp::Contact < Contact
|
|||
at[:statuses] = statuses - statuses_attrs(frame.css('rem'), 'rem') + statuses_attrs(frame.css('add'), 'add')
|
||||
end
|
||||
|
||||
legal_frame = frame.css('legalDocument').first
|
||||
at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
|
||||
# legal_frame = frame.css('legalDocument').first
|
||||
# at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
|
||||
|
||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
||||
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
self.deliver_emails = true # turn on email delivery for epp
|
||||
|
||||
|
||||
|
@ -175,6 +179,8 @@ class Epp::Contact < Contact
|
|||
else
|
||||
throw :epp_error, {code: '2306', msg: I18n.t(:ident_update_error)}
|
||||
end
|
||||
else
|
||||
throw :epp_error, {code: '2306', msg: I18n.t(:ident_update_error)}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -218,4 +224,29 @@ class Epp::Contact < Contact
|
|||
|
||||
status_list
|
||||
end
|
||||
|
||||
def attach_legal_document(legal_document_data)
|
||||
return unless legal_document_data
|
||||
|
||||
legal_documents.create(
|
||||
document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body]
|
||||
)
|
||||
end
|
||||
|
||||
def add_legal_file_to_new frame
|
||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
||||
return unless legal_document_data
|
||||
|
||||
doc = LegalDocument.create(
|
||||
documentable_type: Contact,
|
||||
document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body]
|
||||
)
|
||||
self.legal_documents = [doc]
|
||||
|
||||
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -133,7 +133,8 @@ class Epp::Domain < Domain
|
|||
[:base, :ds_data_not_allowed],
|
||||
[:base, :key_data_not_allowed],
|
||||
[:period, :not_a_number],
|
||||
[:period, :not_an_integer]
|
||||
[:period, :not_an_integer],
|
||||
[:registrant, :cannot_be_missing]
|
||||
],
|
||||
'2308' => [
|
||||
[:base, :domain_name_blocked, { value: { obj: 'name', val: name_dirty } }]
|
||||
|
@ -155,7 +156,8 @@ class Epp::Domain < Domain
|
|||
def attrs_from(frame, current_user, action = nil)
|
||||
at = {}.with_indifferent_access
|
||||
|
||||
code = frame.css('registrant').first.try(:text)
|
||||
registrant_frame = frame.css('registrant').first
|
||||
code = registrant_frame.try(:text)
|
||||
if code.present?
|
||||
if action == 'chg' && registrant_change_prohibited?
|
||||
add_epp_error('2304', nil, DomainStatus::SERVER_REGISTRANT_CHANGE_PROHIBITED, I18n.t(:object_status_prohibits_operation))
|
||||
|
@ -166,7 +168,10 @@ class Epp::Domain < Domain
|
|||
else
|
||||
add_epp_error('2303', 'registrant', code, [:registrant, :not_found])
|
||||
end
|
||||
end
|
||||
else
|
||||
add_epp_error('2306', nil, nil, [:registrant, :cannot_be_missing])
|
||||
end if registrant_frame
|
||||
|
||||
|
||||
at[:name] = frame.css('name').text if new_record?
|
||||
at[:registrar_id] = current_user.registrar.try(:id)
|
||||
|
@ -195,9 +200,27 @@ class Epp::Domain < Domain
|
|||
end
|
||||
|
||||
at[:dnskeys_attributes] = dnskeys_attrs(dnskey_frame, action)
|
||||
at[:legal_documents_attributes] = legal_document_from(frame)
|
||||
|
||||
at
|
||||
end
|
||||
|
||||
|
||||
# Adding legal doc to domain and
|
||||
# if something goes wrong - raise Rollback error
|
||||
def add_legal_file_to_new frame
|
||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
||||
return unless legal_document_data
|
||||
|
||||
doc = LegalDocument.create(
|
||||
documentable_type: Domain,
|
||||
document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body]
|
||||
)
|
||||
self.legal_documents = [doc]
|
||||
|
||||
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
# rubocop: enable Metrics/MethodLength
|
||||
|
@ -457,15 +480,6 @@ class Epp::Domain < Domain
|
|||
status_list
|
||||
end
|
||||
|
||||
def legal_document_from(frame)
|
||||
ld = frame.css('legalDocument').first
|
||||
return [] unless ld
|
||||
|
||||
[{
|
||||
body: ld.text,
|
||||
document_type: ld['type']
|
||||
}]
|
||||
end
|
||||
|
||||
# rubocop: disable Metrics/AbcSize
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
|
@ -477,6 +491,7 @@ class Epp::Domain < Domain
|
|||
|
||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
||||
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
at_add = attrs_from(frame.css('add'), current_user, 'add')
|
||||
|
@ -494,6 +509,15 @@ class Epp::Domain < Domain
|
|||
self.up_date = Time.zone.now
|
||||
end
|
||||
|
||||
if registrant_id && registrant.code == frame.css('registrant')
|
||||
|
||||
throw :epp_error, {
|
||||
code: '2305',
|
||||
msg: I18n.t(:contact_already_associated_with_the_domain)
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
if errors.empty? && verify &&
|
||||
Setting.request_confrimation_on_registrant_change_enabled &&
|
||||
frame.css('registrant').present? &&
|
||||
|
@ -867,6 +891,7 @@ class Epp::Domain < Domain
|
|||
ld = parsed_frame.css('legalDocument').first
|
||||
return nil unless ld
|
||||
return nil if ld.text.starts_with?(ENV['legal_documents_dir']) # escape reloading
|
||||
return nil if ld.text.starts_with?('/home/') # escape reloading
|
||||
|
||||
{
|
||||
body: ld.text,
|
||||
|
|
|
@ -11,6 +11,18 @@ class Invoice < ActiveRecord::Base
|
|||
scope :unbinded, lambda {
|
||||
where('id NOT IN (SELECT invoice_id FROM account_activities where invoice_id IS NOT NULL)')
|
||||
}
|
||||
scope :all_columns, ->{select("invoices.*")}
|
||||
scope :sort_due_date_column, ->{all_columns.select("CASE WHEN invoices.cancelled_at is not null THEN
|
||||
(invoices.cancelled_at + interval '100 year') ELSE
|
||||
invoices.due_date END AS sort_due_date")}
|
||||
scope :sort_by_sort_due_date_asc, ->{sort_due_date_column.order("sort_due_date ASC")}
|
||||
scope :sort_by_sort_due_date_desc, ->{sort_due_date_column.order("sort_due_date DESC")}
|
||||
scope :sort_receipt_date_column, ->{all_columns.includes(:account_activity).references(:account_activity).select(%Q{
|
||||
CASE WHEN account_activities.created_at is not null THEN account_activities.created_at
|
||||
WHEN invoices.cancelled_at is not null THEN invoices.cancelled_at + interval '100 year'
|
||||
ELSE NULL END AS sort_receipt_date })}
|
||||
scope :sort_by_sort_receipt_date_asc, ->{sort_receipt_date_column.order("sort_receipt_date ASC")}
|
||||
scope :sort_by_sort_receipt_date_desc, ->{sort_receipt_date_column.order("sort_receipt_date DESC")}
|
||||
|
||||
attr_accessor :billing_email
|
||||
validates :billing_email, email_format: { message: :invalid }, allow_blank: true
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
class LegalDocument < ActiveRecord::Base
|
||||
include EppErrors
|
||||
MIN_BODY_SIZE = (1.37 * 3.kilobytes).ceil
|
||||
|
||||
if ENV['legal_document_types'].present?
|
||||
TYPES = ENV['legal_document_types'].split(',').map(&:strip)
|
||||
else
|
||||
|
@ -9,9 +12,23 @@ class LegalDocument < ActiveRecord::Base
|
|||
|
||||
belongs_to :documentable, polymorphic: true
|
||||
|
||||
|
||||
validate :val_body_length, if: ->(file){ file.path.blank? && !Rails.env.staging?}
|
||||
|
||||
before_create :add_creator
|
||||
before_save :save_to_filesystem
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2306' => [
|
||||
[:body, :length]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def val_body_length
|
||||
errors.add(:body, :length) if body.nil? || body.size < MIN_BODY_SIZE
|
||||
end
|
||||
|
||||
|
||||
def save_to_filesystem
|
||||
|
|
|
@ -8,6 +8,8 @@ class Pricelist < ActiveRecord::Base
|
|||
)
|
||||
}
|
||||
|
||||
scope :valid_at, ->(time){ where("valid_from IS NULL OR valid_from <= ?", time).where("valid_to IS NULL OR valid_to >= ?", time) }
|
||||
|
||||
monetize :price_cents
|
||||
|
||||
validates :price_cents, :price_currency, :price,
|
||||
|
@ -27,6 +29,14 @@ class Pricelist < ActiveRecord::Base
|
|||
"#{operation_category} #{category}"
|
||||
end
|
||||
|
||||
def years_amount
|
||||
duration.to_i
|
||||
end
|
||||
|
||||
def price_decimal
|
||||
price_cents / BigDecimal.new('100')
|
||||
end
|
||||
|
||||
class << self
|
||||
def pricelist_for(zone, operation, period)
|
||||
lists = valid.where(category: zone, operation_category: operation, duration: period)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class RegistrantUser < User
|
||||
ACCEPTED_ISSUER = 'AS Sertifitseerimiskeskus'
|
||||
attr_accessor :idc_data
|
||||
|
||||
def ability
|
||||
|
@ -6,6 +7,19 @@ class RegistrantUser < User
|
|||
end
|
||||
delegate :can?, :cannot?, to: :ability
|
||||
|
||||
def ident
|
||||
registrant_ident.to_s.split("-").last
|
||||
end
|
||||
|
||||
def domains
|
||||
ident_cc, ident = registrant_ident.to_s.split '-'
|
||||
Domain.includes(:registrar, :registrant).where(contacts: {
|
||||
ident_type: 'priv',
|
||||
ident: ident, #identity_code,
|
||||
ident_country_code: ident_cc #country_code
|
||||
})
|
||||
end
|
||||
|
||||
def to_s
|
||||
username
|
||||
end
|
||||
|
@ -13,15 +27,23 @@ class RegistrantUser < User
|
|||
class << self
|
||||
def find_or_create_by_idc_data(idc_data, issuer_organization)
|
||||
return false if idc_data.blank?
|
||||
return false if issuer_organization != 'AS Sertifitseerimiskeskus'
|
||||
return false if issuer_organization != ACCEPTED_ISSUER
|
||||
|
||||
idc_data.force_encoding('UTF-8')
|
||||
logger.error(idc_data)
|
||||
logger.error(idc_data.encoding)
|
||||
identity_code = idc_data.scan(/serialNumber=(\d+)/).flatten.first
|
||||
country = idc_data.scan(/^\/C=(.{2})/).flatten.first
|
||||
first_name = idc_data.scan(%r{/GN=(.+)/serialNumber}).flatten.first
|
||||
last_name = idc_data.scan(%r{/SN=(.+)/GN}).flatten.first
|
||||
|
||||
# handling here new and old mode
|
||||
if idc_data.starts_with?("/")
|
||||
identity_code = idc_data.scan(/serialNumber=(\d+)/).flatten.first
|
||||
country = idc_data.scan(/^\/C=(.{2})/).flatten.first
|
||||
first_name = idc_data.scan(%r{/GN=(.+)/serialNumber}).flatten.first
|
||||
last_name = idc_data.scan(%r{/SN=(.+)/GN}).flatten.first
|
||||
else
|
||||
parse_str = "," + idc_data
|
||||
identity_code = parse_str.scan(/,serialNumber=(\d+)/).flatten.first
|
||||
country = parse_str.scan(/,C=(.{2})/).flatten.first
|
||||
first_name = parse_str.scan(/,GN=([^,]+)/).flatten.first
|
||||
last_name = parse_str.scan(/,SN=([^,]+)/).flatten.first
|
||||
end
|
||||
|
||||
u = where(registrant_ident: "#{country}-#{identity_code}").first_or_create
|
||||
u.username = "#{first_name} #{last_name}"
|
||||
|
|
|
@ -2,7 +2,11 @@ class ReservedDomain < ActiveRecord::Base
|
|||
include Versions # version/reserved_domain_version.rb
|
||||
before_save :fill_empty_passwords
|
||||
before_save :generate_data
|
||||
before_destroy :remove_data
|
||||
after_destroy :remove_data
|
||||
|
||||
validates :name, domain_name: true, uniqueness: true
|
||||
|
||||
|
||||
|
||||
|
||||
class << self
|
||||
|
@ -18,33 +22,40 @@ class ReservedDomain < ActiveRecord::Base
|
|||
def any_of_domains names
|
||||
where(name: names)
|
||||
end
|
||||
|
||||
def new_password_for name
|
||||
record = by_domain(name).first
|
||||
return unless record
|
||||
|
||||
record.regenerate_password
|
||||
record.save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def fill_empty_passwords
|
||||
self.password = SecureRandom.hex unless self.password
|
||||
end
|
||||
|
||||
def name= val
|
||||
super SimpleIDN.to_unicode(val)
|
||||
end
|
||||
|
||||
def fill_empty_passwords
|
||||
regenerate_password if self.password.blank?
|
||||
end
|
||||
|
||||
def regenerate_password
|
||||
self.password = SecureRandom.hex
|
||||
end
|
||||
|
||||
def generate_data
|
||||
return if Domain.where(name: name).any?
|
||||
|
||||
@json = generate_json
|
||||
@body = generate_body
|
||||
update_whois_server
|
||||
end
|
||||
|
||||
alias_method :update_whois_record, :generate_data
|
||||
|
||||
def update_whois_server
|
||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||
wr.body = @body
|
||||
wr.json = @json
|
||||
wr.json = @json = generate_json # we need @json to bind to class
|
||||
wr.body = generate_body
|
||||
wr.save
|
||||
end
|
||||
alias_method :update_whois_record, :generate_data
|
||||
|
||||
|
||||
def generate_body
|
||||
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
||||
|
@ -59,9 +70,7 @@ class ReservedDomain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def remove_data
|
||||
return if Domain.where(name: name).any?
|
||||
|
||||
Whois::Record.where(name: name).delete_all
|
||||
UpdateWhoisRecordJob.enqueue name, 'reserved'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
219
app/models/soap/arireg.rb
Normal file
219
app/models/soap/arireg.rb
Normal file
|
@ -0,0 +1,219 @@
|
|||
# coding: utf-8
|
||||
require 'savon'
|
||||
=begin
|
||||
|
||||
Estonian Business registry provides information about registered companies via xml (SOAP over HTTPS).
|
||||
|
||||
Note:
|
||||
The SSL endpoint certificate is self signed.
|
||||
|
||||
Documentation:
|
||||
http://www.rik.ee/et/e-ariregister/xml-teenus
|
||||
Specifications are in Eng and Est
|
||||
User contract required
|
||||
|
||||
Testing:
|
||||
https://demo-ariregxml.rik.ee:447/testariport/?wsdl
|
||||
http://demo-ariregxml.rik.ee:81
|
||||
https://demo-ariregxml.rik.ee:447
|
||||
|
||||
Live service:
|
||||
https://ariregxml.rik.ee/ariport/?wsdl
|
||||
https://ariregxml.rik.ee/
|
||||
|
||||
Implements Soap::Arireg # associated_businesses
|
||||
8. arireg.paringesindus_v4
|
||||
Rights of representation of all persons related to the company (newer)
|
||||
http://www2.rik.ee/schemas/xtee/arireg/live/paringesindus_v4.xsd
|
||||
expects personal id code, to fetch list of registered business id codes
|
||||
returning {ident: person, ident_country_code: ... associated_businesses: [...id_codes...]}
|
||||
|
||||
=end
|
||||
|
||||
# do some SSL set up?
|
||||
# ssl_version
|
||||
# ssl_verify_mode
|
||||
# ssl_cert_key_file
|
||||
# ssl_cert_key
|
||||
# ssl_cert_key_password
|
||||
# ssl_cert_file
|
||||
# ssl_cert
|
||||
# ssl_ca_cert_file
|
||||
# ssl_ca_cert
|
||||
|
||||
module Soap
|
||||
|
||||
class Arireg
|
||||
|
||||
class NotAvailableError < StandardError
|
||||
attr_accessor :json
|
||||
def initialize(params)
|
||||
params[:message] = "#{I18n.t(:business_registry_service_not_available)}" unless params.key? :message
|
||||
@json = params
|
||||
|
||||
super(params)
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
attr_accessor :wsdl, :host, :username, :password
|
||||
end
|
||||
|
||||
def initialize
|
||||
if self.class.username.nil?
|
||||
if Rails.application.secrets.key?(:arireg)
|
||||
arireg = Rails.application.secrets[:arireg].with_indifferent_access
|
||||
self.class.username = arireg[:username]
|
||||
self.class.password = arireg[:password]
|
||||
if self.class.wsdl.nil? # no override of config/environments/* ?
|
||||
self.class.wsdl = arireg[:wsdl]
|
||||
self.class.host = arireg[:host]
|
||||
end
|
||||
else
|
||||
self.class.username = ENV['arireg_username']
|
||||
self.class.password = ENV['arireg_password']
|
||||
end
|
||||
end
|
||||
if self.class.wsdl.nil?
|
||||
self.class.wsdl = ENV['arireg_wsdl']
|
||||
self.class.host = ENV['arireg_host']
|
||||
end
|
||||
|
||||
# note Savon has error if https w/non-standard port,
|
||||
# use non-standard force to pre-set endpoint
|
||||
@client = Savon.client(wsdl: self.class.wsdl,
|
||||
host: self.class.host,
|
||||
endpoint: "#{self.class.host}/cgi-bin/consumer_proxy")
|
||||
@session = nil
|
||||
end
|
||||
|
||||
# retrieve business id codes for business that a person has a legal role
|
||||
def associated_businesses(ident, ident_cc = 'EST')
|
||||
begin
|
||||
msg = {
|
||||
'fyysilise_isiku_kood' => ident,
|
||||
'fyysilise_isiku_koodi_riik' => country_code_3(ident_cc)
|
||||
}
|
||||
Rails.logger.info "[Ariregister] Request sent with data: #{msg.inspect}"
|
||||
|
||||
response = @client.call :paringesindus_v4, message: body(msg)
|
||||
content = extract response, :paringesindus_v4_response
|
||||
Rails.logger.info "[Ariregister] Got response with data: #{content.inspect}"
|
||||
|
||||
if content.present? && content[:ettevotjad].key?(:item)
|
||||
business_ident = items(content, :ettevotjad).map{|item| item[:ariregistri_kood]}
|
||||
else
|
||||
business_ident = []
|
||||
end
|
||||
|
||||
{
|
||||
ident: ident,
|
||||
ident_country_code: ident_cc,
|
||||
# ident_type: 'priv',
|
||||
retrieved_on: Time.now,
|
||||
associated_businesses: business_ident
|
||||
}
|
||||
rescue Savon::SOAPFault => fault
|
||||
Rails.logger.error "[Ariregister] #{fault} Äriregister arireg #{self.class.username} at #{self.class.host }"
|
||||
raise NotAvailableError.new(exception: fault)
|
||||
rescue HTTPI::SSLError => ssl_error
|
||||
Rails.logger.error "[Ariregister] #{ssl_error} at #{self.class.host}"
|
||||
raise NotAvailableError.new(exception: ssl_error)
|
||||
rescue SocketError => sock
|
||||
Rails.logger.error "[Ariregister] #{sock}"
|
||||
raise NotAvailableError.new(exception: sock)
|
||||
end
|
||||
end
|
||||
|
||||
def debug
|
||||
@client.globals.log_level :debug
|
||||
@client.globals.log true
|
||||
@client.globals.pretty_print_xml true
|
||||
@debug = true
|
||||
@client
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# add required elements to request
|
||||
def body(args)
|
||||
if @session.nil?
|
||||
args['ariregister_kasutajanimi'] = self.class.username
|
||||
args['ariregister_parool'] = self.class.password
|
||||
else
|
||||
args['ariregister_sessioon'] = @session
|
||||
end
|
||||
{keha: args}
|
||||
end
|
||||
|
||||
# TLA --- three letter acronym required not two letter acronym, transform
|
||||
def country_code_3(code)
|
||||
if code.length == 2
|
||||
code = CC2X3[code]
|
||||
raise NotAvailableError.new(message: 'Unrecognized Country') if code.nil?
|
||||
end
|
||||
code
|
||||
end
|
||||
|
||||
def extract(response, element)
|
||||
# response envelope body has again header/body under element; header is user and password returned
|
||||
response.hash[:envelope][:body][element][:keha]
|
||||
end
|
||||
|
||||
def items(content, parent)
|
||||
items = content[parent][:item]
|
||||
items.is_a?(Array) ? items : [items]
|
||||
end
|
||||
|
||||
CC2X3 = {"AF"=>"AFG", "AX"=>"ALA", "AL"=>"ALB", "DZ"=>"DZA", "AS"=>"ASM",
|
||||
"AD"=>"AND", "AO"=>"AGO", "AI"=>"AIA", "AQ"=>"ATA", "AG"=>"ATG",
|
||||
"AR"=>"ARG", "AM"=>"ARM", "AW"=>"ABW", "AU"=>"AUS", "AT"=>"AUT",
|
||||
"AZ"=>"AZE", "BS"=>"BHS", "BH"=>"BHR", "BD"=>"BGD", "BB"=>"BRB",
|
||||
"BY"=>"BLR", "BE"=>"BEL", "BZ"=>"BLZ", "BJ"=>"BEN", "BM"=>"BMU",
|
||||
"BT"=>"BTN", "BO"=>"BOL", "BQ"=>"BES", "BA"=>"BIH", "BW"=>"BWA",
|
||||
"BV"=>"BVT", "BR"=>"BRA", "IO"=>"IOT", "BN"=>"BRN", "BG"=>"BGR",
|
||||
"BF"=>"BFA", "BI"=>"BDI", "CV"=>"CPV", "KH"=>"KHM", "CM"=>"CMR",
|
||||
"CA"=>"CAN", "KY"=>"CYM", "CF"=>"CAF", "TD"=>"TCD", "CL"=>"CHL",
|
||||
"CN"=>"CHN", "CX"=>"CXR", "CC"=>"CCK", "CO"=>"COL", "KM"=>"COM",
|
||||
"CD"=>"COD", "CG"=>"COG", "CK"=>"COK", "CR"=>"CRI", "CI"=>"CIV",
|
||||
"HR"=>"HRV", "CU"=>"CUB", "CW"=>"CUW", "CY"=>"CYP", "CZ"=>"CZE",
|
||||
"DK"=>"DNK", "DJ"=>"DJI", "DM"=>"DMA", "DO"=>"DOM", "EC"=>"ECU",
|
||||
"EG"=>"EGY", "SV"=>"SLV", "GQ"=>"GNQ", "ER"=>"ERI", "EE"=>"EST",
|
||||
"ET"=>"ETH", "FK"=>"FLK", "FO"=>"FRO", "FJ"=>"FJI", "FI"=>"FIN",
|
||||
"FR"=>"FRA", "GF"=>"GUF", "PF"=>"PYF", "TF"=>"ATF", "GA"=>"GAB",
|
||||
"GM"=>"GMB", "GE"=>"GEO", "DE"=>"DEU", "GH"=>"GHA", "GI"=>"GIB",
|
||||
"GR"=>"GRC", "GL"=>"GRL", "GD"=>"GRD", "GP"=>"GLP", "GU"=>"GUM",
|
||||
"GT"=>"GTM", "GG"=>"GGY", "GN"=>"GIN", "GW"=>"GNB", "GY"=>"GUY",
|
||||
"HT"=>"HTI", "HM"=>"HMD", "VA"=>"VAT", "HN"=>"HND", "HK"=>"HKG",
|
||||
"HU"=>"HUN", "IS"=>"ISL", "IN"=>"IND", "ID"=>"IDN", "IR"=>"IRN",
|
||||
"IQ"=>"IRQ", "IE"=>"IRL", "IM"=>"IMN", "IL"=>"ISR", "IT"=>"ITA",
|
||||
"JM"=>"JAM", "JP"=>"JPN", "JE"=>"JEY", "JO"=>"JOR", "KZ"=>"KAZ",
|
||||
"KE"=>"KEN", "KI"=>"KIR", "KP"=>"PRK", "KR"=>"KOR", "KW"=>"KWT",
|
||||
"KG"=>"KGZ", "LA"=>"LAO", "LV"=>"LVA", "LB"=>"LBN", "LS"=>"LSO",
|
||||
"LR"=>"LBR", "LY"=>"LBY", "LI"=>"LIE", "LT"=>"LTU", "LU"=>"LUX",
|
||||
"MO"=>"MAC", "MK"=>"MKD", "MG"=>"MDG", "MW"=>"MWI", "MY"=>"MYS",
|
||||
"MV"=>"MDV", "ML"=>"MLI", "MT"=>"MLT", "MH"=>"MHL", "MQ"=>"MTQ",
|
||||
"MR"=>"MRT", "MU"=>"MUS", "YT"=>"MYT", "MX"=>"MEX", "FM"=>"FSM",
|
||||
"MD"=>"MDA", "MC"=>"MCO", "MN"=>"MNG", "ME"=>"MNE", "MS"=>"MSR",
|
||||
"MA"=>"MAR", "MZ"=>"MOZ", "MM"=>"MMR", "NA"=>"NAM", "NR"=>"NRU",
|
||||
"NP"=>"NPL", "NL"=>"NLD", "NC"=>"NCL", "NZ"=>"NZL", "NI"=>"NIC",
|
||||
"NE"=>"NER", "NG"=>"NGA", "NU"=>"NIU", "NF"=>"NFK", "MP"=>"MNP",
|
||||
"NO"=>"NOR", "OM"=>"OMN", "PK"=>"PAK", "PW"=>"PLW", "PS"=>"PSE",
|
||||
"PA"=>"PAN", "PG"=>"PNG", "PY"=>"PRY", "PE"=>"PER", "PH"=>"PHL",
|
||||
"PN"=>"PCN", "PL"=>"POL", "PT"=>"PRT", "PR"=>"PRI", "QA"=>"QAT",
|
||||
"RE"=>"REU", "RO"=>"ROU", "RU"=>"RUS", "RW"=>"RWA", "BL"=>"BLM",
|
||||
"SH"=>"SHN", "KN"=>"KNA", "LC"=>"LCA", "MF"=>"MAF", "PM"=>"SPM",
|
||||
"VC"=>"VCT", "WS"=>"WSM", "SM"=>"SMR", "ST"=>"STP", "SA"=>"SAU",
|
||||
"SN"=>"SEN", "RS"=>"SRB", "SC"=>"SYC", "SL"=>"SLE", "SG"=>"SGP",
|
||||
"SX"=>"SXM", "SK"=>"SVK", "SI"=>"SVN", "SB"=>"SLB", "SO"=>"SOM",
|
||||
"ZA"=>"ZAF", "GS"=>"SGS", "SS"=>"SSD", "ES"=>"ESP", "LK"=>"LKA",
|
||||
"SD"=>"SDN", "SR"=>"SUR", "SJ"=>"SJM", "SZ"=>"SWZ", "SE"=>"SWE",
|
||||
"CH"=>"CHE", "SY"=>"SYR", "TW"=>"TWN", "TJ"=>"TJK", "TZ"=>"TZA",
|
||||
"TH"=>"THA", "TL"=>"TLS", "TG"=>"TGO", "TK"=>"TKL", "TO"=>"TON",
|
||||
"TT"=>"TTO", "TN"=>"TUN", "TR"=>"TUR", "TM"=>"TKM", "TC"=>"TCA",
|
||||
"TV"=>"TUV", "UG"=>"UGA", "UA"=>"UKR", "AE"=>"ARE", "GB"=>"GBR",
|
||||
"UM"=>"UMI", "US"=>"USA", "UY"=>"URY", "UZ"=>"UZB", "VU"=>"VUT",
|
||||
"VE"=>"VEN", "VN"=>"VNM", "VG"=>"VGB", "VI"=>"VIR", "WF"=>"WLF",
|
||||
"EH"=>"ESH", "YE"=>"YEM", "ZM"=>"ZMB", "ZW"=>"ZWE"}
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue