callback.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 = PluginSinglesignonToolbox::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. $test = PluginSinglesignonToolbox::getCallbackParameters('test');
  21. if ($test) {
  22. Html::nullHeader("Login", $CFG_GLPI["root_doc"] . '/index.php');
  23. echo '<div class="left spaced">';
  24. echo '<pre>';
  25. echo "### BEGIN ###\n";
  26. print_r($signon_provider->getResourceOwner());
  27. echo "### END ###";
  28. echo '</pre>';
  29. Html::nullFooter();
  30. exit();
  31. }
  32. $user_id = Session::getLoginUserID();
  33. $REDIRECT = "";
  34. if ($user_id || $signon_provider->login()) {
  35. $user_id = $user_id ?: Session::getLoginUserID();
  36. if ($user_id) {
  37. $signon_provider->linkUser($user_id);
  38. }
  39. $params = PluginSinglesignonToolbox::getCallbackParameters('q');
  40. $url_redirect = '';
  41. if (isset($params['redirect'])) {
  42. $REDIRECT = '?redirect=' . $params['redirect'];
  43. } else if (isset($_GET['state']) && is_integer(strpos($_GET['state'], "&redirect="))) {
  44. $REDIRECT = '?' . substr($_GET['state'], strpos($_GET['state'], "&redirect=") + 1);
  45. }
  46. if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
  47. if ($_SESSION['glpiactiveprofile']['create_ticket_on_login'] && empty($REDIRECT)) {
  48. $url_redirect = $CFG_GLPI['root_doc'] . "/front/helpdesk.public.php?create_ticket=1";
  49. } else {
  50. $url_redirect = $CFG_GLPI['root_doc'] . "/front/helpdesk.public.php$REDIRECT";
  51. }
  52. } else {
  53. if ($_SESSION['glpiactiveprofile']['create_ticket_on_login'] && empty($REDIRECT)) {
  54. $url_redirect = $CFG_GLPI['root_doc'] . "/front/ticket.form.php";
  55. } else {
  56. $url_redirect = $CFG_GLPI['root_doc'] . "/front/central.php$REDIRECT";
  57. }
  58. }
  59. Html::nullHeader("Login", $CFG_GLPI["root_doc"] . '/index.php');
  60. echo '<div class="center spaced"><a href="' . $url_redirect . '">' .
  61. __('Automatic redirection, else click') . '</a>';
  62. echo '<script type="text/javascript">
  63. if (window.opener) {
  64. window.opener.location="' . $url_redirect . '";
  65. window.close();
  66. } else {
  67. window.location="' . $url_redirect . '";
  68. }
  69. </script></div>';
  70. Html::nullFooter();
  71. exit();
  72. }
  73. // we have done at least a good login? No, we exit.
  74. Html::nullHeader("Login", $CFG_GLPI["root_doc"] . '/index.php');
  75. echo '<div class="center b">' . __('User not authorized to connect in GLPI') . '<br><br>';
  76. // Logout whit noAUto to manage auto_login with errors
  77. echo '<a href="' . $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1' .
  78. str_replace("?", "&", $REDIRECT) . '" class="singlesignon">' . __('Log in again') . '</a></div>';
  79. echo '<script type="text/javascript">
  80. if (window.opener) {
  81. $(".singlesignon").on("click", function (e) {
  82. e.preventDefault();
  83. window.opener.location = $(this).attr("href");
  84. window.focus();
  85. window.close();
  86. });
  87. }
  88. </script>';
  89. Html::nullFooter();
  90. exit();