-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathguest.php
More file actions
415 lines (320 loc) · 14.3 KB
/
guest.php
File metadata and controls
415 lines (320 loc) · 14.3 KB
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
<?php
// enable display errors only on dev systems
ini_set('display_errors', 1);
use BigBlueButton\Enum\Role;
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/Language/classes/class.ilLanguage.php');
/**
* JoinWithGuestLink initialization ilias class
* @author Jephte Abijuru <jephte.abijuru@minervis.com>
* Credits to MultiVC
* @version $Id$
*
*/
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;
private $bbb;
/** @var int $refId */
private int $refId = 0;
/** @var string $client */
private $client;
/** @var ilObjBigBlueButton $object */
private ilObjBigBlueButton $pluginObject;
/** @var ilBigBlueButtonProtocol $object */
private ilBigBlueButtonProtocol $pluginHelper;
/** @var ilObject $settings */
private ilObject $pluginConfig;
/** @var string $meetingId */
private $meetingId = 0;
/** @var string $attendeePwd */
private $attendeePwd;
/** @var string $urlJoinMeeting */
private string $urlJoinMeeting;
/** @var string $userTitle */
private string $userTitle = '';
/** @var string $displayName */
private string $displayName = '';
/** @var string|null $guestPassword */
private ?string $guestPassword = null;
/** @var string[] $userAccept */
private array $userAccept = [
'termsOfUse' => false
];
/** @var bool[] $errState */
private array $errState = [
'displayname' => false,
'termsOfUse' => false,
'moderator' => false,
'userLimit' => false
];
/** @var string $userLang */
private string $userLang = 'de';
/** @var string[] $isoLangCode */
private array $isoLangCode = [
'de' => 'de-DE',
'en' => 'en-US'
];
/** @var array $formField */
private $formField = [];
/** @var ilTemplate $htmlTpl */
private $htmlTpl;
// BigBlueButton
private function setMeetingId(): void
{
$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
{
if( !$this->isMeetingRunning() ) {
return false;
}
$joinParams = new \BigBlueButton\Parameters\JoinMeetingParameters($this->meetingId, trim($this->userTitle . ' ') . $this->displayName, Role::VIEWER);
$joinParams->setRedirect(true)
->setRole('VIEWER')
->setClientURL($this->dic->http()->request()->getUri())
;
if( strlen($this->urlJoinMeeting = $this->bbb->getJoinMeetingURL($joinParams)) )
{
return true;
}
return false;
}
// Header-Redirect to BBB
private function redirectToBBB(): 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->txt('guest_displayname_input'), 'form-control'),
'submit' => $input('submit', $this->txt('btntext_join_meeting'), 'submit', $this->txt('btntext_join_meeting'), 'btn btn-primary'),
'guest_password' => $input('guest_password', $this->guestPassword, 'password', $this->txt('guest_password_input'), 'form-control', ' autocomplete="new-password"'),
'guest_password_hidden' => $input('guest_password', $this->pluginObject->getAccessToken(), 'hidden', $this->txt('guest_password_input'), 'form-control'),
'guest_login_button' => $input('guest_login_button', $this->txt('btntext_guest_login_button'), 'submit', $this->txt('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->txt('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->txt('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->txt('terms_of_use') );
$this->htmlTpl->setVariable('ERR_STATE_MODERATOR', (int)$this->errState['moderator']);
$this->htmlTpl->setVariable('ERR_MSG_MODERATOR', !$this->errState['moderator'] ? '' : $this->txt('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->txt('join_info'));
$this->htmlTpl->setVariable('INFO_REQUIREMENTS', $this->txt('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->txt('err_msg_guest_password'));
}
$this->htmlTpl->setVariable('INPUT_FIELD', $this->getFormField('guest_password'));
$this->htmlTpl->setVariable('INPUT_FIELD_INFO', $this->txt('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(): void
{
if ($this->dic->http()->wrapper()->post()->has('guest_password')) {
$phrase = trim($this->dic->http()->wrapper()->post()->retrieve('guest_password', $this->dic->refinery()->kindlyTo()->string()));
if ($this->isUserLoggedIn() || $this->checkPw($phrase)) {
ilSession::set('guestLoggedIn', true);
} else {
ilSession::set('guestLoggedIn', false);
}
}else{
ilSession::set('guestLoggedIn', true);
}
}
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 txt(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);
}
}
// validation checks
private function checkPostRequest()
{
$score = 0;
if ($this->dic->http()->wrapper()->post()->has('display_name')){
$this->displayName = trim($this->dic->http()->wrapper()->post()->retrieve('display_name', $this->dic->refinery()->kindlyTo()->string()));
$score += 2;
if($this->displayName == '') {
$score -= 2;
$this->errState['displayname'] = true;
}
}
if ($this->dic->http()->wrapper()->post()->has('terms_of_use')) {
$this->userAccept['termsOfUse'] = (bool) $this->dic->http()->wrapper()->post()->retrieve('terms_of_use', $this->dic->refinery()->kindlyTo()->int());
$score += 4;
} else {
$this->errState['termsOfUse'] = true;
}
return $score >= 6;
}
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()
{
ilContext::init(ilContext::CONTEXT_WEBDAV);
ilInitialisation::initILIAS();
global $DIC;
$this->dic = $DIC;
$this->client = $this->dic->http()->wrapper()->query()->retrieve('client_id', $this->dic->refinery()->kindlyTo()->string());
$this->refId = $this->dic->http()->wrapper()->query()->retrieve('ref_id', $this->dic->refinery()->kindlyTo()->int());
try {
$this->pluginObject = $this->pluginConfig = ilObjectFactory::getInstanceByRefId($this->refId);
} catch (ilDatabaseException $e) {
} catch (ilObjectNotFoundException $e) {
$this->httpExit(404);
}
$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->redirectToBBB();
}
$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();