f10cbc7f0666b28bb91cc23b7e6f9520173dd0bc
[gnucomo.git] / src / web / log.php
1 <?php
2
3 /**************************************************************************
4 **  (c) Copyright 2003, Andromeda Technology & Automation
5 ** This is free software; you can redistribute it and/or modify it under the
6 ** terms of the GNU General Public License, see the file COPYING.
7 ***************************************************************************
8 ** MODULE INFORMATION *
9 ***********************
10 **      FILE NAME      : log.php
11 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
12 **      VERSION NUMBER : $Revision: 1.6 $
13 **
14 **  DESCRIPTION      : Logs page
15 **
16 **  EXPORTED OBJECTS : 
17 **  LOCAL    OBJECTS : 
18 **  MODULES  USED    :
19 ***************************************************************************
20 **  ADMINISTRATIVE INFORMATION *
21 ********************************
22 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
23 **      CREATION DATE   : Dec 04, 2002
24 **      LAST UPDATE     : Jul 15, 2003
25 **      MODIFICATIONS   : 
26 **************************************************************************/
27
28 /*****************************
29    $Log: log.php,v $
30    Revision 1.6  2005-06-04 07:18:26  arjen
31    Added a view for the log analysis with a link from the log page.
32
33    Revision 1.5  2003/08/11 17:59:17  arjen
34    BUGFIX: Convert special characters for HTML (<, >, and &) into
35    their entities.
36
37    Revision 1.4  2003/07/15 11:03:39  arjen
38    Show the log one day at a time.
39
40    Revision 1.3  2003/02/21 08:50:12  arjen
41    Database optimizations.
42
43    Revision 1.2  2003/02/13 09:01:29  arjen
44    All web interface pages use the page class.
45
46    Revision 1.2  2003/02/05 09:48:14  arjen
47    Added display and handling of notifications
48
49 ******************************/
50
51 // RCSID = "$Id: log.php,v 1.6 2005-06-04 07:18:26 arjen Exp $";
52
53 ini_set('include_path', '.:./classes:../phpclasses');
54
55 require_once('page.class.php');
56
57
58 class log_page extends page
59 {
60
61    function Body()
62    {
63       if (!empty($_GET['oid']))
64       {
65          $res = pg_exec($this->database, "SELECT objectname FROM object
66                                WHERE objectid=CAST('" . $_GET['oid']. "' AS BIGINT)");
67          $obj = pg_fetch_object($res, 0);
68          echo "<h1>Log for " . $obj->objectname . "</h1><hr>";
69
70          //  Determine which day to display.
71          //  This is either from a previous button though a _POST[] variable
72          //  or the last day in the log table by default.
73
74          if (empty($_POST['logday']))
75          {
76             $res = pg_exec($this->database, "SELECT date_trunc('day',object_timestamp) FROM log
77                                   WHERE objectid='". $_GET['oid'] ."'
78                                   ORDER BY object_timestamp DESC LIMIT 1");
79
80             $last_time = pg_fetch_object($res, 0);
81             $logday = strtotime($last_time->date_trunc);
82          }
83          else
84          {
85             $logday = $_POST['logday'];
86          }
87
88          //  Make buttons to request the previous and the next day of logs.
89
90          echo "<form method='POST'>";
91          echo "<input type='submit' value='<<'>";
92          echo "<input type='hidden' name='logday' value='" . ($logday - 24 * 60 * 60) . "'>";
93          echo "</form>";
94
95          echo "<h3>" . date('F d, Y', $logday) ."</h3>";
96
97          echo "<form method='POST'>";
98          echo "<input type='submit' value='>>'>";
99          echo "<input type='hidden' name='logday' value='" . ($logday + 24 * 60 * 60) . "'>";
100          echo "</form>";
101
102          // Show the log for one day only.
103
104          $res = pg_exec($this->database, "SELECT logid, object_timestamp, servicecode, rawdata FROM log "
105                         ."WHERE objectid = CAST('" . $_GET['oid'] . "' AS BIGINT)
106                          AND date_trunc('day', object_timestamp)='" . date('Y-m-d', $logday) . "'
107                          ORDER BY object_timestamp, logid");
108
109          echo "<table>\n";
110          echo "<tr><th>Date</th><th>Service</th><th>Log</th></tr>\n";
111          $row = 0;
112          while ($row < pg_numrows($res))
113          {
114             $log = pg_fetch_object($res, $row);
115             ?>
116             <tr><td class='time'>
117                <a target='_new' href='logadv.php?logid=<?php echo $log->logid?>'>
118                  <?php echo $log->object_timestamp?>
119                </a>
120             </td><td>
121                <?php echo $log->servicecode?>
122             </td><td>
123                <?php echo htmlentities($log->rawdata)?>
124             </td></tr>
125             <?php
126             $row++;
127          }
128          echo "</table>";
129       }
130    }
131 }
132
133 $page = new log_page("Gnucomo system logs");
134
135 $page->Showpage();
136
137 ?>