-
Notifications
You must be signed in to change notification settings - Fork 19
/
guest.php
532 lines (426 loc) · 18.2 KB
/
guest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<?php
// enable display errors only on dev systems
ini_set('display_errors', 1);
//ini_set('error_reporting', 5);
use BigBlueButton\Core\Record;
use BigBlueButton\Parameters\CreateMeetingParameters;
use BigBlueButton\Responses\GetMeetingsResponse;
use BigBlueButton\Responses\GetRecordingsResponse;
use BigBlueButton\Parameters\DeleteRecordingsParameters;
use ILIAS\DI\Container;
$directory = strstr($_SERVER['SCRIPT_FILENAME'], 'Customizing', true);
if(empty($directory))
{
$directory = getcwd();
}
chdir($directory);
require_once('./Services/Context/classes/class.ilContext.php');
require_once("./Services/Init/classes/class.ilInitialisation.php");
require_once("./Services/Utilities/classes/class.ilUtil.php");
require_once('./Services/Language/classes/class.ilLanguage.php');
//require_once("./Services/Utilities/classes/class.ilBrowser.php");
require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/BigBlueButton/classes/class.ilBigBlueButtonProtocol.php';
require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/BigBlueButton/vendor/autoload.php';
class ilInitialisationGuest extends ilInitialisation
{
protected static function getIniHost(): string
{
// Create ini-handler (onces)
self::initIliasIniFile();
global $ilIliasIniFile;
// Return [server] -> 'http_path' variable from 'ilias.init.php'
$http_path = $ilIliasIniFile->readVariable('server', 'http_path');
// Strip http:// & https://
if (strpos($http_path, 'https://') !== false)
$http_path = substr($http_path, 8);
if (strpos($http_path, 'http://') !== false)
$http_path = substr($http_path, 7);
// Return clean host
return $http_path;
}
public static function initIlias($client_id=null, $client_token=null): void
{
if(empty($client_id))
{
throw new \Exception("There has been an error. Try it again.");
}
define ("CLIENT_ID", $client_id);
ilContext::init(\ilContext::CONTEXT_SCORM);
//UK
ilInitialisation::initILIAS();
ilInitialisation::buildHTTPPath();
}
/**
* Function; initGlobal($a_name, $a_class, $a_source_file)
* Derive from protected to public...
*
* @see \ilInitialisation::initGlobal($a_name, $a_class, $a_source_file, $destroy_existing)
*/
public static function initGlobal($a_name, $a_class, $a_source_file = null, ?bool $destroy_existing = false): void
{
parent::initGlobal($a_name, $a_class, $a_source_file, $destroy_existing);
}
/**
* Function: initDatabase()
* Derive from protected to public...
*
* @see \ilInitialisation::initDatabase()
*/
public static function initDatabase(): void
{
if (!isset($GLOBALS['ilDB'])) {
parent::initGlobal("ilBench", "ilBenchmark", "./Services/Utilities/classes/class.ilBenchmark.php");
parent::initDatabase();
}
}
/**
* Function: initIliasIniFile()
* Derive from protected to public...
*
* @see \ilInitialisation::initIliasIniFile()
*/
public static function initIliasIniFile(): void
{
if (!isset($GLOBALS['ilIliasIniFile'])) {
parent::initIliasIniFile();
}
}
/**
* Function: initClientIniFile()
* Derive from protected to public...
*
* @see \ilInitialisation::initIliasIniFile()
*/
public static function initClientIniFile(): void
{
if (!isset($GLOBALS['initClientIniFile'])) {
parent::initClientIniFile();
}
}
public static function initLog(): void
{
if (!isset($GLOBALS['ilLog'])) {
parent::initLog();
parent::initGlobal("ilAppEventHandler", "ilAppEventHandler", "./Services/EventHandling/classes/class.ilAppEventHandler.php");
}
}
}
class GuestLink
{
const DEFAULT_LANG = 'de';
const PLUGIN_DIR = 'Customizing/global/plugins/Services/Repository/RepositoryObject/BigBlueButton';
/** @var GuestLink|null $instance */
static private $instance;
/** @var Container $dic */
private $dic;
/** @var ilUtil $ilUtil */
private $ilUtil;
private $bbb;
/** @var int $refId */
private $refId = 0;
/** @var string $client */
private $client;
/** @var ilObjBigBlueButton $object */
private $pluginObject;
/** @var ilBigBlueButtonProtocol $object */
private $pluginHelper;
/** @var ilBigBlueButtonConfig $settings */
private $pluginConfig;
/** @var string $meetingId */
private $meetingId = 0;
/** @var string $attendeePwd */
private $attendeePwd;
/** @var string $urlJoinMeeting */
private $urlJoinMeeting;
/** @var string $iliasDomain */
private $iliasDomain;
private $form;
/** @var string $userTitle */
private $userTitle = '';
/** @var string $displayName */
private $displayName = '';
/** @var string|null $guestPassword */
private $guestPassword = null;
/** @var string[] $userAccept */
private $userAccept = [
'termsOfUse' => false
];
/** @var bool[] $errState */
private $errState = [
'displayname' => false,
'termsOfUse' => false,
'moderator' => false,
'userLimit' => false
];
/** @var string $userLang */
private $userLang = 'de';
/** @var string[] $isoLangCode */
private $isoLangCode = [
'de' => 'de-DE',
'en' => 'en-US'
];
/** @var array $langVar */
private $langVar = [];
/** @var array $formField */
private $formField = [];
/** @var ilTemplate $htmlTpl */
private $htmlTpl;
// BigBlueButton
private function setMeetingId(): void
{
global $ilIliasIniFile;
$this->iliasDomain = $ilIliasIniFile->readVariable('server', 'http_path');
$this->iliasDomain = preg_replace("/^(https:\/\/)|(http:\/\/)+/", "", $this->iliasDomain);
$rawMeetingId = $this->iliasDomain . ';' . $this->client . ';' . $this->pluginObject->getBBBId();
$this->meetingId = $this->pluginObject->getBBBId();//$rawMeetingId;
}
private function isMeetingRunning(): bool
{
try {
$meetingParams = new \BigBlueButton\Parameters\IsMeetingRunningParameters($this->meetingId);
$response = $this->bbb->isMeetingRunning($meetingParams);
$running = $response->isRunning();
} catch (Exception $e) {
$running = false;
}
return $running;
}
private function getUrlJoinMeeting(): bool
{
global $DIC;
if( !$this->isMeetingRunning() ) {
return false;
}
$joinParams = new \BigBlueButton\Parameters\JoinMeetingParameters($this->meetingId, trim($this->userTitle . ' ') . $this->displayName, $this->attendeePwd);
$joinParams->setRedirect(true)->setRole('VIEWER')->setClientURL($this->dic->http()->request()->getUri());
if( (bool)strlen($this->urlJoinMeeting = $this->bbb->getJoinMeetingURL($joinParams)) )
{
return true;
}
return false;
}
// Header-Redirect to BBB
private function redirectToVc(): void {
header('Status: 303 See Other', false, 303);
header('Location:' . $this->urlJoinMeeting);
exit;
}
// Language Vars & HTML-Form
private function setFormElements() {
$input = function($name, $value, $type = 'text', $title = '', $class="", $addAttr = "") {
return '<input type="' . $type . '" name="' . $name . '" value="' . $value . '" title="' . $title . '" placeholder="' . $title . '" class="' . $class . '"' . $addAttr . ' />';
};
$this->formField = [
'user_title' => $input('user_title', $this->userTitle, 'text', 'Titel'),
'display_name' => $input('display_name', $this->displayName, 'text', $this->getLangVar('guest_displayname_input'), 'form-control'),
'submit' => $input('submit', $this->getLangVar('btntext_join_meeting'), 'submit', $this->getLangVar('btntext_join_meeting'), 'btn btn-primary'),
'guest_password' => $input('guest_password', $this->guestPassword, 'password', $this->getLangVar('guest_password_input'), 'form-control', ' autocomplete="new-password"'),
'guest_password_hidden' => $input('guest_password', $this->pluginObject->getAccessToken(), 'hidden', $this->getLangVar('guest_password_input'), 'form-control'),
'guest_login_button' => $input('guest_login_button', $this->getLangVar('btntext_guest_login_button'), 'submit', $this->getLangVar('btntext_guest_login'), 'btn btn-primary'),
];
}
private function setHtmlDocument()
{
$http_base = ILIAS_HTTP_PATH;
if (strpos($http_base,'/m/')) {
$http_base = strstr($http_base,'/m/',true).'/Customizing/global/plugins/Services/Repository/RepositoryObject/BigBlueButton';
}
$this->htmlTpl = new ilTemplate( dirname(__FILE__) . '/' . 'templates/tpl.guest.html', true, true);
$this->htmlTpl->setVariable('USER_LANG', $this->isoLangCode[$this->userLang]);
$this->htmlTpl->setVariable('HTTP_BASE', $http_base);
$this->htmlTpl->setVariable('MEETING_TITLE', $this->getMeetingTitle());// . ' - ' . $this->getLangVar('big_blue_button'));
$this->htmlTpl->setVariable('INFO_TOP_MODERATED_M', $this->getLangVar('top_moderated_m'));
$this->htmlTpl->setVariable('ERR_STATE_INPUT_FIELD', (int)$this->errState['displayname']);
$this->htmlTpl->setVariable('ERR_MSG_INPUT_FIELD', !$this->errState['displayname'] ? '' : $this->getLangVar('err_msg_displayname'));
$this->htmlTpl->setVariable('ERR_STATE_USER_LIMIT', (int)$this->errState['userLimit'] );
$this->htmlTpl->setVariable('ERR_MSG_USER_LIMIT', !$this->errState['userLimit'] ? '': $this->pluginConfig->getMaxConcurrentSessionsMsg());
$this->htmlTpl->setVariable('ERR_STATE_TERMSOFUSE', (int)$this->errState['termsOfUse']);
$this->htmlTpl->setVariable('VAL_TERMSOFUSE', (int)$this->userAccept['termsOfUse']);
$this->htmlTpl->setVariable('TXT_ACCEPT_TERMSOFUSE', $this->getLangVar('terms_of_use') );
$this->htmlTpl->setVariable('ERR_STATE_MODERATOR', (int)$this->errState['moderator']);
$this->htmlTpl->setVariable('ERR_MSG_MODERATOR', !$this->errState['moderator'] ? '' : $this->getLangVar('wait_join_meeting'));
$this->htmlTpl->setVariable('FORM_ACTION', filter_var('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL));
$this->htmlTpl->setVariable('INFO_BOTTOM', $this->getLangVar('join_info'));
$this->htmlTpl->setVariable('INFO_REQUIREMENTS', $this->getLangVar('tech_requirements_info'));
if( $this->isUserLoggedIn() ) {
#ilSession::set('guestLoggedIn', false);
$this->htmlTpl->setVariable('INPUT_FIELD', $this->getFormField('display_name'));
$this->htmlTpl->setVariable('SUBMIT_BUTTON', $this->getFormField('guest_password_hidden') . $this->getFormField('submit'));
}
// GUEST PASSWORD/LOGIN
if( $this->isPwEnabled() && !$this->isUserLoggedIn() ) {
if( isset($_POST['guest_password']) ) {
$this->htmlTpl->setVariable('ERR_STATE_INPUT_FIELD', 1);
$this->htmlTpl->setVariable('ERR_MSG_INPUT_FIELD', $this->getLangVar('err_msg_guest_password'));
}
$this->htmlTpl->setVariable('INPUT_FIELD', $this->getFormField('guest_password'));
$this->htmlTpl->setVariable('INPUT_FIELD_INFO', $this->getLangVar('guest_password_input_info'));
$this->htmlTpl->setVariable('SUBMIT_BUTTON', $this->getFormField('guest_login_button'));
}
}
private function isPwEnabled() {
return (bool)strlen(trim($this->pluginObject->getAccessToken()));
}
private function isUserLoggedIn() {
return ilSession::get('guestLoggedIn');
}
private function checkPw( ?string $phrase = null ) {
return trim($phrase) === trim($this->pluginObject->getAccessToken());
}
private function setGuestLoginState() {
$phrase = isset($_POST['guest_password']) ? filter_var($_POST['guest_password'], FILTER_SANITIZE_ENCODED) : '';
if( $this->isUserLoggedIn() || $this->checkPw($phrase) ) {
ilSession::set('guestLoggedIn', true);
} else {
ilSession::set('guestLoggedIn', false);
}
}
private function getFormField($fieldName) {
return strlen($field = $this->formField[$fieldName]) ? $field : '';
}
private function getMeetingTitle()
{
return $this->pluginObject->getTitle();
}
private function assignTranslatedLangVars()
{
$langFilePath = dirname(__FILE__) . '/lang/';
// lang files
$deLangFileName = $langFilePath . 'ilias_de.lang';
$enLangFileName = $langFilePath . 'ilias_en.lang';
// file content
$deLangFileContent = file_get_contents($deLangFileName);
$enLangFileContent = file_get_contents($enLangFileName);
// content lines 2 array
$deLangFileContentArr = explode("\n", $deLangFileContent);
$enLangFileContentArr = explode("\n", $enLangFileContent);
// build array with langVarKeys
$enLangKeyVal = [];
$i = 0;
foreach( $deLangFileContentArr as $line ) {
if( substr_count($line, '#:#') ) {
list($key, $value) = explode('#:#', $line);
$enLangKeyVal[] = trim($key) . '#:#' . trim($enLangFileContentArr[$i]);
$i++;
}
}
echo implode("\n", $enLangKeyVal);
}
private function getLangVar(string $value): string
{
return ilLanguage::_lookupEntry( $this->userLang, 'rep_robj_xbbb','rep_robj_xbbb_' . $value);
}
private function setUserLangBySvrParam(): void
{
if( isset($this->dic->http()->request()->getServerParams()['HTTP_ACCEPT_LANGUAGE']) && strlen($this->dic->http()->request()->getServerParams()['HTTP_ACCEPT_LANGUAGE']) >= 2 ) {
$this->userLang = substr($this->dic->http()->request()->getServerParams()['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
}
private function setLangVars(): void
{
$langFilePath = dirname(__FILE__) . '/lang/';
$langFileName = 'ilias_' . $this->userLang . '.lang';
$langPathFile = $langFilePath . $langFileName;
if( !file_exists($langPathFile) ) {
$langPathFile = $langFilePath . 'ilias_' . self::DEFAULT_LANG . '.lang';
}
if( file_exists($langPathFile) ) {
$langFileContent = file_get_contents($langPathFile);
foreach( explode("\n", $langFileContent) as $line ) {
if( substr_count($line, '#:#') ) {
list($key, $value) = explode('#:#', $line);
$this->langVar[trim($key)] = trim($value);
}
}
}
}
// validation checks
private function checkPostRequest()
{
$score = 0;
if( is_array($_POST) ) {
foreach($_POST as $key => $val) {
if( filter_var($key, FILTER_SANITIZE_STRING) === 'display_name' ) {
$this->displayName = filter_var($val, FILTER_SANITIZE_STRING);
$score += 2;
}
}
if( !(bool)strlen($this->displayName) ) {
$score -= 2;
$this->errState['displayname'] = isset($_POST['display_name']);
}
}
return $score >= 0;
}
private function validateInvitation()
{
switch( true ) {
case $this->pluginConfig->isGuestGlabalAllowed() && $this->pluginObject->isGuestLinkAllowed():
break;
default:
$this->httpExit(403);
}
}
private function httpExit(int $code = 404)
{
$text = [
403 => 'Forbidden',
404 => 'Not Found'
];
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
http_response_code($code);
header($protocol . ' ' . $code . ' ' . $text[$code]);
exit;
}
private function __construct()
{
$this->client = isset($_GET['client_id']) ? filter_var($_GET['client_id'], FILTER_SANITIZE_STRING) : '';
$this->refId = isset($_GET['ref_id']) ? filter_var($_GET['ref_id'], FILTER_SANITIZE_NUMBER_INT) : 0;
ilInitialisationGuest::initIlias($this->client);
global $DIC; /** @var Container $DIC */
$this->dic = $DIC;
try {
$this->pluginObject = ilObjectFactory::getInstanceByRefId($this->refId);
} catch (ilDatabaseException $e) {
} catch (ilObjectNotFoundException $e) {
$this->httpExit(404);
}
$this->pluginConfig = $this->pluginObject;
$this->pluginHelper = new ilBigBlueButtonProtocol($this->pluginObject);
// exit if not valid
$this->validateInvitation();
$this->setGuestLoginState();
$this->setUserLangBySvrParam();
// redirect to BBB if valid
if( $this->checkPostRequest() ) {
if($this->pluginObject->isMaxConcurrentSessionEnabled()){
$available_sessions = $this->pluginHelper->getMaximumSessionsAvailable();
if($available_sessions['max_sessions'] || ( key_exists($this->pluginObject->getBBBId(), $available_sessions['meetings']) && $available_sessions['meetings'][$this->pluginObject->getBBBId()]['userlimit'])){
$this->errState['userLimit'] = true;
}
}else if( !$this->errState['displayname'] ) {
$this->bbb = new ilBBB($this->pluginConfig->getSvrSalt(), $this->pluginConfig->getSvrPublicUrl());
$this->attendeePwd = $this->pluginObject->getAttendeePwd();
$this->setMeetingId();
if( $this->getUrlJoinMeeting() ) {
$this->redirectToVc();
}
$this->errState['moderator'] = true;
}
}
$this->setFormElements();
$this->setHtmlDocument();
}
public static function init()
{
if( self::$instance instanceof GuestLink) {
return self::$instance;
}
return self::$instance = new self();
}
public function __toString(): string
{
return $this->htmlTpl->get();
}
}
echo GuestLink::init();