Index: trunk/DNSDB.pm
===================================================================
--- trunk/DNSDB.pm	(revision 485)
+++ trunk/DNSDB.pm	(revision 487)
@@ -63,5 +63,5 @@
 	);
 
-@EXPORT		= (); # Export nothing by default.
+@EXPORT		= qw(%typemap %reverse_typemap %permissions @permtypes $permlist %permchains);
 %EXPORT_TAGS	= ( ALL => [qw(
 		&initGlobals &login &initActionLog
@@ -1697,5 +1697,5 @@
       $resultmsg = "Updated default permissions for group $name";
     }
-    _log($dbh, (group_id => ($type eq 'user' ? $parid : $id), entry => $resultmsg));
+    $self->_log(group_id => ($type eq 'user' ? $parid : $id), entry => $resultmsg);
     $dbh->commit;
   }; # end eval
@@ -1787,6 +1787,6 @@
     $dbh->do("UPDATE $par_tbl{$type} SET group_id=? WHERE $id_col{$type}=?", undef, ($newgrp, $id));
     # Log the change in both the old and new groups
-    _log($dbh, (group_id => $oldgid, entry => "Moved $type $entname from $oldgname to $newgname"));
-    _log($dbh, (group_id => $newgrp, entry => "Moved $type $entname from $oldgname to $newgname"));
+    $self->_log(group_id => $oldgid, entry => "Moved $type $entname from $oldgname to $newgname");
+    $self->_log(group_id => $newgrp, entry => "Moved $type $entname from $oldgname to $newgname");
     $dbh->commit;
   };
@@ -1795,5 +1795,5 @@
     eval { $dbh->rollback; };
     if ($config{log_failures}) {
-      _log($dbh, (group_id => $oldgid, entry => "Error moving $type $entname to $newgname: $msg"));
+      $self->_log(group_id => $oldgid, entry => "Error moving $type $entname to $newgname: $msg");
       $dbh->commit;	# since we enabled transactions earlier
     }
@@ -1858,6 +1858,6 @@
 	undef, ($domain));
 
-    _log($dbh, (domain_id => $dom_id, group_id => $group,
-	entry => "Added ".($state ? 'active' : 'inactive')." domain $domain"));
+    $self->_log(domain_id => $dom_id, group_id => $group,
+	entry => "Added ".($state ? 'active' : 'inactive')." domain $domain");
 
     # ... and now we construct the standard records from the default set.  NB:  group should be variable.
@@ -1873,13 +1873,13 @@
 	my @tmp1 = split /:/, $host;
 	my @tmp2 = split /:/, $val;
-	_log($dbh, (domain_id => $dom_id, group_id => $group,
+	$self->_log(domain_id => $dom_id, group_id => $group,
 		entry => "[new $domain] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ".
-		"[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl"));
+		"[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl");
       } else {
 	my $logentry = "[new $domain] Added record '$host $typemap{$type}";
 	$logentry .= " [distance $dist]" if $typemap{$type} eq 'MX';
 	$logentry .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$type} eq 'SRV';
-	_log($dbh, (domain_id => $dom_id, group_id => $group,
-		entry => $logentry." $val', TTL $ttl"));
+	$self->_log(domain_id => $dom_id, group_id => $group,
+		entry => $logentry." $val', TTL $ttl");
       }
     }
@@ -1892,5 +1892,5 @@
     my $msg = $@;
     eval { $dbh->rollback; };
-    _log($dbh, (group_id => $group, entry => "Failed adding domain $domain ($msg)"))
+    $self->_log(group_id => $group, entry => "Failed adding domain $domain ($msg)")
 	if $config{log_failures};
     $dbh->commit;	# since we enabled transactions earlier
@@ -1962,5 +1962,5 @@
     $msg = "Deleted ".($revrec eq 'n' ? 'domain' : 'reverse zone')." $zone";
     $loghash{entry} = $msg;
-    _log($dbh, %loghash);
+    $self->_log(%loghash);
 
     # once we get here, we should have suceeded.
@@ -1973,5 +1973,5 @@
     $loghash{entry} = "Error deleting $zone: $msg ($failmsg)";
     if ($config{log_failures}) {
-      _log($dbh, %loghash);
+      $self->_log(%loghash);
       $dbh->commit;	# since we enabled transactions earlier
     }
@@ -2089,6 +2089,6 @@
     ($rdns_id) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')");
 
