index.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/vesta/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. $mailtext .= __('PASSWORD_RESET_REQUEST',$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey);
  31. if (!empty($rkey)) send_email($to, $subject, $mailtext, $from);
  32. unset($output);
  33. }
  34. header("Location: /reset/?action=code&user=".$_POST['user']);
  35. exit;
  36. }
  37. if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) {
  38. if ( $_POST['password'] == $_POST['password_confirm'] ) {
  39. $v_user = escapeshellarg($_POST['user']);
  40. $user = $_POST['user'];
  41. $v_password = escapeshellarg($_POST['password']);
  42. $cmd="/usr/bin/sudo /usr/local/vesta/bin/v-list-user";
  43. exec ($cmd." ".$v_user." json", $output, $return_var);
  44. if ( $return_var == 0 ) {
  45. $data = json_decode(implode('', $output), true);
  46. $rkey = $data[$user]['RKEY'];
  47. if ($rkey == $_POST['code']) {
  48. $cmd="/usr/bin/sudo /usr/local/vesta/bin/v-change-user-password";
  49. exec ($cmd." ".$v_user." ".$v_password, $output, $return_var);
  50. if ( $return_var > 0 ) {
  51. $ERROR = "<a class=\"error\">".__('An internal error occurred')."</a>";
  52. } else {
  53. $_SESSION['user'] = $_POST['user'];
  54. header("Location: /");
  55. exit;
  56. }
  57. } else {
  58. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  59. }
  60. } else {
  61. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  62. }
  63. } else {
  64. $ERROR = "<a class=\"error\">".__('Passwords not match')."</a>";
  65. }
  66. }
  67. if (empty($_GET['action'])) {
  68. // Set system language
  69. exec (VESTA_CMD . "v-list-sys-config json", $output, $return_var);
  70. $data = json_decode(implode('', $output), true);
  71. if (!empty( $data['config']['LANGUAGE'])) {
  72. $_SESSION['language'] = $data['config']['LANGUAGE'];
  73. } else {
  74. $_SESSION['language'] = 'en';
  75. }
  76. require_once '../templates/header.html';
  77. require_once '../templates/reset_1.html';
  78. } else {
  79. // Set system language
  80. exec (VESTA_CMD . "v-list-sys-config json", $output, $return_var);
  81. $data = json_decode(implode('', $output), true);
  82. if (!empty( $data['config']['LANGUAGE'])) {
  83. $_SESSION['language'] = $data['config']['LANGUAGE'];
  84. } else {
  85. $_SESSION['language'] = 'en';
  86. }
  87. require_once '../templates/header.html';
  88. if ($_GET['action'] == 'code' ) {
  89. require_once '../templates/reset_2.html';
  90. }
  91. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  92. require_once '../templates/reset_3.html';
  93. }
  94. }
  95. ?>