Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 13... Línea 13...
13
//
13
//
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
17
/**
17
/**
18
 * Settings
18
 * Settings for SMS MFA factor.
19
 *
19
 *
20
 * @package     factor_sms
20
 * @package     factor_sms
21
 * @author      Peter Burnett <peterburnett@catalyst-au.net>
21
 * @author      Peter Burnett <peterburnett@catalyst-au.net>
22
 * @copyright   Catalyst IT
22
 * @copyright   Catalyst IT
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Línea 24... Línea 24...
24
 */
24
 */
25
 
-
 
Línea -... Línea 25...
-
 
25
 
-
 
26
defined('MOODLE_INTERNAL') || die();
-
 
27
 
26
defined('MOODLE_INTERNAL') || die();
28
if ($ADMIN->fulltree) {
27
global $CFG, $OUTPUT;
29
    // Get the gateway records.
-
 
30
    $manager = \core\di::get(\core_sms\manager::class);
-
 
31
    $gatewayrecords = $manager->get_gateway_records(['enabled' => 1]);
28
 
32
    $smsconfigureurl = new moodle_url(
29
$enabled = new admin_setting_configcheckbox('factor_sms/enabled',
33
        '/sms/configure.php',
30
    new lang_string('settings:enablefactor', 'tool_mfa'),
34
        [
-
 
35
            'returnurl' => new moodle_url(
-
 
36
                '/admin/settings.php',
31
    new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
37
                ['section' => 'factor_sms'],
32
$enabled->set_updatedcallback(function () {
38
            ),
33
    \tool_mfa\manager::do_factor_action('sms', get_config('factor_sms', 'enabled') ? 'enable' : 'disable');
39
        ],
-
 
40
    );
34
});
41
    $smsconfigureurl = $smsconfigureurl->out();
-
 
42
 
-
 
43
    $settings->add(
-
 
44
        new admin_setting_heading(
35
$settings->add($enabled);
45
            'factor_sms/heading',
-
 
46
            '',
-
 
47
            new lang_string(
-
 
48
                'settings:heading',
-
 
49
                'factor_sms',
36
 
50
            ),
37
$settings->add(new admin_setting_configtext('factor_sms/weight',
51
        ),
38
    new lang_string('settings:weight', 'tool_mfa'),
52
    );
39
    new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
53
    $settings->add(new admin_setting_heading('factor_sms/settings', new lang_string('settings', 'moodle'), ''));
-
 
54
 
-
 
55
    // Get available gateways, or link to gateway creation.
-
 
56
    $gateways = [0 => new lang_string('none')];
-
 
57
    if (count($gatewayrecords) > 0) {
40
 
58
        foreach ($gatewayrecords as $record) {
41
$settings->add(new admin_setting_configduration('factor_sms/duration',
59
            $values = explode('\\', $record->gateway);
-
 
60
            $gatewayname = new lang_string('pluginname', $values[0]);
-
 
61
            $gateways[$record->id] = $record->name . ' (' . $gatewayname . ')';
42
    get_string('settings:duration', 'tool_mfa'),
62
        }
43
    get_string('settings:duration_help', 'tool_mfa'), 30 * MINSECS, MINSECS));
63
    } else {
-
 
64
        $notify = new \core\output\notification(
-
 
65
            get_string('settings:setupdesc', 'factor_sms', $smsconfigureurl),
-
 
66
            \core\output\notification::NOTIFY_WARNING
44
 
67
        );
-
 
68
        $settings->add(new admin_setting_heading('factor_sms/setupdesc', '', $OUTPUT->render($notify)));
45
$codeslink = 'https://en.wikipedia.org/wiki/List_of_country_calling_codes';
69
    }
-
 
70
 
46
$link = \html_writer::link($codeslink, $codeslink);
71
    $settings->add(
47
 
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,
48
$settings->add(new admin_setting_configtext('factor_sms/countrycode',
77
            $gateways,
-
 
78
        ),
49
    get_string('settings:countrycode', 'factor_sms'),
79
    );
50
    get_string('settings:countrycode_help', 'factor_sms', $link), '', PARAM_INT));
80
 
-
 
81
    $enabled = new admin_setting_configcheckbox(
-
 
82
        'factor_sms/enabled',
51
 
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',
52
$gateways = [
91
        );
-
 
92
    });
53
    'aws_sns' => get_string('settings:aws', 'factor_sms'),
93
    $settings->add($enabled);
-
 
94
 
54
];
95
    $settings->add(
55
 
96
        new admin_setting_configtext(
-
 
97
            'factor_sms/weight',
56
$settings->add(new admin_setting_configselect('factor_sms/gateway',
98
            new lang_string('settings:weight', 'tool_mfa'),
-
 
99
            new lang_string('settings:weight_help', 'tool_mfa'),
-
 
100
            100,
57
    get_string('settings:gateway', 'factor_sms'),
101
            PARAM_INT,
-
 
102
        ),
-
 
103
    );
58
    get_string('settings:gateway_help', 'factor_sms'),
104
 
-
 
105
    $settings->add(
-
 
106
        new admin_setting_configduration(
-
 
107
            'factor_sms/duration',
-
 
108
            new lang_string('settings:duration', 'tool_mfa'),
59
    'aws_sns', $gateways));
109
            new lang_string('settings:duration_help', 'tool_mfa'),
-
 
110
            30 * MINSECS,
60
 
111
            MINSECS,
61
if (empty(get_config('factor_sms', 'gateway'))) {
-
 
62
    return;
-
 
63
}
-