Changeset 34 for trunk


Ignore:
Timestamp:
11/11/09 17:55:32 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint - Net::DNS + DBD::Pg crosswiring bug?

(AXFR NOTAUTH causes Pg transaction commit)

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r33 r34  
    3030        &getSOA &getRecLine &getDomRecs
    3131        &addRec &updateRec &delRec
    32         &domStatus
     32        &domStatus &importAXFR
    3333        %typemap %reverse_typemap
    3434        );
     
    4242                &getSOA &getRecLine &getDomRecs
    4343                &addRec &updateRec &delRec
    44                 &domStatus
     44                &domStatus &importAXFR
    4545                %typemap %reverse_typemap
    4646                )]
     
    824824##fixme:  add mode to delete&replace, merge+overwrite, merge new?
    825825
    826   my $res = Net::DNS::Resolver->new;
    827 $res->axfr_start($domain);
     826
    828827my $nrecs = 0;
    829828my $flags = 0;
     829my $warnmsg;
    830830
    831831  # Allow transactions, and raise an exception on errors so we can catch it later.
     
    834834  local $dbh->{RaiseError} = 1;
    835835
     836  my $dom_id;
     837
    836838  eval {
    837839    # can't do this, can't nest transactions.  sigh.
     
    840842##fixme:  serial
    841843    my $sth = $dbh->prepare("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)");
    842     $sth->execute($domain,$group,$state);
     844$warnmsg = "trying lokido... (".$dbh->{AutoCommit}."), (".$dbh->{RaiseError}.")" if $domain eq 'waslokido.com';
     845    $sth->execute($domain,$group,$status);
    843846
    844847    # get domain id so we can do the records
     
    846849    $sth->execute;
    847850    ($dom_id) = $sth->fetchrow_array();
     851$warnmsg .= " [domid $dom_id]";
     852
     853    my $res = Net::DNS::Resolver->new;
     854    unless ($res->axfr_start($domain)) {
     855      $dbh->rollback;
     856      die "Couldn't begin AXFR\n";
     857    }
     858
     859#die "just started AXFR\n";
    848860
    849861    while (my $rr = $res->axfr_next) {
     862$warnmsg = $rr->string;
    850863      my $type = $rr->type;
    851864# nasty big ugly case-like thing here, since we have to do *some* different
    852865# processing depending on the record.  le sigh.
    853       my $sql = "INSERT INTO records (domain_id,host,type,val,ttl";
     866      my $sql = "INSERT INTO records (domain_id,host,type,ttl,val";
    854867      my $vallen = "?,?,?,?,?";
    855       my $host,$val;
     868#      my $host = $rr->name;
     869#      my $ttl = $rr->ttl;
     870#      my $val;
    856871
    857872##work
    858 # gnnnnnh.  going to need to (rr->string)  ->  split  ->  <localvars>
    859 my @vallist;
    860       if ($type eq 'SOA') {
    861         $host = $rr->mname.":".$rr->rname;
    862         $val = $rr->refresh.":".$rr->retry.":".$rr->expire.":".$rr->minimum;
    863       }
    864       if ($type eq 'MX' || $type eq 'SRV') {
     873# gnnnnnh.  going to need to (rr->string)  ->  split  ->  <localvars>  ?
     874my @vallist = ($dom_id, $rr->name, $reverse_typemap{$type}, $rr->ttl);
     875
     876# "Primary" types:
     877# A, NS, CNAME, SOA, PTR(warn in forward), MX, TXT, AAAA, SRV, A6(ob), SPF
     878# maybe KEY
     879
     880      if ($type eq 'A') {
     881        push @vallist, $rr->address;
     882      } elsif ($type eq 'NS') {
     883        push @vallist, $rr->nsdname;
     884      } elsif ($type eq 'CNAME') {
     885        push @vallist, $rr->cname;
     886      } elsif ($type eq 'SOA') {
     887        $vallist[1] = $rr->mname.":".$rr->rname;
     888        push @vallist, ($rr->refresh.":".$rr->retry.":".$rr->expire.":".$rr->minimum);
     889      } elsif ($type eq 'PTR') {
     890        # hmm.  PTR records should not be in forward zones.
     891      } elsif ($type eq 'MX') {
    865892        $sql .= ",distance";
    866893        $vallen .= ",?";
    867         $sql .= ",weight,port" if $type eq 'SRV';
    868         $vallen .= ",?,?" if $type eq 'SRV';
     894        push @vallist, $rr->exchange;
     895        push @vallist, $rr->preference;
     896      } elsif ($type eq 'TXT') {
     897##fixme:  Net::DNS docs say this should be deprecated for rdatastr() or char_str_list(),
     898## but don't really seem enthusiastic about it.
     899        push @vallist, $rr->txtdata;
     900      } elsif ($type eq 'SPF') {
     901##fixme: and the same caveat here, since it is apparently a clone of ::TXT
     902        push @vallist, $rr->txtdata;
     903      } elsif ($type eq 'AAAA') {
     904        push @vallist, $rr->address;
     905      } elsif ($type eq 'SRV') {
     906        $sql .= ",distance,weight,port" if $type eq 'SRV';
     907        $vallen .= ",?,?,?" if $type eq 'SRV';
     908        push @vallist, $rr->priority;
     909        push @vallist, $rr->weight;
     910        push @vallist, $rr->port;
     911      } elsif ($type eq 'KEY') {
     912        push @vallist, ($rr->flags.":".$rr->protocol.":".$rr->algorithm.":".$rr->key.":".$rr->keytag.":".$rr->privatekeyname);
    869913      }
    870 $sth = $dbh->prepare($sql.") VALUES (".$vallen.")");
    871 $sth->execute(@vallist);
     914
     915$warnmsg = $rr->string;
     916$dbh->rollback if $domain eq 'waslokido.com';
     917die "first record: ".$rr->string."\n" if $domain eq 'waslokido.com';
     918
     919# BIND supports:
     920# A CNAME HINFO MB(ex) MD(ob) MF(ob) MG(ex) MINFO(ex) MR(ex) MX NS NULL
     921# PTR SOA TXT WKS AFSDB(ex) ISDN(ex) RP(ex) RT(ex) X25(ex) PX
     922# ... if one can ever find the right magic to format them correctly
     923
     924# Net::DNS supports:
     925# RRSIG SIG NSAP NS NIMLOC NAPTR MX MR MINFO MG MB LOC ISDN IPSECKEY HINFO
     926# EID DNAME CNAME CERT APL AFSDB AAAA A DS NXT NSEC3PARAM NSEC3 NSEC KEY
     927# DNSKEY DLV X25 TXT TSIG TKEY SSHFP SRV SPF SOA RT RP PX PTR NULL APL::AplItem
     928
     929# MX and SRV have known extras to stuff in.
     930      if ($type eq 'MX') {
     931        push @vallist, $rr->preference;
     932      }
     933      if ($type eq 'SRV') {
     934      }
     935
     936      $sth = $dbh->prepare($sql.") VALUES (".$vallen.")");
     937      $sth->execute(@vallist) or die "failed to insert ".$rr->string.": ".$sth->errstr."\n" if $sth->err;
     938
     939      if ($type eq 'SOA') {
     940      }
     941
     942$dbh->rollback;
     943#die "die.die.die!\n";
    872944
    873945      #print $rr->rdata."\n";
     
    878950    my $msg = $@;
    879951    eval { $dbh->rollback; };
    880     return ('FAIL',$msg);
     952    return ('FAIL',$msg." $warnmsg");
    881953  } else {
     954    return ('WARN', "OOOK!  Ooooook.  Ook. ($warnmsg)") if $domain eq 'deepnet.cx';
     955    return ('WARN', "Funky Things Happened: $warnmsg") if $domain eq 'waslokido.com';
    882956    return ('OK',"ook");
    883957  }
    884958
    885   return ('WARN',"
     959  return ('WARN',"OOOK!");
    886960} # end importAXFR()
    887961
  • trunk/dns.cgi

    r33 r34  
    615615my $rnum = 0;
    616616    foreach my $domain (@domlist) {
     617      my %row;
     618      my ($code,$msg) = importAXFR($dbh, $webvar{ifrom}, $domain, $webvar{group},
     619        $webvar{domstatus}, $webvar{rwsoa}, $webvar{rwns});
     620  $row{domok} = 1 if $code eq 'OK';
     621  $row{domwarn} = $msg if $code eq 'WARN';
     622  $row{domerr} = $msg if $code eq 'FAIL';
     623push @debugbits, "$domain: $code<br>\n";
    617624      # do stuff!  DNSDB::importAXFR($webvar{ifrom}, $webvar{rwsoa}, $webvar{rwns}, $domain, <flags>)
    618       my %row;
    619625      $row{domain} = $domain;
    620626#      $row{row} = $rnum++;
    621       if ($domain eq 'deepnet.cx' || $domain eq 'wh-int') {
    622         $row{domok} = 0;  $row{domerr} = "foo!  hahahaha!";
    623       } elsif ($domain eq 'waslokido.com') {
    624         $row{domwarn} = 0;  $row{domwarn} = "foo!  hahahaha!";
    625       } else {
    626         $row{domok} = 1;
    627       }
    628627      push @results, \%row;
    629628    }
  • trunk/templates/axfr.tmpl

    r33 r34  
    44
    55<td align="center">
    6 
    7 <TMPL_IF errmsg><div class="errmsg">Error: <TMPL_VARNAME=errmsg></div></TMPL_IF>
    86
    97<form action="dns.cgi" method="POST">
     
    1311
    1412<table>
     13<TMPL_IF errmsg><tr><td class="errhead" colspan=2>Error: <TMPL_VARNAME=errmsg></td></tr></TMPL_IF>
    1514<tr class="tableheader"><td align="center" colspan=2>Import domains via AXFR</td></tr>
    1615<tr class="datalinelight">
  • trunk/templates/dns.css

    r33 r34  
    6969td.defaults {
    7070        background-color: #DDDDDD;
     71}
     72td.errhead {
     73        font-weight: bold;
     74        font-size: 110%;
     75        color: red;
     76        background-color: #404040;
     77        text-align: center;
     78        padding: 3px;
     79        border: solid 2px #FF0000;
    7180}
    7281td.err {
Note: See TracChangeset for help on using the changeset viewer.