diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php index f41a5d4ca835106e93a6f8588f72c3c269502258..44a444f7e3b45c27dc318550f7a923ad75425e8b 100755 --- a/src/app/attachment/controllers/AttachmentController.php +++ b/src/app/attachment/controllers/AttachmentController.php @@ -33,6 +33,7 @@ use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; use SrcCore\controllers\CoreController; +use SrcCore\controllers\UrlController; use SrcCore\models\CoreConfigModel; use SrcCore\models\ValidatorModel; use User\models\UserModel; @@ -831,7 +832,9 @@ class AttachmentController } $customId = CoreConfigModel::getCustomId(); $customId = empty($customId) ? 'null' : $customId; - exec("php src/app/convert/scripts/ConvertPdfScript.php --customId {$customId} --resId {$id} --type attachment --userId {$GLOBALS['id']} > /dev/null &"); + $coreUrl = str_replace('rest/', '', UrlController::getCoreUrl()); + + exec("php src/app/convert/scripts/ConvertPdfScript.php --customId {$customId} --resId {$id} --type attachment --userId {$GLOBALS['id']} --coreUrl {$coreUrl} > /dev/null &"); } } diff --git a/src/app/contentManagement/controllers/OnlyOfficeController.php b/src/app/contentManagement/controllers/OnlyOfficeController.php index 23f1e7bea0d749da4273e515a7d1898f09dcf094..71f82a4cbbb27b959034bcac4d2bacbef0188a7c 100644 --- a/src/app/contentManagement/controllers/OnlyOfficeController.php +++ b/src/app/contentManagement/controllers/OnlyOfficeController.php @@ -28,6 +28,7 @@ use SrcCore\controllers\CoreController; use SrcCore\controllers\UrlController; use SrcCore\models\CoreConfigModel; use SrcCore\models\CurlModel; +use SrcCore\models\ValidatorModel; use Template\models\TemplateModel; class OnlyOfficeController @@ -298,8 +299,11 @@ class OnlyOfficeController return $response->withJson(['isAvailable' => $isAvailable]); } - public static function canConvert() + public static function canConvert(array $args) { + ValidatorModel::notEmpty($args, ['url']); + ValidatorModel::stringType($args, ['url']); + $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/documentEditorsConfig.xml']); if (empty($loadedXml) || empty($loadedXml->onlyoffice->enabled) || $loadedXml->onlyoffice->enabled == 'false') { return false; @@ -322,12 +326,7 @@ class OnlyOfficeController return false; } - $file = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/config.json']); - if (empty($file['config']['maarchUrl'])) { - return false; - } - - if (strpos($file['config']['maarchUrl'], 'localhost') !== false || strpos($file['config']['maarchUrl'], '127.0.0.1') !== false ) { + if (strpos($args['url'], 'localhost') !== false || strpos($args['url'], '127.0.0.1') !== false ) { return false; } @@ -336,6 +335,10 @@ class OnlyOfficeController public static function convert(array $args) { + ValidatorModel::notEmpty($args, ['url', 'fullFilename', 'userId']); + ValidatorModel::stringType($args, ['url', 'fullFilename']); + ValidatorModel::intVal($args, ['userId']); + $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/documentEditorsConfig.xml']); if (empty($loadedXml) || empty($loadedXml->onlyoffice->enabled) || $loadedXml->onlyoffice->enabled == 'false') { return ['errors' => 'Onlyoffice is not enabled', 'lang' => 'onlyOfficeNotEnabled']; @@ -352,18 +355,13 @@ class OnlyOfficeController $docInfo = pathinfo($args['fullFilename']); $payload = [ - 'userId' => $GLOBALS['id'], + 'userId' => $args['userId'], 'fullFilename' => $args['fullFilename'] ]; $jwt = JWT::encode($payload, CoreConfigModel::getEncryptKey()); - $file = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/config.json']); - if (empty($file['config']['maarchUrl'])) { - return ['errors' => 'Cannot convert with OnlyOffice : maarchUrl not set in config.json']; - } - $coreUrl = $file['config']['maarchUrl']; - $docUrl = $coreUrl . 'rest/onlyOffice/content?token=' . $jwt; + $docUrl = $args['url'] . 'rest/onlyOffice/content?token=' . $jwt; $response = CurlModel::execSimple([ 'url' => $uri . ':' . $port . '/ConvertService.ashx', diff --git a/src/app/convert/controllers/ConvertPdfController.php b/src/app/convert/controllers/ConvertPdfController.php index 663ebf862c3cec4f90566656516e49f9af2a2473..3ebf29da937f948ae907c06f10cc1143827a707a 100755 --- a/src/app/convert/controllers/ConvertPdfController.php +++ b/src/app/convert/controllers/ConvertPdfController.php @@ -25,6 +25,7 @@ use Resource\models\ResModel; use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; +use SrcCore\controllers\UrlController; use SrcCore\models\CoreConfigModel; use SrcCore\models\ValidatorModel; @@ -40,8 +41,9 @@ class ConvertPdfController exec('export DISPLAY=:0 && '.$command.' 2>&1', $output, $return); } else { - if (OnlyOfficeController::canConvert()) { - $converted = OnlyOfficeController::convert(['fullFilename' => $aArgs['fullFilename']]); + $url = str_replace('rest/', '', UrlController::getCoreUrl()); + if (OnlyOfficeController::canConvert(['url' => $url])) { + $converted = OnlyOfficeController::convert(['fullFilename' => $aArgs['fullFilename'], 'url' => $url, 'userId' => $GLOBALS['id']]); if (empty($converted['errors'])) { return ['output' => [], 'return' => 0]; } diff --git a/src/app/convert/scripts/ConvertPdfScript.php b/src/app/convert/scripts/ConvertPdfScript.php index f30921d6d67d997cc4d70209e4d6b474a6e66fcd..8c62ca30d94368be16939a5ac844b2c11bd2c375 100644 --- a/src/app/convert/scripts/ConvertPdfScript.php +++ b/src/app/convert/scripts/ConvertPdfScript.php @@ -52,13 +52,17 @@ class ConvertPdfScript if ($cmd > 0) { $userId = $args[$cmd+1]; } + $cmd = array_search('--coreUrl', $args); + if ($cmd > 0) { + $coreUrl = $args[$cmd+1]; + } if (empty($resId) || empty($type) || empty($userId)) { echo 'Missing arguments'; exit(); } - return ['customId' => $customId, 'resId' => $resId, 'type' => $type, 'userId' => $userId]; + return ['customId' => $customId, 'resId' => $resId, 'type' => $type, 'userId' => $userId, 'coreUrl' => $coreUrl]; } public static function convert(array $args) @@ -103,11 +107,11 @@ class ConvertPdfScript $fullFilename = "{$tmpPath}{$fileNameOnTmp}.{$docInfo['extension']}"; $converted = false; $output = []; - if (OnlyOfficeController::canConvert()) { - $converted = OnlyOfficeController::convert(['fullFilename' => $fullFilename]); + if (OnlyOfficeController::canConvert(['url' => $args['coreUrl']])) { + $converted = OnlyOfficeController::convert(['fullFilename' => $fullFilename, 'url' => $args['coreUrl'], 'userId' => $args['userId']]); $converted = empty($converted['errors']); } - if (!$converted){ + if (!$converted) { ConvertPdfController::addBom($fullFilename); $command = "timeout 30 unoconv -f pdf " . escapeshellarg($fullFilename); exec('export HOME=' . $tmpPath . ' && '.$command, $output, $return);