2020-04-26 11:36:41 +02:00
|
|
|
<?php
|
|
|
|
namespace OCA\BigBlueButton\Controller;
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
use OCA\BigBlueButton\BigBlueButton\API;
|
|
|
|
use OCA\BigBlueButton\BigBlueButton\Presentation;
|
2020-04-26 11:36:41 +02:00
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
|
|
|
use OCP\AppFramework\PublicShareController;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\ISession;
|
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\IConfig;
|
2020-05-16 17:14:17 +02:00
|
|
|
use OCP\Files\NotFoundException;
|
2020-04-26 11:36:41 +02:00
|
|
|
use OCA\BigBlueButton\Service\RoomService;
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
|
|
|
|
class JoinController extends PublicShareController
|
|
|
|
{
|
2020-04-26 12:14:06 +02:00
|
|
|
/** @var RoomService */
|
|
|
|
private $service;
|
|
|
|
|
|
|
|
/** @var IUserSession */
|
|
|
|
private $userSession;
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
/** @var API */
|
|
|
|
private $api;
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
string $appName,
|
|
|
|
IRequest $request,
|
|
|
|
ISession $session,
|
|
|
|
RoomService $service,
|
|
|
|
IUserSession $userSession,
|
|
|
|
IConfig $config,
|
2020-05-16 17:14:17 +02:00
|
|
|
API $api
|
2020-04-26 12:14:06 +02:00
|
|
|
) {
|
|
|
|
parent::__construct($appName, $request, $session);
|
|
|
|
|
|
|
|
$this->service = $service;
|
|
|
|
$this->userSession = $userSession;
|
|
|
|
$this->config = $config;
|
2020-05-16 17:14:17 +02:00
|
|
|
$this->api = $api;
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getPasswordHash(): string
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate the token of this share. If the token is invalid this controller
|
|
|
|
* will return a 404.
|
|
|
|
*/
|
|
|
|
public function isValidToken(): bool
|
|
|
|
{
|
|
|
|
$room = $this->service->findByUid($this->getToken());
|
|
|
|
|
|
|
|
return $room !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows you to specify if this share is password protected
|
|
|
|
*/
|
|
|
|
protected function isPasswordProtected(): bool
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2020-05-16 17:14:17 +02:00
|
|
|
public function index($displayname, $u = '', $filename = '')
|
2020-04-26 12:14:06 +02:00
|
|
|
{
|
|
|
|
$room = $this->service->findByUid($this->getToken());
|
|
|
|
|
|
|
|
if ($room === null) {
|
2020-05-16 17:14:17 +02:00
|
|
|
throw new NotFoundException();
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
$userId = null;
|
|
|
|
$presentation = null;
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
if ($this->userSession->isLoggedIn()) {
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
$displayname = $user->getDisplayName();
|
2020-05-16 17:14:17 +02:00
|
|
|
$userId = $user->getUID();
|
|
|
|
|
|
|
|
if ($userId === $room->userId) {
|
|
|
|
$presentation = new Presentation($u, $filename);
|
|
|
|
}
|
2020-04-26 12:14:06 +02:00
|
|
|
} elseif (empty($displayname) || strlen($displayname) < 3) {
|
|
|
|
$response = new TemplateResponse($this->appName, 'publicdisplayname', [
|
2020-04-28 14:34:30 +02:00
|
|
|
'room' => $room->name,
|
2020-04-26 12:14:06 +02:00
|
|
|
'wrongdisplayname' => !empty($displayname) && strlen($displayname) < 3
|
|
|
|
], 'guest');
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
$this->addFormActionDomain($response);
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
$creationDate = $this->api->createMeeting($room, $presentation);
|
|
|
|
$joinUrl = $this->api->createJoinUrl($room, $creationDate, $displayname, $userId);
|
|
|
|
|
|
|
|
return new RedirectResponse($joinUrl);
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
private function addFormActionDomain($response)
|
2020-04-26 12:14:06 +02:00
|
|
|
{
|
|
|
|
$apiUrl = $this->config->getAppValue($this->appName, 'api.url');
|
2020-05-16 17:14:17 +02:00
|
|
|
$parsedApiUrl = parse_url($apiUrl);
|
2020-04-26 12:14:06 +02:00
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
if ($parsedApiUrl === false) {
|
|
|
|
throw new \Exception('No valid api url provided');
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
$response->getContentSecurityPolicy()->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']);
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|