Changeset 91 for trunk


Ignore:
Timestamp:
04/13/11 16:00:10 (14 years ago)
Author:
Kris Deugau
Message:

/trunk

SQL tabledef update:

  • Tweak log table definition to cope with looooong entries (mainly from AXFR warnings)

DNSDB.pm:

  • Add domainID and getRecCount subs in DNSDB
  • Return more user-friendly error on attempting to add a domain with no name
  • Nitpick-tweak DB calls and SQL formatting in domainName()
  • Replace placeholderish OK message in importAXFR()

dns.cgi:

  • Trim some more direct SQL out in reclist
  • Uninitialized-variable cleanup in AXFR import
  • Add logging to AXFR import
  • Don't complain about uninitialized variables in record-display
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r90 r91  
    2828        &initPermissions &getPermissions &changePermissions &comparePermissions
    2929        &connectDB &finish
    30         &addDomain &delDomain &domainName
     30        &addDomain &delDomain &domainName &domainID
    3131        &addGroup &delGroup &getChildren &groupName
    3232        &addUser &updateUser &delUser &userFullName &userStatus &getUserData
    33         &getSOA &getRecLine &getDomRecs
     33        &getSOA &getRecLine &getDomRecs &getRecCount
    3434        &addRec &updateRec &delRec
    3535        &domStatus &importAXFR
     
    4343                &initPermissions &getPermissions &changePermissions &comparePermissions
    4444                &connectDB &finish
    45                 &addDomain &delDomain &domainName
     45                &addDomain &delDomain &domainName &domainID
    4646                &addGroup &delGroup &getChildren &groupName
    4747                &addUser &updateUser &delUser &userFullName &userStatus &getUserData
    48                 &getSOA &getRecLine &getDomRecs
     48                &getSOA &getRecLine &getDomRecs &getRecCount
    4949                &addRec &updateRec &delRec
    5050                &domStatus &importAXFR
     
    367367  return ('FAIL',"Need database handle") if !$dbh;
    368368  my $domain = shift;
    369   return ('FAIL',"Need domain") if !defined($domain);
     369  return ('FAIL',"Domain must not be blank") if !$domain;
    370370  my $group = shift;
    371371  return ('FAIL',"Need group") if !defined($group);
     
    470470  my $dbh = shift;
    471471  my $domid = shift;
    472   my $sth = $dbh->prepare("select domain from domains where domain_id=?");
    473   $sth->execute($domid);
    474   my ($domname) = $sth->fetchrow_array();
     472  my ($domname) = $dbh->selectrow_array("SELECT domain FROM domains WHERE domain_id=?", undef, ($domid) );
    475473  $errstr = $DBI::errstr if !$domname;
    476474  return $domname if $domname;
    477 } # end domainName
     475} # end domainName()
     476
     477
     478## DNSDB::domainID()
     479# Takes a database handle and domain name
     480# Returns the domain ID number
     481sub domainID {
     482  $errstr = '';
     483  my $dbh = shift;
     484  my $domain = shift;
     485  my ($domid) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE domain=?", undef, ($domain) );
     486  $errstr = $DBI::errstr if !$domid;
     487  return $domid if $domid;
     488} # end domainID()
    478489
    479490
     
    10861097  return $ret;
    10871098} # end getDomRecs()
     1099
     1100
     1101## DNSDB::getRecCount()
     1102# Return count of non-SOA records in domain (or default records in a group)
     1103# Takes a database handle, default/live flag and group/domain ID
     1104# Returns the count
     1105sub getRecCount {
     1106  my $dbh = shift;
     1107  my $defrec = shift;
     1108  my $id = shift;
     1109
     1110  my ($count) = $dbh->selectrow_array("SELECT count(*) FROM ".
     1111        ($defrec eq 'y' ? 'default_' : '')."records ".
     1112        "WHERE ".($defrec eq 'y' ? 'group' : 'domain')."_id=? ".
     1113        "AND NOT type=$reverse_typemap{SOA}", undef, ($id) );
     1114
     1115  return $count;
     1116
     1117} # end getRecCount()
    10881118
    10891119
     
    14871517  } else {
    14881518    return ('WARN', $warnmsg) if $warnmsg;
    1489     return ('OK',"ook");
     1519    return ('OK',"Imported OK");
    14901520  }
    14911521
  • trunk/dns.cgi

    r90 r91  
    249249  $page->param(curpage => $webvar{page});
    250250
    251   my $sth = $dbh->prepare("SELECT count(*) FROM ".
    252         ($webvar{defrec} eq 'y' ? 'default_' : '')."records ".
    253         "WHERE ".($webvar{defrec} eq 'y' ? 'group' : 'domain')."_id=? ".
    254         "AND NOT type=$reverse_typemap{SOA}");
    255   $sth->execute($webvar{id});
    256   my ($count) = ($sth->fetchrow_array);
     251  my $count = getRecCount($dbh, $webvar{defrec}, $webvar{id});
    257252
    258253#  $sortby = 'host';
     
    919914  $page->param(importdoms => $webvar{importdoms}) if $webvar{importdoms};
    920915
    921 ##fixme: check group too?
     916  # shut up warning about uninitialized variable
     917  $webvar{doit} = '' if !defined($webvar{doit});
     918
    922919  if ($webvar{doit} eq 'y' && !$webvar{ifrom}) {
    923920    $page->param(errmsg => "Need to set host to import from");
    924921  } elsif ($webvar{doit} eq 'y' && !$webvar{importdoms}) {
    925922    $page->param(errmsg => "Need domains to import");
    926   } else {
     923  } elsif ($webvar{doit} eq 'y') {
    927924    my @domlist = split /\s+/, $webvar{importdoms};
    928925    my @results;
    929 my $rnum = 0;
    930926    foreach my $domain (@domlist) {
    931927      my %row;
    932928      my ($code,$msg) = importAXFR($dbh, $webvar{ifrom}, $domain, $webvar{group},
    933929        $webvar{domstatus}, $webvar{rwsoa}, $webvar{rwns});
    934 ##fixme: log
    935930      $row{domok} = $msg if $code eq 'OK';
    936931      if ($code eq 'WARN') {
     
    939934      }
    940935      if ($code eq 'FAIL') {
    941         $msg =~ s|\n|<br />|g;
     936        $msg =~ s|\n|<br />\n|g;
    942937        $row{domerr} = $msg;
    943938      }
    944       # do stuff!  DNSDB::importAXFR($webvar{ifrom}, $webvar{rwsoa}, $webvar{rwns}, $domain, <flags>)
     939      $msg = "<br />\n".$msg if $msg =~ m|<br />|;
     940      logaction(domainID($dbh, $domain), $session->param("username"), $webvar{group},
     941        "AXFR import $domain from $webvar{ifrom} ($code): $msg");
    945942      $row{domain} = $domain;
    946 #      $row{row} = $rnum++;
    947943      push @results, \%row;
    948944    }
     
    12241220sub fill_recdata {
    12251221  fill_rectypes($webvar{type});
     1222
     1223# le sigh.  we may get called with many empty %webvar keys
     1224  no warnings qw( uninitialized );
    12261225
    12271226  $page->param(name     => $webvar{name});
  • trunk/dns.sql

    r89 r91  
    5454\.
    5555
     56-- entry is text due to possible long entries from AXFR - a domain with "many"
     57-- odd records will overflow varchar(200)
    5658CREATE TABLE log (
    5759    log_id serial NOT NULL,
     
    6163    email character varying(60),
    6264    name character varying(60),
    63     entry character varying(200),
     65    entry text,
    6466    stamp timestamp with time zone DEFAULT now()
    6567);
Note: See TracChangeset for help on using the changeset viewer.