Changeset 323 for trunk/DNSDB.pm
- Timestamp:
- 04/29/12 18:20:17 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r321 r323 46 46 &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount 47 47 &addRec &updateRec &delRec 48 &getLogCount &getLogEntries 48 49 &getTypelist 49 50 &parentID … … 69 70 &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount 70 71 &addRec &updateRec &delRec 72 &getLogCount &getLogEntries 71 73 &getTypelist 72 74 &parentID … … 3068 3070 return ('OK',$logdata{entry}); 3069 3071 } # end delRec() 3072 3073 3074 ## DNSDB::getLogCount() 3075 # Get a count of log entries 3076 # Takes a database handle and a hash containing at least: 3077 # - Entity ID and entity type as the primary log "slice" 3078 sub getLogCount { 3079 my $dbh = shift; 3080 3081 my %args = @_; 3082 3083 my @filterargs; 3084 ##fixme: which fields do we want to filter on? 3085 # push @filterargs, 3086 3087 $errstr = 'Missing primary parent ID and/or type'; 3088 # fail early if we don't have a "prime" ID to look for log entries for 3089 return if !$args{id}; 3090 3091 # or if the prime id type is missing or invalid 3092 return if !$args{logtype}; 3093 $args{logtype} = 'revzone' if $args{logtype} eq 'rdns'; # hack pthui 3094 $args{logtype} = 'domain' if $args{logtype} eq 'dom'; # hack pthui 3095 return if !grep /^$args{logtype}$/, ('group', 'domain', 'revzone', 'user'); 3096 3097 $args{logtype} = 'revzone' if $args{logtype} eq 'rdns'; # hack pthui 3098 3099 my $sql = "SELECT count(*) FROM log ". 3100 "WHERE $id_col{$args{logtype}}=?". 3101 ($args{filter} ? " AND entry ~* ?" : ''); 3102 my ($count) = $dbh->selectrow_array($sql, undef, ($args{id}, @filterargs) ); 3103 $errstr = $dbh->errstr if !$count; 3104 return $count; 3105 } # end getLogCount() 3106 3107 3108 ## DNSDB::getLogEntries() 3109 # Get a list of log entries 3110 # Takes arguments as with getLogCount() above, plus optional: 3111 # - sort field 3112 # - sort order 3113 # - offset for pagination 3114 sub getLogEntries { 3115 my $dbh = shift; 3116 3117 my %args = @_; 3118 3119 my @filterargs; 3120 3121 # fail early if we don't have a "prime" ID to look for log entries for 3122 return if !$args{id}; 3123 3124 # or if the prime id type is missing or invalid 3125 return if !$args{logtype}; 3126 $args{logtype} = 'revzone' if $args{logtype} eq 'rdns'; # hack pthui 3127 $args{logtype} = 'domain' if $args{logtype} eq 'dom'; # hack pthui 3128 return if !grep /^$args{logtype}$/, ('group', 'domain', 'revzone', 'user'); 3129 3130 # Sorting defaults 3131 $args{sortby} = 'stamp' if !$args{sortby}; 3132 $args{sortorder} = 'DESC' if !$args{sortorder}; 3133 $args{offset} = 0 if !$args{offset}; 3134 3135 my %sortmap = (fname => 'name', username => 'email', entry => 'entry', stamp => 'stamp,log_id'); 3136 $args{sortby} = $sortmap{$args{sortby}}; 3137 3138 my $sql = "SELECT user_id AS userid, email AS useremail, name AS userfname, entry AS logentry, ". 3139 "date_trunc('second',stamp) AS logtime ". 3140 "FROM log ". 3141 "WHERE $id_col{$args{logtype}}=?". 3142 ($args{filter} ? " AND entry ~* ?" : ''). 3143 " ORDER BY $args{sortby} $args{sortorder}". 3144 ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage}); 3145 my $loglist = $dbh->selectall_arrayref($sql, { Slice => {} }, ($args{id}, @filterargs) ); 3146 $errstr = $dbh->errstr if !$loglist; 3147 return $loglist; 3148 } # end getLogEntries() 3070 3149 3071 3150
Note:
See TracChangeset
for help on using the changeset viewer.