user.inc.php 949 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require("comm.inc.php");
  3. require("env.inc.php");
  4. $username = NULL;
  5. $session_expired = false;
  6. function logged_in()
  7. {
  8. return $GLOBALS['username'];
  9. }
  10. function do_login()
  11. {
  12. global $ctl, $username, $session_expired;
  13. $session_id = get('session_id');
  14. if ($session_id === null) $session_id = cookie('gitinfo_sessionid');
  15. if ($session_id === null) return false;
  16. list($res, $arg) = $ctl->cmd("login", $session_id);
  17. switch ($res) {
  18. case "invalid":
  19. setcookie('gitinfo_sessionid', FALSE);
  20. print <<<EOT
  21. <!DOCTYPE HTML>
  22. <html><body><p>Invalid session. Please <a href="index.html">go elsewhere</a> or retry or something.</body></html>
  23. EOT;
  24. exit;
  25. case "expired":
  26. $session_expired = true;
  27. return false;
  28. default:
  29. // Currently, no other responses defined except "ok"
  30. break;
  31. }
  32. if ($_COOKIE["gitinfo_sessionid"] != $session_id) setcookie("gitinfo_sessionid", $session_id);
  33. $username = $arg;
  34. return true;
  35. }
  36. $login = do_login();