|
| 1 | +<?php |
| 2 | +session_start(); |
| 3 | + |
| 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 | + |
| 22 | +if ((!empty($_POST['user'])) && (empty($_POST['code']))) { |
| 23 | + $v_user = escapeshellarg($_POST['user']); |
| 24 | + $user = $_POST['user']; |
| 25 | + $cmd="/usr/bin/sudo /usr/local/vesta/bin/v_list_user"; |
| 26 | + exec ($cmd." ".$v_user." json", $output, $return_var); |
| 27 | + if ( $return_var == 0 ) { |
| 28 | + $data = json_decode(implode('', $output), true); |
| 29 | + $rkey = $data[$user]['RKEY']; |
| 30 | + $fname = $data[$user]['FNAME']; |
| 31 | + $lname = $data[$user]['LNAME']; |
| 32 | + $contact = $data[$user]['CONTACT']; |
| 33 | + $to = $data[$user]['CONTACT']; |
| 34 | + $subject = 'Password Reset '.date("Y-m-d H:i:s"); |
| 35 | + $hostname = exec('hostname'); |
| 36 | + $from = "Vesta Control Panel <noreply@".$hostname.">"; |
| 37 | + if (!empty($fname)) { |
| 38 | + $mailtext = "Hello ".$fname." ".$lname.",\n"; |
| 39 | + } else { |
| 40 | + $mailtext = "Hello,\n"; |
| 41 | + } |
| 42 | + $mailtext .= "You recently asked to reset your control panel password. "; |
| 43 | + $mailtext .= "To complete your request, please follow this link:\n"; |
| 44 | + $mailtext .= "https://".$_SERVER['HTTP_HOST']."/reset/?action=confirm&user=".$user."&code=".$rkey."\n\n"; |
| 45 | + $mailtext .= "Alternately, you may go to https://".$_SERVER['HTTP_HOST']."/reset/?action=code&user=".$user." and enter the following password reset code:\n"; |
| 46 | + $mailtext .= $rkey."\n\n"; |
| 47 | + $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"; |
| 48 | + $mailtext .= "Thanks,\nThe VestaCP Team\n"; |
| 49 | + if (!empty($rkey)) send_email($to, $subject, $mailtext, $from); |
| 50 | + unset($output); |
| 51 | + } |
| 52 | + |
| 53 | + header("Location: /reset/?action=code&user=".$_POST['user']); |
| 54 | + exit; |
| 55 | +} |
| 56 | + |
| 57 | +if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) { |
| 58 | + if ( $_POST['password'] == $_POST['password_confirm'] ) { |
| 59 | + $v_user = escapeshellarg($_POST['user']); |
| 60 | + $user = $_POST['user']; |
| 61 | + $v_password = escapeshellarg($_POST['password']); |
| 62 | + $cmd="/usr/bin/sudo /usr/local/vesta/bin/v_list_user"; |
| 63 | + exec ($cmd." ".$v_user." json", $output, $return_var); |
| 64 | + if ( $return_var == 0 ) { |
| 65 | + $data = json_decode(implode('', $output), true); |
| 66 | + $rkey = $data[$user]['RKEY']; |
| 67 | + if ($rkey == $_POST['code']) { |
| 68 | + $cmd="/usr/bin/sudo /usr/local/vesta/bin/v_change_user_password"; |
| 69 | + exec ($cmd." ".$v_user." ".$v_password, $output, $return_var); |
| 70 | + if ( $return_var > 0 ) { |
| 71 | + $ERROR = "<a class=\"error\">ERROR: Internal error</a>"; |
| 72 | + } else { |
| 73 | + $_SESSION['user'] = $_POST['user']; |
| 74 | + header("Location: /"); |
| 75 | + exit; |
| 76 | + } |
| 77 | + } else { |
| 78 | + $ERROR = "<a class=\"error\">ERROR: Invalid username or code</a>"; |
| 79 | + } |
| 80 | + } else { |
| 81 | + $ERROR = "<a class=\"error\">ERROR: Invalid username or code</a>"; |
| 82 | + } |
| 83 | + } else { |
| 84 | + $ERROR = "<a class=\"error\">ERROR: Passwords not match</a>"; |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +if (empty($_GET['action'])) { |
| 89 | + require_once '../templates/reset_1.html'; |
| 90 | +} else { |
| 91 | + if ($_GET['action'] == 'code' ) { |
| 92 | + require_once '../templates/reset_2.html'; |
| 93 | + } |
| 94 | + if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) { |
| 95 | + require_once '../templates/reset_3.html'; |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +?> |
0 commit comments