PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/poweradmin-2.1.6/reset_password.php

#
PHP | 126 lines | 73 code | 26 blank | 27 comment | 12 complexity | 0f4328f6b5d99a8938666cb6826da2ed MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /* Poweradmin, a friendly web-based admin tool for PowerDNS.
  3. * See <https://www.poweradmin.org> for more details.
  4. *
  5. * Copyright 2007-2010 Rejo Zenger <rejo@zenger.nl>
  6. * Copyright 2010-2012 Poweradmin Development Team
  7. * <https://www.poweradmin.org/trac/wiki/Credits>
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /* Disable reset password functionality, because of improper implementation.
  23. If you know admin or any other user email, then you initiate password change
  24. to some random which will be send to him by email, but that can be done
  25. by some malicious user or some script, which can reset password every sec. */
  26. exit;
  27. session_start();
  28. /* TODO: reimplement displaying of errors/messages */
  29. function error($msg) {
  30. if ($msg) {
  31. echo " <div class=\"error\">Error: " . $msg . "</div>\n";
  32. } else {
  33. echo " <div class=\"error\">" . _('An unknown error has occurred.') . "</div>\n";
  34. }
  35. }
  36. include_once("inc/error.inc.php");
  37. include_once("inc/config-me.inc.php");
  38. if(!@include_once("inc/config.inc.php"))
  39. {
  40. error( _('You have to create a config.inc.php!') );
  41. }
  42. require_once("inc/database.inc.php");
  43. // Generates $db variable to access database.
  44. $db = dbConnect();
  45. if(isset($_POST['submit']) && $_POST['submit']) {
  46. global $db;
  47. $email = $_POST['emailaddr'];
  48. $query = "SELECT id, password, email FROM users WHERE email = " . $db->quote($email, 'text');
  49. $response = $db->query($query);
  50. if (PEAR::isError($response)) { error($response->getMessage()); return false; }
  51. $rinfo = $response->fetchRow();
  52. if(isset($rinfo['email'])) {
  53. $newpass = mt_rand();
  54. $query = "UPDATE users SET password = " . $db->quote(md5($newpass), 'text') . " WHERE id = " . $db->quote($rinfo['id'], 'integer') ;
  55. $response = $db->query($query);
  56. if (PEAR::isError($response)) { error($response->getMessage()); return false; }
  57. $to = $rinfo['email'];
  58. $subject = "Password Reset";
  59. $headers = "From: Poweradmin";
  60. $body = "New Password: ".$newpass."
  61. ";
  62. $mail_sent = @mail($to, $subject, $body, $headers);
  63. echo "A new password has been emailed to the registered email address. <a href='index.php'>(Return to login)</a>";
  64. // logout( _('Password has been changed, please login.'), 'success');
  65. } else {
  66. error(ERR_USER_WRONG_CURRENT_PASS);
  67. return false;
  68. }
  69. }
  70. global $iface_style;
  71. global $iface_title;
  72. global $ignore_install_dir;
  73. echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
  74. echo "<html>\n";
  75. echo " <head>\n";
  76. echo " <title>" . $iface_title ."</title>\n";
  77. echo " <link rel=stylesheet href=\"style/" . $iface_style . ".css\" type=\"text/css\">\n";
  78. echo " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
  79. echo " </head>\n";
  80. echo " <body>\n";
  81. if (! function_exists('session_start')) die(error('You have to install PHP session extension!'));
  82. if (! function_exists('_')) die(error('You have to install PHP gettext extension!'));
  83. if (! function_exists('mcrypt_encrypt')) die(error('You have to install PHP mcrypt extension!'));
  84. echo " <h2>" . _('Reset Password') . "</h2>\n";
  85. echo " <form method=\"post\" action=\"reset_password.php\">\n";
  86. echo " <table border=\"0\" cellspacing=\"4\">\n";
  87. echo " <tr>\n";
  88. echo " <td class=\"n\">" . _('Registered Email Address') . ":</td>\n";
  89. echo " <td class=\"n\"><input type=\"text\" class=\"input\" name=\"emailaddr\" value=\"\"></td>\n";
  90. echo " </tr>\n";
  91. echo " <tr>\n";
  92. echo " <td class=\"n\">&nbsp;</td>\n";
  93. echo " <td class=\"n\">\n";
  94. echo " <input type=\"submit\" class=\"button\" name=\"submit\" value=\"" . _('Reset password') . "\">\n";
  95. echo " </td>\n";
  96. echo " </tr>\n";
  97. echo " </table>\n";
  98. echo " </form>\n";
  99. include_once("inc/footer.inc.php");
  100. ?>