-    _log($dbh, (rdns_id => $rdns_id, group_id => $group,
-	entry => "Added ".($state ? 'active' : 'inactive')." reverse zone $zone"));
+    $self->_log(rdns_id => $rdns_id, group_id => $group,
+	entry => "Added ".($state ? 'active' : 'inactive')." reverse zone $zone");
 
     # ... and now we construct the standard records from the default set.  NB:  group should be variable.
@@ -2154,12 +2154,12 @@
 	my @tmp1 = split /:/, $host;
 	my @tmp2 = split /:/, $val;
-	_log($dbh, (rdns_id => $rdns_id, group_id => $group,
+	$self->_log(rdns_id => $rdns_id, group_id => $group,
 		entry => "[new $zone] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ".
-		"[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl"));
+		"[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl");
 	$defttl = $tmp2[3];
       } else {
 	my $logentry = "[new $zone] Added record '$host $typemap{$type} $val', TTL $ttl";
 	$logentry .= ", default location ".$self->getLoc($defloc)->{description} if $defloc;
-	_log($dbh, (rdns_id => $rdns_id, domain_id => $domid, group_id => $group, entry => $logentry) );
+	$self->_log(rdns_id => $rdns_id, domain_id => $domid, group_id => $group, entry => $logentry);
       }
     }
@@ -2183,10 +2183,10 @@
       $sth_in->execute($domid,$host,$type,$val,$defttl,$defloc);
       my $logentry = "[new $zone] Added record '$host $typemap{$type}";
-      _log($dbh, (rdns_id => $rdns_id, domain_id => $domid, group_id => $group,
-	entry => $logentry." $val', TTL $defttl from pattern"));
+      $self->_log(rdns_id => $rdns_id, domain_id => $domid, group_id => $group,
+	entry => $logentry." $val', TTL $defttl from pattern");
     }
 
     # If there are warnings (presumably about default records skipped for cause) log them
-    _log($dbh, (rdns_id => $rdns_id, group_id => $group, entry => "Warning(s) adding $zone:$warnstr"))
+    $self->_log(rdns_id => $rdns_id, group_id => $group, entry => "Warning(s) adding $zone:$warnstr")
 	if $warnstr;
 
@@ -2198,5 +2198,5 @@
     my $msg = $@;
     eval { $dbh->rollback; };
-    _log($dbh, (group_id => $group, entry => "Failed adding reverse zone $zone ($msg)"))
+    $self->_log(group_id => $group, entry => "Failed adding reverse zone $zone ($msg)")
 	if $config{log_failures};
     $dbh->commit;	# since we enabled transactions earlier
@@ -2411,5 +2411,5 @@
     }
 
-    _log($dbh, (group_id => $pargroup, entry => "Added group $groupname") );
+    $self->_log(group_id => $pargroup, entry => "Added group $groupname");
 
     # once we get here, we should have suceeded.
@@ -2421,5 +2421,5 @@
     eval { $dbh->rollback; };
     if ($config{log_failures}) {
-      _log($dbh, (group_id => $pargroup, entry => "Failed to add group $groupname: $msg") );
+      $self->_log(group_id => $pargroup, entry => "Failed to add group $groupname: $msg");
       $dbh->commit;
     }
@@ -2474,5 +2474,5 @@
     $dbh->do("DELETE from groups WHERE group_id=?", undef, ($groupid));
 
-    _log($dbh, (group_id => $parid, entry => "Deleted group $groupname"));
+    $self->_log(group_id => $parid, entry => "Deleted group $groupname");
     $resultmsg = "Deleted group $groupname";
 
@@ -2485,5 +2485,5 @@
     eval { $dbh->rollback; };
     if ($config{log_failures}) {
-      _log($dbh, (group_id => $parid, entry => "$failmsg: $msg"));
+      $self->_log(group_id => $parid, entry => "$failmsg: $msg");
       $dbh->commit;	# since we enabled transactions earlier
     }
@@ -2757,5 +2757,5 @@
 ##fixme: add another table to hold name/email for log table?
 
-    _log($dbh, (group_id => $group, entry => "Added user $username ($fname $lname)"));
+    $self->_log(group_id => $group, entry => "Added user $username ($fname $lname)");
     # once we get here, we should have suceeded.
     $dbh->commit;
@@ -2766,5 +2766,5 @@
     eval { $dbh->rollback; };
     if ($config{log_failures}) {
-      _log($dbh, (group_id => $group, entry => "Error adding user $username: $msg"));
+      $self->_log(group_id => $group, entry => "Error adding user $username: $msg");
       $dbh->commit;	# since we enabled transactions earlier
     }
