auth.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Allows admin to edit all auth plugin settings.
  4. *
  5. * JH: copied and Hax0rd from admin/enrol.php and admin/filters.php
  6. *
  7. */
  8. require_once('../config.php');
  9. require_once($CFG->libdir.'/adminlib.php');
  10. require_once($CFG->libdir.'/tablelib.php');
  11. require_login();
  12. require_capability('moodle/site:config', context_system::instance());
  13. $returnurl = new moodle_url('/admin/settings.php', array('section'=>'manageauths'));
  14. $PAGE->set_url($returnurl);
  15. $action = optional_param('action', '', PARAM_ALPHANUMEXT);
  16. $auth = optional_param('auth', '', PARAM_PLUGIN);
  17. get_enabled_auth_plugins(true); // fix the list of enabled auths
  18. if (empty($CFG->auth)) {
  19. $authsenabled = array();
  20. } else {
  21. $authsenabled = explode(',', $CFG->auth);
  22. }
  23. if (!empty($auth) and !exists_auth_plugin($auth)) {
  24. print_error('pluginnotinstalled', 'auth', $returnurl, $auth);
  25. }
  26. ////////////////////////////////////////////////////////////////////////////////
  27. // process actions
  28. if (!confirm_sesskey()) {
  29. redirect($returnurl);
  30. }
  31. switch ($action) {
  32. case 'disable':
  33. // remove from enabled list
  34. $key = array_search($auth, $authsenabled);
  35. if ($key !== false) {
  36. unset($authsenabled[$key]);
  37. set_config('auth', implode(',', $authsenabled));
  38. }
  39. if ($auth == $CFG->registerauth) {
  40. set_config('registerauth', '');
  41. }
  42. \core\session\manager::gc(); // Remove stale sessions.
  43. core_plugin_manager::reset_caches();
  44. break;
  45. case 'enable':
  46. // add to enabled list
  47. if (!in_array($auth, $authsenabled)) {
  48. $authsenabled[] = $auth;
  49. $authsenabled = array_unique($authsenabled);
  50. set_config('auth', implode(',', $authsenabled));
  51. }
  52. \core\session\manager::gc(); // Remove stale sessions.
  53. core_plugin_manager::reset_caches();
  54. break;
  55. case 'down':
  56. $key = array_search($auth, $authsenabled);
  57. // check auth plugin is valid
  58. if ($key === false) {
  59. print_error('pluginnotenabled', 'auth', $returnurl, $auth);
  60. }
  61. // move down the list
  62. if ($key < (count($authsenabled) - 1)) {
  63. $fsave = $authsenabled[$key];
  64. $authsenabled[$key] = $authsenabled[$key + 1];
  65. $authsenabled[$key + 1] = $fsave;
  66. set_config('auth', implode(',', $authsenabled));
  67. }
  68. break;
  69. case 'up':
  70. $key = array_search($auth, $authsenabled);
  71. // check auth is valid
  72. if ($key === false) {
  73. print_error('pluginnotenabled', 'auth', $returnurl, $auth);
  74. }
  75. // move up the list
  76. if ($key >= 1) {
  77. $fsave = $authsenabled[$key];
  78. $authsenabled[$key] = $authsenabled[$key - 1];
  79. $authsenabled[$key - 1] = $fsave;
  80. set_config('auth', implode(',', $authsenabled));
  81. }
  82. break;
  83. default:
  84. break;
  85. }
  86. redirect($returnurl);