mirror of
https://github.com/internetee/registry.git
synced 2025-07-13 14:35:05 +02:00
Merge branch 'master' of github.com:internetee/registry
Conflicts: db/schema.rb
This commit is contained in:
commit
907ef1edf7
33 changed files with 629 additions and 288 deletions
41
db/migrate/20141120110330_create_zonefile_setting.rb
Normal file
41
db/migrate/20141120110330_create_zonefile_setting.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
class CreateZonefileSetting < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :zonefile_settings do |t|
|
||||
t.string :origin
|
||||
t.integer :ttl
|
||||
t.integer :refresh
|
||||
t.integer :retry
|
||||
t.integer :expire
|
||||
t.integer :minimum_ttl
|
||||
t.string :email
|
||||
t.string :master_nameserver
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
# rubocop: disable Style/NumericLiterals
|
||||
ZonefileSetting.create({
|
||||
origin: 'ee',
|
||||
ttl: 43200,
|
||||
refresh: 3600,
|
||||
retry: 900,
|
||||
expire: 1209600,
|
||||
minimum_ttl: 3600,
|
||||
email: 'hostmaster.eestiinternet.ee',
|
||||
master_nameserver: 'ns.tld.ee'
|
||||
})
|
||||
|
||||
ZonefileSetting.create({
|
||||
origin: 'pri.ee',
|
||||
ttl: 43200,
|
||||
refresh: 3600,
|
||||
retry: 900,
|
||||
expire: 1209600,
|
||||
minimum_ttl: 3600,
|
||||
email: 'hostmaster.eestiinternet.ee',
|
||||
master_nameserver: 'ns.tld.ee'
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
76
db/migrate/20141120140837_add_ee_domain_objects.rb
Normal file
76
db/migrate/20141120140837_add_ee_domain_objects.rb
Normal file
|
@ -0,0 +1,76 @@
|
|||
class AddEeDomainObjects < ActiveRecord::Migration
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def up
|
||||
r = Registrar.create!(
|
||||
name: 'EIS',
|
||||
reg_no: '123321',
|
||||
address: 'Tallinn',
|
||||
country: Country.estonia
|
||||
)
|
||||
|
||||
c = Contact.create!(
|
||||
name: 'EIS',
|
||||
phone: '+372.123321',
|
||||
email: 'info@testing.ee',
|
||||
ident: '123321',
|
||||
ident_type: 'ico',
|
||||
address: Address.create(
|
||||
city: 'Tallinn',
|
||||
country: Country.estonia
|
||||
),
|
||||
registrar: r
|
||||
)
|
||||
|
||||
EppUser.create!(
|
||||
registrar: r,
|
||||
username: 'testeis',
|
||||
password: 'testeis',
|
||||
active: true
|
||||
)
|
||||
|
||||
Domain.create!(
|
||||
name: 'ee',
|
||||
valid_to: Date.new(9999, 1, 1),
|
||||
period: 1,
|
||||
period_unit: 'y',
|
||||
owner_contact: c,
|
||||
nameservers: [
|
||||
Nameserver.create(hostname: 'ns.tld.ee', ipv4: '195.43.87.10'),
|
||||
Nameserver.create(hostname: 'b.tld.ee', ipv4: '194.146.106.110', ipv6: '2001:67c:1010:28::53'),
|
||||
Nameserver.create(hostname: 'e.tld.ee', ipv4: '204.61.216.36', ipv6: '2001:678:94:53::53'),
|
||||
Nameserver.create(hostname: 'ee.aso.ee', ipv4: '213.184.51.122', ipv6: '2a02:88:0:21::2'),
|
||||
Nameserver.create(hostname: 'ns.ut.ee', ipv4: '193.40.5.99', ipv6: ''),
|
||||
Nameserver.create(hostname: 'sunic.sunet.se', ipv4: '195.80.103.202')
|
||||
],
|
||||
admin_contacts: [c],
|
||||
registrar: r
|
||||
)
|
||||
|
||||
Domain.create!(
|
||||
name: 'pri.ee',
|
||||
valid_to: Date.new(9999, 1, 1),
|
||||
period: 1,
|
||||
period_unit: 'y',
|
||||
owner_contact: c,
|
||||
nameservers: [
|
||||
Nameserver.create(hostname: 'ns.tld.ee', ipv4: '195.43.87.10'),
|
||||
Nameserver.create(hostname: 'b.tld.ee', ipv4: '194.146.106.110', ipv6: '2001:67c:1010:28::53'),
|
||||
Nameserver.create(hostname: 'e.tld.ee', ipv4: '204.61.216.36', ipv6: '2001:678:94:53::53'),
|
||||
Nameserver.create(hostname: 'ee.aso.ee', ipv4: '213.184.51.122', ipv6: '2a02:88:0:21::2'),
|
||||
Nameserver.create(hostname: 'ns.ut.ee', ipv4: '193.40.5.99', ipv6: ''),
|
||||
Nameserver.create(hostname: 'sunic.sunet.se', ipv4: '195.80.103.202')
|
||||
],
|
||||
admin_contacts: [c],
|
||||
registrar: r
|
||||
)
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def down
|
||||
Domain.find_by(name: 'ee').destroy
|
||||
Domain.find_by(name: 'pri.ee').destroy
|
||||
EppUser.find_by(username: 'testeis').destroy
|
||||
Contact.find_by(name: 'EIS').destroy
|
||||
Registrar.find_by(name: 'EIS').destroy
|
||||
end
|
||||
end
|
117
db/migrate/20141121093125_add_zonefile_procedure.rb
Normal file
117
db/migrate/20141121093125_add_zonefile_procedure.rb
Normal file
|
@ -0,0 +1,117 @@
|
|||
class AddZonefileProcedure < ActiveRecord::Migration
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def up
|
||||
execute <<-SQL
|
||||
CREATE OR REPLACE FUNCTION generate_zonefile(i_origin varchar)
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
zone_header text := concat('$ORIGIN ', i_origin, '.');
|
||||
include_filter varchar := '';
|
||||
exclude_filter varchar := '';
|
||||
ns_records text := '';
|
||||
a_records text := '';
|
||||
a4_records text := '';
|
||||
ds_records text := '';
|
||||
BEGIN
|
||||
-- define filters
|
||||
include_filter = '%' || i_origin;
|
||||
|
||||
-- for %.%.%
|
||||
IF i_origin ~ '\\.' THEN
|
||||
exclude_filter := '';
|
||||
-- for %.%
|
||||
ELSE
|
||||
exclude_filter := '%.%.' || i_origin;
|
||||
END IF;
|
||||
|
||||
-- zonefile header
|
||||
SELECT concat(
|
||||
format('%-10s', '$ORIGIN'), i_origin, '.', chr(10),
|
||||
format('%-10s', '$TTL'), zf.ttl, chr(10), chr(10),
|
||||
format('%-10s', i_origin || '.'), 'IN SOA ', zf.master_nameserver, '. ', zf.email, '. (', chr(10),
|
||||
format('%-17s', ''), format('%-12s', '2014111210'), '; serial number', chr(10),
|
||||
format('%-17s', ''), format('%-12s', zf.refresh), '; refresh, seconds', chr(10),
|
||||
format('%-17s', ''), format('%-12s', zf.retry), '; retry, seconds', chr(10),
|
||||
format('%-17s', ''), format('%-12s', zf.expire), '; expire, seconds', chr(10),
|
||||
format('%-17s', ''), format('%-12s', zf.minimum_ttl), '; minimum TTL, seconds', chr(10),
|
||||
format('%-17s', ''), ')'
|
||||
) FROM zonefile_settings zf WHERE i_origin = zf.origin INTO zone_header;
|
||||
|
||||
-- ns records
|
||||
SELECT array_to_string(
|
||||
array(
|
||||
SELECT concat(d.name, '. IN NS ', ns.hostname, '.')
|
||||
FROM domains d
|
||||
JOIN nameservers ns ON ns.domain_id = d.id
|
||||
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
|
||||
ORDER BY
|
||||
CASE d.name
|
||||
WHEN i_origin THEN 1
|
||||
END
|
||||
),
|
||||
chr(10)
|
||||
) INTO ns_records;
|
||||
|
||||
-- a records
|
||||
SELECT array_to_string(
|
||||
array(
|
||||
SELECT concat(cns.hostname, '. IN A ', cns.ipv4, '.') FROM cached_nameservers cns WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM nameservers ns
|
||||
JOIN domains d ON d.id = ns.domain_id
|
||||
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
|
||||
AND ns.hostname = cns.hostname AND ns.ipv4 = cns.ipv4 AND ns.ipv6 = cns.ipv6
|
||||
AND ns.ipv4 IS NOT NULL AND ns.ipv4 <> ''
|
||||
)
|
||||
),
|
||||
chr(10)
|
||||
) INTO a_records;
|
||||
|
||||
-- aaaa records
|
||||
SELECT array_to_string(
|
||||
array(
|
||||
SELECT concat(cns.hostname, '. IN AAAA ', cns.ipv6, '.') FROM cached_nameservers cns WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM nameservers ns
|
||||
JOIN domains d ON d.id = ns.domain_id
|
||||
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
|
||||
AND ns.hostname = cns.hostname AND ns.ipv6 = cns.ipv6 AND ns.ipv6 = cns.ipv6
|
||||
AND ns.ipv6 IS NOT NULL AND ns.ipv6 <> ''
|
||||
)
|
||||
),
|
||||
chr(10)
|
||||
) INTO a4_records;
|
||||
|
||||
-- ds records
|
||||
SELECT array_to_string(
|
||||
array(
|
||||
SELECT concat(
|
||||
d.name, '. 86400 IN DS ', dk.ds_key_tag, ' ',
|
||||
dk.ds_alg, ' ', dk.ds_digest_type, ' ', dk.ds_digest
|
||||
)
|
||||
FROM domains d
|
||||
JOIN dnskeys dk ON dk.domain_id = d.id
|
||||
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
|
||||
),
|
||||
chr(10)
|
||||
) INTO ds_records;
|
||||
|
||||
RETURN concat(
|
||||
zone_header, chr(10), chr(10),
|
||||
'; Zone NS Records', chr(10), ns_records, chr(10), chr(10),
|
||||
'; Zone A Records', chr(10), a_records, chr(10), chr(10),
|
||||
'; Zone AAAA Records', chr(10), a4_records, chr(10), chr(10),
|
||||
'; Zone DS Records', chr(10), ds_records
|
||||
);
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql;
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
execute <<-SQL
|
||||
DROP FUNCTION generate_zonefile(i_origin varchar);
|
||||
SQL
|
||||
end
|
||||
end
|
20
db/migrate/20141125111414_create_nameservers_cache.rb
Normal file
20
db/migrate/20141125111414_create_nameservers_cache.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
class CreateNameserversCache < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :cached_nameservers, id: false do |t|
|
||||
t.string :hostname
|
||||
t.string :ipv4
|
||||
t.string :ipv6
|
||||
end
|
||||
add_index :cached_nameservers, [:hostname, :ipv4, :ipv6], unique: true
|
||||
|
||||
execute <<-SQL
|
||||
INSERT INTO cached_nameservers (
|
||||
SELECT ns.hostname, ns.ipv4, ns.ipv6 FROM nameservers ns GROUP BY ns.hostname, ns.ipv4, ns.ipv6
|
||||
);
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :cached_nameservers
|
||||
end
|
||||
end
|
120
db/migrate/20141126140434_add_serial_to_zonefile_procedure.rb
Normal file
120
db/migrate/20141126140434_add_serial_to_zonefile_procedure.rb
Normal file
|
@ -0,0 +1,120 @@
|
|||
class AddSerialToZonefileProcedure < ActiveRecord::Migration
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def up
|
||||
execute <<-SQL
|
||||
CREATE OR REPLACE FUNCTION generate_zonefile(i_origin varchar)
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
zone_header text := concat('$ORIGIN ', i_origin, '.');
|
||||
serial_num varchar;
|
||||
include_filter varchar := '';
|
||||
exclude_filter varchar := '';
|
||||
ns_records text := '';
|
||||
a_records text := '';
|
||||
a4_records text := '';
|
||||
ds_records text := '';
|
||||
BEGIN
|
||||
-- define filters
|
||||
include_filter = '%' || i_origin;
|
||||
|
||||
-- for %.%.%
|
||||
IF i_origin ~ '\\.' THEN
|
||||
exclude_filter := '';
|
||||
-- for %.%
|
||||
ELSE
|
||||
exclude_filter := '%.%.' || i_origin;
|
||||
END IF;
|
||||
|
||||
SELECT ROUND(extract(epoch from now() at time zone 'utc')) INTO serial_num;
|
||||
|
||||
-- zonefile header
|
||||
SELECT concat(
|
||||
format('%-10s', '$ORIGIN'), i_origin, '.', chr(10),
|
||||
format('%-10s', '$TTL'), zf.ttl, chr(10), chr(10),
|
||||
format('%-10s', i_origin || '.'), 'IN SOA ', zf.master_nameserver, '. ', zf.email, '. (', chr(10),
|
||||
format('%-17s', ''), format('%-12s', serial_num), '; serial number', chr(10),
|
||||
format('%-17s', ''), format('%-12s', zf.refresh), '; refresh, seconds', chr(10),
|
||||
format('%-17s', ''), format('%-12s', zf.retry), '; retry, seconds', chr(10),
|
||||
format('%-17s', ''), format('%-12s', zf.expire), '; expire, seconds', chr(10),
|
||||
format('%-17s', ''), format('%-12s', zf.minimum_ttl), '; minimum TTL, seconds', chr(10),
|
||||
format('%-17s', ''), ')'
|
||||
) FROM zonefile_settings zf WHERE i_origin = zf.origin INTO zone_header;
|
||||
|
||||
-- ns records
|
||||
SELECT array_to_string(
|
||||
array(
|
||||
SELECT concat(d.name, '. IN NS ', ns.hostname, '.')
|
||||
FROM domains d
|
||||
JOIN nameservers ns ON ns.domain_id = d.id
|
||||
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
|
||||
ORDER BY
|
||||
CASE d.name
|
||||
WHEN i_origin THEN 1
|
||||
END
|
||||
),
|
||||
chr(10)
|
||||
) INTO ns_records;
|
||||
|
||||
-- a records
|
||||
SELECT array_to_string(
|
||||
array(
|
||||
SELECT concat(cns.hostname, '. IN A ', cns.ipv4, '.') FROM cached_nameservers cns WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM nameservers ns
|
||||
JOIN domains d ON d.id = ns.domain_id
|
||||
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
|
||||
AND ns.hostname = cns.hostname AND ns.ipv4 = cns.ipv4 AND ns.ipv6 = cns.ipv6
|
||||
AND ns.ipv4 IS NOT NULL AND ns.ipv4 <> ''
|
||||
)
|
||||
),
|
||||
chr(10)
|
||||
) INTO a_records;
|
||||
|
||||
-- aaaa records
|
||||
SELECT array_to_string(
|
||||
array(
|
||||
SELECT concat(cns.hostname, '. IN AAAA ', cns.ipv6, '.') FROM cached_nameservers cns WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM nameservers ns
|
||||
JOIN domains d ON d.id = ns.domain_id
|
||||
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
|
||||
AND ns.hostname = cns.hostname AND ns.ipv6 = cns.ipv6 AND ns.ipv6 = cns.ipv6
|
||||
AND ns.ipv6 IS NOT NULL AND ns.ipv6 <> ''
|
||||
)
|
||||
),
|
||||
chr(10)
|
||||
) INTO a4_records;
|
||||
|
||||
-- ds records
|
||||
SELECT array_to_string(
|
||||
array(
|
||||
SELECT concat(
|
||||
d.name, '. 86400 IN DS ', dk.ds_key_tag, ' ',
|
||||
dk.ds_alg, ' ', dk.ds_digest_type, ' ', dk.ds_digest
|
||||
)
|
||||
FROM domains d
|
||||
JOIN dnskeys dk ON dk.domain_id = d.id
|
||||
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
|
||||
),
|
||||
chr(10)
|
||||
) INTO ds_records;
|
||||
|
||||
RETURN concat(
|
||||
zone_header, chr(10), chr(10),
|
||||
'; Zone NS Records', chr(10), ns_records, chr(10), chr(10),
|
||||
'; Zone A Records', chr(10), a_records, chr(10), chr(10),
|
||||
'; Zone AAAA Records', chr(10), a4_records, chr(10), chr(10),
|
||||
'; Zone DS Records', chr(10), ds_records
|
||||
);
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql;
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
execute <<-SQL
|
||||
DROP FUNCTION generate_zonefile(i_origin varchar);
|
||||
SQL
|
||||
end
|
||||
end
|
21
db/schema.rb
21
db/schema.rb
|
@ -39,6 +39,14 @@ ActiveRecord::Schema.define(version: 20141127091027) do
|
|||
t.string "street3"
|
||||
end
|
||||
|
||||
create_table "cached_nameservers", id: false, force: true do |t|
|
||||
t.string "hostname"
|
||||
t.string "ipv4"
|
||||
t.string "ipv6"
|
||||
end
|
||||
|
||||
add_index "cached_nameservers", ["hostname", "ipv4", "ipv6"], name: "index_cached_nameservers_on_hostname_and_ipv4_and_ipv6", unique: true, using: :btree
|
||||
|
||||
create_table "contact_disclosures", force: true do |t|
|
||||
t.integer "contact_id"
|
||||
t.boolean "phone"
|
||||
|
@ -332,4 +340,17 @@ ActiveRecord::Schema.define(version: 20141127091027) do
|
|||
|
||||
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
|
||||
|
||||
create_table "zonefile_settings", force: true do |t|
|
||||
t.string "origin"
|
||||
t.integer "ttl"
|
||||
t.integer "refresh"
|
||||
t.integer "retry"
|
||||
t.integer "expire"
|
||||
t.integer "minimum_ttl"
|
||||
t.string "email"
|
||||
t.string "master_nameserver"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
12
db/seeds.rb
12
db/seeds.rb
|
@ -9,7 +9,7 @@
|
|||
Country.where(name: 'Estonia', iso: 'EE').first_or_create!
|
||||
Country.where(name: 'Latvia', iso: 'LV').first_or_create!
|
||||
|
||||
zone = Registrar.where(
|
||||
registrar1 = Registrar.where(
|
||||
name: 'Registrar First AS',
|
||||
reg_no: '10300220',
|
||||
address: 'Pärnu mnt 2, Tallinna linn, Harju maakond, 11415',
|
||||
|
@ -20,10 +20,10 @@ EppUser.where(
|
|||
username: 'registrar1',
|
||||
password: 'test1',
|
||||
active: true,
|
||||
registrar: zone
|
||||
registrar: registrar1
|
||||
).first_or_create
|
||||
|
||||
elkdata = Registrar.where(
|
||||
registrar2 = Registrar.where(
|
||||
name: 'Registrar Second AS',
|
||||
reg_no: '10529229',
|
||||
address: 'Vabaduse pst 32, 11316 Tallinn',
|
||||
|
@ -34,7 +34,7 @@ EppUser.where(
|
|||
username: 'registrar2',
|
||||
password: 'test2',
|
||||
active: true,
|
||||
registrar: elkdata
|
||||
registrar: registrar2
|
||||
).first_or_create
|
||||
|
||||
User.where(
|
||||
|
@ -52,7 +52,7 @@ User.where(
|
|||
email: 'user2@example.ee',
|
||||
admin: false,
|
||||
identity_code: '37810010085',
|
||||
registrar_id: zone.id,
|
||||
registrar_id: registrar1.id,
|
||||
country: Country.where(name: 'Estonia').first
|
||||
).first_or_create
|
||||
|
||||
|
@ -62,7 +62,7 @@ User.where(
|
|||
email: 'user3@example.ee',
|
||||
admin: false,
|
||||
identity_code: '37810010727',
|
||||
registrar_id: elkdata.id,
|
||||
registrar_id: registrar2.id,
|
||||
country: Country.where(name: 'Estonia').first
|
||||
).first_or_create
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue