1 |
1347
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package users
|
6 |
1710
|
Luisehahne
|
* @author Ryan Djurovich, WebsiteBaker Project
|
7 |
|
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8 |
1347
|
Luisehahne
|
* @link http://www.websitebaker2.org/
|
9 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
10 |
|
|
* @platform WebsiteBaker 2.8.x
|
11 |
1374
|
Luisehahne
|
* @requirements PHP 5.2.2 and higher
|
12 |
1347
|
Luisehahne
|
* @version $Id$
|
13 |
|
|
* @filesource $HeadURL$
|
14 |
|
|
* @lastmodified $Date$
|
15 |
|
|
*
|
16 |
|
|
*/
|
17 |
|
|
|
18 |
1815
|
Luisehahne
|
/* -------------------------------------------------------- */
|
19 |
|
|
// Must include code to stop this file being accessed directly
|
20 |
|
|
if(!defined('WB_URL')) {
|
21 |
|
|
require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
|
22 |
|
|
throw new IllegalFileException();
|
23 |
1804
|
Luisehahne
|
}
|
24 |
1815
|
Luisehahne
|
/* -------------------------------------------------------- */
|
25 |
1804
|
Luisehahne
|
|
26 |
1815
|
Luisehahne
|
function save_user($admin, &$aActionRequest)
|
27 |
|
|
{
|
28 |
|
|
// Create a javascript back link
|
29 |
|
|
// $js_back = ADMIN_URL.'/users/index.php';
|
30 |
|
|
unset($aActionRequest['save']);
|
31 |
1823
|
Luisehahne
|
|
32 |
1815
|
Luisehahne
|
$aActionRequest['modify']= 'change';
|
33 |
|
|
$database = WbDatabase::getInstance();
|
34 |
2065
|
Luisehahne
|
$mLang = Translate::getInstance();
|
35 |
1815
|
Luisehahne
|
$bRetVal = 0;
|
36 |
|
|
$iMinPassLength = 6;
|
37 |
1804
|
Luisehahne
|
|
38 |
1815
|
Luisehahne
|
if( !$admin->checkFTAN() )
|
39 |
|
|
{
|
40 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_GENERIC_SECURITY_ACCESS);
|
41 |
1815
|
Luisehahne
|
return $bRetVal;
|
42 |
|
|
}
|
43 |
1347
|
Luisehahne
|
|
44 |
1815
|
Luisehahne
|
// Check if user id is a valid number and doesnt equal 1
|
45 |
|
|
if(!isset($aActionRequest['user_id']) OR !is_numeric($aActionRequest['user_id']) OR $aActionRequest['user_id'] == 1) {
|
46 |
2065
|
Luisehahne
|
msgQueue::add('::'.$mLang->MESSAGE_GENERIC_NOT_UPGRADED);
|
47 |
1815
|
Luisehahne
|
return $bRetVal;
|
48 |
|
|
} else {
|
49 |
|
|
$user_id = intval($aActionRequest['user_id']);
|
50 |
|
|
}
|
51 |
1425
|
Luisehahne
|
|
52 |
1815
|
Luisehahne
|
if( ($user_id < 2 ) )
|
53 |
|
|
{
|
54 |
|
|
// if($admin_header) { $admin->print_header(); }
|
55 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_GENERIC_SECURITY_OFFENSE);
|
56 |
1815
|
Luisehahne
|
return $bRetVal;
|
57 |
|
|
}
|
58 |
|
|
// Get existing values
|
59 |
|
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'users` ' ;
|
60 |
|
|
$sql .= 'WHERE user_id = '.$user_id.' ';
|
61 |
|
|
$sql .= 'AND user_id != 1 ';
|
62 |
1347
|
Luisehahne
|
|
63 |
1815
|
Luisehahne
|
if($oRes = $database->query($sql)){
|
64 |
|
|
$olduser = $oRes->fetchRow(MYSQL_ASSOC);
|
65 |
|
|
}
|
66 |
1347
|
Luisehahne
|
|
67 |
1815
|
Luisehahne
|
// Gather details entered
|
68 |
|
|
if($admin->is_group_match($admin->get_groups_id(), '1' )){
|
69 |
|
|
$groups_id = (isset($aActionRequest['groups'])) ? implode(",", $admin->add_slashes($aActionRequest['groups'])) : '';
|
70 |
|
|
} else {
|
71 |
|
|
$groups_id = $olduser['group_id'];
|
72 |
|
|
}
|
73 |
|
|
// there will be an additional ',' when "Please Choose" was selected, too
|
74 |
|
|
$groups_id = trim($groups_id, ',');
|
75 |
|
|
$active = intval(strip_tags($admin->StripCodeFromText($aActionRequest['active'][0])));
|
76 |
|
|
$username_fieldname = strip_tags($admin->StripCodeFromText($aActionRequest['username_fieldname']));
|
77 |
|
|
$username = strtolower(strip_tags($admin->StripCodeFromText($aActionRequest[$username_fieldname])));
|
78 |
|
|
$password = strip_tags($admin->StripCodeFromText($aActionRequest['password']));
|
79 |
|
|
$password2 = strip_tags($admin->StripCodeFromText($aActionRequest['password2']));
|
80 |
|
|
$display_name = strip_tags($admin->StripCodeFromText($aActionRequest['display_name']));
|
81 |
|
|
$email = strip_tags($admin->StripCodeFromText($aActionRequest['email']));
|
82 |
|
|
$home_folder = strip_tags($admin->StripCodeFromText($aActionRequest['home_folder']));
|
83 |
1347
|
Luisehahne
|
|
84 |
1815
|
Luisehahne
|
// Check values
|
85 |
|
|
if($groups_id == "") {
|
86 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_NO_GROUP);
|
87 |
1815
|
Luisehahne
|
} else {
|
88 |
|
|
$aGroups_id = explode(',', $groups_id);
|
89 |
|
|
//if user is in administrator-group, get this group else just get the first one
|
90 |
|
|
if($admin->is_group_match($groups_id,'1')) { $group_id = 1; } else { $group_id = intval($aGroups_id[0]); }
|
91 |
|
|
}
|
92 |
1710
|
Luisehahne
|
|
93 |
1815
|
Luisehahne
|
//$admin->is_group_match($admin->get_groups_id(), '1' )
|
94 |
|
|
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username))
|
95 |
|
|
{
|
96 |
2065
|
Luisehahne
|
msgQueue::add( $mLang->MESSAGE_USERS_NAME_INVALID_CHARS);
|
97 |
1815
|
Luisehahne
|
}
|
98 |
1347
|
Luisehahne
|
|
99 |
1815
|
Luisehahne
|
if($password != "") {
|
100 |
|
|
if(strlen($password) < $iMinPassLength ) {
|
101 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE['USERS_PASSWORD_TOO_SHORT']);
|
102 |
1815
|
Luisehahne
|
}
|
103 |
1347
|
Luisehahne
|
|
104 |
1815
|
Luisehahne
|
$pattern = '/[^'.$admin->password_chars.']/';
|
105 |
|
|
if (preg_match($pattern, $password)) {
|
106 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_PREFERENCES_INVALID_CHARS);
|
107 |
1815
|
Luisehahne
|
}
|
108 |
1347
|
Luisehahne
|
|
109 |
1815
|
Luisehahne
|
if(($password != $password2) ) {
|
110 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_PASSWORD_MISMATCH);
|
111 |
1815
|
Luisehahne
|
}
|
112 |
|
|
}
|
113 |
|
|
// check that display_name is unique in whoole system (prevents from User-faking)
|
114 |
|
|
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` ';
|
115 |
|
|
$sql .= 'WHERE `user_id` <> '.(int)$user_id.' AND `display_name` LIKE "'.$display_name.'"';
|
116 |
|
|
if( $database->get_one($sql) > 0 ){
|
117 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_USERNAME_TAKEN.' ('.$mLang->TEXT_DISPLAY_NAME.')');
|
118 |
|
|
msgQueue::add($mLang->MESSAGE_MEDIA_CANNOT_RENAME);
|
119 |
1815
|
Luisehahne
|
}
|
120 |
|
|
//
|
121 |
|
|
if( ($admin->get_user_id() != '1' ) )
|
122 |
|
|
{
|
123 |
|
|
if(findStringInFileList($display_name, dirname(__FILE__).'/disallowedNames')) {
|
124 |
2065
|
Luisehahne
|
msgQueue::add( $mLang->TEXT_ERROR.' '.$mLang->TEXT_DISPLAY_NAME.' ('.$display_name.')' );
|
125 |
1815
|
Luisehahne
|
}
|
126 |
|
|
}
|
127 |
1347
|
Luisehahne
|
|
128 |
1815
|
Luisehahne
|
$display_name = ( $display_name == '' ? $olduser['display_name'] : $display_name );
|
129 |
1347
|
Luisehahne
|
|
130 |
1815
|
Luisehahne
|
if($email != "")
|
131 |
|
|
{
|
132 |
|
|
if($admin->validate_email($email) == false)
|
133 |
|
|
{
|
134 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_INVALID_EMAIL.' ('.$email.')');
|
135 |
1815
|
Luisehahne
|
}
|
136 |
|
|
} else { // e-mail must be present
|
137 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_SIGNUP_NO_EMAIL);
|
138 |
1815
|
Luisehahne
|
}
|
139 |
|
|
|
140 |
|
|
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` '.
|
141 |
|
|
'WHERE `email` LIKE \''.$email.'\' '.
|
142 |
|
|
'AND `user_id` <> '.(int)$user_id;
|
143 |
|
|
// Check if the email already exists
|
144 |
|
|
if( ($iFoundUser = $database->get_one($sql)) != null ) {
|
145 |
|
|
if($iFoundUser) {
|
146 |
2065
|
Luisehahne
|
if(isset($mLang->MESSAGE_USERS_EMAIL_TAKEN))
|
147 |
1815
|
Luisehahne
|
{
|
148 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_EMAIL_TAKEN.' ('.$email.')');
|
149 |
1815
|
Luisehahne
|
} else {
|
150 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_INVALID_EMAIL.' ('.$email.')');
|
151 |
1815
|
Luisehahne
|
}
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
$bRetVal = $user_id;
|
156 |
|
|
|
157 |
|
|
// no error then save
|
158 |
|
|
if( !msgQueue::getError() )
|
159 |
|
|
{
|
160 |
|
|
if($admin->is_group_match($groups_id,'1')) { $group_id = 1; $groups_id = '1'; }
|
161 |
|
|
// Prevent from renaming user to "admin"
|
162 |
|
|
if($username != 'admin') {
|
163 |
|
|
$username_code = ", username = '$username'";
|
164 |
|
|
} else {
|
165 |
|
|
$username_code = '';
|
166 |
|
|
}
|
167 |
|
|
|
168 |
1823
|
Luisehahne
|
if(defined('HOME_FOLDERS') && HOME_FOLDERS) {
|
169 |
1818
|
Luisehahne
|
|
170 |
1823
|
Luisehahne
|
// Include the WB functions file
|
171 |
|
|
if(!function_exists('media_filename')) { require(WB_PATH.'/framework/functions.php'); }
|
172 |
|
|
|
173 |
|
|
// Remove bad characters
|
174 |
|
|
$sHomeFolder = WB_PATH.MEDIA_DIRECTORY.'/home/'.( media_filename($username) );
|
175 |
|
|
if ( sizeof(createFolderProtectFile( $sHomeFolder )) )
|
176 |
|
|
{
|
177 |
2065
|
Luisehahne
|
// msgQueue::add($mLang->MESSAGE_MEDIA_DIR_NOT_MADE);
|
178 |
1823
|
Luisehahne
|
}
|
179 |
1818
|
Luisehahne
|
}
|
180 |
|
|
|
181 |
1815
|
Luisehahne
|
$sql = 'UPDATE `'.TABLE_PREFIX.'users` SET ';
|
182 |
|
|
// Update the database
|
183 |
|
|
if($password == "") {
|
184 |
|
|
$sql .= '`group_id` = '.intval($group_id).', '.
|
185 |
1868
|
Luisehahne
|
'`groups_id` = \''.$database->escapeString($groups_id).'\', '.
|
186 |
|
|
'`username` = \''.$database->escapeString($username).'\', '.
|
187 |
1815
|
Luisehahne
|
'`active` = '.intval($active).', '.
|
188 |
1868
|
Luisehahne
|
'`display_name` = \''.$database->escapeString($display_name).'\', '.
|
189 |
|
|
'`home_folder` = \''.$database->escapeString($home_folder).'\', '.
|
190 |
|
|
'`email` = \''.$database->escapeString($email).'\' '.
|
191 |
1815
|
Luisehahne
|
'WHERE `user_id` = '.intval($user_id).'';
|
192 |
|
|
|
193 |
|
|
} else {
|
194 |
|
|
|
195 |
|
|
$sql .= '`group_id` = '.intval($group_id).', '.
|
196 |
1868
|
Luisehahne
|
'`groups_id` = \''.$database->escapeString($groups_id).'\', '.
|
197 |
|
|
'`username` = \''.$database->escapeString($username).'\', '.
|
198 |
1815
|
Luisehahne
|
'`password` = \''.md5($password).'\', '.
|
199 |
|
|
'`active` = '.intval($active).', '.
|
200 |
1868
|
Luisehahne
|
'`display_name` = \''.$database->escapeString($display_name).'\', '.
|
201 |
|
|
'`home_folder` = \''.$database->escapeString($home_folder).'\', '.
|
202 |
|
|
'`email` = \''.$database->escapeString($email).'\' '.
|
203 |
1815
|
Luisehahne
|
'WHERE `user_id` = '.intval($user_id).'';
|
204 |
|
|
|
205 |
|
|
}
|
206 |
|
|
if($database->query($sql)) {
|
207 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_SAVED, true);
|
208 |
1815
|
Luisehahne
|
$bRetVal = $user_id;
|
209 |
|
|
}
|
210 |
|
|
if($database->is_error()) {
|
211 |
|
|
msgQueue::add( implode('<br />',explode(';',$database->get_error())) );
|
212 |
|
|
}
|
213 |
|
|
} else {
|
214 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_GENERIC_NOT_UPGRADED);
|
215 |
1815
|
Luisehahne
|
}
|
216 |
|
|
|
217 |
|
|
// return $admin->getIDKEY($user_id);
|
218 |
|
|
//if($admin_header) { $admin->print_header(); }
|
219 |
|
|
return $bRetVal;
|
220 |
|
|
}
|