Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/9.1' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/9.1
  • Loading branch information
metaventis-build committed Dec 9, 2024
2 parents 58adc0c + da6eceb commit 8a7d323
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ rendering_video_default_resolution="${SERVICES_RENDERING_VIDEO_DEFAULT_RESOLUTIO
rendering_video_timeout="${SERVICES_RENDERING_VIDEO_TIMEOUT:-"3600"}"
rendering_video_threads="${SERVICES_RENDERING_VIDEO_THREADS:-"1"}"
rendering_h5p_disable_cache_delay="${SERVICES_RENDERING_H5P_DISABLE_CACHE_DELAY:-0}"
rendering_session_cookie_settings="${SERVICES_RENDERING_SESSION_COOKIE_SETTINGS:-"Path=/; SameSite=Lax;"}"



Expand Down Expand Up @@ -281,6 +282,9 @@ systemConf="${RS_ROOT}/conf/system.conf.php"
sed -i -r 's|\$H5P_DISABLE_CACHE_DELAY = .*|\$H5P_DISABLE_CACHE_DELAY = '"${rendering_h5p_disable_cache_delay}"';|' "${systemConf}"
grep -q '$H5P_DISABLE_CACHE_DELAY' || echo '$H5P_DISABLE_CACHE_DELAY = '"${rendering_h5p_disable_cache_delay}"';' >> "${systemConf}"

sed -i -r 's|\$SESSION_COOKIE_SETTINGS = .*|\$SESSION_COOKIE_SETTINGS = '"'${rendering_session_cookie_settings}'"';|' "${systemConf}"
grep -q '$SESSION_COOKIE_SETTINGS' || echo '$SESSION_COOKIE_SETTINGS = '"'${rendering_session_cookie_settings}'"';' >> "${systemConf}"

