change_password.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. define('VESTA_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
  3. define('V_ROOT_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vesta' . DIRECTORY_SEPARATOR);
  4. require_once V_ROOT_DIR . 'config/Config.class.php';
  5. require_once V_ROOT_DIR . 'core/utils/Utils.class.php';
  6. require_once V_ROOT_DIR . 'core/VestaSession.class.php';
  7. require_once V_ROOT_DIR . 'core/Vesta.class.php';
  8. require_once V_ROOT_DIR . 'core/exceptions/SystemException.class.php';
  9. require_once V_ROOT_DIR . 'core/exceptions/ProtectionException.class.php';
  10. require_once V_ROOT_DIR . 'core/utils/Message.class.php';
  11. require_once V_ROOT_DIR . 'core/Request.class.php';
  12. require_once V_ROOT_DIR . 'api/AjaxHandler.php';
  13. class ChangePassword
  14. {
  15. public function dispatch()
  16. {
  17. if (empty($_GET['v'])) {
  18. return $this->renderError('General error');
  19. }
  20. $key = addslashes(htmlspecialchars($_GET['v']));
  21. $users = Vesta::execute(Vesta::V_LIST_SYS_USERS, 'json');
  22. $email_matched_count = array();
  23. /*if (strcmp($real_key, $key_sha1) != 0) {
  24. return $this->renderError('Invalid keys');
  25. }*/
  26. foreach ($users['data'] as $username => $user) {
  27. if ($user['RKEY'] == trim($key)) {
  28. $email_matched_count[] = array_merge(array('USERNAME' => $username), $user);
  29. }
  30. }
  31. if (isset($_POST['action']) && $_POST['action'] == 'change') {
  32. return $this->doChangePassword($email_matched_count);
  33. }
  34. return $this->showResetForm();
  35. }
  36. protected function doChangePassword($users)
  37. {
  38. if ($_POST['secret_code'] != $_POST['confirm_secret_code']) {
  39. return $this->showResetForm('Passwords don\'t match');
  40. }
  41. if (strlen($_POST['secret_code']) < 6) {
  42. return $this->showResetForm('Passwords is too short');
  43. }
  44. if (strlen($_POST['secret_code']) > 255) {
  45. return $this->showResetForm('Passwords is too long');
  46. }
  47. $success = true;
  48. foreach ($users as $user) {
  49. $rs = Vesta::execute(Vesta::V_CHANGE_SYS_USER_PASSWORD, array('USER' => $user['USERNAME'],
  50. 'PASSWORD' => $_POST['secret_code']));
  51. if (!$rs) {
  52. $success = false;
  53. }
  54. }
  55. if (!$success) {
  56. return $this->showResetForm('Something went wrong. Please contact support.');
  57. }
  58. return $this->showSuccessTpl();
  59. }
  60. public function showSuccessTpl()
  61. {
  62. print <<<HTML
  63. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  64. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
  65. <head>
  66. <title>Vesta Control Panel</title>
  67. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  68. <meta http-equiv="imagetoolbar" content="false" />
  69. <link rel="shortcut icon" href="images/fav.ico" type="image/x-icon">
  70. <link rel="stylesheet" media="all" type="text/css" href="css/reset2.css" />
  71. <link rel="stylesheet" media="all" type="text/css" href="css/main.css" />
  72. <link rel="stylesheet" media="all" type="text/css" href="css/vesta-login-form.css" />
  73. <!--[if lt IE 8]>
  74. <link rel="stylesheet" type="text/css" href="http://dl.dropbox.com/u/1750887/projects/vesta2/css/ie.css" />
  75. <![endif]-->
  76. </head>
  77. <body class="page-auth">
  78. <div id="change-psw-block" class="page2">
  79. <div class="b-auth-form">
  80. <div class="b-auth-form-wrap">
  81. <img width="72" height="24" alt="" src="/images/vesta-logo-2011-12-14.png" class="vesta-logo">
  82. <span style="color: #5E696B; float: right; margin-top: -48px;">~!:VERSION~!</span>
  83. <div class="b-client-title">
  84. <span class="client-title-wrap">Control Panel<i class="planets">&nbsp;</i></span>
  85. </div>
  86. <form id="change_psw-form" method="post" action="" class="auth">
  87. <input type="hidden" value="change" name="action">
  88. <div class="success-box" id="change-psw-success">Password successfully changed.</div>
  89. </form>
  90. <p class="forgot-pwd">&nbsp;</p>
  91. <div class="footnotes cc">
  92. <p class="additional-info">For questions please contact <a href="mailto:info@vestacp.com" class="questions-url">info@vestacp.com</a></p>
  93. <address class="imprint">&copy; 2011 Vesta Control Panel</address>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. </body>
  99. </html>
  100. HTML;
  101. }
  102. public function showResetForm($error_msg = '')
  103. {
  104. if (!empty($error_msg)) {
  105. $error_msg = '<i>'.$error_msg.'</i>';
  106. }
  107. print <<<HTML
  108. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  109. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
  110. <head>
  111. <title>Vesta Control Panel</title>
  112. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  113. <meta http-equiv="imagetoolbar" content="false" />
  114. <link rel="shortcut icon" href="images/fav.ico" type="image/x-icon">
  115. <link rel="stylesheet" media="all" type="text/css" href="css/reset2.css" />
  116. <link rel="stylesheet" media="all" type="text/css" href="css/main.css" />
  117. <link rel="stylesheet" media="all" type="text/css" href="css/vesta-login-form.css" />
  118. <!--[if lt IE 8]>
  119. <link rel="stylesheet" type="text/css" href="http://dl.dropbox.com/u/1750887/projects/vesta2/css/ie.css" />
  120. <![endif]-->
  121. </head>
  122. <body class="page-auth">
  123. <div id="change-psw-block" class="page2">
  124. <div class="b-auth-form">
  125. <div class="b-auth-form-wrap">
  126. <img width="72" height="24" alt="" src="/images/vesta-logo-2011-12-14.png" class="vesta-logo">
  127. <span style="color: #5E696B; float: right; margin-top: -48px;">~!:VERSION~!</span>
  128. <div class="b-client-title">
  129. <span class="client-title-wrap">Control Panel<i class="planets">&nbsp;</i></span>
  130. </div>
  131. <form id="change_psw-form" method="post" action="" class="auth">
  132. <input type="hidden" value="change" name="action">
  133. <div class="form-row cc">
  134. <label for="password" class="field-label">New Password</label>
  135. <input type="password" tabindex="1" id="password" class="field-text" name="secret_code">
  136. </div>
  137. <div class="form-row cc">
  138. <label for="confirm_password" class="field-label">ONE MORE TIME</label>
  139. <input type="password" tabindex="1" id="confirm_password" class="field-text" name="confirm_secret_code">
  140. </div>
  141. <div class="form-row cc last-row">
  142. <input type="submit" tabindex="4" value="Change Password" class="sumbit-btn">
  143. </div>
  144. </form>
  145. <p class="forgot-pwd">&nbsp;</p>
  146. <div class="footnotes cc">
  147. <p class="additional-info">For questions please contact <a href="mailto:info@vestacp.com" class="questions-url">info@vestacp.com</a></p>
  148. <address class="imprint">&copy; 2011 Vesta Control Panel</address>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. </body>
  154. </html>
  155. <!--
  156. <center>
  157. vesta password reset form
  158. <hr />
  159. {$error_msg}
  160. <form action="" method="POST">
  161. <table>
  162. <tr>
  163. <td>
  164. <input type="hidden" name="action" value="change" />
  165. <label>Enter secret code:</label>
  166. </td>
  167. <td>
  168. <input type="password" name="secret_code" value="" />
  169. </td>
  170. </tr>
  171. <tr>
  172. <td>
  173. <label>Enter new password:</label>
  174. </td>
  175. <td>
  176. <input type="password" name="confirm_secret_code" value="" />
  177. </td>
  178. </tr>
  179. <tr>
  180. <td colspan="2">
  181. <input type="submit" name="Apply" />
  182. </td>
  183. </tr>
  184. </table>
  185. </form>
  186. </center> -->
  187. HTML;
  188. }
  189. public function renderError($message)
  190. {
  191. print <<<HTML
  192. {$message}
  193. HTML;
  194. }
  195. }
  196. $changePassword = new ChangePassword();
  197. $changePassword->dispatch();
  198. ?>