From 65b49f5be684e30d372273bd1bcb6834812961e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20D=C3=A9niz?= Date: Fri, 14 Jan 2022 11:01:19 +0000 Subject: [PATCH] MDL-73582 registration: Add endpoint to provide version to linkchecker --- admin/registration/check.php | 48 ++++++++++++++++++++++++++++++++++++ lib/moodlelib.php | 5 ++++ 2 files changed, 53 insertions(+) create mode 100644 admin/registration/check.php diff --git a/admin/registration/check.php b/admin/registration/check.php new file mode 100644 index 00000000000..7b92c410747 --- /dev/null +++ b/admin/registration/check.php @@ -0,0 +1,48 @@ +. + +/** + * Endpoint to get the Moodle version + * + * Moodle linkchecker will check this endpoint when it cannot get the Moodle version otherwise. + * + * @package core + * @copyright 2022 Victor Deniz + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(__DIR__ . '/../../config.php'); +require_once($CFG->libdir . '/filelib.php'); + +// Get public key. +$key = download_file_content(HUB_STATSPUBLICKEY); +// Check $key is a valid public key. +$publickey = openssl_pkey_get_public($key); +if ($publickey !== false) { + $publickeystr = openssl_pkey_get_details($publickey)['key']; +} else { + die('Error getting a valid public key'); +} + +// Encrypt data. +$message = $CFG->release; +$success = openssl_public_encrypt(utf8_encode($message), $encrypteddata, $publickeystr); + +if ($success) { + echo base64_encode($encrypteddata); +} else { + die ('Error encrypting the data'); +} diff --git a/lib/moodlelib.php b/lib/moodlelib.php index cc6bd768b78..4d366223dc6 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -495,6 +495,11 @@ define('HOMEPAGE_USER', 2); */ defined('HUB_MOODLEORGHUBURL') || define('HUB_MOODLEORGHUBURL', 'https://stats.moodle.org'); +/** + * URL of the statistic server public key. + */ +defined('HUB_STATSPUBLICKEY') || define('HUB_STATSPUBLICKEY', 'https://moodle.org/static/statspubkey.pem'); + /** * Moodle mobile app service name */