callback.php 3.1 KB

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