Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
$returnurl = get_local_referer(false);
35
 
36
$PAGE->set_url('/admin/tool/mfa/index.php');
37
 
38
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
39
$factor = optional_param('factor', '', PARAM_ALPHANUMEXT);
40
 
41
if (empty($factor) || !\tool_mfa\plugininfo\factor::factor_exists($factor)) {
42
    throw new moodle_exception('factornotfound', 'tool_mfa', $returnurl, $factor);
43
}
44
 
45
if (empty($action) || !in_array($action, \tool_mfa\plugininfo\factor::get_factor_actions())) {
46
    throw new moodle_exception('actionnotfound', 'tool_mfa', $returnurl, $action);
47
}
48
 
49
require_sesskey();
50
 
51
$enabledfactors = [];
52
foreach (\tool_mfa\plugininfo\factor::get_enabled_factors() as $enabledfactor) {
53
    $enabledfactors[] = $enabledfactor->name;
54
}
55
 
56
 
57
switch ($action) {
58
    case 'disable':
59
        if (in_array($factor, $enabledfactors)) {
60
            \tool_mfa\manager::set_factor_config(['enabled' => 0], 'factor_' . $factor);
61
            \tool_mfa\manager::do_factor_action($factor, $action);
62
 
63
            \core\session\manager::gc(); // Remove stale sessions.
64
            core_plugin_manager::reset_caches();
65
        }
66
        break;
67
 
68
    case 'enable':
69
        if (!in_array($factor, $enabledfactors)) {
70
            \tool_mfa\manager::set_factor_config(['enabled' => 1], 'factor_' . $factor);
71
            \tool_mfa\manager::do_factor_action($factor, $action);
72
 
73
            \core\session\manager::gc(); // Remove stale sessions.
74
            core_plugin_manager::reset_caches();
75
        }
76
        break;
77
 
78
    case 'up':
79
    case 'down':
80
        \tool_mfa\manager::do_factor_action($factor, $action);
81
 
82
        \core\session\manager::gc(); // Remove stale sessions.
83
        core_plugin_manager::reset_caches();
84
        break;
85
 
86
    default:
87
        break;
88
}
89
 
90
redirect($returnurl);