jfederico /
moodle-mod_bigbluebuttonbn
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 | /** |
||
| 18 | * Mobile output class for bigbluebuttonbn |
||
| 19 | * |
||
| 20 | * @package mod_bigbluebuttonbn |
||
| 21 | * @copyright 2018 onwards, Blindside Networks Inc |
||
| 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||
| 23 | * @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) |
||
| 24 | */ |
||
| 25 | |||
| 26 | namespace mod_bigbluebuttonbn\output; |
||
| 27 | |||
| 28 | defined('MOODLE_INTERNAL') || die(); |
||
| 29 | |||
| 30 | use context_module; |
||
| 31 | use mod_bigbluebuttonbn\locallib\bigbluebutton; |
||
| 32 | |||
| 33 | require_once($CFG->dirroot . '/mod/bigbluebuttonbn/locallib.php'); |
||
| 34 | require_once($CFG->dirroot . '/lib/grouplib.php'); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Mobile output class for bigbluebuttonbn |
||
| 38 | * |
||
| 39 | * @package mod_bigbluebuttonbn |
||
| 40 | * @copyright 2018 onwards, Blindside Networks Inc |
||
| 41 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||
| 42 | * @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) |
||
| 43 | */ |
||
| 44 | class mobile { |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Returns the bigbluebuttonbn course view for the mobile app. |
||
| 48 | * @param mixed $args |
||
| 49 | * @return array HTML, javascript and other data. |
||
| 50 | * @throws \coding_exception |
||
| 51 | * @throws \moodle_exception |
||
| 52 | * @throws \require_login_exception |
||
| 53 | * @throws \required_capability_exception |
||
| 54 | */ |
||
| 55 | public static function mobile_course_view($args) { |
||
| 56 | |||
| 57 | global $OUTPUT, $SESSION; |
||
| 58 | |||
| 59 | $args = (object) $args; |
||
| 60 | $viewinstance = bigbluebuttonbn_view_validator($args->cmid, null); |
||
|
0 ignored issues
–
show
|
|||
| 61 | if (!$viewinstance) { |
||
| 62 | $error = get_string('view_error_url_missing_parameters', 'bigbluebuttonbn'); |
||
| 63 | return(self::mobile_print_error($error)); |
||
| 64 | } |
||
| 65 | |||
| 66 | $bbbsession = bigbluebutton::build_bbb_session_fromviewinstance($viewinstance); |
||
|
0 ignored issues
–
show
$viewinstance is of type array, but the function expects a object.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 67 | |||
| 68 | // Create variables for easy access. |
||
| 69 | $bigbluebuttonbn = $viewinstance['bigbluebuttonbn']; |
||
| 70 | $serverversion = $bbbsession['serverversion']; |
||
| 71 | $cm = $bbbsession['cm']; |
||
| 72 | $course = $bbbsession['course']; |
||
| 73 | $context = $bbbsession['context']; |
||
| 74 | |||
| 75 | // Check activity status. |
||
| 76 | $activitystatus = \mod_bigbluebuttonbn\locallib\mobileview::get_activity_status($bbbsession); |
||
| 77 | if ($activitystatus == 'not_started') { |
||
| 78 | $message = get_string('view_message_conference_not_started', 'bigbluebuttonbn'); |
||
| 79 | |||
| 80 | $notstarted = array(); |
||
| 81 | $notstarted['starts_at'] = ''; |
||
| 82 | $notstarted['ends_at'] = ''; |
||
| 83 | if (!empty($bigbluebuttonbn->openingtime)) { |
||
| 84 | $notstarted['starts_at'] = sprintf( |
||
| 85 | '%s: %s', |
||
| 86 | get_string('mod_form_field_openingtime', 'bigbluebuttonbn'), |
||
| 87 | userdate($bigbluebuttonbn->openingtime) |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | if (!empty($bigbluebuttonbn->closingtime)) { |
||
| 91 | $notstarted['ends_at'] = sprintf( |
||
| 92 | '%s: %s', |
||
| 93 | get_string('mod_form_field_closingtime', 'bigbluebuttonbn'), |
||
| 94 | userdate($bigbluebuttonbn->closingtime) |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | |||
| 98 | return(self::mobile_print_notification($bigbluebuttonbn, $cm, $message, $notstarted)); |
||
| 99 | } |
||
| 100 | if ($activitystatus == 'ended') { |
||
| 101 | $message = get_string('view_message_conference_has_ended', 'bigbluebuttonbn'); |
||
| 102 | return(self::mobile_print_notification($bigbluebuttonbn, $cm, $message)); |
||
| 103 | } |
||
| 104 | |||
| 105 | // Check if the BBB server is working. |
||
| 106 | View Code Duplication | if (is_null($serverversion)) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 107 | |||
| 108 | if ($bbbsession['administrator']) { |
||
| 109 | $error = get_string('view_error_unable_join', 'bigbluebuttonbn'); |
||
| 110 | } else if ($bbbsession['moderator']) { |
||
| 111 | $error = get_string('view_error_unable_join_teacher', 'bigbluebuttonbn'); |
||
| 112 | } else { |
||
| 113 | $error = get_string('view_error_unable_join_student', 'bigbluebuttonbn'); |
||
| 114 | } |
||
| 115 | |||
| 116 | return(self::mobile_print_error($error)); |
||
| 117 | } |
||
| 118 | |||
| 119 | // Mark viewed by user (if required). |
||
| 120 | $completion = new \completion_info($course); |
||
| 121 | $completion->set_module_viewed($cm); |
||
| 122 | |||
| 123 | // Validate if the user is in a role allowed to join. |
||
| 124 | if (!has_capability('moodle/category:manage', $context) && |
||
| 125 | !has_capability('mod/bigbluebuttonbn:join', $context)) { |
||
| 126 | $error = get_string('view_nojoin', 'bigbluebuttonbn'); |
||
| 127 | return(self::mobile_print_error($error)); |
||
| 128 | } |
||
| 129 | |||
| 130 | // Initialize session variable used across views. |
||
| 131 | $SESSION->bigbluebuttonbn_bbbsession = $bbbsession; |
||
| 132 | |||
| 133 | // Logic of bbb_view for join to session. |
||
| 134 | // If user is not administrator nor moderator (user is student) and waiting is required. |
||
| 135 | if (!$bbbsession['administrator'] && !$bbbsession['moderator'] && $bbbsession['wait']) { |
||
| 136 | $canjoin = \mod_bigbluebuttonbn\locallib\bigbluebutton::can_join_meeting($args->cmid); |
||
| 137 | if (!$canjoin['can_join']) { |
||
| 138 | $message = get_string('view_message_conference_wait_for_moderator', 'bigbluebuttonbn'); |
||
| 139 | return (self::mobile_print_notification($bigbluebuttonbn, $cm, $message)); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | // See if the BBB session is already in progress. |
||
| 144 | if (!bigbluebuttonbn_is_meeting_running($bbbsession['meetingid'])) { |
||
| 145 | |||
| 146 | // The meeting doesnt exist in BBB server, must be created. |
||
| 147 | $response = bigbluebuttonbn_get_create_meeting_array( |
||
| 148 | \mod_bigbluebuttonbn\locallib\mobileview::create_meeting_data($bbbsession), |
||
| 149 | \mod_bigbluebuttonbn\locallib\mobileview::create_meeting_metadata($bbbsession), |
||
| 150 | $bbbsession['presentation']['name'], |
||
| 151 | $bbbsession['presentation']['url'] |
||
| 152 | ); |
||
| 153 | |||
| 154 | View Code Duplication | if (empty($response)) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 155 | // The BBB server is failing. |
||
| 156 | if ($bbbsession['administrator']) { |
||
| 157 | $e = get_string('view_error_unable_join', 'bigbluebuttonbn'); |
||
| 158 | } else if ($bbbsession['moderator']) { |
||
| 159 | $e = get_string('view_error_unable_join_teacher', 'bigbluebuttonbn'); |
||
| 160 | } else { |
||
| 161 | $e = get_string('view_error_unable_join_student', 'bigbluebuttonbn'); |
||
| 162 | } |
||
| 163 | return(self::mobile_print_error($e)); |
||
| 164 | } |
||
| 165 | if ($response['returncode'] == 'FAILED') { |
||
| 166 | // The meeting could not be created. |
||
| 167 | $errorkey = bigbluebuttonbn_get_error_key($response['messageKey'], 'view_error_create'); |
||
| 168 | $e = get_string($errorkey, 'bigbluebuttonbn'); |
||
| 169 | return(self::mobile_print_error($e)); |
||
| 170 | } |
||
| 171 | if ($response['hasBeenForciblyEnded'] == 'true') { |
||
| 172 | $e = get_string('index_error_forciblyended', 'bigbluebuttonbn'); |
||
| 173 | return(self::mobile_print_error($e)); |
||
| 174 | } |
||
| 175 | |||
| 176 | // Event meeting created. |
||
| 177 | bigbluebuttonbn_event_log(\mod_bigbluebuttonbn\event\events::$events['meeting_create'], $bigbluebuttonbn); |
||
| 178 | // Insert a record that meeting was created. |
||
| 179 | $overrides = array('meetingid' => $bbbsession['meetingid']); |
||
| 180 | $meta = '{"record":'.($bbbsession['record'] ? 'true' : 'false').'}'; |
||
| 181 | bigbluebuttonbn_log($bbbsession['bigbluebuttonbn'], BIGBLUEBUTTONBN_LOG_EVENT_CREATE, $overrides, $meta); |
||
| 182 | } |
||
| 183 | |||
| 184 | // It is part of 'bigbluebuttonbn_bbb_view_join_meeting' in bbb_view. |
||
| 185 | // Update the cache. |
||
| 186 | $meetinginfo = bigbluebuttonbn_get_meeting_info($bbbsession['meetingid'], BIGBLUEBUTTONBN_UPDATE_CACHE); |
||
| 187 | if ($bbbsession['userlimit'] > 0 && intval($meetinginfo['participantCount']) >= $bbbsession['userlimit']) { |
||
| 188 | // No more users allowed to join. |
||
| 189 | $message = get_string('view_error_userlimit_reached', 'bigbluebuttonbn'); |
||
| 190 | return(self::mobile_print_notification($bigbluebuttonbn, $cm, $message)); |
||
| 191 | } |
||
| 192 | |||
| 193 | // Build final url to BBB. |
||
| 194 | $urltojoin = \mod_bigbluebuttonbn\locallib\mobileview::build_url_join_session($bbbsession); |
||
| 195 | |||
| 196 | // Check groups access and show message. |
||
| 197 | $msjgroup = array(); |
||
| 198 | $groupmode = groups_get_activity_groupmode($bbbsession['cm']); |
||
| 199 | if ($groupmode != NOGROUPS) { |
||
| 200 | $msjgroup = array("message" => get_string('view_mobile_message_groups_not_supported', |
||
| 201 | 'bigbluebuttonbn')); |
||
| 202 | } |
||
| 203 | |||
| 204 | $data = array( |
||
| 205 | 'bigbluebuttonbn' => $bigbluebuttonbn, |
||
| 206 | 'bbbsession' => (object) $bbbsession, |
||
| 207 | 'msjgroup' => $msjgroup, |
||
| 208 | 'urltojoin' => $urltojoin, |
||
| 209 | 'cmid' => $cm->id, |
||
| 210 | 'courseid' => $course->id |
||
| 211 | ); |
||
| 212 | |||
| 213 | // We want to show a notification when user excedded 45 seconds without click button. |
||
| 214 | $jstimecreatedmeeting = 'setTimeout(function(){ |
||
| 215 | document.getElementById("bigbluebuttonbn-mobile-notifications").style.display = "block"; |
||
| 216 | document.getElementById("bigbluebuttonbn-mobile-join").disabled = true; |
||
| 217 | document.getElementById("bigbluebuttonbn-mobile-meetingready").style.display = "none"; |
||
| 218 | }, 45000);'; |
||
| 219 | |||
| 220 | return array( |
||
| 221 | 'templates' => array( |
||
| 222 | array( |
||
| 223 | 'id' => 'main', |
||
| 224 | 'html' => $OUTPUT->render_from_template('mod_bigbluebuttonbn/mobile_view_page', $data), |
||
| 225 | ), |
||
| 226 | ), |
||
| 227 | 'javascript' => $jstimecreatedmeeting, |
||
| 228 | 'otherdata' => '', |
||
| 229 | 'files' => '' |
||
| 230 | ); |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Returns the view for errors. |
||
| 235 | * @param string $error Error to display. |
||
| 236 | * |
||
| 237 | * @return array HTML, javascript and otherdata |
||
| 238 | */ |
||
| 239 | protected static function mobile_print_error($error) { |
||
| 240 | |||
| 241 | global $OUTPUT; |
||
| 242 | $data = array( |
||
| 243 | 'error' => $error |
||
| 244 | ); |
||
| 245 | |||
| 246 | return array( |
||
| 247 | 'templates' => array( |
||
| 248 | array( |
||
| 249 | 'id' => 'main', |
||
| 250 | 'html' => $OUTPUT->render_from_template('mod_bigbluebuttonbn/mobile_view_error', $data), |
||
| 251 | ), |
||
| 252 | ), |
||
| 253 | 'javascript' => '', |
||
| 254 | 'otherdata' => '', |
||
| 255 | 'files' => '' |
||
| 256 | ); |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Returns the view for messages. |
||
| 261 | * @param object $bigbluebuttonbn |
||
| 262 | * @param stdClass $cm |
||
| 263 | * @param string $message Message to display. |
||
| 264 | * @param array $notstarted Extra messages for not started session. |
||
| 265 | * @return array HTML, javascript and otherdata |
||
| 266 | */ |
||
| 267 | protected static function mobile_print_notification($bigbluebuttonbn, $cm, $message, $notstarted = array()) { |
||
| 268 | |||
| 269 | global $OUTPUT, $CFG; |
||
| 270 | $data = array( |
||
| 271 | 'bigbluebuttonbn' => $bigbluebuttonbn, |
||
| 272 | 'cmid' => $cm->id, |
||
| 273 | 'message' => $message, |
||
| 274 | 'not_started' => $notstarted |
||
| 275 | ); |
||
| 276 | |||
| 277 | return array( |
||
| 278 | 'templates' => array( |
||
| 279 | array( |
||
| 280 | 'id' => 'main', |
||
| 281 | 'html' => $OUTPUT->render_from_template('mod_bigbluebuttonbn/mobile_view_notification', $data), |
||
| 282 | ), |
||
| 283 | ), |
||
| 284 | 'javascript' => file_get_contents($CFG->dirroot . '/mod/bigbluebuttonbn/mobile.notification.js'), |
||
| 285 | 'otherdata' => '', |
||
| 286 | 'files' => '' |
||
| 287 | ); |
||
| 288 | } |
||
| 289 | } |
||
| 290 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: