Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   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  /**
  18   * Check API manager
  19   *
  20   * @package    core
  21   * @category   check
  22   * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace core\check;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  /**
  31   * Check API manager
  32   *
  33   * @package    core
  34   * @category   check
  35   * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class manager {
  39  
  40      /**
  41       * The list of valid check types
  42       */
  43      public const TYPES = ['status', 'security', 'performance'];
  44  
  45      /**
  46       * Return all status checks
  47       *
  48       * @param string $type of checks to fetch
  49       * @return array of check objects
  50       */
  51      public static function get_checks(string $type): array {
  52          if (!in_array($type, self::TYPES)) {
  53              throw new \moodle_exception("Invalid check type '$type'");
  54          }
  55          $method = 'get_' . $type . '_checks';
  56          $checks = self::$method();
  57          return $checks;
  58      }
  59  
  60      /**
  61       * Return all performance checks
  62       *
  63       * @return array of check objects
  64       */
  65      static public function get_performance_checks() : array {
  66          $checks = [
  67              new performance\designermode(),
  68              new performance\cachejs(),
  69              new performance\debugging(),
  70              new performance\backups(),
  71              new performance\stats(),
  72          ];
  73  
  74          // Any plugin can add status checks to this report by implementing a callback
  75          // <component>_status_checks() which returns a check object.
  76          $morechecks = get_plugins_with_function('performance_checks', 'lib.php');
  77          foreach ($morechecks as $plugintype => $plugins) {
  78              foreach ($plugins as $plugin => $pluginfunction) {
  79                  $result = $pluginfunction();
  80                  foreach ($result as $check) {
  81                      $check->set_component($plugintype . '_' . $plugin);
  82                      $checks[] = $check;
  83                  }
  84              }
  85          }
  86          return $checks;
  87      }
  88  
  89      /**
  90       * Return all status checks
  91       *
  92       * @return array of check objects
  93       */
  94      public static function get_status_checks(): array {
  95          $checks = [
  96              new environment\environment(),
  97              new environment\upgradecheck(),
  98          ];
  99  
 100          // Any plugin can add status checks to this report by implementing a callback
 101          // <component>_status_checks() which returns a check object.
 102          $morechecks = get_plugins_with_function('status_checks', 'lib.php');
 103          foreach ($morechecks as $plugintype => $plugins) {
 104              foreach ($plugins as $plugin => $pluginfunction) {
 105                  $result = $pluginfunction();
 106                  foreach ($result as $check) {
 107                      $check->set_component($plugintype . '_' . $plugin);
 108                      $checks[] = $check;
 109                  }
 110              }
 111          }
 112          return $checks;
 113      }
 114  
 115      /**
 116       * Return all security checks
 117       *
 118       * @return array of check objects
 119       */
 120      public static function get_security_checks(): array {
 121          $checks = [
 122              new environment\displayerrors(),
 123              new environment\unsecuredataroot(),
 124              new environment\publicpaths(),
 125              new environment\configrw(),
 126              new environment\preventexecpath(),
 127              new security\mediafilterswf(),
 128              new security\embed(),
 129              new security\openprofiles(),
 130              new security\crawlers(),
 131              new security\passwordpolicy(),
 132              new security\emailchangeconfirmation(),
 133              new security\webcron(),
 134              new http\cookiesecure(),
 135              new access\riskadmin(),
 136              new access\riskxss(),
 137              new access\riskbackup(),
 138              new access\defaultuserrole(),
 139              new access\guestrole(),
 140              new access\frontpagerole(),
 141          ];
 142          // Any plugin can add security checks to this report by implementing a callback
 143          // <component>_security_checks() which returns a check object.
 144          $morechecks = get_plugins_with_function('security_checks', 'lib.php');
 145          foreach ($morechecks as $plugintype => $plugins) {
 146              foreach ($plugins as $plugin => $pluginfunction) {
 147                  $result = $pluginfunction();
 148                  foreach ($result as $check) {
 149                      $check->set_component($plugintype . '_' . $plugin);
 150                      $checks[] = $check;
 151                  }
 152              }
 153          }
 154          return $checks;
 155      }
 156  }
 157