setup.php 2.3 KB

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