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.12 $
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 : Jul 13, 2010
28 **************************************************************************/
30 /*****************************
32 Revision 1.12 2011-03-24 09:59:21 arjen
33 When removing an object, clean up logs, parameters and notifications.
35 Revision 1.11 2007/11/21 14:38:06 arjen
36 The buttonbar at the top of each page is now a fixed 'div' element
37 instead of a framed page.
38 Contributed by Edwin Nadorp.
40 Revision 1.10 2005/06/04 07:24:38 arjen
43 Revision 1.9 2003/09/01 06:55:00 arjen
44 Provides an interface to edit the list of
45 services and users for an object.
47 Revision 1.8 2003/08/14 10:35:07 arjen
48 Added editing of detailed object information.
50 Revision 1.7 2003/07/15 11:02:25 arjen
51 Use the new object_statistics table.
53 Revision 1.6 2003/02/21 08:46:58 arjen
54 Improved the table layout.
56 Revision 1.5 2003/02/13 09:01:29 arjen
57 All web interface pages use the page class.
59 Revision 1.4 2003/02/13 08:48:23 arjen
60 Added log, notification and parameter counters to the 'object' table.
61 Counting these things at the time a user interface needs them is
62 too slow. Other programs, like gcm_daemon en gcm_input should prepare
63 these counters for quick retrieval.
65 Revision 1.3 2003/02/10 15:42:24 arjen
66 Show the total number of Log entries, parameters and notifications
68 Revision 1.2 2003/02/05 09:48:14 arjen
69 Added display and handling of notifications
71 ******************************/
73 // RCSID = "$Id: objects.php,v 1.12 2011-03-24 09:59:21 arjen Exp $";
75 ini_set('include_path', '.:./classes:../phpclasses');
77 require_once('page.class.php');
79 function clientscripts()
83 <script type='text/ecmascript'>
85 function CheckCreate(f)
87 if (f.objectname.value == "")
89 alert("You must supply a name");
95 function CheckRemove(f)
97 var message = "Are you sure you want to remove object ";
98 message += f.objectname.value;
101 return confirm(message);
109 class object_page extends page
112 var $nr_parameters, $removed_parameters;
113 var $nr_notifications, $closed_notifications;
116 function GatherStatistics($objectid)
118 // Gather statistics on parameters
120 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
121 . $objectid . "' AS BIGINT) AND statname='parameters'");
122 $stat = pg_fetch_object($r, 0);
123 $this->nr_parameters = $stat->statvalue;
125 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
126 . $objectid . "' AS BIGINT) AND statname='removed_parameters'");
127 $stat = pg_fetch_object($r, 0);
128 $this->removed_parameters = $stat->statvalue;
130 // Gather statistics on notifications
132 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
133 . $objectid . "' AS BIGINT) AND statname='notifications'");
134 $stat = pg_fetch_object($r, 0);
135 $this->nr_notifications = $stat->statvalue;
137 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
138 . $objectid . "' AS BIGINT) AND statname='closed_notifications'");
139 $stat = pg_fetch_object($r, 0);
140 $this->closed_notifications = $stat->statvalue;
142 // Gather statistics on log entries
144 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
145 . $objectid . "' AS BIGINT) AND statname='logs'");
146 $stat = pg_fetch_object($r, 0);
147 $this->nr_logs = $stat->statvalue;
155 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
157 pg_exec($this->database, "INSERT INTO object (objectname, log_count, parameter_count, notification_count)
158 VALUES ('" . $_POST['objectname'] . "', '0', '0', '0')");
161 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectid']))
163 $oid = $_POST['objectid'];
165 // Cleanup notifications for this object
167 $r = pg_exec($this->database, "SELECT notificationid FROM notification WHERE objectid='$oid'");
168 for ($i = 0; $i < pg_numrows($r); $i++)
170 $notif = pg_fetch_object($r, $i);
171 $notid = $notif->notificationid;
172 pg_exec($this->database, "DELETE FROM log_notification WHERE notificationid='$notid'");
173 pg_exec($this->database, "DELETE FROM action_user WHERE notificationid='$notid'");
174 pg_exec($this->database, "DELETE FROM parameter_notification WHERE notificationid='$notid'");
176 pg_exec($this->database, "DELETE FROM notification WHERE objectid='$oid'");
178 // Cleanup parameters for this object
180 $r = pg_exec($this->database, "SELECT paramid FROM parameter WHERE objectid='$oid'");
181 for ($i = 0; $i < pg_numrows($r); $i++)
183 $param = pg_fetch_object($r, $i);
184 $parid = $param->paramid;
185 pg_exec($this->database, "DELETE FROM history WHERE paramid='$parid'");
186 pg_exec($this->database, "DELETE FROM property WHERE paramid='$parid'");
188 pg_exec($this->database, "DELETE FROM parameter WHERE objectid='$oid'");
190 // Cleanup log and abuses for this object
192 pg_exec($this->database, "DELETE FROM log_abuse WHERE objectid='$oid'");
193 pg_exec($this->database, "DELETE FROM object_abuse WHERE objectid='$oid'");
194 pg_exec($this->database, "DELETE FROM log WHERE objectid='$oid'");
196 // Cleanup services, statistics, users and finally, the object itself.
198 pg_exec($this->database, "DELETE FROM object_service WHERE objectid='$oid'");
199 pg_exec($this->database, "DELETE FROM object_statistics WHERE objectid='$oid'");
200 pg_exec($this->database, "DELETE FROM object_user WHERE objectid='$oid'");
201 pg_exec($this->database, "DELETE FROM object WHERE objectid='$oid'");
204 if (isset($_GET['oid']))
206 echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = \"<h1>Detailed information for object " . $_GET['oid'] . "<\/h1>\"</script><br>\n";
208 if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
210 $qry = "UPDATE object SET objectname='" . $_POST['oname'] . "'";
211 $qry .= ", objectcode='" . $_POST['ocode'] . "'";
212 $qry .= ", object_description='" . $_POST['odescription'] . "'";
213 $qry .= ", object_owner='" . $_POST['oowner'] . "'";
214 $qry .= ", physical_location='" . $_POST['olocation'] . "'";
215 $qry .= ", remark='" . $_POST['oremark'] . "'";
216 $qry .= ", timezone='" . $_POST['otimezone'] . "'";
217 $qry .= " WHERE objectid=" . $_GET['oid'];
219 pg_exec($this->database, $qry);
221 else if (isset($_POST['action']) && $_POST['action'] == 'Modify Service')
223 $obj_srv_res = pg_exec($this->database, "SELECT * from object_service WHERE objectid='" . $_GET['oid']
224 . "' AND servicecode='" . $_POST['servcode'] . "'");
226 if (pg_numrows($obj_srv_res) == 0)
228 // Add a new service for this object
229 if (isset($_POST['servused']))
231 $qry = "INSERT INTO object_service (objectid, servicecode, expected_interval) ";
232 $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['servcode'] . "', '";
233 $qry .= $_POST['expinterval'] . "')";
235 pg_exec($this->database, $qry);
240 // Modify or remove the service for this object
241 if (isset($_POST['servused']))
243 // Service is still used; update some values.
244 $qry = "UPDATE object_service SET expected_interval='" . $_POST['expinterval'];
245 $qry .= "' WHERE objectid='" . $_GET['oid'];
246 $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
247 pg_exec($this->database, $qry);
251 // Checkbox was turned off, remove the service
253 $qry = "DELETE FROM object_service WHERE objectid='" . $_GET['oid'];
254 $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
255 pg_exec($this->database, $qry);
259 else if (isset($_POST['action']) && $_POST['action'] == 'Modify User')
261 $obj_srv_res = pg_exec($this->database, "SELECT * from object_user WHERE objectid='" . $_GET['oid']
262 . "' AND username='" . $_POST['username'] . "'");
264 if (pg_numrows($obj_srv_res) == 0)
266 // Add a new user for this object
267 if (isset($_POST['userused']))
269 $qry = "INSERT INTO object_user (objectid, username, security_level) ";
270 $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['username'] . "', '";
271 $qry .= $_POST['seclevel'] . "')";
273 pg_exec($this->database, $qry);
278 // Modify or remove the user for this object
279 if (isset($_POST['userused']))
281 // Service is still used; update some values.
282 $qry = "UPDATE object_user SET security_level='" . $_POST['seclevel'];
283 $qry .= "' WHERE objectid='" . $_GET['oid'];
284 $qry .= "' AND username='" . $_POST['username'] . "'";
285 pg_exec($this->database, $qry);
289 // Checkbox was turned off, remove the user
291 $qry = "DELETE FROM object_user WHERE objectid='" . $_GET['oid'];
292 $qry .= "' AND username='" . $_POST['username'] . "'";
293 pg_exec($this->database, $qry);
298 $res = pg_exec($this->database, "SELECT * FROM object
299 WHERE objectid='" . $_GET['oid'] . "'");
300 $obj = pg_fetch_object($res, 0);
302 echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
305 echo "<tr><td>Name</td><td><input name='oname' type='text' value='";
306 echo $obj->objectname . "'></td></tr>";
307 echo "<tr><td>Identification code</td><td><input name='ocode' type='text' value='";
308 echo $obj->objectcode . "'></td></tr>";
309 echo "<tr><td>Description</td><td><textarea name='odescription' rows='3' cols='30'>";
310 echo $obj->object_description . "</textarea></td></tr>";
311 echo "<tr><td>Owner</td><td><textarea name='oowner' rows='3' cols='30'>";
312 echo $obj->object_owner . "</textarea></td></tr>";
313 echo "<tr><td>Physical location</td><td><textarea name='olocation' rows='3' cols='30'>";
314 echo $obj->physical_location . "</textarea></td></tr>";
315 echo "<tr><td>Remarks</td><td><textarea name='oremark' rows='3' cols='30'>";
316 echo $obj->remark . "</textarea></td></tr>";
317 echo "<tr><td>Timezone</td><td><input name='otimezone' type='text' value='";
318 echo $obj->timezone . "'></td></tr>";
321 echo "<input type='submit' name='action' value='Save Changes'>";
324 echo "<h1>Services on " . $obj->objectname . "</h1><hr>\n";
327 echo "<tr><th>Service name</th><th>Last entry</th><th>Expected interval</th></tr>";
328 $srv_res = pg_exec($this->database, "SELECT servicecode, servicename FROM service
329 ORDER BY servicecode");
330 for ($srv_row = 0; $srv_row < pg_numrows($srv_res); $srv_row++)
332 $srv = pg_fetch_object($srv_res, $srv_row);
333 $srv_obj_res = pg_exec($this->database, "SELECT * FROM object_service WHERE objectid='"
334 . $obj->objectid . "' AND servicecode='" . $srv->servicecode . "'");
337 echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
338 echo "<input type='hidden' name='servcode' value='" . $srv->servicecode . "'>";
340 if (pg_numrows($srv_obj_res) == 0)
342 echo "<td><input name='servused' type='checkbox'> " . $srv->servicename . "</td>";
343 echo "<td> </td>";
344 echo "<td><input name='expinterval' type='text' value='0'></td>";
345 echo "<td><input type='submit' name='action' value='Modify Service'></td>";
349 $obj_srv = pg_fetch_object($srv_obj_res, 0);
350 echo "<td><input name='servused' type='checkbox' checked='true'> " . $srv->servicename . "</td>";
351 echo "<td>" . $obj_srv->last_entry . "</td>";
352 echo "<td><input name='expinterval' type='text' value='" . $obj_srv->expected_interval . "'></td>";
353 echo "<td><input type='submit' name='action' value='Modify Service'></td>";
359 echo "<h1>Users of " . $obj->objectname . "</h1><hr>\n";
362 echo "<tr><th>User name</th><th>Security level</th><th> </th></tr>";
364 $usr_res = pg_exec($this->database, "SELECT username, security_level FROM usr ORDER BY username");
365 for ($usr_row = 0; $usr_row < pg_numrows($usr_res); $usr_row++)
367 $usr = pg_fetch_object($usr_res, $usr_row);
368 $usr_obj_res = pg_exec($this->database, "SELECT * FROM object_user WHERE objectid='"
369 . $obj->objectid . "' AND username='" . $usr->username . "'");
372 echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
373 echo "<input type='hidden' name='username' value='" . $usr->username . "'>";
375 if (pg_numrows($usr_obj_res) == 0)
377 echo "<td><input name='userused' type='checkbox'> " . $usr->username . "</td>";
378 echo "<td><input name='seclevel' type='text' value='" . $usr->security_level . "'></td>";
379 echo "<td><input type='submit' name='action' value='Modify User'></td>";
383 $usr_obj = pg_fetch_object($usr_obj_res, 0);
384 echo "<td><input name='userused' type='checkbox' checked='on'> " . $usr->username . "</td>";
385 echo "<td><input name='seclevel' type='text' value='" . $usr_obj->security_level . "'></td>";
386 echo "<td><input type='submit' name='action' value='Modify User'></td>";
394 echo "<script type='text/ecmascript'>
395 document.getElementById('menu_title').innerHTML = \"<h1>Objects Administration<\/h1>\"
400 $res = pg_exec($this->database, "SELECT * FROM object ORDER BY objectname");
404 <tr><th>Object</th><th>Description</th><th>Log entries</th>
405 <th>Parameters</th><th>Notifications</th><th>Abuses</th></tr>
410 //The counters are set to zero
412 $count_notifications = 0;
413 $closed_notifications = 0;
414 $count_parameters = 0;
415 $removed_parameters = 0;
417 while ($obj < pg_numrows($res))
419 $u = pg_fetch_object($res, $obj);
421 $this->GatherStatistics($u->objectid);
423 $count_parameters += $this->nr_parameters;
424 $removed_parameters += $this->removed_parameters;
425 $count_logs = $count_logs + $this->nr_logs;
427 $count_notifications += $this->nr_notifications;
428 $closed_notifications += $this->closed_notifications;
430 <tr><td><center><a href='objects.php?oid=<?php echo $u->objectid?>'><img src='server.png' alt='server'></a><br>
431 <b><?php echo $u->objectname ?></b></center>
433 <?php echo nl2br($u->object_description) ?>
434 </td><td class='number'>
435 <?php if ( $this->nr_logs > 0 )
437 echo "<a href='log.php?oid=$u->objectid'> $this->nr_logs </a>";
444 </td><td class='number'>
445 <?php echo "<a href='parameter.php?oid=$u->objectid'>" . $this->nr_parameters
446 . " (" . $this->removed_parameters . " removed)</a>" ?>
447 </td><td class='number'>
448 <?php if( $this->nr_notifications == $this->closed_notifications )
450 echo $this->nr_notifications . " (" . $this->closed_notifications . " closed)";
454 echo "<a href='notification.php?oid=$u->objectid'>" . $this->nr_notifications
455 . " (" . $this->closed_notifications . " closed)</a>";
458 </td><td class='number'>
459 <?php echo "<a href='abuse.php?oid=$u->objectid'>" . "Abuse list"
462 <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
463 <input type='hidden' name='objectid' value='<?php echo $u->objectid ?>'>
464 <input type='submit' name='action' value='Remove'>
472 echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
473 echo "<td> </td>";
474 echo "<td class='number'>$count_logs</td>";
475 echo "<td class='number'>$count_parameters ($removed_parameters removed)</td>";
476 echo "<td class='number'>$count_notifications ($closed_notifications closed)</td>";
477 echo "<td> </td>";
483 <h2>Create new object:</h2>
485 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
486 Object's name (FQDN): <input name='objectname' type='text'>
488 <input type='submit' name='action' value='Create'>
497 $obj_page = new object_page("Gnucomo Objects Administration");
499 $obj_page->Showpage();