-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig-users.php
366 lines (347 loc) · 15.4 KB
/
config-users.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<?php
$subsys = "admin";
require_once('session.inc');
require_once('db-open.php');
require_once('functions.php');
require_once('local-dls.php');
SessionErrorIfReadonly();
if (isset($DEBUG) && $DEBUG) {
foreach ($_POST as $key => $value) {
if ($key == 'password' || $key == 'password2') {
syslog(LOG_INFO, "\$_POST[$key] = (omitted)");
}
else {
syslog(LOG_INFO, "\$_POST[$key] = $value");
}
}
}
#
# Verify access level
#
if (!CheckAuthByLevel('edit_users', $_SESSION['access_level'])) {
syslog(LOG_WARNING, "User editing attempted without permissions by user ". $_SESSION['username'] ." level ". $_SESSION['access_level']);
echo "Access level insufficient for this operation.<br />\n";
echo "User: " . $_SESSION['username'] . "<br />\n";
echo "Level: " . $_SESSION['access_level'] . "<br />\n";
exit;
}
$check_password = 0;
$check_accesslevel = 0;
$check_accessacl = 0;
$check_timeout = 0;
$check_errormsg = "";
if (isset($_GET["delete"]) && $_GET["delete"]) {
$cleandelete = MysqlClean($_GET, "delete", 20);
$levelrow = MysqlQuery("SELECT username, access_level FROM $DB_NAME.users WHERE id='$cleandelete'");
$levelobj = mysql_fetch_object($levelrow);
$username = $levelobj->username;
if ($_SESSION['access_level'] < $levelobj->access_level ) {
syslog(LOG_WARNING, "User [".$_SESSION['username']."] (level ".$_SESSION["access_level"].") attempted to delete [$username] (level ".$levelobj->access_level.")!");
echo "ERROR: Cannot delete users with a higher access level than your own.";
exit;
}
else {
syslog(LOG_INFO, "User [$username] was deleted by [".$_SESSION['username']."]");
MysqlQuery("DELETE FROM $DB_NAME.users WHERE id='$cleandelete'");
header('Location: config-users.php?action=Deleted&username='.$username);
}
}
elseif (isset($_POST["edituser"]) && $_POST["edituser"]) {
#
# Submitted a user form to save - check validation.
#
if ($DEBUG) syslog (LOG_INFO, "entering post edituser");
if (!isset($_POST["password"]) || $_POST["password"]=='') {
if (isset($_POST['newuser']) && $_POST['newuser']) {
print "Must set password when adding new user.<br />\n";
print "<a href=\"config-users.php?adduser\">Return to form and try again</a><br>\n";
exit;
}
}
elseif ($_POST["password"] != $_POST["password2"])
{
$check_password = 1;
$check_errormsg .= "Passwords do not match.<br />";
}
if ($_POST["username"] == $_SESSION['username'])
{
$check_accesslevel = 1;
$check_errormsg .= "You cannot change your own access level.<br>";
}
if ($check_errormsg != "") {
# If we did not pass validation, continue to the GET edituser case, and flag corrections...
$_GET["edituserid"] = $_POST["id"];
}
else {
if ($DEBUG) syslog (LOG_INFO, "saving user");
# Save user and return to user listing
$cleanuser = MysqlClean($_POST, "username", 40);
$cleanid = MysqlClean($_POST, "id", 40);
$cleanname = MysqlClean($_POST, "name", 40);
$tainted_password = $_POST["password"];
$cleanaccesslevel = MysqlClean($_POST, "access_level", 10);
$cleanaccessacl = MysqlClean($_POST, "access_acl", 10);
$cleantimeout = MysqlClean($_POST, "timeout", 10);
$locked_out = (int)$_POST["locked_out"];
$change_password = (int)$_POST["change_password"];
# TODO: form values currently nullify the database default for numerical values
$levelrow = MysqlQuery("SELECT username, access_level FROM $DB_NAME.users WHERE id='$cleanid'");
$levelobj = mysql_fetch_object($levelrow);
$username = $levelobj->username;
$pwhash_query_frag = '';
$hash = '';
if ($tainted_password != '') {
$hash = $t_hasher->HashPassword($tainted_password);
$pwhash_query_frag = "password='$hash', ";
}
if ($_SESSION['access_level'] < $levelobj->access_level ) {
syslog(LOG_WARNING, "User [".$_SESSION['username']."] (level ".$_SESSION["access_level"].") attempted to modify [$username] (level ".$levelobj->access_level.")!");
echo "ERROR: Cannot modify users with a higher access level than your own.<br>";
exit;
#TODO: go back to editor rather than exit ignominiously
$check_errormsg .= "ERROR: Cannot modify users with a higher access level than your own.<br>";
}
elseif (isset($_POST["newuser"]) && $_POST['newuser']) {
if ($_SESSION['access_level'] < $cleanaccesslevel ) {
syslog(LOG_WARNING, "User [".$_SESSION['username']."] (level ".$_SESSION['access_level'].") attempted to add [$username] with greater access level $cleanaccesslevel!");
echo "ERROR: Cannot add users with a higher access level than your own.<br>";
#TODO: go back to editor rather than exit ignominiously
$check_errormsg .= "ERROR: Cannot add users with a higher access level than your own.<br>";
exit;
}
else {
syslog(LOG_INFO, "User [$cleanuser] was added by [".$_SESSION['username']."]");
MysqlQuery("INSERT INTO $DB_NAME.users (username, password, name, access_level, access_acl, timeout, locked_out, change_password) VALUES ('$cleanuser', '$hash', '$cleanname', '$cleanaccesslevel', '$cleanaccessacl', '$cleantimeout', $locked_out, $change_password)");
header('Location: config-users.php?moduser='.mysql_insert_id().'&action=Added');
exit;
}
}
elseif ($cleanid) {
syslog(LOG_INFO, "User [$cleanuser] was edited by [".$_SESSION['username']."]");
MysqlQuery("UPDATE $DB_NAME.users SET $pwhash_query_frag access_level='$cleanaccesslevel', access_acl='$cleanaccessacl', timeout='$cleantimeout', name='$cleanname', locked_out=$locked_out, change_password=$change_password WHERE id='$cleanid'");
header('Location: config-users.php?moduser='.$cleanid.'&action=Saved');
exit;
}
else {
#TODO: error
exit;
}
}
}
if (isset($_GET["edituserid"]) || isset($_GET["adduser"]) || $check_errormsg != "") {
#
# Loaded a user to edit (could have edited and come back to this screen)
#
if ($DEBUG) syslog (LOG_INFO, "Entering GET edituserid/GET adduser / checkerrmsg");
$user = array();
$user['access_level'] = 1;
$user['timeout'] = 300;
$user['name'] = '';
$user['username'] = '';
$user['name'] = '';
$user['name'] = '';
$user['name'] = '';
if ($_GET["edituserid"]) {
if ($DEBUG) syslog (LOG_INFO, "entering GET edituserid display");
$edituserid = MysqlClean($_GET, "edituserid", 20);
$oneuser = MysqlQuery("SELECT * FROM $DB_NAME.users WHERE id='$edituserid'");
if (mysql_num_rows($oneuser) != 1) {
syslog(LOG_CRITICAL, "Expected 1 row for config-users.php?edituserid=$edituserid -- got " . mysql_num_rows($oneuser));
echo "INTERNAL ERROR: bad number of rows (". mysql_num_rows($oneuser) . ") for user ID [$edituserid] (expected 1).<p>";
exit;
}
else {
$user = mysql_fetch_array($oneuser, MYSQL_ASSOC);
# TODO: if any new columns WERE accepted in previous form validation that set check_errormsg, recall and use the changed ones.
}
}
header_html("Dispatch :: Configuration :: Users");
?>
<body vlink="blue" link="blue" alink="cyan">
<?php include('include-title.php'); ?>
<p>
<span style='h1'><b>Editing User Values</b></span>
<form method="post" action="<?php print $_SERVER["PHP_SELF"]?>">
<table>
<tr>
<?php if (isset($_GET["adduser"])) { ?>
<td class="cell">New User Login name:</td>
<td><input size="20"0 type="text" name="username" onChange="this.style.backgroundColor='yellow'" />
<input type="hidden" name="newuser" value="1" />
<script language="javascript">document.forms[0].username.focus();</script></td>
<?php } else { ?>
<td class="cell">Editing User</td>
<td class="cell b">
<input type="hidden" name="id" value="<?php print $user['id']; ?>" />
<input type="hidden" name="username" value="<?php print $user['username'];?>" />
<?php print $user['username'] ?> </td>
<?php } ?>
</tr>
<tr><td><input type=hidden name="edituser" value="1"/> </td></tr>
</tr>
<tr><td class="cell">Full Name
<td><input type="text" size="40" name="name"
value="<?php print MysqlUnClean($user['name']);?>"
onChange="this.style.backgroundColor='yellow'" />
</td>
<?php if (!isset($_GET["adduser"])) {
echo "<script type=\"text/javascript\">document.forms[0].name.focus();</script>\n";
}?>
</tr>
<tr><td class="cell">Password
<td><input type="password" size="40" id="password_input" name="password"
value=""
onChange="this.style.backgroundColor='yellow'" />
<?php if ($check_password) echo "<font color=\"red\">*"; ?>
</td>
</tr>
<tr><td class="cell">Password (verify)
<td><input type="password" size="40" name="password2"
value=""
onChange="this.style.backgroundColor='yellow'" />
<?php if ($check_password) echo "<font color=\"red\">*"; ?>
</td>
</tr>
<tr><td class="cell">Access Level
<td><input type="text" size="10" name="access_level"
value="<?php print MysqlUnClean($user['access_level']);?>"
onChange="this.style.backgroundColor='yellow'" />
<?php if ($check_accesslevel) echo "<font color=\"red\">*"; ?>
<span class=text> (1 = normal user; 5 = supervisor; 9 = asst/dep/chief; 10 = system admin)</span>
</td>
</tr>
<tr><td class="cell">Access ACL
<td><input type="text" size="10" name="access_acl"
value="<?php print MysqlUnClean($user['access_acl']);?>"
onChange="this.style.backgroundColor='yellow'" />
<?php if ($check_accessacl) echo "<font color=\"red\">*"; ?>
</td>
</tr>
<tr><td class="cell">Timeout
<td><input type="text" size="10" name="timeout"
value="<?php print MysqlUnClean($user['timeout']);?>"
onChange="this.style.backgroundColor='yellow'" />
<?php if ($check_timeout) echo "<font color=\"red\">*"; ?>
</td>
</tr>
<tr><td class="cell">Password expired?
<td class="cell">Yes<input type="radio" id="change_password" name="change_password" value="1"
<?php if ($user['change_password']) print "checked";?> >
No<input type="radio" name="change_password" value="0"
<?php if (!$user['change_password']) print "checked";?> >
<span style="color:red; font-weight: bold" id="expireinstrs"></span>
</td>
</tr>
<tr><td class="cell">User locked out?
<td class="cell">Yes<input type="radio" name="locked_out" value="1"
<?php if ($user['locked_out']) print "checked";?> >
No<input type="radio" name="locked_out" value="0"
<?php if (!$user['locked_out']) print "checked";?>
onclick="
alert('Unlocking user: set their password to a temporary value now (will expire on next login).');
document.getElementById('unlockinstrs').innerHTML = 'Unlocked. Set a temporary password.';
document.getElementById('expireinstrs').innerHTML = 'Expired.';
document.forms[0].change_password[0].checked = true;
document.getElementById('password_input').focus();
document.getElementById('password_input').select();
">
<span style="color:red; font-weight: bold" id="unlockinstrs"></span>
</td>
</tr>
<?php if ($check_errormsg) {
?>
<tr><td colspan="2" style="font-weight: bold">Error: settings flagged above are invalid, reverting:</td> </tr>
<tr><td colspan="2" style="color: red"><?php print $check_errormsg;?></td></tr>
<?php }
?>
</table>
<input value="Save Changes" type="submit"><input value="Clear Changes" type="reset" />
<?php if (!isset($_GET["adduser"])) {
echo " <a class=button href=\"config-users.php?delete=".$user['id']."\">Delete This User</a><br>";
}?>
</form>
<p>
<p>
<a class=button href="config-users.php">Abort Changes, Go Back To Config::Users</a>
<a class=button href="admin.php">Abort Changes, Go Back To Config main menu</a>
</body>
</html>
<?php
exit;
}
else {
#
# Display list of users
#
$moduser = "";
$action = "";
if (isset($_GET["moduser"]) && $_GET["moduser"]) {
$moduser = $_GET["moduser"];
}
if (isset($_GET["action"]) && $_GET["action"]) {
$action = $_GET["action"];
}
header_html('Dispatch :: Configuration :: Users')
?>
<body vlink="blue" link="blue" alink="cyan">
<?php
include('include-title.php');
?>
<p>
<span style="h1"><b>User Administration</b></span><p>
<a class=button href="config-users.php?adduser">Add New User</a>
<a class=button href="admin.php">Back to Main Configuration Menu</a><p>
<table style="border: black solid 1px; background-color: gray" >
<tr>
<td class="th">Login</td>
<td class="th">Name</td>
<td class="th">Access Level</td>
<td class="th">Access ACL</td>
<td class="th">Timeout</td>
<td class="th">Password expired?</td>
<td class="th">Locked out?</td>
<td class="th">Failed logins</td>
<td class="th">Last login</td>
<?php if ($moduser) {
echo "<td class=\"th\">Status</td>\n";
}
?>
</tr>
<?php
$userlist = MysqlQuery("SELECT * FROM $DB_NAME.users ORDER BY username");
while ($user = mysql_fetch_object($userlist)) {
echo "<tr>\n";
echo " <td class=\"cell bgeee\"><a href=\"config-users.php?edituserid=$user->id\">" .
MysqlUnClean($user->username) . "</a></td>\n";
echo " <td class=\"cell bgeee\">" . MysqlUnClean($user->name) . "</td>\n";
echo " <td class=\"cell bgeee\">" . MysqlUnClean($user->access_level) . "</td>\n";
echo " <td class=\"cell bgeee\">" . MysqlUnClean($user->access_acl) . "</td>\n";
echo " <td class=\"cell bgeee\">" . MysqlUnClean($user->timeout) . "</td>\n";
if ($user->change_password) echo " <td class=\"cell bgeee green b\">Yes</td>\n";
else echo " <td class=\"cell bgeee fgray\">No</td>\n";
if ($user->locked_out) echo " <td class=\"cell bgred b\">Yes</td>\n";
else echo " <td class=\"cell bgeee fgray\">No</td>\n";
echo " <td class=\"cell bgeee\">" . MysqlUnClean($user->failed_login_count) . "</td>\n";
echo " <td class=\"cell bgeee\">" . dls_utime($user->last_login_time) . "</td>\n";
if ($moduser) {
if ($moduser == $user->id) {
echo " <td class=\"notice\">$action user.</td>\n";
}
else {
echo " <td class=\"cell bgeee\"> </td>\n";
}
}
echo "</tr>";
}
if ($action == "Deleted") {
echo "<tr>";
echo " <td colspan=\"100%\" class=\"notice\">Deleted user '".$_GET["username"]."'.</td></tr>";
}
?>
</table>
<p>
<a class=button href="config-users.php?adduser">Add New User</a>
<a class=button href="admin.php">Back to Main Configuration Menu</a>
<?php
}
echo "</body>\n</html>\n";