Changeset 256 for trunk


Ignore:
Timestamp:
03/02/12 16:08:45 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Update internal _log() sub to handle rdns_id
Update existing calls to _log() in addDomain()
See #26

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r255 r256  
    10001000# Log an action
    10011001# Internal sub
    1002 # Takes a database handle, domain_id, user_id, group_id, email, name and log entry
     1002# Takes a database handle and log entry hash containing at least:
     1003# user_id, group_id, log entry
     1004# and optionally one or more of:
     1005# username/email, user full name, domain_id, rdns_id
    10031006##fixme:  convert to trailing hash for user info
    10041007# User info must contain a (user ID OR username)+fullname
    10051008sub _log {
    10061009  my $dbh = shift;
    1007   my ($domain_id,$user_id,$group_id,$username,$name,$entry) = @_;
     1010
     1011  my %args = @_;
     1012
     1013  $args{rdns_id} = 0 if !$args{rdns_id};
     1014  $args{domain_id} = 0 if !$args{domain_id};
    10081015
    10091016##fixme:  need better way(s?) to snag userinfo for log entries.  don't want to have
    10101017# to pass around yet *another* constant (already passing $dbh, shouldn't need to)
    10111018  my $fullname;
    1012   if (!$user_id) {
    1013     ($user_id, $fullname) = $dbh->selectrow_array("SELECT user_id, firstname || ' ' || lastname FROM users".
    1014         " WHERE username=?", undef, ($username));
    1015   } elsif (!$username) {
    1016     ($username, $fullname) = $dbh->selectrow_array("SELECT username, firstname || ' ' || lastname FROM users".
    1017         " WHERE user_id=?", undef, ($user_id));
     1019  if (!$args{user_id}) {
     1020    ($args{user_id}, $fullname) = $dbh->selectrow_array("SELECT user_id, firstname || ' ' || lastname FROM users".
     1021        " WHERE username=?", undef, ($args{username}));
     1022  } elsif (!$args{username}) {
     1023    ($args{username}, $fullname) = $dbh->selectrow_array("SELECT username, firstname || ' ' || lastname FROM users".
     1024        " WHERE user_id=?", undef, ($args{user_id}));
    10181025  } else {
    10191026    ($fullname) = $dbh->selectrow_array("SELECT firstname || ' ' || lastname FROM users".
    1020         " WHERE user_id=?", undef, ($user_id));
    1021   }
    1022 
    1023   $name = $fullname if !$name;
     1027        " WHERE user_id=?", undef, ($args{user_id}));
     1028  }
     1029
     1030  $args{name} = $fullname if !$args{name};
    10241031
    10251032##fixme:  farm out the actual logging to different subs for file, syslog, internal, etc based on config
    1026   $dbh->do("INSERT INTO log (domain_id,user_id,group_id,email,name,entry) VALUES (?,?,?,?,?,?)", undef,
    1027         ($domain_id,$user_id,$group_id,$username,$name,$entry));
    1028 #            123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
    1029 #                     1         2         3         4         5         6         7
     1033  $dbh->do("INSERT INTO log (domain_id,rdns_id,user_id,group_id,email,name,entry) VALUES (?,?,?,?,?,?,?)",
     1034        undef,
     1035        ($args{domain_id},$args{rdns_id},$args{user_id},$args{group_id},$args{username},$args{name},$args{entry}));
     1036
    10301037} # end _log
    10311038
     
    10851092    ($dom_id) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE domain=?", undef, ($domain));
    10861093
    1087     _log($dbh, $dom_id, $userinfo{id}, $group, $userinfo{name}, $userinfo{fullname},
     1094    _log($dbh, (domain => $dom_id, user_id => $userinfo{id}, group_id => $group, username => $userinfo{name},
     1095                name => $userinfo{fullname}),
    10881096        "Added ".($state ? 'active' : 'inactive')." domain $domain");
    10891097
     
    11001108        my @tmp1 = split /:/, $host;
    11011109        my @tmp2 = split /:/, $val;
    1102         _log($dbh, $dom_id, $userinfo{id}, $group, $userinfo{name}, $userinfo{fullname},
     1110        _log($dbh, (domain => $dom_id, user_id => $userinfo{id}, group_id => $group,
     1111                        username => $userinfo{name}, name => $userinfo{fullname}),
    11031112                "[new $domain] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ".
    11041113                "[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl");
     
    11071116        $logentry .= " [distance $dist]" if $typemap{$type} eq 'MX';
    11081117        $logentry .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$type} eq 'SRV';
    1109         _log($dbh, $dom_id, $userinfo{id}, $group, $userinfo{name}, $userinfo{fullname},
     1118        _log($dbh, (domain => $dom_id, user_id => $userinfo{id}, group_id => $group,
     1119                        username => $userinfo{name}, name => $userinfo{fullname}),
    11101120                $logentry." $val', TTL $ttl");
    11111121      }
Note: See TracChangeset for help on using the changeset viewer.