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 : services.php
11 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
12 ** VERSION NUMBER : $Revision: 1.4 $
14 ** DESCRIPTION : Service Administration page.
15 ** Input parameters: action (POST) : empty, 'Create'
16 ** servcode (POST) : short name of the service to create or remove
21 ***************************************************************************
22 ** ADMINISTRATIVE INFORMATION *
23 ********************************
24 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
25 ** CREATION DATE : Aug 04, 2003
26 ** LAST UPDATE : Aug 28, 2003
28 **************************************************************************/
30 /*****************************
31 $Log: services.php,v $
32 Revision 1.4 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.3 2007/10/19 07:16:44 arjen
38 Improved interface for editing check patterns.
40 Revision 1.2 2005/06/04 07:25:59 arjen
41 Added an interface to edit check patterns
43 Revision 1.1 2003/09/01 06:53:22 arjen
44 New page to enter and modify services.
46 ******************************/
48 // RCSID = "$Id: services.php,v 1.4 2007-11-21 14:38:06 arjen Exp $";
50 ini_set('include_path', '.:./classes:../phpclasses');
52 require_once('page.class.php');
54 function clientscripts()
59 <script type='text/ecmascript'>
61 function CheckCreate(f)
63 if (f.servcode.value == "")
65 alert("You must supply a service code");
71 function CheckRemove(f)
73 var message = "Are you sure you want to remove service ";
74 message += f.servcode.value;
77 return confirm(message);
85 class service_page extends page
93 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['servcode']))
95 pg_exec($this->database, "INSERT INTO service
96 (servicecode, servicename, default_priority, max_priority) VALUES ('"
97 . $_POST['servcode'] . "','" . $_POST['servname'] . "','"
98 . $_POST['defprior'] . "','" . $_POST['maxprior'] . "')");
101 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['servcode']))
103 pg_exec($this->database, "DELETE FROM service WHERE servicecode='"
104 . $_POST['servcode'] . "'");
107 if (isset($_GET['servcode']))
109 echo "<script type='text/ecmascript'>
110 document.getElementById('menu_title').innerHTML =
111 '<h1>Detailed Information for service " . $_GET['servcode'] . "<\/h1>'</script><br>";
113 if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
115 $qry = "UPDATE service SET servicename='" . $_POST['servname'] . "'";
116 $qry .= ", default_priority='" . $_POST['defprior'] . "'";
117 $qry .= ", max_priority='" . $_POST['maxprior'] . "'";
118 $qry .= " WHERE servicecode='" . $_GET['servcode'] . "'";
120 pg_exec($this->database, $qry);
122 if (isset($_POST['action']) && $_POST['action'] == 'Add')
124 $qry = "INSERT INTO service_pattern VALUES ('". $_GET['servcode'] . "'";
125 $qry .= ", '" . $_POST['Rank'] . "'";
126 $qry .= ", '" . $_POST['Pattern'] . "'";
127 $qry .= ", '" . $_POST['Pat_Action'] . "'";
128 $qry .= ", '" . $_POST['Argument'] . "')";
130 pg_exec($this->database, $qry);
132 if (isset($_POST['action']) && $_POST['action'] == 'Change')
134 $qry = "UPDATE service_pattern SET rank = '" . $_POST['Rank'] . "'";
135 $qry .= ", pattern = '" . $_POST['Pattern'] . "'";
136 $qry .= ", action = '" . $_POST['Pat_Action'] . "'";
137 $qry .= ", argument = '" . $_POST['Argument'] . "'";
138 $qry .= " WHERE service = '" . $_GET['servcode'] . "' AND rank = '" . $_POST['Rank'] . "'";
140 pg_exec($this->database, $qry);
142 if (isset($_POST['action']) && $_POST['action'] == 'Delete')
144 $qry = "DELETE FROM service_pattern WHERE service = '". $_GET['servcode'] . "'";
145 $qry .= " AND rank = '" . $_POST['Rank'] . "'";
147 pg_exec($this->database, $qry);
150 $res = pg_exec($this->database, "SELECT * FROM service
151 WHERE servicecode='" . $_GET['servcode'] . "'");
152 $srv = pg_fetch_object($res, 0);
154 echo "<form action='services.php?servcode=" . $srv->servicecode . "' method='POST'>";
157 echo "<tr><td>Service name</td><td><input name='servname' type='text' value='";
158 echo $srv->servicename . "'></td></tr>";
159 echo "<tr><td>Default priority</td><td><select name='defprior'>";
160 for ($prior = 1; $prior < 6; $prior++)
162 echo "<option value='$prior'";
163 if ($prior == $srv->default_priority)
167 echo ">$prior</option>\n";
170 echo "<tr><td>Maximum priority</td><td><select name='maxprior'>";
171 for ($prior = 1; $prior < 6; $prior++)
173 echo "<option value='$prior'";
174 if ($prior == $srv->max_priority)
178 echo ">$prior</option>\n";
182 echo "<input type='submit' name='action' value='Save Changes'>";
185 echo "<h1>Patterns to check logs of " . $srv->servicename . "</h1>\n";
188 echo "<tr><th>Rank</th><th>Pattern</th><th>Action</th>";
189 echo "<th>Argument</th><th> </th><th> </th></tr>\n";
191 $pat_res = pg_exec($this->database, "SELECT * FROM service_pattern
192 WHERE service = '" . $srv->servicecode . "' ORDER BY rank");
193 for ($pat_row = 0; $pat_row < pg_numrows($pat_res); $pat_row++)
195 $pat = pg_fetch_object($pat_res, $pat_row);
196 echo "<tr><form action='services.php?servcode=" . $srv->servicecode . "' method='POST'><td>";
197 echo "<input type='text' name='Rank' value='" . $pat->rank . "'>";
199 echo "<input type='text' size='80' name='Pattern' value='" . $pat->pattern . "'>";
201 //echo "<input type='text' name='Pat_Action' value='" . $pat->action . "'>";
202 echo "<select name='Pat_Action'>";
204 if ($pat->action =='ignore') echo ' selected';
205 echo ">ignore</option>";
207 if ($pat->action =='notify') echo ' selected';
208 echo ">notify</option>";
210 if ($pat->action =='abuse') echo ' selected';
211 echo ">abuse</option>";
213 if ($pat->action =='forgive') echo ' selected';
214 echo ">forgive</option>";
217 echo "<input type='text' name='Argument' value='" . $pat->argument . "'>";
219 echo "<input type='submit' name='action' value='Change'>";
221 echo "<input type='submit' name='action' value='Delete'>";
222 echo "</td></form></tr>";
224 echo "<tr><form action='services.php?servcode=" . $srv->servicecode . "' method='POST'><td>";
225 echo "<input type='text' name='Rank' value=''>";
227 echo "<input type='text' size='80' name='Pattern' value=''>";
229 //echo "<input type='text' name='Pat_Action' value=''>";
230 echo "<select name='Pat_Action'>";
231 echo " <option selected>ignore</option>";
232 echo " <option>notify</option>";
233 echo " <option>abuse</option>";
234 echo " <option>forgive</option>";
237 echo "<input type='text' name='Argument' value=''>";
239 echo "<input type='submit' name='action' value='Add'>";
240 echo "</td><td> ";
241 echo "</td></form></tr>";
246 echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = '<h1>Service Administration<\/h1>'</script><br>";
248 $res = pg_exec($this->database, "SELECT * FROM service ORDER BY servicecode");
251 echo "<tr><th>Service code</th><th>Name</th><th>Priority</th><th>Max priority</th></tr>";
253 while ($srv < pg_numrows($res))
255 $u = pg_fetch_object($res, $srv);
257 <tr><td align='center'><a href='services.php?servcode=<?php echo $u->servicecode?>'><img src='service.png' alt='service'></a><br>
258 <b><?php echo $u->servicecode ?></b>
260 <?php echo $u->servicename ?>
262 <?php echo $u->default_priority ?>
264 <?php echo $u->max_priority ?>
266 <form action='services.php' method='post' onSubmit='return CheckRemove(this)'>
267 <input type='hidden' name='servcode' value='<?php echo $u->servicecode ?>'>
268 <input type='submit' name='action' value='Remove'>
278 <h2>Create new service:</h2>
280 <form action='services.php' method='post' onSubmit='return CheckCreate(this)'>
281 Service code: <input name='servcode' type='text'>
282 Service name: <input name='servname' type='text'>
283 Default priority: <select name='defprior'>
284 <option value='1'>1</option>
285 <option value='2'>2</option>
286 <option value='3'>3</option>
287 <option value='4'>4</option>
288 <option value='5'>5</option>
290 Maximum priority: <select name='maxprior'>
291 <option value='1'>1</option>
292 <option value='2'>2</option>
293 <option value='3'>3</option>
294 <option value='4'>4</option>
295 <option value='5' SELECTED>5</option>
298 <input type='submit' name='action' value='Create'>
306 $page = new service_page("Gnucomo User Administration");