<%doc>
# 
# $Id: events.html,v 1.12 2002/02/17 21:52:04 fpmip Exp $
#
# events is basic dump of events

# Authors : Alexandre Dulaunoy
#	    Tycho Fruru

# Copyright (C) 2002 Tycho Fruru <tycho@fruru.com>
# Copyright (C) 2001 Alexandre Dulaunoy <alex@thinkingsecure.com>
# Copyright (C) 2001 Conostix S.A. Luxembourg - Alexandre Dulaunoy <alex@conostix.com>

# 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 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# 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.
#
</%doc>
<%args>
$session

$web_agent_id => undef
$time => undef
$web_like => undef
$start => undef
$max => undef
$event_type => undef
$order => undef
$orderdirection => undef

</%args>

<%perl>
use URI::Escape;

if (defined($web_agent_id)) {
	$session->{web_agent_id}=$web_agent_id;
}

if (defined($time)) {
	$session->{time}=$time;
}

if (defined($web_like)) {
    if ($web_like ne "") {
    	my $cleaned_web_like = $web_like;
	$cleaned_web_like =~ s/\\/\\\\/g;
    	$cleaned_web_like =~ s/\'/\\\'/g;
	$session->{web_like}="%".$cleaned_web_like."%";
    } else {
        $session->{web_like}="";
    }
}

if (defined($start)) {
	$session->{start}=$start;
}

if (defined($max)) {
	$session->{max}=$max;
}

if (defined($event_type)) {
	$session->{event_type}=$event_type;
}

if (defined($order)) {
	$session->{order}=$order;
}

if (defined($orderdirection)) {
	$session->{orderdirection}=$orderdirection;
}

my $query = "select \"event_id\",\"agent_id\",\"entry_type\",\"entry_subtype\",\"time\",\"logfile_id\",\"message\" from events,table_names where events.table_id = table_names.table_id ";

if (defined($session->{web_like}) && $session->{web_like} ne "") {
	$query.="and lower(\"message\") like lower('$session->{web_like}') ";
}

if (defined($session->{web_agent_id}) && $session->{web_agent_id} ne "") {
	$query.="and \"agent_id\" in (".$session->{web_agent_id}.") ";
}

if (defined($session->{time}) && $session->{time} != 0) {
	$query.="and \"time\" > ((now()::abstime::int - $session->{time})::abstime::timestamp) ";
}

if (defined($session->{order}) && $session->{order} ne "") {
	$query.="order by \"$session->{order}\" ";
	if ($session->{orderdirection} eq "desc") {
		$query.="desc ";
	}
}

if (defined($session->{max}) && $session->{max} != 0) {
	$query.="limit $session->{max} ";
}

if (defined($session->{start}) && $session->{start} != 0) {
	$query.="offset $session->{start} ";
}

my @results = $m->comp('../internal/sql-query.ipfc',query=>$query);
</%perl>

<%perl>
$session->{lastaction} = "Executed SQL query : $query";
my $return = $m->comp('../internal/head-page.html',title=>'Events screen',session=>$session); </%perl>

<body>
<hr noshade>
<table width=100%> 
  <tr bgcolor=#BBBBBB>
    <td> <b>Event ID</b> </td>
    <td> <b>Agent ID</b> </td>
    <td> <b>Event Type</b> </td>
    <td> <b>Event Subtype</b> </td>
    <td> <b>Time</b> </td>
    <td> <b>Logfile ID</b> </td>
    <td> <b>Message</b> </td> 
    <td> <b>Action</b> </td>
  </tr>
% foreach my $current_line (@results) {
% $current_line->[6] =~ s/\&/&and;/g ;
% $current_line->[6] =~ s/\</&lt;/g ;
% $current_line->[6] =~ s/\>/&gt;/g ;
% use MIME::Base64;
% my $subject = "IPFC : Event id ".$current_line->[0]; 
% my $descriptionencoded = encode_base64($current_line->[6]);
  <tr>
    <td> <% $current_line->[0] %> </td>
    <td> <% $current_line->[1] %> </td>
    <td> <% $current_line->[2] %> </td>
    <td> <% $current_line->[3] %> </td>
    <td> <% $current_line->[4] %> </td>
    <td> <% $current_line->[5] %> </td>
    <td> <% $current_line->[6] %> </td> 
    <td> <form action="create-ticket.html" method="post"> 
    <input type="hidden" name="encoded" value="base64"> 
    <input type="hidden" name="description" value="<% $descriptionencoded %>"> 
    <input type="hidden" name="subject" value="<% $subject %>">
    <input type="submit" name="generate ticket" value="generate ticket">
    </form></td> 
  </tr>
% }
</table>
</body>

<%perl>
my $endbody = $m->comp('../internal/end-page.html');
</%perl>

