index.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. session_start();
  3. define('NO_AUTH_REQUIRED',true);
  4. $TAB = 'RESET PASSWORD';
  5. //
  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\">"._('ERROR: Invalid username or code')."</a>";
  56. }
  57. } else {
  58. $ERROR = "<a class=\"error\">"._('ERROR: Invalid username or code')."</a>";
  59. }
  60. } else {
  61. $ERROR = "<a class=\"error\">"._('ERROR: Passwords not match')."</a>";
  62. }
  63. }
  64. require_once '../templates/header.html';
  65. if (empty($_GET['action'])) {
  66. require_once '../templates/reset_1.html';
  67. } else {
  68. if ($_GET['action'] == 'code' ) {
  69. require_once '../templates/reset_2.html';
  70. }
  71. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  72. require_once '../templates/reset_3.html';
  73. }
  74. }
  75. ?>