forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_user_handler.php
More file actions
137 lines (125 loc) · 4.7 KB
/
edit_user_handler.php
File metadata and controls
137 lines (125 loc) · 4.7 KB
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
<?php // $Id: edit_user_handler.php,v 1.54.2.1 2012/02/28 15:43:10 cknudsen Exp $
// There is the potential for a lot of mischief from users trying to access this
// file in ways they shouldn't. Users may try to type in a URL to get around
// functions that are not being displayed on the web page to them.
include_once 'includes/init.php';
require_valid_referring_url ();
load_user_layers();
$referer = '';
if ( ! empty ( $_SERVER['HTTP_REFERER']) ) {
$refurl = parse_url($_SERVER['HTTP_REFERER']);
if (!empty($refurl['path']))
$referer = strrchr($refurl['path'], '/edit_user.php' );
}
if ( $referer != '/edit_user.php' ) {
activity_log( 0, $login, $login, SECURITY_VIOLATION, 'Hijack attempt:edit_user' );
exit;
}
$delete = getPostValue ( 'delete' );
$formtype = getPostValue ( 'formtype' );
$add = getPostValue ( 'add' );
$user = getPostValue ( 'user' );
$ufirstname = getPostValue ( 'ufirstname' );
$ulastname = getPostValue ( 'ulastname' );
$uemail = getPostValue ( 'uemail' );
$upassword1 = getPostValue ( 'upassword1' );
$upassword2 = getPostValue ( 'upassword2' );
$uis_admin = getPostValue ( 'uis_admin' );
$uenabled = getPostValue ( 'u_enabled' );
$error = '';
if ( ! $is_admin )
$user = $login;
$notAuthStr = print_not_auth();
$deleteStr = translate ( 'Deleting users not supported.' );
$notIdenticalStr = translate ( 'The passwords were not identical.' );
$noPasswordStr = translate ( 'You have not entered a password.' );
$blankUserStr = translate ( 'Username cannot be blank.' );
// Don't let them edit users if they'e not authorized.
if ( empty ( $user ) ) {
// Asking to create a new user. Must be admin...
if ( ! $is_admin && ! access_can_access_function ( ACCESS_USER_MANAGEMENT ) )
send_to_preferred_view();
if ( ! $admin_can_add_user ) {
// If adding users is not allowed...
send_to_preferred_view();
exit;
}
} else {
// User is editing their account info.
if ( ! access_can_access_function ( ACCESS_ACCOUNT_INFO ) )
send_to_preferred_view();
}
// Handle delete.
if ( ! empty ( $delete ) && $formtype == 'edituser' ) {
if ( access_can_access_function ( ACCESS_USER_MANAGEMENT ) ) {
if ( $admin_can_delete_user ) {
user_delete_user ( $user ); // Will also delete user's events.
activity_log ( 0, $login, $user, LOG_USER_DELETE, '' );
} else
$error = $deleteStr;
} else
$error = $notAuthStr;
} else {
// Handle update of password.
if ( $formtype == 'setpassword' && strlen ( $user ) ) {
if ( ! access_can_access_function ( ACCESS_USER_MANAGEMENT ) && !
access_can_access_function ( ACCESS_ACCOUNT_INFO ) )
$error = $notAuthStr;
else
if ( $upassword1 != $upassword2 )
$error = $notIdenticalStr;
else {
if ( strlen ( $upassword1 ) ) {
if ( $user_can_update_password ) {
user_update_user_password ( $user, $upassword1 );
activity_log ( 0, $login, $user, LOG_USER_UPDATE,
translate ( 'Set Password' ) );
} else
$error = $notAuthStr;
} else
$error = $noPasswordStr;
}
} else {
// Handle update of user info.
if ( $formtype == 'edituser' ) {
if ( ! empty ( $add ) && $is_admin ) {
if ( $upassword1 != $upassword2 )
$error = $notIdenticalStr;
else {
if ( addslashes ( $user ) != $user )
// This error should get caught before here anyhow,
// so no need to translate this. This is just in case. :-)
$error = 'Invalid characters in login.';
else {
if ( empty ( $user ) )
// Username cannot be blank. This is currently the only place
// that calls addUser that is located in $user_inc.
$error = $blankUserStr;
else {
user_add_user ( $user, $upassword1, $ufirstname, $ulastname,
$uemail, $uis_admin, $uenabled );
activity_log ( 0, $login, $user, LOG_USER_ADD,
"$ufirstname $ulastname"
. ( empty ( $uemail ) ? '' : " <$uemail>" ) );
}
}
}
} else {
if ( ! empty ( $add ) && !
access_can_access_function ( ACCESS_USER_MANAGEMENT ) )
$error = $notAuthStr;
else {
// Don't allow a user to change themself to an admin by setting
// uis_admin in the URL by hand. They must be admin beforehand.
if ( ! $is_admin )
$uis_admin = 'N';
user_update_user ( $user, $ufirstname, $ulastname, $uemail, $uis_admin, $uenabled );
activity_log ( 0, $login, $user, LOG_USER_UPDATE,
"$ufirstname $ulastname" . ( empty ( $uemail ) ? '' : " <$uemail>" ) );
}
}
}
}
}
echo error_check ( 'users.php', false );
?>