1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 /** 17 * MFA configuration page. 18 * 19 * @package tool_mfa 20 * @author Mikhail Golenkov <golenkovm@gmail.com> 21 * @copyright Catalyst IT 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 require_once(__DIR__ . '/../../../config.php'); 27 require_once (__DIR__ . '/lib.php'); 28 require_once($CFG->libdir.'/adminlib.php'); 29 require_once($CFG->libdir.'/tablelib.php'); 30 31 require_login(null, false); 32 require_capability('moodle/site:config', context_system::instance()); 33 34 global $_SERVER; 35 $returnurl = $_SERVER['HTTP_REFERER']; 36 37 $PAGE->set_url('/admin/tool/mfa/index.php'); 38 39 $action = optional_param('action', '', PARAM_ALPHANUMEXT); 40 $factor = optional_param('factor', '', PARAM_ALPHANUMEXT); 41 42 if (empty($factor) || !\tool_mfa\plugininfo\factor::factor_exists($factor)) { 43 throw new moodle_exception('factornotfound', 'tool_mfa', $returnurl, $factor); 44 } 45 46 if (empty($action) || !in_array($action, \tool_mfa\plugininfo\factor::get_factor_actions())) { 47 throw new moodle_exception('actionnotfound', 'tool_mfa', $returnurl, $action); 48 } 49 50 require_sesskey(); 51 52 $enabledfactors = []; 53 foreach (\tool_mfa\plugininfo\factor::get_enabled_factors() as $enabledfactor) { 54 $enabledfactors[] = $enabledfactor->name; 55 } 56 57 58 switch ($action) { 59 case 'disable': 60 if (in_array($factor, $enabledfactors)) { 61 \tool_mfa\manager::set_factor_config(['enabled' => 0], 'factor_' . $factor); 62 \tool_mfa\manager::do_factor_action($factor, $action); 63 64 \core\session\manager::gc(); // Remove stale sessions. 65 core_plugin_manager::reset_caches(); 66 } 67 break; 68 69 case 'enable': 70 if (!in_array($factor, $enabledfactors)) { 71 \tool_mfa\manager::set_factor_config(['enabled' => 1], 'factor_' . $factor); 72 \tool_mfa\manager::do_factor_action($factor, $action); 73 74 \core\session\manager::gc(); // Remove stale sessions. 75 core_plugin_manager::reset_caches(); 76 } 77 break; 78 79 case 'up': 80 case 'down': 81 \tool_mfa\manager::do_factor_action($factor, $action); 82 83 \core\session\manager::gc(); // Remove stale sessions. 84 core_plugin_manager::reset_caches(); 85 break; 86 87 default: 88 break; 89 } 90 91 redirect($returnurl);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body