setup.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. define('PLUGIN_SINGLESIGNON_VERSION', '1.2.0');
  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_HOOKS['csrf_compliant']['singlesignon'] = true;
  16. $CFG_SSO = Config::getConfigurationValues('singlesignon');
  17. $PLUGIN_HOOKS['display_login']['singlesignon'] = "plugin_singlesignon_display_login";
  18. $PLUGIN_HOOKS['menu_toadd']['singlesignon'] = [
  19. 'config' => 'PluginSinglesignonProvider',
  20. ];
  21. }
  22. // Get the name and the version of the plugin - Needed
  23. function plugin_version_singlesignon() {
  24. return [
  25. 'name' => __sso('Single Sign-on'),
  26. 'version' => PLUGIN_SINGLESIGNON_VERSION,
  27. 'author' => 'Edgard Lorraine Messias',
  28. 'homepage' => 'https://github.com/edgardmessias/glpi-singlesignon',
  29. 'minGlpiVersion' => '0.85'
  30. ];
  31. }
  32. // Optional : check prerequisites before install : may print errors or add to message after redirect
  33. function plugin_singlesignon_check_prerequisites() {
  34. $autoload = __DIR__ . '/vendor/autoload.php';
  35. // if (!file_exists($autoload)) {
  36. // echo __sso("Run first: composer install");
  37. // return false;
  38. // }
  39. if (version_compare(GLPI_VERSION, '0.85', 'lt')) {
  40. echo __sso("This plugin requires GLPI >= 0.85");
  41. return false;
  42. } else {
  43. return true;
  44. }
  45. }
  46. function plugin_singlesignon_check_config() {
  47. return true;
  48. }
  49. function __sso($str) {
  50. return __($str, 'singlesignon');
  51. }
  52. function sso_TableExists($table) {
  53. if (function_exists("TableExists")) {
  54. return TableExists($table);
  55. }
  56. global $DB;
  57. return $DB->TableExists($table);
  58. }
  59. function sso_FieldExists($table, $field, $usecache = true) {
  60. if (function_exists("FieldExists")) {
  61. return FieldExists($table);
  62. }
  63. global $DB;
  64. return $DB->FieldExists($table, $field, $usecache);
  65. }