index.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. session_start();
  3. $TAB = 'RESET PASSWORD';
  4. //
  5. function send_email($to,$subject,$mailtext,$from) {
  6. $charset = "utf-8";
  7. $to = '<'.$to.'>';
  8. $boundary='--' . md5( uniqid("myboundary") );
  9. $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
  10. $priority = $priorities[2];
  11. $ctencoding = "8bit";
  12. $sep = chr(13) . chr(10);
  13. $disposition = "inline";
  14. $subject = "=?$charset?B?".base64_encode($subject)."?=";
  15. $header.="From: $from \nX-Priority: $priority\nCC: $cc\n";
  16. $header.="Mime-Version: 1.0\nContent-Type: text/plain; charset=$charset \n";
  17. $header.="Content-Transfer-Encoding: $ctencoding\nX-Mailer: Php/libMailv1.3\n";
  18. $message .= $mailtext;
  19. mail($to, $subject, $message, $header);
  20. }
  21. if ((!empty($_POST['user'])) && (empty($_POST['code']))) {
  22. $v_user = escapeshellarg($_POST['user']);
  23. $user = $_POST['user'];
  24. $cmd="/usr/bin/sudo /usr/local/vesta/bin/v-list-user";
  25. exec ($cmd." ".$v_user." json", $output, $return_var);
  26. if ( $return_var == 0 ) {
  27. $data = json_decode(implode('', $output), true);
  28. $rkey = $data[$user]['RKEY'];
  29. $fname = $data[$user]['FNAME'];
  30. $lname = $data[$user]['LNAME'];
  31. $contact = $data[$user]['CONTACT'];
  32. $to = $data[$user]['CONTACT'];
  33. $subject = 'Password Reset '.date("Y-m-d H:i:s");
  34. $hostname = exec('hostname');
  35. $from = "Vesta Control Panel <noreply@".$hostname.">";
  36. if (!empty($fname)) {
  37. $mailtext = "Hello ".$fname." ".$lname.",\n";
  38. } else {
  39. $mailtext = "Hello,\n";
  40. }
  41. $mailtext .= "You recently asked to reset your control panel password. ";
  42. $mailtext .= "To complete your request, please follow this link:\n";
  43. $mailtext .= "https://".$_SERVER['HTTP_HOST']."/reset/?action=confirm&user=".$user."&code=".$rkey."\n\n";
  44. $mailtext .= "Alternately, you may go to https://".$_SERVER['HTTP_HOST']."/reset/?action=code&user=".$user." and enter the following password reset code:\n";
  45. $mailtext .= $rkey."\n\n";
  46. $mailtext .= "If you did not request a new password please ignore this letter and accept our apologies — we didn't intend to disturb you.\n\n";
  47. $mailtext .= "--\nVesta Control Panel\n";
  48. if (!empty($rkey)) send_email($to, $subject, $mailtext, $from);
  49. unset($output);
  50. }
  51. header("Location: /reset/?action=code&user=".$_POST['user']);
  52. exit;
  53. }
  54. if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) {
  55. if ( $_POST['password'] == $_POST['password_confirm'] ) {
  56. $v_user = escapeshellarg($_POST['user']);
  57. $user = $_POST['user'];
  58. $v_password = escapeshellarg($_POST['password']);
  59. $cmd="/usr/bin/sudo /usr/local/vesta/bin/v-list-user";
  60. exec ($cmd." ".$v_user." json", $output, $return_var);
  61. if ( $return_var == 0 ) {
  62. $data = json_decode(implode('', $output), true);
  63. $rkey = $data[$user]['RKEY'];
  64. if ($rkey == $_POST['code']) {
  65. $cmd="/usr/bin/sudo /usr/local/vesta/bin/v-change-user-password";
  66. exec ($cmd." ".$v_user." ".$v_password, $output, $return_var);
  67. if ( $return_var > 0 ) {
  68. $ERROR = "<a class=\"error\">ERROR: Internal error</a>";
  69. } else {
  70. $_SESSION['user'] = $_POST['user'];
  71. header("Location: /");
  72. exit;
  73. }
  74. } else {
  75. $ERROR = "<a class=\"error\">ERROR: Invalid username or code</a>";
  76. }
  77. } else {
  78. $ERROR = "<a class=\"error\">ERROR: Invalid username or code</a>";
  79. }
  80. } else {
  81. $ERROR = "<a class=\"error\">ERROR: Passwords not match</a>";
  82. }
  83. }
  84. require_once '../templates/header.html';
  85. if (empty($_GET['action'])) {
  86. require_once '../templates/reset_1.html';
  87. } else {
  88. if ($_GET['action'] == 'code' ) {
  89. require_once '../templates/reset_2.html';
  90. }
  91. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  92. require_once '../templates/reset_3.html';
  93. }
  94. }
  95. ?>