change_password.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. require_once V_ROOT_DIR . 'api/MAIN.class.php';
  14. class ChangePassword
  15. {
  16. public function dispatch()
  17. {
  18. if (empty($_GET['v'])) {
  19. return $this->renderError('General error');
  20. }
  21. $key = addslashes(htmlspecialchars($_GET['v']));
  22. $cmd = Config::get('sudo_path')." ".Config::get('vesta_functions_path').Vesta::V_LIST_SYS_USERS." 'json'";
  23. exec($cmd, $output, $return);
  24. $users = json_decode(implode('', $output), true);
  25. $email_matched_count = array();
  26. foreach ($users 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. $cmd = Config::get('sudo_path')." ".Config::get('vesta_functions_path').Vesta::V_CHANGE_SYS_USER_PASSWORD." ".$user['USERNAME']." ".$_POST['secret_code'];
  50. exec($cmd, $output, $return);
  51. if (!$return) {
  52. $success = false;
  53. }
  54. }
  55. if (!$success) {
  56. $main = new MAIN();
  57. $about = json_decode($main->aboutExecute(), TRUE);
  58. return $this->showResetForm('Something went wrong. Please contact support: '.$about['data']['company_email']);
  59. }
  60. return $this->showSuccessTpl();
  61. }
  62. public function showSuccessTpl()
  63. {
  64. $main = new MAIN();
  65. $about = json_decode($main->aboutExecute(), TRUE);
  66. $current_year = date("Y");
  67. print <<<HTML
  68. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  69. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
  70. <head>
  71. <title>Vesta Control Panel</title>
  72. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  73. <meta http-equiv="imagetoolbar" content="false" />
  74. <link rel="shortcut icon" href="images/fav.ico" type="image/x-icon">
  75. <link rel="stylesheet" media="all" type="text/css" href="css/reset2.css" />
  76. <link rel="stylesheet" media="all" type="text/css" href="css/main.css" />
  77. <link rel="stylesheet" media="all" type="text/css" href="css/vesta-login-form.css" />
  78. <!--[if lt IE 8]>
  79. <link rel="stylesheet" type="text/css" href="http://dl.dropbox.com/u/1750887/projects/vesta2/css/ie.css" />
  80. <![endif]-->
  81. </head>
  82. <body class="page-auth">
  83. <div id="change-psw-block" class="page2">
  84. <div class="b-auth-form">
  85. <div class="b-auth-form-wrap">
  86. <img width="72" height="24" alt="" src="/images/vesta-logo-2011-12-14.png" class="vesta-logo">
  87. <span style="color: #5E696B; float: right; margin-top: -48px;">{$about['data']['version_name']}</span>
  88. <div class="b-client-title">
  89. <span class="client-title-wrap">Control Panel<i class="planets">&nbsp;</i></span>
  90. </div>
  91. <form id="change_psw-form" method="post" action="" class="auth">
  92. <input type="hidden" value="change" name="action">
  93. <div class="success-box" id="change-psw-success">Password successfully changed.</div>
  94. </form>
  95. <p class="forgot-pwd"><a href="/" class="forgot-pwd-url">Back to login?</a></p>
  96. <div class="footnotes cc">
  97. <p class="additional-info">For questions please contact <a href="mailto:{$about['data']['company_email']}" class="questions-url">{$about['data']['company_email']}</a></p>
  98. <address class="imprint">&copy; {$current_year} Vesta Control Panel</address>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </body>
  104. </html>
  105. HTML;
  106. }
  107. public function showResetForm($error_msg = '')
  108. {
  109. if (!empty($error_msg)) {
  110. $error_msg = '<div class="error-box" id="auth-error">'.$error_msg.'</div>';
  111. }
  112. $main = new MAIN();
  113. $about = json_decode($main->aboutExecute(), TRUE);
  114. $current_year = date("Y");
  115. print <<<HTML
  116. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  117. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
  118. <head>
  119. <title>Vesta Control Panel</title>
  120. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  121. <meta http-equiv="imagetoolbar" content="false" />
  122. <link rel="shortcut icon" href="images/fav.ico" type="image/x-icon">
  123. <link rel="stylesheet" media="all" type="text/css" href="css/reset2.css" />
  124. <link rel="stylesheet" media="all" type="text/css" href="css/main.css" />
  125. <link rel="stylesheet" media="all" type="text/css" href="css/vesta-login-form.css" />
  126. <!--[if lt IE 8]>
  127. <link rel="stylesheet" type="text/css" href="http://dl.dropbox.com/u/1750887/projects/vesta2/css/ie.css" />
  128. <![endif]-->
  129. </head>
  130. <body class="page-auth">
  131. <div id="change-psw-block" class="page2">
  132. <div class="b-auth-form">
  133. <div class="b-auth-form-wrap">
  134. <a href="/">
  135. <img width="72" height="24" alt="" src="/images/vesta-logo-2011-12-14.png" class="vesta-logo">
  136. </a>
  137. <span style="color: #5E696B; float: right; margin-top: -48px;">{$about['data']['version_name']}</span>
  138. <div class="b-client-title">
  139. <span class="client-title-wrap">Control Panel<i class="planets">&nbsp;</i></span>
  140. </div>
  141. <form id="change_psw-form" method="post" action="" class="auth">
  142. <input type="hidden" value="change" name="action">
  143. <div class="form-row cc">
  144. <label for="password" class="field-label">New Password</label>
  145. <input type="password" tabindex="1" id="password" class="field-text" name="secret_code">
  146. </div>
  147. <div class="form-row cc">
  148. <label for="confirm_password" class="field-label">ONE MORE TIME</label>
  149. <input type="password" tabindex="1" id="confirm_password" class="field-text" name="confirm_secret_code">
  150. </div>
  151. {$error_msg}
  152. <div class="form-row cc last-row">
  153. <input type="submit" tabindex="4" value="Change Password" class="sumbit-btn">
  154. </div>
  155. </form>
  156. <p class="forgot-pwd"><a href="/" class="forgot-pwd-url">Back to login?</a></p>\
  157. <div class="footnotes cc">
  158. <p class="additional-info">For questions please contact <a href="mailto:{$about['data']['company_email']}" class="questions-url">{$about['data']['company_email']}</a></p>
  159. <address class="imprint">&copy; {$current_year} Vesta Control Panel</address>
  160. </div>
  161. </div>
  162. </div>
  163. </div>
  164. </body>
  165. </html>
  166. HTML;
  167. }
  168. public function renderError($message)
  169. {
  170. print <<<HTML
  171. {$message}
  172. HTML;
  173. }
  174. }
  175. $changePassword = new ChangePassword();
  176. $changePassword->dispatch();
  177. ?>