index.php 4.0 KB

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