index.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. session_start();
  3. define('NO_AUTH_REQUIRED',true);
  4. $TAB = 'RESET PASSWORD';
  5. if (isset($_SESSION['user'])) {
  6. header("Location: /list/user");
  7. }
  8. // Main include
  9. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  10. if ((!empty($_POST['user'])) && (empty($_POST['code']))) {
  11. $v_user = escapeshellarg($_POST['user']);
  12. $user = $_POST['user'];
  13. $email = $_POST['email'];
  14. $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-list-user";
  15. exec ($cmd." ".$v_user." json", $output, $return_var);
  16. if ( $return_var == 0 ) {
  17. $data = json_decode(implode('', $output), true);
  18. if($email == $data[$user]['CONTACT']){
  19. //genrate new rkey
  20. exec ("/usr/bin/sudo /usr/local/hestia/bin/v-change-user-rkey ".$v_user."", $output, $return_var);
  21. unset($output);
  22. exec ($cmd." ".$v_user." json", $output, $return_var);
  23. $data = json_decode(implode('', $output), true);
  24. $rkey = $data[$user]['RKEY'];
  25. $fname = $data[$user]['FNAME'];
  26. $lname = $data[$user]['LNAME'];
  27. $contact = $data[$user]['CONTACT'];
  28. $to = $data[$user]['CONTACT'];
  29. $subject = __('MAIL_RESET_SUBJECT',date("Y-m-d H:i:s"));
  30. $hostname = exec('hostname');
  31. $from = __('MAIL_FROM',$hostname);
  32. if (!empty($fname)) {
  33. $mailtext = __('GREETINGS_GORDON_FREEMAN',$fname,$lname);
  34. } else {
  35. $mailtext = __('GREETINGS');
  36. }
  37. 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')))){
  38. $mailtext .= __('PASSWORD_RESET_REQUEST',$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey);
  39. if (!empty($rkey)) send_email($to, $subject, $mailtext, $from);
  40. header("Location: /reset/?action=code&user=".$_POST['user']);
  41. exit;
  42. } else {
  43. $ERROR = "<a class=\"error\">".__('Invalid host domain')."</a>";
  44. }
  45. }
  46. }
  47. unset($output);
  48. }
  49. if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) {
  50. if ( $_POST['password'] == $_POST['password_confirm'] ) {
  51. $v_user = escapeshellarg($_POST['user']);
  52. $user = $_POST['user'];
  53. $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-list-user";
  54. exec ($cmd." ".$v_user." json", $output, $return_var);
  55. if ( $return_var == 0 ) {
  56. $data = json_decode(implode('', $output), true);
  57. $rkey = $data[$user]['RKEY'];
  58. if (hash_equals($rkey, $_POST['code'])) {
  59. unset($output);
  60. exec("/usr/bin/sudo /usr/local/hestia/bin/v-get-user-value ".$v_user." RKEYEXP", $output,$return_var);
  61. if($output[0] > time() - 900){
  62. $v_password = tempnam("/tmp","vst");
  63. $fp = fopen($v_password, "w");
  64. fwrite($fp, $_POST['password']."\n");
  65. fclose($fp);
  66. $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-change-user-password";
  67. exec ($cmd." ".$v_user." ".$v_password, $output, $return_var);
  68. unlink($v_password);
  69. if ( $return_var > 0 ) {
  70. sleep(5);
  71. $ERROR = "<a class=\"error\">".__('An internal error occurred')."</a>";
  72. } else {
  73. $_SESSION['user'] = $_POST['user'];
  74. header("Location: /");
  75. exit;
  76. }
  77. }else{
  78. sleep(5);
  79. $ERROR = "<a class=\"error\">".__('Code has been expired')."</a>";
  80. }
  81. } else {
  82. sleep(5);
  83. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  84. }
  85. } else {
  86. sleep(5);
  87. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  88. }
  89. } else {
  90. $ERROR = "<a class=\"error\">".__('Passwords not match')."</a>";
  91. }
  92. }
  93. // Detect language
  94. if (empty($_SESSION['language'])) $_SESSION['language'] = detect_user_language();
  95. if (empty($_GET['action'])) {
  96. require_once '../templates/header.html';
  97. require_once '../templates/reset_1.html';
  98. } else {
  99. require_once '../templates/header.html';
  100. if ($_GET['action'] == 'code' ) {
  101. require_once '../templates/reset_2.html';
  102. }
  103. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  104. require_once '../templates/reset_3.html';
  105. }
  106. }
  107. ?>