diff --git a/lib/classes/check/access/defaultuserrole.php b/lib/classes/check/access/defaultuserrole.php index c33f62f956e..da15a5743f7 100644 --- a/lib/classes/check/access/defaultuserrole.php +++ b/lib/classes/check/access/defaultuserrole.php @@ -41,13 +41,22 @@ use core\check\result; class defaultuserrole extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { + public function get_name(): string { + return get_string('check_defaultuserrole_name', 'report_security'); + } + + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { global $CFG; - $this->id = 'defaultuserrole'; - $this->name = get_string('check_defaultuserrole_name', 'report_security'); - $this->actionlink = new \action_link( + return new \action_link( new \moodle_url('/admin/roles/define.php?action=view&roleid=' . $CFG->defaultuserroleid), get_string('userpolicies', 'admin')); } diff --git a/lib/classes/check/access/frontpagerole.php b/lib/classes/check/access/frontpagerole.php index 8defa5ff618..5fcd3d826cd 100644 --- a/lib/classes/check/access/frontpagerole.php +++ b/lib/classes/check/access/frontpagerole.php @@ -41,12 +41,21 @@ use core\check\result; class frontpagerole extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - $this->id = 'frontpagerole'; - $this->name = get_string('check_frontpagerole_name', 'report_security'); - $this->actionlink = new \action_link( + public function get_name(): string { + return get_string('check_frontpagerole_name', 'report_security'); + } + + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/settings.php?section=frontpagesettings#admin-defaultfrontpageroleid'), get_string('frontpagesettings', 'admin')); } diff --git a/lib/classes/check/access/guestrole.php b/lib/classes/check/access/guestrole.php index cea00385db1..99d13592ddc 100644 --- a/lib/classes/check/access/guestrole.php +++ b/lib/classes/check/access/guestrole.php @@ -41,13 +41,21 @@ use core\check\result; class guestrole extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { + public function get_name(): string { + return get_string('check_guestrole_name', 'report_security'); + } - $this->id = 'guestrole'; - $this->name = get_string('check_guestrole_name', 'report_security'); - $this->actionlink = new \action_link( + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/settings.php?section=userpolicies'), get_string('userpolicies', 'admin')); } diff --git a/lib/classes/check/access/riskadmin.php b/lib/classes/check/access/riskadmin.php index 9a67a250c9e..7c0729cfaad 100644 --- a/lib/classes/check/access/riskadmin.php +++ b/lib/classes/check/access/riskadmin.php @@ -41,12 +41,21 @@ use core\check\result; class riskadmin extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - $this->id = 'riskadmin'; - $this->name = get_string('check_riskadmin_name', 'report_security'); - $this->actionlink = new \action_link( + public function get_name(): string { + return get_string('check_riskadmin_name', 'report_security'); + } + + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/roles/admins.php'), get_string('siteadministrators', 'role')); } diff --git a/lib/classes/check/access/riskbackup.php b/lib/classes/check/access/riskbackup.php index 6b33b2488d3..630efc37c7a 100644 --- a/lib/classes/check/access/riskbackup.php +++ b/lib/classes/check/access/riskbackup.php @@ -39,13 +39,21 @@ use core\check\result; class riskbackup extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { + public function get_name(): string { + return get_string('check_riskbackup_name', 'report_security'); + } - $this->id = 'riskbackup'; - $this->name = get_string('check_riskbackup_name', 'report_security'); - $this->actionlink = new \action_link( + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/roles/manage.php'), get_string('manageroles', 'role')); } diff --git a/lib/classes/check/access/riskxss.php b/lib/classes/check/access/riskxss.php index a959d206eeb..3ce984a19e8 100644 --- a/lib/classes/check/access/riskxss.php +++ b/lib/classes/check/access/riskxss.php @@ -46,13 +46,21 @@ use core\check\result; class riskxss extends \core\check\check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { + public function get_name(): string { + return get_string('check_riskxss_name', 'report_security'); + } - $this->id = 'riskxss'; - $this->name = get_string('check_riskxss_name', 'report_security'); - $this->actionlink = new \action_link( + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/roles/manage.php'), get_string('manageroles', 'role')); } diff --git a/lib/classes/check/check.php b/lib/classes/check/check.php index 97ecfd14eb8..8042fe8315b 100644 --- a/lib/classes/check/check.php +++ b/lib/classes/check/check.php @@ -41,21 +41,6 @@ abstract class check { */ protected $component = 'core'; - /** - * @var string $id - Should be unique identifier within a component. - */ - protected $id = ''; - - /** - * @var string $name - Name for the check, should be the same regardless of state. - */ - protected $name = ''; - - /** - * @var action_link - an optional link to a place to address the check. - */ - protected $actionlink = null; - /** * Get the frankenstyle component name * @@ -77,10 +62,16 @@ abstract class check { /** * Get the check's id * - * @return string must be unique for it's component + * This defaults to the base name of the class which is ok in the most + * cases but if you have a check which can have multiple instances then + * you should override this to be unique. + * + * @return string must be unique within a component */ public function get_id(): string { - return $this->id; + $class = get_class($this); + $id = explode("\\", $class); + return end($id); } /** @@ -103,7 +94,8 @@ abstract class check { * @return string */ public function get_name(): string { - return $this->name; + $id = $this->get_id(); + return get_string("check{$id}", $this->get_component()); } /** @@ -112,7 +104,7 @@ abstract class check { * @return action_link|null */ public function get_action_link(): ?\action_link { - return $this->actionlink; + return null; } /** diff --git a/lib/classes/check/environment/configrw.php b/lib/classes/check/environment/configrw.php index c7f6be38e6a..32d4221b693 100644 --- a/lib/classes/check/environment/configrw.php +++ b/lib/classes/check/environment/configrw.php @@ -41,12 +41,12 @@ use core\check\result; class configrw extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - global $CFG; - $this->id = 'configrw'; - $this->name = get_string('check_configrw_name', 'report_security'); + public function get_name(): string { + return get_string('check_configrw_name', 'report_security'); } /** diff --git a/lib/classes/check/environment/displayerrors.php b/lib/classes/check/environment/displayerrors.php index 4db52720bca..e99c66993c9 100644 --- a/lib/classes/check/environment/displayerrors.php +++ b/lib/classes/check/environment/displayerrors.php @@ -47,12 +47,12 @@ use core\check\check; class displayerrors extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - - $this->id = 'displayerrors'; - $this->name = get_string('check_displayerrors_name', 'report_security'); + public function get_name(): string { + return get_string('check_displayerrors_name', 'report_security'); } /** diff --git a/lib/classes/check/environment/nodemodules.php b/lib/classes/check/environment/nodemodules.php index 1d72bf1628a..34780d1ebbd 100644 --- a/lib/classes/check/environment/nodemodules.php +++ b/lib/classes/check/environment/nodemodules.php @@ -41,12 +41,12 @@ use core\check\result; class nodemodules extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - global $CFG; - $this->id = 'nodemodules'; - $this->name = get_string('check_nodemodules_name', 'report_security'); + public function get_name(): string { + return get_string('check_nodemodules_name', 'report_security'); } /** diff --git a/lib/classes/check/environment/preventexecpath.php b/lib/classes/check/environment/preventexecpath.php index 0452a51a403..a6f90cd633d 100644 --- a/lib/classes/check/environment/preventexecpath.php +++ b/lib/classes/check/environment/preventexecpath.php @@ -41,13 +41,12 @@ use core\check\result; class preventexecpath extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - - global $CFG; - $this->id = 'preventexecpath'; - $this->name = get_string('check_preventexecpath_name', 'report_security'); + public function get_name(): string { + return get_string('check_preventexecpath_name', 'report_security'); } /** diff --git a/lib/classes/check/environment/unsecuredataroot.php b/lib/classes/check/environment/unsecuredataroot.php index ef1ea1f7268..c243e27091d 100644 --- a/lib/classes/check/environment/unsecuredataroot.php +++ b/lib/classes/check/environment/unsecuredataroot.php @@ -40,14 +40,12 @@ use core\check\result; class unsecuredataroot extends \core\check\check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - - global $CFG; - - $this->id = 'unsecuredataroot'; - $this->name = get_string('check_unsecuredataroot_name', 'report_security'); + public function get_name(): string { + return get_string('check_unsecuredataroot_name', 'report_security'); } /** diff --git a/lib/classes/check/environment/vendordir.php b/lib/classes/check/environment/vendordir.php index 6c3274c97c0..55da2bcef13 100644 --- a/lib/classes/check/environment/vendordir.php +++ b/lib/classes/check/environment/vendordir.php @@ -41,12 +41,12 @@ use core\check\result; class vendordir extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - global $CFG; - $this->id = 'vendordir'; - $this->name = get_string('check_vendordir_name', 'report_security'); + public function get_name(): string { + return get_string('check_vendordir_name', 'report_security'); } /** diff --git a/lib/classes/check/http/cookiesecure.php b/lib/classes/check/http/cookiesecure.php index 0a63cbd18de..3f403be7e5a 100644 --- a/lib/classes/check/http/cookiesecure.php +++ b/lib/classes/check/http/cookiesecure.php @@ -45,13 +45,21 @@ use core\check\result; class cookiesecure extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { + public function get_name(): string { + return get_string('check_cookiesecure_name', 'report_security'); + } - $this->id = 'cookiesecure'; - $this->name = get_string('check_cookiesecure_name', 'report_security'); - $this->actionlink = new \action_link( + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/settings.php?section=httpsecurity#admin-cookiesecure'), get_string('httpsecurity', 'admin')); } diff --git a/lib/classes/check/security/crawlers.php b/lib/classes/check/security/crawlers.php index 2ed2b5b31ca..e6b00406049 100644 --- a/lib/classes/check/security/crawlers.php +++ b/lib/classes/check/security/crawlers.php @@ -47,13 +47,21 @@ use core\check\result; class crawlers extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { + public function get_name(): string { + return get_string('check_crawlers_name', 'report_security'); + } - $this->id = 'crawlers'; - $this->name = get_string('check_crawlers_name', 'report_security'); - $this->actionlink = new \action_link( + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/settings.php?section=sitepolicies#admin-opentowebcrawlers'), get_string('sitepolicies', 'admin')); } diff --git a/lib/classes/check/security/emailchangeconfirmation.php b/lib/classes/check/security/emailchangeconfirmation.php index 6328b9eb4f0..8c4f1069ac1 100644 --- a/lib/classes/check/security/emailchangeconfirmation.php +++ b/lib/classes/check/security/emailchangeconfirmation.php @@ -41,12 +41,21 @@ use core\check\result; class emailchangeconfirmation extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - $this->id = 'emailchangeconfirmation'; - $this->name = get_string('check_emailchangeconfirmation_name', 'report_security'); - $this->actionlink = new \action_link( + public function get_name(): string { + return get_string('check_emailchangeconfirmation_name', 'report_security'); + } + + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/settings.php?section=sitepolicies#admin-emailchangeconfirmation'), get_string('sitepolicies', 'admin')); } diff --git a/lib/classes/check/security/embed.php b/lib/classes/check/security/embed.php index d8e305c2cf1..bfdd767b5a2 100644 --- a/lib/classes/check/security/embed.php +++ b/lib/classes/check/security/embed.php @@ -41,12 +41,21 @@ use core\check\result; class embed extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - $this->id = 'embed'; - $this->name = get_string('check_embed_name', 'report_security'); - $this->actionlink = new \action_link( + public function get_name(): string { + return get_string('check_embed_name', 'report_security'); + } + + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/settings.php?section=sitepolicies#admin-allowobjectembed'), get_string('sitepolicies', 'admin')); } diff --git a/lib/classes/check/security/mediafilterswf.php b/lib/classes/check/security/mediafilterswf.php index 38dabc30d70..78632b99d70 100644 --- a/lib/classes/check/security/mediafilterswf.php +++ b/lib/classes/check/security/mediafilterswf.php @@ -41,13 +41,21 @@ use core\check\result; class mediafilterswf extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - global $CFG; - $this->id = 'mediafilterswf'; - $this->name = get_string('check_mediafilterswf_name', 'report_security'); - $this->actionlink = new \action_link( + public function get_name(): string { + return get_string('check_mediafilterswf_name', 'report_security'); + } + + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/settings.php?section=managemediaplayers'), get_string('managemediaplayers', 'media')); } diff --git a/lib/classes/check/security/openprofiles.php b/lib/classes/check/security/openprofiles.php index dc252c7394b..b6d5faafa57 100644 --- a/lib/classes/check/security/openprofiles.php +++ b/lib/classes/check/security/openprofiles.php @@ -41,13 +41,21 @@ use core\check\result; class openprofiles extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { + public function get_name(): string { + return get_string('check_openprofiles_name', 'report_security'); + } - $this->id = 'openprofiles'; - $this->name = get_string('check_openprofiles_name', 'report_security'); - $this->actionlink = new \action_link( + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/settings.php?section=sitepolicies#admin-forcelogin'), get_string('sitepolicies', 'admin')); } diff --git a/lib/classes/check/security/passwordpolicy.php b/lib/classes/check/security/passwordpolicy.php index 8d1000af46a..cc5d1b1a7f9 100644 --- a/lib/classes/check/security/passwordpolicy.php +++ b/lib/classes/check/security/passwordpolicy.php @@ -41,12 +41,21 @@ use core\check\result; class passwordpolicy extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - $this->id = 'passwordpolicy'; - $this->name = get_string('check_passwordpolicy_name', 'report_security'); - $this->actionlink = new \action_link( + public function get_name(): string { + return get_string('check_passwordpolicy_name', 'report_security'); + } + + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( new \moodle_url('/admin/settings.php?section=sitepolicies#admin-passwordpolicy'), get_string('sitepolicies', 'admin')); } diff --git a/lib/classes/check/security/webcron.php b/lib/classes/check/security/webcron.php index 0b4f8626cc4..f1c6f177e56 100644 --- a/lib/classes/check/security/webcron.php +++ b/lib/classes/check/security/webcron.php @@ -41,14 +41,23 @@ use core\check\result; class webcron extends check { /** - * Constructor + * Get the short check name + * + * @return string */ - public function __construct() { - $this->id = 'webcron'; - $this->name = get_string('check_webcron_name', 'report_security'); - $this->actionlink = new \action_link( - new \moodle_url('/admin/settings.php?section=sitepolicies#admin-cronclionly'), - get_string('sitepolicies', 'admin')); + public function get_name(): string { + return get_string('check_webcron_name', 'report_security'); + } + + /** + * A link to a place to action this + * + * @return action_link|null + */ + public function get_action_link(): ?\action_link { + return new \action_link( + new \moodle_url('/admin/settings.php?section=sitepolicies#admin-cronclionly'), + get_string('sitepolicies', 'admin')); } /**