Skip to content
Snippets Groups Projects
Verified Commit b03381e8 authored by Damien's avatar Damien
Browse files

FEAT #11698 TIME 4:00 Jnlp for resource

parent d173b013
No related branches found
No related tags found
No related merge requests found
......@@ -23,14 +23,11 @@ use Respect\Validation\Validator;
use setasign\Fpdi\Tcpdf\Fpdi;
use Slim\Http\Request;
use Slim\Http\Response;
use User\models\UserModel;
class AcknowledgementReceiptController
{
public function createPaperAcknowledgement(Request $request, Response $response)
{
$currentUser = UserModel::getByLogin(['login' => $GLOBALS['userId'], 'select' => ['id']]);
$bodyData = $request->getParsedBody();
if (!Validator::arrayType()->notEmpty()->validate($bodyData['resources'])) {
......
......@@ -17,22 +17,21 @@ namespace ContentManagement\controllers;
use Docserver\models\DocserverModel;
use Slim\Http\Request;
use Slim\Http\Response;
use SrcCore\controllers\UrlController;
use SrcCore\models\CoreConfigModel;
use SrcCore\models\ValidatorModel;
use Template\models\TemplateModel;
require_once 'core/class/Url.php';
class JnlpController
{
public function generateJnlp(Request $request, Response $response)
{
$data = $request->getParams();
$body = $request->getParsedBody();
$coreUrl = str_replace('rest/', '', \Url::coreurl());
$coreUrl = str_replace('rest/', '', UrlController::getCoreUrl());
$tmpPath = CoreConfigModel::getTmpPath();
$jnlpUniqueId = CoreConfigModel::uniqueId();
$jnlpFileName = $GLOBALS['userId'] . '_maarchCM_' . $jnlpUniqueId;
$jnlpFileName = $GLOBALS['id'] . '_maarchCM_' . $jnlpUniqueId;
$jnlpFileNameExt = $jnlpFileName . '.jnlp';
$allCookies = '';
......@@ -42,11 +41,11 @@ class JnlpController
}
$allCookies .= $key . '=' . str_replace(' ', '+', $value);
}
if (!empty($data['cookies'])) {
if (!empty($body['cookies'])) {
if (!empty($allCookies)) {
$allCookies .= '; ';
}
$allCookies .= $data['cookies'];
$allCookies .= $body['cookies'];
}
$loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/content_management/xml/config.xml']);
......@@ -125,17 +124,17 @@ class JnlpController
$tagApplication->appendChild($newAttribute);
$tagArg1 = $jnlpDocument->createElement('argument', $coreUrl . 'rest/jnlp/' . $jnlpUniqueId); //ProcessJnlp
$tagArg2 = $jnlpDocument->createElement('argument', $data['objectType']); //Type
$tagArg3 = $jnlpDocument->createElement('argument', $data['table']); //Table
$tagArg4 = $jnlpDocument->createElement('argument', $data['objectId']); //ObjectId
$tagArg5 = $jnlpDocument->createElement('argument', $data['uniqueId']);
$tagArg2 = $jnlpDocument->createElement('argument', $body['objectType']); //Type
$tagArg3 = $jnlpDocument->createElement('argument', 'table'); //Useless
$tagArg4 = $jnlpDocument->createElement('argument', $body['objectId']); //ObjectId
$tagArg5 = $jnlpDocument->createElement('argument', 0); //Useless
$tagArg6 = $jnlpDocument->createElement('argument', "maarchCourrierAuth={$_COOKIE['maarchCourrierAuth']}"); //MaarchCookie
$tagArg7 = $jnlpDocument->createElement('argument', htmlentities($allCookies)); //AllCookies
$tagArg8 = $jnlpDocument->createElement('argument', $jnlpFileName); //JnlpFileName
$tagArg9 = $jnlpDocument->createElement('argument', $GLOBALS['userId']); //CurrentUser
$tagArg10 = $jnlpDocument->createElement('argument', 'false'); //ConvertPdf
$tagArg11 = $jnlpDocument->createElement('argument', 'false'); //OnlyConvert
$tagArg12 = $jnlpDocument->createElement('argument', 0); //HashFile
$tagArg9 = $jnlpDocument->createElement('argument', $GLOBALS['id']); //CurrentUser
$tagArg10 = $jnlpDocument->createElement('argument', 'false'); //ConvertPdf //Useless
$tagArg11 = $jnlpDocument->createElement('argument', 'false'); //OnlyConvert //Useless
$tagArg12 = $jnlpDocument->createElement('argument', 0); //HashFile //Useless
$tagJnlp->appendChild($tagInformation);
......@@ -197,22 +196,23 @@ class JnlpController
}
public function processJnlp(Request $request, Response $response, array $aArgs)
public function processJnlp(Request $request, Response $response, array $args)
{
$data = $request->getParams();
$body = $request->getParsedBody();
$tmpPath = CoreConfigModel::getTmpPath();
if ($data['action'] == 'editObject') {
if ($data['objectType'] == 'templateCreation') {
$explodeFile = explode('.', $data['objectId']);
if ($body['action'] == 'editObject') {
if ($body['objectType'] == 'templateCreation') {
//TODO passer l'id et pas le chemin dans objectId
$explodeFile = explode('.', $body['objectId']);
$ext = $explodeFile[count($explodeFile) - 1];
$newFileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['jnlpUniqueId']}.{$ext}";
$newFileOnTmp = "tmp_file_{$GLOBALS['id']}_{$args['jnlpUniqueId']}.{$ext}";
$pathToCopy = $data['objectId'];
} elseif ($data['objectType'] == 'templateModification') {
$pathToCopy = $body['objectId'];
} elseif ($body['objectType'] == 'templateModification') {
$docserver = DocserverModel::getCurrentDocserver(['typeId' => 'TEMPLATES', 'collId' => 'templates', 'select' => ['path_template']]);
$template = TemplateModel::getById(['id' => $data['objectId'], 'select' => ['template_path', 'template_file_name']]);
$template = TemplateModel::getById(['id' => $body['objectId'], 'select' => ['template_path', 'template_file_name']]);
if (empty($template)) {
$xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => "Template does not exist"]]);
$response->write($xmlResponse);
......@@ -221,7 +221,27 @@ class JnlpController
$explodeFile = explode('.', $template['template_file_name']);
$ext = $explodeFile[count($explodeFile) - 1];
$newFileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['jnlpUniqueId']}.{$ext}";
$newFileOnTmp = "tmp_file_{$GLOBALS['id']}_{$args['jnlpUniqueId']}.{$ext}";
$pathToCopy = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template['template_path']) . $template['template_file_name'];
} elseif ($body['objectType'] == 'resourceCreation') {
$docserver = DocserverModel::getCurrentDocserver(['typeId' => 'TEMPLATES', 'collId' => 'templates', 'select' => ['path_template']]);
$template = TemplateModel::getById(['id' => $body['objectId'], 'select' => ['template_path', 'template_file_name']]);
if (empty($template)) {
$xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => "Template does not exist"]]);
$response->write($xmlResponse);
return $response->withHeader('Content-Type', 'application/xml');
}
//TODO revoir le merge avec les data
// $mergedDocument = MergeController::mergeDocument([
// 'path' => $pathToDocument,
// 'data' => ['resId' => $aArgs['resId'], 'contactAddressId' => $contactToProcess, 'userId' => $currentUser['id']]
// ]);
$explodeFile = explode('.', $template['template_file_name']);
$ext = $explodeFile[count($explodeFile) - 1];
$newFileOnTmp = "tmp_file_{$GLOBALS['id']}_{$args['jnlpUniqueId']}.{$ext}";
$pathToCopy = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template['template_path']) . $template['template_file_name'];
} else {
......@@ -240,10 +260,10 @@ class JnlpController
$result = [
'STATUS' => 'ok',
'OBJECT_TYPE' => $data['objectType'],
'OBJECT_TABLE' => $data['objectTable'],
'OBJECT_ID' => $data['objectId'],
'UNIQUE_ID' => $data['uniqueId'],
'OBJECT_TYPE' => $body['objectType'],
'OBJECT_TABLE' => $body['objectTable'],
'OBJECT_ID' => $body['objectId'],
'UNIQUE_ID' => $body['uniqueId'],
'APP_PATH' => 'start',
'FILE_CONTENT' => base64_encode($fileContent),
'FILE_EXTENSION' => $ext,
......@@ -252,42 +272,42 @@ class JnlpController
];
$xmlResponse = JnlpController::generateResponse(['type' => 'SUCCESS', 'data' => $result]);
} elseif ($data['action'] == 'saveObject') {
if (empty($data['fileContent']) || empty($data['fileExtension'])) {
} elseif ($body['action'] == 'saveObject') {
if (empty($body['fileContent']) || empty($body['fileExtension'])) {
$xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => 'File content or file extension empty']]);
$response->write($xmlResponse);
return $response->withHeader('Content-Type', 'application/xml');
}
$encodedFileContent = str_replace(' ', '+', $data['fileContent']);
$ext = str_replace(["\\", "/", '..'], '', $data['fileExtension']);
$encodedFileContent = str_replace(' ', '+', $body['fileContent']);
$ext = str_replace(["\\", "/", '..'], '', $body['fileExtension']);
$fileContent = base64_decode($encodedFileContent);
$fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['jnlpUniqueId']}.{$ext}";
$fileOnTmp = "tmp_file_{$GLOBALS['id']}_{$args['jnlpUniqueId']}.{$ext}";
$file = fopen($tmpPath . $fileOnTmp, 'w');
fwrite($file, $fileContent);
fclose($file);
if (!empty($data['step']) && $data['step'] == 'end') {
if (file_exists("{$tmpPath}{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck")) {
unlink("{$tmpPath}{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck");
if (file_exists("{$tmpPath}{$GLOBALS['id']}_maarchCM_{$args['jnlpUniqueId']}.lck")) {
unlink("{$tmpPath}{$GLOBALS['id']}_maarchCM_{$args['jnlpUniqueId']}.lck");
}
}
$xmlResponse = JnlpController::generateResponse(['type' => 'SUCCESS', 'data' => ['END_MESSAGE' => 'Update ok']]);
} elseif ($data['action'] == 'terminate') {
if (file_exists("{$tmpPath}{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck")) {
unlink("{$tmpPath}{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck");
} elseif ($body['action'] == 'terminate') {
if (file_exists("{$tmpPath}{$GLOBALS['id']}_maarchCM_{$args['jnlpUniqueId']}.lck")) {
unlink("{$tmpPath}{$GLOBALS['id']}_maarchCM_{$args['jnlpUniqueId']}.lck");
}
$xmlResponse = JnlpController::generateResponse(['type' => 'SUCCESS', 'data' => ['END_MESSAGE' => 'Terminate ok']]);
} else {
$result = [
'STATUS' => 'ko',
'OBJECT_TYPE' => $data['objectType'],
'OBJECT_TABLE' => $data['objectTable'],
'OBJECT_ID' => $data['objectId'],
'UNIQUE_ID' => $data['uniqueId'],
'OBJECT_TYPE' => $body['objectType'],
'OBJECT_TABLE' => $body['objectTable'],
'OBJECT_ID' => $body['objectId'],
'UNIQUE_ID' => $body['uniqueId'],
'APP_PATH' => 'start',
'FILE_CONTENT' => '',
'FILE_EXTENSION' => '',
......@@ -305,7 +325,7 @@ class JnlpController
public function isLockFileExisting(Request $request, Response $response, array $aArgs)
{
$tmpPath = CoreConfigModel::getTmpPath();
$lockFileName = "{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck";
$lockFileName = "{$GLOBALS['id']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck";
$fileFound = false;
if (file_exists($tmpPath . $lockFileName)) {
......
......@@ -129,7 +129,7 @@ class TemplateController
return $response->withStatus(400)->withJson(['errors' => 'Template style is missing']);
}
$explodeStyle = explode(':', $data['template_style']);
$fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['jnlpUniqueId']}." . strtolower($explodeStyle[0]);
$fileOnTmp = "tmp_file_{$GLOBALS['id']}_{$data['jnlpUniqueId']}." . strtolower($explodeStyle[0]);
} else {
if (empty($data['uploadedFile']['base64']) || empty($data['uploadedFile']['name'])) {
return $response->withStatus(400)->withJson(['errors' => 'Uploaded file is missing']);
......@@ -407,6 +407,7 @@ class TemplateController
return $check;
}
public static function mergeDatasource(array $aArgs)
{
include_once 'apps/maarch_entreprise/tools/tbs/tbs_class_php5.php';
......
......@@ -22,14 +22,12 @@ use SrcCore\models\CoreConfigModel;
use SrcCore\models\ValidatorModel;
use User\models\UserModel;
require_once 'core/class/Url.php';
class CoreController
{
public function initialize(Request $request, Response $response)
{
$aInit = [];
$aInit['coreUrl'] = str_replace('rest/', '', \Url::coreurl());
$aInit['coreUrl'] = str_replace('rest/', '', UrlController::getCoreUrl());
$aInit['applicationName'] = CoreConfigModel::getApplicationName();
$aInit['applicationVersion'] = CoreConfigModel::getApplicationVersion();
$aInit['lang'] = CoreConfigModel::getLanguage();
......
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*/
/**
* @brief Url Controller
* @author dev@maarch.org
*/
namespace SrcCore\controllers;
class UrlController
{
private static function getPath()
{
if (!empty($_SERVER['HTTP_X_FORWARDED_SCRIPT_NAME'])) {
$baseUri = $_SERVER['HTTP_X_FORWARDED_SCRIPT_NAME'];
} else {
$baseUri = $_SERVER['SCRIPT_NAME'];
}
$baseUri = trim(dirname($baseUri), '/');
$baseUri = str_replace('rest', '', $baseUri);
return '/'.$baseUri;
}
private static function getHost()
{
if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
return $_SERVER['HTTP_X_FORWARDED_HOST'];
}
$rawHost = explode(':',$_SERVER['HTTP_HOST']);
return $rawHost[0];
}
private static function getPort()
{
if (!empty($_SERVER['HTTP_X_FORWARDED_PORT'])) {
return $_SERVER['HTTP_X_FORWARDED_PORT'];
}
return $_SERVER['SERVER_PORT'];
}
private static function getProto()
{
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
return $_SERVER['HTTP_X_FORWARDED_PROTO'];
}
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
return 'https';
}
return 'http';
}
public static function getCoreUrl()
{
$url = UrlController::getProto();
$url .= '://';
$url .= UrlController::getHost();
$port = UrlController::getPort();
if ($port != 80 && $port != 443) {
$url .= ':';
$url .= $port;
}
$url .= UrlController::getPath();
return $url;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment