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