@@ -2918,5 +2918,5 @@
 	" WHERE user_id=?", undef, ($username, $pass, $fname, $lname, $phone, $type, $state, $uid));
     $resultmsg = "Updated user info for $username ($fname $lname)";
-    _log($dbh, group_id => $group, entry => $resultmsg);
+    $self->_log(group_id => $group, entry => $resultmsg);
     $dbh->commit;
   };
@@ -2925,5 +2925,5 @@
     eval { $dbh->rollback; };
     if ($config{log_failures}) {
-      _log($dbh, (group_id => $group, entry => "Error updating user $username: $msg"));
+      $self->_log(group_id => $group, entry => "Error updating user $username: $msg");
       $dbh->commit;	# since we enabled transactions earlier
     }
@@ -2955,7 +2955,7 @@
   eval {
     $dbh->do("DELETE FROM users WHERE user_id=?", undef, ($userid));
-    _log($dbh, (group_id => $userdata->{group_id},
+    $self->_log(group_id => $userdata->{group_id},
 	entry => "Deleted user ID $userid/".$userdata->{username}.
-		" (".$userdata->{firstname}." ".$userdata->{lastname}.")") );
+		" (".$userdata->{firstname}." ".$userdata->{lastname}.")");
     $dbh->commit;
   };
@@ -2964,6 +2964,6 @@
     eval { $dbh->rollback; };
     if ($config{log_failures}) {
-      _log($dbh, (group_id => $userdata->{group_id}, entry => "Error deleting user ID ".
-	"$userid/".$userdata->{username}.": $msg") );
+      $self->_log(group_id => $userdata->{group_id}, entry => "Error deleting user ID ".
+	"$userid/".$userdata->{username}.": $msg");
       $dbh->commit;
     }
@@ -3034,5 +3034,5 @@
       $loghash{group_id} = $self->parentID(id => $id, type => 'user');
       $loghash{entry} = $resultstr;
-      _log($dbh, %loghash);
+      $self->_log(%loghash);
 
       $dbh->commit;
@@ -3130,5 +3130,5 @@
     $dbh->do("INSERT INTO locations (location, group_id, iplist, description, comments) VALUES (?,?,?,?,?)", 
 	undef, ($loc, $grp, $iplist, $shdesc, $comments) );
-    _log($dbh, entry => "Added location ($shdesc, '$iplist')");
+    $self->_log(entry => "Added location ($shdesc, '$iplist')");
     $dbh->commit;
   };
@@ -3138,5 +3138,5 @@
     if ($config{log_failures}) {
       $shdesc = $loc if !$shdesc;
-      _log($dbh, (entry => "Failed adding location ($shdesc, '$iplist'): $msg"));
+      $self->_log(entry => "Failed adding location ($shdesc, '$iplist'): $msg");
       $dbh->commit;
     }
@@ -3177,5 +3177,5 @@
     $dbh->do("UPDATE locations SET group_id=?,iplist=?,description=?,comments=? WHERE location=?",
 	undef, ($grp, $iplist, $shdesc, $comments, $loc) );
-    _log($dbh, entry => $okmsg);
+    $self->_log(entry => $okmsg);
     $dbh->commit;
   };
@@ -3185,5 +3185,5 @@
     if ($config{log_failures}) {
       $shdesc = $loc if !$shdesc;
-      _log($dbh, (entry => "Failed updating location ($shdesc, '$iplist'): $msg"));
+      $self->_log(entry => "Failed updating location ($shdesc, '$iplist'): $msg");
       $dbh->commit;
     }
@@ -3216,5 +3216,5 @@
     die "Records still exist in location $olddesc\n" if $r;
     $dbh->do("DELETE FROM locations WHERE location=?", undef, ($loc) );
-    _log($dbh, entry => $okmsg);
+    $self->_log(entry => $okmsg);
     $dbh->commit;
   };
@@ -3223,5 +3223,5 @@
     eval { $dbh->rollback; };
     if ($config{log_failures}) {
-      _log($dbh, (entry => "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg"));
+      $self->_log(entry => "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg");
       $dbh->commit;
     }
@@ -3418,5 +3418,5 @@
 
     $logdata{entry} = $msg;
-    _log($dbh, %logdata);
+    $self->_log(%logdata);
 
     $dbh->commit;
@@ -3428,5 +3428,5 @@
 	"SOA record for $parname: $msg";
     if ($config{log_failures}) {
-      _log($dbh, %logdata);
+      $self->_log(%logdata);
       $dbh->commit;
     }
