Changeset 532 for trunk


Ignore:
Timestamp:
09/26/13 16:50:54 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Expand _template4_expand a little to match potential usage
Move "quick" hostname validation into a sub to handle validating template

hostnames and "@"

Add help link and reference page for rDNS templates on record add/edit page

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r531 r532  
    12311231  #major patterns:
    12321232  #dashed IP, forward and reverse
     1233  #underscoreed IP, forward and reverse
    12331234  #dotted IP, forward and reverse (even if forward is... dumb)
    1234   # -> %r for reverse, %i for forward, leading - or . to indicate separator, defaults to -
     1235  # -> %r for reverse, %i for forward, leading -, _, or . to indicate separator, defaults to -
    12351236  # %r or %-r   => %4d-%3d-%2d-%1d
     1237  # %_r         => %4d_%3d_%2d_%1d
    12361238  # %.r         => %4d.%3d.%2d.%1d
    12371239  # %i or %-i   => %1d-%2d-%3d-%4d
     1240  # %_i         => %1d_%2d_%3d_%4d
    12381241  # %.i         => %1d.%2d.%3d.%4d
    12391242  $$tmpl =~ s/\%r/\%4d-\%3d-\%2d-\%1d/g;
    1240   $$tmpl =~ s/\%([-.])r/\%4d$1\%3d$1\%2d$1\%1d/g;
     1243  $$tmpl =~ s/\%([-._])r/\%4d$1\%3d$1\%2d$1\%1d/g;
    12411244  $$tmpl =~ s/\%i/\%1d-\%2d-\%3d-\%4d/g;
    1242   $$tmpl =~ s/\%([-.])i/\%1d$1\%2d$1\%3d$1\%4d/g;
     1245  $$tmpl =~ s/\%([-._])i/\%1d$1\%2d$1\%3d$1\%4d/g;
    12431246
    12441247  #hex-coded IP
     
    12601263  $$tmpl =~ s/\%([1234])0/$ippad[$1-1]/g;
    12611264} # _template4_expand()
     1265
     1266# Broad syntactic check on the hostname.  Checks for valid characters, correctly-expandable template patterns.
     1267# Takes the hostname, type, and live/default and forward/reverse flags
     1268# Returns true/false, sets errstr on failures
     1269sub _check_hostname_form {
     1270  my ($hname,$rectype,$defrec,$revrec) = @_;
     1271
     1272  if ($hname =~ /\%/ && ($rectype == 65282 || $rectype == 65283) ) {
     1273    my $tmphost = $hname;
     1274    # we don't actually need to test with the real IP passed;  that saves a bit of fiddling.
     1275    _template4_expand(\$tmphost, '10.10.10.10');
     1276    if ($tmphost =~ /\%/) {
     1277      $errstr = "Invalid template $hname";
     1278      return;
     1279    }
     1280  } elsif ($revrec eq 'y') {
     1281    # Reverse zones don't support @ in hostnames
     1282    # Also skip failure on revzone TXT records;  the hostname contains the TXT content in that case.
     1283    if ($rectype != $reverse_typemap{TXT} && lc($hname) !~ /^[0-9a-z_.-]+$/) {
     1284      $errstr = "Hostnames may not contain anything other than (0-9 a-z . _)";
     1285      return;
     1286    }
     1287  } else {
     1288    if (lc($hname) !~ /^(?:[0-9a-z_.-]+|@)$/) {
     1289      # Don't mention @, because it would be far too wordy to explain the nuance of @
     1290      $errstr = "Hostnames may not contain anything other than (0-9 a-z . _)";
     1291      return;
     1292    }
     1293  }
     1294  return 1;
     1295} # _check_hostname_form()
    12621296
    12631297
     
    36703704  return ('FAIL', "TTL must be numeric") unless $ttl =~ /^\d+$/;
    36713705
    3672   # Quick check on hostname parts.  Note the regex is more forgiving than the error message;
    3673   # domain names technically are case-insensitive, and we use printf-like % codes for a couple
    3674   # of types.  Other things may also be added to validate default records of several flavours.
    3675   return ('FAIL', "Hostnames may not contain anything other than (0-9 a-z . _)")
    3676         if $defrec eq 'n' && ($revrec eq 'y' ? $$rectype != $reverse_typemap{TXT} : 1) &&
    3677                 $$host !~ /^(?:[0-9a-z_%.-]+|@)$/i;
     3706  # Quick check on hostname parts.  There are enough variations to justify a sub now.
     3707  return ('FAIL', $errstr) if ! _check_hostname_form($$host, $$rectype, $defrec, $revrec);
    36783708
    36793709  # Collect these even if we're only doing a simple A record so we can call *any* validation sub
     
    38073837  return ('FAIL', "TTL must be numeric") unless $ttl =~ /^\d+$/;
    38083838
    3809   # Quick check on hostname parts.  Note the regex is more forgiving than the error message;
    3810   # domain names technically are case-insensitive, and we use printf-like % codes for a couple
    3811   # of types.  Other things may also be added to validate default records of several flavours.
    3812   return ('FAIL', "Hostnames may not contain anything other than (0-9 a-z - . _)")
    3813         if $defrec eq 'n' && ($revrec eq 'y' ? $$rectype != $reverse_typemap{TXT} : 1) &&
    3814                 $$host !~ /^(?:[0-9a-z_%.-]+|@)$/i;
     3839  # Quick check on hostname parts.  There are enough variations to justify a sub now.
     3840  return ('FAIL', $errstr) if ! _check_hostname_form($$host, $$rectype, $defrec, $revrec);
    38153841
    38163842  # only MX and SRV will use these
  • trunk/UPGRADE

    r530 r532  
    11$Id$
    22
    3 Upgrading from a previous release
    4 =================================
     3DeepNet DNS Administrator - Upgrade Notes
     4=========================================
    55
    661.0 -> 1.2
  • trunk/templates/dns.css

    r210 r532  
    3636        background-color: #F0F0F0;
    3737}
    38 table.container {
     38.container {
    3939        background-color: #FFFFFF;
    4040        border: none;
  • trunk/templates/record.tmpl

    r493 r532  
    2727<TMPL_IF fwdzone>
    2828                <td>Hostname</td>
    29                 <td><input type="text" name="name" value="<TMPL_VAR NAME=name>" size="30" /></td>
     29                <td><input type="text" name="name" value="<TMPL_VAR NAME=name>" size="30" />&nbsp; &nbsp; <a href="reverse-patterns.html">?</a></td>
    3030<TMPL_ELSE>
    3131                <td>IP Address</td>
     
    4747<TMPL_ELSE>
    4848                <td>Hostname</td>
    49                 <td><input type="text" name="name" value="<TMPL_VAR NAME=name>" size="30" /></td>
     49                <td><input type="text" name="name" value="<TMPL_VAR NAME=name>" size="30" />&nbsp; &nbsp; <a href="reverse-patterns.html">?</a></td>
    5050</TMPL_IF>
    5151        </tr>
Note: See TracChangeset for help on using the changeset viewer.