Ignore:
Timestamp:
12/10/13 17:15:56 (11 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge reverse DNS work; 1 of mumble

  • from branch creation through r261

Minor conflicts in dns.cgi and DNSDB.pm

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/dns.cgi

    r438 r544  
    6262
    6363# shut up some warnings, in case we arrive somewhere we forgot to set this
    64 $webvar{defrec} = 'n' if !$webvar{defrec};
     64$webvar{defrec} = 'n' if !$webvar{defrec};      # non-default records
     65$webvar{revrec} = 'n' if !$webvar{revrec};      # non-reverse (domain) records
    6566
    6667# load some local system defaults (mainly DB connect info)
     
    8788  $session->param('domlistsortby','domain');
    8889  $session->param('domlistorder','ASC');
     90  $session->param('revzonessortby','revnet');
     91  $session->param('revzonesorder','ASC');
    8992  $session->param('useradminsortby','user');
    9093  $session->param('useradminorder','ASC');
     
    204207my $page;
    205208eval {
    206   $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl");
     209  # sigh.  can't set loop_context_vars or global_vars once instantiated.
     210  $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl",
     211        loop_context_vars => 1, global_vars => 1);
    207212};
    208213if ($@) {
    209   warn "Bad page $webvar{page} requested";
     214  my $msg = $@;
    210215  $page = HTML::Template->new(filename => "$templatedir/badpage.tmpl");
    211   $page->param(badpage => $q->escapeHTML($webvar{page}));
     216  if (-e "$templatedir/$webvar{page}.tmpl") {
     217    $page->param(badtemplate => $q->escapeHTML($msg));
     218  } else {
     219    warn "Bad page $webvar{page} requested";
     220    $page->param(badpage => $q->escapeHTML($webvar{page}));
     221  }
    212222  $webvar{page} = 'badpage';
    213223}
     
    279289
    280290    # I hate special cases.
     291##fixme: probably need to handle webvar{revrec}=='y' too
    281292    if ($webvar{page} eq 'reclist' && $webvar{defrec} eq 'y') {
    282       my %args = (page => $webvar{page}, id => $curgroup, defrec => $webvar{defrec});
     293      my %args = (page => $webvar{page}, id => $curgroup, defrec => $webvar{defrec}, revrec => $webvar{revrec});
    283294      $args{errmsg} = $errmsg if $errmsg;
    284295      changepage(%args);
     
    300311
    301312} elsif ($webvar{page} eq 'domlist' or $webvar{page} eq 'index') {
     313
     314  $page->param(domlist => 1);
    302315
    303316# hmm.  seeing problems in some possibly-not-so-corner cases.
     
    312325      my $stat = domStatus($dbh,$webvar{id},$webvar{domstatus});
    313326##fixme  switch to more consise "Enabled <domain"/"Disabled <domain>" as with users?
    314       logaction($webvar{id}, $session->param("username"), parentID($webvar{id}, 'dom', 'group'),
     327      logaction($webvar{id}, $session->param("username"),
     328        parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec})),
    315329        "Changed ".domainName($dbh, $webvar{id})." state to ".($stat ? 'active' : 'inactive'));
    316330      $page->param(resultmsg => "Changed ".domainName($dbh, $webvar{id})." state to ".
     
    366380
    367381  my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0),
    368         (name => $session->param("username"), id => $session->param("uid")));
     382        (username => $session->param("username"), id => $session->param("uid")));
    369383
    370384  if ($code eq 'OK') {
     
    401415
    402416  } elsif ($webvar{del} eq 'ok') {
    403     my $pargroup = parentID($webvar{id}, 'dom', 'group');
     417    my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec}));
    404418    my $dom = domainName($dbh, $webvar{id});
    405419    my ($code,$msg) = delDomain($dbh, $webvar{id});
     
    418432  }
    419433
     434} elsif ($webvar{page} eq 'revzones') {
     435
     436  $webvar{revrec} = 'y';
     437  $page->param(curpage => $webvar{page});
     438  listzones();
     439
     440} elsif ($webvar{page} eq 'newrevzone') {
     441
     442## scope/access check - use domain settings?  invent new (bleh)
     443  changepage(page => "revzones", errmsg => "You are not permitted to add reverse zones")
     444       unless ($permissions{admin} || $permissions{domain_create});
     445
     446  fill_grouplist("grouplist");
     447
     448  if ($webvar{add_failed}) {
     449    $page->param(add_failed => 1);
     450    $page->param(errmsg => $webvar{errmsg});
     451    $page->param(revzone => $webvar{revzone});
     452    $page->param(revpatt => $webvar{revpatt});
     453  }
     454
     455} elsif ($webvar{page} eq 'addrevzone') {
     456
     457  changepage(page => "revzones", errmsg => "You are not permitted to add reverse zones")
     458       unless ($permissions{admin} || $permissions{domain_create});
     459
     460  # security check - does the user have permission to access this entity?
     461  if (!check_scope(id => $webvar{group}, type => 'group')) {
     462    changepage(page => "newrevzone", add_failed => 1, revzone => $webvar{revzone}, revpatt => $webvar{revpatt},
     463       errmsg => "You do not have permission to add a reverse zone to the requested group");
     464  }
     465
     466  my ($code,$msg) = addRDNS($dbh, $webvar{revzone}, $webvar{revpatt}, $webvar{group},
     467        ($webvar{makeactive} eq 'on' ? 1 : 0),
     468        (username => $session->param("username"), id => $session->param("uid")) );
     469
     470  if ($code eq 'OK') {
     471    logaction(0, $session->param("username"), $webvar{group}, "Added reverse zone $webvar{revzone}", $msg);
     472    changepage(page => "reclist", id => $msg, revrec => 'y');
     473  } else {
     474    logaction(0, $session->param("username"), $webvar{group}, "Failed adding reverse zone $webvar{revzone} ($msg)");
     475    changepage(page => "newrevzone", add_failed => 1, revzone => $webvar{revzone}, revpatt => $webvar{revpatt},
     476       errmsg => $msg);
     477  }
     478
     479#} elsif ($webvar{page} eq 'delrevzone') {
     480
    420481} elsif ($webvar{page} eq 'reclist') {
    421482
    422483  # security check - does the user have permission to view this entity?
    423   if (!check_scope(id => $webvar{id}, type => ($webvar{defrec} eq 'y' ? 'group' : 'domain'))) {
     484  if (!check_scope(id => $webvar{id}, type =>
     485        ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) {
    424486    $page->param(errmsg => "You are not permitted to view or change the requested ".
    425         ($webvar{defrec} eq 'y' ? "group's default records" : "domain's records"));
     487        ($webvar{defrec} eq 'y' ? "group's default records" :
     488                ($webvar{revrec} eq 'y' ? "reverse zone's records" : "domain's records")));
    426489    $page->param(perm_err => 1);        # this causes the template to skip the record listing output.
    427490    goto DONERECLIST;   # and now we skip filling in the content which is not printed due to perm_err above
     
    446509
    447510    $page->param(defrec => $webvar{defrec});
     511    $page->param(revrec => $webvar{revrec});
    448512    $page->param(id => $webvar{id});
    449513    $page->param(curpage => $webvar{page});
    450514
    451     my $count = getRecCount($dbh, $webvar{defrec}, $webvar{id}, $filter);
     515    my $count = getRecCount($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter);
    452516
    453517    $sortby = 'host';
     
    460524
    461525# set up the headers
    462     my @cols = ('host', 'type', 'val', 'distance', 'weight', 'port', 'ttl');
    463     my %colheads = (host => 'Name', type => 'Type', val => 'Address',
     526    my @cols;
     527    my %colheads;
     528    if ($webvar{revrec} eq 'n') {
     529      @cols = ('host', 'type', 'val', 'distance', 'weight', 'port', 'ttl');
     530      %colheads = (host => 'Name', type => 'Type', val => 'Address',
    464531        distance => 'Distance', weight => 'Weight', port => 'Port', ttl => 'TTL');
    465     my %custom = (id => $webvar{id}, defrec => $webvar{defrec});
     532    } else {
     533      @cols = ('host', 'type', 'val', 'ttl');
     534      %colheads = (host => 'IP Address', type => 'Type', val => 'Hostname', ttl => 'TTL');
     535    }
     536    my %custom = (id => $webvar{id}, defrec => $webvar{defrec}, revrec => $webvar{revrec});
    466537    fill_colheads($sortby, $sortorder, \@cols, \%colheads, \%custom);
    467538
    468539# fill the page-count and first-previous-next-last-all details
    469540    fill_pgcount($count,"records",
    470         ($webvar{defrec} eq 'y' ? "group ".groupName($dbh,$webvar{id}) : domainName($dbh,$webvar{id})));
     541        ($webvar{defrec} eq 'y' ? "group ".groupName($dbh,$webvar{id}) :
     542                ($webvar{revrec} eq 'y' ? revName($dbh,$webvar{id}) : domainName($dbh,$webvar{id}))
     543        ));
    471544    fill_fpnla($count);  # should put some params on this sub...
    472545
    473546    $page->param(defrec => $webvar{defrec});
    474     if ($webvar{defrec} eq 'y') {
    475       showdomain('y',$curgroup);
    476     } else {
    477       showdomain('n',$webvar{id});
     547    showzone($webvar{defrec}, $webvar{revrec}, $webvar{id});
     548    if ($webvar{defrec} eq 'n') {
     549#      showzone('n',$webvar{id});
    478550##fixme:  permission for viewing logs?
    479       $page->param(logdom => 1);
     551##fixme:  determine which slice of the log we view (group, domain, revzone)
     552      if ($webvar{revrec} eq 'n') {
     553        $page->param(logdom => 1);
     554      } else {
     555        $page->param(logrdns => 1);
     556      }
    480557    }
    481558
     
    484561      $session->clear('resultmsg');
    485562    }
     563    if ($session->param('warnmsg')) {
     564      $page->param(warnmsg => $session->param('warnmsg'));
     565      $session->clear('warnmsg');
     566    }
    486567    if ($session->param('errmsg')) {
    487568      $page->param(errmsg => $session->param('errmsg'));
     
    497578
    498579  # security check - does the user have permission to access this entity?
    499   if (!check_scope(id => $webvar{id}, type => ($webvar{defrec} eq 'y' ? 'defrec' : 'record'))) {
     580  if (!check_scope(id => $webvar{id}, type =>
     581        ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) {
    500582    $page->param(perm_err => "You are not permitted to edit the requested record");
    501583    goto DONEREC;
    502584  }
    503585  # round 2, check the parent.
    504   if (!check_scope(id => $webvar{parentid}, type => ($webvar{defrec} eq 'y' ? 'group' : 'domain'))) {
     586  if (!check_scope(id => $webvar{parentid}, type =>
     587        ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) {
    505588    my $msg = ($webvar{defrec} eq 'y' ?
    506589        "You are not permitted to add or edit default records in the requested group" :
    507         "You are not permitted to add or edit records in the requested domain");
     590        "You are not permitted to add or edit records in the requested domain/zone");
    508591    $page->param(perm_err => $msg);
    509592    goto DONEREC;
    510593  }
     594
     595  $page->param(defrec => $webvar{defrec});
     596  $page->param(revrec => $webvar{revrec});
     597  $page->param(fwdzone => $webvar{revrec} eq 'n');
    511598
    512599  if ($webvar{recact} eq 'new') {
     
    518605    $page->param(recact => "add");
    519606    $page->param(parentid => $webvar{parentid});
    520     $page->param(defrec => $webvar{defrec});
    521607
    522608    fill_recdata();
     
    527613        unless ($permissions{admin} || $permissions{record_create});
    528614
    529 ##fixme: this should probably go in DNSDB::addRec(), need to ponder what to do about PTR and friends
    530     # prevent out-of-domain records from getting added by appending the domain, or DOMAIN for default records
    531     my $pname = ($webvar{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$webvar{parentid}));
    532     $webvar{name} =~ s/\.*$/\.$pname/ if $webvar{name} !~ /$pname$/;
    533 
    534     my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl});
     615    my @recargs = ($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid},
     616        \$webvar{name},\$webvar{type},\$webvar{address},$webvar{ttl});
    535617    if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
    536618      push @recargs, $webvar{distance};
     
    543625    my ($code,$msg) = addRec(@recargs);
    544626
    545     if ($code eq 'OK') {
     627    if ($code eq 'OK' || $code eq 'WARN') {
     628      my $restr;
    546629      if ($webvar{defrec} eq 'y') {
    547         my $restr = "Added default record '$webvar{name} $typemap{$webvar{type}}";
     630        $restr = "Added default record '$webvar{name} $typemap{$webvar{type}}";
    548631        $restr .= " [distance $webvar{distance}]" if $typemap{$webvar{type}} eq 'MX';
    549632        $restr .= " [priority $webvar{distance}] [weight $webvar{weight}] [port $webvar{port}]"
     
    551634        $restr .= " $webvar{address}', TTL $webvar{ttl}";
    552635        logaction(0, $session->param("username"), $webvar{parentid}, $restr);
    553         changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
    554636      } else {
    555         my $restr = "Added record '$webvar{name} $typemap{$webvar{type}}";
     637        $restr = "Added record '$webvar{name} $typemap{$webvar{type}}";
    556638        $restr .= " [distance $webvar{distance}]" if $typemap{$webvar{type}} eq 'MX';
    557639        $restr .= " [priority $webvar{distance}] [weight $webvar{weight}] [port $webvar{port}]"
    558640                if $typemap{$webvar{type}} eq 'SRV';
    559641        $restr .= " $webvar{address}', TTL $webvar{ttl}";
    560         logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), $restr);
    561         changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
    562       }
     642        logaction($webvar{parentid}, $session->param("username"),
     643                parentID($dbh, (id => $webvar{parentid}, type => 'domain', revrec => $webvar{revrec})), $restr);
     644      }
     645      my %pageparams = (page => "reclist", id => $webvar{parentid},
     646        defrec => $webvar{defrec}, revrec => $webvar{revrec});
     647      $pageparams{warnmsg} = $msg."<br><br>\n".$restr if $code eq 'WARN';
     648      $pageparams{resultmsg} = $restr if $code eq 'OK';
     649      changepage(%pageparams);
    563650    } else {
    564651      $page->param(failed       => 1);
     
    568655      $page->param(recact       => "add");
    569656      $page->param(parentid     => $webvar{parentid});
    570       $page->param(defrec       => $webvar{defrec});
    571657      $page->param(id           => $webvar{id});
    572658      fill_recdata();   # populate the form... er, mostly.
    573       $page->param(name => $webvar{name});
    574659      if ($config{log_failures}) {
    575660        if ($webvar{defrec} eq 'y') {
     
    577662                "Failed adding default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)");
    578663        } else {
    579           logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
     664          logaction($webvar{parentid}, $session->param("username"),
     665                parentID($dbh, (id => $webvar{parentid}, type => 'domain', revrec => $webvar{revrec})),
    580666                "Failed adding record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)");
    581667        }
     
    592678    $page->param(parentid       => $webvar{parentid});
    593679    $page->param(id             => $webvar{id});
    594     $page->param(defrec         => $webvar{defrec});
    595     my $recdata = getRecLine($dbh, $webvar{defrec}, $webvar{id});
     680    my $recdata = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    596681    $page->param(name           => $recdata->{host});
    597682    $page->param(address        => $recdata->{val});
     
    600685    $page->param(port           => $recdata->{port});
    601686    $page->param(ttl            => $recdata->{ttl});
    602     fill_rectypes($recdata->{type});
     687    $page->param(typelist       => getTypelist($dbh, $webvar{revrec}, $webvar{type}));
    603688
    604689  } elsif ($webvar{recact} eq 'update') {
     
    613698
    614699    # get current/previous record info so we can log "updated 'foo A 1.2.3.4' to 'foo A 2.3.4.5'"
    615     my $oldrec = getRecLine($dbh, $webvar{defrec}, $webvar{id});
     700    my $oldrec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    616701
    617702    my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{id},
     
    629714        my $restr = "Updated record from '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl}\n".
    630715                "to '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}";
    631         logaction($webvar{parentid}, $session->param("username"), parentID($webvar{id}, 'rec', 'group'), $restr);
     716        logaction($webvar{parentid}, $session->param("username"),
     717                parentID($dbh, (id => $webvar{id}, type => 'record', defrec => $webvar{defrec},
     718                        revrec => $webvar{revrec}, partype => 'group')),
     719                $restr);
    632720        changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
    633721      }
     
    639727      $page->param(recact       => "update");
    640728      $page->param(parentid     => $webvar{parentid});
    641       $page->param(defrec       => $webvar{defrec});
    642729      $page->param(id           => $webvar{id});
    643730      fill_recdata();
     
    647734                "Failed updating default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)");
    648735        } else {
    649           logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
     736          logaction($webvar{parentid}, $session->param("username"),
     737                parentID($dbh, (id => $webvar{parentid}, type => 'domain', revrec => $webvar{revrec})),
    650738                "Failed updating record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)");
    651739        }
     
    658746  } else {
    659747    $page->param(parentid => $webvar{parentid});
    660     $page->param(dohere => domainName($dbh,$webvar{parentid}));
     748    $page->param(dohere => domainName($dbh,$webvar{parentid})) if $webvar{revrec} eq 'n';
     749    $page->param(dohere => revName($dbh,$webvar{parentid})) if $webvar{revrec} eq 'y';
    661750  }
    662751
     
    668757  # This is a complete separate segment since it uses a different template from add/edit records above
    669758
    670   changepage(page => "reclist", errmsg => "You are not permitted to delete records", id => $webvar{parentid})
     759  changepage(page => "reclist", errmsg => "You are not permitted to delete records", id => $webvar{parentid},
     760                defrec => $webvar{defrec}, revrec => $webvar{revrec})
    671761        unless ($permissions{admin} || $permissions{record_delete});
    672762
    673763  if (!check_scope(id => $webvar{id}, type =>
    674764        ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) {
    675     changepage(page => 'domlist', errmsg => "You do not have permission to delete records in the requested ".
     765    # redirect to domlist because we don't have permission for the entity requested
     766    changepage(page => 'domlist', revrec => $webvar{revrec},
     767        errmsg => "You do not have permission to delete records in the requested ".
    676768        ($webvar{defrec} eq 'y' ? 'group' : 'domain'));
    677769  }
     
    679771  $page->param(id => $webvar{id});
    680772  $page->param(defrec => $webvar{defrec});
     773  $page->param(revrec => $webvar{revrec});
    681774  $page->param(parentid => $webvar{parentid});
    682775  # first pass = confirm y/n (sorta)
    683776  if (!defined($webvar{del})) {
    684777    $page->param(del_getconf => 1);
    685     my $rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
     778    my $rec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    686779    $page->param(host => $rec->{host});
    687780    $page->param(ftype => $typemap{$rec->{type}});
     
    689782  } elsif ($webvar{del} eq 'ok') {
    690783# get rec data before we try to delete it
    691     my $rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
    692     my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
     784    my $rec = getRecLine($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
     785    my ($code,$msg) = delRec($dbh, $webvar{defrec}, $webvar{revrec}, $webvar{id});
    693786    if ($code eq 'OK') {
    694787      if ($webvar{defrec} eq 'y') {
     788        my $recclass = ($webvar{revrec} eq 'n' ? 'default record' : 'default reverse record');
    695789##fixme:  log distance for MX;  log port/weight/distance for SRV
    696         my $restr = "Deleted default record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
     790        my $restr = "Deleted $recclass '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
    697791        logaction(0, $session->param("username"), $rec->{parid}, $restr);
    698         changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
     792        changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
     793                revrec => $webvar{revrec}, resultmsg => $restr);
    699794      } else {
    700         my $restr = "Deleted record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
    701         logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'), $restr);
    702         changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
     795        my $recclass = ($webvar{revrec} eq 'n' ? 'record' : 'reverse record');
     796        my $restr = "Deleted $recclass '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}";
     797        logaction($rec->{parid}, $session->param("username"),
     798                parentID($dbh, (id => $rec->{parid}, type => 'domain', revrec => $webvar{revrec})),
     799                $restr);
     800        changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
     801                revrec => $webvar{revrec}, resultmsg => $restr);
    703802      }
    704803    } else {
     
    710809                " TTL $rec->{ttl} ($msg)");
    711810        } else {
    712           logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'),
     811          logaction($rec->{parid}, $session->param("username"),
     812                parentID($dbh, (id => $rec->{parid}, type => 'domain', revrec => $webvar{revrec})),
    713813                "Failed deleting record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl} ($msg)");
    714814        }
    715815      }
    716816      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
    717                 errmsg => "Error deleting record: $msg");
     817                revrec => $webvar{revrec}, errmsg => "Error deleting record: $msg");
    718818    }
    719819  } else {
    720     changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
     820    changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, revrec => $webvar{revrec});
    721821  }
    722822
     
    724824
    725825  # security check - does the user have permission to view this entity?
    726   if (!check_scope(id => $webvar{id}, type => ($webvar{defrec} eq 'y' ? 'group' : 'domain'))) {
     826  # id is domain/revzone/group id
     827  if (!check_scope(id => $webvar{id}, type =>
     828        ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) {
    727829    changepage(page => 'domlist', errmsg => "You do not have permission to edit the ".
    728830        ($webvar{defrec} eq 'y' ? 'default ' : '')."SOA record for the requested ".
     
    744846  # security check - does the user have permission to view this entity?
    745847  # pass 1, record ID
    746   if (!check_scope(id => $webvar{recid}, type => ($webvar{defrec} eq 'y' ? 'defrec' : 'record'))) {
     848  if (!check_scope(id => $webvar{recid}, type =>
     849        ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) {
    747850    changepage(page => 'domlist', errmsg => "You do not have permission to edit the requested SOA record");
    748851  }
    749852  # pass 2, parent (group or domain) ID
    750   if (!check_scope(id => $webvar{id}, type => ($webvar{defrec} eq 'y' ? 'group' : 'domain'))) {
     853  if (!check_scope(id => $webvar{id}, type =>
     854        ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) {
    751855    changepage(page => 'domlist', errmsg => "You do not have permission to edit the ".
    752856        ($webvar{defrec} eq 'y' ? 'default ' : '')."SOA record for the requested ".
     
    787891      $logdomain = 0;
    788892    } else {
    789       $loggroup = parentID($logdomain, 'dom', 'group', $webvar{defrec});
     893      $loggroup = parentID($dbh, (id => $logdomain, type => 'domain', revrec => $webvar{revrec}));
    790894    }
    791895
     
    8981002  } elsif ($webvar{del} eq 'ok') {
    8991003    my $deleteme = groupName($dbh,$webvar{id}); # get this before we delete it...
    900     my $delparent = parentID($webvar{id}, 'group','group');
     1004    my $delparent = parentID($dbh, (id => $webvar{id}, type => 'group'));
    9011005    my ($code,$msg) = delGroup($dbh, $webvar{id});
    9021006    if ($code eq 'OK') {
     
    10411145      my ($code, $msg) = changeGroup($dbh, 'domain', $webvar{$_}, $webvar{destgroup});
    10421146      if ($code eq 'OK') {
    1043         logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'),
     1147        logaction($webvar{$_}, $session->param("username"),
     1148                parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})),
    10441149                "Moved domain ".domainName($dbh, $webvar{$_})." to group $newgname");
    10451150        $row{domok} = ($code eq 'OK');
    10461151      } else {
    1047         logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'),
     1152        logaction($webvar{$_}, $session->param("username"),
     1153                parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})),
    10481154                "Failed to move domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg")
    10491155                if $config{log_failures};
     
    10721178##fixme:  error handling on status change
    10731179      my $stat = domStatus($dbh,$webvar{$_},($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff'));
    1074       logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'),
    1075                 "Changed domain ".domainName($dbh, $webvar{$_})." state to ".($stat ? 'active' : 'inactive'));
     1180      logaction($webvar{$_}, $session->param("username"),
     1181        parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})),
     1182        "Changed domain ".domainName($dbh, $webvar{$_})." state to ".($stat ? 'active' : 'inactive'));
    10761183      $row{domok} = 1;
    10771184#      $row{domok} = ($code eq 'OK');
     
    10971204      }
    10981205      $row{domain} = domainName($dbh,$webvar{$_});
    1099       my $pargroup = parentID($webvar{$_}, 'dom', 'group');
     1206      my $pargroup = parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec}));
    11001207      my $dom = domainName($dbh, $webvar{$_});
    11011208      my ($code, $msg) = delDomain($dbh, $webvar{$_});
     
    11301237    if ($flag && ($permissions{admin} || $permissions{user_edit})) {
    11311238      my $stat = userStatus($dbh,$webvar{id},$webvar{userstatus});
    1132       logaction(0, $session->param("username"), parentID($webvar{id}, 'user', 'group'),
     1239      logaction(0, $session->param("username"), parentID($dbh, (id => $webvar{id}, type => 'user')),
    11331240        ($stat ? 'Enabled' : 'Disabled')." ".userFullName($dbh, $webvar{id}, '%u'));
    11341241      $page->param(resultmsg => ($stat ? 'Enabled' : 'Disabled')." ".userFullName($dbh, $webvar{id}, '%u'));
     
    13881495
    13891496  $page->param(qfor => $webvar{qfor}) if $webvar{qfor};
    1390   fill_rectypes($webvar{type} ? $webvar{type} : '', 1);
     1497  $page->param(typelist => getTypelist($dbh, 'l', ($webvar{type} ? $webvar{type} : undef)));
    13911498  $page->param(nrecurse => $webvar{nrecurse}) if $webvar{nrecurse};
    13921499  $page->param(resolver => $webvar{resolver}) if $webvar{resolver};
     
    15631670    }
    15641671    $page->param(logfor => 'domain '.domainName($dbh,$id));
     1672  } elsif ($webvar{ltype} && $webvar{ltype} eq 'rdns') {
     1673    $sql .= "rdns_id=?";
     1674    $id = $webvar{id};
     1675    if (!check_scope(id => $id, type => 'revzone')) {
     1676      $page->param(errmsg => "You are not permitted to view log entries for the requested reverse zone");
     1677      goto DONELOG;
     1678    }
     1679    $page->param(logfor => 'reverse zone '.revName($dbh,$id));
    15651680  } else {
    15661681    # Default to listing curgroup log
     
    15701685    # group log is always for the "current" group
    15711686  }
     1687##fixme:
     1688# - filtering
     1689# - show reverse zone column?
     1690# - pagination/limiting number of records - put newest-first so user
     1691#   doesn't always need to go to the last page for recent activity?
    15721692  my $sth = $dbh->prepare($sql);
    15731693  $sth->execute($id);
     
    16011721  $page->param(logingrp => groupName($dbh,$logingroup));
    16021722  $page->param(logingrp_num => $logingroup);
     1723
     1724##fixme
     1725  $page->param(mayrdns => 1);
    16031726
    16041727  $page->param(maydefrec => $permissions{admin});
     
    16961819  # handle user check
    16971820  my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?sid=$sid";
    1698   foreach (keys %params) {
     1821  foreach (sort keys %params) {
    16991822    $newurl .= "&$_=".$q->url_encode($params{$_});
    17001823  }
     
    17431866}
    17441867
    1745 sub showdomain {
     1868sub showzone {
    17461869  my $def = shift;
     1870  my $rev = shift;
    17471871  my $id = shift;
    17481872
    17491873  # get the SOA first
    1750   my %soa = getSOA($dbh,$def,$id);
     1874  my %soa = getSOA($dbh,$def,$rev,$id);
    17511875
    17521876  $page->param(contact  => $soa{contact});
     
    17581882  $page->param(ttl      => $soa{ttl});
    17591883
    1760   my $foo2 = getDomRecs($dbh,$def,$id,$perpage,$webvar{offset},$sortby,$sortorder,$filter);
     1884  my $foo2 = getDomRecs($dbh,$def,$rev,$id,$perpage,$webvar{offset},$sortby,$sortorder,$filter);
    17611885
    17621886  my $row = 0;
     
    17651889    $rec->{row} = $row % 2;
    17661890    $rec->{defrec} = $def;
     1891    $rec->{revrec} = $rev;
    17671892    $rec->{sid} = $webvar{sid};
    17681893    $rec->{id} = $id;
     1894    $rec->{fwdzone} = $rev eq 'n';
    17691895    $rec->{distance} = 'n/a' unless ($rec->{type} eq 'MX' || $rec->{type} eq 'SRV');
    17701896    $rec->{weight} = 'n/a' unless ($rec->{type} eq 'SRV');
     
    17781904}
    17791905
    1780 # fill in record type list on add/update/edit record template
    1781 sub fill_rectypes {
    1782   my $type = shift || $reverse_typemap{A};
    1783   my $soaflag = shift || 0;
    1784 
    1785   my $sth = $dbh->prepare("SELECT val,name FROM rectypes WHERE stdflag=1 ORDER BY listorder");
    1786   $sth->execute;
    1787   my @typelist;
    1788   while (my ($rval,$rname) = $sth->fetchrow_array()) {
    1789     my %row = ( recval => $rval, recname => $rname );
    1790     $row{tselect} = 1 if $rval == $type;
    1791     push @typelist, \%row;
    1792   }
    1793   if ($soaflag) {
    1794     my %row = ( recval => $reverse_typemap{SOA}, recname => 'SOA' );
    1795     $row{tselect} = 1 if $reverse_typemap{SOA} == $type;
    1796     push @typelist, \%row;
    1797   }
    1798   $page->param(typelist => \@typelist);
    1799 } # fill_rectypes
    1800 
    18011906sub fill_recdata {
    1802   fill_rectypes($webvar{type});
     1907  $page->param(typelist => getTypelist($dbh, $webvar{revrec}, $webvar{type}));
    18031908
    18041909# le sigh.  we may get called with many empty %webvar keys
     
    18071912##todo:  allow BIND-style bare names, ASS-U-ME that the name is within the domain?
    18081913# prefill <domain> or DOMAIN in "Host" space for new records
    1809   my $domroot = ($webvar{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$webvar{parentid}));
    1810   $page->param(name     => $domroot);
    1811   $page->param(address  => $webvar{address});
    1812   $page->param(distance => $webvar{distance})
     1914  if ($webvar{revrec} eq 'n') {
     1915    my $domroot = ($webvar{defrec} eq 'y' ? 'DOMAIN' : domainName($dbh,$webvar{parentid}));
     1916    $page->param(name   => $domroot);
     1917    $page->param(address        => $webvar{address});
     1918    $page->param(distance       => $webvar{distance})
    18131919        if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
    1814   $page->param(weight   => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
    1815   $page->param(port     => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
     1920    $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
     1921    $page->param(port   => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
     1922  } else {
     1923    my $domroot = ($webvar{defrec} eq 'y' ? 'ADMINDOMAIN' : ".$config{domain}");
     1924    $page->param(name   => ($webvar{name} ? $webvar{name} : $domroot));
     1925    my $zname = ($webvar{defrec} eq 'y' ? 'ZONE' : revName($dbh,$webvar{parentid}));
     1926    $zname =~ s|\d*/\d+$||;
     1927    $page->param(address        => ($webvar{address} ? $webvar{address} : $zname));
     1928  }
    18161929# retrieve the right ttl instead of falling (way) back to the hardcoded system default
    1817   my %soa = getSOA($dbh,$webvar{defrec},$webvar{parentid});
     1930  my %soa = getSOA($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid});
    18181931  $page->param(ttl      => ($webvar{ttl} ? $webvar{ttl} : $soa{minttl}));
    18191932}
     
    18932006  # on a page showing nothing.
    18942007  # For bonus points, this reverts to the original offset on clicking the "All" link (mostly)
    1895   if ($offset ne 'all') { 
     2008  if ($offset ne 'all') {
    18962009    $offset-- while ($offset * $perpage) >= $pgcount;
    18972010  }
     
    19072020} # end fill_pgcount()
    19082021
    1909 sub listdomains {
    1910 
     2022
     2023sub listdomains { listzones(); }        # temp
     2024
     2025sub listzones {
    19112026# ACLs
    19122027  $page->param(domain_create    => ($permissions{admin} || $permissions{domain_create}) );
     
    19182033  my $childlist = join(',',@childgroups);
    19192034
    1920   my $sql = "SELECT count(*) FROM domains WHERE group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
    1921         ($startwith ? " AND domain ~* ?" : '').
    1922         ($filter ? " AND domain ~* ?" : '');
    1923   my $sth = $dbh->prepare($sql);
    1924   $sth->execute(@filterargs);
    1925   my ($count) = $sth->fetchrow_array;
     2035  my $count = getZoneCount($dbh, (childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec},
     2036        filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) );
    19262037
    19272038# fill page count and first-previous-next-last-all bits
    1928   fill_pgcount($count,"domains",groupName($dbh,$curgroup));
     2039  fill_pgcount($count,($webvar{revrec} eq 'n' ? 'domains' : 'revzones'),groupName($dbh,$curgroup));
    19292040  fill_fpnla($count);
    19302041
     
    19372048
    19382049# set up the headers
    1939   my @cols = ('domain', 'status', 'group');
    1940   my %colheads = (domain => 'Domain', status => 'Status', group => 'Group');
     2050  my @cols = (($webvar{revrec} eq 'n' ? 'domain' : 'revnet'), 'status', 'group');
     2051  my %colheads = (domain => 'Domain', revnet => 'Reverse Zone', status => 'Status', group => 'Group');
    19412052  fill_colheads($sortby, $sortorder, \@cols, \%colheads);
    19422053
     
    19462057
    19472058# waffle, waffle - keep state on these as well as sortby, sortorder?
     2059##fixme:  put this higher so the count doesn't get munched?
    19482060  $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
    19492061
     
    19512063  $page->param(searchsubs => $searchsubs) if $searchsubs;
    19522064
    1953 ##fixme
    1954 ##fixme  push the SQL and direct database fiddling off into a sub in DNSDB.pm
    1955 ##fixme
    1956 
    19572065  $page->param(group => $curgroup);
    1958   my @domlist;
    1959   $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains".
    1960         " INNER JOIN groups ON domains.group_id=groups.group_id".
    1961         " WHERE domains.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
    1962         ($startwith ? " AND domain ~* ?" : '').
    1963         ($filter ? " AND domain ~* ?" : '').
    1964         " ORDER BY ".($sortby eq 'group' ? 'groups.group_name' : $sortby).
    1965         " $sortorder ".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage);
    1966   $sth = $dbh->prepare($sql);
    1967   $sth->execute(@filterargs);
    1968   my $rownum = 0;
    1969   while (my @data = $sth->fetchrow_array) {
    1970     my %row;
    1971     $row{domainid} = $data[0];
    1972     $row{domain} = $data[1];
    1973     $row{status} = ($data[2] ? 'Active' : 'Inactive');
    1974     $row{group} = $data[3];
    1975     $row{bg} = ($rownum++)%2;
    1976     $row{mkactive} = !$data[2];
    1977     $row{sid} = $sid;
    1978     $row{offset} = $offset;
    1979 # ACLs
    1980     $row{domain_edit} = ($permissions{admin} || $permissions{domain_edit});
    1981     $row{domain_delete} = ($permissions{admin} || $permissions{domain_delete});
    1982     push @domlist, \%row;
    1983   }
    1984   $page->param(domtable => \@domlist);
     2066
     2067  my $zonelist = getZoneList($dbh, (childlist => $childlist, curgroup => $curgroup,
     2068        revrec => $webvar{revrec},
     2069        filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef),
     2070        offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder
     2071        ) );
     2072# probably don't need this, keeping for reference for now
     2073#  foreach (@$zonelist) {
     2074#  }
     2075  $page->param(domtable => $zonelist);
    19852076} # end listdomains()
    19862077
     
    22212312  my $groupid = shift;
    22222313  my $entry = shift;
     2314  my $revid = shift || 0;
    22232315
    22242316##fixme: push SQL into DNSDB.pm
     
    22282320  my ($user_id, $fullname) = $sth->fetchrow_array;
    22292321
    2230   $sth = $dbh->prepare("INSERT INTO log (domain_id,user_id,group_id,email,name,entry) ".
    2231         "VALUES (?,?,?,?,?,?)") or warn $dbh->errstr;
    2232   $sth->execute($domid,$user_id,$groupid,$username,$fullname,$entry) or warn $sth->errstr;
     2322  $sth = $dbh->prepare("INSERT INTO log (domain_id,user_id,group_id,email,name,entry,rdns_id) ".
     2323        "VALUES (?,?,?,?,?,?,?)") or warn $dbh->errstr;
     2324  $sth->execute($domid,$user_id,$groupid,$username,$fullname,$entry,$revid) or warn $sth->errstr;
    22332325} # end logaction()
    2234 
    2235 
    2236 ##fixme:  generalize to return appropriate id on all cases (ie, use $partype)
    2237 sub parentID {
    2238   my $id = shift;
    2239   my $idtype = shift;
    2240   my $partype = shift;
    2241   my $defrec = shift || '';
    2242 
    2243   my $sql = '';
    2244 
    2245   if ($idtype eq 'dom') {
    2246     return $id if $defrec eq 'y';  # "domain" + default records, we're really looking at a group.
    2247     $sql = "SELECT group_id FROM domains WHERE domain_id=?";
    2248   } elsif ($idtype eq 'rec') {
    2249     if ($defrec eq 'y') {
    2250       $sql = "SELECT group_id FROM default_records WHERE record_id=?";
    2251     } else {
    2252       $sql = "SELECT d.group_id FROM domains d".
    2253         " INNER JOIN records r ON d.domain_id=r.domain_id".
    2254         " WHERE r.record_id=?";
    2255     }
    2256   } elsif ($idtype eq 'group') {
    2257     $sql = "SELECT parent_group_id FROM groups WHERE group_id=?";
    2258   } elsif ($idtype eq 'user') {
    2259     $sql = "SELECT group_id FROM users WHERE user_id=?";
    2260   } else {
    2261     return "FOO", "BAR";  # can't get here.... we think.
    2262   }
    2263   my $sth = $dbh->prepare($sql);
    2264   $sth->execute($id);
    2265   my ($retid) = $sth->fetchrow_array;
    2266   return $retid if $retid;
    2267   # ahh! fall of the edge of the world if things went sideways
    2268   ##fixme:  really need to do a little more error handling, I think
    2269 } # end parentID()
    22702326
    22712327
Note: See TracChangeset for help on using the changeset viewer.