Changeset 389


Ignore:
Timestamp:
09/21/12 13:08:05 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Add location support to addRec() and updateRec().
Extend add/update record UI to make sure the user can only update
the location if they have record_locchg permission, by retrieving
the parent/original location for add/update respectively.
See #10.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r387 r389  
    32613261  my $id = shift;
    32623262
    3263   my $sql = "SELECT record_id,host,type,val,ttl".($revrec eq 'n' ? ',distance,weight,port' : '').
     3263  my $sql = "SELECT record_id,host,type,val,ttl,location".($revrec eq 'n' ? ',distance,weight,port' : '').
    32643264        (($defrec eq 'y') ? ',group_id FROM ' : ',domain_id,rdns_id FROM ').
    32653265        _rectable($defrec,$revrec)." WHERE record_id=?";
     
    34023402  my $val = shift;
    34033403  my $ttl = shift;
     3404  my $location = shift;
     3405  $location  = '' if !$location;
    34043406
    34053407  # prep for validation
     
    34403442
    34413443  # Set up database fields and bind parameters
    3442   $fields .= "host,type,val,ttl,"._recparent($defrec,$revrec);
    3443   push @vallist, ($$host,$$rectype,$$val,$ttl,$id);
     3444  $fields .= "host,type,val,ttl,location,"._recparent($defrec,$revrec);
     3445  push @vallist, ($$host,$$rectype,$$val,$ttl,$location,$id);
    34443446  my $vallen = '?'.(',?'x$#vallist);
    34453447
     
    34683470  $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]"
    34693471        if $typemap{$$rectype} eq 'SRV';
    3470   $logdata{entry} .= "', TTL $ttl";
     3472  $logdata{entry} .= "', TTL $ttl, location $location";
    34713473
    34723474  # Allow transactions, and raise an exception on errors so we can catch it later.
     
    35183520  my $val = shift;
    35193521  my $ttl = shift;
     3522  my $location = shift; # may be empty/null/undef depending on caller
     3523  $location  = '' if !$location;
    35203524
    35213525  # prep for validation
     
    35643568  # Set up database fields and bind parameters.  Note only the optional fields
    35653569  # (distance, weight, port, secondary parent ID) are added in the validation call above
    3566   $fields .= "host,type,val,ttl,"._recparent($defrec,$revrec);
    3567   push @vallist, ($$host,$$rectype,$$val,$ttl,
     3570  $fields .= "host,type,val,ttl,location,"._recparent($defrec,$revrec);
     3571  push @vallist, ($$host,$$rectype,$$val,$ttl,$location,
    35683572        ($defrec eq 'y' ? $oldrec->{group_id} : ($revrec eq 'n' ? $oldrec->{domain_id} : $oldrec->{rdns_id})) );
    35693573
     
    36183622  $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]"
    36193623        if $typemap{$oldrec->{type}} eq 'SRV';
    3620   $logdata{entry} .= "', TTL $oldrec->{ttl}\nto\n";
     3624  $logdata{entry} .= "', TTL $oldrec->{ttl}, location $oldrec->{location}\nto\n";
    36213625  # More NS special
    36223626  if ($revrec eq 'y' && $$rectype == 2) {
     
    36273631  $logdata{entry} .= " [distance $dist]" if $typemap{$$rectype} eq 'MX';
    36283632  $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$$rectype} eq 'SRV';
    3629   $logdata{entry} .= "', TTL $ttl";
     3633  $logdata{entry} .= "', TTL $ttl, location $location";
    36303634
    36313635  local $dbh->{AutoCommit} = 0;
  • trunk/dns.cgi

    r388 r389  
    642642        unless ($permissions{admin} || $permissions{record_create});
    643643
     644    # location check - if user does not have record_locchg, set $webvar{location} to default location for zone
     645    my $parloc = getZoneLocation($dbh, $webvar{revrec}, $webvar{parentid});
     646    $webvar{location} = $parloc unless ($permissions{admin} || $permissions{record_locchg});
     647
    644648    my @recargs = ($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid},
    645         \$webvar{name},\$webvar{type},\$webvar{address},$webvar{ttl});
     649        \$webvar{name},\$webvar{type},\$webvar{address},$webvar{ttl},$webvar{location});
    646650    if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
    647651      push @recargs, $webvar{distance};
     
    701705        unless ($permissions{admin} || $permissions{record_edit});
    702706
     707    # retain old location if user doesn't have permission to fiddle locations
     708    my $oldrec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
     709    $webvar{location} = $oldrec->{location} unless ($permissions{admin} || $permissions{record_locchg});
     710
    703711    my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{revrec},$webvar{id},$webvar{parentid},
    704         \$webvar{name},\$webvar{type},\$webvar{address},$webvar{ttl},
     712        \$webvar{name},\$webvar{type},\$webvar{address},$webvar{ttl},$webvar{location},
    705713        $webvar{distance},$webvar{weight},$webvar{port});
    706714
Note: See TracChangeset for help on using the changeset viewer.