index.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. session_start();
  3. define('NO_AUTH_REQUIRED',true);
  4. $TAB = 'RESET PASSWORD';
  5. // Main include
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. if ((!empty($_POST['user'])) && (empty($_POST['code']))) {
  8. $v_user = escapeshellarg($_POST['user']);
  9. $user = $_POST['user'];
  10. $cmd="/usr/bin/sudo /usr/local/vesta/bin/v-list-user";
  11. exec ($cmd." ".$v_user." json", $output, $return_var);
  12. if ( $return_var == 0 ) {
  13. $data = json_decode(implode('', $output), true);
  14. $rkey = $data[$user]['RKEY'];
  15. $fname = $data[$user]['FNAME'];
  16. $lname = $data[$user]['LNAME'];
  17. $contact = $data[$user]['CONTACT'];
  18. $to = $data[$user]['CONTACT'];
  19. $subject = __('MAIL_RESET_SUBJECT',date("Y-m-d H:i:s"));
  20. $hostname = exec('hostname');
  21. $from = __('MAIL_FROM',$hostname);
  22. if (!empty($fname)) {
  23. $mailtext = __('GREETINGS_GORDON_FREEMAN',$fname,$lname);
  24. } else {
  25. $mailtext = __('GREETINGS');
  26. }
  27. $mailtext .= __('PASSWORD_RESET_REQUEST',$_SERVER['HTTP_HOST'],$user,$rkey,$_SERVER['HTTP_HOST'],$user,$rkey);
  28. if (!empty($rkey)) send_email($to, $subject, $mailtext, $from);
  29. unset($output);
  30. }
  31. header("Location: /reset/?action=code&user=".$_POST['user']);
  32. exit;
  33. }
  34. if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) {
  35. if ( $_POST['password'] == $_POST['password_confirm'] ) {
  36. $v_user = escapeshellarg($_POST['user']);
  37. $user = $_POST['user'];
  38. $v_password = escapeshellarg($_POST['password']);
  39. $cmd="/usr/bin/sudo /usr/local/vesta/bin/v-list-user";
  40. exec ($cmd." ".$v_user." json", $output, $return_var);
  41. if ( $return_var == 0 ) {
  42. $data = json_decode(implode('', $output), true);
  43. $rkey = $data[$user]['RKEY'];
  44. if ($rkey == $_POST['code']) {
  45. $cmd="/usr/bin/sudo /usr/local/vesta/bin/v-change-user-password";
  46. exec ($cmd." ".$v_user." ".$v_password, $output, $return_var);
  47. if ( $return_var > 0 ) {
  48. $ERROR = "<a class=\"error\">".__('An internal error occurred')."</a>";
  49. } else {
  50. $_SESSION['user'] = $_POST['user'];
  51. header("Location: /");
  52. exit;
  53. }
  54. } else {
  55. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  56. }
  57. } else {
  58. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  59. }
  60. } else {
  61. $ERROR = "<a class=\"error\">".__('Passwords not match')."</a>";
  62. }
  63. }
  64. if (empty($_GET['action'])) {
  65. // Set system language
  66. exec (VESTA_CMD . "v-list-sys-config json", $output, $return_var);
  67. $data = json_decode(implode('', $output), true);
  68. if (!empty( $data['config']['LANGUAGE'])) {
  69. $_SESSION['language'] = $data['config']['LANGUAGE'];
  70. } else {
  71. $_SESSION['language'] = 'en';
  72. }
  73. require_once '../templates/header.html';
  74. require_once '../templates/reset_1.html';
  75. } else {
  76. // Set system language
  77. exec (VESTA_CMD . "v-list-sys-config json", $output, $return_var);
  78. $data = json_decode(implode('', $output), true);
  79. if (!empty( $data['config']['LANGUAGE'])) {
  80. $_SESSION['language'] = $data['config']['LANGUAGE'];
  81. } else {
  82. $_SESSION['language'] = 'en';
  83. }
  84. require_once '../templates/header.html';
  85. if ($_GET['action'] == 'code' ) {
  86. require_once '../templates/reset_2.html';
  87. }
  88. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  89. require_once '../templates/reset_3.html';
  90. }
  91. }
  92. ?>