Skip to content

Commit 15b90d5

Browse files
committed
Revert "Fixes issue 1717 and others (Cacti#1775)"
This reverts commit ca23733.
1 parent 10fdb4c commit 15b90d5

File tree

20 files changed

+417
-639
lines changed

20 files changed

+417
-639
lines changed
Lines changed: 117 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,46 @@
2222
+-------------------------------------------------------------------------+
2323
*/
2424

25+
include('./include/global.php');
26+
2527
set_default_action();
2628

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 = ?',
3059
array($_SESSION['sess_user_id']));
3160

3261
$version = get_cacti_version();
3362

3463
if ($user['realm'] != 0) {
35-
auth_raise_message('nodomainpassword');
64+
raise_message('nodomainpassword');
3665
if (isset($_SERVER['HTTP_REFERER'])) {
3766
header('Location: ' . sanitize_uri($_SERVER['HTTP_REFERER']));
3867
} else {
@@ -42,7 +71,7 @@
4271
}
4372

4473
if ($user['password_change'] != 'on') {
45-
auth_raise_message('nopassword');
74+
raise_message('nopassword');
4675

4776
/* destroy session information */
4877
kill_session_var('sess_user_id');
@@ -71,7 +100,7 @@
71100
set_default_action();
72101

73102
switch (get_request_var('action')) {
74-
case 'updatepassword':
103+
case 'changepassword':
75104
// Get current user
76105
$user_id = intval($_SESSION['sess_user_id']);
77106

@@ -165,7 +194,8 @@
165194
array(compat_password_hash($password,PASSWORD_DEFAULT), $user_id));
166195

167196
kill_session_var('sess_change_password');
168-
auth_raise_message('password_success');
197+
198+
raise_message('password_success');
169199

170200
/* ok, at the point the user has been sucessfully authenticated; so we must decide what to do next */
171201

@@ -242,15 +272,24 @@
242272
$secpass_tooltip .= $secpass_body;
243273

244274
$selectedTheme = get_selected_theme();
245-
$html_header = "";
246-
$html_footer = "";
247-
248-
global $config;
249275

250-
html_common_login_header('change_password_title', __('Change Password'), __('Change Password'), $html_header);
251276
?>
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>
252291
<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'>
254293
<input type='hidden' name='ref' value='<?php print sanitize_uri(get_request_var('ref')); ?>'>
255294
<input type='hidden' name='name' value='<?php print isset($user['username']) ? $user['username'] : '';?>'>
256295
<div class='loginTitle'>
@@ -264,113 +303,92 @@
264303
</tr>
265304
<tr>
266305
<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>
271307
</tr>
272308
<tr>
273309
<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>
278311
</tr>
279312
<tr>
280-
<td>&nbsp;</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'); ?>'>
282314
<?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') . "'>":"";?>
283315
</td>
284316
</tr>
285317
</table>
286318
</div>
287319
</form>
288320
<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();
317343
checkPasswordConfirm();
318344
} 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();
343348
}
349+
});
350+
}
351+
}
344352

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();
347363
}
364+
} else {
365+
$('#passconfirm').remove();
366+
}
367+
}
348368

349-
var password_change = $('#password_change').is(':checked');
369+
var password_change = $('#password_change').is(':checked');
350370

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');
355375

356-
/* clear passwords */
357-
var inputs = $('#password, #pass, #password_confirm, #passconfirm');
358-
inputs.tooltip();
376+
/* clear passwords */
377+
$('#password').val('');
378+
$('#password_confirm').val('');
359379

360-
$('#password, password_confirm').val('');
361-
//$('#password_confirm').val('');
380+
$('#password').keyup(function() {
381+
checkPassword();
382+
});
362383

363-
$('#password').keyup(function() {
364-
checkPassword();
365-
});
384+
$('#password_confirm').keyup(function() {
385+
checkPasswordConfirm();
386+
});
387+
});
388+
</script>
389+
<?php
366390

367-
$('#password_confirm').keyup(function() {
368-
checkPasswordConfirm();
369-
});
391+
include_once('./include/global_session.php');
370392

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

Comments
 (0)