forked from Cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_changepassword.php
233 lines (208 loc) · 9.74 KB
/
auth_changepassword.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2015 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
include('./include/global.php');
// If the user is not logged in, redirect them to the login page
if (!isset($_SESSION['sess_user_id'])) {
if (isset($_SERVER['HTTP_REFERER'])) {
header('Location: ' . $_SERVER['HTTP_REFERER']);
}else{
header('Location: index.php');
}
header('Location: index.php');
exit;
}
$user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', array($_SESSION['sess_user_id']));
$version = db_fetch_cell('SELECT cacti FROM version');
$auth_method = read_config_option('auth_method');
if ($auth_method != 1 && $user['realm'] != 0) {
raise_message('nodomainpassword');
if (isset($_SERVER['HTTP_REFERER'])) {
header('Location: ' . $_SERVER['HTTP_REFERER']);
}else{
header('Location: index.php');
}
exit;
}
if ($user['password_change'] != 'on') {
raise_message('nopassword');
if (isset($_SERVER['HTTP_REFERER'])) {
header('Location: ' . $_SERVER['HTTP_REFERER']);
}else{
header('Location: index.php');
}
exit;
}
/* find out if we are logged in as a 'guest user' or not, if we are redirect away from password change */
if (sizeof($user) && $user['username'] == read_config_option('guest_user')) {
header('Location: graph_view.php');
exit;
}
/* default to !bad_password */
$bad_password = false;
$errorMessage = '';
/* set default action */
if (!isset($_REQUEST['action'])) { $_REQUEST['action'] = ''; }
switch ($_REQUEST['action']) {
case 'changepassword':
if ($user['password'] != md5($_POST['current_password'])) {
$bad_password = true;
$errorMessage = "<span color='#FF0000'>Your current password is not correct. Please try again.</span>";
}
if ($user['password'] == md5($_POST['password'])) {
$bad_password = true;
$errorMessage = "<span color='#FF0000'>Your new password can not be the same as the old password. Please try again.</span>";
}
// Secpass checking
$error = secpass_check_pass($_POST['password']);
if ($error != '') {
$bad_password = true;
$errorMessage = "<span color='#FF0000'>$error</span>";
}
if (!secpass_check_history($_SESSION['sess_user_id'], $_POST['password'])) {
$bad_password = true;
$errorMessage = "<span color='#FF0000'>You can not use a previously entered password!</span>";
}
if ($bad_password == false && $_POST['password'] == $_POST['confirm'] && $_POST['password'] != '') {
// Password change is good to go
if (read_config_option('secpass_expirepass') > 0) {
db_execute("UPDATE user_auth SET lastchange = " . time() . " WHERE id = " . intval($_SESSION['sess_user_id']) . " AND realm = 0 AND enabled = 'on'");
}
$history = intval(read_config_option('secpass_history'));
if ($history > 0) {
$h = db_fetch_row_prepared("SELECT password, password_history FROM user_auth WHERE id = ? AND realm = 0 AND enabled = 'on'", array($_SESSION['sess_user_id']));
$op = $h['password'];
$h = explode('|', $h['password_history']);
while (count($h) > $history - 1) {
array_shift($h);
}
$h[] = $op;
$h = implode('|', $h);
db_execute_prepared("UPDATE user_auth SET password_history = ? WHERE id = ? AND realm = 0 AND enabled = 'on'", array($h, $_SESSION['sess_user_id']));
}
db_execute_prepared('INSERT IGNORE INTO user_log (username, result, ip) VALUES (?, 3, ?)', array($user['username'], $_SERVER['REMOTE_ADDR']));
db_execute_prepared("UPDATE user_auth SET must_change_password = '', password = ? WHERE id = ?", array(md5($_POST['password']), $_SESSION['sess_user_id']));
kill_session_var('sess_change_password');
/* ok, at the point the user has been sucessfully authenticated; so we must
decide what to do next */
/* if no console permissions show graphs otherwise, pay attention to user setting */
$realm_id = $user_auth_realm_filenames['index.php'];
$has_console = db_fetch_cell('SELECT realm_id FROM user_auth_realm WHERE user_id = ? AND realm_id = ?', array($_SESSION['sess_user_id'], $realm_id));
if (basename($_POST['ref']) == 'auth_changepassword.php' || basename($_POST['ref']) == '') {
if ($has_console) {
$_POST['ref'] = 'index.php';
}else{
$_POST['ref'] = 'graph_view.php';
}
}
if (!empty($has_console)) {
switch ($user['login_opts']) {
case '1': /* referer */
header('Location: ' . sanitize_uri($_POST['ref'])); break;
case '2': /* default console page */
header('Location: index.php'); break;
case '3': /* default graph page */
header('Location: graph_view.php'); break;
default:
api_plugin_hook_function('login_options_navigate', $user['login_opts']);
}
}else{
header('Location: graph_view.php');
}
exit;
}else{
$bad_password = true;
}
break;
}
if (api_plugin_hook_function('custom_password', OPER_MODE_NATIVE) == OPER_MODE_RESKIN) {
exit;
}
if ($bad_password && $errorMessage == "") {
$errorMessage = "<span color='#FF0000'>Your new passwords do not match, please retype.</span>";
}elseif ($_REQUEST['action'] == 'force') {
$errorMessage = "<span color='#FF0000'>*** Forced password change ***</span>";
}
print "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n";
print "<html>\n";
print "<head>\n";
print "\t<title>Change Password</title>\n";
print "\t<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>\n";
print "\t<link href='" . $config['url_path'] . "include/themes/" . read_config_option('selected_theme') . "/main.css' type='text/css' rel='stylesheet'>\n";
print "\t<link href='" . $config['url_path'] . "include/themes/" . read_config_option('selected_theme') . "/jquery-ui.css' type='text/css' rel='stylesheet'>\n";
print "\t<link href='" . $config['url_path'] . "images/favicon.ico' rel='shortcut icon'>\n";
print "\t<script type='text/javascript' src='" . $config['url_path'] . "include/js/jquery.js' language='javascript'></script>\n";
print "\t<script type='text/javascript' src='" . $config['url_path'] . "include/js/jquery-ui.js' language='javascript'></script>\n";
print "\t<script type='text/javascript' src='" . $config['url_path'] . "include/js/jquery.cookie.js' language='javascript'></script>\n";
print "\t<script type='text/javascript' src='" . $config['url_path'] . "include/js/jquery.hotkeys.js'></script>\n";
print "\t<script type='text/javascript' src='" . $config['url_path'] . "include/layout.js'></script>\n";
print "\t<script type='text/javascript' src='" . $config['url_path'] . "include/themes/" . read_config_option('selected_theme') . "/main.js'></script>\n";
print "<script type='text/javascript'>var theme='" . read_config_option('selected_theme') . "';</script>\n";
print "</head>\n";
print "<body class='loginBody'>
<div class='loginLeft'></div>
<div class='loginCenter'>
<div class='loginArea'>
<div class='cactiLogoutLogo'></div>
<legend>Change Password</legend>
<form name='login' method='post' action='" . basename($_SERVER['PHP_SELF']) . "'>
<input type='hidden' name='action' value='changepassword'>
<input type='hidden' name='ref' value='" . (isset($_REQUEST['ref']) ? sanitize_uri($_REQUEST['ref']) : '') . "'>
<input type='hidden' name='name' value='" . (isset($user['username']) ? $user['username'] : '') . "'>
<div class='loginTitle'>
<p>Please enter your current password and your new<br>Cacti password.</p>
</div>
<div class='cactiLogin'>
<table class='cactiLoginTable'>
<tr>
<td>Current password</td>
<td><input type='password' id='current' name='current_password' autocomplete='off' size='20' placeholder='********'></td>
</tr>
<tr>
<td>New password</td>
<td><input type='password' name='password' autocomplete='off' size='20' placeholder='********'></td>
</tr>
<tr>
<td>Confirm new password</td>
<td><input type='password' name='confirm' autocomplete='off' size='20' placeholder='********'></td>
</tr>
<tr>
<td><input type='submit' value='Save'></td>
</tr>
</table>
</div>
</form>
<div class='loginErrors'>" . $errorMessage . "</div>
</div>
<div class='versionInfo'>Version " . $version . " | " . COPYRIGHT_YEARS_SHORT . "</div>
</div>
<div class='loginRight'></div>
<script type='text/javascript'>
$(function() {
$('#current').focus();
$('.loginLeft').css('width',parseInt($(window).width()*0.33)+'px');
$('.loginRight').css('width',parseInt($(window).width()*0.33)+'px');
});
</script>
</body>
</html>\n";