From 75e167392b52af67ab09e428cd881e533cfe4e13 Mon Sep 17 00:00:00 2001 From: "Shamiso.Jaravaza" <33659194+ssj365@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:33:24 -0600 Subject: [PATCH] CONTRIB-9484: Backport registration code to v2.4 * Warning when test-install/test-moodle used --- classes/locallib/config.php | 25 +++++++++++++++++++++++-- classes/settings/renderer.php | 5 +++-- config-dist.php | 4 ++-- lang/en/bigbluebuttonbn.php | 10 ++++++---- locallib.php | 7 +++++-- viewlib.php | 19 ++++++++++++++----- 6 files changed, 53 insertions(+), 17 deletions(-) diff --git a/classes/locallib/config.php b/classes/locallib/config.php index f44d8597f..7b6c4ca20 100644 --- a/classes/locallib/config.php +++ b/classes/locallib/config.php @@ -55,8 +55,8 @@ public static function get_moodle_version_major() { */ public static function defaultvalues() { return array( - 'server_url' => (string) BIGBLUEBUTTONBN_DEFAULT_SERVER_URL, - 'shared_secret' => (string) BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET, + 'server_url' => '', + 'shared_secret' => '', 'checksum_algorithm' => (string) BIGBLUEBUTTONBN_DEFAULT_CHECKSUM_ALGORITHM, 'voicebridge_editable' => false, 'importrecordings_enabled' => false, @@ -179,6 +179,27 @@ public static function clienttype_enabled() { return (boolean)self::get('clienttype_enabled'); } + /** + * Check if bbb server credentials are invalid. + * + * @return bool + */ + public static function server_credentials_invalid(): bool { + // Test server credentials across all versions of the plugin are flagged. + $parsedurl = parse_url(self::get('server_url')); + $defaultserverurl = parse_url(BIGBLUEBUTTONBN_DEFAULT_SERVER_URL); + if (!isset($parsedurl['host'])) { + return false; + } + if (strpos($parsedurl['host'], $defaultserverurl['host']) === 0) { + return true; + } + if (strpos($parsedurl['host'], 'test-moodle.blindsidenetworks.com') === 0) { + return true; + } + return false; + } + /** * Wraps current settings in an array. * diff --git a/classes/settings/renderer.php b/classes/settings/renderer.php index 45ba07d41..4d9670ab7 100644 --- a/classes/settings/renderer.php +++ b/classes/settings/renderer.php @@ -199,13 +199,14 @@ public function render_group_element_password($name, $default = null, $type = PA * @return Object */ public function render_warning_message($name, $message, $type = 'warning', $closable = true) { - $output = $this->output->box_start('box boxalignleft adminerror alert alert-' . $type . ' alert-block fade in', + global $OUTPUT; + $output = $OUTPUT->box_start('box boxalignleft adminerror alert alert-' . $type . ' alert-block fade in', 'bigbluebuttonbn_' . $name)."\n"; if ($closable) { $output .= ' ' . "\n"; } $output .= ' ' . $message . "\n"; - $output .= $this->output->box_end() . "\n"; + $output .= $OUTPUT->box_end() . "\n"; $item = new \admin_setting_heading('bigbluebuttonbn_' . $name, '', $output); $this->settings->add($item); return $item; diff --git a/config-dist.php b/config-dist.php index 38188c6ae..846de43f4 100644 --- a/config-dist.php +++ b/config-dist.php @@ -62,8 +62,8 @@ * checksum_algorithm can be set to SHA1 (default), SHA256, SHA384 and SHA512. **/ -$CFG->bigbluebuttonbn['server_url'] = 'http://test-install.blindsidenetworks.com/bigbluebutton/'; -$CFG->bigbluebuttonbn['shared_secret'] = '8cd8ef52e8e101574e400365b55e11a6'; +$CFG->bigbluebuttonbn['server_url'] = ''; +$CFG->bigbluebuttonbn['shared_secret'] = ''; $CFG->bigbluebuttonbn['checksum_algorithm'] = 'SHA1'; /* diff --git a/lang/en/bigbluebuttonbn.php b/lang/en/bigbluebuttonbn.php index 2516b1c8f..c3c9bea78 100644 --- a/lang/en/bigbluebuttonbn.php +++ b/lang/en/bigbluebuttonbn.php @@ -102,11 +102,11 @@ $string['minutes'] = 'minutes'; $string['config_general'] = 'General configuration'; -$string['config_general_description'] = 'These settings are always used'; +$string['config_general_description'] = '

These settings are always used.

To use BigBlueButton, you can setup your own BigBlueButton server and enter the credentials below, or visit the Blindside Networks Registration Portal (opens in a new window) to obtain free trial credentials

'; $string['config_server_url'] = 'BigBlueButton Server URL'; -$string['config_server_url_description'] = 'The URL of your BigBlueButton server must end with /bigbluebutton/. (This default URL is for a BigBlueButton server provided by Blindside Networks that you can use for testing.)'; +$string['config_server_url_description'] = 'The URL of your BigBlueButton server must end with /bigbluebutton/'; $string['config_shared_secret'] = 'BigBlueButton Shared Secret'; -$string['config_shared_secret_description'] = 'The security salt of your BigBlueButton server. (This default salt is for a BigBlueButton server provided by Blindside Networks that you can use for testing.)'; +$string['config_shared_secret_description'] = 'The security salt of your BigBlueButton server.'; $string['config_checksum_algorithm'] = 'BigBlueButton Checksum Algorithm'; $string['config_checksum_algorithm_description'] = 'The checksum algorithm of your BigBlueButton server. (SHA1 guarantees compatability with older server versions but is less secure whereas SHA512 is FIPS 140-2 compliant.)'; @@ -539,7 +539,9 @@ $string['view_error_meeting_not_running'] = 'Something went wrong, the meeting is not running.'; $string['view_error_current_state_not_found'] = 'Current state was not found. The recording may have been deleted or the BigBlueButton server is not compatible with the action performed.'; $string['view_error_action_not_completed'] = 'Action could not be completed'; -$string['view_warning_default_server'] = 'This Moodle server is making use of the BigBlueButton testing server that comes pre-configured by default. It should be replaced for production.'; +$string['view_warning_default_server'] = 'Default BigBlueButton plugin credentials will soon expire. See BigBlueButton plugin settings (opens in a new window) for more information.'; +$string['view_warning_default_server_no_capability'] = 'The use of default server credentials will soon expire. To use BigBlueButton your site will require new server credentials. Please contact your site administrator for help with this.'; +$string['credentials_warning'] = 'The use of default server credentials will soon expire (see note above to obtain new credentials).'; $string['view_room'] = 'View room'; $string['mod_form_block_clienttype'] = 'Web Client Technology'; diff --git a/locallib.php b/locallib.php index 70af73f5c..d70a4b713 100644 --- a/locallib.php +++ b/locallib.php @@ -2685,13 +2685,16 @@ function bigbluebuttonbn_settings_general(&$renderer) { // Configuration for BigBlueButton. if ((boolean) \mod_bigbluebuttonbn\settings\validator::section_general_shown()) { $renderer->render_group_header('general'); + if ((boolean) \mod_bigbluebuttonbn\locallib\config::server_credentials_invalid()) { + $renderer->render_warning_message('credentials_warning', get_string('credentials_warning', 'bigbluebuttonbn'), 'danger'); + } $renderer->render_group_element( 'server_url', - $renderer->render_group_element_text('server_url', BIGBLUEBUTTONBN_DEFAULT_SERVER_URL) + $renderer->render_group_element_text('server_url', '') ); $renderer->render_group_element( 'shared_secret', - $renderer->render_group_element_password('shared_secret', BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET) + $renderer->render_group_element_password('shared_secret', '') ); $checksumchoices = array('SHA1' => 'SHA1', 'SHA256' => 'SHA256', 'SHA512' => 'SHA512'); $renderer->render_group_element( diff --git a/viewlib.php b/viewlib.php index 35a4111fe..bf8cf0dc4 100644 --- a/viewlib.php +++ b/viewlib.php @@ -325,20 +325,29 @@ function bigbluebuttonbn_view_ended(&$bbbsession) { } /** - * Renders a default server warning message when using test-install. + * Renders a default server warning message when using test-install or test-moodle. * * @param array $bbbsession * * @return string */ function bigbluebuttonbn_view_warning_default_server(&$bbbsession) { - if (!is_siteadmin($bbbsession['userID'])) { - return ''; + if (\mod_bigbluebuttonbn\locallib\config::server_credentials_invalid()) { + $context = context_module::instance($bbbsession['cm']->id); + // Admin and teacher should see warning. + if (is_siteadmin($bbbsession['userID'])) { + $settingslink = new moodle_url('/admin/settings.php', ['section' => 'modsettingbigbluebuttonbn']); + return bigbluebuttonbn_render_warning(get_string('view_warning_default_server', 'bigbluebuttonbn', + ['settingslink' => $settingslink->out()]), 'danger'); + } else if (has_capability('moodle/course:manageactivities', $context, $bbbsession['userID'])) { + return bigbluebuttonbn_render_warning(get_string('view_warning_default_server_no_capability', 'bigbluebuttonbn'), + 'danger'); + } } - if (BIGBLUEBUTTONBN_DEFAULT_SERVER_URL != \mod_bigbluebuttonbn\locallib\config::get('server_url')) { + if (!bigbluebuttonbn_view_warning_shown($bbbsession)) { return ''; } - return bigbluebuttonbn_render_warning(get_string('view_warning_default_server', 'bigbluebuttonbn'), 'warning'); + return ''; } /**