1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
$Id: system_usermanager.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2005 Paul Taylor <paultaylor@winn-dixie.com>.
|
8
|
All rights reserved.
|
9
|
|
10
|
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
11
|
All rights reserved.
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
2. Redistributions in binary form must reproduce the above copyright
|
20
|
notice, this list of conditions and the following disclaimer in the
|
21
|
documentation and/or other materials provided with the distribution.
|
22
|
|
23
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
POSSIBILITY OF SUCH DAMAGE.
|
33
|
*/
|
34
|
|
35
|
require("guiconfig.inc");
|
36
|
|
37
|
// The page title for non-admins
|
38
|
$pgtitle = array("System", "User password");
|
39
|
|
40
|
if ($_SERVER['REMOTE_USER'] === $config['system']['username']) {
|
41
|
|
42
|
// Page title for main admin
|
43
|
$pgtitle = array("System", "User manager");
|
44
|
|
45
|
$id = $_GET['id'];
|
46
|
if (isset($_POST['id']))
|
47
|
$id = $_POST['id'];
|
48
|
|
49
|
if (!is_array($config['system']['user'])) {
|
50
|
$config['system']['user'] = array();
|
51
|
}
|
52
|
admin_users_sort();
|
53
|
$a_user = &$config['system']['user'];
|
54
|
|
55
|
if ($_GET['act'] == "del") {
|
56
|
if ($a_user[$_GET['id']]) {
|
57
|
$userdeleted = $a_user[$_GET['id']]['name'];
|
58
|
unset($a_user[$_GET['id']]);
|
59
|
write_config();
|
60
|
$retval = system_password_configure();
|
61
|
$savemsg = get_std_save_message($retval);
|
62
|
$savemsg = "User ".$userdeleted." successfully deleted<br>";
|
63
|
}
|
64
|
}
|
65
|
|
66
|
if ($_POST) {
|
67
|
|
68
|
unset($input_errors);
|
69
|
$pconfig = $_POST;
|
70
|
|
71
|
/* input validation */
|
72
|
if (isset($id) && ($a_user[$id])) {
|
73
|
$reqdfields = explode(" ", "username");
|
74
|
$reqdfieldsn = explode(",", "Username");
|
75
|
} else {
|
76
|
$reqdfields = explode(" ", "username password");
|
77
|
$reqdfieldsn = explode(",", "Username,Password");
|
78
|
}
|
79
|
|
80
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
81
|
|
82
|
if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['username']))
|
83
|
$input_errors[] = "The username contains invalid characters.";
|
84
|
|
85
|
if($_POST['username']==$config['system']['username']) {
|
86
|
$input_errors[] = "username can not match the administrator username!";
|
87
|
}
|
88
|
|
89
|
if (($_POST['password']) && ($_POST['password'] != $_POST['password2']))
|
90
|
$input_errors[] = "The passwords do not match.";
|
91
|
|
92
|
if (!$input_errors && !(isset($id) && $a_user[$id])) {
|
93
|
/* make sure there are no dupes */
|
94
|
foreach ($a_user as $userent) {
|
95
|
if ($userent['name'] == $_POST['username']) {
|
96
|
$input_errors[] = "Another entry with the same username already exists.";
|
97
|
break;
|
98
|
}
|
99
|
}
|
100
|
}
|
101
|
|
102
|
if(!isset($groupindex[$_POST['groupname']])) {
|
103
|
$input_errors[] = "group does not exist, please define the group before assigning users.";
|
104
|
}
|
105
|
|
106
|
if (!$input_errors) {
|
107
|
|
108
|
if (isset($id) && $a_user[$id])
|
109
|
$userent = $a_user[$id];
|
110
|
|
111
|
$userent['name'] = $_POST['username'];
|
112
|
$userent['fullname'] = $_POST['fullname'];
|
113
|
$userent['groupname'] = $_POST['groupname'];
|
114
|
|
115
|
if ($_POST['password'])
|
116
|
$userent['password'] = crypt($_POST['password']);
|
117
|
|
118
|
if (isset($id) && $a_user[$id])
|
119
|
$a_user[$id] = $userent;
|
120
|
else
|
121
|
$a_user[] = $userent;
|
122
|
|
123
|
write_config();
|
124
|
$retval = system_password_configure();
|
125
|
$savemsg = get_std_save_message($retval);
|
126
|
|
127
|
header("Location: system_usermanager.php");
|
128
|
}
|
129
|
}
|
130
|
|
131
|
include("head.inc");
|
132
|
|
133
|
?>
|
134
|
<?php include("fbegin.inc"); ?>
|
135
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
136
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
137
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
138
|
<tr><td class="tabnavtbl">
|
139
|
<ul id="tabnav">
|
140
|
<?php
|
141
|
$tab_array = array();
|
142
|
$tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
|
143
|
$tab_array[] = array(gettext("Group"), false, "system_groupmanager.php");
|
144
|
$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
|
145
|
display_top_tabs($tab_array);
|
146
|
?>
|
147
|
</ul>
|
148
|
</td></tr>
|
149
|
<tr>
|
150
|
<td class="tabcont">
|
151
|
<?php
|
152
|
if($_GET['act']=="new" || $_GET['act']=="edit" || $input_errors){
|
153
|
if($_GET['act']=="edit"){
|
154
|
if (isset($id) && $a_user[$id]) {
|
155
|
$pconfig['username'] = $a_user[$id]['name'];
|
156
|
$pconfig['fullname'] = $a_user[$id]['fullname'];
|
157
|
$pconfig['groupname'] = $a_group[$id]['groupname'];
|
158
|
}
|
159
|
}
|
160
|
?>
|
161
|
<form action="system_usermanager.php" method="post" name="iform" id="iform">
|
162
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
163
|
<tr>
|
164
|
<td width="22%" valign="top" class="vncellreq">Username</td>
|
165
|
<td width="78%" class="vtable">
|
166
|
<input name="username" type="text" class="formfld" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
|
167
|
</td>
|
168
|
</tr>
|
169
|
<tr>
|
170
|
<td width="22%" valign="top" class="vncellreq">Password</td>
|
171
|
<td width="78%" class="vtable">
|
172
|
<input name="password" type="password" class="formfld" id="password" size="20" value=""> <br>
|
173
|
<input name="password2" type="password" class="formfld" id="password2" size="20" value="">
|
174
|
(confirmation) </td>
|
175
|
</tr>
|
176
|
<tr>
|
177
|
<td width="22%" valign="top" class="vncell">Full name</td>
|
178
|
<td width="78%" class="vtable">
|
179
|
<input name="fullname" type="text" class="formfld" id="fullname" size="20" value="<?=htmlspecialchars($pconfig['fullname']);?>">
|
180
|
<br>
|
181
|
User's full name, for your own information only</td>
|
182
|
</tr>
|
183
|
<tr>
|
184
|
<td width="22%" valign="top" class="vncell">Group Name</td>
|
185
|
<td width="78%" class="vtable">
|
186
|
<select name="groupname" class="formfld" id="groupname">
|
187
|
<?php foreach ($config['system']['group'] as $group): ?>
|
188
|
<option value="<?=$group['name'];?>" <?php if ($group['name'] == $pconfig['groupname']) echo "selected"; ?>>
|
189
|
<?=htmlspecialchars($group['name']);?>
|
190
|
</option>
|
191
|
<?php endforeach; ?>
|
192
|
</select>
|
193
|
<br>
|
194
|
The admin group to which this user is assigned.</td>
|
195
|
</tr>
|
196
|
<tr>
|
197
|
<td width="22%" valign="top"> </td>
|
198
|
<td width="78%">
|
199
|
<input name="save" type="submit" class="formbtn" value="Save">
|
200
|
<?php if (isset($id) && $a_user[$id]): ?>
|
201
|
<input name="id" type="hidden" value="<?=$id;?>">
|
202
|
<?php endif; ?>
|
203
|
</td>
|
204
|
</tr>
|
205
|
</table>
|
206
|
</form>
|
207
|
<?php
|
208
|
} else {
|
209
|
?>
|
210
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
211
|
<tr>
|
212
|
<td width="35%" class="listhdrr">Username</td>
|
213
|
<td width="20%" class="listhdrr">Full name</td>
|
214
|
<td width="20%" class="listhdrr">Group</td>
|
215
|
<td width="10%" class="list"></td>
|
216
|
</tr>
|
217
|
<?php $i = 0; foreach($a_user as $userent): ?>
|
218
|
<tr>
|
219
|
<td class="listlr">
|
220
|
<?=htmlspecialchars($userent['name']); ?>
|
221
|
</td>
|
222
|
<td class="listr">
|
223
|
<?=htmlspecialchars($userent['fullname']);?>
|
224
|
</td>
|
225
|
<td class="listbg">
|
226
|
<?=htmlspecialchars($userent['groupname']); ?>
|
227
|
</td>
|
228
|
<td valign="middle" nowrap class="list"> <a href="system_usermanager.php?act=edit&id=<?=$i; ?>"><img src="e.gif" title="edit user" width="17" height="17" border="0"></a>
|
229
|
<a href="system_usermanager.php?act=del&id=<?=$i; ?>" onclick="return confirm('Do you really want to delete this User?')"><img src="x.gif" title="delete user" width="17" height="17" border="0"></a></td>
|
230
|
</tr>
|
231
|
<?php $i++; endforeach; ?>
|
232
|
<tr>
|
233
|
<td class="list" colspan="3"></td>
|
234
|
<td class="list"> <a href="system_usermanager.php?act=new"><img src="plus.gif" title="add user" width="17" height="17" border="0"></a></td>
|
235
|
</tr>
|
236
|
<tr>
|
237
|
<td colspan="3">
|
238
|
Additional webGUI users can be added here. User permissions are determined by the admin group they are a member of.
|
239
|
</td>
|
240
|
</tr>
|
241
|
</table>
|
242
|
<?php } ?>
|
243
|
|
244
|
</td>
|
245
|
</tr>
|
246
|
</table>
|
247
|
<?php
|
248
|
} else { // end of admin user code, start of normal user code
|
249
|
if (isset($_POST['save'])) {
|
250
|
|
251
|
unset($input_errors);
|
252
|
|
253
|
/* input validation */
|
254
|
$reqdfields = explode(" ", "password");
|
255
|
$reqdfieldsn = explode(",", "Password");
|
256
|
|
257
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
258
|
|
259
|
if ($_POST['password'] != $_POST['password2'])
|
260
|
$input_errors[] = "The passwords do not match.";
|
261
|
|
262
|
if (!$input_errors) {
|
263
|
//all values are okay --> saving changes
|
264
|
$config['system']['user'][$userindex[$_SERVER['REMOTE_USER']]]['password']=crypt(trim($_POST['password']));
|
265
|
|
266
|
write_config();
|
267
|
$retval = system_password_configure();
|
268
|
$savemsg = get_std_save_message($retval);
|
269
|
$savemsg = "Password successfully changed<br>";
|
270
|
}
|
271
|
}
|
272
|
|
273
|
|
274
|
?>
|
275
|
<?php include("fbegin.inc"); ?>
|
276
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
277
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
278
|
<form action="system_usermanager.php" method="post" name="iform" id="iform">
|
279
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
280
|
<tr>
|
281
|
<td colspan="2" valign="top" class="listtopic"><?=$_SERVER['REMOTE_USER']?>'s Password</td>
|
282
|
</tr>
|
283
|
<tr>
|
284
|
<td width="22%" valign="top" class="vncell">Password</td>
|
285
|
<td width="78%" class="vtable"> <input name="password" type="password" class="formfld" id="password" size="20">
|
286
|
<br> <input name="password2" type="password" class="formfld" id="password2" size="20">
|
287
|
(confirmation) <br> <span class="vexpl">Select a new password</span></td>
|
288
|
</tr>
|
289
|
<tr>
|
290
|
<td width="22%" valign="top"> </td>
|
291
|
<td width="78%">
|
292
|
<input name="save" type="submit" class="formbtn" value="Save">
|
293
|
</td>
|
294
|
</tr>
|
295
|
</table>
|
296
|
</form>
|
297
|
|
298
|
<?php
|
299
|
} // end of normal user code ?>
|
300
|
<?php include("fend.inc"); ?>
|