Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
/**
1441 ariadna 18
 * Settings for SMS MFA factor.
1 efrain 19
 *
20
 * @package     factor_sms
21
 * @author      Peter Burnett <peterburnett@catalyst-au.net>
22
 * @copyright   Catalyst IT
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
1441 ariadna 28
if ($ADMIN->fulltree) {
29
    // Get the gateway records.
30
    $manager = \core\di::get(\core_sms\manager::class);
31
    $gatewayrecords = $manager->get_gateway_records(['enabled' => 1]);
32
    $smsconfigureurl = new moodle_url(
33
        '/sms/configure.php',
34
        [
35
            'returnurl' => new moodle_url(
36
                '/admin/settings.php',
37
                ['section' => 'factor_sms'],
38
            ),
39
        ],
40
    );
41
    $smsconfigureurl = $smsconfigureurl->out();
1 efrain 42
 
1441 ariadna 43
    $settings->add(
44
        new admin_setting_heading(
45
            'factor_sms/heading',
46
            '',
47
            new lang_string(
48
                'settings:heading',
49
                'factor_sms',
50
            ),
51
        ),
52
    );
53
    $settings->add(new admin_setting_heading('factor_sms/settings', new lang_string('settings', 'moodle'), ''));
1 efrain 54
 
1441 ariadna 55
    // Get available gateways, or link to gateway creation.
56
    $gateways = [0 => new lang_string('none')];
57
    if (count($gatewayrecords) > 0) {
58
        foreach ($gatewayrecords as $record) {
59
            $values = explode('\\', $record->gateway);
60
            $gatewayname = new lang_string('pluginname', $values[0]);
61
            $gateways[$record->id] = $record->name . ' (' . $gatewayname . ')';
62
        }
63
    } else {
64
        $notify = new \core\output\notification(
65
            get_string('settings:setupdesc', 'factor_sms', $smsconfigureurl),
66
            \core\output\notification::NOTIFY_WARNING
67
        );
68
        $settings->add(new admin_setting_heading('factor_sms/setupdesc', '', $OUTPUT->render($notify)));
69
    }
1 efrain 70
 
1441 ariadna 71
    $settings->add(
72
        new admin_setting_configselect(
73
            'factor_sms/smsgateway',
74
            new lang_string('settings:smsgateway', 'factor_sms'),
75
            new lang_string('settings:smsgateway_help', 'factor_sms', $smsconfigureurl),
76
            0,
77
            $gateways,
78
        ),
79
    );
1 efrain 80
 
1441 ariadna 81
    $enabled = new admin_setting_configcheckbox(
82
        'factor_sms/enabled',
83
        new lang_string('settings:enablefactor', 'tool_mfa'),
84
        new lang_string('settings:enablefactor_help', 'tool_mfa'),
85
        0,
86
    );
87
    $enabled->set_updatedcallback(function () {
88
        \tool_mfa\manager::do_factor_action(
89
            'sms',
90
            get_config('factor_sms', 'enabled') ? 'enable' : 'disable',
91
        );
92
    });
93
    $settings->add($enabled);
1 efrain 94
 
1441 ariadna 95
    $settings->add(
96
        new admin_setting_configtext(
97
            'factor_sms/weight',
98
            new lang_string('settings:weight', 'tool_mfa'),
99
            new lang_string('settings:weight_help', 'tool_mfa'),
100
            100,
101
            PARAM_INT,
102
        ),
103
    );
1 efrain 104
 
1441 ariadna 105
    $settings->add(
106
        new admin_setting_configduration(
107
            'factor_sms/duration',
108
            new lang_string('settings:duration', 'tool_mfa'),
109
            new lang_string('settings:duration_help', 'tool_mfa'),
110
            30 * MINSECS,
111
            MINSECS,
112
        ),
113
    );
1 efrain 114
}