Changeset 311
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r309 r311 2494 2494 my $rev = shift; 2495 2495 my $id = shift; 2496 my %ret;2497 2496 2498 2497 # (ab)use distance and weight columns to store SOA data? can't for default_rev_records... … … 2501 2500 my $sql = "SELECT record_id,host,val,ttl from "._rectable($def,$rev). 2502 2501 " WHERE "._recparent($def,$rev)." = ? AND type=$reverse_typemap{SOA}"; 2503 2504 my $sth = $dbh->prepare($sql); 2505 $sth->execute($id); 2502 my $ret = $dbh->selectrow_hashref($sql, undef, ($id) ); 2503 return if !$ret; 2506 2504 ##fixme: stick a flag somewhere if the record doesn't exist. by the API, this is an impossible case, but... 2507 2505 2508 my ($recid,$host,$val,$ttl) = $sth->fetchrow_array() or return; 2509 my ($contact,$prins) = split /:/, $host; 2510 my ($refresh,$retry,$expire,$minttl) = split /:/, $val; 2511 2512 $ret{recid} = $recid; 2513 $ret{ttl} = $ttl; 2514 # $ret{serial} = $serial; # ca't use distance for serial with default_rev_records 2515 $ret{prins} = $prins; 2516 $ret{contact} = $contact; 2517 $ret{refresh} = $refresh; 2518 $ret{retry} = $retry; 2519 $ret{expire} = $expire; 2520 $ret{minttl} = $minttl; 2521 2522 return %ret; 2506 ($ret->{contact},$ret->{prins}) = split /:/, $ret->{host}; 2507 delete $ret->{host}; 2508 ($ret->{refresh},$ret->{retry},$ret->{expire},$ret->{minttl}) = split /:/, $ret->{val}; 2509 delete $ret->{val}; 2510 2511 return $ret; 2523 2512 } # end getSOA() 2524 2513 … … 2535 2524 my %soa = @_; 2536 2525 2537 my %oldsoa = getSOA($dbh, $defrec, $revrec, $soa{recid}); 2526 my $oldsoa = getSOA($dbh, $defrec, $revrec, $soa{id}); 2527 2528 my $msg; 2529 my %logdata; 2530 if ($defrec eq 'n') { 2531 $logdata{domain_id} = $soa{id} if $revrec eq 'n'; 2532 $logdata{rdns_id} = $soa{id} if $revrec eq 'y'; 2533 $logdata{group_id} = parentID($dbh, (id => $soa{id}, revrec => $revrec, 2534 type => ($revrec eq 'n' ? 'domain' : 'revzone') ) ); 2535 } else { 2536 $logdata{group_id} = $soa{id}; 2537 } 2538 my $parname = ($defrec eq 'y' ? groupName($dbh, $soa{id}) : 2539 ($revrec eq 'n' ? domainName($dbh, $soa{id}) : revName($dbh, $soa{id})) ); 2538 2540 2539 2541 # Allow transactions, and raise an exception on errors so we can catch it later. … … 2542 2544 local $dbh->{RaiseError} = 1; 2543 2545 2544 my $msg;2545 2546 2546 eval { 2547 ##fixme: data validation: make sure {recid} is really the SOA for {parent}2548 2547 my $sql = "UPDATE "._rectable($defrec, $revrec)." SET host=?, val=?, ttl=? WHERE record_id=? AND type=6"; 2549 2548 $dbh->do($sql, undef, ("$soa{contact}:$soa{prins}", "$soa{refresh}:$soa{retry}:$soa{expire}:$soa{minttl}", 2550 $soa{ttl}, $soa{recid}) ); 2551 2552 $msg = "Updated ".($defrec eq 'y' ? 'default ' : '')."SOA for ". 2553 ($defrec eq 'y' ? groupName($dbh, $soa{recid}) : 2554 ($revrec eq 'n' ? domainName($dbh, $soa{recid}) : revName($dbh, $soa{recid}) ) ). 2555 ": (ns $oldsoa{prins}, contact $oldsoa{contact}, refresh $oldsoa{refresh},". 2556 " retry $oldsoa{retry}, expire $oldsoa{expire}, minTTL $oldsoa{minttl}, TTL $oldsoa{ttl}) to ". 2549 $soa{ttl}, $oldsoa->{record_id}) ); 2550 $msg = "Updated ".($defrec eq 'y' ? ($revrec eq 'y' ? 'default reverse ' : 'default ') : ''). 2551 "SOA for $parname: ". 2552 "(ns $oldsoa->{prins}, contact $oldsoa->{contact}, refresh $oldsoa->{refresh},". 2553 " retry $oldsoa->{retry}, expire $oldsoa->{expire}, minTTL $oldsoa->{minttl}, TTL $oldsoa->{ttl}) to ". 2557 2554 "(ns $soa{prins}, contact $soa{contact}, refresh $soa{refresh},". 2558 2555 " retry $soa{retry}, expire $soa{expire}, minTTL $soa{minttl}, TTL $soa{ttl})"; 2559 2556 2560 # _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group, 2561 # username => $userinfo{name}, entry => $msg));2557 $logdata{entry} = $msg; 2558 _log($dbh, %logdata); 2562 2559 2563 2560 $dbh->commit; … … 2566 2563 $msg = $@; 2567 2564 eval { $dbh->rollback; }; 2568 return ('FAIL',$msg); 2565 $logdata{entry} = "Error updating ".($defrec eq 'y' ? ($revrec eq 'y' ? 'default reverse zone ' : 'default ') : ''). 2566 "SOA record for $parname: $msg"; 2567 if ($config{log_failures}) { 2568 _log($dbh, %logdata); 2569 $dbh->commit; 2570 } 2571 return ('FAIL', $logdata{entry}); 2569 2572 } else { 2570 2573 return ('OK', $msg); -
trunk/dns.cgi
r310 r311 804 804 if (!check_scope(id => $webvar{recid}, type => 805 805 ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) { 806 ##fixme: should we redirect to the requested record list page instead of the domain list? 806 807 changepage(page => 'domlist', errmsg => "You do not have permission to edit the requested SOA record"); 807 808 } … … 809 810 if (!check_scope(id => $webvar{id}, type => 810 811 ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) { 811 changepage(page => 'domlist', errmsg => "You do not have permission to edit the ". 812 changepage(page => ($webvar{revrec} eq 'y' ? 'revzones' : 'domlist'), 813 errmsg => "You do not have permission to edit the ". 812 814 ($webvar{defrec} eq 'y' ? 'default ' : '')."SOA record for the requested ". 813 ($webvar{defrec} eq 'y' ? 'group' : 'domain'));815 ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'reverse zone' : 'domain')) ); 814 816 } 815 817 … … 817 819 unless ($permissions{admin} || $permissions{domain_edit}); 818 820 819 # get old SOA for log820 my %soa = getSOA($dbh,$webvar{defrec},$webvar{revrec},$webvar{id});821 822 # my $sth;823 ###fixme: push SQL into DNSDB.pm824 ###fixme: data validation: make sure {recid} is really the SOA for {id}825 # # no domain ID, so we're editing the default SOA for a group (we don't care which one here)826 # # plus a bit of magic to update the appropriate table827 # my $sql = "UPDATE ".($webvar{defrec} eq 'y' ? "default_records" : "records").828 # " SET host=?, val=?, ttl=? WHERE record_id=?";829 # $sth = $dbh->prepare($sql);830 # $sth->execute("$webvar{contact}:$webvar{prins}",831 # "$webvar{refresh}:$webvar{retry}:$webvar{expire}:$webvar{minttl}",832 # $webvar{ttl},833 # $webvar{recid});834 835 821 my ($code, $msg) = updateSOA($dbh, $webvar{defrec}, $webvar{revrec}, 836 822 (contact => $webvar{contact}, prins => $webvar{prins}, refresh => $webvar{refresh}, 837 retry => $webvar{retry}, expire => $webvar{expire}, minttl => $ soa{minttl},838 ttl => $webvar{ttl}, recid => $webvar{recid}) );823 retry => $webvar{retry}, expire => $webvar{expire}, minttl => $webvar{minttl}, 824 ttl => $webvar{ttl}, id => $webvar{id}) ); 839 825 if ($code eq 'OK') { 840 826 changepage(page => "reclist", id => $webvar{id}, defrec => $webvar{defrec}, revrec => $webvar{revrec}, … … 842 828 } else { 843 829 $page->param(update_failed => 1); 844 $page->param(msg => $DNSDB::errstr); 845 fillsoa($webvar{defrec},$webvar{revrec},$webvar{id}); 846 } 847 848 ##fixme: faillog 849 # } else { 850 if (0) { 851 # do this in the order of "default to most common case" 852 my $loggroup; 853 my $logdomain = $webvar{id}; 854 if ($webvar{defrec} eq 'y') { 855 $loggroup = $webvar{id}; 856 $logdomain = 0; 857 } else { 858 $loggroup = parentID($dbh, (id => $logdomain, type => 'domain', revrec => $webvar{revrec})); 859 } 860 861 logaction($logdomain, $session->param("username"), $loggroup, 862 "Updated ".($webvar{defrec} eq 'y' ? 'default ' : '')."SOA for ". 863 ($webvar{defrec} eq 'y' ? groupName($dbh, $webvar{id}) : domainName($dbh, $webvar{id}) ). 864 ": (ns $soa{prins}, contact $soa{contact}, refresh $soa{refresh},". 865 " retry $soa{retry}, expire $soa{expire}, minTTL $soa{minttl}, TTL $soa{ttl}) to ". 866 "(ns $webvar{prins}, contact $webvar{contact}, refresh $webvar{refresh},". 867 " retry $webvar{retry}, expire $webvar{expire}, minTTL $webvar{minttl}, TTL $webvar{ttl})"); 868 } # if (0) 830 $page->param(msg => $msg); 831 fillsoa($webvar{defrec}, $webvar{revrec}, $webvar{id}, 'w'); 832 } 869 833 870 834 } elsif ($webvar{page} eq 'grpman') { … … 1723 1687 my $revrec = shift; 1724 1688 my $id = shift; 1689 my $preserve = shift || 'd'; # Flag to use webvar fields or retrieve from database 1690 1725 1691 my $domname = ($defrec eq 'y' ? '' : "DOMAIN"); 1726 1692 … … 1744 1710 $page->param(defminttl => $DNSDB::def{minttl}); 1745 1711 1746 # there are probably better ways to do this. TMTOWTDI.1747 my %soa = getSOA($dbh,$defrec,$revrec,$id);1748 1749 1712 $page->param(id => $id); 1750 $page->param(recid => $soa{recid}); 1751 $page->param(prins => ($soa{prins} ? $soa{prins} : $DNSDB::def{prins})); 1752 $page->param(contact => ($soa{contact} ? $soa{contact} : $DNSDB::def{contact})); 1753 $page->param(refresh => ($soa{refresh} ? $soa{refresh} : $DNSDB::def{refresh})); 1754 $page->param(retry => ($soa{retry} ? $soa{retry} : $DNSDB::def{retry})); 1755 $page->param(expire => ($soa{expire} ? $soa{expire} : $DNSDB::def{expire})); 1756 $page->param(minttl => ($soa{minttl} ? $soa{minttl} : $DNSDB::def{minttl})); 1757 $page->param(ttl => ($soa{ttl} ? $soa{ttl} : $DNSDB::def{soattl})); 1713 1714 if ($preserve eq 'd') { 1715 # there are probably better ways to do this. TMTOWTDI. 1716 my $soa = getSOA($dbh,$defrec,$revrec,$id); 1717 1718 $page->param(prins => ($soa->{prins} ? $soa->{prins} : $DNSDB::def{prins})); 1719 $page->param(contact => ($soa->{contact} ? $soa->{contact} : $DNSDB::def{contact})); 1720 $page->param(refresh => ($soa->{refresh} ? $soa->{refresh} : $DNSDB::def{refresh})); 1721 $page->param(retry => ($soa->{retry} ? $soa->{retry} : $DNSDB::def{retry})); 1722 $page->param(expire => ($soa->{expire} ? $soa->{expire} : $DNSDB::def{expire})); 1723 $page->param(minttl => ($soa->{minttl} ? $soa->{minttl} : $DNSDB::def{minttl})); 1724 $page->param(ttl => ($soa->{ttl} ? $soa->{ttl} : $DNSDB::def{soattl})); 1725 } else { 1726 $page->param(prins => ($webvar{prins} ? $webvar{prins} : $DNSDB::def{prins})); 1727 $page->param(contact => ($webvar{contact} ? $webvar{contact} : $DNSDB::def{contact})); 1728 $page->param(refresh => ($webvar{refresh} ? $webvar{refresh} : $DNSDB::def{refresh})); 1729 $page->param(retry => ($webvar{retry} ? $webvar{retry} : $DNSDB::def{retry})); 1730 $page->param(expire => ($webvar{expire} ? $webvar{expire} : $DNSDB::def{expire})); 1731 $page->param(minttl => ($webvar{minttl} ? $webvar{minttl} : $DNSDB::def{minttl})); 1732 $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{soattl})); 1733 } 1758 1734 } 1759 1735 … … 1764 1740 1765 1741 # get the SOA first 1766 my %soa = getSOA($dbh,$def,$rev,$id);1767 1768 $page->param(contact => $soa {contact});1769 $page->param(prins => $soa {prins});1770 $page->param(refresh => $soa {refresh});1771 $page->param(retry => $soa {retry});1772 $page->param(expire => $soa {expire});1773 $page->param(minttl => $soa {minttl});1774 $page->param(ttl => $soa {ttl});1742 my $soa = getSOA($dbh,$def,$rev,$id); 1743 1744 $page->param(contact => $soa->{contact}); 1745 $page->param(prins => $soa->{prins}); 1746 $page->param(refresh => $soa->{refresh}); 1747 $page->param(retry => $soa->{retry}); 1748 $page->param(expire => $soa->{expire}); 1749 $page->param(minttl => $soa->{minttl}); 1750 $page->param(ttl => $soa->{ttl}); 1775 1751 1776 1752 my $foo2 = getDomRecs($dbh,$def,$rev,$id,$perpage,$webvar{offset},$sortby,$sortorder,$filter); … … 1820 1796 } 1821 1797 # retrieve the right ttl instead of falling (way) back to the hardcoded system default 1822 my %soa = getSOA($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid});1823 $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $soa {minttl}));1798 my $soa = getSOA($dbh,$webvar{defrec},$webvar{revrec},$webvar{parentid}); 1799 $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $soa->{minttl})); 1824 1800 } 1825 1801 -
trunk/templates/editsoa.tmpl
r277 r311 16 16 <input type="hidden" name="page" value="updatesoa" /> 17 17 <input type="hidden" name="id" value="<TMPL_VAR NAME=id>" /> 18 <input type="hidden" name="recid" value="<TMPL_VAR NAME=recid>" />19 18 <input type="hidden" name="defrec" value="<TMPL_VAR NAME=defrec>" /> 20 19 <input type="hidden" name="revrec" value="<TMPL_VAR NAME=revrec>" />
Note:
See TracChangeset
for help on using the changeset viewer.