| 1 | efrain | 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 | namespace mod_bigbluebuttonbn\local;
 | 
        
           |  |  | 18 |   | 
        
           |  |  | 19 | use mod_bigbluebuttonbn\instance;
 | 
        
           |  |  | 20 | use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
 | 
        
           |  |  | 21 | use mod_bigbluebuttonbn\recording;
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 | /**
 | 
        
           |  |  | 24 |  * Handles the global configuration based on config.php.
 | 
        
           |  |  | 25 |  *
 | 
        
           |  |  | 26 |  * @package   mod_bigbluebuttonbn
 | 
        
           |  |  | 27 |  * @copyright 2010 onwards, Blindside Networks Inc
 | 
        
           |  |  | 28 |  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 29 |  * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
 | 
        
           |  |  | 30 |  */
 | 
        
           |  |  | 31 | class config {
 | 
        
           |  |  | 32 |   | 
        
           |  |  | 33 |     /** @var string Default bigbluebutton server url */
 | 
        
           |  |  | 34 |     public const DEFAULT_SERVER_URL = 'https://test-moodle.blindsidenetworks.com/bigbluebutton/';
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 |     /** @var string Default bigbluebutton server shared secret */
 | 
        
           |  |  | 37 |     public const DEFAULT_SHARED_SECRET = '0b21fcaf34673a8c3ec8ed877d76ae34';
 | 
        
           |  |  | 38 |   | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 |     /** @var string the default bigbluebutton checksum algorithm */
 | 
        
           |  |  | 41 |     public const DEFAULT_CHECKSUM_ALGORITHM = 'SHA256';
 | 
        
           |  |  | 42 |   | 
        
           |  |  | 43 |     /** @var array list of supported bigbluebutton checksum algorithm */
 | 
        
           |  |  | 44 |     const CHECKSUM_ALGORITHMS = [
 | 
        
           |  |  | 45 |         self::DEFAULT_CHECKSUM_ALGORITHM,
 | 
        
           |  |  | 46 |         'SHA1',
 | 
        
           |  |  | 47 |         'SHA512'
 | 
        
           |  |  | 48 |     ];
 | 
        
           |  |  | 49 |   | 
        
           |  |  | 50 |     /**
 | 
        
           |  |  | 51 |      * Returns moodle version.
 | 
        
           |  |  | 52 |      *
 | 
        
           |  |  | 53 |      * @return string
 | 
        
           |  |  | 54 |      */
 | 
        
           |  |  | 55 |     protected static function get_moodle_version_major(): string {
 | 
        
           |  |  | 56 |         global $CFG;
 | 
        
           |  |  | 57 |         $versionarray = explode('.', $CFG->version);
 | 
        
           |  |  | 58 |         return $versionarray[0];
 | 
        
           |  |  | 59 |     }
 | 
        
           |  |  | 60 |   | 
        
           |  |  | 61 |     /**
 | 
        
           |  |  | 62 |      * Returns configuration default values.
 | 
        
           |  |  | 63 |      *
 | 
        
           |  |  | 64 |      * @return array
 | 
        
           |  |  | 65 |      */
 | 
        
           |  |  | 66 |     protected static function defaultvalues(): array {
 | 
        
           |  |  | 67 |         return [
 | 
        
           |  |  | 68 |             'server_url' => '',
 | 
        
           |  |  | 69 |             'shared_secret' => '',
 | 
        
           |  |  | 70 |             'voicebridge_editable' => false,
 | 
        
           |  |  | 71 |             'importrecordings_enabled' => false,
 | 
        
           |  |  | 72 |             'importrecordings_from_deleted_enabled' => false,
 | 
        
           |  |  | 73 |             'waitformoderator_default' => false,
 | 
        
           |  |  | 74 |             'waitformoderator_editable' => true,
 | 
        
           |  |  | 75 |             'waitformoderator_ping_interval' => '10',
 | 
        
           |  |  | 76 |             'waitformoderator_cache_ttl' => '60',
 | 
        
           |  |  | 77 |             'userlimit_default' => '0',
 | 
        
           |  |  | 78 |             'userlimit_editable' => false,
 | 
        
           |  |  | 79 |             'preuploadpresentation_editable' => false,
 | 
        
           |  |  | 80 |             'recordingready_enabled' => false,
 | 
        
           |  |  | 81 |             'recordingstatus_enabled' => false,
 | 
        
           |  |  | 82 |             'meetingevents_enabled' => false,
 | 
        
           |  |  | 83 |             'participant_moderator_default' => '0',
 | 
        
           |  |  | 84 |             'profile_picture_enabled' => false,
 | 
        
           |  |  | 85 |             'scheduled_pre_opening' => '10',
 | 
        
           |  |  | 86 |             'recordings_enabled' => true,
 | 
        
           |  |  | 87 |             'recordings_deleted_default' => false,
 | 
        
           |  |  | 88 |             'recordings_deleted_editable' => false,
 | 
        
           |  |  | 89 |             'recordings_imported_default' => false,
 | 
        
           |  |  | 90 |             'recordings_imported_editable' => false,
 | 
        
           |  |  | 91 |             'recordings_preview_default' => true,
 | 
        
           |  |  | 92 |             'recordings_preview_editable' => false,
 | 
        
           |  |  | 93 |             'recording_default' => true,
 | 
        
           |  |  | 94 |             'recording_editable' => true,
 | 
        
           |  |  | 95 |             'recording_refresh_period' => recording::RECORDING_REFRESH_DEFAULT_PERIOD,
 | 
        
           |  |  | 96 |             'recording_all_from_start_default' => false,
 | 
        
           |  |  | 97 |             'recording_all_from_start_editable' => false,
 | 
        
           |  |  | 98 |             'recording_hide_button_default' => false,
 | 
        
           |  |  | 99 |             'recording_hide_button_editable' => false,
 | 
        
           |  |  | 100 |             'recording_protect_editable' => true,
 | 
        
           |  |  | 101 |             'general_warning_message' => '',
 | 
        
           |  |  | 102 |             'general_warning_roles' => 'editingteacher,teacher',
 | 
        
           |  |  | 103 |             'general_warning_box_type' => 'info',
 | 
        
           |  |  | 104 |             'general_warning_button_text' => '',
 | 
        
           |  |  | 105 |             'general_warning_button_href' => '',
 | 
        
           |  |  | 106 |             'general_warning_button_class' => '',
 | 
        
           |  |  | 107 |             'muteonstart_default' => false,
 | 
        
           |  |  | 108 |             'muteonstart_editable' => false,
 | 
        
           |  |  | 109 |             'disablecam_default' => false,
 | 
        
           |  |  | 110 |             'disablecam_editable' => true,
 | 
        
           |  |  | 111 |             'disablemic_default' => false,
 | 
        
           |  |  | 112 |             'disablemic_editable' => true,
 | 
        
           |  |  | 113 |             'disableprivatechat_default' => false,
 | 
        
           |  |  | 114 |             'disableprivatechat_editable' => true,
 | 
        
           |  |  | 115 |             'disablepublicchat_default' => false,
 | 
        
           |  |  | 116 |             'disablepublicchat_editable' => true,
 | 
        
           |  |  | 117 |             'disablenote_default' => false,
 | 
        
           |  |  | 118 |             'disablenote_editable' => true,
 | 
        
           |  |  | 119 |             'hideuserlist_default' => false,
 | 
        
           |  |  | 120 |             'hideuserlist_editable' => true,
 | 
        
           |  |  | 121 |             'welcome_default' => '',
 | 
        
           |  |  | 122 |             'welcome_editable' => true,
 | 
        
           |  |  | 123 |             'default_dpa_accepted' => false,
 | 
        
           |  |  | 124 |             'poll_interval' => bigbluebutton_proxy::DEFAULT_POLL_INTERVAL,
 | 
        
           |  |  | 125 |             'checksum_algorithm' => self::DEFAULT_CHECKSUM_ALGORITHM,
 | 
        
           | 1441 | ariadna | 126 |             'showpresentation_default' => true,
 | 
        
           |  |  | 127 |             'showpresentation_editable' => false,
 | 
        
           | 1 | efrain | 128 |         ];
 | 
        
           |  |  | 129 |     }
 | 
        
           |  |  | 130 |   | 
        
           |  |  | 131 |     /**
 | 
        
           |  |  | 132 |      * Returns default value for an specific setting.
 | 
        
           |  |  | 133 |      *
 | 
        
           |  |  | 134 |      * @param string $setting
 | 
        
           |  |  | 135 |      * @return string|null
 | 
        
           |  |  | 136 |      */
 | 
        
           |  |  | 137 |     public static function defaultvalue(string $setting): ?string {
 | 
        
           |  |  | 138 |         $defaultvalues = self::defaultvalues();
 | 
        
           |  |  | 139 |         if (!array_key_exists($setting, $defaultvalues)) {
 | 
        
           |  |  | 140 |             return null;
 | 
        
           |  |  | 141 |         }
 | 
        
           |  |  | 142 |         return $defaultvalues[$setting];
 | 
        
           |  |  | 143 |     }
 | 
        
           |  |  | 144 |   | 
        
           |  |  | 145 |     /**
 | 
        
           |  |  | 146 |      * Returns value for an specific setting.
 | 
        
           |  |  | 147 |      *
 | 
        
           |  |  | 148 |      * @param string $setting
 | 
        
           |  |  | 149 |      * @return string
 | 
        
           |  |  | 150 |      */
 | 
        
           |  |  | 151 |     public static function get(string $setting): string {
 | 
        
           |  |  | 152 |         global $CFG;
 | 
        
           |  |  | 153 |         if (isset($CFG->bigbluebuttonbn[$setting])) {
 | 
        
           |  |  | 154 |             return (string) $CFG->bigbluebuttonbn[$setting];
 | 
        
           |  |  | 155 |         }
 | 
        
           |  |  | 156 |         if (isset($CFG->{'bigbluebuttonbn_' . $setting})) {
 | 
        
           |  |  | 157 |             return (string) $CFG->{'bigbluebuttonbn_' . $setting};
 | 
        
           |  |  | 158 |         }
 | 
        
           |  |  | 159 |         return (string) self::defaultvalue($setting);
 | 
        
           |  |  | 160 |     }
 | 
        
           |  |  | 161 |   | 
        
           |  |  | 162 |     /**
 | 
        
           |  |  | 163 |      * Validates if recording settings are enabled.
 | 
        
           |  |  | 164 |      *
 | 
        
           |  |  | 165 |      * @return bool
 | 
        
           |  |  | 166 |      */
 | 
        
           |  |  | 167 |     public static function recordings_enabled(): bool {
 | 
        
           |  |  | 168 |         return (boolean) self::get('recordings_enabled');
 | 
        
           |  |  | 169 |     }
 | 
        
           |  |  | 170 |   | 
        
           |  |  | 171 |     /**
 | 
        
           |  |  | 172 |      * Validates if imported recording settings are enabled.
 | 
        
           |  |  | 173 |      *
 | 
        
           |  |  | 174 |      * @return bool
 | 
        
           |  |  | 175 |      */
 | 
        
           |  |  | 176 |     public static function importrecordings_enabled(): bool {
 | 
        
           |  |  | 177 |         return (boolean) self::get('importrecordings_enabled');
 | 
        
           |  |  | 178 |     }
 | 
        
           |  |  | 179 |   | 
        
           |  |  | 180 |     /**
 | 
        
           |  |  | 181 |      * Check if bbb server credentials are invalid.
 | 
        
           |  |  | 182 |      *
 | 
        
           |  |  | 183 |      * @return bool
 | 
        
           |  |  | 184 |      */
 | 
        
           |  |  | 185 |     public static function server_credentials_invalid(): bool {
 | 
        
           |  |  | 186 |         // Test server credentials across all versions of the plugin are flagged.
 | 
        
           |  |  | 187 |         $parsedurl = parse_url(self::get('server_url'));
 | 
        
           |  |  | 188 |         $defaultserverurl = parse_url(self::DEFAULT_SERVER_URL);
 | 
        
           |  |  | 189 |         if (!isset($parsedurl['host'])) {
 | 
        
           |  |  | 190 |             return false;
 | 
        
           |  |  | 191 |         }
 | 
        
           |  |  | 192 |         if (strpos($parsedurl['host'], $defaultserverurl['host']) === 0) {
 | 
        
           |  |  | 193 |             return true;
 | 
        
           |  |  | 194 |         }
 | 
        
           |  |  | 195 |         if (strpos($parsedurl['host'], 'test-install.blindsidenetworks.com') === 0) {
 | 
        
           |  |  | 196 |             return true;
 | 
        
           |  |  | 197 |         }
 | 
        
           |  |  | 198 |         return false;
 | 
        
           |  |  | 199 |     }
 | 
        
           |  |  | 200 |   | 
        
           |  |  | 201 |     /**
 | 
        
           |  |  | 202 |      * Wraps current settings in an array.
 | 
        
           |  |  | 203 |      *
 | 
        
           |  |  | 204 |      * @return array
 | 
        
           |  |  | 205 |      */
 | 
        
           |  |  | 206 |     public static function get_options(): array {
 | 
        
           |  |  | 207 |         return [
 | 
        
           |  |  | 208 |             'version_major' => self::get_moodle_version_major(),
 | 
        
           |  |  | 209 |             'voicebridge_editable' => self::get('voicebridge_editable'),
 | 
        
           |  |  | 210 |             'importrecordings_enabled' => self::get('importrecordings_enabled'),
 | 
        
           |  |  | 211 |             'importrecordings_from_deleted_enabled' => self::get('importrecordings_from_deleted_enabled'),
 | 
        
           |  |  | 212 |             'waitformoderator_default' => self::get('waitformoderator_default'),
 | 
        
           |  |  | 213 |             'waitformoderator_editable' => self::get('waitformoderator_editable'),
 | 
        
           |  |  | 214 |             'userlimit_default' => self::get('userlimit_default'),
 | 
        
           |  |  | 215 |             'userlimit_editable' => self::get('userlimit_editable'),
 | 
        
           |  |  | 216 |             'preuploadpresentation_editable' => self::get('preuploadpresentation_editable'),
 | 
        
           |  |  | 217 |             'recordings_enabled' => self::get('recordings_enabled'),
 | 
        
           |  |  | 218 |             'meetingevents_enabled' => self::get('meetingevents_enabled'),
 | 
        
           |  |  | 219 |             'recordings_deleted_default' => self::get('recordings_deleted_default'),
 | 
        
           |  |  | 220 |             'recordings_deleted_editable' => self::get('recordings_deleted_editable'),
 | 
        
           |  |  | 221 |             'recordings_imported_default' => self::get('recordings_imported_default'),
 | 
        
           |  |  | 222 |             'recordings_imported_editable' => self::get('recordings_imported_editable'),
 | 
        
           |  |  | 223 |             'recordings_preview_default' => self::get('recordings_preview_default'),
 | 
        
           |  |  | 224 |             'recordings_preview_editable' => self::get('recordings_preview_editable'),
 | 
        
           |  |  | 225 |             'recording_default' => self::get('recording_default'),
 | 
        
           |  |  | 226 |             'recording_editable' => self::get('recording_editable'),
 | 
        
           |  |  | 227 |             'recording_refresh_period' => self::get('recording_refresh_period'),
 | 
        
           |  |  | 228 |             'recording_all_from_start_default' => self::get('recording_all_from_start_default'),
 | 
        
           |  |  | 229 |             'recording_all_from_start_editable' => self::get('recording_all_from_start_editable'),
 | 
        
           |  |  | 230 |             'recording_hide_button_default' => self::get('recording_hide_button_default'),
 | 
        
           |  |  | 231 |             'recording_hide_button_editable' => self::get('recording_hide_button_editable'),
 | 
        
           |  |  | 232 |             'recording_protect_editable' => self::get('recording_protect_editable'),
 | 
        
           |  |  | 233 |             'general_warning_message' => self::get('general_warning_message'),
 | 
        
           |  |  | 234 |             'general_warning_box_type' => self::get('general_warning_box_type'),
 | 
        
           |  |  | 235 |             'general_warning_button_text' => self::get('general_warning_button_text'),
 | 
        
           |  |  | 236 |             'general_warning_button_href' => self::get('general_warning_button_href'),
 | 
        
           |  |  | 237 |             'general_warning_button_class' => self::get('general_warning_button_class'),
 | 
        
           |  |  | 238 |             'muteonstart_editable' => self::get('muteonstart_editable'),
 | 
        
           |  |  | 239 |             'muteonstart_default' => self::get('muteonstart_default'),
 | 
        
           |  |  | 240 |             'disablecam_editable' => self::get('disablecam_editable'),
 | 
        
           |  |  | 241 |             'disablecam_default' => self::get('disablecam_default'),
 | 
        
           |  |  | 242 |             'disablemic_editable' => self::get('disablemic_editable'),
 | 
        
           |  |  | 243 |             'disablemic_default' => self::get('disablemic_default'),
 | 
        
           |  |  | 244 |             'disableprivatechat_editable' => self::get('disableprivatechat_editable'),
 | 
        
           |  |  | 245 |             'disableprivatechat_default' => self::get('disableprivatechat_default'),
 | 
        
           |  |  | 246 |             'disablepublicchat_editable' => self::get('disablepublicchat_editable'),
 | 
        
           |  |  | 247 |             'disablepublicchat_default' => self::get('disablepublicchat_default'),
 | 
        
           |  |  | 248 |             'disablenote_editable' => self::get('disablenote_editable'),
 | 
        
           |  |  | 249 |             'disablenote_default' => self::get('disablenote_default'),
 | 
        
           |  |  | 250 |             'hideuserlist_editable' => self::get('hideuserlist_editable'),
 | 
        
           |  |  | 251 |             'hideuserlist_default' => self::get('hideuserlist_default'),
 | 
        
           |  |  | 252 |             'welcome_default' => self::get('welcome_default'),
 | 
        
           |  |  | 253 |             'welcome_editable' => self::get('welcome_editable'),
 | 
        
           |  |  | 254 |             'poll_interval' => self::get('poll_interval'),
 | 
        
           |  |  | 255 |             'guestaccess_enabled' => self::get('guestaccess_enabled'),
 | 
        
           | 1441 | ariadna | 256 |             'showpresentation_editable' => self::get('showpresentation_editable'),
 | 
        
           |  |  | 257 |             'showpresentation_default' => self::get('showpresentation_default'),
 | 
        
           | 1 | efrain | 258 |         ];
 | 
        
           |  |  | 259 |     }
 | 
        
           |  |  | 260 |   | 
        
           |  |  | 261 |     /**
 | 
        
           |  |  | 262 |      * Helper function returns an array with enabled features for an specific profile type.
 | 
        
           |  |  | 263 |      *
 | 
        
           |  |  | 264 |      * @param array $typeprofiles
 | 
        
           |  |  | 265 |      * @param string|null $type
 | 
        
           |  |  | 266 |      *
 | 
        
           |  |  | 267 |      * @return array
 | 
        
           |  |  | 268 |      */
 | 
        
           |  |  | 269 |     public static function get_enabled_features(array $typeprofiles, ?string $type = null): array {
 | 
        
           |  |  | 270 |         $enabledfeatures = [];
 | 
        
           |  |  | 271 |         $features = $typeprofiles[instance::TYPE_ALL]['features'];
 | 
        
           |  |  | 272 |         if (!is_null($type) && key_exists($type, $typeprofiles)) {
 | 
        
           |  |  | 273 |             $features = $typeprofiles[$type]['features'];
 | 
        
           |  |  | 274 |         }
 | 
        
           |  |  | 275 |         $enabledfeatures['showroom'] = (in_array('all', $features) || in_array('showroom', $features));
 | 
        
           |  |  | 276 |         // Evaluates if recordings are enabled for the Moodle site.
 | 
        
           |  |  | 277 |         $enabledfeatures['showrecordings'] = false;
 | 
        
           |  |  | 278 |         if (self::recordings_enabled()) {
 | 
        
           |  |  | 279 |             $enabledfeatures['showrecordings'] = (in_array('all', $features) || in_array('showrecordings', $features));
 | 
        
           |  |  | 280 |         }
 | 
        
           |  |  | 281 |         $enabledfeatures['importrecordings'] = false;
 | 
        
           |  |  | 282 |         if (self::importrecordings_enabled()) {
 | 
        
           |  |  | 283 |             $enabledfeatures['importrecordings'] = (in_array('all', $features) || in_array('importrecordings', $features));
 | 
        
           |  |  | 284 |         }
 | 
        
           |  |  | 285 |         return $enabledfeatures;
 | 
        
           |  |  | 286 |     }
 | 
        
           |  |  | 287 | }
 |