BUGFIX: Convert special characters for HTML (<, >, and &) into
[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.5 $
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.5  2003-08-11 17:59:17  arjen
31    BUGFIX: Convert special characters for HTML (<, >, and &) into
32    their entities.
33
34    Revision 1.4  2003/07/15 11:03:39  arjen
35    Show the log one day at a time.
36
37    Revision 1.3  2003/02/21 08:50:12  arjen
38    Database optimizations.
39
40    Revision 1.2  2003/02/13 09:01:29  arjen
41    All web interface pages use the page class.
42
43    Revision 1.2  2003/02/05 09:48:14  arjen
44    Added display and handling of notifications
45
46 ******************************/
47
48 // RCSID = "$Id: log.php,v 1.5 2003-08-11 17:59:17 arjen Exp $";
49
50 ini_set('include_path', '.:./classes:../phpclasses');
51
52 require_once('page.class.php');
53
54
55 class log_page extends page
56 {
57
58    function Body()
59    {
60       if (!empty($_GET['oid']))
61       {
62          $res = pg_exec($this->database, "SELECT objectname FROM object
63                                WHERE objectid=CAST('" . $_GET['oid']. "' AS BIGINT)");
64          $obj = pg_fetch_object($res, 0);
65          echo "<h1>Log for " . $obj->objectname . "</h1><hr>";
66
67          //  Determine which day to display.
68          //  This is either from a previous button though a _POST[] variable
69          //  or the last day in the log table by default.
70
71          if (empty($_POST['logday']))
72          {
73             $res = pg_exec($this->database, "SELECT date_trunc('day',object_timestamp) FROM log
74                                   WHERE objectid='". $_GET['oid'] ."'
75                                   ORDER BY object_timestamp DESC LIMIT 1");
76
77             $last_time = pg_fetch_object($res, 0);
78             $logday = strtotime($last_time->date_trunc);
79          }
80          else
81          {
82             $logday = $_POST['logday'];
83          }
84
85          //  Make buttons to request the previous and the next day of logs.
86
87          echo "<form method='POST'>";
88          echo "<input type='submit' value='<<'>";
89          echo "<input type='hidden' name='logday' value='" . ($logday - 24 * 60 * 60) . "'>";
90          echo "</form>";
91
92          echo "<h3>" . date('F d, Y', $logday) ."</h3>";
93
94          echo "<form method='POST'>";
95          echo "<input type='submit' value='>>'>";
96          echo "<input type='hidden' name='logday' value='" . ($logday + 24 * 60 * 60) . "'>";
97          echo "</form>";
98
99          // Show the log for one day only.
100
101          $res = pg_exec($this->database, "SELECT object_timestamp, servicecode, rawdata FROM log "
102                         ."WHERE objectid = CAST('" . $_GET['oid'] . "' AS BIGINT)
103                          AND date_trunc('day', object_timestamp)='" . date('Y-m-d', $logday) . "'
104                          ORDER BY object_timestamp, logid");
105
106          echo "<table>\n";
107          echo "<tr><th>Date</th><th>Service</th><th>Log</th></tr>\n";
108          $row = 0;
109          while ($row < pg_numrows($res))
110          {
111             $log = pg_fetch_object($res, $row);
112             ?>
113             <tr><td class='time'>
114                <?php echo $log->object_timestamp?>
115             </td><td>
116                <?php echo $log->servicecode?>
117             </td><td>
118                <?php echo htmlentities($log->rawdata)?>
119             </td></tr>
120             <?php
121             $row++;
122          }
123          echo "</table>";
124       }
125    }
126 }
127
128 $page = new log_page("Gnucomo system logs");
129
130 $page->Showpage();
131
132 ?>