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