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 : users.php
11 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
12 ** VERSION NUMBER : $Revision: 1.3 $
14 ** DESCRIPTION : User Administration page.
15 ** Input parameters: action (POST) : empty, 'Create'
16 ** username (POST) : name of the user 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 : Feb 14, 2003
28 **************************************************************************/
30 /*****************************
32 Revision 1.3 2003-02-21 08:44:19 arjen
33 Add a new user and make him/her a member of a group.
34 Change of passwords added.
36 Revision 1.2 2003/02/13 09:01:29 arjen
37 All web interface pages use the page class.
39 ******************************/
41 // RCSID = "$Id: users.php,v 1.3 2003-02-21 08:44:19 arjen Exp $";
43 ini_set('include_path', '.:./classes:../phpclasses');
45 require_once('page.class.php');
47 function clientscripts()
51 <script language='JavaScript'>
52 function CheckCreate(f)
54 if (f.username.value == "")
56 alert("You must supply a username");
59 if (f.passwd.value == "")
61 alert("You must supply a password");
64 if (f.passwd.value != f.pwverify.value)
66 alert("Passwords don't match");
72 function CheckRemove(f)
74 var message = "Are you sure you want to remove user ";
75 message += f.username.value;
78 return confirm(message);
83 if (f.passwd.value == "")
85 alert("You must supply a password");
88 if (f.passwd.value != f.pwverify.value)
90 alert("Passwords don't match");
100 class user_page extends page
105 echo "<h1>User Administration</h1><hr>";
107 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['username']))
109 $query = "CREATE USER " . $_POST['username'] . " PASSWORD '"
110 . $_POST['passwd'] . "' IN GROUP " . $_POST['group'];
111 if (pg_exec($this->database, $query) == FALSE)
113 echo "You can not create a new user.<br>";
117 pg_exec($this->database, "INSERT INTO usr (username, security_level) VALUES ('"
118 . $_POST['username'] . "','" . $_POST['seclevel'] . "')");
122 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['username']))
124 pg_exec($this->database, "DELETE FROM usr WHERE username='" . $_POST['username'] . "'");
125 pg_exec($this->database, "DROP USER " . $_POST['username']);
128 if (isset($_POST['action']) && $_POST['action'] == 'Change Password')
130 pg_exec($this->database, "ALTER USER " . $_SESSION['username'] .
131 " PASSWORD '" . $_POST['passwd'] . "'");
134 $res = pg_exec($this->database, "SELECT username, security_level FROM usr ORDER BY username");
138 while ($usr < pg_numrows($res))
140 $u = pg_fetch_object($res, $usr);
142 <tr><td align='center'><img src='user.png'><br>
143 <b><?php echo $u->username ?></b>
145 Sec. Level <?php echo $u->security_level ?>
147 <?php if ($_SESSION['username'] != $u->username)
150 <form action='users.php' method='post' onSubmit='return CheckRemove(this)'>
151 <input type='hidden' name='username' value='<?php echo $u->username ?>'>
152 <input type='submit' name='action' value='Remove'>
165 <h2>Create new user:</h2>
168 <form action='users.php' method='post' onSubmit='return CheckCreate(this)'>
169 User name: <input name='username' type='text'>
170 Group: <select name='group'>
171 <option value='view'>View</option>
172 <option value='ops'>Operator</option>
173 <option value='admin'>Admin</option>
175 Security level: <select name='seclevel'>
176 <option value='1'>1</option>
177 <option value='2'>2</option>
178 <option value='3'>3</option>
179 <option value='4'>4</option>
180 <option value='5'>5</option>
183 Password: <input type='password' name='passwd'>
184 Verify password: <input type='password' name='pwverify'>
186 <input type='submit' name='action' value='Create'>
190 <h2>Change your password:</h2>
191 <form action='users.php' method='post' onSubmit='return CheckPW(this)'>
192 New Password: <input type='password' name='passwd'>
193 Verify password: <input type='password' name='pwverify'>
195 <input type='submit' name='action' value='Change Password'>
201 $page = new user_page("Gnucomo User Administration");