Merge branch 'MDL-80468-factorpage-m' of https://github.com/bwalkerl/moodle

This commit is contained in:
Jun Pataleta 2025-01-16 12:25:44 +08:00
commit 4a2e2086a4
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
14 changed files with 376 additions and 343 deletions

View File

@ -280,6 +280,10 @@ class factor extends \core\plugininfo\base {
* @param bool $hassiteconfig whether the current user has moodle/site:config capability
*/
public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig): void {
global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
/** @var \admin_root $ADMIN */
$ADMIN = $adminroot; // May be used in settings.php.
$plugininfo = $this; // Also can be used inside settings.php.
if (!$this->is_installed_and_upgraded()) {
return;
@ -293,9 +297,7 @@ class factor extends \core\plugininfo\base {
$settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
if ($adminroot->fulltree) {
include($this->full_path('settings.php'));
}
include($this->full_path('settings.php'));
$adminroot->add($parentnodename, $settings);
}

View File

@ -25,17 +25,20 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_admin/description', '', new lang_string('settings:description', 'factor_admin')));
$settings->add(new admin_setting_heading('factor_admin/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_admin/description', '',
new lang_string('settings:description', 'factor_admin')));
$settings->add(new admin_setting_heading('factor_admin/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_admin/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('admin', get_config('factor_admin', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_admin/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('admin', get_config('factor_admin', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_admin/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'factor_admin'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_admin/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'factor_admin'), 100, PARAM_INT));
}

View File

@ -25,28 +25,31 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_auth/description', '', new lang_string('settings:description', 'factor_auth')));
$settings->add(new admin_setting_heading('factor_auth/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_auth/description', '',
new lang_string('settings:description', 'factor_auth')));
$settings->add(new admin_setting_heading('factor_auth/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_auth/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('auth', get_config('factor_auth', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_auth/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('auth', get_config('factor_auth', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_auth/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_auth/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$authtypes = get_enabled_auth_plugins(true);
$authselect = [];
foreach ($authtypes as $type) {
$auth = get_auth_plugin($type);
$authselect[$type] = $auth->get_title();
$authtypes = get_enabled_auth_plugins(true);
$authselect = [];
foreach ($authtypes as $type) {
$auth = get_auth_plugin($type);
$authselect[$type] = $auth->get_title();
}
$settings->add(new admin_setting_configmulticheckbox('factor_auth/goodauth',
get_string('settings:goodauth', 'factor_auth'),
get_string('settings:goodauth_help', 'factor_auth'), [], $authselect));
}
$settings->add(new admin_setting_configmulticheckbox('factor_auth/goodauth',
get_string('settings:goodauth', 'factor_auth'),
get_string('settings:goodauth_help', 'factor_auth'), [], $authselect));

View File

@ -25,23 +25,25 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_capability/description', '',
new lang_string('settings:description', 'factor_capability')));
$settings->add(new admin_setting_heading('factor_capability/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_capability/description', '',
new lang_string('settings:description', 'factor_capability')));
$settings->add(new admin_setting_heading('factor_capability/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_capability/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('capability', get_config('factor_capability', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_capability/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('capability', get_config('factor_capability', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_capability/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_capability/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
// Admin passes bool logic is inverted due to negative capability check.
$settings->add(new admin_setting_configcheckbox('factor_capability/adminpasses',
new lang_string('settings:adminpasses', 'factor_capability'),
new lang_string('settings:adminpasses_help', 'factor_capability'), 1, 0, 1));
// Admin passes bool logic is inverted due to negative capability check.
$settings->add(new admin_setting_configcheckbox('factor_capability/adminpasses',
new lang_string('settings:adminpasses', 'factor_capability'),
new lang_string('settings:adminpasses_help', 'factor_capability'), 1, 0, 1));
}

View File

@ -26,31 +26,33 @@
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/../../../../../cohort/lib.php');
$settings->add(new admin_setting_heading('factor_cohort/description', '',
new lang_string('settings:description', 'factor_cohort')));
$settings->add(new admin_setting_heading('factor_cohort/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_cohort/description', '',
new lang_string('settings:description', 'factor_cohort')));
$settings->add(new admin_setting_heading('factor_cohort/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_cohort/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('cohort', get_config('factor_cohort', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_cohort/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('cohort', get_config('factor_cohort', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_cohort/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_cohort/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$cohorts = cohort_get_all_cohorts();
$choices = [];
$cohorts = cohort_get_all_cohorts();
$choices = [];
foreach ($cohorts['cohorts'] as $cohort) {
$choices[$cohort->id] = $cohort->name;
}
if (!empty($choices)) {
$settings->add(new admin_setting_configmultiselect('factor_cohort/cohorts',
new lang_string('settings:cohort', 'factor_cohort'),
new lang_string('settings:cohort_help', 'factor_cohort'), [], $choices));
foreach ($cohorts['cohorts'] as $cohort) {
$choices[$cohort->id] = $cohort->name;
}
if (!empty($choices)) {
$settings->add(new admin_setting_configmultiselect('factor_cohort/cohorts',
new lang_string('settings:cohort', 'factor_cohort'),
new lang_string('settings:cohort_help', 'factor_cohort'), [], $choices));
}
}

View File

@ -25,25 +25,28 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_email/description', '', new lang_string('settings:description', 'factor_email')));
$settings->add(new admin_setting_heading('factor_email/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_email/description', '',
new lang_string('settings:description', 'factor_email')));
$settings->add(new admin_setting_heading('factor_email/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_email/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 1);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('email', get_config('factor_email', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_email/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 1);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('email', get_config('factor_email', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_email/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_email/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configduration('factor_email/duration',
get_string('settings:duration', 'factor_email'),
get_string('settings:duration_help', 'factor_email'), 30 * MINSECS, MINSECS));
$settings->add(new admin_setting_configduration('factor_email/duration',
get_string('settings:duration', 'factor_email'),
get_string('settings:duration_help', 'factor_email'), 30 * MINSECS, MINSECS));
$settings->add(new admin_setting_configcheckbox('factor_email/suspend',
get_string('settings:suspend', 'factor_email'),
get_string('settings:suspend_help', 'factor_email'), 0));
$settings->add(new admin_setting_configcheckbox('factor_email/suspend',
get_string('settings:suspend', 'factor_email'),
get_string('settings:suspend_help', 'factor_email'), 0));
}

View File

@ -25,39 +25,42 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_grace/description', '', new lang_string('settings:description', 'factor_grace')));
$settings->add(new admin_setting_heading('factor_grace/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_grace/description', '',
new lang_string('settings:description', 'factor_grace')));
$settings->add(new admin_setting_heading('factor_grace/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_grace/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('grace', get_config('factor_grace', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_grace/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('grace', get_config('factor_grace', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_grace/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_grace/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configcheckbox('factor_grace/forcesetup',
new lang_string('settings:forcesetup', 'factor_grace'),
new lang_string('settings:forcesetup_help', 'factor_grace'), 0));
$settings->add(new admin_setting_configcheckbox('factor_grace/forcesetup',
new lang_string('settings:forcesetup', 'factor_grace'),
new lang_string('settings:forcesetup_help', 'factor_grace'), 0));
$settings->add(new admin_setting_configduration('factor_grace/graceperiod',
new lang_string('settings:graceperiod', 'factor_grace'),
new lang_string('settings:graceperiod_help', 'factor_grace'), '604800'));
$settings->add(new admin_setting_configduration('factor_grace/graceperiod',
new lang_string('settings:graceperiod', 'factor_grace'),
new lang_string('settings:graceperiod_help', 'factor_grace'), '604800'));
$gracefactor = \tool_mfa\plugininfo\factor::get_factor('grace');
$factors = $gracefactor->get_all_affecting_factors();
$gracefactors = [];
foreach ($factors as $factor) {
$gracefactors[$factor->name] = $factor->get_display_name();
$gracefactor = \tool_mfa\plugininfo\factor::get_factor('grace');
$factors = $gracefactor->get_all_affecting_factors();
$gracefactors = [];
foreach ($factors as $factor) {
$gracefactors[$factor->name] = $factor->get_display_name();
}
$settings->add(new admin_setting_configmultiselect('factor_grace/ignorelist',
new lang_string('settings:ignorelist', 'factor_grace'),
new lang_string('settings:ignorelist_help', 'factor_grace'), [], $gracefactors));
$settings->add(new admin_setting_confightmleditor('factor_grace/customwarning',
new lang_string('settings:customwarning', 'factor_grace'),
new lang_string('settings:customwarning_help', 'factor_grace'), '', PARAM_RAW));
}
$settings->add(new admin_setting_configmultiselect('factor_grace/ignorelist',
new lang_string('settings:ignorelist', 'factor_grace'),
new lang_string('settings:ignorelist_help', 'factor_grace'), [], $gracefactors));
$settings->add(new admin_setting_confightmleditor('factor_grace/customwarning',
new lang_string('settings:customwarning', 'factor_grace'),
new lang_string('settings:customwarning_help', 'factor_grace'), '', PARAM_RAW));

View File

@ -27,39 +27,40 @@ defined('MOODLE_INTERNAL') || die();
global $OUTPUT;
$settings->add(new admin_setting_heading('factor_iprange/description', '',
new lang_string('settings:description', 'factor_iprange')));
$settings->add(new admin_setting_heading('factor_iprange/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_iprange/description', '',
new lang_string('settings:description', 'factor_iprange')));
$settings->add(new admin_setting_heading('factor_iprange/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_iprange/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('iprange', get_config('factor_iprange', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_iprange/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('iprange', get_config('factor_iprange', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_iprange/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_iprange/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
// Current IP validation against list for description.
$allowedips = get_config('factor_iprange', 'safeips');
if (trim($allowedips) == '') {
$message = 'allowedipsempty';
$type = 'notifyerror';
} else if (remoteip_in_list($allowedips)) {
$message = 'allowedipshasmyip';
$type = 'notifysuccess';
} else {
$message = 'allowedipshasntmyip';
$type = 'notifyerror';
};
$info = $OUTPUT->notification(get_string($message, 'factor_iprange', ['ip' => getremoteaddr()]), $type);
$settings->add(new admin_setting_configiplist('factor_iprange/safeips',
new lang_string('settings:safeips', 'factor_iprange'),
new lang_string('settings:safeips_help', 'factor_iprange',
['info' => $info, 'syntax' => get_string('ipblockersyntax', 'admin')]), '', PARAM_TEXT));
// Current IP validation against list for description.
$allowedips = get_config('factor_iprange', 'safeips');
if (trim($allowedips) == '') {
$message = 'allowedipsempty';
$type = 'notifyerror';
} else if (remoteip_in_list($allowedips)) {
$message = 'allowedipshasmyip';
$type = 'notifysuccess';
} else {
$message = 'allowedipshasntmyip';
$type = 'notifyerror';
};
$info = $OUTPUT->notification(get_string($message, 'factor_iprange', ['ip' => getremoteaddr()]), $type);
$settings->add(new admin_setting_configiplist('factor_iprange/safeips',
new lang_string('settings:safeips', 'factor_iprange'),
new lang_string('settings:safeips_help', 'factor_iprange',
['info' => $info, 'syntax' => get_string('ipblockersyntax', 'admin')]), '', PARAM_TEXT));
}

View File

@ -25,18 +25,20 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_nosetup/description', '',
new lang_string('settings:description', 'factor_nosetup')));
$settings->add(new admin_setting_heading('factor_nosetup/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_nosetup/description', '',
new lang_string('settings:description', 'factor_nosetup')));
$settings->add(new admin_setting_heading('factor_nosetup/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_nosetup/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('nosetup', get_config('factor_nosetup', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_nosetup/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('nosetup', get_config('factor_nosetup', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_nosetup/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_nosetup/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
}

View File

@ -25,27 +25,30 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_role/description', '', new lang_string('settings:description', 'factor_role')));
$settings->add(new admin_setting_heading('factor_role/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_role/description', '',
new lang_string('settings:description', 'factor_role')));
$settings->add(new admin_setting_heading('factor_role/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_role/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('role', get_config('factor_role', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_role/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('role', get_config('factor_role', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_role/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_role/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$choices = ['admin' => get_string('administrator')];
$roles = get_all_roles();
foreach ($roles as $role) {
$choices[$role->id] = role_get_name($role);
$choices = ['admin' => get_string('administrator')];
$roles = get_all_roles();
foreach ($roles as $role) {
$choices[$role->id] = role_get_name($role);
}
$settings->add(new admin_setting_configmultiselect('factor_role/roles',
new lang_string('settings:roles', 'factor_role'),
new lang_string('settings:roles_help', 'factor_role'), ['admin'], $choices));
}
$settings->add(new admin_setting_configmultiselect('factor_role/roles',
new lang_string('settings:roles', 'factor_role'),
new lang_string('settings:roles_help', 'factor_role'), ['admin'], $choices));

View File

@ -25,96 +25,97 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
// Get the gateway records.
$manager = \core\di::get(\core_sms\manager::class);
$gatewayrecords = $manager->get_gateway_records(['enabled' => 1]);
$smsconfigureurl = new moodle_url(
'/sms/configure.php',
[
'returnurl' => new moodle_url(
'/admin/settings.php',
['section' => 'factor_sms'],
),
],
);
$smsconfigureurl = $smsconfigureurl->out();
$settings->add(
new admin_setting_heading(
'factor_sms/heading',
'',
new lang_string(
'settings:heading',
'factor_sms',
),
),
);
$settings->add(new admin_setting_heading('factor_sms/settings', new lang_string('settings', 'moodle'), ''));
if (count($gatewayrecords) > 0) {
$gateways = [0 => new lang_string('none')];
foreach ($gatewayrecords as $record) {
$values = explode('\\', $record->gateway);
$gatewayname = new lang_string('pluginname', $values[0]);
$gateways[$record->id] = $record->name . ' (' . $gatewayname . ')';
}
if ($ADMIN->fulltree) {
// Get the gateway records.
$manager = \core\di::get(\core_sms\manager::class);
$gatewayrecords = $manager->get_gateway_records(['enabled' => 1]);
$smsconfigureurl = new moodle_url(
'/sms/configure.php',
[
'returnurl' => new moodle_url(
'/admin/settings.php',
['section' => 'factor_sms'],
),
],
);
$smsconfigureurl = $smsconfigureurl->out();
$settings->add(
new admin_setting_configselect(
'factor_sms/smsgateway',
new lang_string('settings:smsgateway', 'factor_sms'),
new lang_string('settings:smsgateway_help', 'factor_sms', $smsconfigureurl),
0,
$gateways,
),
);
$enabled = new admin_setting_configcheckbox(
'factor_sms/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'),
0,
);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action(
'sms',
get_config('factor_sms', 'enabled') ? 'enable' : 'disable',
);
});
$settings->add($enabled);
$settings->add(
new admin_setting_configtext(
'factor_sms/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'),
100,
PARAM_INT,
),
);
$settings->hide_if('factor_sms/weight', 'factor_sms/enabled');
$settings->add(
new admin_setting_configduration(
'factor_sms/duration',
new lang_string('settings:duration', 'tool_mfa'),
new lang_string('settings:duration_help', 'tool_mfa'),
30 * MINSECS,
MINSECS,
),
);
$settings->hide_if('factor_sms/duration', 'factor_sms/enabled');
} else {
$settings->add(
new admin_setting_description(
'factor_sms/setupdesc',
new admin_setting_heading(
'factor_sms/heading',
'',
new lang_string(
'settings:setupdesc',
'settings:heading',
'factor_sms',
$smsconfigureurl,
),
),
);
$settings->add(new admin_setting_heading('factor_sms/settings', new lang_string('settings', 'moodle'), ''));
if (count($gatewayrecords) > 0) {
$gateways = [0 => new lang_string('none')];
foreach ($gatewayrecords as $record) {
$values = explode('\\', $record->gateway);
$gatewayname = new lang_string('pluginname', $values[0]);
$gateways[$record->id] = $record->name . ' (' . $gatewayname . ')';
}
$settings->add(
new admin_setting_configselect(
'factor_sms/smsgateway',
new lang_string('settings:smsgateway', 'factor_sms'),
new lang_string('settings:smsgateway_help', 'factor_sms', $smsconfigureurl),
0,
$gateways,
),
);
$enabled = new admin_setting_configcheckbox(
'factor_sms/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'),
0,
);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action(
'sms',
get_config('factor_sms', 'enabled') ? 'enable' : 'disable',
);
});
$settings->add($enabled);
$settings->add(
new admin_setting_configtext(
'factor_sms/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'),
100,
PARAM_INT,
),
);
$settings->hide_if('factor_sms/weight', 'factor_sms/enabled');
$settings->add(
new admin_setting_configduration(
'factor_sms/duration',
new lang_string('settings:duration', 'tool_mfa'),
new lang_string('settings:duration_help', 'tool_mfa'),
30 * MINSECS,
MINSECS,
),
);
$settings->hide_if('factor_sms/duration', 'factor_sms/enabled');
} else {
$settings->add(
new admin_setting_description(
'factor_sms/setupdesc',
'',
new lang_string(
'settings:setupdesc',
'factor_sms',
$smsconfigureurl,
),
),
);
}
}

View File

@ -26,25 +26,28 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_token/description', '', new lang_string('settings:description', 'factor_token')));
$settings->add(new admin_setting_heading('factor_token/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_token/description', '',
new lang_string('settings:description', 'factor_token')));
$settings->add(new admin_setting_heading('factor_token/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_token/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('token', get_config('factor_token', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_token/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('token', get_config('factor_token', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_token/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_token/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configduration('factor_token/expiry',
new lang_string('settings:expiry', 'factor_token'),
new lang_string('settings:expiry_help', 'factor_token'), DAYSECS));
$settings->add(new admin_setting_configduration('factor_token/expiry',
new lang_string('settings:expiry', 'factor_token'),
new lang_string('settings:expiry_help', 'factor_token'), DAYSECS));
$settings->add(new admin_setting_configcheckbox('factor_token/expireovernight',
new lang_string('settings:expireovernight', 'factor_token'),
new lang_string('settings:expireovernight_help', 'factor_token'), 1));
$settings->add(new admin_setting_configcheckbox('factor_token/expireovernight',
new lang_string('settings:expireovernight', 'factor_token'),
new lang_string('settings:expireovernight_help', 'factor_token'), 1));
}

