index.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. $user = $_POST['user'];
  12. $return_var = v_exec('v-list-user', [$user, 'json'], false, $output);
  13. if ($return_var == 0) {
  14. $data = json_decode($output, true);
  15. $rkey = $data[$user]['RKEY'];
  16. $fname = $data[$user]['FNAME'];
  17. $lname = $data[$user]['LNAME'];
  18. $contact = $data[$user]['CONTACT'];
  19. $to = $data[$user]['CONTACT'];
  20. $subject = __('MAIL_RESET_SUBJECT', date('Y-m-d H:i:s'));
  21. $hostname = exec('hostname');
  22. $from = __('MAIL_FROM', $hostname);
  23. if (!empty($fname) || !empty($lname)) {
  24. $mailtext = __('GREETINGS_GORDON_FREEMAN', $fname, $lname);
  25. } else {
  26. $mailtext = __('GREETINGS');
  27. }
  28. $mailtext .= __('PASSWORD_RESET_REQUEST', $_SERVER['HTTP_HOST'], $user, $rkey, $_SERVER['HTTP_HOST'], $user, $rkey);
  29. if (!empty($rkey)) send_email($to, $subject, $mailtext, $from);
  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. $user = $_POST['user'];
  37. $return_var = v_exec('v-list-user', [$user, 'json'], false, $output);
  38. if ($return_var == 0) {
  39. $data = json_decode($output, true);
  40. $rkey = $data[$user]['RKEY'];
  41. if ($rkey == $_POST['code']) {
  42. $v_password = tempnam("/tmp","vst");
  43. $fp = fopen($v_password, "w");
  44. fwrite($fp, $_POST['password']."\n");
  45. fclose($fp);
  46. $return_var = v_exec('v-change-user-password', [$user, $v_password], false);
  47. unlink($v_password);
  48. if ($return_var > 0) {
  49. $ERROR = "<a class=\"error\">".__('An internal error occurred')."</a>";
  50. } else {
  51. $_SESSION['user'] = $_POST['user'];
  52. header("Location: /");
  53. exit;
  54. }
  55. } else {
  56. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  57. }
  58. } else {
  59. $ERROR = "<a class=\"error\">".__('Invalid username or code')."</a>";
  60. }
  61. } else {
  62. $ERROR = "<a class=\"error\">".__('Passwords not match')."</a>";
  63. }
  64. }
  65. // Detect language
  66. if (empty($_SESSION['language'])) $_SESSION['language'] = detect_user_language();
  67. if (empty($_GET['action'])) {
  68. require_once '../templates/header.html';
  69. require_once '../templates/reset_1.html';
  70. } else {
  71. require_once '../templates/header.html';
  72. if ($_GET['action'] == 'code' ) {
  73. require_once '../templates/reset_2.html';
  74. }
  75. if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
  76. require_once '../templates/reset_3.html';
  77. }
  78. }
  79. ?>