2020-04-26 11:36:41 +02:00
|
|
|
<?php
|
2020-06-19 09:28:58 +02:00
|
|
|
|
2020-04-26 11:36:41 +02:00
|
|
|
namespace OCA\BigBlueButton\Controller;
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
use OCA\BigBlueButton\BigBlueButton\API;
|
|
|
|
use OCA\BigBlueButton\BigBlueButton\Presentation;
|
2020-06-04 10:25:51 +02:00
|
|
|
use OCA\BigBlueButton\Db\Room;
|
2020-06-16 16:54:50 +02:00
|
|
|
use OCA\BigBlueButton\NoPermissionException;
|
2020-06-04 09:52:49 +02:00
|
|
|
use OCA\BigBlueButton\NotFoundException;
|
2020-06-16 16:54:50 +02:00
|
|
|
use OCA\BigBlueButton\Permission;
|
2020-04-26 11:36:41 +02:00
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\ISession;
|
2020-06-04 18:56:55 +02:00
|
|
|
use OCP\IURLGenerator;
|
2020-04-26 11:36:41 +02:00
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCA\BigBlueButton\Service\RoomService;
|
2020-06-04 09:52:49 +02:00
|
|
|
use OCP\AppFramework\Controller;
|
2020-04-26 11:36:41 +02:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
class JoinController extends Controller {
|
2020-06-04 09:52:49 +02:00
|
|
|
/** @var string */
|
|
|
|
protected $token;
|
|
|
|
|
2020-06-04 10:25:51 +02:00
|
|
|
/** @var Room */
|
|
|
|
protected $room;
|
|
|
|
|
2020-04-26 12:14:06 +02:00
|
|
|
/** @var RoomService */
|
|
|
|
private $service;
|
|
|
|
|
2020-06-04 18:56:55 +02:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
|
|
|
|
2020-04-26 12:14:06 +02:00
|
|
|
/** @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
|
|
|
|
2020-06-16 16:54:50 +02:00
|
|
|
/** @var Permission */
|
|
|
|
private $permission;
|
|
|
|
|
2020-04-26 12:14:06 +02:00
|
|
|
public function __construct(
|
|
|
|
string $appName,
|
|
|
|
IRequest $request,
|
|
|
|
ISession $session,
|
|
|
|
RoomService $service,
|
2020-06-04 18:56:55 +02:00
|
|
|
IURLGenerator $urlGenerator,
|
2020-04-26 12:14:06 +02:00
|
|
|
IUserSession $userSession,
|
|
|
|
IConfig $config,
|
2020-06-16 16:54:50 +02:00
|
|
|
API $api,
|
|
|
|
Permission $permission
|
2020-04-26 12:14:06 +02:00
|
|
|
) {
|
|
|
|
parent::__construct($appName, $request, $session);
|
|
|
|
|
|
|
|
$this->service = $service;
|
2020-06-04 18:56:55 +02:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2020-04-26 12:14:06 +02:00
|
|
|
$this->userSession = $userSession;
|
|
|
|
$this->config = $config;
|
2020-05-16 17:14:17 +02:00
|
|
|
$this->api = $api;
|
2020-06-16 16:54:50 +02:00
|
|
|
$this->permission = $permission;
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function setToken(string $token) {
|
2020-06-04 09:52:49 +02:00
|
|
|
$this->token = $token;
|
2020-06-04 10:25:51 +02:00
|
|
|
$this->room = null;
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function isValidToken(): bool {
|
2020-06-04 10:25:51 +02:00
|
|
|
$room = $this->getRoom();
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
return $room !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2020-06-19 09:28:58 +02:00
|
|
|
public function index($displayname, $u = '', $filename = '', $password = '') {
|
2020-06-04 10:25:51 +02:00
|
|
|
$room = $this->getRoom();
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
if ($room === null) {
|
2020-05-16 17:14:17 +02:00
|
|
|
throw new NotFoundException();
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-06-17 15:09:20 +02:00
|
|
|
$displayname = trim($displayname);
|
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();
|
|
|
|
|
2020-06-16 16:54:50 +02:00
|
|
|
if ($room->access == Room::ACCESS_INTERNAL_RESTRICTED && !$this->permission->isUser($room, $userId)) {
|
|
|
|
throw new NoPermissionException();
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:41:40 +02:00
|
|
|
if ($this->permission->isAdmin($room, $userId)) {
|
2020-05-16 17:14:17 +02:00
|
|
|
$presentation = new Presentation($u, $filename);
|
|
|
|
}
|
2020-06-16 16:54:50 +02:00
|
|
|
} elseif ($room->access === Room::ACCESS_INTERNAL || $room->access == Room::ACCESS_INTERNAL_RESTRICTED) {
|
2020-06-04 18:56:55 +02:00
|
|
|
return new RedirectResponse(
|
|
|
|
$this->urlGenerator->linkToRoute('core.login.showLoginForm', [
|
|
|
|
'redirect_url' => $this->urlGenerator->linkToRoute(
|
|
|
|
'bbb.join.index',
|
|
|
|
['token' => $this->token]
|
|
|
|
),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
} elseif (empty($displayname) || strlen($displayname) < 3 || ($room->access === Room::ACCESS_PASSWORD && $password !== $room->password)) {
|
|
|
|
$response = new TemplateResponse($this->appName, 'join', [
|
2020-04-28 14:34:30 +02:00
|
|
|
'room' => $room->name,
|
2020-06-04 18:56:55 +02:00
|
|
|
'wrongdisplayname' => !empty($displayname) && strlen($displayname) < 3,
|
|
|
|
'passwordRequired' => $room->access === Room::ACCESS_PASSWORD,
|
|
|
|
'wrongPassword' => $password !== $room->password && $password !== '',
|
2020-04-26 12:14:06 +02:00
|
|
|
], '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-06-19 09:28:58 +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-06-04 10:25:51 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
private function getRoom(): ?Room {
|
2020-06-04 10:25:51 +02:00
|
|
|
if ($this->room === null) {
|
|
|
|
$this->room = $this->service->findByUid($this->token);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->room;
|
|
|
|
}
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|