Changeset 33
- Timestamp:
- 11/10/09 17:51:55 (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r29 r33 15 15 use Exporter; 16 16 use DBI; 17 use Net::DNS; 17 18 #use Net::SMTP; 18 19 #use NetAddr::IP qw( Compact ); … … 811 812 812 813 814 ## DNSDB::importAXFR 815 # Import a domain via AXFR 816 sub importAXFR { 817 my $dbh = shift; 818 my $ifrom = shift; 819 my $domain = shift; 820 my $group = shift; 821 my $status = shift || 1; 822 my $rwsoa = shift || 0; 823 my $rwns = shift || 0; 824 ##fixme: add mode to delete&replace, merge+overwrite, merge new? 825 826 my $res = Net::DNS::Resolver->new; 827 $res->axfr_start($domain); 828 my $nrecs = 0; 829 my $flags = 0; 830 831 # Allow transactions, and raise an exception on errors so we can catch it later. 832 # Use local to make sure these get "reset" properly on exiting this block 833 local $dbh->{AutoCommit} = 0; 834 local $dbh->{RaiseError} = 1; 835 836 eval { 837 # can't do this, can't nest transactions. sigh. 838 #my ($dcode, $dmsg) = addDomain($dbh, $domain, $group, $status); 839 840 ##fixme: serial 841 my $sth = $dbh->prepare("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)"); 842 $sth->execute($domain,$group,$state); 843 844 # get domain id so we can do the records 845 $sth = $dbh->prepare("select domain_id from domains where domain='$domain'"); 846 $sth->execute; 847 ($dom_id) = $sth->fetchrow_array(); 848 849 while (my $rr = $res->axfr_next) { 850 my $type = $rr->type; 851 # nasty big ugly case-like thing here, since we have to do *some* different 852 # processing depending on the record. le sigh. 853 my $sql = "INSERT INTO records (domain_id,host,type,val,ttl"; 854 my $vallen = "?,?,?,?,?"; 855 my $host,$val; 856 857 ##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') { 865 $sql .= ",distance"; 866 $vallen .= ",?"; 867 $sql .= ",weight,port" if $type eq 'SRV'; 868 $vallen .= ",?,?" if $type eq 'SRV'; 869 } 870 $sth = $dbh->prepare($sql.") VALUES (".$vallen.")"); 871 $sth->execute(@vallist); 872 873 #print $rr->rdata."\n"; 874 } 875 }; 876 877 if ($@) { 878 my $msg = $@; 879 eval { $dbh->rollback; }; 880 return ('FAIL',$msg); 881 } else { 882 return ('OK',"ook"); 883 } 884 885 return ('WARN'," 886 } # end importAXFR() 887 888 813 889 # shut Perl up 814 890 1; -
trunk/dns.cgi
r31 r33 601 601 $page->param(rwsoa => $webvar{rwsoa}) if $webvar{rwsoa}; 602 602 $page->param(rwns => $webvar{rwns}) if $webvar{rwns}; 603 $page->param(dominactive => 1) unless $webvar{domactive}; 603 604 $page->param(importdoms => $webvar{importdoms}) if $webvar{importdoms}; 604 605 ##work 606 607 ##fixme: check group too? 608 if ($webvar{doit} eq 'y' && !$webvar{ifrom}) { 609 $page->param(errmsg => "Need to set host to import from"); 610 } elsif ($webvar{doit} eq 'y' && !$webvar{importdoms}) { 611 $page->param(errmsg => "Need domains to import"); 612 } else { 613 my @domlist = split /\s+/, $webvar{importdoms}; 614 my @results; 615 my $rnum = 0; 616 foreach my $domain (@domlist) { 617 # do stuff! DNSDB::importAXFR($webvar{ifrom}, $webvar{rwsoa}, $webvar{rwns}, $domain, <flags>) 618 my %row; 619 $row{domain} = $domain; 620 # $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 } 628 push @results, \%row; 629 } 630 $page->param(axfrresults => \@results); 631 } 632 605 633 push @debugbits, "<pre>$webvar{importdoms}</pre>"; 606 634 } -
trunk/templates/axfr.tmpl
r32 r33 5 5 <td align="center"> 6 6 7 <TMPL_IF errmsg><div class="errmsg"> Query error: <TMPL_VARNAME=errmsg></div></TMPL_IF>7 <TMPL_IF errmsg><div class="errmsg">Error: <TMPL_VARNAME=errmsg></div></TMPL_IF> 8 8 9 9 <form action="dns.cgi" method="POST"> … … 35 35 </tr> 36 36 <tr class="datalinelight"> 37 <td>Import as active?</td> 38 <td><input type=checkbox name="domactive"<TMPL_UNLESS dominactive> checked</TMPL_UNLESS>></td> 39 </tr> 40 <tr class="datalinelight"> 37 41 <td valign="top">Domains to import:<br />(one per line)</td> 38 42 <td><textarea name="importdoms" rows=10><TMPL_IF importdoms><TMPL_VAR NAME=importdoms></TMPL_IF></textarea></td> … … 46 50 47 51 <TMPL_IF axfrresults> 52 <br /> 48 53 <table> 49 54 <tr class="tableheader"><td colspan=2>AXFR Import Results</td></tr> 50 55 <TMPL_LOOP NAME=axfrresults> 51 <TMPL_IF domok><tr class="tableheader"><td><TMPL_VAR NAME=domain></td><td>Imported OK</td></tr>52 <TMPL_ELSE><tr class="tableheader"><td><TMPL_VAR NAME=domain></td><td>Failed: <TMPL_VAR NAME=domerr></td></tr>53 56 <tr class="datalinelight"> 54 <td>Try again?</td> 55 <td> 56 <input type=radio name=try<TMPL_VAR NAME=row> value="0">No/Discard<br /> 57 <input type=radio name=try<TMPL_VAR NAME=row> value="R">Replace<br /> 58 <input type=radio name=try<TMPL_VAR NAME=row> value="M">Merge + Overwrite<br /> 59 <input type=radio name=try<TMPL_VAR NAME=row> value="M">Merge only new records 60 </td> 57 <td><TMPL_VAR NAME=domain></td> 58 <TMPL_IF domok> <td>Imported OK</td> 59 <TMPL_ELSE><TMPL_IF domwarn> <td class="warn">Warning: <TMPL_VAR NAME=domwarn></td> 60 <TMPL_ELSE> <td class="err">Failed: <TMPL_VAR NAME=domerr></td> 61 </TMPL_IF></TMPL_IF> 61 62 </tr> 62 </TMPL_IF>63 63 </TMPL_LOOP> 64 64 </table> -
trunk/templates/dns.css
r24 r33 70 70 background-color: #DDDDDD; 71 71 } 72 td.err { 73 border: solid 2px #FF0000; 74 color: red; 75 background-color: #e0e0e0; 76 } 77 td.warn { 78 border: solid 2px #FFFF00; 79 color: #333300; 80 background-color: #e0e0e0; 81 } 82 72 83 .meat { 73 84 align: center;
Note:
See TracChangeset
for help on using the changeset viewer.