forked from .cyb/cyberman
Further record validation cleanup, support for CNAME records
This commit is contained in:
parent
d2499d551f
commit
57a0c8b1e9
|
@ -51,29 +51,17 @@ get '/domains/:name/records/add' => sub {
|
|||
};
|
||||
};
|
||||
|
||||
my %patterns = (
|
||||
"ipv4" => qr/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}$/,
|
||||
"ipv6" => qr/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,
|
||||
"name" => qr/^([a-zA-Z0-9]([a-zA-Z0-9-_]*[a-zA-Z0-9])?\.)+$/,
|
||||
);
|
||||
|
||||
my %tests = ( IN => {
|
||||
# Tests return 1 on invalid value, 0 on valid
|
||||
A => sub {
|
||||
my $val_l = shift;
|
||||
if ($val_l !~ m/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}$/) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
AAAA => sub {
|
||||
my $val_l = shift;
|
||||
if ($val_l !~ m/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
NS => sub {
|
||||
my $val_l = shift;
|
||||
if ($val_l !~ m/^([a-zA-Z0-9]([a-zA-Z0-9-_]*[a-zA-Z0-9])?\.)+$/) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
"A" => "ipv4",
|
||||
"AAAA" => "ipv6",
|
||||
"NS" => "name",
|
||||
"CNAME" => "name",
|
||||
});
|
||||
|
||||
post '/domains/:name/records/add' => sub {
|
||||
|
@ -92,8 +80,10 @@ post '/domains/:name/records/add' => sub {
|
|||
|
||||
my %errs;
|
||||
|
||||
if ( ref($tests{param("type")}) == "CODE" ) {
|
||||
$errs{"e_bad_value"} = 1 if &{$tests{IN}{param("type")}}(param("value"));
|
||||
if ( exists($tests{"IN"}->{param("type")}) ) {
|
||||
if (param("value") !~ m/$patterns{ $tests{"IN"}->{param("type")} }/) {
|
||||
$errs{"e_bad_value"} = 1;
|
||||
}
|
||||
} else {
|
||||
$errs{"e_bad_type"} = 1;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<ul>
|
||||
<% IF e_bad_value %>
|
||||
<li>The value you entered was invalid.
|
||||
<% IF params.type == 'NS' %>(Did you forget the trailing '.'?)<% END %></li>
|
||||
<% IF params.type == 'NS' || params.type == 'CNAME' %>(Did you forget the trailing '.'?)<% END %></li>
|
||||
<% END %>
|
||||
<% IF e_bad_type %>
|
||||
<li>You must choose a type for the record.</li>
|
||||
|
@ -39,7 +39,7 @@
|
|||
</td>
|
||||
<td>
|
||||
<input type="text" style="width: 100px" name="rname" id="rname" placeholder="Use @ for root"
|
||||
value="<% params.rname | html_entity %>" />.<% domain.name | html_entity %>.<% vars.config.tld %>
|
||||
value="<% params.rname | html_entity %>" />.<% domain.name | html_entity %>.<% vars.config.tld %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -50,9 +50,11 @@
|
|||
</td>
|
||||
<td>
|
||||
<select name="type" id="type">
|
||||
<%# TODO: machine generate this %>
|
||||
<option value="">- Select -</option>
|
||||
<option value="A">A</option>
|
||||
<option value="AAAA">AAAA</option>
|
||||
<option value="CNAME">CNAME</option>
|
||||
<option value="NS">NS</option>
|
||||
</select>
|
||||
</td>
|
||||
|
|
Loading…
Reference in New Issue