Skip to content

Commit a0617a4

Browse files
committed
Support multiple dns roots
1 parent c94c8a0 commit a0617a4

File tree

9 files changed

+159
-233
lines changed

9 files changed

+159
-233
lines changed

docs/manage/tpl/vendor/form.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<small>Contact <a href="[email protected]">[email protected]</a> for help.</small>
1313
</div>
1414
[% END %]
15-
<input type="text" class="text" name="zone_name" value="[% vz.zone_name | html %]" id="name" size="40" maxsize="50">
15+
<input type="text" class="text" name="zone_name" value="[% vz.zone_name | html %]" id="name" size="18" maxsize="50">
16+
.[% vz.dns_root.origin || dns_roots.0.origin %]
1617

1718
<br/>
1819
<br>
@@ -23,7 +24,9 @@
2324
<br>
2425

2526
<b>Vendor zone information</b><br>
26-
What devices will use the pool? How often will they poll? (only visible to the NTP Pool admins)<br>
27+
What devices will use the pool? How often will they poll?
28+
Please read the <a href="[% combust.www_url("/vendors.html") %]">vendor zone information faq</a>.
29+
(only visible to the NTP Pool admins)<br>
2730
[% IF errors.request_information %]<div class="error">[% errors.request_information | html %]</div>[% END %]
2831
<textarea name="request_information" rows="12" cols="65">[% vz.request_information | html %]</textarea>
2932

docs/manage/tpl/vendor/submitted.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[% PROCESS tpl/manage/navigation.html %]
2+
<div class="block">
13

24
<h3>Vendor Zone Application Submitted</h3>
35

@@ -14,3 +16,4 @@ <h3>Vendor Zone Application Submitted</h3>
1416
<a href="/manage/vendor">Back to your zones</a>
1517
</p>
1618

19+
</div>

header

Lines changed: 0 additions & 60 deletions
This file was deleted.

lib/NP/DB/ConventionManager.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ my %not_a_map_table;
1515
@not_a_map_table{qw(
1616
log_scores
1717
server_scores
18+
vendor_zones
19+
dns_roots
1820
)} = ();
1921

