|
13 | 13 | if ((!empty($_POST['user'])) && (empty($_POST['code']))) { |
14 | 14 | $v_user = escapeshellarg($_POST['user']); |
15 | 15 | $user = $_POST['user']; |
| 16 | + $email = $_POST['email']; |
16 | 17 | $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-list-user"; |
17 | 18 | exec ($cmd." ".$v_user." json", $output, $return_var); |
18 | 19 | if ( $return_var == 0 ) { |
19 | 20 | $data = json_decode(implode('', $output), true); |
20 | | - $rkey = $data[$user]['RKEY']; |
21 | | - $fname = $data[$user]['FNAME']; |
22 | | - $lname = $data[$user]['LNAME']; |
23 | | - $contact = $data[$user]['CONTACT']; |
24 | | - $to = $data[$user]['CONTACT']; |
25 | | - $subject = __('MAIL_RESET_SUBJECT',date("Y-m-d H:i:s")); |
26 | | - $hostname = exec('hostname'); |
27 | | - $from = __('MAIL_FROM',$hostname); |
28 | | - if (!empty($fname)) { |
29 | | - $mailtext = __('GREETINGS_GORDON_FREEMAN',$fname,$lname); |
30 | | - } else { |
31 | | - $mailtext = __('GREETINGS'); |
32 | | - } |
33 | | - if (in_array(str_replace(':'.$_SERVER['SERVER_PORT'],'.conf',$_SERVER['HTTP_HOST']), array_merge(scandir('/etc/nginx/conf.d'),scandir('/etc/nginx/conf.d/domains'),scandir('/etc/apache2/conf.d/domains'),scandir('/etc/apache2/conf.d')))){ |
34 | | - $mailtext .= __('PASSWORD_RESET_REQUEST',$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey); |
35 | | - if (!empty($rkey)) send_email($to, $subject, $mailtext, $from); |
36 | | - header("Location: /reset/?action=code&user=".$_POST['user']); |
37 | | - exit; |
38 | | - } else { |
39 | | - $ERROR = "<a class=\"error\">".__('Invalid host domain')."</a>"; |
40 | | - } |
41 | | - unset($output); |
| 21 | + if($email == $data[$user]['CONTACT']){ |
| 22 | + //genrate new rkey |
| 23 | + exec ("/usr/bin/sudo /usr/local/hestia/bin/v-change-user-rkey ".$v_user."", $output, $return_var); |
| 24 | + unset($output); |
| 25 | + exec ($cmd." ".$v_user." json", $output, $return_var); |
| 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 = __('MAIL_RESET_SUBJECT',date("Y-m-d H:i:s")); |
| 33 | + $hostname = exec('hostname'); |
| 34 | + $from = __('MAIL_FROM',$hostname); |
| 35 | + if (!empty($fname)) { |
| 36 | + $mailtext = __('GREETINGS_GORDON_FREEMAN',$fname,$lname); |
| 37 | + } else { |
| 38 | + $mailtext = __('GREETINGS'); |
| 39 | + } |
| 40 | + if (in_array(str_replace(':'.$_SERVER['SERVER_PORT'],'.conf',$_SERVER['HTTP_HOST']), array_merge(scandir('/etc/nginx/conf.d'),scandir('/etc/nginx/conf.d/domains'),scandir('/etc/apache2/conf.d/domains'),scandir('/etc/apache2/conf.d')))){ |
| 41 | + $mailtext .= __('PASSWORD_RESET_REQUEST',$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey); |
| 42 | + if (!empty($rkey)) send_email($to, $subject, $mailtext, $from); |
| 43 | + header("Location: /reset/?action=code&user=".$_POST['user']); |
| 44 | + exit; |
| 45 | + } else { |
| 46 | + $ERROR = "<a class=\"error\">".__('Invalid host domain')."</a>"; |
| 47 | + } |
| 48 | + } |
42 | 49 | } |
| 50 | + unset($output); |
43 | 51 | } |
44 | 52 |
|
45 | 53 | if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) { |
|
52 | 60 | $data = json_decode(implode('', $output), true); |
53 | 61 | $rkey = $data[$user]['RKEY']; |
54 | 62 | if (hash_equals($rkey, $_POST['code'])) { |
55 | | - $v_password = tempnam("/tmp","vst"); |
56 | | - $fp = fopen($v_password, "w"); |
57 | | - fwrite($fp, $_POST['password']."\n"); |
58 | | - fclose($fp); |
59 | | - $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-change-user-password"; |
60 | | - exec ($cmd." ".$v_user." ".$v_password, $output, $return_var); |
61 | | - unlink($v_password); |
62 | | - if ( $return_var > 0 ) { |
63 | | - $ERROR = "<a class=\"error\">".__('An internal error occurred')."</a>"; |
64 | | - } else { |
65 | | - $_SESSION['user'] = $_POST['user']; |
66 | | - header("Location: /"); |
67 | | - exit; |
| 63 | + unset($output); |
| 64 | + exec("/usr/bin/sudo /usr/local/hestia/bin/v-get-user-value ".$v_user." RKEYEXP", $output,$return_var); |
| 65 | + if($output[0] > time() - 900){ |
| 66 | + $v_password = tempnam("/tmp","vst"); |
| 67 | + $fp = fopen($v_password, "w"); |
| 68 | + fwrite($fp, $_POST['password']."\n"); |
| 69 | + fclose($fp); |
| 70 | + $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-change-user-password"; |
| 71 | + exec ($cmd." ".$v_user." ".$v_password, $output, $return_var); |
| 72 | + unlink($v_password); |
| 73 | + if ( $return_var > 0 ) { |
| 74 | + sleep(5); |
| 75 | + $ERROR = "<a class=\"error\">".__('An internal error occurred')."</a>"; |
| 76 | + } else { |
| 77 | + $_SESSION['user'] = $_POST['user']; |
| 78 | + header("Location: /"); |
| 79 | + exit; |
| 80 | + } |
| 81 | + }else{ |
| 82 | + sleep(5); |
| 83 | + $ERROR = "<a class=\"error\">".__('Code has been expired')."</a>"; |
68 | 84 | } |
69 | 85 | } else { |
| 86 | + sleep(5); |
70 | 87 | $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>"; |
71 | 88 | } |
72 | 89 | } else { |
| 90 | + sleep(5); |
73 | 91 | $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>"; |
74 | 92 | } |
75 | 93 | } else { |
|
0 commit comments