callback.php 3.1 KB

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