Changeset 254
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r252 r254 36 36 &addRec &updateRec &delRec 37 37 &getTypelist 38 & getParents38 &parentID 39 39 &isParent 40 40 &domStatus &importAXFR … … 58 58 &addRec &updateRec &delRec 59 59 &getTypelist 60 & getParents60 &parentID 61 61 &isParent 62 62 &domStatus &importAXFR … … 2235 2235 2236 2236 2237 ## DNSDB::getParents() 2238 # Find out which entities are parent to the requested id 2239 # Returns arrayref containing hash pairs of id/type 2240 sub getParents { 2241 my $dbh = shift; 2242 my $id = shift; 2243 my $type = shift; 2244 my $depth = shift || 'all'; # valid values: 'all', 'immed', <int> (stop at this group ID) 2245 2246 my @parlist; 2247 2248 while (1) { 2249 my $result = $dbh->selectrow_hashref("SELECT $par_col{$type} FROM $par_tbl{$type} WHERE $id_col{$type} = ?", 2250 undef, ($id) ); 2251 my %tmp = ($result->{$par_col{$type}} => $par_type{$type}); 2252 unshift @parlist, \%tmp; 2253 last if $result->{$par_col{$type}} == 1; # group 1 is its own parent 2254 $id = $result->{$par_col{$type}}; 2255 $type = $par_type{$type}; 2256 } 2257 2258 return \@parlist; 2259 2260 } # end getParents() 2237 ## DNSDB::parentID() 2238 # Get ID of entity that is nearest parent to requested id 2239 # Takes a database handle and a hash of entity ID, entity type, optional parent type flag 2240 # (domain/reverse zone or group), and optional default/live and forward/reverse flags 2241 # Returns the ID or undef on failure 2242 sub parentID { 2243 my $dbh = shift; 2244 2245 my %args = @_; 2246 2247 # clean up the parent-type. Set it to group if not set; coerce revzone to domain for simpler logic 2248 $args{partype} = 'group' if !$args{partype}; 2249 $args{partype} = 'domain' if $args{partype} eq 'revzone'; 2250 2251 # clean up defrec and revrec. default to live record, forward zone 2252 $args{defrec} = 'n' if !$args{defrec}; 2253 $args{revrec} = 'n' if !$args{revrec}; 2254 2255 if ($par_type{$args{partype}} eq 'domain') { 2256 # only live records can have a domain/zone parent 2257 return unless ($args{type} eq 'record' && $args{defrec} eq 'n'); 2258 my $result = $dbh->selectrow_hashref("SELECT ".($args{revrec} eq 'n' ? 'domain_id' : 'rdns_id'). 2259 " FROM records WHERE record_id = ?", 2260 undef, ($args{id}) ) or return; 2261 return $result; 2262 } else { 2263 # snag some arguments that will either fall through or be overwritten to save some code duplication 2264 my $tmpid = $args{id}; 2265 my $type = $args{type}; 2266 if ($type eq 'record' && $args{defrec} eq 'n') { 2267 # Live records go through the records table first. 2268 ($tmpid) = $dbh->selectrow_array("SELECT ".($args{revrec} eq 'n' ? 'domain_id' : 'rdns_id'). 2269 " FROM records WHERE record_id = ?", 2270 undef, ($args{id}) ) or return; 2271 $type = ($args{revrec} eq 'n' ? 'domain' : 'revzone'); 2272 } 2273 my ($result) = $dbh->selectrow_array("SELECT $par_col{$type} FROM $par_tbl{$type} WHERE $id_col{$type} = ?", 2274 undef, ($tmpid) ); 2275 return $result; 2276 } 2277 # should be impossible to get here with even remotely sane arguments 2278 return; 2279 } # end parentID() 2261 2280 2262 2281 -
trunk/dns.cgi
r253 r254 314 314 my $stat = domStatus($dbh,$webvar{id},$webvar{domstatus}); 315 315 ##fixme switch to more consise "Enabled <domain"/"Disabled <domain>" as with users? 316 logaction($webvar{id}, $session->param("username"), parentID($webvar{id}, 'dom', 'group'), 316 logaction($webvar{id}, $session->param("username"), 317 parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec})), 317 318 "Changed ".domainName($dbh, $webvar{id})." state to ".($stat ? 'active' : 'inactive')); 318 319 $page->param(resultmsg => "Changed ".domainName($dbh, $webvar{id})." state to ". … … 403 404 404 405 } elsif ($webvar{del} eq 'ok') { 405 my $pargroup = parentID($ webvar{id}, 'dom', 'group');406 my $pargroup = parentID($dbh, (id => $webvar{id}, type => 'domain', revrec => $webvar{revrec})); 406 407 my $dom = domainName($dbh, $webvar{id}); 407 408 my ($code,$msg) = delDomain($dbh, $webvar{id}); … … 587 588 if $typemap{$webvar{type}} eq 'SRV'; 588 589 $restr .= " $webvar{address}', TTL $webvar{ttl}"; 589 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), $restr); 590 logaction($webvar{parentid}, $session->param("username"), 591 parentID($dbh, (id => $webvar{parentid}, type => 'domain', revrec => $webvar{revrec})), $restr); 590 592 } 591 593 my %pageparams = (page => "reclist", id => $webvar{parentid}, … … 608 610 "Failed adding default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)"); 609 611 } else { 610 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), 612 logaction($webvar{parentid}, $session->param("username"), 613 parentID($dbh, (id => $webvar{parentid}, type => 'domain', revrec => $webvar{revrec})), 611 614 "Failed adding record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)"); 612 615 } … … 658 661 my $restr = "Updated record from '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl}\n". 659 662 "to '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}"; 660 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{id}, 'rec', 'group'), $restr); 663 logaction($webvar{parentid}, $session->param("username"), 664 parentID($dbh, (id => $webvar{id}, type => 'record', defrec => $webvar{defrec}, 665 revrec => $webvar{revrec}, partype => 'group')), 666 $restr); 661 667 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr); 662 668 } … … 675 681 "Failed updating default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)"); 676 682 } else { 677 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), 683 logaction($webvar{parentid}, $session->param("username"), 684 parentID($dbh, (id => $webvar{parentid}, type => 'domain', revrec => $webvar{revrec})), 678 685 "Failed updating record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)"); 679 686 } … … 735 742 my $recclass = ($webvar{revrec} eq 'n' ? 'record' : 'reverse record'); 736 743 my $restr = "Deleted $recclass '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl}"; 737 logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'), $restr); 744 logaction($rec->{parid}, $session->param("username"), 745 parentID($dbh, (id => $rec->{parid}, type => 'domain', revrec => $webvar{revrec})), 746 $restr); 738 747 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, 739 748 revrec => $webvar{revrec}, resultmsg => $restr); … … 747 756 " TTL $rec->{ttl} ($msg)"); 748 757 } else { 749 logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'), 758 logaction($rec->{parid}, $session->param("username"), 759 parentID($dbh, (id => $rec->{parid}, type => 'domain', revrec => $webvar{revrec})), 750 760 "Failed deleting record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl} ($msg)"); 751 761 } … … 828 838 $logdomain = 0; 829 839 } else { 830 $loggroup = parentID($ logdomain, 'dom', 'group', $webvar{defrec});840 $loggroup = parentID($dbh, (id => $logdomain, type => 'domain', revrec => $webvar{revrec})); 831 841 } 832 842 … … 936 946 } elsif ($webvar{del} eq 'ok') { 937 947 my $deleteme = groupName($dbh,$webvar{id}); # get this before we delete it... 938 my $delparent = parentID($ webvar{id}, 'group','group');948 my $delparent = parentID($dbh, (id => $webvar{id}, type => 'group')); 939 949 my ($code,$msg) = delGroup($dbh, $webvar{id}); 940 950 if ($code eq 'OK') { … … 1079 1089 my ($code, $msg) = changeGroup($dbh, 'domain', $webvar{$_}, $webvar{destgroup}); 1080 1090 if ($code eq 'OK') { 1081 logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'), 1091 logaction($webvar{$_}, $session->param("username"), 1092 parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})), 1082 1093 "Moved domain ".domainName($dbh, $webvar{$_})." to group $newgname"); 1083 1094 $row{domok} = ($code eq 'OK'); 1084 1095 } else { 1085 logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'), 1096 logaction($webvar{$_}, $session->param("username"), 1097 parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})), 1086 1098 "Failed to move domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg") 1087 1099 if $config{log_failures}; … … 1110 1122 ##fixme: error handling on status change 1111 1123 my $stat = domStatus($dbh,$webvar{$_},($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff')); 1112 logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'), 1113 "Changed domain ".domainName($dbh, $webvar{$_})." state to ".($stat ? 'active' : 'inactive')); 1124 logaction($webvar{$_}, $session->param("username"), 1125 parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})), 1126 "Changed domain ".domainName($dbh, $webvar{$_})." state to ".($stat ? 'active' : 'inactive')); 1114 1127 $row{domok} = 1; 1115 1128 # $row{domok} = ($code eq 'OK'); … … 1135 1148 } 1136 1149 $row{domain} = domainName($dbh,$webvar{$_}); 1137 my $pargroup = parentID($ webvar{$_}, 'dom', 'group');1150 my $pargroup = parentID($dbh, (id => $webvar{$_}, type => 'domain', revrec => $webvar{revrec})); 1138 1151 my $dom = domainName($dbh, $webvar{$_}); 1139 1152 my ($code, $msg) = delDomain($dbh, $webvar{$_}); … … 1168 1181 if ($flag && ($permissions{admin} || $permissions{user_edit})) { 1169 1182 my $stat = userStatus($dbh,$webvar{id},$webvar{userstatus}); 1170 logaction(0, $session->param("username"), parentID($ webvar{id}, 'user', 'group'),1183 logaction(0, $session->param("username"), parentID($dbh, (id => $webvar{id}, type => 'user')), 1171 1184 ($stat ? 'Enabled' : 'Disabled')." ".userFullName($dbh, $webvar{id}, '%u')); 1172 1185 $page->param(resultmsg => ($stat ? 'Enabled' : 'Disabled')." ".userFullName($dbh, $webvar{id}, '%u')); … … 2255 2268 2256 2269 2257 ##fixme: generalize to return appropriate id on all cases (ie, use $partype)2258 sub parentID {2259 my $id = shift;2260 my $idtype = shift;2261 my $partype = shift;2262 my $defrec = shift || '';2263 2264 my $sql = '';2265 2266 if ($idtype eq 'dom') {2267 return $id if $defrec eq 'y'; # "domain" + default records, we're really looking at a group.2268 $sql = "SELECT group_id FROM domains WHERE domain_id=?";2269 } elsif ($idtype eq 'rec') {2270 if ($defrec eq 'y') {2271 $sql = "SELECT group_id FROM default_records WHERE record_id=?";2272 } else {2273 $sql = "SELECT d.group_id FROM domains d".2274 " INNER JOIN records r ON d.domain_id=r.domain_id".2275 " WHERE r.record_id=?";2276 }2277 } elsif ($idtype eq 'group') {2278 $sql = "SELECT parent_group_id FROM groups WHERE group_id=?";2279 } elsif ($idtype eq 'user') {2280 $sql = "SELECT group_id FROM users WHERE user_id=?";2281 } else {2282 return "FOO", "BAR"; # can't get here.... we think.2283 }2284 my $sth = $dbh->prepare($sql);2285 $sth->execute($id);2286 my ($retid) = $sth->fetchrow_array;2287 return $retid if $retid;2288 # ahh! fall of the edge of the world if things went sideways2289 ##fixme: really need to do a little more error handling, I think2290 } # end parentID()2291 2292 2293 2270 # we have to do this in a variety of places; let's make it consistent 2294 2271 sub fill_permissions {
Note:
See TracChangeset
for help on using the changeset viewer.