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 : objects.php
11 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
12 ** VERSION NUMBER : $Revision: 1.11 $
14 ** DESCRIPTION : Objects Administration page.
15 ** Input parameters: action (POST) : empty, 'Create'
16 ** objname (POST) : name of the object to create or remove
21 ***************************************************************************
22 ** ADMINISTRATIVE INFORMATION *
23 ********************************
24 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
25 ** CREATION DATE : Dec 04, 2002
26 ** LAST UPDATE : Aug 04, 2003
28 **************************************************************************/
30 /*****************************
32 Revision 1.11 2007-11-21 14:38:06 arjen
33 The buttonbar at the top of each page is now a fixed 'div' element
34 instead of a framed page.
35 Contributed by Edwin Nadorp.
37 Revision 1.10 2005/06/04 07:24:38 arjen
40 Revision 1.9 2003/09/01 06:55:00 arjen
41 Provides an interface to edit the list of
42 services and users for an object.
44 Revision 1.8 2003/08/14 10:35:07 arjen
45 Added editing of detailed object information.
47 Revision 1.7 2003/07/15 11:02:25 arjen
48 Use the new object_statistics table.
50 Revision 1.6 2003/02/21 08:46:58 arjen
51 Improved the table layout.
53 Revision 1.5 2003/02/13 09:01:29 arjen
54 All web interface pages use the page class.
56 Revision 1.4 2003/02/13 08:48:23 arjen
57 Added log, notification and parameter counters to the 'object' table.
58 Counting these things at the time a user interface needs them is
59 too slow. Other programs, like gcm_daemon en gcm_input should prepare
60 these counters for quick retrieval.
62 Revision 1.3 2003/02/10 15:42:24 arjen
63 Show the total number of Log entries, parameters and notifications
65 Revision 1.2 2003/02/05 09:48:14 arjen
66 Added display and handling of notifications
68 ******************************/
70 // RCSID = "$Id: objects.php,v 1.11 2007-11-21 14:38:06 arjen Exp $";
72 ini_set('include_path', '.:./classes:../phpclasses');
74 require_once('page.class.php');
76 function clientscripts()
80 <script type='text/ecmascript'>
82 function CheckCreate(f)
84 if (f.objectname.value == "")
86 alert("You must supply a name");
92 function CheckRemove(f)
94 var message = "Are you sure you want to remove object ";
95 message += f.objectname.value;
98 return confirm(message);
106 class object_page extends page
109 var $nr_parameters, $removed_parameters;
110 var $nr_notifications, $closed_notifications;
113 function GatherStatistics($objectid)
115 // Gather statistics on parameters
117 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
118 . $objectid . "' AS BIGINT) AND statname='parameters'");
119 $stat = pg_fetch_object($r, 0);
120 $this->nr_parameters = $stat->statvalue;
122 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
123 . $objectid . "' AS BIGINT) AND statname='removed_parameters'");
124 $stat = pg_fetch_object($r, 0);
125 $this->removed_parameters = $stat->statvalue;
127 // Gather statistics on notifications
129 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
130 . $objectid . "' AS BIGINT) AND statname='notifications'");
131 $stat = pg_fetch_object($r, 0);
132 $this->nr_notifications = $stat->statvalue;
134 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
135 . $objectid . "' AS BIGINT) AND statname='closed_notifications'");
136 $stat = pg_fetch_object($r, 0);
137 $this->closed_notifications = $stat->statvalue;
139 // Gather statistics on log entries
141 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
142 . $objectid . "' AS BIGINT) AND statname='logs'");
143 $stat = pg_fetch_object($r, 0);
144 $this->nr_logs = $stat->statvalue;
152 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
154 pg_exec($this->database, "INSERT INTO object (objectname, log_count, parameter_count, notification_count)
155 VALUES ('" . $_POST['objectname'] . "', '0', '0', '0')");
158 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
160 pg_exec($this->database, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
163 if (isset($_GET['oid']))
165 echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = \"<h1>Detailed information for object " . $_GET['oid'] . "<\/h1>\"</script><br>\n";
167 if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
169 $qry = "UPDATE object SET objectname='" . $_POST['oname'] . "'";
170 $qry .= ", objectcode='" . $_POST['ocode'] . "'";
171 $qry .= ", object_description='" . $_POST['odescription'] . "'";
172 $qry .= ", object_owner='" . $_POST['oowner'] . "'";
173 $qry .= ", physical_location='" . $_POST['olocation'] . "'";
174 $qry .= ", remark='" . $_POST['oremark'] . "'";
175 $qry .= ", timezone='" . $_POST['otimezone'] . "'";
176 $qry .= " WHERE objectid=" . $_GET['oid'];
178 pg_exec($this->database, $qry);
180 else if (isset($_POST['action']) && $_POST['action'] == 'Modify Service')
182 $obj_srv_res = pg_exec($this->database, "SELECT * from object_service WHERE objectid='" . $_GET['oid']
183 . "' AND servicecode='" . $_POST['servcode'] . "'");
185 if (pg_numrows($obj_srv_res) == 0)
187 // Add a new service for this object
188 if (isset($_POST['servused']))
190 $qry = "INSERT INTO object_service (objectid, servicecode, expected_interval) ";
191 $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['servcode'] . "', '";
192 $qry .= $_POST['expinterval'] . "')";
194 pg_exec($this->database, $qry);
199 // Modify or remove the service for this object
200 if (isset($_POST['servused']))
202 // Service is still used; update some values.
203 $qry = "UPDATE object_service SET expected_interval='" . $_POST['expinterval'];
204 $qry .= "' WHERE objectid='" . $_GET['oid'];
205 $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
206 pg_exec($this->database, $qry);
210 // Checkbox was turned off, remove the service
212 $qry = "DELETE FROM object_service WHERE objectid='" . $_GET['oid'];
213 $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
214 pg_exec($this->database, $qry);
218 else if (isset($_POST['action']) && $_POST['action'] == 'Modify User')
220 $obj_srv_res = pg_exec($this->database, "SELECT * from object_user WHERE objectid='" . $_GET['oid']
221 . "' AND username='" . $_POST['username'] . "'");
223 if (pg_numrows($obj_srv_res) == 0)
225 // Add a new user for this object
226 if (isset($_POST['userused']))
228 $qry = "INSERT INTO object_user (objectid, username, security_level) ";
229 $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['username'] . "', '";
230 $qry .= $_POST['seclevel'] . "')";
232 pg_exec($this->database, $qry);
237 // Modify or remove the user for this object
238 if (isset($_POST['userused']))
240 // Service is still used; update some values.
241 $qry = "UPDATE object_user SET security_level='" . $_POST['seclevel'];
242 $qry .= "' WHERE objectid='" . $_GET['oid'];
243 $qry .= "' AND username='" . $_POST['username'] . "'";
244 pg_exec($this->database, $qry);
248 // Checkbox was turned off, remove the user
250 $qry = "DELETE FROM object_user WHERE objectid='" . $_GET['oid'];
251 $qry .= "' AND username='" . $_POST['username'] . "'";
252 pg_exec($this->database, $qry);
257 $res = pg_exec($this->database, "SELECT * FROM object
258 WHERE objectid='" . $_GET['oid'] . "'");
259 $obj = pg_fetch_object($res, 0);
261 echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
264 echo "<tr><td>Name</td><td><input name='oname' type='text' value='";
265 echo $obj->objectname . "'></td></tr>";
266 echo "<tr><td>Identification code</td><td><input name='ocode' type='text' value='";
267 echo $obj->objectcode . "'></td></tr>";
268 echo "<tr><td>Description</td><td><textarea name='odescription' rows='3' cols='30'>";
269 echo $obj->object_description . "</textarea></td></tr>";
270 echo "<tr><td>Owner</td><td><textarea name='oowner' rows='3' cols='30'>";
271 echo $obj->object_owner . "</textarea></td></tr>";
272 echo "<tr><td>Physical location</td><td><textarea name='olocation' rows='3' cols='30'>";
273 echo $obj->physical_location . "</textarea></td></tr>";
274 echo "<tr><td>Remarks</td><td><textarea name='oremark' rows='3' cols='30'>";
275 echo $obj->remark . "</textarea></td></tr>";
276 echo "<tr><td>Timezone</td><td><input name='otimezone' type='text' value='";
277 echo $obj->timezone . "'></td></tr>";
280 echo "<input type='submit' name='action' value='Save Changes'>";
283 echo "<h1>Services on " . $obj->objectname . "</h1><hr>\n";
286 echo "<tr><th>Service name</th><th>Last entry</th><th>Expected interval</th></tr>";
287 $srv_res = pg_exec($this->database, "SELECT servicecode, servicename FROM service
288 ORDER BY servicecode");
289 for ($srv_row = 0; $srv_row < pg_numrows($srv_res); $srv_row++)
291 $srv = pg_fetch_object($srv_res, $srv_row);
292 $srv_obj_res = pg_exec($this->database, "SELECT * FROM object_service WHERE objectid='"
293 . $obj->objectid . "' AND servicecode='" . $srv->servicecode . "'");
296 echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
297 echo "<input type='hidden' name='servcode' value='" . $srv->servicecode . "'>";
299 if (pg_numrows($srv_obj_res) == 0)
301 echo "<td><input name='servused' type='checkbox'> " . $srv->servicename . "</td>";
302 echo "<td> </td>";
303 echo "<td><input name='expinterval' type='text' value='0'></td>";
304 echo "<td><input type='submit' name='action' value='Modify Service'></td>";
308 $obj_srv = pg_fetch_object($srv_obj_res, 0);
309 echo "<td><input name='servused' type='checkbox' checked='true'> " . $srv->servicename . "</td>";
310 echo "<td>" . $obj_srv->last_entry . "</td>";
311 echo "<td><input name='expinterval' type='text' value='" . $obj_srv->expected_interval . "'></td>";
312 echo "<td><input type='submit' name='action' value='Modify Service'></td>";
318 echo "<h1>Users of " . $obj->objectname . "</h1><hr>\n";
321 echo "<tr><th>User name</th><th>Security level</th><th> </th></tr>";
323 $usr_res = pg_exec($this->database, "SELECT username, security_level FROM usr ORDER BY username");
324 for ($usr_row = 0; $usr_row < pg_numrows($usr_res); $usr_row++)
326 $usr = pg_fetch_object($usr_res, $usr_row);
327 $usr_obj_res = pg_exec($this->database, "SELECT * FROM object_user WHERE objectid='"
328 . $obj->objectid . "' AND username='" . $usr->username . "'");
331 echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
332 echo "<input type='hidden' name='username' value='" . $usr->username . "'>";
334 if (pg_numrows($usr_obj_res) == 0)
336 echo "<td><input name='userused' type='checkbox'> " . $usr->username . "</td>";
337 echo "<td><input name='seclevel' type='text' value='" . $usr->security_level . "'></td>";
338 echo "<td><input type='submit' name='action' value='Modify User'></td>";
342 $usr_obj = pg_fetch_object($usr_obj_res, 0);
343 echo "<td><input name='userused' type='checkbox' checked='on'> " . $usr->username . "</td>";
344 echo "<td><input name='seclevel' type='text' value='" . $usr_obj->security_level . "'></td>";
345 echo "<td><input type='submit' name='action' value='Modify User'></td>";
353 echo "<script type='text/ecmascript'>
354 document.getElementById('menu_title').innerHTML = \"<h1>Objects Administration<\/h1>\"
359 $res = pg_exec($this->database, "SELECT * FROM object ORDER BY objectname");
363 <tr><th>Object</th><th>Description</th><th>Log entries</th>
364 <th>Parameters</th><th>Notifications</th><th>Abuses</th></tr>
369 //The counters are set to zero
371 $count_notifications = 0;
372 $closed_notifications = 0;
373 $count_parameters = 0;
374 $removed_parameters = 0;
376 while ($obj < pg_numrows($res))
378 $u = pg_fetch_object($res, $obj);
380 $this->GatherStatistics($u->objectid);
382 $count_parameters += $this->nr_parameters;
383 $removed_parameters += $this->removed_parameters;
384 $count_logs = $count_logs + $this->nr_logs;
386 $count_notifications += $this->nr_notifications;
387 $closed_notifications += $this->closed_notifications;
389 <tr><td><center><a href='objects.php?oid=<?php echo $u->objectid?>'><img src='server.png' alt='server'></a><br>
390 <b><?php echo $u->objectname ?></b></center>
392 <?php echo nl2br($u->object_description) ?>
393 </td><td class='number'>
394 <?php if ( $this->nr_logs > 0 )
396 echo "<a href='log.php?oid=$u->objectid'> $this->nr_logs </a>";
403 </td><td class='number'>
404 <?php echo "<a href='parameter.php?oid=$u->objectid'>" . $this->nr_parameters
405 . " (" . $this->removed_parameters . " removed)</a>" ?>
406 </td><td class='number'>
407 <?php if( $this->nr_notifications == $this->closed_notifications )
409 echo $this->nr_notifications . " (" . $this->closed_notifications . " closed)";
413 echo "<a href='notification.php?oid=$u->objectid'>" . $this->nr_notifications
414 . " (" . $this->closed_notifications . " closed)</a>";
417 </td><td class='number'>
418 <?php echo "<a href='abuse.php?oid=$u->objectid'>" . "Abuse list"
421 <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
422 <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
423 <input type='submit' name='action' value='Remove'>
431 echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
432 echo "<td> </td>";
433 echo "<td class='number'>$count_logs</td>";
434 echo "<td class='number'>$count_parameters ($removed_parameters removed)</td>";
435 echo "<td class='number'>$count_notifications ($closed_notifications closed)</td>";
436 echo "<td> </td>";
442 <h2>Create new object:</h2>
444 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
445 Object's name (FQDN): <input name='objectname' type='text'>
447 <input type='submit' name='action' value='Create'>
456 $obj_page = new object_page("Gnucomo Objects Administration");
458 $obj_page->Showpage();