Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   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\vendordir(),
 125              new environment\nodemodules(),
 126              new environment\configrw(),
 127              new environment\preventexecpath(),
 128              new security\mediafilterswf(),
 129              new security\embed(),
 130              new security\openprofiles(),
 131              new security\crawlers(),
 132              new security\passwordpolicy(),
 133              new security\emailchangeconfirmation(),
 134              new security\webcron(),
 135              new http\cookiesecure(),
 136              new access\riskadmin(),
 137              new access\riskxss(),
 138              new access\riskbackup(),
 139              new access\defaultuserrole(),
 140              new access\guestrole(),
 141              new access\frontpagerole(),
 142          ];
 143          // Any plugin can add security checks to this report by implementing a callback
 144          // <component>_security_checks() which returns a check object.
 145          $morechecks = get_plugins_with_function('security_checks', 'lib.php');
 146          foreach ($morechecks as $plugintype => $plugins) {
 147              foreach ($plugins as $plugin => $pluginfunction) {
 148                  $result = $pluginfunction();
 149                  foreach ($result as $check) {
 150                      $check->set_component($plugintype . '_' . $plugin);
 151                      $checks[] = $check;
 152                  }
 153              }
 154          }
 155          return $checks;
 156      }
 157  }
 158