From 04645f4e9b2cb0721afab24632b4da31b6ba654e Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 6 May 2019 19:16:39 +0200 Subject: [PATCH 1/2] MDL-65187 core_hub: send more important info first to moodle.net Rumor has it that some browsers may truncate the GET request to 2000 characters, make sure that all important info is sent first Everything else will be updated on the first registration update request. --- lib/classes/hub/registration.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/classes/hub/registration.php b/lib/classes/hub/registration.php index 25867914b06..3807d9c4655 100644 --- a/lib/classes/hub/registration.php +++ b/lib/classes/hub/registration.php @@ -40,11 +40,11 @@ use html_writer; */ class registration { - /** @var Fields used in a site registration form. + /** @var array Fields used in a site registration form. * IMPORTANT: any new fields with non-empty defaults have to be added to CONFIRM_NEW_FIELDS */ - const FORM_FIELDS = ['name', 'description', 'contactname', 'contactemail', 'contactphone', 'imageurl', 'privacy', 'street', - 'regioncode', 'countrycode', 'geolocation', 'contactable', 'emailalert', 'emailalertemail', 'commnews', 'commnewsemail', - 'language', 'policyagreed']; + const FORM_FIELDS = ['policyagreed', 'language', 'countrycode', 'privacy', + 'contactemail', 'contactable', 'emailalert', 'emailalertemail', 'commnews', 'commnewsemail', + 'contactname', 'name', 'description', 'imageurl', 'contactphone', 'regioncode', 'geolocation', 'street']; /** @var List of new FORM_FIELDS or siteinfo fields added indexed by the version when they were added. * If site was already registered, admin will be promted to confirm new registration data manually. Until registration is manually confirmed, @@ -397,8 +397,7 @@ class registration { self::$registration = null; } - $params = self::get_site_info(); - $params['token'] = $hub->token; + $params = ['token' => $hub->token] + self::get_site_info(); $SESSION->registrationredirect = $returnurl; redirect(new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/siteregistration.php', $params)); From ec8453c122cc40b7695ed5058c142a073d84ab2c Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 28 May 2019 13:56:53 +0200 Subject: [PATCH 2/2] MDL-65187 core_hub: truncate registration request, use post --- lib/classes/hub/api.php | 3 ++- lib/classes/hub/registration.php | 23 ++++++++++++++++++++-- lib/classes/hub/site_registration_form.php | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/classes/hub/api.php b/lib/classes/hub/api.php index 2a1434ddb7d..7c0ed3716e8 100644 --- a/lib/classes/hub/api.php +++ b/lib/classes/hub/api.php @@ -88,7 +88,8 @@ class api { $curl = new curl(); $serverurl = HUB_MOODLEORGHUBURL . "/local/hub/webservice/webservices.php"; - $curloutput = @json_decode($curl->get($serverurl, $params), true); + $query = http_build_query($params, '', '&'); + $curloutput = @json_decode($curl->post($serverurl, $query), true); $info = $curl->get_info(); if ($curl->get_errno()) { // Connection error. diff --git a/lib/classes/hub/registration.php b/lib/classes/hub/registration.php index 3807d9c4655..cead3bb7544 100644 --- a/lib/classes/hub/registration.php +++ b/lib/classes/hub/registration.php @@ -350,6 +350,13 @@ class registration { $record['timemodified'] = time(); $DB->update_record('registration_hubs', $record); self::$registration = null; + + $siteinfo = self::get_site_info(); + if (strlen(http_build_query($siteinfo)) > 1800) { + // Update registration again because the initial request was too long and could have been truncated. + api::update_registration($siteinfo); + self::$registration = null; + } } /** @@ -397,10 +404,22 @@ class registration { self::$registration = null; } - $params = ['token' => $hub->token] + self::get_site_info(); + $params = self::get_site_info(); + + // The most conservative limit for the redirect URL length is 2000 characters. Only pass parameters before + // we reach this limit. The next registration update will update all fields. + // We will also update registration after we receive confirmation from moodle.net. + $url = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/siteregistration.php', + ['token' => $hub->token, 'url' => $params['url']]); + foreach ($params as $key => $value) { + if (strlen($url->out(false, [$key => $value])) > 2000) { + break; + } + $url->param($key, $value); + } $SESSION->registrationredirect = $returnurl; - redirect(new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/siteregistration.php', $params)); + redirect($url); } /** diff --git a/lib/classes/hub/site_registration_form.php b/lib/classes/hub/site_registration_form.php index 510a2da42b0..0369aa3958d 100644 --- a/lib/classes/hub/site_registration_form.php +++ b/lib/classes/hub/site_registration_form.php @@ -75,7 +75,7 @@ class site_registration_form extends \moodleform { $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub')); $mform->addElement('text', 'name', get_string('sitename', 'hub'), - array('class' => 'registration_textfield')); + array('class' => 'registration_textfield', 'maxlength' => 255)); $mform->setType('name', PARAM_TEXT); $mform->addHelpButton('name', 'sitename', 'hub');