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 : user.php
11 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
12 ** VERSION NUMBER : $Revision: 1.2 $
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 08, 2003
28 **************************************************************************/
30 /*****************************
32 Revision 1.2 2003-02-13 09:01:29 arjen
33 All web interface pages use the page class.
35 ******************************/
37 // RCSID = "$Id: users.php,v 1.2 2003-02-13 09:01:29 arjen Exp $";
39 ini_set('include_path', '.:./classes:../phpclasses');
41 require_once('page.class.php');
43 function clientscripts()
47 <script language='JavaScript'>
48 function CheckCreate(f)
50 if (f.username.value == "")
52 alert("You must supply a username");
55 if (f.passwd.value == "")
57 alert("You must supply a password");
60 if (f.passwd.value != f.pwverify.value)
62 alert("Passwords don't match");
68 function CheckRemove(f)
70 var message = "Are you sure you want to remove user ";
71 message += f.username.value;
74 return confirm(message);
82 class user_page extends page
87 echo "<h1>User Administration</h1><hr>";
89 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['username']))
91 pg_exec($this->database, "CREATE USER " . $_POST['username'] . " PASSWORD '"
92 . $_POST['passwd'] . "'");
93 pg_exec($this->database, "INSERT INTO usr (username, security_level) VALUES ('"
94 . $_POST['username'] . "','" . $_POST['seclevel'] . "')");
97 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['username']))
99 pg_exec($this->database, "DELETE FROM usr WHERE username='" . $_POST['username'] . "'");
100 pg_exec($this->database, "DROP USER " . $_POST['username']);
103 $res = pg_exec($this->database, "SELECT username, security_level FROM usr");
107 while ($usr < pg_numrows($res))
109 $u = pg_fetch_object($res, $usr);
111 <tr><td align='center'><img src='user.png'><br>
112 <b><?php echo $u->username ?></b>
114 Sec. Level <?php echo $u->security_level ?>
116 <?php if ($_SESSION['username'] != $u->username)
119 <form action='users.php' method='post' onSubmit='return CheckRemove(this)'>
120 <input type='hidden' name='username' value='<?php echo $u->username ?>'>
121 <input type='submit' name='action' value='Remove'>
134 <h2>Create new user:</h2>
137 <form action='users.php' method='post' onSubmit='return CheckCreate(this)'>
138 User name: <input name='username' type='text'>
139 Security level: <select name='seclevel'>
140 <option value='1'>1</option>
141 <option value='2'>2</option>
142 <option value='3'>3</option>
143 <option value='4'>4</option>
144 <option value='5'>5</option>
147 Password: <input type='password' name='passwd'>
148 Verify password: <input type='password' name='pwverify'>
150 <input type='submit' name='action' value='Create'>
158 $page = new user_page("Gnucomo User Administration");