This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
1 | <?php declare(strict_types=1); |
||
2 | // ------------------------------------------------------------------------ // |
||
3 | // XOOPS - PHP Content Management System // |
||
4 | // Copyright (c) 2000 XOOPS.org // |
||
5 | // <https://xoops.org> // |
||
6 | // ------------------------------------------------------------------------- // |
||
7 | // This program is free software; you can redistribute it and/or modify // |
||
8 | // it under the terms of the GNU General Public License as published by // |
||
9 | // the Free Software Foundation; either version 2 of the License, or // |
||
10 | // (at your option) any later version. // |
||
11 | // // |
||
12 | // You may not change or alter any portion of this comment or credits // |
||
13 | // of supporting developers from this source code or any supporting // |
||
14 | // source code which is considered copyrighted (c) material of the // |
||
15 | // original comment or credit authors. // |
||
16 | // // |
||
17 | // This program is distributed in the hope that it will be useful, // |
||
18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
20 | // GNU General Public License for more details. // |
||
21 | // // |
||
22 | // You should have received a copy of the GNU General Public License // |
||
23 | // along with this program; if not, write to the Free Software // |
||
24 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
25 | // ------------------------------------------------------------------------ // |
||
26 | use Xmf\Request; |
||
27 | use XoopsModules\Suico\Form\RegisterForm; |
||
28 | |||
29 | $GLOBALS['xoopsOption']['template_main'] = 'suico_user.tpl'; |
||
30 | require __DIR__ . '/header.php'; |
||
31 | /** |
||
32 | * If is user redirects to own profile |
||
33 | */ |
||
34 | if (($xoopsUser)) { |
||
35 | $isAnonym = 0; |
||
36 | if (isset($_GET['uid'])) { |
||
37 | $uid_owner = Request::getInt('uid', 0, 'GET'); |
||
38 | $isOwner = $xoopsUser->getVar('uid') === $uid_owner ? 1 : 0; |
||
39 | } else { |
||
40 | $uid_owner = (int)$xoopsUser->getVar('uid'); |
||
41 | $isOwner = 1; |
||
42 | } |
||
43 | redirect_header('' . XOOPS_URL . "/modules/suico/index.php?uid=$uid_owner"); |
||
44 | } |
||
45 | $op = $_REQUEST['op'] ?? ''; |
||
46 | if ('register' === $op) { |
||
47 | $GLOBALS['xoopsOption']['template_main'] = 'suico_register.tpl'; |
||
48 | include $GLOBALS['xoops']->path('header.php'); |
||
49 | if (!empty($_GET['op']) && in_array($_GET['op'], ['actv', 'activate'], true)) { |
||
50 | header('location: ./activate.php' . (Request::getString('QUERY_STRING', '', 'SERVER'))); |
||
51 | exit(); |
||
52 | } |
||
53 | xoops_load('XoopsUserUtility'); |
||
54 | $myts = \MyTextSanitizer::getInstance(); |
||
55 | /** @var XoopsConfigHandler $configHandler */ |
||
56 | $configHandler = xoops_getHandler('config'); |
||
57 | $GLOBALS['xoopsConfigUser'] = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
||
58 | if (empty($GLOBALS['xoopsConfigUser']['allow_register'])) { |
||
59 | redirect_header('index.php', 6, _US_NOREGISTER); |
||
60 | } |
||
61 | // get the key we need to access our 'op' in $_POST |
||
62 | // if this key is not set, empty $_POST since this is a new registration and |
||
63 | // no legitimate data would be there. |
||
64 | $opkey = 'profile_opname'; |
||
65 | if (isset($_SESSION[$opkey])) { |
||
66 | $current_opname = $_SESSION[$opkey]; |
||
67 | unset($_SESSION[$opkey]); |
||
68 | if (!isset($_POST[$current_opname])) { |
||
69 | $_POST = []; |
||
70 | } |
||
71 | } else { |
||
72 | $_POST = []; |
||
73 | $current_opname = 'op'; // does not matter, it isn't there |
||
74 | } |
||
75 | $op = Request::getString($current_opname, 'register', 'POST'); |
||
76 | $current_step = isset($_POST['step']) ? (int)$_POST['step'] : 0; |
||
77 | // The newly introduced variable $_SESSION['profile_post'] is contaminated by $_POST, thus we use an old vaiable to hold uid parameter |
||
78 | $uid = !empty($_SESSION['profile_register_uid']) ? (int)$_SESSION['profile_register_uid'] : 0; |
||
79 | // First step is already secured by with the captcha Token so lets check the others |
||
80 | if ($current_step > 0 && !$GLOBALS['xoopsSecurity']->check()) { |
||
81 | redirect_header('user.php', 5, _MD_SUICO_EXPIRED); |
||
82 | } |
||
83 | $criteria = new CriteriaCompo(); |
||
84 | $criteria->setSort('step_order'); |
||
85 | $regstepHandler = $helper->getHandler('Regstep'); |
||
86 | if (!$steps = $regstepHandler->getAll($criteria, null, false, false)) { |
||
87 | redirect_header(XOOPS_URL . '/', 6, _MD_SUICO_NOSTEPSAVAILABLE); |
||
88 | } |
||
89 | foreach (array_keys($steps) as $key) { |
||
90 | $steps[$key]['step_no'] = $key + 1; |
||
91 | } |
||
92 | $GLOBALS['xoopsTpl']->assign('steps', $steps); |
||
93 | $GLOBALS['xoopsTpl']->assign('lang_register_steps', _MD_SUICO_REGISTER_STEPS); |
||
94 | $xoBreadcrumbs[] = [ |
||
95 | 'link' => XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/register.php', |
||
96 | 'title' => _MD_SUICO_REGISTER, |
||
97 | ]; |
||
98 | if (isset($steps[$current_step])) { |
||
99 | $xoBreadcrumbs[] = ['title' => $steps[$current_step]['step_name']]; |
||
100 | } |
||
101 | /** @var \XoopsMemberHandler $memberHandler */ |
||
102 | $memberHandler = xoops_getHandler('member'); |
||
103 | $profileHandler = $helper->getHandler('Profile'); |
||
104 | $fields = $profileHandler->loadFields(); |
||
105 | $userfields = $profileHandler->getUserVars(); |
||
106 | if (0 == $uid) { |
||
107 | // No user yet? Create one and set default values. |
||
108 | $newuser = $memberHandler->createUser(); |
||
109 | $profile = $profileHandler->create(); |
||
110 | if (count($fields) > 0) { |
||
111 | foreach (array_keys($fields) as $i) { |
||
112 | $fieldname = $fields[$i]->getVar('field_name'); |
||
113 | if (in_array($fieldname, $userfields, true)) { |
||
114 | $default = $fields[$i]->getVar('field_default'); |
||
115 | if ('' === $default || null === $default) { |
||
116 | continue; |
||
117 | } |
||
118 | $newuser->setVar($fieldname, $default); |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | } else { |
||
123 | // We already have a user? Just load it! Security is handled by token so there is no fake uid here. |
||
124 | $newuser = $memberHandler->getUser($uid); |
||
125 | $profile = $profileHandler->get($uid); |
||
126 | } |
||
127 | // Lets merge current $_POST with $_SESSION['profile_post'] so we can have access to info submited in previous steps |
||
128 | // Get all fields that we can expect from a $_POST inlcuding our private '_message_' |
||
129 | $fieldnames = []; |
||
130 | foreach (array_keys($fields) as $i) { |
||
131 | $fieldnames[] = $fields[$i]->getVar('field_name'); |
||
132 | } |
||
133 | $fieldnames = array_merge($fieldnames, $userfields); |
||
134 | $fieldnames[] = '_message_'; |
||
135 | // Get $_POST that matches above criteria, we do not need to store step, tokens, etc |
||
136 | $postfields = []; |
||
137 | foreach ($fieldnames as $fieldname) { |
||
138 | if (isset($_POST[$fieldname])) { |
||
139 | $postfields[$fieldname] = $_POST[$fieldname]; |
||
140 | } |
||
141 | } |
||
142 | if (0 == $current_step) { |
||
143 | // Reset any previous session for first step |
||
144 | $_SESSION['profile_post'] = []; |
||
145 | $_SESSION['profile_register_uid'] = null; |
||
146 | } else { |
||
147 | // Merge current $_POST with $_SESSION['profile_post'] |
||
148 | $_SESSION['profile_post'] = array_merge($_SESSION['profile_post'], $postfields); |
||
149 | $_POST = array_merge($_SESSION['profile_post'], $_POST); |
||
150 | } |
||
151 | // Set vars from $_POST/$_SESSION['profile_post'] |
||
152 | foreach (array_keys($fields) as $field) { |
||
153 | if (!isset($_POST[$field])) { |
||
154 | continue; |
||
155 | } |
||
156 | $value = $fields[$field]->getValueForSave($_POST[$field]); |
||
157 | if (in_array($field, $userfields, true)) { |
||
158 | $newuser->setVar($field, $value); |
||
159 | } else { |
||
160 | $profile->setVar($field, $value); |
||
161 | } |
||
162 | } |
||
163 | $stop = ''; |
||
164 | //Client side validation |
||
165 | if (isset($_POST['step'], $_SESSION['profile_required'])) { |
||
166 | foreach ($_SESSION['profile_required'] as $name => $title) { |
||
167 | if (empty($_POST[$name])) { |
||
168 | $stop .= sprintf(_FORM_ENTER, $title) . '<br>'; |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | // Check user data at first step |
||
173 | if (1 == $current_step) { |
||
174 | $uname = Request::getString('uname', '', 'POST'); |
||
175 | $email = Request::getString('email', '', 'POST'); |
||
176 | $url = Request::getString('url', '', 'POST'); |
||
177 | $pass = Request::getString('pass', '', 'POST'); |
||
178 | $vpass = Request::getString('vpass', '', 'POST'); |
||
179 | $agree_disc = (isset($_POST['agree_disc']) && (int)$_POST['agree_disc']) ? 1 : 0; |
||
180 | if (0 != $GLOBALS['xoopsConfigUser']['reg_dispdsclmr'] && '' !== $GLOBALS['xoopsConfigUser']['reg_disclaimer']) { |
||
181 | if (empty($agree_disc)) { |
||
182 | $stop .= _US_UNEEDAGREE . '<br>'; |
||
183 | } |
||
184 | } |
||
185 | $newuser->setVar('uname', $uname); |
||
186 | $newuser->setVar('email', $email); |
||
187 | $newuser->setVar('pass', $pass ? password_hash($pass, PASSWORD_DEFAULT) : ''); |
||
188 | $stop .= XoopsUserUtility::validate($newuser, $pass, $vpass); |
||
189 | xoops_load('XoopsCaptcha'); |
||
190 | $xoopsCaptcha = XoopsCaptcha::getInstance(); |
||
191 | if (!$xoopsCaptcha->verify()) { |
||
192 | $stop .= $xoopsCaptcha->getMessage(); |
||
193 | } |
||
194 | } |
||
195 | // If the last step required SAVE or if we're on the last step then we will insert/update user on database |
||
196 | if ($current_step > 0 && empty($stop) && (!empty($steps[$current_step - 1]['step_save']) || !isset($steps[$current_step]))) { |
||
197 | if (1 == $GLOBALS['xoopsModuleConfig']['profileCaptchaAfterStep1'] && $current_step > 1) { |
||
198 | xoops_load('XoopsCaptcha'); |
||
199 | $xoopsCaptcha2 = XoopsCaptcha::getInstance(); |
||
200 | if (!$xoopsCaptcha2->verify()) { |
||
201 | $stop .= $xoopsCaptcha2->getMessage(); |
||
202 | } |
||
203 | } |
||
204 | if (empty($stop)) { |
||
205 | $isNew = $newuser->isNew(); |
||
206 | //Did created an user already? If not then let us set some extra info |
||
207 | if ($isNew) { |
||
208 | $uname = Request::getString('uname', '', 'POST'); |
||
209 | $email = Request::getString('email', '', 'POST'); |
||
210 | $url = Request::getString('url', '', 'POST'); |
||
211 | $pass = Request::getString('pass', '', 'POST'); |
||
212 | $newuser->setVar('uname', $uname); |
||
213 | $newuser->setVar('email', $email); |
||
214 | $newuser->setVar('pass', $pass ? password_hash($pass, PASSWORD_DEFAULT) : ''); |
||
215 | |||
216 | try { |
||
217 | $actkey = bin2hex(random_bytes(4)); |
||
218 | } catch (\Throwable $e) { |
||
219 | echo 'Caught exception: ', $e->getMessage(), "\n"; |
||
220 | } |
||
221 | $newuser->setVar('actkey', $actkey, true); |
||
222 | $newuser->setVar('user_regdate', time(), true); |
||
223 | $newuser->setVar('uorder', $GLOBALS['xoopsConfig']['com_order'], true); |
||
224 | $newuser->setVar('umode', $GLOBALS['xoopsConfig']['com_mode'], true); |
||
225 | $newuser->setVar('theme', $GLOBALS['xoopsConfig']['theme_set'], true); |
||
226 | $newuser->setVar('user_avatar', 'avatars/blank.gif', true); |
||
227 | if (1 == $GLOBALS['xoopsConfigUser']['activation_type']) { |
||
228 | $newuser->setVar('level', 1, true); |
||
229 | } else { |
||
230 | $newuser->setVar('level', 0, true); |
||
231 | } |
||
232 | } |
||
233 | // Insert/update user and check if we have succeded |
||
234 | if ($memberHandler->insertUser($newuser)) { |
||
235 | // User inserted! Now insert custom profile fields |
||
236 | $profile->setVar('profile_id', $newuser->getVar('uid')); |
||
237 | $profileHandler->insert($profile); |
||
238 | // We are good! If this is 'was' a new user then we handle notification |
||
239 | if ($isNew) { |
||
240 | if (1 == $GLOBALS['xoopsConfigUser']['new_user_notify'] && !empty($GLOBALS['xoopsConfigUser']['new_user_notify_group'])) { |
||
241 | $xoopsMailer = xoops_getMailer(); |
||
242 | $xoopsMailer->reset(); |
||
243 | $xoopsMailer->useMail(); |
||
244 | $xoopsMailer->setToGroups($memberHandler->getGroup($GLOBALS['xoopsConfigUser']['new_user_notify_group'])); |
||
245 | $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']); |
||
246 | $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']); |
||
247 | $xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT, $GLOBALS['xoopsConfig']['sitename'])); |
||
248 | $xoopsMailer->setBody(sprintf(_US_HASJUSTREG, $newuser->getVar('uname'))); |
||
249 | $xoopsMailer->send(true); |
||
250 | } |
||
251 | $message = ''; |
||
252 | if (!$memberHandler->addUserToGroup(XOOPS_GROUP_USERS, $newuser->getVar('uid'))) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
253 | $message = _MD_SUICO_REGISTER_NOTGROUP . '<br>'; |
||
254 | } elseif (1 == $GLOBALS['xoopsConfigUser']['activation_type']) { |
||
255 | XoopsUserUtility::sendWelcome($newuser); |
||
256 | } elseif (0 == $GLOBALS['xoopsConfigUser']['activation_type']) { |
||
257 | $xoopsMailer = xoops_getMailer(); |
||
258 | $xoopsMailer->reset(); |
||
259 | $xoopsMailer->useMail(); |
||
260 | $xoopsMailer->setTemplate('register.tpl'); |
||
261 | $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']); |
||
262 | $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']); |
||
263 | $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
||
264 | $xoopsMailer->assign('X_UPASS', $_POST['vpass']); |
||
265 | $xoopsMailer->setToUsers($newuser); |
||
266 | $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']); |
||
267 | $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']); |
||
268 | $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $newuser->getVar('uname'))); |
||
269 | if ($xoopsMailer->send(true)) { |
||
270 | $_SESSION['profile_post']['_message_'] = 1; |
||
271 | } else { |
||
272 | $_SESSION['profile_post']['_message_'] = 0; |
||
273 | } |
||
274 | } elseif (2 == $GLOBALS['xoopsConfigUser']['activation_type']) { |
||
275 | $xoopsMailer = xoops_getMailer(); |
||
276 | $xoopsMailer->reset(); |
||
277 | $xoopsMailer->useMail(); |
||
278 | $xoopsMailer->setTemplate('adminactivate.tpl'); |
||
279 | $xoopsMailer->assign('USERNAME', $newuser->getVar('uname')); |
||
280 | $xoopsMailer->assign('USEREMAIL', $newuser->getVar('email')); |
||
281 | $xoopsMailer->assign('USERACTLINK', XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/activate.php?id=' . $newuser->getVar('uid') . '&actkey=' . $newuser->getVar('actkey', 'n')); |
||
282 | $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']); |
||
283 | $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']); |
||
284 | $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
||
285 | $xoopsMailer->setToGroups($memberHandler->getGroup($GLOBALS['xoopsConfigUser']['activation_group'])); |
||
286 | $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']); |
||
287 | $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']); |
||
288 | $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $newuser->getVar('uname'))); |
||
289 | if ($xoopsMailer->send()) { |
||
290 | $_SESSION['profile_post']['_message_'] = 3; |
||
291 | } else { |
||
292 | $_SESSION['profile_post']['_message_'] = 2; |
||
293 | } |
||
294 | } |
||
295 | if ($message) { |
||
296 | $GLOBALS['xoopsTpl']->append('confirm', $message); |
||
297 | } |
||
298 | $_SESSION['profile_register_uid'] = $newuser->getVar('uid'); |
||
299 | } |
||
300 | } else { |
||
301 | $stop .= _US_REGISTERNG . '<br>'; |
||
302 | $stop .= implode('<br>', $newuser->getErrors()); |
||
303 | } |
||
304 | } |
||
305 | } |
||
306 | if (!empty($stop) || isset($steps[$current_step])) { |
||
307 | $current_step = empty($stop) ? $current_step : $current_step - 1; |
||
308 | $reg_form = new RegisterForm($newuser, $profile, $steps[$current_step]); |
||
309 | $reg_form->assign($GLOBALS['xoopsTpl']); |
||
310 | $GLOBALS['xoopsTpl']->assign('current_step', $current_step); |
||
311 | $GLOBALS['xoopsTpl']->assign('stop', $stop); |
||
312 | } else { |
||
313 | // No errors and no more steps, finish |
||
314 | $GLOBALS['xoopsTpl']->assign('finish', _MD_SUICO_REGISTER_FINISH); |
||
315 | $GLOBALS['xoopsTpl']->assign('current_step', -1); |
||
316 | if (1 == $GLOBALS['xoopsConfigUser']['activation_type'] && !empty($_SESSION['profile_post']['pass'])) { |
||
317 | $GLOBALS['xoopsTpl']->assign('finish_login', _MD_SUICO_FINISH_LOGIN); |
||
318 | $GLOBALS['xoopsTpl']->assign('finish_uname', $newuser->getVar('uname')); |
||
319 | $GLOBALS['xoopsTpl']->assign('finish_pass', htmlspecialchars($_SESSION['profile_post']['pass'], ENT_QUOTES | ENT_HTML5)); |
||
320 | } |
||
321 | if (isset($_SESSION['profile_post']['_message_'])) { |
||
322 | //todo, if user is activated by admin, then we should inform it along with error messages. _US_YOURREGMAILNG is not enough |
||
323 | $messages = [_US_YOURREGMAILNG, _US_YOURREGISTERED, _US_YOURREGMAILNG, _US_YOURREGISTERED2]; |
||
324 | $GLOBALS['xoopsTpl']->assign('finish_message', $messages[$_SESSION['profile_post']['_message_']]); |
||
325 | } |
||
326 | $_SESSION['profile_post'] = null; |
||
327 | } |
||
328 | } |
||
329 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
330 |