Changeset 281


Ignore:
Timestamp:
03/22/12 15:31:21 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up some lingering structural messes in DNSDB.pm

  • Make comment headers on all utility subs consistent
  • Move _log() into "utility subs" grouping. Remove commented user-info-finding code in passing.
  • Add heading comment on validation subs since it would be pretty much the same for all of them.

Fix a bug in addRec() in passing as well; weight and port were
shift'ed from the argument list in the wrong order.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r279 r281  
    156156##
    157157## utility functions
    158 # _rectable()
     158##
     159
     160## DNSDB::_rectable()
    159161# Takes default+rdns flags, returns appropriate table name
    160162sub _rectable {
     
    167169} # end _rectable()
    168170
    169 # _recparent()
     171## DNSDB::_recparent()
    170172# Takes default+rdns flags, returns appropriate parent-id column name
    171173sub _recparent {
     
    178180} # end _recparent()
    179181
     182## DNSDB::_ipparent()
    180183# Check an IP to be added in a reverse zone to see if it's really in the requested parent.
    181184# Takes a database handle, default and reverse flags, IP (fragment) to check, parent zone ID,
     
    241244} # end _ipparent()
    242245
     246## DNSDB::_hostparent()
    243247# A little different than _ipparent above;  this tries to *find* the parent zone of a hostname
     248# Takes a database handle and hostname.
     249# Returns the domain ID of the parent domain if one was found.
    244250sub _hostparent {
    245251  my $dbh = shift;
     
    258264} # end _hostparent()
    259265
     266## DNSDB::_log()
     267# Log an action
     268# Takes a database handle and log entry hash containing at least:
     269#  user_id, group_id, log entry
     270# and optionally one or more of:
     271#  domain_id, rdns_id
     272sub _log {
     273  my $dbh = shift;
     274
     275  my %args = @_;
     276
     277  $args{rdns_id} = 0 if !$args{rdns_id};
     278  $args{domain_id} = 0 if !$args{domain_id};
     279
     280##fixme:  farm out the actual logging to different subs for file, syslog, internal, etc based on config
     281#  if ($config{log_channel} eq 'sql') {
     282  $dbh->do("INSERT INTO log (domain_id,rdns_id,group_id,entry,user_id,email,name) VALUES (?,?,?,?,?,?,?)",
     283        undef,
     284        ($args{domain_id}, $args{rdns_id}, $args{group_id}, $args{entry},
     285                $userdata{userid}, $userdata{username}, $userdata{fullname}) );
     286#  } elsif ($config{log_channel} eq 'file') {
     287#  } elsif ($config{log_channel} eq 'syslog') {
     288#  }
     289} # end _log
     290
     291
    260292##
    261293## Record validation subs.
    262294##
     295
     296## All of these subs take substantially the same arguments:
     297# a database handle
     298# a hash containing at least the following keys:
     299#  - defrec (default/live flag)
     300#  - revrec (forward/reverse flag)
     301#  - id (parent entity ID)
     302#  - host (hostname)
     303#  - rectype
     304#  - val (IP, hostname [CNAME/MX/SRV] or text)
     305#  - addr (NetAddr::IP object from val.  May be undef.)
     306# MX and SRV record validation also expect distance, and SRV records expect weight and port as well.
     307# host, rectype, and addr should be references as these may be modified in validation
    263308
    264309# A record
     
    11921237
    11931238
    1194 ## DNSDB::_log()
    1195 # Log an action
    1196 # Internal sub
    1197 # Takes a database handle and log entry hash containing at least:
    1198 # user_id, group_id, log entry
    1199 # and optionally one or more of:
    1200 # username/email, user full name, domain_id, rdns_id
    1201 ##fixme:  convert to trailing hash for user info
    1202 # User info must contain a (user ID OR username)+fullname
    1203 sub _log {
    1204   my $dbh = shift;
    1205 
    1206   my %args = @_;
    1207 
    1208   $args{rdns_id} = 0 if !$args{rdns_id};
    1209   $args{domain_id} = 0 if !$args{domain_id};
    1210 
    1211 ##fixme:  need better way(s?) to snag userinfo for log entries.  don't want to have
    1212 # to pass around yet *another* constant (already passing $dbh, shouldn't need to)
    1213 #  my $fullname;
    1214 #  if (!$args{user_id}) {
    1215 #    ($args{user_id}, $fullname) = $dbh->selectrow_array("SELECT user_id, firstname || ' ' || lastname FROM users".
    1216 #       " WHERE username=?", undef, ($args{username}));
    1217 #  }
    1218 #  if (!$args{username}) {
    1219 #    ($args{username}, $fullname) = $dbh->selectrow_array("SELECT username, firstname || ' ' || lastname FROM users".
    1220 #       " WHERE user_id=?", undef, ($args{user_id}));
    1221 #  }
    1222 #  if (!$args{fullname}) {
    1223 #    ($fullname) = $dbh->selectrow_array("SELECT firstname || ' ' || lastname FROM users".
    1224 #       " WHERE user_id=?", undef, ($args{user_id}));
    1225 #  }
    1226 #
    1227 #  $args{name} = $fullname if !$args{name};
    1228 
    1229 ##fixme:  farm out the actual logging to different subs for file, syslog, internal, etc based on config
    1230 #  if ($config{log_channel} eq 'sql') {
    1231   $dbh->do("INSERT INTO log (domain_id,rdns_id,group_id,entry,user_id,email,name) VALUES (?,?,?,?,?,?,?)",
    1232         undef,
    1233         ($args{domain_id}, $args{rdns_id}, $args{group_id}, $args{entry},
    1234                 $userdata{userid}, $userdata{username}, $userdata{fullname}) );
    1235 #  } elsif ($config{log_channel} eq 'file') {
    1236 #  } elsif ($config{log_channel} eq 'syslog') {
    1237 #  }
    1238 
    1239 } # end _log
    1240 
    1241 
    12421239##
    12431240## Processing subs
     
    24622459  # Collect these even if we're only doing a simple A record so we can call *any* validation sub
    24632460  my $dist = shift;
     2461  my $weight = shift;
    24642462  my $port = shift;
    2465   my $weight = shift;
    24662463
    24672464  my $fields;
Note: See TracChangeset for help on using the changeset viewer.