2022
sub looks_like_map_table {

lib/NP/Model.pm

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,54 @@ BEGIN {
3636
our $VERSION = 0;
3737
}
3838

39+
{ package NP::Model::DnsRoot;
40+
41+
use strict;
42+
43+
use base qw(NP::Model::_Object);
44+
45+
__PACKAGE__->meta->setup(
46+
table => 'dns_roots',
47+
48+
columns => [
49+
id => { type => 'serial', not_null => 1 },
50+
origin => { type => 'varchar', length => 255, not_null => 1 },
51+
vendor_available => { type => 'integer', default => '0', not_null => 1 },
52+
general_use => { type => 'integer', default => '0', not_null => 1 },
53+
ns_list => { type => 'varchar', length => 255, not_null => 1 },
54+
],
55+
56+
primary_key_columns => [ 'id' ],
57+
58+
unique_key => [ 'origin' ],
59+
60+
relationships => [
61+
vendor_zones => {
62+
class => 'NP::Model::VendorZone',
63+
column_map => { id => 'dns_root_id' },
64+
type => 'one to many',
65+
},
66+
],
67+
);
68+
69+
push @table_classes, __PACKAGE__;
70+
}
71+
72+
{ package NP::Model::DnsRoot::Manager;
73+
74+
use strict;
75+
76+
our @ISA = qw(Combust::RoseDB::Manager);
77+
78+
sub object_class { 'NP::Model::DnsRoot' }
79+
80+
__PACKAGE__->make_manager_methods('dns_roots');
81+
}
82+
83+
# Allow user defined methods to be added
84+
eval { require NP::Model::DnsRoot }
85+
or $@ !~ m:^Can't locate NP/Model/DnsRoot.pm: and die $@;
86+
3987
{ package NP::Model::Log;
4088

4189
use strict;
@@ -782,7 +830,6 @@ __PACKAGE__->meta->setup(
782830
status => { type => 'enum', check_in => [ 'New', 'Pending', 'Approved', 'Rejected' ], default => 'New', not_null => 1 },
783831
user_id => { type => 'integer' },
784832
organization_name => { type => 'varchar', length => 255 },
785-
dns_root => { type => 'varchar', length => 255 },
786833
client_type => { type => 'enum', check_in => [ 'ntp', 'sntp', 'all' ], default => 'ntp', not_null => 1 },
787834
contact_information => { type => 'text', length => 65535 },
788835
request_information => { type => 'text', length => 65535 },
@@ -791,13 +838,19 @@ __PACKAGE__->meta->setup(
791838
approved_on => { type => 'datetime' },
792839
created_on => { type => 'datetime', default => 'now', not_null => 1 },
793840
modified_on => { type => 'timestamp', not_null => 1 },
841+
dns_root_id => { type => 'integer', not_null => 1 },
794842
],
795843

796844
primary_key_columns => [ 'id' ],
797845

798-
unique_key => [ 'zone_name' ],
846+
unique_key => [ 'zone_name', 'dns_root_id' ],
799847

800848
foreign_keys => [
849+
dns_root => {
850+
class => 'NP::Model::DnsRoot',
851+
key_columns => { dns_root_id => 'id' },
852+
},
853+
801854
user => {
802855
class => 'NP::Model::User',
803856
key_columns => { user_id => 'id' },
@@ -957,6 +1010,7 @@ eval { require NP::Model::ZoneServerCount }
9571010
$_->clear_object_cache for @cache_classes;
9581011
}
9591012

1013+
sub dns_root { our $dns_root ||= bless [], 'NP::Model::DnsRoot::Manager' }
9601014
sub log { our $log ||= bless [], 'NP::Model::Log::Manager' }
9611015
sub log_score { our $log_score ||= bless [], 'NP::Model::LogScore::Manager' }
9621016
sub monitor { our $monitor ||= bless [], 'NP::Model::Monitor::Manager' }

lib/NP/Model/VendorZone.pm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ my %reserved_zone_names = map { $_ => 1 }
1111
asia
1212
africa
1313
14+
root
1415
ntppool
1516
vendor
1617
);
@@ -29,9 +30,12 @@ sub validate {
2930
$errors->{zone_name} = 'That zone name is in use or reserved.';
3031
}
3132

32-
if (my $vz2 = NP::Model->vendor_zone->fetch(zone_name => $vz->zone_name)) {
33-
unless ($vz and $vz->id == $vz2->id) {
34-
$errors->{zone_name} = 'That zone name is already used in an application.';
33+
{
34+
my $vz2 = NP::Model->vendor_zone->get_objects(query => [zone_name => $vz->zone_name]);
35+
if (@$vz2) {
36+
unless ($vz and grep { $vz->id == $_->id } @$vz2) {
37+
$errors->{zone_name} = 'That zone name is already used.';
38+
}
3539
}
3640
}
3741

lib/NTPPool/Control/Vendor.pm

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ sub manage_dispatch {
3232
sub render_form {
3333
my $self = shift;
3434
my $vz = shift;
35-
$self->tpl_param('vz', $vz) if ($vz);
35+
$self->tpl_param('vz', $vz) if $vz;
36+
if ($vz) {
37+
$self->tpl_param('dns_roots', [$vz->dns_root]);
38+
}
39+
else {
40+
$self->tpl_param('dns_roots', NP::Model->dns_root->get_objects(query => [vendor_available => 1]));
41+
}
42+
3643
return OK, $self->evaluate_template('tpl/vendor/form.html');
3744
}
3845

@@ -86,8 +93,6 @@ sub render_submit {
8693
return OK, $self->evaluate_template('tpl/vendor/submitted.html');
8794
}
8895

89-
90-
9196
sub render_edit {
9297
my $self = shift;
9398

@@ -110,9 +115,14 @@ sub render_edit {
110115
}
111116
}
112117
else {
118+
119+
# TODO: If we ever have more than one public dns_root, be smarter here.
120+
my $dns_root = (NP::Model->dns_root->get_objects(query => [vendor_available => 1], limit => 1))->[0];
121+
113122
$vz = NP::Model->vendor_zone->create
114123
( zone_name => $zone_name,
115124
user_id => $self->user->id,
125+
dns_root => $dns_root->id,
116126
(map { $_ => ($self->req_param($_) || '')
117127
} qw(organization_name request_information contact_information device_count)
118128
)
@@ -128,7 +138,6 @@ sub render_edit {
128138
$vz->save;
129139

130140
return $self->render_zone($vz->id, 'show');
131-
132141
}
133142

134143
sub render_admin {

0 commit comments

Comments
 (0)