Exemplo n.º 1
0
 public function execute()
 {
     global $CFG;
     $action = $this->arguments[0];
     $pluginname = $this->arguments[1];
     // Does the authentication module exist?
     if (!exists_auth_plugin($pluginname)) {
         print_error('pluginnotinstalled', 'auth', '', $pluginname);
     }
     // Get enabled plugins.
     $authsenabled = get_enabled_auth_plugins(true);
     if (empty($CFG->auth)) {
         $authsenabled = array();
     } else {
         $authsenabled = explode(',', $CFG->auth);
     }
     switch ($action) {
         case 'disable':
             $key = array_search($pluginname, $authsenabled);
             if ($key !== false) {
                 unset($authsenabled[$key]);
                 set_config('auth', implode(',', $authsenabled));
             }
             break;
         case 'down':
             $key = array_search($pluginname, $authsenabled);
             if ($key !== false && $key < count($authsenabled) - 1) {
                 $fsave = $authsenabled[$key];
                 $authsenabled[$key] = $authsenabled[$key + 1];
                 $authsenabled[$key + 1] = $fsave;
                 set_config('auth', implode(',', $authsenabled));
             }
         case 'enable':
             if (!in_array($pluginname, $authsenabled)) {
                 $authsenabled[] = $pluginname;
                 $authsenabled = array_unique($authsenabled);
                 set_config('auth', implode(',', $authsenabled));
             }
             break;
         case 'up':
             $key = array_search($pluginname, $authsenabled);
             if ($key !== false && $key >= 1) {
                 $fsave = $authsenabled[$key];
                 $authsenabled[$key] = $authsenabled[$key - 1];
                 $authsenabled[$key - 1] = $fsave;
                 set_config('auth', implode(',', $authsenabled));
             }
             break;
     }
     echo "Auth modules enabled: " . implode(',', $authsenabled) . "\n";
 }
Exemplo n.º 2
0
require_once $CFG->libdir . '/tablelib.php';
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
$returnurl = "{$CFG->wwwroot}/{$CFG->admin}/settings.php?section=manageauths";
$action = optional_param('action', '', PARAM_ACTION);
$auth = optional_param('auth', '', PARAM_SAFEDIR);
// get currently installed and enabled auth plugins
$authsavailable = get_list_of_plugins('auth');
get_enabled_auth_plugins(true);
// fix the list of enabled auths
if (empty($CFG->auth)) {
    $authsenabled = array();
} else {
    $authsenabled = explode(',', $CFG->auth);
}
if (!empty($auth) and !exists_auth_plugin($auth)) {
    print_error('pluginnotinstalled', 'auth', $url, $auth);
}
////////////////////////////////////////////////////////////////////////////////
// process actions
if (!confirm_sesskey()) {
    redirect($returnurl);
}
switch ($action) {
    case 'disable':
        // remove from enabled list
        $key = array_search($auth, $authsenabled);
        if ($key !== false) {
            unset($authsenabled[$key]);
            set_config('auth', implode(',', $authsenabled));
        }
Exemplo n.º 3
0
/**
 * Returns array of active auth plugins.
 *
 * @param bool $fix fix $CFG->auth if needed
 * @return array
 */
function get_enabled_auth_plugins($fix = false)
{
    global $CFG;
    $default = array('manual', 'nologin');
    if (empty($CFG->auth)) {
        $auths = array();
    } else {
        $auths = explode(',', $CFG->auth);
    }
    if ($fix) {
        $auths = array_unique($auths);
        foreach ($auths as $k => $authname) {
            if (!exists_auth_plugin($authname) or in_array($authname, $default)) {
                unset($auths[$k]);
            }
        }
        $newconfig = implode(',', $auths);
        if (!isset($CFG->auth) or $newconfig != $CFG->auth) {
            set_config('auth', $newconfig);
        }
    }
    return array_merge($default, $auths);
}
 function action($action)
 {
     global $CFG;
     get_enabled_auth_plugins(true);
     // fix the list of enabled auths
     if (empty($CFG->auth)) {
         $authsenabled = array();
     } else {
         $authsenabled = explode(',', $CFG->auth);
     }
     if (!exists_auth_plugin($this->plugin)) {
         return get_string('pluginnotinstalled', 'auth', $this->plugin);
     }
     switch ($action) {
         case 'enable':
             // add to enabled list
             if (!in_array($this->plugin, $authsenabled)) {
                 $authsenabled[] = $this->plugin;
                 $authsenabled = array_unique($authsenabled);
                 set_config('auth', implode(',', $authsenabled));
             }
             break;
         case 'disable':
             // Remove from enabled list.
             $key = array_search($this->plugin, $authsenabled);
             if ($key !== false) {
                 unset($authsenabled[$key]);
                 set_config('auth', implode(',', $authsenabled));
             }
             if ($this->plugin == $CFG->registerauth) {
                 set_config('registerauth', '');
             }
             break;
     }
     \core\session\manager::gc();
     // remove stale sessions
     return 0;
 }