|
22 | 22 | +-------------------------------------------------------------------------+ |
23 | 23 | */ |
24 | 24 |
|
| 25 | +include('./include/global.php'); |
| 26 | + |
25 | 27 | set_default_action(); |
26 | 28 |
|
27 | | -$user = db_fetch_row_prepared('SELECT * |
28 | | - FROM user_auth |
29 | | - WHERE id = ?', |
| 29 | +switch (get_request_var('action')) { |
| 30 | + case 'checkpass': |
| 31 | + $error = secpass_check_pass(get_nfilter_request_var('password')); |
| 32 | + |
| 33 | + if ($error == '') { |
| 34 | + print $error; |
| 35 | + } else { |
| 36 | + print 'ok'; |
| 37 | + } |
| 38 | + |
| 39 | + exit; |
| 40 | + |
| 41 | + break; |
| 42 | + default: |
| 43 | + // If the user is not logged in, redirect them to the login page |
| 44 | + if (!isset($_SESSION['sess_user_id'])) { |
| 45 | + if (isset($_SERVER['HTTP_REFERER'])) { |
| 46 | + header('Location: ' . sanitize_uri($_SERVER['HTTP_REFERER'])); |
| 47 | + } else { |
| 48 | + header('Location: index.php'); |
| 49 | + } |
| 50 | + |
| 51 | + header('Location: index.php'); |
| 52 | + exit; |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +$user = db_fetch_row_prepared('SELECT * |
| 57 | + FROM user_auth |
| 58 | + WHERE id = ?', |
30 | 59 | array($_SESSION['sess_user_id'])); |
31 | 60 |
|
32 | 61 | $version = get_cacti_version(); |
33 | 62 |
|
34 | 63 | if ($user['realm'] != 0) { |
35 | | - auth_raise_message('nodomainpassword'); |
| 64 | + raise_message('nodomainpassword'); |
36 | 65 | if (isset($_SERVER['HTTP_REFERER'])) { |
37 | 66 | header('Location: ' . sanitize_uri($_SERVER['HTTP_REFERER'])); |
38 | 67 | } else { |
|
42 | 71 | } |
43 | 72 |
|
44 | 73 | if ($user['password_change'] != 'on') { |
45 | | - auth_raise_message('nopassword'); |
| 74 | + raise_message('nopassword'); |
46 | 75 |
|
47 | 76 | /* destroy session information */ |
48 | 77 | kill_session_var('sess_user_id'); |
|
71 | 100 | set_default_action(); |
72 | 101 |
|
73 | 102 | switch (get_request_var('action')) { |
74 | | -case 'updatepassword': |
| 103 | +case 'changepassword': |
75 | 104 | // Get current user |
76 | 105 | $user_id = intval($_SESSION['sess_user_id']); |
77 | 106 |
|
|
165 | 194 | array(compat_password_hash($password,PASSWORD_DEFAULT), $user_id)); |
166 | 195 |
|
167 | 196 | kill_session_var('sess_change_password'); |
168 | | - auth_raise_message('password_success'); |
| 197 | + |
| 198 | + raise_message('password_success'); |
169 | 199 |
|
170 | 200 | /* ok, at the point the user has been sucessfully authenticated; so we must decide what to do next */ |
171 | 201 |
|
|
242 | 272 | $secpass_tooltip .= $secpass_body; |
243 | 273 |
|
244 | 274 | $selectedTheme = get_selected_theme(); |
245 | | -$html_header = ""; |
246 | | -$html_footer = ""; |
247 | | - |
248 | | -global $config; |
249 | 275 |
|
250 | | -html_common_login_header('change_password_title', __('Change Password'), __('Change Password'), $html_header); |
251 | 276 | ?> |
| 277 | +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 278 | +<html> |
| 279 | +<head> |
| 280 | + <?php html_common_header(api_plugin_hook_function('change_password_title', __('Change Password')));?> |
| 281 | + <script type='text/javascript'> |
| 282 | + $(function() { |
| 283 | + } |
| 284 | +</head> |
| 285 | +<body class='loginBody'> |
| 286 | + <div class='loginLeft'></div> |
| 287 | + <div class='loginCenter'> |
| 288 | + <div class='loginArea'> |
| 289 | + <div class='cactiLogoutLogo'></div> |
| 290 | + <legend><?php print __('Change Password');?></legend> |
252 | 291 | <form name='login' method='post' action='<?php print get_current_page();?>'> |
253 | | - <input type='hidden' name='action' value='updatepassword'> |
| 292 | + <input type='hidden' name='action' value='changepassword'> |
254 | 293 | <input type='hidden' name='ref' value='<?php print sanitize_uri(get_request_var('ref')); ?>'> |
255 | 294 | <input type='hidden' name='name' value='<?php print isset($user['username']) ? $user['username'] : '';?>'> |
256 | 295 | <div class='loginTitle'> |
|
264 | 303 | </tr> |
265 | 304 | <tr> |
266 | 305 | <td><?php print __('New password');?></td> |
267 | | - <td> |
268 | | - <input type='password' class='ui-state-default ui-corner-all' id='password' name='password' autocomplete='off' size='20' placeholder='********'><?php display_tooltip($secpass_tooltip);?> |
269 | | - <div id="pass" class="password badpassword fa fa-times" title="<?php print __('Password not set');?>"></div> |
270 | | - </td> |
| 306 | + <td><input type='password' class='ui-state-default ui-corner-all' id='password' name='password' autocomplete='off' size='20' placeholder='********'><?php display_tooltip($secpass_tooltip);?></td> |
271 | 307 | </tr> |
272 | 308 | <tr> |
273 | 309 | <td><?php print __('Confirm new password');?></td> |
274 | | - <td> |
275 | | - <input type='password' class='ui-state-default ui-corner-all' id='password_confirm' name='password_confirm' autocomplete='off' size='20' placeholder='********'> |
276 | | - <div id="passconfirm" class="passconfirm badpassword fa fa-times" title="<?php print __('Password not set')?>"></div> |
277 | | - </td> |
| 310 | + <td><input type='password' class='ui-state-default ui-corner-all' id='password_confirm' name='password_confirm' autocomplete='off' size='20' placeholder='********'></td> |
278 | 311 | </tr> |
279 | 312 | <tr> |
280 | | - <td> </td> |
281 | | - <td class='nowrap'><input id='save' type='submit' class='ui-button ui-corner-all ui-widget' value='<?php print __esc('Save'); ?>'> |
| 313 | + <td class='nowrap' colspan='2'><input type='submit' class='ui-button ui-corner-all ui-widget' value='<?php print __esc('Save'); ?>'> |
282 | 314 | <?php print $user['must_change_password'] != 'on' ? "<input type='button' class='ui-button ui-corner-all ui-widget' onClick='window.history.go(-1)' value='". __esc('Return') . "'>":"";?> |
283 | 315 | </td> |
284 | 316 | </tr> |
285 | 317 | </table> |
286 | 318 | </div> |
287 | 319 | </form> |
288 | 320 | <div class='loginErrors'><?php print $errorMessage ?></div> |
289 | | - <script type='text/javascript'> |
290 | | - |
291 | | - var minChars=<?php print read_config_option('secpass_minlen'); ?>; |
292 | | - |
293 | | - function setPassword(field, isValid, title = '') { |
294 | | - if (title == '' || title == undefined) { |
295 | | - title = '<?php print __('Password Too Short');?>'; |
296 | | - } |
297 | | - |
298 | | - if (isValid) { |
299 | | - classAdd = 'goodpassword fa-check'; |
300 | | - classDel = 'badpassword fa-times'; |
301 | | - title = '<?php print __('Password Validation Passes');?>'; |
302 | | - } else { |
303 | | - classAdd = 'badpassword fa-times'; |
304 | | - classDel = 'goodpassword fa-check'; |
305 | | - titleIcon = 'times'; |
306 | | - } |
307 | | - |
308 | | - $('#' + field).removeClass(classDel).addClass(classAdd).tooltip('option','content',title); |
309 | | - } |
310 | | - |
311 | | - function checkPassword() { |
312 | | - if ($('#password').val().length == 0) { |
313 | | - setPassword('pass', false); |
314 | | - checkPasswordConfirm(); |
315 | | - } else if ($('#password').val().length < minChars) { |
316 | | - setPassword('pass', false); |
| 321 | + </div> |
| 322 | + <div class='versionInfo'><?php __('Version %1$s | %2$s', $version, COPYRIGHT_YEARS_SHORT); ?></div> |
| 323 | + </div> |
| 324 | + <div class='loginRight'></div> |
| 325 | + <script type='text/javascript'> |
| 326 | + |
| 327 | + var minChars=<?php print read_config_option('secpass_minlen');?>; |
| 328 | + |
| 329 | + function checkPassword() { |
| 330 | + if ($('#password').val().length == 0) { |
| 331 | + $('#pass').remove(); |
| 332 | + $('#passconfirm').remove(); |
| 333 | + }else if ($('#password').val().length < minChars) { |
| 334 | + $('#pass').remove(); |
| 335 | + $('#password').after('<div id="pass" class="password badpassword fa fa-times" title="<?php print __esc('Password Too Short');?>"></div>'); |
| 336 | + $('.password').tooltip(); |
| 337 | + } else { |
| 338 | + $.post('auth_changepassword.php?action=checkpass', { password: $('#password').val(), password_confim: $('#password_confirm').val(), __csrf_magic: csrfMagicToken } ).done(function(data) { |
| 339 | + if (data == 'ok') { |
| 340 | + $('#pass').remove(); |
| 341 | + $('#password').after('<div id="pass" class="password goodpassword fa fa-check" title="<?php print __esc('Password Validation Passes');?>"></div>'); |
| 342 | + $('.password').tooltip(); |
317 | 343 | checkPasswordConfirm(); |
318 | 344 | } else { |
319 | | - var checkPage = '<?php print URL_PATH;?>check_json.php?action=checkpass'; |
320 | | - $.post(checkPage, { password: $('#password').val(), password_confim: $('#password_confirm').val(), __csrf_magic: csrfMagicToken } ).done(function(data) { |
321 | | - if (data == 'ok') { |
322 | | - setPassword('pass', true); |
323 | | - } else { |
324 | | - setPassword('pass', false, data); |
325 | | - } |
326 | | - checkPasswordConfirm(); |
327 | | - }).fail(function() { |
328 | | - setPassword('pass', false); |
329 | | - checkPasswordConfirm(); |
330 | | - }); |
331 | | - } |
332 | | - } |
333 | | - |
334 | | - function checkPasswordConfirm() { |
335 | | - var isValid = false; |
336 | | - if ($('#password_confirm').val().length > 0) { |
337 | | - isValid= ($('#password').val() == $('#password_confirm').val()); |
338 | | - } |
339 | | - |
340 | | - title = '<?php print __('Passwords do Not Match');?>'; |
341 | | - if (isValid) { |
342 | | - title = '<?php print __('Passwords Match'); ?>'; |
| 345 | + $('#pass').remove(); |
| 346 | + $('#password').after('<div id="pass" class="password badpassword fa fa-times" title="'+data+'"></div>'); |
| 347 | + $('.password').tooltip(); |
343 | 348 | } |
| 349 | + }); |
| 350 | + } |
| 351 | + } |
344 | 352 |
|
345 | | - setPassword('passconfirm', isValid, title); |
346 | | - $('#save').button( "option", "disabled", !isValid ); |
| 353 | + function checkPasswordConfirm() { |
| 354 | + if ($('#password_confirm').val().length > 0) { |
| 355 | + if ($('#password').val() != $('#password_confirm').val()) { |
| 356 | + $('#passconfirm').remove(); |
| 357 | + $('#password_confirm').after('<div id="passconfirm" class="passconfirm badpassword fa fa-times" title="<?php print __esc('Passwords do Not Match');?>"></div>'); |
| 358 | + $('.passconfirm').tooltip(); |
| 359 | + } else { |
| 360 | + $('#passconfirm').remove(); |
| 361 | + $('#password_confirm').after('<div id="passconfirm" class="passconfirm goodpassword fa fa-check" title="<?php print __esc('Passwords Match');?>"></div>'); |
| 362 | + $('.passconfirm').tooltip(); |
347 | 363 | } |
| 364 | + } else { |
| 365 | + $('#passconfirm').remove(); |
| 366 | + } |
| 367 | + } |
348 | 368 |
|
349 | | - var password_change = $('#password_change').is(':checked'); |
| 369 | + var password_change = $('#password_change').is(':checked'); |
350 | 370 |
|
351 | | - $(function() { |
352 | | - $('#current').focus(); |
353 | | - $('.loginLeft').css('width',parseInt($(window).width()*0.33)+'px'); |
354 | | - $('.loginRight').css('width',parseInt($(window).width()*0.33)+'px'); |
| 371 | + $(function() { |
| 372 | + $('#current').focus(); |
| 373 | + $('.loginLeft').css('width',parseInt($(window).width()*0.33)+'px'); |
| 374 | + $('.loginRight').css('width',parseInt($(window).width()*0.33)+'px'); |
355 | 375 |
|
356 | | - /* clear passwords */ |
357 | | - var inputs = $('#password, #pass, #password_confirm, #passconfirm'); |
358 | | - inputs.tooltip(); |
| 376 | + /* clear passwords */ |
| 377 | + $('#password').val(''); |
| 378 | + $('#password_confirm').val(''); |
359 | 379 |
|
360 | | - $('#password, password_confirm').val(''); |
361 | | - //$('#password_confirm').val(''); |
| 380 | + $('#password').keyup(function() { |
| 381 | + checkPassword(); |
| 382 | + }); |
362 | 383 |
|
363 | | - $('#password').keyup(function() { |
364 | | - checkPassword(); |
365 | | - }); |
| 384 | + $('#password_confirm').keyup(function() { |
| 385 | + checkPasswordConfirm(); |
| 386 | + }); |
| 387 | + }); |
| 388 | + </script> |
| 389 | +<?php |
366 | 390 |
|
367 | | - $('#password_confirm').keyup(function() { |
368 | | - checkPasswordConfirm(); |
369 | | - }); |
| 391 | +include_once('./include/global_session.php'); |
370 | 392 |
|
371 | | - checkPassword(); |
372 | | - checkPasswordConfirm(); |
373 | | - }); |
374 | | - </script> |
375 | | -<?php |
376 | | -html_common_login_footer($html_footer); |
| 393 | +print "</body> |
| 394 | + </html>\n"; |
0 commit comments