Commit 187eb378 authored by Carsten  Rose's avatar Carsten Rose
Browse files

WIP #F10715 - a first version wihth " 'd|s:1|t:qfqpdf:...

WIP #F10715 - a first version wihth " 'd|s:1|t:qfqpdf: JES|u:jes.math.uzh.ch/?--scale=0.5|M:qfqpdf' AS _link" works
parent 05e52e3e
Pipeline #6542 failed with stages
in 2 minutes and 14 seconds
......@@ -1681,6 +1681,7 @@ const FORM_LOG_ACTIVE = 'formLogActive';
const DOWNLOAD_MODE = 'mode';
const DOWNLOAD_MODE_FILE = 'file';
const DOWNLOAD_MODE_PDF = 'pdf';
const DOWNLOAD_MODE_QFQPDF = 'qfqpdf';
const DOWNLOAD_MODE_SAVE_PDF = 'save-pdf';
const DOWNLOAD_MODE_EXCEL = 'excel';
const DOWNLOAD_MODE_ZIP = 'zip';
......
......@@ -20,6 +20,11 @@ class SessionCookie {
*/
private $pathFileNameCookie = '';
/**
* @var array
*/
private $arrCookieString = array();
/**
* @var bool
*/
......@@ -55,11 +60,10 @@ class SessionCookie {
foreach ($_COOKIE as $key => $value) {
$data[] = ['name' => $key, 'value' => $value, 'url' => $domain, 'path' => $path];
$this->arrCookieString[] = "name:$key,value:$value,url:$domain,path:$path";
}
$data = json_encode(['cookies' => $data]);
file_put_contents($this->pathFileNameCookie, $data, FILE_APPEND);
file_put_contents($this->pathFileNameCookie, json_encode(['cookies' => $data]), FILE_APPEND);
}
/**
......@@ -84,4 +88,13 @@ class SessionCookie {
return $this->pathFileNameCookie;
}
/**
* Returns a string, with optional several cookies, separeted by space
* Example: '"name:firstCookie,value:tunjngvnjfr23r" "name:secondCookie,value:249ur4jn233d"'
* @return string
*/
public function getCookieQfqPdf() {
return '"' . implode('" "', $this->arrCookieString) . '"';
}
}
\ No newline at end of file
......@@ -457,7 +457,7 @@ class Download {
HelperFile::cleanTempFiles([$tmpFilename]);
} else {
$filename = $this->html2pdf->page2pdf($token, $value);
$filename = $this->html2pdf->page2pdf($token, $value, $downloadMode);
}
}
break;
......@@ -671,6 +671,7 @@ class Download {
break;
case DOWNLOAD_MODE_PDF:
case DOWNLOAD_MODE_QFQPDF:
$filename = $this->concatFilesToPdf($srcFiles, $filesCleanLater);
......
......@@ -131,7 +131,7 @@ class Html2Pdf {
* @throws \UserFormException
* @throws \exception
*/
public function page2pdf($token, $url) {
public function page2pdf($token, $url, $downloadMode = DOWNLOAD_MODE_PDF) {
$rcArgs = array();
$urlParamString = '';
$host = '';
......@@ -153,6 +153,8 @@ class Html2Pdf {
}
$rcSipEncode = false;
// Sets view port too
$urlParam = OnString::splitParam($urlParamString, $rcArgs, $rcSipEncode);
$rcArgs = OnArray::arrayEscapeshellarg($rcArgs);
......@@ -170,30 +172,38 @@ class Html2Pdf {
}
$urlPrint = escapeshellarg($url);
$wkhtmlToPdf = $this->config[SYSTEM_CMD_WKHTMLTOPDF];
$qfqPdf = $this->config[SYSTEM_CMD_QFQPDF];
$filename = HelperFile::tempnam();
$filenameEscape = escapeshellarg($filename);
$cookieOptions = '--cookie-jar ' . escapeshellarg($this->sessionCookie->getFile());
$customHeader = '--custom-header User-Agent ' . escapeshellarg($_SERVER['HTTP_USER_AGENT'] ?? '') . ' --custom-header-propagation'; // By default 'Typo3' expects the same User-Agent for the FE-Session
switch ($downloadMode) {
case DOWNLOAD_MODE_PDF:
$cookieOptions = '--cookie-jar ' . escapeshellarg($this->sessionCookie->getFile());
$customHeader = '--custom-header User-Agent ' . escapeshellarg($_SERVER['HTTP_USER_AGENT'] ?? '') . ' --custom-header-propagation'; // By default 'Typo3' expects the same User-Agent for the FE-Session
$cmd = $this->config[SYSTEM_CMD_WKHTMLTOPDF] . " $customHeader $cookieOptions $options $urlPrint $filenameEscape";
break;
case DOWNLOAD_MODE_QFQPDF:
// /opt/qfqpdf/qfqpdf "https://www.math.uzh.ch" fileadmin/outputNew.pdf --page-size A5 --margin-top 22mm --template-header "<h1>Test</h1>" -Fb -c "name:firstCookie,value:tunjngvnjfr23r" "name:secondCookie,value:249ur4jn233d"'
$customHeader = '';
$options .= ' -b';
$cookieOptions = '--cookies ' . escapeshellarg($this->sessionCookie->getCookieQfqPdf());
// qfqpdf
$customHeader = '';
// $cookieOptions = '--cookies-inline ' . ) ;
$cookieOptions = '--cookie-file ' . escapeshellarg($this->sessionCookie->getFile());
$options = '';
$cookieOptions = '';
// Very important: The current lock on session SESSION_NAME has to be freed, cause wkhtmltopdf will use the same
// session in a few moments and this script remains active during that time and that would cause a deadlock else.
$this->session->close();
// $cmd = "$wkhtmlToPdf $customHeader $cookieOptions $options $urlPrint $filenameEscape";
$cmd = "$qfqPdf $customHeader $cookieOptions $options $urlPrint $filenameEscape";
$cmd = $this->config[SYSTEM_CMD_QFQPDF] . " $urlPrint $filenameEscape $customHeader $cookieOptions $options";
break;
default:
throw new \exception("Unknown Download mode: $downloadMode", ERROR_UNKNOWN_MODE);
}
if ($this->logFilePathAbsolute != '') {
Logger::logMessage("Html2Pdf: $cmd", $this->logFilePathAbsolute);
}
// Very important: The current lock on session SESSION_NAME has to be freed, cause wkhtmltopdf will use the same
// session in a few moments and this script remains active during that time and that would cause a deadlock else.
$this->session->close();
$rc = 0;
$line = system($cmd, $rc);
......
......@@ -1026,6 +1026,7 @@ class Link {
// Do some checks.
switch ($mode) {
case DOWNLOAD_MODE_PDF:
case DOWNLOAD_MODE_QFQPDF:
case DOWNLOAD_MODE_SAVE_PDF:
case DOWNLOAD_MODE_ZIP:
case DOWNLOAD_MODE_EXCEL:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment