1 |
1475
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* @category admin
|
5 |
|
|
* @package users
|
6 |
1529
|
Luisehahne
|
* @author Ryan Djurovich, WebsiteBaker Project
|
7 |
1475
|
Luisehahne
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
8 |
|
|
* @link http://www.websitebaker2.org/
|
9 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
10 |
|
|
* @platform WebsiteBaker 2.8.x
|
11 |
|
|
* @requirements PHP 5.2.2 and higher
|
12 |
|
|
* @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 |
|
|
}
|
24 |
|
|
/* -------------------------------------------------------- */
|
25 |
1475
|
Luisehahne
|
|
26 |
1815
|
Luisehahne
|
function add_user($admin, &$aActionRequest)
|
27 |
|
|
{
|
28 |
|
|
$database = WbDatabase::getInstance();
|
29 |
2065
|
Luisehahne
|
$mLang = Translate::getInstance();
|
30 |
1815
|
Luisehahne
|
$bRetVal = false;
|
31 |
|
|
$iMinPassLength = 6;
|
32 |
1475
|
Luisehahne
|
|
33 |
1815
|
Luisehahne
|
if( !$admin->checkFTAN() )
|
34 |
|
|
{
|
35 |
|
|
// $admin->print_header();
|
36 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_GENERIC_SECURITY_ACCESS);
|
37 |
1815
|
Luisehahne
|
return $bRetVal;
|
38 |
|
|
}
|
39 |
1475
|
Luisehahne
|
|
40 |
1815
|
Luisehahne
|
// Get details entered
|
41 |
|
|
$groups_id = (isset($aActionRequest['groups'])) ? implode(",", $admin->add_slashes($aActionRequest['groups'])) : '';
|
42 |
|
|
$groups_id = trim($groups_id, ','); // there will be an additional ',' when "Please Choose" was selected, too
|
43 |
|
|
$active = intval(strip_tags($admin->StripCodeFromText($aActionRequest['active'][0])));
|
44 |
|
|
$username_fieldname = strip_tags($admin->StripCodeFromText($aActionRequest['username_fieldname']));
|
45 |
|
|
$username = strtolower(strip_tags($admin->StripCodeFromText($aActionRequest[$username_fieldname])));
|
46 |
|
|
$password = strip_tags($admin->StripCodeFromText($aActionRequest['password']));
|
47 |
|
|
$password2 = strip_tags($admin->StripCodeFromText($aActionRequest['password2']));
|
48 |
|
|
$display_name = strip_tags($admin->StripCodeFromText($aActionRequest['display_name']));
|
49 |
|
|
$email = strip_tags($admin->StripCodeFromText($aActionRequest['email']));
|
50 |
|
|
$home_folder = strip_tags($admin->StripCodeFromText($aActionRequest['home_folder']));
|
51 |
1475
|
Luisehahne
|
|
52 |
1815
|
Luisehahne
|
$language = DEFAULT_LANGUAGE;
|
53 |
|
|
$timezone = -72000;
|
54 |
|
|
$date_format = DEFAULT_DATE_FORMAT;
|
55 |
|
|
$time_format = DEFAULT_TIME_FORMAT;
|
56 |
|
|
$confirm_code = '';
|
57 |
|
|
$confirm_timeout = 0;
|
58 |
|
|
$remember_key = '';
|
59 |
|
|
$login_ip = '';
|
60 |
|
|
$last_reset = 0;
|
61 |
|
|
$login_when = 0;
|
62 |
1475
|
Luisehahne
|
|
63 |
1815
|
Luisehahne
|
// Check values
|
64 |
|
|
// Check values
|
65 |
|
|
if($groups_id == "") {
|
66 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_NO_GROUP);
|
67 |
1815
|
Luisehahne
|
} else {
|
68 |
|
|
$aGroups_id = explode(',', $groups_id);
|
69 |
|
|
//if user is in administrator-group, get this group else just get the first one
|
70 |
|
|
if($admin->is_group_match($groups_id,'1')) { $group_id = 1; } else { $group_id = intval($aGroups_id[0]); }
|
71 |
|
|
}
|
72 |
1475
|
Luisehahne
|
|
73 |
1815
|
Luisehahne
|
if(!preg_match('/^[a-z]{1}[a-z0-9_-]{2,}$/i', $username)) {
|
74 |
2065
|
Luisehahne
|
msgQueue::add( $mLang->MESSAGE_USERS_NAME_INVALID_CHARS);
|
75 |
1815
|
Luisehahne
|
}
|
76 |
1475
|
Luisehahne
|
|
77 |
1815
|
Luisehahne
|
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` '.
|
78 |
|
|
'WHERE `username` LIKE \''.$username.'\' ';
|
79 |
|
|
// Check if username already exists
|
80 |
|
|
if( ($iFoundUser = $database->get_one($sql)) != null ) {
|
81 |
|
|
if($iFoundUser) {
|
82 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_USERNAME_TAKEN);
|
83 |
1815
|
Luisehahne
|
}
|
84 |
|
|
}
|
85 |
1475
|
Luisehahne
|
|
86 |
1815
|
Luisehahne
|
if(strlen($password) < $iMinPassLength ) {
|
87 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_PASSWORD_TOO_SHORT);
|
88 |
1815
|
Luisehahne
|
}
|
89 |
1475
|
Luisehahne
|
|
90 |
1815
|
Luisehahne
|
$pattern = '/[^'.$admin->password_chars.']/';
|
91 |
|
|
if (preg_match($pattern, $password)) {
|
92 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_PREFERENCES_INVALID_CHARS);
|
93 |
1815
|
Luisehahne
|
}
|
94 |
1475
|
Luisehahne
|
|
95 |
1815
|
Luisehahne
|
if(($password != $password2) ) {
|
96 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE__USERS_PASSWORD_MISMATCH);
|
97 |
1815
|
Luisehahne
|
}
|
98 |
|
|
|
99 |
|
|
//
|
100 |
|
|
// check that display_name is unique in whoole system (prevents from User-faking)
|
101 |
|
|
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` ';
|
102 |
|
|
$sql .= 'WHERE `user_id` <> '.(int)$admin->get_user_id().' AND `display_name` LIKE "'.$display_name.'"';
|
103 |
|
|
if( ($iFoundUser = intval($database->get_one($sql))) > 0 ){
|
104 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_USERNAME_TAKEN.' ('.$mLang->TEXT_DISPLAY_NAME.')');
|
105 |
1815
|
Luisehahne
|
} else {
|
106 |
|
|
if($display_name == '') {
|
107 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_GENERIC_FILL_IN_ALL.' ('.$mLang->TEXT_DISPLAY_NAME.')');
|
108 |
1815
|
Luisehahne
|
}
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
if(findStringInFileList($display_name, dirname(__FILE__).'/disallowedNames')) {
|
112 |
2065
|
Luisehahne
|
msgQueue::add( $mLang->TEXT_ERROR.' '.$mLang->TEXT_DISPLAY_NAME.' ('.$display_name.')' );
|
113 |
1815
|
Luisehahne
|
}
|
114 |
|
|
|
115 |
|
|
if($email != "")
|
116 |
|
|
{
|
117 |
|
|
if($admin->validate_email($email) == false)
|
118 |
|
|
{
|
119 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_INVALID_EMAIL.' ('.$email.')');
|
120 |
1815
|
Luisehahne
|
}
|
121 |
|
|
} else { // e-mail must be present
|
122 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_SIGNUP_NO_EMAIL);
|
123 |
1815
|
Luisehahne
|
}
|
124 |
|
|
|
125 |
|
|
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` '.
|
126 |
|
|
'WHERE `email` LIKE \''.$email.'\' ';
|
127 |
|
|
|
128 |
|
|
// Check if the email already exists
|
129 |
|
|
if( ($iFoundUser = $database->get_one($sql)) != null ) {
|
130 |
|
|
if($iFoundUser) {
|
131 |
2065
|
Luisehahne
|
if(isset($mLang->MESSAGE_USERS_EMAIL_TAKEN))
|
132 |
1815
|
Luisehahne
|
{
|
133 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_EMAIL_TAKEN.' ('.$email.')');
|
134 |
1815
|
Luisehahne
|
} else {
|
135 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_INVALID_EMAIL.' ('.$email.')');
|
136 |
1815
|
Luisehahne
|
}
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
if( ($msg = msgQueue::getError()) == '')
|
141 |
|
|
{
|
142 |
|
|
//if user is in administrator-group, get this group else just get the first one
|
143 |
|
|
if($admin->is_group_match($groups_id,'1')) { $group_id = 1; $groups_id = '1'; }
|
144 |
1818
|
Luisehahne
|
|
145 |
1823
|
Luisehahne
|
if(defined('HOME_FOLDERS') && HOME_FOLDERS) {
|
146 |
|
|
// Include the WB functions file
|
147 |
|
|
if(!function_exists('media_filename')) { require(WB_PATH.'/framework/functions.php'); }
|
148 |
1818
|
Luisehahne
|
|
149 |
1823
|
Luisehahne
|
// Remove bad characters
|
150 |
|
|
$sHomeFolder = WB_PATH.MEDIA_DIRECTORY.'/home/'.( media_filename($username) );
|
151 |
|
|
if ( sizeof(createFolderProtectFile( $sHomeFolder )) )
|
152 |
|
|
{
|
153 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_MEDIA_DIR_NOT_MADE.' ('.basename($sHomeFolder).') ' );
|
154 |
1823
|
Luisehahne
|
}
|
155 |
1818
|
Luisehahne
|
}
|
156 |
1815
|
Luisehahne
|
// Inser the user into the database
|
157 |
|
|
$sql = 'INSERT INTO `'.TABLE_PREFIX.'users` SET '.
|
158 |
|
|
'`group_id` = '.intval($group_id).', '.
|
159 |
1868
|
Luisehahne
|
'`groups_id` = \''.$database->escapeString($groups_id).'\', '.
|
160 |
1815
|
Luisehahne
|
'`active` = '.intval($active).', '.
|
161 |
1868
|
Luisehahne
|
'`username` = \''.$database->escapeString($username).'\', '.
|
162 |
1815
|
Luisehahne
|
'`password` = \''.md5($password).'\', '.
|
163 |
1868
|
Luisehahne
|
'`confirm_code` = \''.$database->escapeString($confirm_code).'\', '.
|
164 |
1815
|
Luisehahne
|
'`confirm_timeout` = '.intval($confirm_timeout).', '.
|
165 |
1868
|
Luisehahne
|
'`remember_key` = \''.$database->escapeString($remember_key).'\', '.
|
166 |
1815
|
Luisehahne
|
'`last_reset` = '.intval($last_reset).', '.
|
167 |
1868
|
Luisehahne
|
'`display_name` = \''.$database->escapeString($display_name).'\', '.
|
168 |
|
|
'`email` = \''.$database->escapeString($email).'\', '.
|
169 |
1815
|
Luisehahne
|
'`timezone` = '.intval($timezone).', '.
|
170 |
1868
|
Luisehahne
|
'`date_format` = \''.$database->escapeString($date_format).'\', '.
|
171 |
|
|
'`time_format` = \''.$database->escapeString($time_format).'\', '.
|
172 |
|
|
'`language` = \''.$database->escapeString($language).'\', '.
|
173 |
|
|
'`home_folder` = \''.$database->escapeString($home_folder).'\', '.
|
174 |
1815
|
Luisehahne
|
'`login_when` = '.intval($login_when).', '.
|
175 |
1868
|
Luisehahne
|
'`login_ip` = \''.$database->escapeString($login_ip).'\' '.
|
176 |
1815
|
Luisehahne
|
'';
|
177 |
|
|
if($database->query($sql)) {
|
178 |
2065
|
Luisehahne
|
msgQueue::add($mLang->MESSAGE_USERS_ADDED, true);
|
179 |
1844
|
Luisehahne
|
$bRetVal = true;
|
180 |
1815
|
Luisehahne
|
}
|
181 |
|
|
if($database->is_error()) {
|
182 |
|
|
msgQueue::add( implode('<br />',explode(';',$database->get_error())) );
|
183 |
|
|
}
|
184 |
|
|
} else {
|
185 |
2065
|
Luisehahne
|
msgQueue::add($mLang->HEADING_ADD_USER.' '.$mLang->MESSAGE_GENERIC_NOT_COMPARE);
|
186 |
1815
|
Luisehahne
|
|
187 |
1844
|
Luisehahne
|
}
|
188 |
|
|
return $bRetVal;
|
189 |
|
|
}
|