index.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. $name = $data[$user]['NAME'];
  26. $contact = $data[$user]['CONTACT'];
  27. $to = $data[$user]['CONTACT'];
  28. $subject = sprintf(_('MAIL_RESET_SUBJECT'),date("Y-m-d H:i:s"));
  29. $hostname = exec('hostname');
  30. $from = sprintf(_('MAIL_FROM'),$hostname);
  31. if (!empty($name)) {
  32. $mailtext = sprintf(_('GREETINGS_GORDON'),$name);
  33. } else {
  34. $mailtext = _('GREETINGS');
  35. }
  36. 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')))){
  37. $mailtext .= sprintf(_('PASSWORD_RESET_REQUEST'),$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey);
  38. if (!empty($rkey)) send_email($to, $subject, $mailtext, $from);
  39. header("Location: /reset/?action=code&user=".$_POST['user']);
  40. exit;
  41. } else {
  42. $ERROR = "<a class=\"error\">"._('Invalid host domain')."</a>";
  43. }
  44. }
  45. }
  46. unset($output);
  47. }
  48. if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) {
  49. if ( $_POST['password'] == $_POST['password_confirm'] ) {
  50. $v_user = escapeshellarg($_POST['user']);
  51. $user = $_POST['user'];
  52. $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-list-user";
  53. exec ($cmd." ".$v_user." json", $output, $return_var);
  54. if ( $return_var == 0 ) {
  55. $data = json_decode(implode('', $output), true);
  56. $rkey = $data[$user]['RKEY'];
  57. if (hash_equals($rkey, $_POST['code'])) {
  58. unset($output);
  59. exec("/usr/bin/sudo /usr/local/hestia/bin/v-get-user-value ".$v_user." RKEYEXP", $output,$return_var);
  60. if($output[0] > time() - 900){
  61. $v_password = tempnam("/tmp","vst");
  62. $fp = fopen($v_password, "w");
  63. fwrite($fp, $_POST['password']."\n");
  64. fclose($fp);
  65. $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-change-user-password";
  66. exec ($cmd." ".$v_user." ".$v_password, $output, $return_var);
  67. unlink($v_password);
  68. if ( $return_var > 0 ) {
  69. sleep(5);
  70. $ERROR = "<a class=\"error\">"._('An internal error occurred')."</a>";
  71. } else {
  72. $_SESSION['user'] = $_POST['user'];
  73. header("Location: /");
  74. exit;
  75. }
  76. }else{
  77. sleep(5);
  78. $ERROR = "<a class=\"error\">"._('Code has been expired')."</a>";
  79. }
  80. } else {
  81. sleep(5);
  82. $ERROR = "<a class=\"error\">"._('Invalid username or code')."</a>";
  83. }
  84. } else {
  85. sleep(5);
  86. $ERROR = "<a class=\"error\">"._('Invalid username or code')."</a>";
  87. }
  88. } else {
  89. $ERROR = "<a class=\"error\">"._('Passwords not match')."</a>";
  90. }
  91. }
  92. if (empty($_GET['action'])) {
  93. require_once '../templates/header.html';
  94. require_once '../templates/reset_1.html';
  95. } else {
  96. require_once '../templates/header.html';
  97. if ($_GET['action'] == 'code' ) {
  98. require_once '../templates/reset_2.html';
  99. }
  100. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  101. require_once '../templates/reset_3.html';
  102. }
  103. }
  104. ?>