index.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 = "noreply@".$hostname;
  35. $from_name = _('Hestia Control Panel');
  36. if (!empty($name)) {
  37. $mailtext = sprintf(_('GREETINGS_GORDON'),$name);
  38. } else {
  39. $mailtext = _('GREETINGS');
  40. }
  41. 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')))){
  42. $mailtext .= sprintf(_('PASSWORD_RESET_REQUEST'),$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey);
  43. if (!empty($rkey)) send_email($to, $subject, $mailtext, $from, $from_name, $data[$user]['NAME']);
  44. header("Location: /reset/?action=code&user=".$_POST['user']);
  45. exit;
  46. } else {
  47. $ERROR = "<a class=\"error\">"._('Invalid host domain')."</a>";
  48. }
  49. }
  50. }
  51. unset($output);
  52. }
  53. if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) {
  54. if ( $_POST['password'] == $_POST['password_confirm'] ) {
  55. $v_user = escapeshellarg($_POST['user']);
  56. $user = $_POST['user'];
  57. $cmd="/usr/bin/sudo /usr/local/hestia/bin/v-list-user";
  58. exec ($cmd." ".$v_user." json", $output, $return_var);
  59. if ( $return_var == 0 ) {
  60. $data = json_decode(implode('', $output), true);
  61. $rkey = $data[$user]['RKEY'];
  62. if (password_verify($_POST['code'], $rkey)) {
  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>";
  84. }
  85. } else {
  86. sleep(5);
  87. $ERROR = "<a class=\"error\">"._('Invalid username or code')."</a>";
  88. }
  89. } else {
  90. sleep(5);
  91. $ERROR = "<a class=\"error\">"._('Invalid username or code')."</a>";
  92. }
  93. } else {
  94. $ERROR = "<a class=\"error\">"._('Passwords not match')."</a>";
  95. }
  96. }
  97. if (empty($_GET['action'])) {
  98. require_once '../templates/header.html';
  99. require_once '../templates/pages/login/reset_1.html';
  100. } else {
  101. require_once '../templates/header.html';
  102. if ($_GET['action'] == 'code' ) {
  103. require_once '../templates/pages/login/reset_2.html';
  104. }
  105. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  106. require_once '../templates/pages/login/reset_3.html';
  107. }
  108. }
  109. ?>