2020-05-17 11:09:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\BigBlueButton\Controller;
|
|
|
|
|
|
|
|
use OCA\BigBlueButton\BigBlueButton\API;
|
2020-06-17 10:56:28 +02:00
|
|
|
use OCA\BigBlueButton\Permission;
|
2020-05-17 11:09:16 +02:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
|
|
|
|
use OCA\BigBlueButton\Service\RoomService;
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
class ServerController extends Controller {
|
2020-05-17 11:09:16 +02:00
|
|
|
/** @var RoomService */
|
|
|
|
private $service;
|
|
|
|
|
|
|
|
/** @var API */
|
|
|
|
private $server;
|
|
|
|
|
2020-06-17 10:56:28 +02:00
|
|
|
/** @var Permission */
|
|
|
|
private $permission;
|
|
|
|
|
2020-05-17 11:09:16 +02:00
|
|
|
/** @var string */
|
|
|
|
private $userId;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
$appName,
|
|
|
|
IRequest $request,
|
|
|
|
RoomService $service,
|
|
|
|
API $server,
|
2020-06-17 10:56:28 +02:00
|
|
|
Permission $permission,
|
2020-05-17 11:09:16 +02:00
|
|
|
$UserId
|
|
|
|
) {
|
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
|
|
|
$this->service = $service;
|
|
|
|
$this->server = $server;
|
2020-06-17 10:56:28 +02:00
|
|
|
$this->permission = $permission;
|
2020-05-17 11:09:16 +02:00
|
|
|
$this->userId = $UserId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-19 09:28:58 +02:00
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function records(string $roomUid): DataResponse {
|
2020-05-17 11:09:16 +02:00
|
|
|
$room = $this->service->findByUid($roomUid);
|
|
|
|
|
|
|
|
if ($room === null) {
|
|
|
|
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
2020-06-17 10:56:28 +02:00
|
|
|
if (!$this->permission->isAdmin($room, $this->userId)) {
|
2020-05-17 11:09:16 +02:00
|
|
|
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
$recordings = $this->server->getRecordings($room);
|
|
|
|
|
|
|
|
return new DataResponse($recordings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-19 09:28:58 +02:00
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function deleteRecord(string $recordId): DataResponse {
|
2020-05-17 11:09:16 +02:00
|
|
|
$record = $this->server->getRecording($recordId);
|
|
|
|
|
|
|
|
$room = $this->service->findByUid($record['metas']['meetingId']);
|
|
|
|
|
|
|
|
if ($room === null) {
|
|
|
|
return new DataResponse(false, Http::STATUS_NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
2020-06-17 10:56:28 +02:00
|
|
|
if (!$this->permission->isAdmin($room, $this->userId)) {
|
2020-05-17 11:09:16 +02:00
|
|
|
return new DataResponse(false, Http::STATUS_FORBIDDEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
$success = $this->server->deleteRecording($recordId);
|
|
|
|
|
|
|
|
return new DataResponse($success);
|
|
|
|
}
|
2020-05-17 13:39:01 +02:00
|
|
|
|
2020-06-19 10:49:40 +02:00
|
|
|
public function check(?string $url, ?string $secret) {
|
2020-05-17 13:39:01 +02:00
|
|
|
if ($url === null || empty($url) || $secret === null || empty($secret)) {
|
|
|
|
return new DataResponse(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new DataResponse($this->server->check($url, $secret));
|
|
|
|
}
|
|
|
|
|
2020-06-19 10:49:40 +02:00
|
|
|
public function version(?string $url) {
|
2020-05-17 13:39:01 +02:00
|
|
|
if ($url === null || empty($url)) {
|
|
|
|
return new DataResponse(false, Http::STATUS_NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$version = $this->server->getVersion($url);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return new DataResponse(false, Http::STATUS_NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new DataResponse($version);
|
|
|
|
}
|
2020-05-17 11:09:16 +02:00
|
|
|
}
|