setup.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * ---------------------------------------------------------------------
  4. * SingleSignOn is a plugin which allows to use SSO for auth
  5. * ---------------------------------------------------------------------
  6. * Copyright (C) 2022 Edgard
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. * ---------------------------------------------------------------------
  21. * @copyright Copyright © 2021 - 2022 Edgard
  22. * @license http://www.gnu.org/licenses/gpl.txt GPLv3+
  23. * @link https://github.com/edgardmessias/glpi-singlesignon/
  24. * ---------------------------------------------------------------------
  25. */
  26. define('PLUGIN_SINGLESIGNON_VERSION', '1.3.3');
  27. $folder = basename(dirname(__FILE__));
  28. if ($folder !== "singlesignon") {
  29. $msg = sprintf(__sso("Please, rename the plugin folder \"%s\" to \"singlesignon\""), $folder);
  30. Session::addMessageAfterRedirect($msg, true, ERROR);
  31. }
  32. // Init the hooks of the plugins -Needed
  33. function plugin_init_singlesignon() {
  34. global $PLUGIN_HOOKS, $CFG_GLPI, $CFG_SSO;
  35. $autoload = __DIR__ . '/vendor/autoload.php';
  36. if (file_exists($autoload)) {
  37. include_once $autoload;
  38. }
  39. Plugin::registerClass('PluginSinglesignonPreference', [
  40. 'addtabon' => ['Preference', 'User']
  41. ]);
  42. $PLUGIN_HOOKS['csrf_compliant']['singlesignon'] = true;
  43. $PLUGIN_HOOKS['config_page']['singlesignon'] = 'front/provider.php';
  44. $CFG_SSO = Config::getConfigurationValues('singlesignon');
  45. $PLUGIN_HOOKS['display_login']['singlesignon'] = "plugin_singlesignon_display_login";
  46. $PLUGIN_HOOKS['menu_toadd']['singlesignon'] = [
  47. 'config' => 'PluginSinglesignonProvider',
  48. ];
  49. }
  50. // Get the name and the version of the plugin - Needed
  51. function plugin_version_singlesignon() {
  52. return [
  53. 'name' => __sso('Single Sign-on'),
  54. 'version' => PLUGIN_SINGLESIGNON_VERSION,
  55. 'author' => 'Edgard Lorraine Messias',
  56. 'homepage' => 'https://github.com/edgardmessias/glpi-singlesignon',
  57. 'minGlpiVersion' => '0.85'
  58. ];
  59. }
  60. // Optional : check prerequisites before install : may print errors or add to message after redirect
  61. function plugin_singlesignon_check_prerequisites() {
  62. $autoload = __DIR__ . '/vendor/autoload.php';
  63. // if (!file_exists($autoload)) {
  64. // echo __sso("Run first: composer install");
  65. // return false;
  66. // }
  67. if (version_compare(GLPI_VERSION, '0.85', 'lt')) {
  68. echo __sso("This plugin requires GLPI >= 0.85");
  69. return false;
  70. } else {
  71. return true;
  72. }
  73. }
  74. function plugin_singlesignon_check_config() {
  75. return true;
  76. }
  77. function __sso($str) {
  78. return __($str, 'singlesignon');
  79. }
  80. function sso_TableExists($table) {
  81. if (function_exists("TableExists")) {
  82. return TableExists($table);
  83. }
  84. global $DB;
  85. return $DB->TableExists($table);
  86. }
  87. function sso_FieldExists($table, $field, $usecache = true) {
  88. if (function_exists("FieldExists")) {
  89. return FieldExists($table);
  90. }
  91. global $DB;
  92. return $DB->FieldExists($table, $field, $usecache);
  93. }