View File

@ -26,27 +26,30 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_totp/description', '', new lang_string('settings:description', 'factor_totp')));
$settings->add(new admin_setting_heading('factor_totp/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_totp/description', '',
new lang_string('settings:description', 'factor_totp')));
$settings->add(new admin_setting_heading('factor_totp/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_totp/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('totp', get_config('factor_totp', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_totp/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function () {
\tool_mfa\manager::do_factor_action('totp', get_config('factor_totp', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_totp/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_totp/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$window = new admin_setting_configduration('factor_totp/window',
new lang_string('settings:window', 'factor_totp'),
new lang_string('settings:window_help', 'factor_totp'), 15);
$window->set_max_duration(29);
$settings->add($window);
$window = new admin_setting_configduration('factor_totp/window',
new lang_string('settings:window', 'factor_totp'),
new lang_string('settings:window_help', 'factor_totp'), 15);
$window->set_max_duration(29);
$settings->add($window);
$settings->add(new admin_setting_configcheckbox('factor_totp/totplink',
new lang_string('settings:totplink', 'factor_totp'),
new lang_string('settings:totplink_help', 'factor_totp'), 1));
$settings->add(new admin_setting_configcheckbox('factor_totp/totplink',
new lang_string('settings:totplink', 'factor_totp'),
new lang_string('settings:totplink_help', 'factor_totp'), 1));
}

View File

@ -25,40 +25,42 @@
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_heading('factor_webauthn/description', '',
new lang_string('settings:description', 'factor_webauthn')));
$settings->add(new admin_setting_heading('factor_webauthn/settings', new lang_string('settings', 'moodle'), ''));
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_heading('factor_webauthn/description', '',
new lang_string('settings:description', 'factor_webauthn')));
$settings->add(new admin_setting_heading('factor_webauthn/settings', new lang_string('settings', 'moodle'), ''));
$enabled = new admin_setting_configcheckbox('factor_webauthn/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function() {
\tool_mfa\manager::do_factor_action('webauthn', get_config('factor_webauthn', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$enabled = new admin_setting_configcheckbox('factor_webauthn/enabled',
new lang_string('settings:enablefactor', 'tool_mfa'),
new lang_string('settings:enablefactor_help', 'tool_mfa'), 0);
$enabled->set_updatedcallback(function() {
\tool_mfa\manager::do_factor_action('webauthn', get_config('factor_webauthn', 'enabled') ? 'enable' : 'disable');
});
$settings->add($enabled);
$settings->add(new admin_setting_configtext('factor_webauthn/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$settings->add(new admin_setting_configtext('factor_webauthn/weight',
new lang_string('settings:weight', 'tool_mfa'),
new lang_string('settings:weight_help', 'tool_mfa'), 100, PARAM_INT));
$authenticators = [
'usb' => get_string('authenticator:usb', 'factor_webauthn'),
'nfc' => get_string('authenticator:nfc', 'factor_webauthn'),
'ble' => get_string('authenticator:ble', 'factor_webauthn'),
'hybrid' => get_string('authenticator:hybrid', 'factor_webauthn'),
'internal' => get_string('authenticator:internal', 'factor_webauthn'),
];
$settings->add(new admin_setting_configmultiselect('factor_webauthn/authenticatortypes',
new lang_string('settings:authenticatortypes', 'factor_webauthn'),
new lang_string('settings:authenticatortypes_help', 'factor_webauthn'),
array_keys($authenticators), $authenticators));
$authenticators = [
'usb' => get_string('authenticator:usb', 'factor_webauthn'),
'nfc' => get_string('authenticator:nfc', 'factor_webauthn'),
'ble' => get_string('authenticator:ble', 'factor_webauthn'),
'hybrid' => get_string('authenticator:hybrid', 'factor_webauthn'),
'internal' => get_string('authenticator:internal', 'factor_webauthn'),
];
$settings->add(new admin_setting_configmultiselect('factor_webauthn/authenticatortypes',
new lang_string('settings:authenticatortypes', 'factor_webauthn'),
new lang_string('settings:authenticatortypes_help', 'factor_webauthn'),
array_keys($authenticators), $authenticators));
$settings->add(new admin_setting_configselect('factor_webauthn/userverification',
new lang_string('settings:userverification', 'factor_webauthn'),
new lang_string('settings:userverification_help', 'factor_webauthn'),
'preferred',
$userverification = [
'required' => get_string('userverification:required', 'factor_webauthn'),
'preferred' => get_string('userverification:preferred', 'factor_webauthn'),
'discouraged' => get_string('userverification:discouraged', 'factor_webauthn'),
]));
$settings->add(new admin_setting_configselect('factor_webauthn/userverification',
new lang_string('settings:userverification', 'factor_webauthn'),
new lang_string('settings:userverification_help', 'factor_webauthn'),
'preferred',
$userverification = [
'required' => get_string('userverification:required', 'factor_webauthn'),
'preferred' => get_string('userverification:preferred', 'factor_webauthn'),
'discouraged' => get_string('userverification:discouraged', 'factor_webauthn'),
]));
}