- Timestamp:
- 03/02/12 16:08:45 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r255 r256 1000 1000 # Log an action 1001 1001 # 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 1003 1006 ##fixme: convert to trailing hash for user info 1004 1007 # User info must contain a (user ID OR username)+fullname 1005 1008 sub _log { 1006 1009 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}; 1008 1015 1009 1016 ##fixme: need better way(s?) to snag userinfo for log entries. don't want to have 1010 1017 # to pass around yet *another* constant (already passing $dbh, shouldn't need to) 1011 1018 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})); 1018 1025 } else { 1019 1026 ($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}; 1024 1031 1025 1032 ##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 1030 1037 } # end _log 1031 1038 … … 1085 1092 ($dom_id) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE domain=?", undef, ($domain)); 1086 1093 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}), 1088 1096 "Added ".($state ? 'active' : 'inactive')." domain $domain"); 1089 1097 … … 1100 1108 my @tmp1 = split /:/, $host; 1101 1109 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}), 1103 1112 "[new $domain] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ". 1104 1113 "[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl"); … … 1107 1116 $logentry .= " [distance $dist]" if $typemap{$type} eq 'MX'; 1108 1117 $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}), 1110 1120 $logentry." $val', TTL $ttl"); 1111 1121 }
Note:
See TracChangeset
for help on using the changeset viewer.