forked from poweradmin/poweradmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset_password.php
126 lines (100 loc) · 4.46 KB
/
reset_password.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
<?php
/* Poweradmin, a friendly web-based admin tool for PowerDNS.
* See <https://www.poweradmin.org> for more details.
*
* Copyright 2007-2010 Rejo Zenger <[email protected]>
* Copyright 2010-2012 Poweradmin Development Team
* <https://www.poweradmin.org/trac/wiki/Credits>
*
* 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 3 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Disable reset password functionality, because of improper implementation.
If you know admin or any other user email, then you initiate password change
to some random which will be send to him by email, but that can be done
by some malicious user or some script, which can reset password every sec. */
exit;
session_start();
/* TODO: reimplement displaying of errors/messages */
function error($msg) {
if ($msg) {
echo " <div class=\"error\">Error: " . $msg . "</div>\n";
} else {
echo " <div class=\"error\">" . _('An unknown error has occurred.') . "</div>\n";
}
}
include_once("inc/error.inc.php");
include_once("inc/config-me.inc.php");
if(!@include_once("inc/config.inc.php"))
{
error( _('You have to create a config.inc.php!') );
}
require_once("inc/database.inc.php");
// Generates $db variable to access database.
$db = dbConnect();
if(isset($_POST['submit']) && $_POST['submit']) {
global $db;
$email = $_POST['emailaddr'];
$query = "SELECT id, password, email FROM users WHERE email = " . $db->quote($email, 'text');
$response = $db->query($query);
if (PEAR::isError($response)) { error($response->getMessage()); return false; }
$rinfo = $response->fetchRow();
if(isset($rinfo['email'])) {
$newpass = mt_rand();
$query = "UPDATE users SET password = " . $db->quote(md5($newpass), 'text') . " WHERE id = " . $db->quote($rinfo['id'], 'integer') ;
$response = $db->query($query);
if (PEAR::isError($response)) { error($response->getMessage()); return false; }
$to = $rinfo['email'];
$subject = "Password Reset";
$headers = "From: Poweradmin";
$body = "New Password: ".$newpass."
";
$mail_sent = @mail($to, $subject, $body, $headers);
echo "A new password has been emailed to the registered email address. <a href='index.php'>(Return to login)</a>";
// logout( _('Password has been changed, please login.'), 'success');
} else {
error(ERR_USER_WRONG_CURRENT_PASS);
return false;
}
}
global $iface_style;
global $iface_title;
global $ignore_install_dir;
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
echo "<html>\n";
echo " <head>\n";
echo " <title>" . $iface_title ."</title>\n";
echo " <link rel=stylesheet href=\"style/" . $iface_style . ".css\" type=\"text/css\">\n";
echo " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
echo " </head>\n";
echo " <body>\n";
if (! function_exists('session_start')) die(error('You have to install PHP session extension!'));
if (! function_exists('_')) die(error('You have to install PHP gettext extension!'));
if (! function_exists('mcrypt_encrypt')) die(error('You have to install PHP mcrypt extension!'));
echo " <h2>" . _('Reset Password') . "</h2>\n";
echo " <form method=\"post\" action=\"reset_password.php\">\n";
echo " <table border=\"0\" cellspacing=\"4\">\n";
echo " <tr>\n";
echo " <td class=\"n\">" . _('Registered Email Address') . ":</td>\n";
echo " <td class=\"n\"><input type=\"text\" class=\"input\" name=\"emailaddr\" value=\"\"></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class=\"n\"> </td>\n";
echo " <td class=\"n\">\n";
echo " <input type=\"submit\" class=\"button\" name=\"submit\" value=\"" . _('Reset password') . "\">\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " </form>\n";
include_once("inc/footer.inc.php");
?>