@@ -3683,5 +3683,5 @@
     $dbh->do("INSERT INTO "._rectable($defrec, $revrec)." ($fields) VALUES ($vallen)",
 	undef, @vallist);
-    _log($dbh, %logdata);
+    $self->_log(%logdata);
     $dbh->commit;
   };
@@ -3692,5 +3692,5 @@
       $logdata{entry} = "Failed adding ".($defrec eq 'y' ? 'default ' : '').
 	"record '$$host $typemap{$$rectype} $$val', TTL $ttl ($msg)";
-      _log($dbh, %logdata);
+      $self->_log(%logdata);
       $dbh->commit;
     }
@@ -3863,5 +3863,5 @@
   eval {
     $dbh->do("UPDATE "._rectable($defrec,$revrec)." SET $fields WHERE record_id=?", undef, (@vallist, $id) );
-    _log($dbh, %logdata);
+    $self->_log(%logdata);
     $dbh->commit;
   };
@@ -3872,5 +3872,5 @@
       $logdata{entry} = "Failed updating ".($defrec eq 'y' ? 'default ' : '').
 	"record '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl} ($msg)";
-      _log($dbh, %logdata);
+      $self->_log(%logdata);
       $dbh->commit;
     }
@@ -3974,5 +3974,5 @@
   eval {
     my $sth = $dbh->do("DELETE FROM "._rectable($defrec,$revrec)." WHERE record_id=?", undef, ($id));
-    _log($dbh, %logdata);
+    $self->_log(%logdata);
     $dbh->commit;
   };
@@ -3983,5 +3983,5 @@
       $logdata{entry} = "Error deleting ".($defrec eq 'y' ? 'default record' : 'record').
 	" '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl} ($msg)";
-      _log($dbh, %logdata);
+      $self->_log(%logdata);
       $dbh->commit;
     }
@@ -4304,5 +4304,5 @@
       $loghash{group_id} = $self->parentID(id => $id, type => ($revrec eq 'n' ? 'domain' : 'revzone'), revrec => $revrec);
       $loghash{entry} = $resultstr;
-      _log($dbh, %loghash);
+      $self->_log(%loghash);
 
       $dbh->commit;
@@ -4471,6 +4471,6 @@
       ($zone_id) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')");
       $domain_id = $zone_id;
-      _log($dbh, (group_id => $group, domain_id => $domain_id,
-		entry => "[Added ".($status ? 'active' : 'inactive')." domain $zone via AXFR]") );
+      $self->_log(group_id => $group, domain_id => $domain_id,
+		entry => "[Added ".($args{status} ? 'active' : 'inactive')." domain $zone via AXFR]");
     } else {
 ##fixme:  serial
@@ -4480,6 +4480,6 @@
       ($zone_id) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')");
       $rdns_id = $zone_id;
-      _log($dbh, (group_id => $group, rdns_id => $rdns_id,
-		entry => "[Added ".($status ? 'active' : 'inactive')." reverse zone $cidr via AXFR]") );
+      $self->_log(group_id => $group, rdns_id => $rdns_id,
+		entry => "[Added ".($args{status} ? 'active' : 'inactive')." reverse zone $cidr via AXFR]");
     }
 
@@ -4649,5 +4649,5 @@
 		($domain_id, $ettl, $etype, $erid));
 	    $nrecs++;
-	    _log($dbh, (group_id => $group, domain_id => $domain_id, rdns_id => $erdns, entry => $logentry) );
+	    $self->_log(group_id => $group, domain_id => $domain_id, rdns_id => $erdns, entry => $logentry);
 	    next;	# while axfr_next
 	  }
@@ -4671,5 +4671,5 @@
 		($rdns_id, $ettl, $etype, $erid));
 	    $nrecs++;
-	    _log($dbh, (group_id => $group, domain_id => $domid, rdns_id => $rdns_id, entry => $logentry) );
+	    $self->_log(group_id => $group, domain_id => $domid, rdns_id => $rdns_id, entry => $logentry);
 	    next;	# while axfr_next
 	  }
@@ -4698,5 +4698,5 @@
 	$logentry .= " $val', TTL $ttl";
       }
-      _log($dbh, (group_id => $group, domain_id => $domain_id, rdns_id => $rdns_id, entry => $logentry) );
+      $self->_log(group_id => $group, domain_id => $domain_id, rdns_id => $rdns_id, entry => $logentry);
 
     } # while axfr_next
