Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402] [Versions 402 and 403]

   1  <?php
   2  // This file is part of Moodle - https://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  /**
  18   * Defines settingpages and externalpages under the "server" category.
  19   *
  20   * @package     core
  21   * @category    admin
  22   * @copyright   2006 Martin Dougiamas
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  if ($hassiteconfig) {
  29      // System paths.
  30      $temp = new admin_settingpage('systempaths', new lang_string('systempaths', 'admin'));
  31      $temp->add(new admin_setting_configexecutable('pathtophp', new lang_string('pathtophp', 'admin'),
  32          new lang_string('configpathtophp', 'admin'), ''));
  33      $temp->add(new admin_setting_configexecutable('pathtodu', new lang_string('pathtodu', 'admin'),
  34          new lang_string('configpathtodu', 'admin'), ''));
  35      $temp->add(new admin_setting_configexecutable('aspellpath', new lang_string('aspellpath', 'admin'),
  36          new lang_string('edhelpaspellpath'), ''));
  37      $temp->add(new admin_setting_configexecutable('pathtodot', new lang_string('pathtodot', 'admin'),
  38          new lang_string('pathtodot_help', 'admin'), ''));
  39      $temp->add(new admin_setting_configexecutable('pathtogs', new lang_string('pathtogs', 'admin'),
  40          new lang_string('pathtogs_help', 'admin'), '/usr/bin/gs'));
  41      $temp->add(new admin_setting_configexecutable('pathtopdftoppm', new lang_string('pathtopdftoppm', 'admin'),
  42          new lang_string('pathtopdftoppm_help', 'admin'), ''));
  43      $temp->add(new admin_setting_configexecutable('pathtopython', new lang_string('pathtopython', 'admin'),
  44          new lang_string('pathtopythondesc', 'admin'), ''));
  45      $ADMIN->add('server', $temp);
  46  
  47      // Support contact.
  48      $temp = new admin_settingpage('supportcontact', new lang_string('supportcontact', 'admin'));
  49      $primaryadmin = get_admin();
  50      if ($primaryadmin) {
  51          $primaryadminname = fullname($primaryadmin, true);
  52      } else {
  53          // No defaults during installation - admin user must be created first.
  54          $primaryadminname = null;
  55      }
  56      $temp->add(new admin_setting_configtext('supportname', new lang_string('supportname', 'admin'),
  57          new lang_string('configsupportname', 'admin'), $primaryadminname, PARAM_NOTAGS));
  58      $setting = new admin_setting_requiredtext('supportemail', new lang_string('supportemail', 'admin'),
  59          new lang_string('configsupportemail', 'admin'), null, PARAM_EMAIL);
  60      $setting->set_force_ltr(true);
  61      $temp->add($setting);
  62      $temp->add(new admin_setting_configtext('supportpage', new lang_string('supportpage', 'admin'),
  63          new lang_string('configsupportpage', 'admin'), '', PARAM_URL));
  64      $temp->add(new admin_setting_configselect('supportavailability', new lang_string('supportavailability', 'admin'),
  65          new lang_string('configsupportavailability', 'admin'), CONTACT_SUPPORT_AUTHENTICATED,
  66          [
  67              CONTACT_SUPPORT_ANYONE => new lang_string('availabletoanyone', 'admin'),
  68              CONTACT_SUPPORT_AUTHENTICATED => new lang_string('availabletoauthenticated', 'admin'),
  69              CONTACT_SUPPORT_DISABLED => new lang_string('disabled', 'admin'),
  70          ]
  71      ));
  72      $temp->add(new admin_setting_configtext('servicespage', new lang_string('servicespage', 'admin'),
  73          new lang_string('configservicespage', 'admin'), '', PARAM_URL));
  74  
  75      $ADMIN->add('server', $temp);
  76  
  77      // Session handling.
  78      $temp = new admin_settingpage('sessionhandling', new lang_string('sessionhandling', 'admin'));
  79      if (empty($CFG->session_handler_class) and $DB->session_lock_supported()) {
  80          $temp->add(new admin_setting_configcheckbox('dbsessions', new lang_string('dbsessions', 'admin'),
  81              new lang_string('configdbsessions', 'admin'), 0));
  82      }
  83  
  84      $temp->add(new admin_setting_configduration('sessiontimeout', new lang_string('sessiontimeout', 'admin'),
  85          new lang_string('configsessiontimeout', 'admin'), 8 * 60 * 60));
  86  
  87      $sessiontimeoutwarning = new admin_setting_configduration('sessiontimeoutwarning',
  88          new lang_string('sessiontimeoutwarning', 'admin'),
  89          new lang_string('configsessiontimeoutwarning', 'admin'), 20 * 60);
  90  
  91      $sessiontimeoutwarning->set_validate_function(function(int $value): string {
  92          global $CFG;
  93          // Check sessiontimeoutwarning is less than sessiontimeout.
  94          if ($CFG->sessiontimeout <= $value) {
  95              return get_string('configsessiontimeoutwarningcheck', 'admin');
  96          } else {
  97              return '';
  98          }
  99      });
 100  
 101      $temp->add($sessiontimeoutwarning);
 102  
 103      $temp->add(new admin_setting_configtext('sessioncookie', new lang_string('sessioncookie', 'admin'),
 104          new lang_string('configsessioncookie', 'admin'), '', PARAM_ALPHANUM));
 105      $temp->add(new admin_setting_configtext('sessioncookiepath', new lang_string('sessioncookiepath', 'admin'),
 106          new lang_string('configsessioncookiepath', 'admin'), '', PARAM_RAW));
 107      $temp->add(new admin_setting_configtext('sessioncookiedomain', new lang_string('sessioncookiedomain', 'admin'),
 108          new lang_string('configsessioncookiedomain', 'admin'), '', PARAM_RAW, 50));
 109      $ADMIN->add('server', $temp);
 110  
 111      // Statistics.
 112      $temp = new admin_settingpage('stats', new lang_string('stats'), 'moodle/site:config', empty($CFG->enablestats));
 113      $temp->add(new admin_setting_configselect('statsfirstrun', new lang_string('statsfirstrun', 'admin'),
 114          new lang_string('configstatsfirstrun', 'admin'), 'none',
 115          [
 116              'none' => new lang_string('none'),
 117              60 * 60 * 24 * 7 => new lang_string('numweeks', 'moodle', 1),
 118              60 * 60 * 24 * 14 => new lang_string('numweeks', 'moodle', 2),
 119              60 * 60 * 24 * 21 => new lang_string('numweeks', 'moodle', 3),
 120              60 * 60 * 24 * 28 => new lang_string('nummonths', 'moodle', 1),
 121              60 * 60 * 24 * 56 => new lang_string('nummonths', 'moodle', 2),
 122              60 * 60 * 24 * 84 => new lang_string('nummonths', 'moodle', 3),
 123              60 * 60 * 24 * 112 => new lang_string('nummonths', 'moodle', 4),
 124              60 * 60 * 24 * 140 => new lang_string('nummonths', 'moodle', 5),
 125              60 * 60 * 24 * 168 => new lang_string('nummonths', 'moodle', 6),
 126              'all' => new lang_string('all')
 127          ]
 128      ));
 129      $temp->add(new admin_setting_configselect('statsmaxruntime', new lang_string('statsmaxruntime', 'admin'),
 130          new lang_string('configstatsmaxruntime3', 'admin'), 0,
 131          [
 132              0 => new lang_string('untilcomplete'),
 133              60 * 30 => '10 ' . new lang_string('minutes'),
 134              60 * 30 => '30 ' . new lang_string('minutes'),
 135              60 * 60 => '1 ' . new lang_string('hour'),
 136              60 * 60 * 2 => '2 ' . new lang_string('hours'),
 137              60 * 60 * 3 => '3 ' . new lang_string('hours'),
 138              60 * 60 * 4 => '4 ' . new lang_string('hours'),
 139              60 * 60 * 5 => '5 ' . new lang_string('hours'),
 140              60 * 60 * 6 => '6 ' . new lang_string('hours'),
 141              60 * 60 * 7 => '7 ' . new lang_string('hours'),
 142              60 * 60 * 8 => '8 ' . new lang_string('hours'),
 143          ]
 144      ));
 145      $temp->add(new admin_setting_configtext('statsruntimedays', new lang_string('statsruntimedays', 'admin'),
 146          new lang_string('configstatsruntimedays', 'admin'), 31, PARAM_INT));
 147      $temp->add(new admin_setting_configtext('statsuserthreshold', new lang_string('statsuserthreshold', 'admin'),
 148          new lang_string('configstatsuserthreshold', 'admin'), 0, PARAM_INT));
 149      $ADMIN->add('server', $temp);
 150  
 151      // HTTP.
 152      $temp = new admin_settingpage('http', new lang_string('http', 'admin'));
 153      $temp->add(new admin_setting_configcheckbox('slasharguments', new lang_string('slasharguments', 'admin'),
 154          new lang_string('configslasharguments', 'admin'), 1));
 155      $temp->add(new admin_setting_heading('reverseproxy', new lang_string('reverseproxy', 'admin'), '', ''));
 156      $options = [
 157          0 => 'HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, REMOTE_ADDR',
 158          GETREMOTEADDR_SKIP_HTTP_CLIENT_IP => 'HTTP_X_FORWARDED_FOR, REMOTE_ADDR',
 159          GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR => 'HTTP_CLIENT, REMOTE_ADDR',
 160          GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR | GETREMOTEADDR_SKIP_HTTP_CLIENT_IP => 'REMOTE_ADDR'
 161      ];
 162      $temp->add(new admin_setting_configselect('getremoteaddrconf', new lang_string('getremoteaddrconf', 'admin'),
 163          new lang_string('configgetremoteaddrconf', 'admin'),
 164          GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR | GETREMOTEADDR_SKIP_HTTP_CLIENT_IP, $options));
 165      $temp->add(new admin_setting_configtext('reverseproxyignore', new lang_string('reverseproxyignore', 'admin'),
 166          new lang_string('configreverseproxyignore', 'admin'), ''));
 167  
 168      $temp->add(new admin_setting_heading('webproxy', new lang_string('webproxy', 'admin'),
 169          new lang_string('webproxyinfo', 'admin')));
 170      $temp->add(new admin_setting_configtext('proxyhost', new lang_string('proxyhost', 'admin'),
 171          new lang_string('configproxyhost', 'admin'), '', PARAM_HOST));
 172      $temp->add(new admin_setting_configtext('proxyport', new lang_string('proxyport', 'admin'),
 173          new lang_string('configproxyport', 'admin'), 0, PARAM_INT));
 174      $options = ['HTTP' => 'HTTP'];
 175      if (defined('CURLPROXY_SOCKS5')) {
 176          $options['SOCKS5'] = 'SOCKS5';
 177      }
 178      $temp->add(new admin_setting_configselect('proxytype', new lang_string('proxytype', 'admin'),
 179          new lang_string('configproxytype', 'admin'), 'HTTP', $options));
 180      $temp->add(new admin_setting_configtext('proxyuser', new lang_string('proxyuser', 'admin'),
 181          new lang_string('configproxyuser', 'admin'), ''));
 182      $temp->add(new admin_setting_configpasswordunmask('proxypassword', new lang_string('proxypassword', 'admin'),
 183          new lang_string('configproxypassword', 'admin'), ''));
 184      $temp->add(new admin_setting_configtext('proxybypass', new lang_string('proxybypass', 'admin'),
 185          new lang_string('configproxybypass', 'admin'), 'localhost, 127.0.0.1'));
 186      $temp->add(new admin_setting_configcheckbox('proxylogunsafe', new lang_string('proxylogunsafe', 'admin'),
 187          new lang_string('configproxylogunsafe_help', 'admin'), 0));
 188      $temp->add(new admin_setting_configcheckbox('proxyfixunsafe', new lang_string('proxyfixunsafe', 'admin'),
 189          new lang_string('configproxyfixunsafe_help', 'admin'), 0));
 190  
 191      $ADMIN->add('server', $temp);
 192  
 193      $temp = new admin_settingpage('maintenancemode', new lang_string('sitemaintenancemode', 'admin'));
 194      $options = [0 => new lang_string('disable'), 1 => new lang_string('enable')];
 195      $temp->add(new admin_setting_configselect('maintenance_enabled', new lang_string('sitemaintenancemode', 'admin'),
 196          new lang_string('helpsitemaintenance', 'admin'), 0, $options));
 197      $temp->add(new admin_setting_confightmleditor('maintenance_message', new lang_string('optionalmaintenancemessage', 'admin'),
 198          '', ''));
 199      $ADMIN->add('server', $temp);
 200  
 201      // Cleanup.
 202      $temp = new admin_settingpage('cleanup', new lang_string('cleanup', 'admin'));
 203      $temp->add(new admin_setting_configselect('deleteunconfirmed', new lang_string('deleteunconfirmed', 'admin'),
 204          new lang_string('configdeleteunconfirmed', 'admin'), 168,
 205          [
 206              0 => new lang_string('never'),
 207              168 => new lang_string('numdays', '', 7),
 208              144 => new lang_string('numdays', '', 6),
 209              120 => new lang_string('numdays', '', 5),
 210              96 => new lang_string('numdays', '', 4),
 211              72 => new lang_string('numdays', '', 3),
 212              48 => new lang_string('numdays', '', 2),
 213              24 => new lang_string('numdays', '', 1),
 214              12 => new lang_string('numhours', '', 12),
 215              6 => new lang_string('numhours', '', 6),
 216              1 => new lang_string('numhours', '', 1),
 217          ]
 218      ));
 219  
 220      $temp->add(new admin_setting_configselect('deleteincompleteusers', new lang_string('deleteincompleteusers', 'admin'),
 221          new lang_string('configdeleteincompleteusers', 'admin'), 0,
 222          [
 223              0 => new lang_string('never'),
 224              168 => new lang_string('numdays', '', 7),
 225              144 => new lang_string('numdays', '', 6),
 226              120 => new lang_string('numdays', '', 5),
 227              96 => new lang_string('numdays', '', 4),
 228              72 => new lang_string('numdays', '', 3),
 229              48 => new lang_string('numdays', '', 2),
 230              24 => new lang_string('numdays', '', 1),
 231          ]
 232      ));
 233  
 234      $temp->add(new admin_setting_configcheckbox('disablegradehistory', new lang_string('disablegradehistory', 'grades'),
 235          new lang_string('disablegradehistory_help', 'grades'), 0));
 236  
 237      $temp->add(new admin_setting_configselect('gradehistorylifetime', new lang_string('gradehistorylifetime', 'grades'),
 238          new lang_string('gradehistorylifetime_help', 'grades'), 0,
 239          [
 240              0 => new lang_string('neverdeletehistory', 'grades'),
 241              1000 => new lang_string('numdays', '', 1000),
 242              365 => new lang_string('numdays', '', 365),
 243              180 => new lang_string('numdays', '', 180),
 244              150 => new lang_string('numdays', '', 150),
 245              120 => new lang_string('numdays', '', 120),
 246              90 => new lang_string('numdays', '', 90),
 247              60 => new lang_string('numdays', '', 60),
 248              30 => new lang_string('numdays', '', 30),
 249          ]
 250      ));
 251  
 252      $temp->add(new admin_setting_configselect('tempdatafoldercleanup', new lang_string('tempdatafoldercleanup', 'admin'),
 253          new lang_string('configtempdatafoldercleanup', 'admin'), 168,
 254          [
 255              1 => new lang_string('numhours', '', 1),
 256              3 => new lang_string('numhours', '', 3),
 257              6 => new lang_string('numhours', '', 6),
 258              9 => new lang_string('numhours', '', 9),
 259              12 => new lang_string('numhours', '', 12),
 260              18 => new lang_string('numhours', '', 18),
 261              24 => new lang_string('numhours', '', 24),
 262              48 => new lang_string('numdays', '', 2),
 263              168 => new lang_string('numdays', '', 7),
 264          ]
 265      ));
 266  
 267      $temp->add(new admin_setting_configduration(
 268          'xapicleanupperiod',
 269          new lang_string('xapicleanupperiod', 'xapi'),
 270          new lang_string('xapicleanupperiod_help', 'xapi'),
 271          WEEKSECS * 8,
 272          WEEKSECS
 273      ));
 274  
 275      $ADMIN->add('server', $temp);
 276  
 277      $temp->add(new admin_setting_configduration('filescleanupperiod',
 278          new lang_string('filescleanupperiod', 'admin'),
 279          new lang_string('filescleanupperiod_help', 'admin'),
 280          86400));
 281  
 282      // Environment.
 283      $ADMIN->add('server', new admin_externalpage('environment', new lang_string('environment', 'admin'),
 284          "{$CFG->wwwroot}/{$CFG->admin}/environment.php"));
 285  
 286      // PHP info.
 287      $ADMIN->add('server', new admin_externalpage('phpinfo', new lang_string('phpinfo'),
 288          "{$CFG->wwwroot}/{$CFG->admin}/phpinfo.php"));
 289  
 290      // Test outgoing mail configuration (hidden, accessed via direct link from the settings page).
 291      $ADMIN->add('server', new admin_externalpage('testoutgoingmailconf', new lang_string('testoutgoingmailconf', 'admin'),
 292          new moodle_url('/admin/testoutgoingmailconf.php'), 'moodle/site:config', true));
 293  
 294      // Performance.
 295      $temp = new admin_settingpage('performance', new lang_string('performance', 'admin'));
 296  
 297      // Memory limit options for large administration tasks.
 298      $memoryoptions = [
 299          '64M' => '64M',
 300          '128M' => '128M',
 301          '256M' => '256M',
 302          '512M' => '512M',
 303          '1024M' => '1024M',
 304          '2048M' => '2048M',
 305      ];
 306  
 307      // Allow larger memory usage for 64-bit sites only.
 308      if (PHP_INT_SIZE === 8) {
 309          $memoryoptions['3072M'] = '3072M';
 310          $memoryoptions['4096M'] = '4096M';
 311      }
 312  
 313      $temp->add(new admin_setting_configselect('extramemorylimit', new lang_string('extramemorylimit', 'admin'),
 314          new lang_string('configextramemorylimit', 'admin'), '512M', $memoryoptions));
 315  
 316      $temp->add(new admin_setting_configtext('maxtimelimit', new lang_string('maxtimelimit', 'admin'),
 317          new lang_string('maxtimelimit_desc', 'admin'), 0, PARAM_INT));
 318  
 319      $temp->add(new admin_setting_configtext('curlcache', new lang_string('curlcache', 'admin'),
 320          new lang_string('configcurlcache', 'admin'), 120, PARAM_INT));
 321  
 322      $temp->add(new admin_setting_configtext('curltimeoutkbitrate', new lang_string('curltimeoutkbitrate', 'admin'),
 323          new lang_string('curltimeoutkbitrate_help', 'admin'), 56, PARAM_INT));
 324  
 325      $ADMIN->add('server', $temp);
 326  
 327      // Tasks.
 328      $ADMIN->add('server', new admin_category('taskconfig', new lang_string('taskadmintitle', 'admin')));
 329  
 330      // Task processing.
 331      $temp = new admin_settingpage('taskprocessing', new lang_string('taskprocessing', 'admin'));
 332  
 333      $setting = new admin_setting_configcheckbox(
 334          'cron_enabled',
 335          new lang_string('cron_enabled', 'admin'),
 336          new lang_string('cron_enabled_desc', 'admin'),
 337          1
 338      );
 339      $setting->set_updatedcallback('theme_reset_static_caches');
 340      $temp->add($setting);
 341  
 342      $setting = new admin_setting_configduration(
 343          'cron_keepalive',
 344          new lang_string('cron_keepalive', 'admin'),
 345          new lang_string('cron_keepalive_desc', 'admin'),
 346          \core\cron::DEFAULT_MAIN_PROCESS_KEEPALIVE,
 347          // The default unit is minutes.
 348          MINSECS,
 349      );
 350  
 351      // Set an upper limit.
 352      $setting->set_max_duration(\core\cron::MAX_MAIN_PROCESS_KEEPALIVE);
 353  
 354      $temp->add($setting);
 355  
 356      $temp->add(
 357          new admin_setting_configtext(
 358              'task_scheduled_concurrency_limit',
 359              new lang_string('task_scheduled_concurrency_limit', 'admin'),
 360              new lang_string('task_scheduled_concurrency_limit_desc', 'admin'),
 361              3,
 362              PARAM_INT
 363          )
 364      );
 365  
 366      $temp->add(
 367          new admin_setting_configduration(
 368              'task_scheduled_max_runtime',
 369              new lang_string('task_scheduled_max_runtime', 'admin'),
 370              new lang_string('task_scheduled_max_runtime_desc', 'admin'),
 371              30 * MINSECS
 372          )
 373      );
 374  
 375      $temp->add(
 376          new admin_setting_configtext(
 377              'task_adhoc_concurrency_limit',
 378              new lang_string('task_adhoc_concurrency_limit', 'admin'),
 379              new lang_string('task_adhoc_concurrency_limit_desc', 'admin'),
 380              3,
 381              PARAM_INT
 382          )
 383      );
 384  
 385      $temp->add(
 386          new admin_setting_configduration(
 387              'task_adhoc_max_runtime',
 388              new lang_string('task_adhoc_max_runtime', 'admin'),
 389              new lang_string('task_adhoc_max_runtime_desc', 'admin'),
 390              30 * MINSECS
 391          )
 392      );
 393      $ADMIN->add('taskconfig', $temp);
 394  
 395      // Task log configuration.
 396      $temp = new admin_settingpage('tasklogging', new lang_string('tasklogging', 'admin'));
 397      $temp->add(
 398          new admin_setting_configselect(
 399              'task_logmode',
 400              new lang_string('task_logmode', 'admin'),
 401              new lang_string('task_logmode_desc', 'admin'),
 402              \core\task\logmanager::MODE_ALL,
 403              [
 404                  \core\task\logmanager::MODE_ALL => new lang_string('task_logmode_all', 'admin'),
 405                  \core\task\logmanager::MODE_FAILONLY => new lang_string('task_logmode_failonly', 'admin'),
 406                  \core\task\logmanager::MODE_NONE => new lang_string('task_logmode_none', 'admin'),
 407              ]
 408          )
 409      );
 410      $temp->add(
 411          new admin_setting_configcheckbox(
 412              'task_logtostdout',
 413              new lang_string('task_logtostdout', 'admin'),
 414              new lang_string('task_logtostdout_desc', 'admin'),
 415              1
 416          )
 417      );
 418  
 419      if (\core\task\logmanager::uses_standard_settings()) {
 420          $temp->add(
 421              new admin_setting_configduration(
 422                  'task_logretention',
 423                  new \lang_string('task_logretention', 'admin'),
 424                  new \lang_string('task_logretention_desc', 'admin'),
 425                  28 * DAYSECS
 426              )
 427          );
 428  
 429          $temp->add(
 430              new admin_setting_configtext(
 431                  'task_logretainruns',
 432                  new \lang_string('task_logretainruns', 'admin'),
 433                  new \lang_string('task_logretainruns_desc', 'admin'),
 434                  20,
 435                  PARAM_INT
 436              )
 437          );
 438      }
 439      $ADMIN->add('taskconfig', $temp);
 440  
 441      // Task logs.
 442      if (\core\task\logmanager::uses_standard_settings()) {
 443          $ADMIN->add('taskconfig', new admin_externalpage(
 444              'tasklogs',
 445              new lang_string('tasklogs', 'admin'),
 446              "{$CFG->wwwroot}/{$CFG->admin}/tasklogs.php"
 447          ));
 448      }
 449  
 450      // Email.
 451      $ADMIN->add('server', new admin_category('email', new lang_string('categoryemail', 'admin')));
 452  
 453      // Outgoing mail configuration.
 454      $temp = new admin_settingpage('outgoingmailconfig', new lang_string('outgoingmailconfig', 'admin'));
 455  
 456      $temp->add(new admin_setting_heading('smtpheading', new lang_string('smtp', 'admin'),
 457          new lang_string('smtpdetail', 'admin')));
 458  
 459      $temp->add(new admin_setting_configtext('smtphosts', new lang_string('smtphosts', 'admin'),
 460          new lang_string('configsmtphosts', 'admin'), '', PARAM_RAW));
 461  
 462      $options = [
 463          '' => new lang_string('none', 'admin'),
 464          'ssl' => 'SSL',
 465          'tls' => 'TLS',
 466      ];
 467  
 468      $temp->add(new admin_setting_configselect('smtpsecure', new lang_string('smtpsecure', 'admin'),
 469          new lang_string('configsmtpsecure', 'admin'), '', $options));
 470  
 471      $authtypeoptions = [
 472          'LOGIN' => 'LOGIN',
 473          'PLAIN' => 'PLAIN',
 474          'NTLM' => 'NTLM',
 475          'CRAM-MD5' => 'CRAM-MD5',
 476      ];
 477  
 478      // Get all the issuers.
 479      $issuers = \core\oauth2\api::get_all_issuers();
 480      $enabledissuers = [];
 481      foreach ($issuers as $issuer) {
 482          // Get the enabled issuer only.
 483          if ($issuer->get('enabled')) {
 484              $enabledissuers[] = $issuer;
 485          }
 486      }
 487  
 488      if (count($enabledissuers) > 0) {
 489          $authtypeoptions['XOAUTH2'] = 'XOAUTH2';
 490      }
 491  
 492      $temp->add(new admin_setting_configselect('smtpauthtype', new lang_string('smtpauthtype', 'admin'),
 493          new lang_string('configsmtpauthtype', 'admin'), 'LOGIN', $authtypeoptions));
 494  
 495      if (count($enabledissuers) > 0) {
 496          $oauth2services = [
 497              '' => new lang_string('none', 'admin'),
 498          ];
 499          foreach ($enabledissuers as $issuer) {
 500              $oauth2services[$issuer->get('id')] = s($issuer->get('name'));
 501          }
 502  
 503          $temp->add(new admin_setting_configselect('smtpoauthservice', new lang_string('issuer', 'auth_oauth2'),
 504              new lang_string('configsmtpoauthservice', 'admin'), '', $oauth2services));
 505      }
 506  
 507      $temp->add(new admin_setting_configtext('smtpuser', new lang_string('smtpuser', 'admin'),
 508          new lang_string('configsmtpuser', 'admin'), '', PARAM_NOTAGS));
 509  
 510      $temp->add(new admin_setting_configpasswordunmask('smtppass', new lang_string('smtppass', 'admin'),
 511          new lang_string('configsmtpuser', 'admin'), ''));
 512  
 513      $temp->add(new admin_setting_configtext('smtpmaxbulk', new lang_string('smtpmaxbulk', 'admin'),
 514          new lang_string('configsmtpmaxbulk', 'admin'), 1, PARAM_INT));
 515  
 516      $temp->add(new admin_setting_heading('noreplydomainheading', new lang_string('noreplydomain', 'admin'),
 517          new lang_string('noreplydomaindetail', 'admin')));
 518  
 519      $temp->add(new admin_setting_configtext('noreplyaddress', new lang_string('noreplyaddress', 'admin'),
 520          new lang_string('confignoreplyaddress', 'admin'), 'noreply@' . get_host_from_url($CFG->wwwroot), PARAM_EMAIL));
 521  
 522      $temp->add(new admin_setting_configtextarea('allowedemaildomains',
 523          new lang_string('allowedemaildomains', 'admin'),
 524          new lang_string('configallowedemaildomains', 'admin'),
 525          ''));
 526  
 527      $temp->add(new admin_setting_heading('divertallemailsheading', new lang_string('divertallemails', 'admin'),
 528          new lang_string('divertallemailsdetail', 'admin')));
 529      $temp->add(new admin_setting_configtext('divertallemailsto',
 530          new lang_string('divertallemailsto', 'admin'),
 531          new lang_string('divertallemailsto_desc', 'admin'),
 532          ''));
 533      $temp->add(new admin_setting_configtextarea('divertallemailsexcept',
 534          new lang_string('divertallemailsexcept', 'admin'),
 535          new lang_string('divertallemailsexcept_desc', 'admin'),
 536          '', PARAM_RAW, '50', '4'));
 537  
 538      $noreplyaddress = isset($CFG->noreplyaddress) ? $CFG->noreplyaddress : 'noreply@example.com';
 539      $dkimdomain = substr(strrchr($noreplyaddress, "@"), 1);
 540      $dkimselector = empty($CFG->emaildkimselector) ? '[selector]' : $CFG->emaildkimselector;
 541      $pempath = "\$CFG->dataroot/dkim/{$dkimdomain}/{$dkimselector}.private";
 542      $temp->add(new admin_setting_heading('emaildkim', new lang_string('emaildkim', 'admin'),
 543          new lang_string('emaildkiminfo', 'admin', ['path' => $pempath, 'docs' => \get_docs_url('Mail_configuration#DKIM')])));
 544      $temp->add(new admin_setting_configtext('emaildkimselector', new lang_string('emaildkimselector', 'admin'),
 545          new lang_string('configemaildkimselector', 'admin'), '', PARAM_FILE));
 546  
 547      $url = new moodle_url('/admin/testoutgoingmailconf.php');
 548      $link = html_writer::link($url, get_string('testoutgoingmailconf', 'admin'));
 549      $temp->add(new admin_setting_heading('testoutgoinmailc', new lang_string('testoutgoingmailconf', 'admin'),
 550          new lang_string('testoutgoingmaildetail', 'admin', $link)));
 551  
 552      $temp->add(new admin_setting_heading('emaildoesnotfit', new lang_string('doesnotfit', 'admin'),
 553          new lang_string('doesnotfitdetail', 'admin')));
 554  
 555      $charsets = get_list_of_charsets();
 556      unset($charsets['UTF-8']);
 557      $options = [
 558          '0' => 'UTF-8',
 559      ];
 560      $options = array_merge($options, $charsets);
 561      $temp->add(new admin_setting_configselect('sitemailcharset', new lang_string('sitemailcharset', 'admin'),
 562          new lang_string('configsitemailcharset', 'admin'), '0', $options));
 563  
 564      $temp->add(new admin_setting_configcheckbox('allowusermailcharset', new lang_string('allowusermailcharset', 'admin'),
 565          new lang_string('configallowusermailcharset', 'admin'), 0));
 566  
 567      $temp->add(new admin_setting_configcheckbox('allowattachments', new lang_string('allowattachments', 'admin'),
 568          new lang_string('configallowattachments', 'admin'), 1));
 569  
 570      $options = [
 571          'LF' => 'LF',
 572          'CRLF' => 'CRLF',
 573      ];
 574      $temp->add(new admin_setting_configselect('mailnewline', new lang_string('mailnewline', 'admin'),
 575          new lang_string('configmailnewline', 'admin'), 'LF', $options));
 576  
 577      $choices = [
 578          new lang_string('never', 'admin'),
 579          new lang_string('always', 'admin'),
 580          new lang_string('onlynoreply', 'admin'),
 581      ];
 582      $temp->add(new admin_setting_configselect('emailfromvia', new lang_string('emailfromvia', 'admin'),
 583          new lang_string('configemailfromvia', 'admin'), 1, $choices));
 584  
 585      $temp->add(new admin_setting_configtext('emailsubjectprefix', new lang_string('emailsubjectprefix', 'admin'),
 586          new lang_string('configemailsubjectprefix', 'admin'), '', PARAM_RAW));
 587  
 588      $temp->add(new admin_setting_configtextarea('emailheaders', new lang_string('emailheaders', 'admin'),
 589          new lang_string('configemailheaders', 'admin'), '', PARAM_RAW, '50', '3'));
 590  
 591      $ADMIN->add('email', $temp);
 592  
 593      // Update notifications.
 594      if (empty($CFG->disableupdatenotifications)) {
 595          $temp = new admin_settingpage('updatenotifications', new lang_string('updatenotifications', 'core_admin'));
 596          $temp->add(new admin_setting_configcheckbox('updateautocheck', new lang_string('updateautocheck', 'core_admin'),
 597              new lang_string('updateautocheck_desc', 'core_admin'), 1));
 598          $temp->add(new admin_setting_configselect('updateminmaturity', new lang_string('updateminmaturity', 'core_admin'),
 599              new lang_string('updateminmaturity_desc', 'core_admin'), MATURITY_STABLE,
 600              [
 601                  MATURITY_ALPHA => new lang_string('maturity'.MATURITY_ALPHA, 'core_admin'),
 602                  MATURITY_BETA => new lang_string('maturity'.MATURITY_BETA, 'core_admin'),
 603                  MATURITY_RC => new lang_string('maturity'.MATURITY_RC, 'core_admin'),
 604                  MATURITY_STABLE => new lang_string('maturity'.MATURITY_STABLE, 'core_admin'),
 605              ]
 606          ));
 607          $temp->add(new admin_setting_configcheckbox('updatenotifybuilds', new lang_string('updatenotifybuilds', 'core_admin'),
 608              new lang_string('updatenotifybuilds_desc', 'core_admin'), 0));
 609          $ADMIN->add('server', $temp);
 610      }
 611  
 612      // Web services.
 613      $ADMIN->add('server', new admin_category('webservicesettings', new lang_string('webservices', 'webservice')));
 614  
 615      // Web services > Overview.
 616      $temp = new admin_settingpage('webservicesoverview', new lang_string('webservicesoverview', 'webservice'));
 617      $temp->add(new admin_setting_webservicesoverview());
 618      $ADMIN->add('webservicesettings', $temp);
 619  
 620      // Web services > API documentation.
 621      $ADMIN->add('webservicesettings', new admin_externalpage('webservicedocumentation', new lang_string('wsdocapi', 'webservice'),
 622          "{$CFG->wwwroot}/{$CFG->admin}/webservice/documentation.php", 'moodle/site:config', false));
 623  
 624      // Web services > External services.
 625      $temp = new admin_settingpage('externalservices', new lang_string('externalservices', 'webservice'));
 626  
 627      $temp->add(new admin_setting_heading('manageserviceshelpexplaination', new lang_string('information', 'webservice'),
 628          new lang_string('servicehelpexplanation', 'webservice')));
 629  
 630      $temp->add(new admin_setting_manageexternalservices());
 631  
 632      $ADMIN->add('webservicesettings', $temp);
 633  
 634      $ADMIN->add('webservicesettings', new admin_externalpage('externalservice', new lang_string('editaservice', 'webservice'),
 635          "{$CFG->wwwroot}/{$CFG->admin}/webservice/service.php", 'moodle/site:config', true));
 636  
 637      $ADMIN->add('webservicesettings', new admin_externalpage('externalservicefunctions',
 638          new lang_string('externalservicefunctions', 'webservice'), "{$CFG->wwwroot}/{$CFG->admin}/webservice/service_functions.php",
 639          'moodle/site:config', true));
 640  
 641      $ADMIN->add('webservicesettings', new admin_externalpage('externalserviceusers',
 642          new lang_string('externalserviceusers', 'webservice'), "{$CFG->wwwroot}/{$CFG->admin}/webservice/service_users.php",
 643          'moodle/site:config', true));
 644  
 645      $ADMIN->add('webservicesettings', new admin_externalpage('externalserviceusersettings',
 646          new lang_string('serviceusersettings', 'webservice'), "{$CFG->wwwroot}/{$CFG->admin}/webservice/service_user_settings.php",
 647          'moodle/site:config', true));
 648  
 649      // Web services > Manage protocols.
 650      $temp = new admin_settingpage('webserviceprotocols', new lang_string('manageprotocols', 'webservice'));
 651      $temp->add(new admin_setting_managewebserviceprotocols());
 652      if (empty($CFG->enablewebservices)) {
 653          $temp->add(new admin_setting_heading('webservicesaredisabled', '', new lang_string('disabledwarning', 'webservice')));
 654      }
 655  
 656      // We cannot use $OUTPUT->doc_link() this early, we would lose the ability to set the page layout on all admin pages.
 657      $url = new moodle_url(get_docs_url('How_to_get_a_security_key'));
 658      $wsdoclink = html_writer::link($url, new lang_string('supplyinfo', 'webservice'), ['target' => '_blank']);
 659      $temp->add(new admin_setting_configcheckbox('enablewsdocumentation', new lang_string('enablewsdocumentation', 'admin'),
 660          new lang_string('configenablewsdocumentation', 'admin', $wsdoclink), false));
 661  
 662      $ADMIN->add('webservicesettings', $temp);
 663  
 664      $plugins = core_plugin_manager::instance()->get_plugins_of_type('webservice');
 665      core_collator::asort_objects_by_property($plugins, 'displayname');
 666      foreach ($plugins as $plugin) {
 667          /** @var \core\plugininfo\webservice $plugin */
 668          $plugin->load_settings($ADMIN, 'webservicesettings', $hassiteconfig);
 669      }
 670  
 671      // Web services > Manage tokens.
 672      $ADMIN->add('webservicesettings', new admin_externalpage('webservicetokens', new lang_string('managetokens', 'webservice'),
 673          new moodle_url('/admin/webservice/tokens.php')));
 674  }