callback.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. //Disable CSRF token
  3. define('GLPI_USE_CSRF_CHECK', 0);
  4. ini_set('display_errors', 1);
  5. ini_set('display_startup_errors', 1);
  6. error_reporting(E_ALL);
  7. include ('../../../inc/includes.php');
  8. $provider_id = PluginSinglesignonProvider::getCallbackParameters('provider');
  9. if (!$provider_id) {
  10. Html::displayErrorAndDie(__sso("Provider not defined."), false);
  11. }
  12. $signon_provider = new PluginSinglesignonProvider();
  13. if (!$signon_provider->getFromDB($provider_id)) {
  14. Html::displayErrorAndDie(__sso("Provider not found."), true);
  15. }
  16. if (!$signon_provider->fields['is_active']) {
  17. Html::displayErrorAndDie(__sso("Provider not active."), true);
  18. }
  19. $signon_provider->checkAuthorization();
  20. if ($signon_provider->login()) {
  21. $params = PluginSinglesignonProvider::getCallbackParameters('q');
  22. $url_redirect = '';
  23. $REDIRECT = "";
  24. if (isset($params['redirect'])) {
  25. $REDIRECT = '?redirect=' . $params['redirect'];
  26. }
  27. if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
  28. if ($_SESSION['glpiactiveprofile']['create_ticket_on_login'] && empty($REDIRECT)) {
  29. $url_redirect = $CFG_GLPI['root_doc'] . "/front/helpdesk.public.php?create_ticket=1";
  30. } else {
  31. $url_redirect = $CFG_GLPI['root_doc'] . "/front/helpdesk.public.php$REDIRECT";
  32. }
  33. } else {
  34. if ($_SESSION['glpiactiveprofile']['create_ticket_on_login'] && empty($REDIRECT)) {
  35. $url_redirect = $CFG_GLPI['root_doc'] . "/front/ticket.form.php";
  36. } else {
  37. $url_redirect = $CFG_GLPI['root_doc'] . "/front/central.php$REDIRECT";
  38. }
  39. }
  40. Html::nullHeader("Login", $CFG_GLPI["root_doc"] . '/index.php');
  41. echo '<div class="center spaced"><a href="' . $url_redirect . '">' .
  42. __('Automatic redirection, else click') . '</a>';
  43. echo '<script type="text/javascript">
  44. if (window.opener) {
  45. window.opener.location="' . $url_redirect . '";
  46. window.close();
  47. } else {
  48. window.location="' . $url_redirect . '";
  49. }
  50. </script></div>';
  51. Html::nullFooter();
  52. exit();
  53. }
  54. // we have done at least a good login? No, we exit.
  55. Html::nullHeader("Login", $CFG_GLPI["root_doc"] . '/index.php');
  56. echo '<div class="center b">' . __('User not authorized to connect in GLPI') . '<br><br>';
  57. // Logout whit noAUto to manage auto_login with errors
  58. echo '<a href="' . $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1' .
  59. str_replace("?", "&", $REDIRECT) . '" class="singlesignon">' . __('Log in again') . '</a></div>';
  60. echo '<script type="text/javascript">
  61. if (window.opener) {
  62. $(".singlesignon").on("click", function (e) {
  63. e.preventDefault();
  64. window.opener.location = $(this).attr("href");
  65. window.focus();
  66. window.close();
  67. });
  68. }
  69. </script>';
  70. Html::nullFooter();
  71. exit();