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.10 $
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.10 2005-06-04 07:24:38 arjen
35 Revision 1.9 2003/09/01 06:55:00 arjen
36 Provides an interface to edit the list of
37 services and users for an object.
39 Revision 1.8 2003/08/14 10:35:07 arjen
40 Added editing of detailed object information.
42 Revision 1.7 2003/07/15 11:02:25 arjen
43 Use the new object_statistics table.
45 Revision 1.6 2003/02/21 08:46:58 arjen
46 Improved the table layout.
48 Revision 1.5 2003/02/13 09:01:29 arjen
49 All web interface pages use the page class.
51 Revision 1.4 2003/02/13 08:48:23 arjen
52 Added log, notification and parameter counters to the 'object' table.
53 Counting these things at the time a user interface needs them is
54 too slow. Other programs, like gcm_daemon en gcm_input should prepare
55 these counters for quick retrieval.
57 Revision 1.3 2003/02/10 15:42:24 arjen
58 Show the total number of Log entries, parameters and notifications
60 Revision 1.2 2003/02/05 09:48:14 arjen
61 Added display and handling of notifications
63 ******************************/
65 // RCSID = "$Id: objects.php,v 1.10 2005-06-04 07:24:38 arjen Exp $";
67 ini_set('include_path', '.:./classes:../phpclasses');
69 require_once('page.class.php');
71 function clientscripts()
75 <script language='JavaScript'>
77 function CheckCreate(f)
79 if (f.objectname.value == "")
81 alert("You must supply a name");
87 function CheckRemove(f)
89 var message = "Are you sure you want to remove object ";
90 message += f.objectname.value;
93 return confirm(message);
101 class object_page extends page
104 var $nr_parameters, $removed_parameters;
105 var $nr_notifications, $closed_notifications;
108 function GatherStatistics($objectid)
110 // Gather statistics on parameters
112 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
113 . $objectid . "' AS BIGINT) AND statname='parameters'");
114 $stat = pg_fetch_object($r, 0);
115 $this->nr_parameters = $stat->statvalue;
117 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
118 . $objectid . "' AS BIGINT) AND statname='removed_parameters'");
119 $stat = pg_fetch_object($r, 0);
120 $this->removed_parameters = $stat->statvalue;
122 // Gather statistics on notifications
124 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
125 . $objectid . "' AS BIGINT) AND statname='notifications'");
126 $stat = pg_fetch_object($r, 0);
127 $this->nr_notifications = $stat->statvalue;
129 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
130 . $objectid . "' AS BIGINT) AND statname='closed_notifications'");
131 $stat = pg_fetch_object($r, 0);
132 $this->closed_notifications = $stat->statvalue;
134 // Gather statistics on log entries
136 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
137 . $objectid . "' AS BIGINT) AND statname='logs'");
138 $stat = pg_fetch_object($r, 0);
139 $this->nr_logs = $stat->statvalue;
147 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
149 pg_exec($this->database, "INSERT INTO object (objectname, log_count, parameter_count, notification_count)
150 VALUES ('" . $_POST['objectname'] . "', '0', '0', '0')");
153 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
155 pg_exec($this->database, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
158 if (isset($_GET['oid']))
160 echo "<h1>Detailed information for object " . $_GET['oid'] . "</h1><hr>";
162 if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
164 $qry = "UPDATE object SET objectname='" . $_POST['oname'] . "'";
165 $qry .= ", objectcode='" . $_POST['ocode'] . "'";
166 $qry .= ", object_description='" . $_POST['odescription'] . "'";
167 $qry .= ", object_owner='" . $_POST['oowner'] . "'";
168 $qry .= ", physical_location='" . $_POST['olocation'] . "'";
169 $qry .= ", remark='" . $_POST['oremark'] . "'";
170 $qry .= ", timezone='" . $_POST['otimezone'] . "'";
171 $qry .= " WHERE objectid=" . $_GET['oid'];
173 pg_exec($this->database, $qry);
175 else if (isset($_POST['action']) && $_POST['action'] == 'Modify Service')
177 $obj_srv_res = pg_exec($this->database, "SELECT * from object_service WHERE objectid='" . $_GET['oid']
178 . "' AND servicecode='" . $_POST['servcode'] . "'");
180 if (pg_numrows($obj_srv_res) == 0)
182 // Add a new service for this object
183 if (isset($_POST['servused']))
185 $qry = "INSERT INTO object_service (objectid, servicecode, expected_interval) ";
186 $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['servcode'] . "', '";
187 $qry .= $_POST['expinterval'] . "')";
189 pg_exec($this->database, $qry);
194 // Modify or remove the service for this object
195 if (isset($_POST['servused']))
197 // Service is still used; update some values.
198 $qry = "UPDATE object_service SET expected_interval='" . $_POST['expinterval'];
199 $qry .= "' WHERE objectid='" . $_GET['oid'];
200 $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
201 pg_exec($this->database, $qry);
205 // Checkbox was turned off, remove the service
207 $qry = "DELETE FROM object_service WHERE objectid='" . $_GET['oid'];
208 $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
209 pg_exec($this->database, $qry);
213 else if (isset($_POST['action']) && $_POST['action'] == 'Modify User')
215 $obj_srv_res = pg_exec($this->database, "SELECT * from object_user WHERE objectid='" . $_GET['oid']
216 . "' AND username='" . $_POST['username'] . "'");
218 if (pg_numrows($obj_srv_res) == 0)
220 // Add a new user for this object
221 if (isset($_POST['userused']))
223 $qry = "INSERT INTO object_user (objectid, username, security_level) ";
224 $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['username'] . "', '";
225 $qry .= $_POST['seclevel'] . "')";
227 pg_exec($this->database, $qry);
232 // Modify or remove the user for this object
233 if (isset($_POST['userused']))
235 // Service is still used; update some values.
236 $qry = "UPDATE object_user SET security_level='" . $_POST['seclevel'];
237 $qry .= "' WHERE objectid='" . $_GET['oid'];
238 $qry .= "' AND username='" . $_POST['username'] . "'";
239 pg_exec($this->database, $qry);
243 // Checkbox was turned off, remove the user
245 $qry = "DELETE FROM object_user WHERE objectid='" . $_GET['oid'];
246 $qry .= "' AND username='" . $_POST['username'] . "'";
247 pg_exec($this->database, $qry);
252 $res = pg_exec($this->database, "SELECT * FROM object
253 WHERE objectid='" . $_GET['oid'] . "'");
254 $obj = pg_fetch_object($res, 0);
256 echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
259 echo "<tr><td>Name</td><td><input name='oname' type='text' value='";
260 echo $obj->objectname . "'></td></tr>";
261 echo "<tr><td>Identification code</td><td><input name='ocode' type='text' value='";
262 echo $obj->objectcode . "'></td></tr>";
263 echo "<tr><td>Description</td><td><textarea name='odescription'>";
264 echo $obj->object_description . "</textarea></td></tr>";
265 echo "<tr><td>Owner</td><td><textarea name='oowner'>";
266 echo $obj->object_owner . "</textarea></td></tr>";
267 echo "<tr><td>Physical location</td><td><textarea name='olocation'>";
268 echo $obj->physical_location . "</textarea></td></tr>";
269 echo "<tr><td>Remarks</td><td><textarea name='oremark'>";
270 echo $obj->remark . "</textarea></td></tr>";
271 echo "<tr><td>Timezone</td><td><input name='otimezone' type='text' value='";
272 echo $obj->timezone . "'></td></tr>";
275 echo "<input type='submit' name='action' value='Save Changes'>";
278 echo "<h1>Services on " . $obj->objectname . "</h1><hr>\n";
281 echo "<tr><th>Service name</th><th>Last entry</th><th>Expected interval</th></tr>";
282 $srv_res = pg_exec($this->database, "SELECT servicecode, servicename FROM service
283 ORDER BY servicecode");
284 for ($srv_row = 0; $srv_row < pg_numrows($srv_res); $srv_row++)
286 $srv = pg_fetch_object($srv_res, $srv_row);
287 $srv_obj_res = pg_exec($this->database, "SELECT * FROM object_service WHERE objectid='"
288 . $obj->objectid . "' AND servicecode='" . $srv->servicecode . "'");
290 echo "<tr><form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
291 echo "<input type='hidden' name='servcode' value='" . $srv->servicecode . "'>";
293 if (pg_numrows($srv_obj_res) == 0)
295 echo "<td><input name='servused' type='checkbox'> " . $srv->servicename . "</td>";
296 echo "<td> </td>";
297 echo "<td><input name='expinterval' type='text' value='0'></td>";
298 echo "<td><input type='submit' name='action' value='Modify Service'></td>";
302 $obj_srv = pg_fetch_object($srv_obj_res, 0);
303 echo "<td><input name='servused' type='checkbox' checked='true'> " . $srv->servicename . "</td>";
304 echo "<td>" . $obj_srv->last_entry . "</td>";
305 echo "<td><input name='expinterval' type='text' value='" . $obj_srv->expected_interval . "'></td>";
306 echo "<td><input type='submit' name='action' value='Modify Service'></td>";
312 echo "<h1>Users of " . $obj->objectname . "</h1><hr>\n";
315 echo "<tr><th>User name</th><th>Security level</th><th> </th></tr>";
317 $usr_res = pg_exec($this->database, "SELECT username, security_level FROM usr ORDER BY username");
318 for ($usr_row = 0; $usr_row < pg_numrows($usr_res); $usr_row++)
320 $usr = pg_fetch_object($usr_res, $usr_row);
321 $usr_obj_res = pg_exec($this->database, "SELECT * FROM object_user WHERE objectid='"
322 . $obj->objectid . "' AND username='" . $usr->username . "'");
324 echo "<tr><form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
325 echo "<input type='hidden' name='username' value='" . $usr->username . "'>";
327 if (pg_numrows($usr_obj_res) == 0)
329 echo "<td><input name='userused' type='checkbox'> " . $usr->username . "</td>";
330 echo "<td><input name='seclevel' type='text' value='" . $usr->security_level . "'></td>";
331 echo "<td><input type='submit' name='action' value='Modify User'></td>";
335 $usr_obj = pg_fetch_object($usr_obj_res, 0);
336 echo "<td><input name='userused' type='checkbox' checked='on'> " . $usr->username . "</td>";
337 echo "<td><input name='seclevel' type='text' value='" . $usr_obj->security_level . "'></td>";
338 echo "<td><input type='submit' name='action' value='Modify User'></td>";
346 echo "<h1>Objects Administration</h1><hr>";
348 $res = pg_exec($this->database, "SELECT * FROM object ORDER BY objectname");
352 <tr><th>Object</th><th>Description</th><th>Log entries</th>
353 <th>Parameters</th><th>Notifications</th><th>Abuses</th></tr>
358 //The counters are set to zero
360 $count_notifications = 0;
361 $closed_notifications = 0;
362 $count_parameters = 0;
363 $removed_parameters = 0;
365 while ($obj < pg_numrows($res))
367 $u = pg_fetch_object($res, $obj);
369 $this->GatherStatistics($u->objectid);
371 $count_parameters += $this->nr_parameters;
372 $removed_parameters += $this->removed_parameters;
373 $count_logs = $count_logs + $this->nr_logs;
375 $count_notifications += $this->nr_notifications;
376 $closed_notifications += $this->closed_notifications;
378 <tr><td><center><a href='objects.php?oid=<?php echo $u->objectid?>'><img src='server.png'></a><br>
379 <b><?php echo $u->objectname ?></b></center>
381 <?php echo nl2br($u->object_description) ?>
382 </td><td class='number'>
383 <?php echo "<a href='log.php?oid=$u->objectid'> $this->nr_logs </a>" ?>
384 </td><td class='number'>
385 <?php echo "<a href='parameter.php?oid=$u->objectid'>" . $this->nr_parameters
386 . " (" . $this->removed_parameters . " removed)</a>" ?>
387 </td><td class='number'>
388 <?php echo "<a href='notification.php?oid=$u->objectid'>" . $this->nr_notifications
389 . " (" . $this->closed_notifications . " closed)</a>" ?>
390 </td><td class='number'>
391 <?php echo "<a href='abuse.php?oid=$u->objectid'>" . "Abuse list"
394 <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
395 <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
396 <input type='submit' name='action' value='Remove'>
404 echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
405 echo "<td> </td>";
406 echo "<td class='number'>$count_logs</td>";
407 echo "<td class='number'>$count_parameters ($removed_parameters removed)</td>";
408 echo "<td class='number'>$count_notifications ($closed_notifications closed)</td>";
409 echo "<td> </td>";
415 <h2>Create new object:</h2>
418 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
419 Object's name (FQDN): <input name='objectname' type='text'>
421 <input type='submit' name='action' value='Create'>
431 $obj_page = new object_page("Gnucomo Objects Administration");
433 $obj_page->Showpage();