#!/usr/bin/perl #------------------------------------------------------------------------------ # mwForum - Web-based discussion forum # Copyright (c) 1999-2015 Markus Wichitill # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. #------------------------------------------------------------------------------ use strict; use warnings; no warnings qw(uninitialized redefine); # Imports use TyfMain; #------------------------------------------------------------------------------ # Init my ( $m, $cfg, $lng, $user, $userId ) = TyfMain->new( $_[0] ); # Check if user is admin $user->{admin} or $m->error('errNoAccess'); # Print header $m->printHeader(); # Get CGI parameters my $mode = $m->paramStrId('mode') || ""; my $page = $m->paramInt('pg') || 1; my $search = $m->paramStr('search') || ""; my $field = $m->paramStrId('field') || 'action'; my $sort = $m->paramStrId('sort') || 'id'; my $order = $m->paramStrId('order') || 'desc'; # Define values and names for selectable fields my %fields = ( level => "Level", entity => "Entity", action => "Action", userId => "User ID", boardId => "Board ID", topicId => "Topic ID", postId => "Post ID", extraId => "Other ID", ip => "IP Address", string => "String", ); # Enforce valid options $field = 'action' if !$fields{$field}; $sort = 'id' if $sort !~ /^(?:id|field)\z/; $order = 'desc' if $order !~ /^(?:asc|desc)\z/; # Preserve parameters in links my @params = ( mode => $mode, search => $search, field => $field, sort => $sort, order => $order ); # Search for my $fieldCast = $m->{pgsql} ? "CAST($field AS VARCHAR)" : $field; my $searchEsc = $m->escHtml($search); my $searchLike = $m->dbEscLike($searchEsc); my $searchStr = $search ? "WHERE $fieldCast = :search" : ""; # Sort list by my $orderStr = ""; if ( $sort eq 'field' ) { $orderStr = "$field $order, id DESC" } else { $orderStr = "id $order" } # Get ids of log lines my $lines = []; if ( $mode eq 'searches' ) { $lines = $m->fetchAllArray( " SELECT id FROM log WHERE entity = 'forum' AND action = 'search' AND string <> '' ORDER BY $orderStr LIMIT 2000" ); } else { $lines = $m->fetchAllArray( " SELECT id FROM log $searchStr ORDER BY $orderStr LIMIT 2000", { search => $search } ); } # Print page bar my $linesPP = 100; my $pageNum = int( @$lines / $linesPP ) + ( @$lines % $linesPP != 0 ); my @pageLinks = $pageNum < 2 ? () : $m->pageLinks( 'log_admin', \@params, $page, $pageNum ); my @navLinks = ( { url => $m->url('forum_show'), txt => 'comUp', ico => 'up' } ); my @adminLinks = (); push @adminLinks, { url => $m->url( 'log_admin', mode => 'searches' ), txt => "Searches", ico => 'search' }; push @adminLinks, { url => $m->url('log_delete'), txt => "Delete", ico => 'delete' }; $m->printPageBar( mainTitle => "Log", navLinks => \@navLinks, pageLinks => \@pageLinks, adminLinks => \@adminLinks ); # Get lines on page my @pageLines = @$lines[ ( $page - 1 ) * $linesPP .. $m->min( $page * $linesPP, scalar @$lines ) - 1 ]; my @pageLineIds = map( $_->[0], @pageLines ); $lines = $m->fetchAllArray( " SELECT id, level, entity, action, userId, boardId, topicId, postId, extraId, logTime, ip, string FROM log WHERE id IN (:pageLineIds) ORDER BY $orderStr", { pageLineIds => \@pageLineIds } ); # Determine checkbox, radiobutton and listbox states my %state = ( $sort => 'selected', $order => 'selected', "field$field" => 'selected' ); # Print log list form print "
\n\n"; # Print log list header print "| ID | \n", "Time | \n", "Lvl | \n", "Entity | \n", "Action | \n", "IP Address | \n", "User | \n", "Board | \n", "Topic | \n", "Post | \n", "Other | \n", "String | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|
| $id | \n", "$logTime | \n", "$level | \n", "$entity | \n", "$action | \n", "$ip | \n", "$logUserId | \n", "$boardId | \n", "$topicId | \n", "$postId | \n", "$extraId | \n", "$string | \n", "