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.2 $
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.2 2005-06-04 07:25:59 arjen
33 Added an interface to edit check patterns
35 Revision 1.1 2003/09/01 06:53:22 arjen
36 New page to enter and modify services.
38 ******************************/
40 // RCSID = "$Id: services.php,v 1.2 2005-06-04 07:25:59 arjen Exp $";
42 ini_set('include_path', '.:./classes:../phpclasses');
44 require_once('page.class.php');
46 function clientscripts()
51 <script language='JavaScript'>
53 function CheckCreate(f)
55 if (f.servcode.value == "")
57 alert("You must supply a service code");
63 function CheckRemove(f)
65 var message = "Are you sure you want to remove service ";
66 message += f.servcode.value;
69 return confirm(message);
77 class service_page extends page
85 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['servcode']))
87 pg_exec($this->database, "INSERT INTO service
88 (servicecode, servicename, default_priority, max_priority) VALUES ('"
89 . $_POST['servcode'] . "','" . $_POST['servname'] . "','"
90 . $_POST['defprior'] . "','" . $_POST['maxprior'] . "')");
93 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['servcode']))
95 pg_exec($this->database, "DELETE FROM service WHERE servicecode='"
96 . $_POST['servcode'] . "'");
99 if (isset($_GET['servcode']))
101 echo "<h1>Detailed information for service " . $_GET['servcode'] . "</h1><br>\n";
103 if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
105 $qry = "UPDATE service SET servicename='" . $_POST['servname'] . "'";
106 $qry .= ", default_priority='" . $_POST['defprior'] . "'";
107 $qry .= ", max_priority='" . $_POST['maxprior'] . "'";
108 $qry .= " WHERE servicecode='" . $_GET['servcode'] . "'";
110 pg_exec($this->database, $qry);
112 if (isset($_POST['action']) && $_POST['action'] == 'Add')
114 $qry = "INSERT INTO service_pattern VALUES ('". $_GET['servcode'] . "'";
115 $qry .= ", '" . $_POST['Rank'] . "'";
116 $qry .= ", '" . $_POST['Pattern'] . "'";
117 $qry .= ", '" . $_POST['Pat_Action'] . "'";
118 $qry .= ", '" . $_POST['Argument'] . "')";
120 pg_exec($this->database, $qry);
122 if (isset($_POST['action']) && $_POST['action'] == 'Change')
124 $qry = "UPDATE service_pattern SET rank = '" . $_POST['Rank'] . "'";
125 $qry .= ", pattern = '" . $_POST['Pattern'] . "'";
126 $qry .= ", action = '" . $_POST['Pat_Action'] . "'";
127 $qry .= ", argument = '" . $_POST['Argument'] . "'";
128 $qry .= " WHERE service = '" . $_GET['servcode'] . "' AND rank = '" . $_POST['Rank'] . "'";
130 pg_exec($this->database, $qry);
132 if (isset($_POST['action']) && $_POST['action'] == 'Delete')
134 $qry = "DELETE FROM service_pattern WHERE service = '". $_GET['servcode'] . "'";
135 $qry .= " AND rank = '" . $_POST['Rank'] . "'";
137 pg_exec($this->database, $qry);
140 $res = pg_exec($this->database, "SELECT * FROM service
141 WHERE servicecode='" . $_GET['servcode'] . "'");
142 $srv = pg_fetch_object($res, 0);
144 echo "<form action='services.php?servcode=" . $srv->servicecode . "' method='POST'>";
147 echo "<tr><td>Service name</td><td><input name='servname' type='text' value='";
148 echo $srv->servicename . "'></td></tr>";
149 echo "<tr><td>Default priority</td><td><select name='defprior'>";
150 for ($prior = 1; $prior < 6; $prior++)
152 echo "<option value='$prior'";
153 if ($prior == $srv->default_priority)
155 echo " selected='true'";
157 echo ">$prior</option>\n";
160 echo "<tr><td>Maximum priority</td><td><select name='maxprior'>";
161 for ($prior = 1; $prior < 6; $prior++)
163 echo "<option value='$prior'";
164 if ($prior == $srv->max_priority)
166 echo " selected='true'";
168 echo ">$prior</option>\n";
172 echo "<input type='submit' name='action' value='Save Changes'>";
175 echo "<h1>Patterns to check logs of " . $srv->servicename . "</h1>\n";
178 echo "<tr><th>Rank</th><th>Pattern</th><th>Action</th>";
179 echo "<th>Argument</th><th> </th><th> </th></tr>\n";
181 $pat_res = pg_exec($this->database, "SELECT * FROM service_pattern
182 WHERE service = '" . $srv->servicecode . "' ORDER BY rank");
183 for ($pat_row = 0; $pat_row < pg_numrows($pat_res); $pat_row++)
185 $pat = pg_fetch_object($pat_res, $pat_row);
186 echo "<tr><form action='services.php?servcode=" . $srv->servicecode . "' method='POST'><td>";
187 echo "<input type='text' name='Rank' value='" . $pat->rank . "'>";
189 echo "<input type='text' size='40' name='Pattern' value='" . $pat->pattern . "'>";
191 echo "<input type='text' name='Pat_Action' value='" . $pat->action . "'>";
193 echo "<input type='text' name='Argument' value='" . $pat->argument . "'>";
195 echo "<input type='submit' name='action' value='Change'>";
197 echo "<input type='submit' name='action' value='Delete'>";
198 echo "</td></form></tr>";
200 echo "<tr><form action='services.php?servcode=" . $srv->servicecode . "' method='POST'><td>";
201 echo "<input type='text' name='Rank' value=''>";
203 echo "<input type='text' size='40' name='Pattern' value=''>";
205 echo "<input type='text' name='Pat_Action' value=''>";
207 echo "<input type='text' name='Argument' value=''>";
209 echo "<input type='submit' name='action' value='Add'>";
210 echo "</td><td> ";
211 echo "</td></form></tr>";
216 echo "<h1>Service Administration</h1><hr>";
218 $res = pg_exec($this->database, "SELECT * FROM service ORDER BY servicecode");
221 echo "<tr><th>Service code</th><th>Name</th><th>Priority</th><th>Max priority</th><tr>";
223 while ($srv < pg_numrows($res))
225 $u = pg_fetch_object($res, $srv);
227 <tr><td align='center'><a href='services.php?servcode=<?php echo $u->servicecode?>'><img src='service.png'></a><br>
228 <b><?php echo $u->servicecode ?></b>
230 <?php echo $u->servicename ?>
232 <?php echo $u->default_priority ?>
234 <?php echo $u->max_priority ?>
236 <form action='services.php' method='post' onSubmit='return CheckRemove(this)'>
237 <input type='hidden' name='servcode' value='<?php echo $u->servicecode ?>'>
238 <input type='submit' name='action' value='Remove'>
248 <h2>Create new service:</h2>
251 <form action='services.php' method='post' onSubmit='return CheckCreate(this)'>
252 Service code: <input name='servcode' type='text'>
253 Service name: <input name='servname' type='text'>
254 Default priority: <select name='defprior'>
255 <option value='1'>1</option>
256 <option value='2'>2</option>
257 <option value='3'>3</option>
258 <option value='4'>4</option>
259 <option value='5'>5</option>
261 Maximum priority: <select name='maxprior'>
262 <option value='1'>1</option>
263 <option value='2'>2</option>
264 <option value='3'>3</option>
265 <option value='4'>4</option>
266 <option value='5' selected='true'>5</option>
269 <input type='submit' name='action' value='Create'>
278 $page = new service_page("Gnucomo User Administration");