diff --git a/Changelog.txt b/Changelog.txt index 84c3591..3587f4d 100755 --- a/Changelog.txt +++ b/Changelog.txt @@ -64,3 +64,8 @@ BigBLueButton-ILIAS Plugin Changelog - Fix phone calls - delete recording messages when the meeting is not being recorded - Add proxy to the new client + + --------# +2024-12-04 Version 3.1 + - Fix guest links + - Fix some PHP 7 errors diff --git a/guest.php b/guest.php index 36df869..4d1f8ab 100644 --- a/guest.php +++ b/guest.php @@ -1,13 +1,8 @@ '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"); - } - } -} - +/** + * JoinWithGuestLink initialization ilias class + * @author Jephte Abijuru + * Credits to MultiVC + * @version $Id$ + * + */ class GuestLink { @@ -133,25 +37,21 @@ class GuestLink /** @var Container $dic */ private $dic; - /** @var ilUtil $ilUtil */ - private $ilUtil; - - private $bbb; /** @var int $refId */ - private $refId = 0; + private int $refId = 0; /** @var string $client */ private $client; /** @var ilObjBigBlueButton $object */ - private $pluginObject; + private ilObjBigBlueButton $pluginObject; /** @var ilBigBlueButtonProtocol $object */ - private $pluginHelper; + private ilBigBlueButtonProtocol $pluginHelper; - /** @var ilBigBlueButtonConfig $settings */ - private $pluginConfig; + /** @var ilObject $settings */ + private ilObject $pluginConfig; /** @var string $meetingId */ private $meetingId = 0; @@ -160,29 +60,24 @@ class GuestLink private $attendeePwd; /** @var string $urlJoinMeeting */ - private $urlJoinMeeting; - - /** @var string $iliasDomain */ - private $iliasDomain; - - private $form; + private string $urlJoinMeeting; /** @var string $userTitle */ - private $userTitle = ''; + private string $userTitle = ''; /** @var string $displayName */ - private $displayName = ''; + private string $displayName = ''; /** @var string|null $guestPassword */ - private $guestPassword = null; + private ?string $guestPassword = null; /** @var string[] $userAccept */ - private $userAccept = [ + private array $userAccept = [ 'termsOfUse' => false ]; /** @var bool[] $errState */ - private $errState = [ + private array $errState = [ 'displayname' => false, 'termsOfUse' => false, 'moderator' => false, @@ -190,16 +85,14 @@ class GuestLink ]; /** @var string $userLang */ - private $userLang = 'de'; + private string $userLang = 'de'; /** @var string[] $isoLangCode */ - private $isoLangCode = [ + private array $isoLangCode = [ 'de' => 'de-DE', 'en' => 'en-US' ]; - /** @var array $langVar */ - private $langVar = []; /** @var array $formField */ private $formField = []; @@ -214,11 +107,7 @@ class GuestLink 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; } @@ -236,14 +125,17 @@ private function isMeetingRunning(): bool 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()); + $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( (bool)strlen($this->urlJoinMeeting = $this->bbb->getJoinMeetingURL($joinParams)) ) + if( strlen($this->urlJoinMeeting = $this->bbb->getJoinMeetingURL($joinParams)) ) { return true; } @@ -254,7 +146,7 @@ private function getUrlJoinMeeting(): bool // Header-Redirect to BBB - private function redirectToVc(): void { + private function redirectToBBB(): void { header('Status: 303 See Other', false, 303); header('Location:' . $this->urlJoinMeeting); exit; @@ -270,11 +162,11 @@ private function setFormElements() { }; $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'), + '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'), ]; } @@ -290,19 +182,19 @@ private function setHtmlDocument() $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('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->getLangVar('err_msg_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->getLangVar('terms_of_use') ); + $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->getLangVar('wait_join_meeting')); + $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->getLangVar('join_info')); - $this->htmlTpl->setVariable('INFO_REQUIREMENTS', $this->getLangVar('tech_requirements_info')); + $this->htmlTpl->setVariable('INFO_BOTTOM', $this->txt('join_info')); + $this->htmlTpl->setVariable('INFO_REQUIREMENTS', $this->txt('tech_requirements_info')); if( $this->isUserLoggedIn() ) { @@ -314,10 +206,10 @@ private function setHtmlDocument() 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('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->getLangVar('guest_password_input_info')); + $this->htmlTpl->setVariable('INPUT_FIELD_INFO', $this->txt('guest_password_input_info')); $this->htmlTpl->setVariable('SUBMIT_BUTTON', $this->getFormField('guest_login_button')); } @@ -335,12 +227,17 @@ 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) ) { + 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); - } else { - ilSession::set('guestLoggedIn', false); } } @@ -387,7 +284,7 @@ private function assignTranslatedLangVars() } - private function getLangVar(string $value): string + private function txt(string $value): string { return ilLanguage::_lookupEntry( $this->userLang, 'rep_robj_xbbb','rep_robj_xbbb_' . $value); } @@ -399,44 +296,27 @@ private function setUserLangBySvrParam(): void } } - 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) ) { + 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'] = isset($_POST['display_name']); + $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 >= 0; + return $score >= 6; } private function validateInvitation() @@ -463,19 +343,22 @@ private function httpExit(int $code = 404) 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 */ + + 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 = ilObjectFactory::getInstanceByRefId($this->refId); + $this->pluginObject = $this->pluginConfig = 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 @@ -496,7 +379,7 @@ private function __construct() $this->attendeePwd = $this->pluginObject->getAttendeePwd(); $this->setMeetingId(); if( $this->getUrlJoinMeeting() ) { - $this->redirectToVc(); + $this->redirectToBBB(); } $this->errState['moderator'] = true; } diff --git a/plugin.php b/plugin.php index 78a28ca..2fc59d7 100755 --- a/plugin.php +++ b/plugin.php @@ -4,7 +4,7 @@ $id = "xbbb"; // code version; must be changed for all code changes -$version = "3.0"; +$version = "3.1"; // ilias min and max version; must always reflect the versions that should // run with the plugin