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.9 $
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.9 2003-09-01 06:55:00 arjen
33 Provides an interface to edit the list of
34 services and users for an object.
36 Revision 1.8 2003/08/14 10:35:07 arjen
37 Added editing of detailed object information.
39 Revision 1.7 2003/07/15 11:02:25 arjen
40 Use the new object_statistics table.
42 Revision 1.6 2003/02/21 08:46:58 arjen
43 Improved the table layout.
45 Revision 1.5 2003/02/13 09:01:29 arjen
46 All web interface pages use the page class.
48 Revision 1.4 2003/02/13 08:48:23 arjen
49 Added log, notification and parameter counters to the 'object' table.
50 Counting these things at the time a user interface needs them is
51 too slow. Other programs, like gcm_daemon en gcm_input should prepare
52 these counters for quick retrieval.
54 Revision 1.3 2003/02/10 15:42:24 arjen
55 Show the total number of Log entries, parameters and notifications
57 Revision 1.2 2003/02/05 09:48:14 arjen
58 Added display and handling of notifications
60 ******************************/
62 // RCSID = "$Id: objects.php,v 1.9 2003-09-01 06:55:00 arjen Exp $";
64 ini_set('include_path', '.:./classes:../phpclasses');
66 require_once('page.class.php');
68 function clientscripts()
72 <script language='JavaScript'>
74 function CheckCreate(f)
76 if (f.objectname.value == "")
78 alert("You must supply a name");
84 function CheckRemove(f)
86 var message = "Are you sure you want to remove object ";
87 message += f.objectname.value;
90 return confirm(message);
98 class object_page extends page
101 var $nr_parameters, $removed_parameters;
102 var $nr_notifications, $closed_notifications;
105 function GatherStatistics($objectid)
107 // Gather statistics on parameters
109 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
110 . $objectid . "' AS BIGINT) AND statname='parameters'");
111 $stat = pg_fetch_object($r, 0);
112 $this->nr_parameters = $stat->statvalue;
114 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
115 . $objectid . "' AS BIGINT) AND statname='removed_parameters'");
116 $stat = pg_fetch_object($r, 0);
117 $this->removed_parameters = $stat->statvalue;
119 // Gather statistics on notifications
121 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
122 . $objectid . "' AS BIGINT) AND statname='notifications'");
123 $stat = pg_fetch_object($r, 0);
124 $this->nr_notifications = $stat->statvalue;
126 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
127 . $objectid . "' AS BIGINT) AND statname='closed_notifications'");
128 $stat = pg_fetch_object($r, 0);
129 $this->closed_notifications = $stat->statvalue;
131 // Gather statistics on log entries
133 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
134 . $objectid . "' AS BIGINT) AND statname='logs'");
135 $stat = pg_fetch_object($r, 0);
136 $this->nr_logs = $stat->statvalue;
144 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
146 pg_exec($this->database, "INSERT INTO object (objectname, log_count, parameter_count, notification_count)
147 VALUES ('" . $_POST['objectname'] . "', '0', '0', '0')");
150 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
152 pg_exec($this->database, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
155 if (isset($_GET['oid']))
157 echo "<h1>Detailed information for object " . $_GET['oid'] . "</h1><hr>";
159 if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
161 $qry = "UPDATE object SET objectname='" . $_POST['oname'] . "'";
162 $qry .= ", objectcode='" . $_POST['ocode'] . "'";
163 $qry .= ", object_description='" . $_POST['odescription'] . "'";
164 $qry .= ", object_owner='" . $_POST['oowner'] . "'";
165 $qry .= ", physical_location='" . $_POST['olocation'] . "'";
166 $qry .= ", remark='" . $_POST['oremark'] . "'";
167 $qry .= ", timezone='" . $_POST['otimezone'] . "'";
168 $qry .= " WHERE objectid=" . $_GET['oid'];
170 pg_exec($this->database, $qry);
172 else if (isset($_POST['action']) && $_POST['action'] == 'Modify Service')
174 $obj_srv_res = pg_exec($this->database, "SELECT * from object_service WHERE objectid='" . $_GET['oid']
175 . "' AND servicecode='" . $_POST['servcode'] . "'");
177 if (pg_numrows($obj_srv_res) == 0)
179 // Add a new service for this object
180 if (isset($_POST['servused']))
182 $qry = "INSERT INTO object_service (objectid, servicecode, expected_interval) ";
183 $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['servcode'] . "', '";
184 $qry .= $_POST['expinterval'] . "')";
186 pg_exec($this->database, $qry);
191 // Modify or remove the service for this object
192 if (isset($_POST['servused']))
194 // Service is still used; update some values.
195 $qry = "UPDATE object_service SET expected_interval='" . $_POST['expinterval'];
196 $qry .= "' WHERE objectid='" . $_GET['oid'];
197 $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
198 pg_exec($this->database, $qry);
202 // Checkbox was turned off, remove the service
204 $qry = "DELETE FROM object_service WHERE objectid='" . $_GET['oid'];
205 $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
206 pg_exec($this->database, $qry);
210 else if (isset($_POST['action']) && $_POST['action'] == 'Modify User')
212 $obj_srv_res = pg_exec($this->database, "SELECT * from object_user WHERE objectid='" . $_GET['oid']
213 . "' AND username='" . $_POST['username'] . "'");
215 if (pg_numrows($obj_srv_res) == 0)
217 // Add a new user for this object
218 if (isset($_POST['userused']))
220 $qry = "INSERT INTO object_user (objectid, username, security_level) ";
221 $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['username'] . "', '";
222 $qry .= $_POST['seclevel'] . "')";
224 pg_exec($this->database, $qry);
229 // Modify or remove the user for this object
230 if (isset($_POST['userused']))
232 // Service is still used; update some values.
233 $qry = "UPDATE object_user SET security_level='" . $_POST['seclevel'];
234 $qry .= "' WHERE objectid='" . $_GET['oid'];
235 $qry .= "' AND username='" . $_POST['username'] . "'";
236 pg_exec($this->database, $qry);
240 // Checkbox was turned off, remove the user
242 $qry = "DELETE FROM object_user WHERE objectid='" . $_GET['oid'];
243 $qry .= "' AND username='" . $_POST['username'] . "'";
244 pg_exec($this->database, $qry);
249 $res = pg_exec($this->database, "SELECT * FROM object
250 WHERE objectid='" . $_GET['oid'] . "'");
251 $obj = pg_fetch_object($res, 0);
253 echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
256 echo "<tr><td>Name</td><td><input name='oname' type='text' value='";
257 echo $obj->objectname . "'></td></tr>";
258 echo "<tr><td>Identification code</td><td><input name='ocode' type='text' value='";
259 echo $obj->objectcode . "'></td></tr>";
260 echo "<tr><td>Description</td><td><textarea name='odescription'>";
261 echo $obj->object_description . "</textarea></td></tr>";
262 echo "<tr><td>Owner</td><td><textarea name='oowner'>";
263 echo $obj->object_owner . "</textarea></td></tr>";
264 echo "<tr><td>Physical location</td><td><textarea name='olocation'>";
265 echo $obj->physical_location . "</textarea></td></tr>";
266 echo "<tr><td>Remarks</td><td><textarea name='oremark'>";
267 echo $obj->remark . "</textarea></td></tr>";
268 echo "<tr><td>Timezone</td><td><input name='otimezone' type='text' value='";
269 echo $obj->timezone . "'></td></tr>";
272 echo "<input type='submit' name='action' value='Save Changes'>";
275 echo "<h1>Services on " . $obj->objectname . "</h1><hr>\n";
278 echo "<tr><th>Service name</th><th>Last entry</th><th>Expected interval</th></tr>";
279 $srv_res = pg_exec($this->database, "SELECT servicecode, servicename FROM service
280 ORDER BY servicecode");
281 for ($srv_row = 0; $srv_row < pg_numrows($srv_res); $srv_row++)
283 $srv = pg_fetch_object($srv_res, $srv_row);
284 $srv_obj_res = pg_exec($this->database, "SELECT * FROM object_service WHERE objectid='"
285 . $obj->objectid . "' AND servicecode='" . $srv->servicecode . "'");
287 echo "<tr><form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
288 echo "<input type='hidden' name='servcode' value='" . $srv->servicecode . "'>";
290 if (pg_numrows($srv_obj_res) == 0)
292 echo "<td><input name='servused' type='checkbox'> " . $srv->servicename . "</td>";
293 echo "<td> </td>";
294 echo "<td><input name='expinterval' type='text' value='0'></td>";
295 echo "<td><input type='submit' name='action' value='Modify Service'></td>";
299 $obj_srv = pg_fetch_object($srv_obj_res, 0);
300 echo "<td><input name='servused' type='checkbox' checked='true'> " . $srv->servicename . "</td>";
301 echo "<td>" . $obj_srv->last_entry . "</td>";
302 echo "<td><input name='expinterval' type='text' value='" . $obj_srv->expected_interval . "'></td>";
303 echo "<td><input type='submit' name='action' value='Modify Service'></td>";
309 echo "<h1>Users of " . $obj->objectname . "</h1><hr>\n";
312 echo "<tr><th>User name</th><th>Security level</th><th> </th></tr>";
314 $usr_res = pg_exec($this->database, "SELECT username, security_level FROM usr ORDER BY username");
315 for ($usr_row = 0; $usr_row < pg_numrows($usr_res); $usr_row++)
317 $usr = pg_fetch_object($usr_res, $usr_row);
318 $usr_obj_res = pg_exec($this->database, "SELECT * FROM object_user WHERE objectid='"
319 . $obj->objectid . "' AND username='" . $usr->username . "'");
321 echo "<tr><form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
322 echo "<input type='hidden' name='username' value='" . $usr->username . "'>";
324 if (pg_numrows($usr_obj_res) == 0)
326 echo "<td><input name='userused' type='checkbox'> " . $usr->username . "</td>";
327 echo "<td><input name='seclevel' type='text' value='" . $usr->security_level . "'></td>";
328 echo "<td><input type='submit' name='action' value='Modify User'></td>";
332 $usr_obj = pg_fetch_object($usr_obj_res, 0);
333 echo "<td><input name='userused' type='checkbox' checked='on'> " . $usr->username . "</td>";
334 echo "<td><input name='seclevel' type='text' value='" . $usr_obj->security_level . "'></td>";
335 echo "<td><input type='submit' name='action' value='Modify User'></td>";
343 echo "<h1>Objects Administration</h1><hr>";
345 $res = pg_exec($this->database, "SELECT * FROM object ORDER BY objectname");
349 <tr><th>Object</th><th>Description</th><th>Log entries</th>
350 <th>Parameters</th><th>Notifications</th></tr>
355 //The counters are set to zero
357 $count_notifications = 0;
358 $closed_notifications = 0;
359 $count_parameters = 0;
360 $removed_parameters = 0;
362 while ($obj < pg_numrows($res))
364 $u = pg_fetch_object($res, $obj);
366 $this->GatherStatistics($u->objectid);
368 $count_parameters += $this->nr_parameters;
369 $removed_parameters += $this->removed_parameters;
370 $count_logs = $count_logs + $this->nr_logs;
372 $count_notifications += $this->nr_notifications;
373 $closed_notifications += $this->closed_notifications;
375 <tr><td><center><a href='objects.php?oid=<?php echo $u->objectid?>'><img src='server.png'></a><br>
376 <b><?php echo $u->objectname ?></b></center>
378 <?php echo nl2br($u->object_description) ?>
379 </td><td class='number'>
380 <?php echo "<a href='log.php?oid=$u->objectid'> $this->nr_logs </a>" ?>
381 </td><td class='number'>
382 <?php echo "<a href='parameter.php?oid=$u->objectid'>" . $this->nr_parameters
383 . " (" . $this->removed_parameters . " removed)</a>" ?>
384 </td><td class='number'>
385 <?php echo "<a href='notification.php?oid=$u->objectid'>" . $this->nr_notifications
386 . " (" . $this->closed_notifications . " closed)</a>" ?>
388 <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
389 <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
390 <input type='submit' name='action' value='Remove'>
398 echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
399 echo "<td> </td>";
400 echo "<td class='number'>$count_logs</td>";
401 echo "<td class='number'>$count_parameters ($removed_parameters removed)</td>";
402 echo "<td class='number'>$count_notifications ($closed_notifications closed)</td></tr>";
407 <h2>Create new object:</h2>
410 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
411 Object's name (FQDN): <input name='objectname' type='text'>
413 <input type='submit' name='action' value='Create'>
423 $obj_page = new object_page("Gnucomo Objects Administration");
425 $obj_page->Showpage();