diff --git a/core/class/class_functions.php b/core/class/class_functions.php index 509fee12debc6ad5fa17bdf4fd52778a0fad4514..ba6253ac958a56a846faa42cd4e872092bc76450 100755 --- a/core/class/class_functions.php +++ b/core/class/class_functions.php @@ -707,7 +707,8 @@ class functions public function return_bytes($val) { $val = trim($val); - $last = strtolower($val{strlen($val)-1}); + $strlen = strlen($val)-1; + $last = strtolower($val.$strlen); switch($last) { // 'G' modifier available since PHP 5.1.0 case 'g': diff --git a/rest/index.php b/rest/index.php index 369be2a6f29b8873dc571bd4b6654f8260050ac7..46717cff6912d02b83513e7b6d3c51510c51f58c 100755 --- a/rest/index.php +++ b/rest/index.php @@ -145,9 +145,6 @@ $app->post('/convertedFile', \Convert\controllers\ConvertPdfController::class . $app->get('/convertedFile/{filename}', \Convert\controllers\ConvertPdfController::class . ':getConvertedFileByFilename'); //ContentManagement -$app->post('/onlyOfficeCallback', function (\Slim\Http\Request $request, \Slim\Http\Response $response) { - return $response->withJson(['error' => 0]); -}); $app->post('/jnlp', \ContentManagement\controllers\JnlpController::class . ':generateJnlp'); $app->get('/jnlp/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':renderJnlp'); $app->post('/jnlp/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':processJnlp'); @@ -157,6 +154,10 @@ $app->get('/onlyOffice/configuration', \ContentManagement\controllers\OnlyOffice $app->post('/onlyOffice/mergedFile', \ContentManagement\controllers\OnlyOfficeController::class . ':saveMergedFile'); $app->get('/onlyOffice/mergedFile', \ContentManagement\controllers\OnlyOfficeController::class . ':getMergedFile'); $app->get('/onlyOffice/encodedFile', \ContentManagement\controllers\OnlyOfficeController::class . ':getEncodedFileFromUrl'); +$app->get('/onlyOffice/available', \ContentManagement\controllers\OnlyOfficeController::class . ':isAvailable'); +$app->post('/onlyOfficeCallback', function (\Slim\Http\Request $request, \Slim\Http\Response $response) { + return $response->withJson(['error' => 0]); +}); //CustomFields $app->get('/customFields', \CustomField\controllers\CustomFieldController::class . ':get'); diff --git a/src/app/contentManagement/controllers/OnlyOfficeController.php b/src/app/contentManagement/controllers/OnlyOfficeController.php index 6115d1b694d5fc2d6a0a25f9185d0327a9035797..3b8c915851b66975f34f4a94c91a284fcab7ad49 100644 --- a/src/app/contentManagement/controllers/OnlyOfficeController.php +++ b/src/app/contentManagement/controllers/OnlyOfficeController.php @@ -164,4 +164,20 @@ class OnlyOfficeController return $response->withJson(['encodedFile' => base64_encode($fileContent)]); } + + public static function isAvailable(Request $request, Response $response) + { + $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/documentEditorsConfig.xml']); + if (empty($loadedXml) || empty($loadedXml->onlyoffice->enabled) || $loadedXml->onlyoffice->enabled == 'false' || empty($loadedXml->onlyoffice->server_uri)) { + return $response->withStatus(400)->withJson(['errors' => 'Onlyoffice is not enabled']); + } + + $uri = (string)$loadedXml->onlyoffice->server_uri; + + $exec = shell_exec("ping -c 1 -w 5 {$uri}"); + + $isAvailable = strpos($exec, '1 packets transmitted, 1 received') !== false; + + return $response->withJson(['isAvailable' => $isAvailable]); + } }