setup.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. define('PLUGIN_SINGLESIGNON_VERSION', '1.3.3');
  3. $folder = basename(dirname(__FILE__));
  4. if ($folder !== "singlesignon") {
  5. $msg = sprintf(__sso("Please, rename the plugin folder \"%s\" to \"singlesignon\""), $folder);
  6. Session::addMessageAfterRedirect($msg, true, ERROR);
  7. }
  8. // Init the hooks of the plugins -Needed
  9. function plugin_init_singlesignon() {
  10. global $PLUGIN_HOOKS, $CFG_GLPI, $CFG_SSO;
  11. $autoload = __DIR__ . '/vendor/autoload.php';
  12. if (file_exists($autoload)) {
  13. include_once $autoload;
  14. }
  15. Plugin::registerClass('PluginSinglesignonPreference', [
  16. 'addtabon' => ['Preference', 'User']
  17. ]);
  18. $PLUGIN_HOOKS['csrf_compliant']['singlesignon'] = true;
  19. $PLUGIN_HOOKS['config_page']['singlesignon'] = 'front/provider.php';
  20. $CFG_SSO = Config::getConfigurationValues('singlesignon');
  21. $PLUGIN_HOOKS['display_login']['singlesignon'] = "plugin_singlesignon_display_login";
  22. $PLUGIN_HOOKS['menu_toadd']['singlesignon'] = [
  23. 'config' => 'PluginSinglesignonProvider',
  24. ];
  25. }
  26. // Get the name and the version of the plugin - Needed
  27. function plugin_version_singlesignon() {
  28. return [
  29. 'name' => __sso('Single Sign-on'),
  30. 'version' => PLUGIN_SINGLESIGNON_VERSION,
  31. 'author' => 'Edgard Lorraine Messias',
  32. 'homepage' => 'https://github.com/edgardmessias/glpi-singlesignon',
  33. 'minGlpiVersion' => '0.85'
  34. ];
  35. }
  36. // Optional : check prerequisites before install : may print errors or add to message after redirect
  37. function plugin_singlesignon_check_prerequisites() {
  38. $autoload = __DIR__ . '/vendor/autoload.php';
  39. // if (!file_exists($autoload)) {
  40. // echo __sso("Run first: composer install");
  41. // return false;
  42. // }
  43. if (version_compare(GLPI_VERSION, '0.85', 'lt')) {
  44. echo __sso("This plugin requires GLPI >= 0.85");
  45. return false;
  46. } else {
  47. return true;
  48. }
  49. }
  50. function plugin_singlesignon_check_config() {
  51. return true;
  52. }
  53. function __sso($str) {
  54. return __($str, 'singlesignon');
  55. }
  56. function sso_TableExists($table) {
  57. if (function_exists("TableExists")) {
  58. return TableExists($table);
  59. }
  60. global $DB;
  61. return $DB->TableExists($table);
  62. }
  63. function sso_FieldExists($table, $field, $usecache = true) {
  64. if (function_exists("FieldExists")) {
  65. return FieldExists($table);
  66. }
  67. global $DB;
  68. return $DB->FieldExists($table, $field, $usecache);
  69. }