sed -i -r 's|\$MC_URL = ['"'"'"].*|\$MC_URL = '"'${my_external_url}'"';|' "${systemConf}"
sed -i -r 's|\$MC_DOCROOT.*|\$MC_DOCROOT = "'"${RS_ROOT}"'";|' "${systemConf}"
sed -i -r 's|\$CC_RENDER_PATH.*|\$CC_RENDER_PATH = "'"${RS_CACHE}/data"'";|' "${systemConf}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ services:
SERVICES_RENDERING_VIDEO_TIMEOUT: "${SERVICES_RENDERING_VIDEO_TIMEOUT:-3600}"
SERVICES_RENDERING_VIDEO_THREADS: "${SERVICES_RENDERING_VIDEO_THREADS:-1}"
SERVICES_RENDERING_H5P_DISABLE_CACHE_DELAY: "${SERVICES_RENDERING_H5P_DISABLE_CACHE_DELAY:-0}"
SERVICES_RENDERING_SESSION_COOKIE_SETTINGS: "${SERVICES_RENDERING_SESSION_COOKIE_SETTINGS:-Path=/; SameSite=Lax;}"
REPOSITORY_SERVICE_HOST: repository-service
REPOSITORY_SERVICE_PORT: "8080"
expose:
Expand Down
1 change: 1 addition & 0 deletions deploy/docker/helm/service/src/main/chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
| `config.rendermoodle.token` | Set token for moodle renderer | `""` |
| `config.rendermoodle.categoryId` | Set categoryId for moodle renderer | `1` |
| `config.h5p.disableCacheDelay` | Set delay in seconds that the h5p will be re-generated | `0` |
| `config.session.cookieSettings` | Set session cookie settings | `""` |
| `persistence.share.config.create` | Create persistent share | `true` |
| `persistence.share.config.type` | Set volume type of config share | `persistentVolumeClaim:
claimName: {{ include "edusharing_services_rendering.pvc.share.config" . }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ data:
SERVICES_RENDERING_VIDEO_THREADS: {{ .Values.config.converter.video.threads | quote }}
SERVICES_RENDERING_VIDEO_TIMEOUT: {{ .Values.config.converter.video.timeout | quote }}
SERVICES_RENDERING_H5P_DISABLE_CACHE_DELAY: {{ .Values.config.h5p.disableCacheDelay | quote }}
SERVICES_RENDERING_SESSION_COOKIE_SETTINGS: {{ .Values.config.session.cookieSettings | quote }}
4 changes: 4 additions & 0 deletions deploy/docker/helm/service/src/main/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ config:
## @param config.h5p.disableCacheDelay Set delay in seconds that the h5p will be re-generated
disableCacheDelay: 0

session:
## @param config.session.cookieSettings Set session cookie settings
cookieSettings: ""

########################################################################################################################

persistence:
Expand Down
2 changes: 2 additions & 0 deletions service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
</executions>
</plugin>

<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand All @@ -94,6 +95,7 @@
</execution>
</executions>
</plugin>
-->

<plugin>
<groupId>uk.co.codezen</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
$ROOT_PATH = current(explode("conf", dirname(__FILE__)));
$ROOT_URI = $MC_URL . '/';
$H5P_DISABLE_CACHE_DELAY = 0;
$SESSION_COOKIE_SETTINGS = "";
3 changes: 2 additions & 1 deletion service/src/main/php/application/esmain/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


// init translate
global $Translate, $LanguageCode;
global $Translate, $LanguageCode, $SESSION_COOKIE_SETTINGS;
$Translate = new Phools_Translate_Array();

// LANGUAGE
Expand Down Expand Up @@ -70,6 +70,7 @@
if (!session_start()) {
throw new Exception('Could not start session.');
}
header("Set-Cookie: $ESRENDER_SESSION_NAME=$sessid; $SESSION_COOKIE_SETTINGS");

$esrenderSessionId = session_id();
if (!$esrenderSessionId) {
Expand Down
121 changes: 121 additions & 0 deletions service/src/main/php/func/classes.new/ESRender/Plugin/Sodix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

require_once(dirname(__FILE__) . '/../../../../vendor/autoload.php');

use GuzzleHttp\RequestOptions;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\Psr7;

class ESRender_Plugin_Sodix extends ESRender_Plugin_Abstract
{
protected String $url;
protected String $user;
protected String $password;

public function __construct(array $properties = [
"url" => "",
"user" => "",
"password" => ""
]) {
parent::__construct($properties);
}

public function postRetrieveObjectProperties(&$data): void {
$esObject = new ESObject($data);
$logger = $this->getLogger();
if ($esObject->getNodeProperty('ccm:replicationsource') !== 'SODIX') {
return;
}
if (empty($esObject->getNodeProperty('ccm:replicationsourceid'))) {
$logger->error("No SODIX ID found for");
}
$isPayedMedia = $esObject->getNodeProperty('ccm:editorial_state') === 'restricted_mz';
$logger->info("Started communication with SODIX API for node" . ($isPayedMedia ? ' (payed media)' : ''));
$repId = $esObject->getNodeProperty('ccm:replicationsourceid');
$token = $this->getToken();
if (empty($token)) {
$logger->error("Token could not be retrieved, aborting");
return;
}
$logger->info("Successfully retrieved token.");
if (!$isPayedMedia) {
$body = [
"operationName" => "getPlayoutWindow",
"query" => "query getPlayoutWindow { getPlayoutWindow(mediaId: \"$repId\") { playoutUrl } }"
];
} else {
$body = [
"operationName" => "paidMediaLinks",
"query" => "query paidMediaLinks { paidMediaLinks(id: \"$repId\") { links { href linkType } } }"
];
}
$response = $this->getGraphQL($token, $body);
if (empty($response)) {
return;
}
$this->handlePlayOut($response, $data, $isPayedMedia);
}

private function getToken(): String {
$logger = $this->getLogger();
$uri = substr($this->url, 0, -8) . '/auth/login';
$client = GuzzleHelper::getClient();
try {
$result = $client->post($uri, [
GuzzleHttp\RequestOptions::JSON =>["login" => $this->user, "password" => $this->password],
'http_errors' => true
]);
} catch (GuzzleHttp\Exception\ClientException | GuzzleHttp\Exception\TransferException $exception) {
$logger->error(GuzzleHttp\Psr7\Message::toString($exception->getResponse()));
return "";
}

return json_decode($result->getBody(), true)["access_token"] ?? "";
}

private function getGraphQL(String $token, array $body): array {
$logger = $this->getLogger();
$client = GuzzleHelper::getClient();
try {
$result = $client->post($this->url, [
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/json'
],
GuzzleHttp\RequestOptions::JSON => $body,
'http_errors' => true
]);
} catch (GuzzleHttp\Exception\ClientException | GuzzleHttp\Exception\TransferException $exception) {
$logger->error(GuzzleHttp\Psr7\Message::toString($exception->getResponse()));
return [];
}

return json_decode($result->getBody(), true);
}

private function handlePlayOut(array $response, &$data, bool $isPayedMedia): void {
$logger = $this->getLogger();
if ($response["errors"][0]["extensions"]["classification"] ?? "" === "DataFetchingException") {
$logger->error("SODIX content contains errors. Url could not be found or retrieved.");
return;
}
if ($isPayedMedia) {
$playOutLinkEntry = array_filter($response['data']['paidMediaLinks']['links'] ?? [], fn($link) => $link['linkType'] === 'direct');
$playOutUrl = reset($playOutLinkEntry)['href'] ?? '';
$downloadLinkEntry = array_filter($response['data']['paidMediaLinks']['links'] ?? [], fn($link) => $link['linkType'] === 'download');
if (!empty($downloadLinkEntry)) {
Config::set('downloadUrl', reset($downloadLinkEntry)['href'] ?? '');
}
} else {
$playOutUrl = $response["data"]["getPlayoutWindow"]["playoutUrl"] ?? "";
}
if (empty($playOutUrl)) {
$logger->error("SODIX response does not contain expected url: " . json_encode($response));
}
$logger->info("SODIX url successfully retrieved.");
$data->node->properties->{'ccm:wwwurl'} = $playOutUrl;
$unique = uniqid();
Config::set('urlEmbedding', '<iframe id="'.$unique.'" src="'. $playOutUrl . '" width="100%" height="800" border="0"></iframe>');
}
}
3 changes: 3 additions & 0 deletions service/src/main/php/modules/redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
set_time_limit(0);
include_once ('../conf.inc.php');

global $SESSION_COOKIE_SETTINGS, $MC_DOCROOT, $MC_DOCROOT, $MC_URL, $CC_RENDER_PATH;

$skipToken = false;
$logCacheRead = false;

Expand Down Expand Up @@ -140,6 +142,7 @@ function sendFile($src_file) {
session_name($ESRENDER_SESSION_NAME);
session_id($l_sid);
session_start();
header("Set-Cookie: $ESRENDER_SESSION_NAME=$l_sid; $SESSION_COOKIE_SETTINGS");

if (empty($_SESSION['esrender'])) {
error_log('Missing "esrender"-session-data.');
Expand Down
3 changes: 3 additions & 0 deletions service/src/main/php/vendor/js/ViewerJS/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require_once '../../../conf.inc.php';

global $SESSION_COOKIE_SETTINGS;

// start session
if (empty($ESRENDER_SESSION_NAME)) {
error_log('ESRENDER_SESSION_NAME not set in conf/system.conf.php');
Expand All @@ -18,6 +20,7 @@
if (!session_start()) {
throw new Exception('Could not start session.');
}
header("Set-Cookie: $ESRENDER_SESSION_NAME=$sessid; $SESSION_COOKIE_SETTINGS");

$esrenderSessionId = session_id();
if (!$esrenderSessionId) {
Expand Down
6 changes: 3 additions & 3 deletions service/src/main/php/vendor/js/metadataToggler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ if (typeof window.toggleMetadataListener === 'undefined') {
// Case 1: toggle button was clicked -> show/hide the respective node's metadata div
if (event.target.classList.contains("edusharing_metadata_toggle_button")) {
const metadataNode = event.target.parentNode.querySelector(".edusharing_metadata")
metadataNode.style.display = metadataNode.style.display === 'none' ? '' : 'none';
metadataNode.classList.toggle("edusharing_metadata_inline")
// Case 2: Outside click -> Close all metadata divs
} else if (event.target.closest(".edusharing_metadata") === null) {
const allMetadataNodes = document.querySelectorAll(".edusharing_metadata")
allMetadataNodes.forEach(node => node.style.display = 'none')
allMetadataNodes.forEach(node => node.classList.toggle("edusharing_metadata_inline"))
}
}
document.addEventListener('click', window.toggleMetadataListener)
}
}
3 changes: 2 additions & 1 deletion service/src/main/php/vendor/js/pdfJS/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once '../../../conf.inc.php';

global $MC_URL, $CC_RENDER_PATH;
global $MC_URL, $CC_RENDER_PATH, $SESSION_COOKIE_SETTINGS;

// start session
if (empty($ESRENDER_SESSION_NAME)) {
Expand All @@ -21,6 +21,7 @@
if (!session_start()) {
throw new Exception('Could not start session.');
}
header("Set-Cookie: $ESRENDER_SESSION_NAME=$sessid; $SESSION_COOKIE_SETTINGS");
$esrenderSessionId = session_id();
if (!$esrenderSessionId) {
throw new Exception('Could not get current session_id().');
Expand Down
3 changes: 2 additions & 1 deletion service/src/main/php/vendor/js/pdfJS/web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once '../../../../conf.inc.php';

global $MC_URL;
global $MC_URL, $SESSION_COOKIE_SETTINGS;

// start session
if (empty($ESRENDER_SESSION_NAME)) {
Expand All @@ -23,6 +23,7 @@
if (!session_start()) {
throw new Exception('Could not start session.');
}
header("Set-Cookie: $ESRENDER_SESSION_NAME=$sessid; $SESSION_COOKIE_SETTINGS");

$esrenderSessionId = session_id();
if (!$esrenderSessionId) {
Expand Down

0 comments on commit 8a7d323

Please sign in to comment.