index.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-list-user";
  14. exec ($cmd." ".$v_user." json", $output, $return_var);
  15. if ( $return_var == 0 ) {
  16. $data = json_decode(implode('', $output), true);
  17. $rkey = $data[$user]['RKEY'];
  18. $fname = $data[$user]['FNAME'];
  19. $lname = $data[$user]['LNAME'];
  20. $contact = $data[$user]['CONTACT'];
  21. $to = $data[$user]['CONTACT'];
  22. $subject = __('MAIL_RESET_SUBJECT',date("Y-m-d H:i:s"));
  23. $hostname = exec('hostname');
  24. $from = __('MAIL_FROM',$hostname);
  25. if (!empty($fname)) {
  26. $mailtext = __('GREETINGS_GORDON_FREEMAN',$fname,$lname);
  27. } else {
  28. $mailtext = __('GREETINGS');
  29. }
  30. 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')))){
  31. $mailtext .= __('PASSWORD_RESET_REQUEST',$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey);
  32. if (!empty($rkey)) send_email($to, $subject, $mailtext, $from);
  33. header("Location: /reset/?action=code&user=".$_POST['user']);
  34. exit;
  35. } else {
  36. $ERROR = "<a class=\"error\">".__('Invalid host domain')."</a>";
  37. }
  38. unset($output);
  39. }
  40. }
  41. if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) {
  42. if ( $_POST['password'] == $_POST['password_confirm'] ) {
  43. $v_user = escapeshellarg($_POST['user']);
  44. $user = $_POST['user'];
  45. $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-list-user";
  46. exec ($cmd." ".$v_user." json", $output, $return_var);
  47. if ( $return_var == 0 ) {
  48. $data = json_decode(implode('', $output), true);
  49. $rkey = $data[$user]['RKEY'];
  50. if (hash_equals($rkey, $_POST['code'])) {
  51. $v_password = tempnam("/tmp","vst");
  52. $fp = fopen($v_password, "w");
  53. fwrite($fp, $_POST['password']."\n");
  54. fclose($fp);
  55. $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-change-user-password";
  56. exec ($cmd." ".$v_user." ".$v_password, $output, $return_var);
  57. unlink($v_password);
  58. if ( $return_var > 0 ) {
  59. $ERROR = "<a class=\"error\">".__('An internal error occurred')."</a>";
  60. } else {
  61. $_SESSION['user'] = $_POST['user'];
  62. header("Location: /");
  63. exit;
  64. }
  65. } else {
  66. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  67. }
  68. } else {
  69. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  70. }
  71. } else {
  72. $ERROR = "<a class=\"error\">".__('Passwords not match')."</a>";
  73. }
  74. }
  75. // Detect language
  76. if (empty($_SESSION['language'])) $_SESSION['language'] = detect_user_language();
  77. if (empty($_GET['action'])) {
  78. require_once '../templates/header.html';
  79. require_once '../templates/reset_1.html';
  80. } else {
  81. require_once '../templates/header.html';
  82. if ($_GET['action'] == 'code' ) {
  83. require_once '../templates/reset_2.html';
  84. }
  85. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  86. require_once '../templates/reset_3.html';
  87. }
  88. }
  89. ?>