index.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // Set system language
  68. exec (VESTA_CMD . "v-list-sys-config json", $output, $return_var);
  69. $data = json_decode(implode('', $output), true);
  70. if (!empty( $data['config']['LANGUAGE'])) {
  71. $_SESSION['language'] = $data['config']['LANGUAGE'];
  72. } else {
  73. $_SESSION['language'] = 'en';
  74. }
  75. if (empty($_GET['action'])) {
  76. require_once '../templates/header.html';
  77. require_once '../templates/reset_1.html';
  78. } else {
  79. require_once '../templates/header.html';
  80. if ($_GET['action'] == 'code' ) {
  81. require_once '../templates/reset_2.html';
  82. }
  83. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  84. require_once '../templates/reset_3.html';
  85. }
  86. }
  87. ?>