mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 01:11:43 +02:00
Add zonefile generation procedure
This commit is contained in:
parent
f5ce88b548
commit
ac4b63f390
23 changed files with 370 additions and 255 deletions
|
@ -27,11 +27,6 @@ class Admin::DomainsController < AdminController
|
|||
end
|
||||
end
|
||||
|
||||
def zonefile
|
||||
@zonefile = @domain.generate_zonefile
|
||||
# send_data @zonefile, filename: 'bla.txt'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_domain
|
||||
|
|
30
app/controllers/admin/zonefile_settings_controller.rb
Normal file
30
app/controllers/admin/zonefile_settings_controller.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
class Admin::ZonefileSettingsController < ApplicationController
|
||||
before_action :set_zonefile_setting, only: [:update, :edit]
|
||||
def index
|
||||
@zonefile_settings = ZonefileSetting.all
|
||||
end
|
||||
|
||||
def edit
|
||||
@zonefile_setting = ZonefileSetting.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
if @zonefile_setting.update(zonefile_setting_params)
|
||||
flash[:notice] = I18n.t('shared.record_updated')
|
||||
redirect_to admin_zonefile_settings_path
|
||||
else
|
||||
flash.now[:alert] = I18n.t('shared.failed_to_update_record')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_zonefile_setting
|
||||
@zonefile_setting = ZonefileSetting.find(params[:id])
|
||||
end
|
||||
|
||||
def zonefile_setting_params
|
||||
params.require(:zonefile_setting).permit(:ttl, :refresh, :retry, :expire, :minimum_ttl, :email)
|
||||
end
|
||||
end
|
|
@ -2,44 +2,7 @@ class Admin::ZonefilesController < ApplicationController
|
|||
# TODO: Refactor this
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def index
|
||||
zf = Zonefile.new
|
||||
|
||||
zf.origin = 'ee.'
|
||||
zf.ttl = '43200'
|
||||
|
||||
zf.soa[:primary_ns] = 'ns.tld.ee.'
|
||||
zf.soa[:email] = 'hostmaster.eestiinternet.ee.'
|
||||
zf.soa[:origin] = 'ee.'
|
||||
zf.soa[:refresh] = '3600'
|
||||
zf.soa[:retry] = '900'
|
||||
zf.soa[:expire] = '1209600'
|
||||
zf.soa[:minimumTTL] = '3600'
|
||||
zf.new_serial
|
||||
|
||||
zf.ns << { name: 'ee.', class: 'IN', host: 'b.tld.ee.' }
|
||||
zf.ns << { name: 'ee.', class: 'IN', host: 'e.tld.ee.' }
|
||||
zf.ns << { name: 'ee.', class: 'IN', host: 'ee.aso.ee.' }
|
||||
zf.ns << { name: 'ee.', class: 'IN', host: 'ns.ut.ee.' }
|
||||
zf.ns << { name: 'ee.', class: 'IN', host: 'ns.tld.ee.' }
|
||||
zf.ns << { name: 'ee.', class: 'IN', host: 'sunic.sunet.se.' }
|
||||
|
||||
zf.a << { name: 'b.tld.ee.', class: 'IN', host: '194.146.106.110' }
|
||||
zf.a4 << { name: 'b.tld.ee.', class: 'IN', host: '2001:67c:1010:28::53' }
|
||||
zf.a << { name: 'e.tld.ee.', class: 'IN', host: '204.61.216.36' }
|
||||
zf.a4 << { name: 'e.tld.ee.', class: 'IN', host: '2001:678:94:53::53' }
|
||||
zf.a << { name: 'ee.aso.ee.', class: 'IN', host: '213.184.51.122' }
|
||||
zf.a4 << { name: 'ee.aso.ee.', class: 'IN', host: '2a02:88:0:21::2' }
|
||||
zf.a << { name: 'ns.ut.ee.', class: 'IN', host: '193.40.5.99' }
|
||||
zf.a << { name: 'ns.tld.ee.', class: 'IN', host: '195.43.87.10' }
|
||||
zf.a << { name: 'sunic.sunet.se.', class: 'IN', host: '192.36.125.2' }
|
||||
zf.a4 << { name: 'sunic.sunet.se.', class: 'IN', host: '2001:6b0:7::2' }
|
||||
|
||||
Nameserver.all.includes(:domain).each do |x|
|
||||
zf.ns << { name: "#{x.domain_name}.", class: 'IN', host: "#{x.hostname}." }
|
||||
zf.a << { name: "#{x.hostname}.", class: 'IN', host: x.ipv4 } if x.ipv4.present?
|
||||
zf.a4 << { name: "#{x.hostname}.", class: 'IN', host: x.ipv6 } if x.ipv6.present?
|
||||
end
|
||||
|
||||
@zonefile = zf.generate
|
||||
@zonefile = ActiveRecord::Base.connection.execute("select generate_zonefile('ee')")[0]['generate_zonefile']
|
||||
send_data @zonefile, filename: 'zonefile-1000.txt'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,4 +2,10 @@ class Country < ActiveRecord::Base
|
|||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
class << self
|
||||
def estonia
|
||||
find_by(iso: 'EE')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -301,35 +301,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def generate_zonefile
|
||||
zf = Zonefile.new
|
||||
zf.ttl = '3600'
|
||||
zf.origin = "#{name}."
|
||||
ns = nameservers.first
|
||||
zf.soa[:primary_ns] = "#{ns.hostname}."
|
||||
zf.soa[:email] = 'hostmaster.internet.ee'
|
||||
zf.soa[:origin] = "#{name}."
|
||||
zf.soa[:refresh] = '10800'
|
||||
zf.soa[:retry] = '3600'
|
||||
zf.soa[:expire] = '604800'
|
||||
zf.soa[:minimumTTL] = '3600'
|
||||
|
||||
nameservers.each do |x|
|
||||
zf.ns << { name: "#{name}.", class: 'IN', host: "#{x.hostname}." }
|
||||
end
|
||||
|
||||
dnskeys.each do |x|
|
||||
zf.ds << { name: "#{name}.", ttl: '86400', class: 'IN', key_tag: x.ds_key_tag, algorithm: x.ds_alg,
|
||||
digest_type: x.ds_digest_type, digest: x.ds_digest }
|
||||
|
||||
zf.dnskey << { name: "#{name}.", ttl: '86400', class: 'IN', flag: x.flags,
|
||||
protocol: x.protocol, algorithm: x.alg, public_key: x.public_key }
|
||||
end
|
||||
|
||||
zf.new_serial
|
||||
zf.generate
|
||||
end
|
||||
|
||||
class << self
|
||||
def convert_period_to_time(period, unit)
|
||||
return period.to_i.days if unit == 'd'
|
||||
|
|
3
app/models/zonefile.rb
Normal file
3
app/models/zonefile.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Zonefile < ActiveRecord::Base
|
||||
|
||||
end
|
7
app/models/zonefile_setting.rb
Normal file
7
app/models/zonefile_setting.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class ZonefileSetting < ActiveRecord::Base
|
||||
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, presence: true
|
||||
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true }
|
||||
def to_s
|
||||
origin
|
||||
end
|
||||
end
|
|
@ -16,6 +16,7 @@ class DomainNameValidator < ActiveModel::EachValidator
|
|||
|
||||
class << self
|
||||
def validate_format(value)
|
||||
return true if value == 'ee'
|
||||
return true unless value
|
||||
value = value.mb_chars.downcase.strip
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
%tbody
|
||||
- @settings.each do |x|
|
||||
%tr
|
||||
%td= t("shared.#{x.var}")
|
||||
%td= t("#{x.var}")
|
||||
- if [TrueClass, FalseClass].include?(x.value.class)
|
||||
%td
|
||||
= hidden_field_tag("[settings][#{x.var}]", '')
|
||||
|
|
50
app/views/admin/zonefile_settings/edit.haml
Normal file
50
app/views/admin/zonefile_settings/edit.haml
Normal file
|
@ -0,0 +1,50 @@
|
|||
%h2= t('zonefile_settings')
|
||||
%hr
|
||||
= form_for [:admin, @zonefile_setting], html: { class: 'form-horizontal' } do |f|
|
||||
.row
|
||||
.col-md-12
|
||||
#domain-statuses
|
||||
.errors
|
||||
- if f.object.errors.any?
|
||||
- f.object.errors.full_messages.each do |x|
|
||||
= x
|
||||
%br
|
||||
- if f.object.errors.any?
|
||||
%hr
|
||||
.form-group
|
||||
= f.label :origin, class: 'col-md-2 control-label'
|
||||
.col-md-10
|
||||
= f.text_field :origin, class: 'form-control', disabled: true
|
||||
|
||||
.form-group
|
||||
= f.label :ttl, class: 'col-md-2 control-label'
|
||||
.col-md-10
|
||||
= f.text_field :ttl, class: 'form-control'
|
||||
|
||||
.form-group
|
||||
= f.label :refresh, class: 'col-md-2 control-label'
|
||||
.col-md-10
|
||||
= f.text_field :refresh, class: 'form-control'
|
||||
|
||||
.form-group
|
||||
= f.label :retry, class: 'col-md-2 control-label'
|
||||
.col-md-10
|
||||
= f.text_field :retry, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :expire, class: 'col-md-2 control-label'
|
||||
.col-md-10
|
||||
= f.text_field :expire, class: 'form-control'
|
||||
|
||||
.form-group
|
||||
= f.label :minimum_ttl, class: 'col-md-2 control-label'
|
||||
.col-md-10
|
||||
= f.text_field :minimum_ttl, class: 'form-control'
|
||||
|
||||
.form-group
|
||||
= f.label :email, class: 'col-md-2 control-label'
|
||||
.col-md-10
|
||||
= f.text_field :email, class: 'form-control'
|
||||
|
||||
.row
|
||||
.col-md-12.text-right
|
||||
%button.btn.btn-primary=t('shared.save')
|
20
app/views/admin/zonefile_settings/index.haml
Normal file
20
app/views/admin/zonefile_settings/index.haml
Normal file
|
@ -0,0 +1,20 @@
|
|||
.row
|
||||
.col-sm-12
|
||||
%h2.text-center-xs= t('zonefile_settings')
|
||||
%hr
|
||||
.row
|
||||
.col-md-12
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-10'}
|
||||
= t('origin')
|
||||
%th{class: 'col-xs-2'}
|
||||
= t('action')
|
||||
%tbody
|
||||
- @zonefile_settings.each do |x|
|
||||
%tr
|
||||
%td= link_to(x, edit_admin_zonefile_setting_path(x))
|
||||
%td
|
||||
= link_to(t('generate_zonefile'), admin_zonefiles_path, class: 'btn btn-xs btn-primary')
|
|
@ -38,7 +38,7 @@
|
|||
%li
|
||||
= link_to t('shared.settings'), admin_settings_path
|
||||
%li
|
||||
= link_to t('zonefile'), admin_zonefiles_path
|
||||
= link_to t('zonefile'), admin_zonefile_settings_path
|
||||
%li.divider
|
||||
%li.dropdown-header= t('shared.users')
|
||||
%li
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue