Changeset 546 for branches


Ignore:
Timestamp:
12/11/13 15:31:44 (11 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge reverse DNS work from /trunk, 3 of mumble.

Includes changes through r440. One minor conflict
due to old partial merge

Location:
branches/stable
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/DNSDB.pm

    r545 r546  
    30743074
    30753075## DNSDB::updateLoc()
     3076# Update details of a location.
     3077# Takes a database handle, location ID, group ID, short description,
     3078# long comments/notes, and comma/space-separated IP list
     3079# Returns a result code and message
    30763080sub updateLoc {
    30773081  my $dbh = shift;
     
    31163120
    31173121## DNSDB::delLoc()
    3118 sub delLoc {}
     3122sub delLoc {
     3123  my $dbh = shift;
     3124  my $loc = shift;
     3125
     3126  # Allow transactions, and raise an exception on errors so we can catch it later.
     3127  # Use local to make sure these get "reset" properly on exiting this block
     3128  local $dbh->{AutoCommit} = 0;
     3129  local $dbh->{RaiseError} = 1;
     3130
     3131  my $oldloc = getLoc($dbh, $loc);
     3132  my $olddesc = ($oldloc->{description} ? $oldloc->{description} : $loc);
     3133  my $okmsg = "Deleted location ($olddesc, '".$oldloc->{iplist}."')";
     3134
     3135  eval {
     3136    # Check for records with this location first.  Deleting a location without deleting records
     3137    # tagged for that location will render them unpublished without other warning.
     3138    my ($r) = $dbh->selectrow_array("SELECT record_id FROM records WHERE location=? LIMIT 1", undef, ($loc) );
     3139    die "Records still exist in location $olddesc\n" if $r;
     3140    $dbh->do("DELETE FROM locations WHERE location=?", undef, ($loc) );
     3141    _log($dbh, entry => $okmsg);
     3142    $dbh->commit;
     3143  };
     3144  if ($@) {
     3145    my $msg = $@;
     3146    eval { $dbh->rollback; };
     3147    if ($config{log_failures}) {
     3148      _log($dbh, (entry => "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg"));
     3149      $dbh->commit;
     3150    }
     3151    return ('FAIL', "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg");
     3152  }
     3153
     3154  return ('OK',$okmsg);
     3155} # end delLoc()
    31193156
    31203157
    31213158## DNSDB::getLoc()
     3159# Get details about a location/view
     3160# Takes a database handle and location ID.
     3161# Returns a reference to a hash containing the group ID, IP list, description, and comments/notes
    31223162sub getLoc {
    31233163  my $dbh = shift;
     
    33253365  my $id = shift;
    33263366
    3327   my $sql = "SELECT record_id,host,type,val,ttl,location".($revrec eq 'n' ? ',distance,weight,port' : '').
     3367  my $sql = "SELECT record_id,host,type,val,ttl".
     3368        ($defrec eq 'n' ? ',location' : '').
     3369        ($revrec eq 'n' ? ',distance,weight,port' : '').
    33283370        (($defrec eq 'y') ? ',group_id FROM ' : ',domain_id,rdns_id FROM ').
    33293371        _rectable($defrec,$revrec)." WHERE record_id=?";
     
    34003442  $sql .= "WHERE "._recparent($args{defrec},$args{revrec})." = ?";
    34013443  $sql .= " AND NOT r.type=$reverse_typemap{SOA}";
    3402   $sql .= " AND host ~* ?" if $args{filter};
     3444  $sql .= " AND (r.host ~* ? OR r.val ~* ?)" if $args{filter};
    34033445  $sql .= " ORDER BY $args{sortby} $args{sortorder}";
    34043446  # ensure consistent ordering by sorting on record_id too
     
    34073449
    34083450  my @bindvars = ($args{id});
    3409   push @bindvars, $args{filter} if $args{filter};
     3451  push @bindvars, ($args{filter},$args{filter}) if $args{filter};
    34103452
    34113453  my $ret = $dbh->selectall_arrayref($sql, { Slice => {} }, (@bindvars) );
     
    35483590  $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]"
    35493591        if $typemap{$$rectype} eq 'SRV';
    3550   $logdata{entry} .= "', TTL $ttl, location $location";
     3592  $logdata{entry} .= "', TTL $ttl";
     3593  $logdata{entry} .= ", location ".getLoc($dbh, $location)->{description} if $location;
    35513594
    35523595  # Allow transactions, and raise an exception on errors so we can catch it later.
     
    37093752  $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]"
    37103753        if $typemap{$oldrec->{type}} eq 'SRV';
    3711   $logdata{entry} .= "', TTL $oldrec->{ttl}, location $oldrec->{location}\nto\n";
     3754  $logdata{entry} .= "', TTL $oldrec->{ttl}";
     3755  $logdata{entry} .= ", location ".getLoc($dbh, $oldrec->{location})->{description} if $oldrec->{location};
     3756  $logdata{entry} .= "\nto\n";
    37123757  # More NS special
    37133758  if ($revrec eq 'y' && $$rectype == 2) {
     
    37183763  $logdata{entry} .= " [distance $dist]" if $typemap{$$rectype} eq 'MX';
    37193764  $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$$rectype} eq 'SRV';
    3720   $logdata{entry} .= "', TTL $ttl, location $location";
     3765  $logdata{entry} .= "', TTL $ttl";
     3766  $logdata{entry} .= ", location ".getLoc($dbh, $location)->{description} if $location;
    37213767
    37223768  local $dbh->{AutoCommit} = 0;
     
    37783824  $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]"
    37793825        if $typemap{$oldrec->{type}} eq 'SRV';
    3780   $logdata{entry} .= "', TTL $oldrec->{ttl}\n";
     3826  $logdata{entry} .= "', TTL $oldrec->{ttl}";
     3827  $logdata{entry} .= ", location ".getLoc($dbh, $oldrec->{location})->{description} if $oldrec->{location};
    37813828
    37823829  eval {
  • branches/stable/Makefile

    r438 r546  
    5555        templates/adddomain.tmpl templates/addgroup.tmpl templates/addrec.tmpl templates/adduser.tmpl \
    5656        templates/axfr.tmpl templates/bulkchange.tmpl templates/bulkdomain.tmpl templates/dberr.tmpl \
    57         templates/deldom.tmpl templates/delgrp.tmpl templates/delrec.tmpl templates/deluser.tmpl \
     57        templates/deldom.tmpl templates/delgrp.tmpl templates/delloc.tmpl templates/delrec.tmpl \
     58        templates/delrevzone.tmpl templates/deluser.tmpl \
    5859        templates/dns.css templates/dnsq.tmpl templates/domlist.tmpl templates/edgroup.tmpl \
    5960        templates/editsoa.tmpl templates/footer.tmpl templates/fpnla.tmpl templates/grouptree.css \
     
    8283        templates/adddomain.tmpl templates/addgroup.tmpl templates/addrec.tmpl templates/adduser.tmpl \
    8384        templates/axfr.tmpl templates/bulkchange.tmpl templates/bulkdomain.tmpl templates/dberr.tmpl \
    84         templates/deldom.tmpl templates/delgrp.tmpl templates/delrec.tmpl templates/deluser.tmpl \
     85        templates/deldom.tmpl templates/delgrp.tmpl templates/delloc.tmpl templates/delrec.tmpl \
     86        templates/delrevzone.tmpl templates/deluser.tmpl \
    8587        templates/dns.css templates/dnsq.tmpl templates/domlist.tmpl templates/edgroup.tmpl \
    8688        templates/editsoa.tmpl templates/footer.tmpl templates/fpnla.tmpl templates/grouptree.css \
  • branches/stable/dns-rpc.cgi

    r545 r546  
    356356  _commoncheck(\%args, 'y');
    357357
     358  # add records in the zone's default location if none is specified
     359  if (!$args{location} && $args{defrec} eq 'n') {
     360    $args{location} = DNSDB::getZoneLocation($dbh, $args{revrec}, $args{parent_id});
     361  }
     362
     363  my @recargs = ($dbh, $args{defrec}, $args{revrec}, $args{parent_id},
     364        \$args{name}, \$args{type}, \$args{address}, $args{ttl}, $args{location});
     365  if ($args{type} == $DNSDB::reverse_typemap{MX} or $args{type} == $DNSDB::reverse_typemap{SRV}) {
     366    push @recargs, $args{distance};
     367    if ($args{type} == $DNSDB::reverse_typemap{SRV}) {
     368      push @recargs, $args{weight};
     369      push @recargs, $args{port};
     370    }
     371  }
     372
     373  my ($code, $msg) = DNSDB::addRec(@recargs);
     374
     375  die $msg if $code eq 'FAIL';
     376  return $msg;
     377}
     378
     379sub updateRec {
     380  my %args = @_;
     381
     382  _commoncheck(\%args, 'y');
     383
    358384  # note dist, weight, port are not required on all types;  will be ignored if not needed.
    359   my ($code, $msg) = DNSDB::addRec($dbh, $args{def}, $args{domid}, $args{host}, $DNSDB::typemap{$args{type}},
    360         $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port});
    361 
    362   die $msg if $code eq 'FAIL';
    363 }
    364 
    365 sub updateRec {
    366   my %args = @_;
    367 
    368   _commoncheck(\%args, 'y');
    369 
    370   # note dist, weight, port are not required on all types;  will be ignored if not needed.
    371   my ($code, $msg) = DNSDB::updateRec($dbh, $args{def}, $args{recid}, $args{host}, $DNSDB::typemap{$args{type}},
    372         $args{val}, $args{ttl}, $args{dist}, $args{weight}, $args{port});
    373 
    374   die $msg if $code eq 'FAIL';
     385  # parent_id is the "primary" zone we're updating;  necessary for forward/reverse voodoo
     386  my ($code, $msg) = DNSDB::updateRec($dbh, $args{defrec}, $args{revrec}, $args{id}, $args{parent_id},
     387        \$args{name}, \$args{type}, \$args{address}, $args{ttl}, $args{location},
     388        $args{distance}, $args{weight}, $args{port});
     389
     390  die $msg if $code eq 'FAIL';
     391  return $msg;
    375392}
    376393
     
    380397  _commoncheck(\%args, 'y');
    381398
    382   my ($code, $msg) = DNSDB::delRec($dbh, $args{def}, $args{recid});
    383 
    384   die $msg if $code eq 'FAIL';
     399  my ($code, $msg) = DNSDB::delRec($dbh, $args{defrec}, $args{recrev}, $args{id});
     400
     401  die $msg if $code eq 'FAIL';
     402  return $msg;
    385403}
    386404
  • branches/stable/dns.cgi

    r545 r546  
    13621362#  }
    13631363
    1364   if ($webvar{locact} eq 'new') {
    1365     # uuhhmm....
    1366   } elsif ($webvar{locact} eq 'add') {
     1364  $webvar{locact} = '' if !$webvar{locact};
     1365
     1366  if ($webvar{locact} eq 'add') {
    13671367    changepage(page => "loclist", errmsg => "You are not permitted to add locations/views", id => $webvar{parentid})
    13681368        unless ($permissions{admin} || $permissions{location_create});
     
    14301430
    14311431    show_msgs();
     1432  }
     1433
     1434} elsif ($webvar{page} eq 'delloc') {
     1435
     1436  changepage(page=> "loclist", errmsg => "You are not allowed to delete locations")
     1437        unless $permissions{admin} || $permissions{location_delete};
     1438
     1439  # security check - does the user have permission to access this entity?
     1440#  if (!check_scope(id => $webvar{id}, type => 'loc')) {
     1441#    changepage(page => "loclist", errmsg => "You are not permitted to <foo> the requested location/view");
     1442#  }
     1443
     1444  $page->param(locid => $webvar{locid});
     1445  my $locdata = getLoc($dbh, $webvar{locid});
     1446  $locdata->{description} = $webvar{locid} if !$locdata->{description};
     1447  # first pass = confirm y/n (sorta)
     1448  if (!defined($webvar{del})) {
     1449    $page->param(del_getconf => 1);
     1450    $page->param(location => $locdata->{description});
     1451  } elsif ($webvar{del} eq 'ok') {
     1452    my ($code,$msg) = delLoc($dbh, $webvar{locid});
     1453    if ($code eq 'OK') {
     1454      # success.  go back to the user list, do not pass "GO"
     1455      changepage(page => "loclist", resultmsg => $msg);
     1456    } else {
     1457      changepage(page => "loclist", errmsg => $msg);
     1458    }
     1459  } else {
     1460    # cancelled.  whee!
     1461    changepage(page => "loclist");
    14321462  }
    14331463
  • branches/stable/templates/deldom.tmpl

    r100 r546  
    55<td align="center" valign="top">
    66<h3>Are you really sure you want to delete domain <TMPL_VAR NAME=domain>?</h3>
    7 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=deldom&amp;del=cancel&amp;id=<TMPL_VAR NAME=id>">cancel</a> &nbsp; | &nbsp; <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=deldom&amp;del=ok&amp;id=<TMPL_VAR NAME=id>">confirm</a>
     7<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=deldom&amp;del=cancel&amp;id=<TMPL_VAR NAME=id>">cancel</a> &nbsp; | &nbsp;
     8<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=deldom&amp;del=ok&amp;id=<TMPL_VAR NAME=id>">confirm</a>
    89</td></tr></table>
    910
  • branches/stable/templates/delgrp.tmpl

    r141 r546  
    44
    55<td align="center" valign="top">
    6 
    76<h3>Are you really sure you want to delete group <TMPL_VAR NAME=delgroupname>?</h3>
    87<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delgrp&amp;del=cancel&amp;id=<TMPL_VAR NAME=id>">cancel</a> &nbsp; | &nbsp;
    98<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delgrp&amp;del=ok&amp;id=<TMPL_VAR NAME=id>">confirm</a>
    10 
    11 <!--
    12  fixme:  do a check for "group has stuff in it", and splatter a big warning
    13  up along with an unchecked-by-default check box to YES DAMMIT DELETE THE WHOLE THING
    14  -->
    15 
    169</td></tr></table>
    1710
  • branches/stable/templates/delrevzone.tmpl

    r545 r546  
    55<td align="center" valign="top">
    66<h3>Are you really sure you want to delete reverse zone <TMPL_VAR NAME=revzone>?</h3>
    7 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delrevzone&amp;del=cancel&amp;id=<TMPL_VAR NAME=id>">cancel</a> &nbsp; | &nbsp; <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delrevzone&amp;del=ok&amp;id=<TMPL_VAR NAME=id>">confirm</a>
     7<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delrevzone&amp;del=cancel&amp;id=<TMPL_VAR NAME=id>">cancel</a> &nbsp; | &nbsp;
     8<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delrevzone&amp;del=ok&amp;id=<TMPL_VAR NAME=id>">confirm</a>
    89</td></tr></table>
    910
  • branches/stable/templates/deluser.tmpl

    r100 r546  
    55<td align="center" valign="top">
    66<h3>Are you really sure you want to delete user <TMPL_VAR NAME=user>?</h3>
    7 <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=deluser&amp;del=cancel&amp;id=<TMPL_VAR NAME=id>">cancel</a> &nbsp; | &nbsp; <a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=deluser&amp;del=ok&amp;id=<TMPL_VAR NAME=id>">confirm</a>
     7<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=deluser&amp;del=cancel&amp;id=<TMPL_VAR NAME=id>">cancel</a> &nbsp; | &nbsp;
     8<a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=deluser&amp;del=ok&amp;id=<TMPL_VAR NAME=id>">confirm</a>
    89</td></tr></table>
    910
  • branches/stable/templates/loclist.tmpl

    r545 r546  
    3636        <td><TMPL_VAR name=group_name></td>
    3737<TMPL_IF delloc>
    38         <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delloc&amp;id=<TMPL_VAR
    39 NAME=loc>"><img src="images/trash2.png" alt="[ Delete ]" /></a></td>
     38        <td align="center"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=delloc&amp;locid=<TMPL_VAR
     39NAME=location>"><img src="images/trash2.png" alt="[ Delete ]" /></a></td>
    4040</TMPL_IF>
    4141</tr>
  • branches/stable/templates/newdomain.tmpl

    r545 r546  
    3232                <td>Make domain active on next DNS propagation</td><td><input type="checkbox" name="makeactive"<TMPL_UNLESS addinactive> checked="checked"</TMPL_UNLESS> /></td>
    3333        </tr>
    34 <TMPL_IF location_view>
     34<TMPL_IF location_view><TMPL_IF record_locchg>
    3535        <tr class="datalinelight">
    3636                <td>Default location/view:</td>
    3737                <td><select name="defloc">
    38                 <option value="">(None/public)</option>
    3938<TMPL_LOOP name=loclist>                <option value="<TMPL_VAR NAME=loc>"<TMPL_IF selected> selected="selected"</TMPL_IF>><TMPL_VAR NAME=locname></option>
    4039</TMPL_LOOP>
    4140                </select></td>
    4241        </tr>
    43 </TMPL_IF>
     42</TMPL_IF></TMPL_IF>
    4443        <tr><td colspan="2" class="tblsubmit"><input type="submit" value="Add domain" /></td></tr>
    4544    </table>
  • branches/stable/textrecs.cgi

    r535 r546  
    8888foreach my $rec (@$reclist) {
    8989  $rec->{type} = $typemap{$rec->{type}};
    90   $rec->{val} .= '.' if $rec->{type} ne 'A' && $rec->{type} ne 'TXT' && $rec->{val} !~ /\.$/;
    91   $rec->{host} .= '.' if $rec->{val} !~ /\.$/;
     90  $rec->{val} .= '.' if $rec->{type} ne 'A' && $rec->{type} ne 'TXT' && $webvar{revrec} eq 'n' && $rec->{val} !~ /\.$/;
     91  $rec->{host} .= '.' if $webvar{revrec} eq 'y' && $rec->{val} !~ /\.$/;
    9292  $rec->{val} = "$rec->{distance}  $rec->{val}" if $rec->{type} eq 'MX';
    9393  $rec->{val} = "$rec->{distance}  $rec->{weight}  $rec->{port}  $rec->{val}" if $rec->{type} eq 'SRV';
Note: See TracChangeset for help on using the changeset viewer.