Commit 0fb64250 authored by Carsten  Rose's avatar Carsten Rose
Browse files

#3751 / download FE_GROUP protected pages failed

Implement additional 'SHOW_DEBUG_INFO = download' to track down problems with 'session forwarding'.
Configure constants for SHOW_DEBUG_INFO for yes|no|auto
parent 44b9b4c3
......@@ -101,6 +101,8 @@ will be *lowered*! Again, this is only needed if `wkhtml` needs access to FE_GRO
alternative to lower the security level, create a separated page subtree which is only accessible (configured via
Typosript) from specific IPs **or** if a FE-User is logged in.
If there are problems with converting/downloading FE_GROUP protected pages, check `SHOW_DEBUG_INFO = download` to debug.
HTML to PDF conversion
''''''''''''''''''''''
......@@ -236,8 +238,8 @@ config.qfq.ini
| SQL_LOG_MODE | SQL_LOG_MODE=modify | *all*: every statement will be logged - this is a lot |
| | | *modify*: log only statements who change data |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| SHOW_DEBUG_INFO | SHOW_DEBUG_INFO=auto | Possible values: auto|yes|no. For 'auto': If a BE User is logged in, |
| | | debug information will be shown on the fronend. |
| SHOW_DEBUG_INFO | SHOW_DEBUG_INFO=auto | Possible values: yes|no|auto|download. For 'auto': If a BE User is logged |
| | | in, a debug information will be shown on the fronend. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| REDIRECT_ALL_MAIL_TO | REDIRECT_ALL_MAIL_TO=john@doe.com | If set, redirect all QFQ generated mails (Form, Report) to the specified. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
......@@ -454,7 +456,7 @@ Debug
`config.qfq.ini`_
* *SHOW_DEBUG_INFO = yes|no|auto*
* *SHOW_DEBUG_INFO = yes|no|auto|download*
* *yes*:
......@@ -474,6 +476,11 @@ Debug
* *SHOW_DEBUG_INFO = yes* (BE session exist)
* *SHOW_DEBUG_INFO = no* (no BE session)
* *download*:
* During a download (especially by using wkhtml), temporary files are not deleted automatically. Also the
`wkhtmltopdf` and `pdftk` commandlines will be logged to SQL_LOG. Use this only to debug problems on download.
.. _REDIRECT_ALL_MAIL_TO:
* *REDIRECT_ALL_MAIL_TO=john@doe.com*
......
......@@ -15,7 +15,7 @@ SQL_LOG = sql.log
; all, modify
SQL_LOG_MODE = modify
; auto|yes|no. 'auto': if BE User is logged in the value will be 'true', else 'false'
; auto|yes|no|download. 'auto': if BE User is logged in the value will be 'yes', else 'no'
SHOW_DEBUG_INFO = auto
; REDIRECT_ALL_MAIL_TO = john.doe@example.com
......
......@@ -73,7 +73,7 @@ abstract class AbstractBuildForm {
$this->store = Store::getInstance();
$this->db = new Database();
$this->evaluate = new Evaluate($this->store, $this->db);
$this->showDebugInfo = ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes');
$this->showDebugInfo = ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === SYSTEM_SHOW_DEBUG_INFO_YES);
$this->sip = $this->store->getSipInstance();
......
......@@ -330,6 +330,11 @@ const SYSTEM_DATE_FORMAT = 'DATE_FORMAT';
const SYSTEM_REDIRECT_ALL_MAIL_TO = 'REDIRECT_ALL_MAIL_TO';
const SYSTEM_SHOW_DEBUG_INFO = 'SHOW_DEBUG_INFO';
const SYSTEM_SHOW_DEBUG_INFO_YES = 'yes';
const SYSTEM_SHOW_DEBUG_INFO_NO = 'no';
const SYSTEM_SHOW_DEBUG_INFO_AUTO = 'auto';
const SYSTEM_SHOW_DEBUG_INFO_DOWNLOAD = 'download';
const SYSTEM_CSS_LINK_CLASS_INTERNAL = 'CSS_LINK_CLASS_INTERNAL';
const SYSTEM_CSS_LINK_CLASS_EXTERNAL = 'CSS_LINK_CLASS_EXTERNAL';
const SYSTEM_CSS_CLASS_QFQ_CONTAINER = 'CSS_CLASS_QFQ_CONTAINER';
......
......@@ -82,7 +82,7 @@ class AbstractException extends \Exception {
$html = "<h2>Error</h2>" . Support::wrapTag('<p>', $html);
$html = Support::wrapTag("<div class='warning'>", $html);
if ($store !== null && $store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes') {
if ($store !== null && $store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === SYSTEM_SHOW_DEBUG_INFO_YES) {
$this->messageArray['current sip'] = $store->getStore(STORE_SIP);
......
......@@ -26,7 +26,6 @@ class Logger {
throw new UserFormException("Error - cannot open. File: " . $filename . " ( CWD: " . getcwd() . ")", ERROR_IO_OPEN);
}
if (fwrite($handle, $msg . PHP_EOL) === FALSE) {
throw new UserFormException("Error - cannot write. File: " . $filename . " ( CWD: " . getcwd() . ")", ERROR_IO_WRITE);
}
......@@ -36,6 +35,7 @@ class Logger {
/**
* @param array $fe
* @return string
*/
public static function formatFormElementName(array $fe) {
Support::setIfNotSet($fe, 'id');
......
......@@ -12,18 +12,31 @@ require_once(__DIR__ . '/../Constants.php');
class SessionCookie {
/**
* @var string
*/
private $pathFileNameCookie = '';
/**
* @var bool
*/
private $cleanTempFiles = true;
/**
* Copy all current cookies to a temporary file.
*
* @param string $domain
* @param string $path
* @param array $config
* @throws CodeException
*/
public function __construct($domain, $path) {
public function __construct(array $config) {
$lines = '';
$this->cleanTempFiles = ($config[SYSTEM_SHOW_DEBUG_INFO] !== SYSTEM_SHOW_DEBUG_INFO_DOWNLOAD);
$urlParts = parse_url($config[SYSTEM_BASE_URL_PRINT]);
$domain = $urlParts['host'];
$path = $urlParts['path'];
// $_COOKIES[]
if (false === ($this->pathFileNameCookie = tempnam(sys_get_temp_dir(), SESSION_COOKIE_PREFEIX))) {
throw new CodeException('Error creating output file.', ERROR_IO_CREATE_FILE);
......@@ -41,9 +54,12 @@ class SessionCookie {
* Unlink current cookie file
*/
public function __destruct() {
if (file_exists($this->pathFileNameCookie)) {
unlink($this->pathFileNameCookie);
$this->pathFileNameCookie = '';
if ($this->cleanTempFiles) {
if (file_exists($this->pathFileNameCookie)) {
unlink($this->pathFileNameCookie);
$this->pathFileNameCookie = '';
}
}
}
......
......@@ -16,6 +16,7 @@ require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../store/Session.php');
require_once(__DIR__ . '/../store/Store.php');
require_once(__DIR__ . '/../helper/OnArray.php');
require_once(__DIR__ . '/../helper/Logger.php');
require_once(__DIR__ . '/../report/Html2Pdf.php');
//require_once(__DIR__ . '/Link.php');
//require_once(__DIR__ . '/Sendmail.php');
......@@ -56,6 +57,11 @@ class Download {
*/
private $html2pdf = null;
/**
* @var string Filename where to write download Information
*/
private $downloadDebugLog = '';
/**
* @param bool|false $phpUnit
*/
......@@ -65,6 +71,10 @@ class Download {
$this->store = Store::getInstance('', $phpUnit);
$this->db = new Database();
$this->html2pdf = new Html2Pdf($this->store->getStore(STORE_SYSTEM), $phpUnit);
if ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === SYSTEM_SHOW_DEBUG_INFO_DOWNLOAD) {
$this->downloadDebugLog = $this->store->getVar(SYSTEM_SQL_LOG, STORE_SYSTEM);
}
}
/**
......@@ -107,6 +117,10 @@ class Download {
$cmd = "pdftk $inputFiles cat output $concatFile";
if ($this->downloadDebugLog != '') {
Logger::logMessage("Download: $cmd", $this->downloadDebugLog);
}
exec($cmd, $output, $rc);
if ($rc != 0) {
......@@ -167,6 +181,11 @@ class Download {
* @param array $files
*/
private function cleanTempFiles(array $files) {
if ($this->downloadDebugLog != '') {
return;
}
$prefix = sys_get_temp_dir() . '/' . DOWNLOAD_FILE_PREFIX;
$len = strlen($prefix);
......@@ -323,6 +342,7 @@ class Download {
public function process() {
$vars = $this->store->getStore(STORE_SIP);
$this->doElements($vars);
}
}
......
......@@ -68,7 +68,7 @@ class SyntaxReportException extends \Exception {
$this->customMessage = [$this->customMessage];
//error message
if ($store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes') {
if ($store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === SYSTEM_SHOW_DEBUG_INFO_YES) {
$errorMsg = nl2br("<hr />Error: <strong>" . htmlentities($this->getMessage()) . "</strong><br />");
$errorMsg .= "Formreport statement: <strong>" . htmlentities($this->fr_error["row"]) . "</strong><br />";
......
......@@ -17,6 +17,7 @@ require_once(__DIR__ . '/../store/Sip.php');
require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../helper/KeyValueStringParser.php');
require_once(__DIR__ . '/../helper/SessionCookie.php');
require_once(__DIR__ . '/../helper/Logger.php');
class Html2Pdf {
......@@ -72,9 +73,8 @@ class Html2Pdf {
throw new \exception(CONFIG_INI . ' - ' . SYSTEM_WKHTMLTOPDF . '=' . $config[SYSTEM_WKHTMLTOPDF] . ' - not found or not executable.');
}
$urlParts = parse_url($config[SYSTEM_BASE_URL_PRINT]);
$this->session = Session::getInstance($phpUnit);
$this->sessionCookie = new SessionCookie($urlParts['host'], $urlParts['path']);
$this->sessionCookie = new SessionCookie($config);
$this->sip = new Sip($phpUnit);
}
......@@ -152,10 +152,13 @@ class Html2Pdf {
*
* @param string $token TOKEN_URL | TOKEN_URL_PARAM
* @param string $url id=exportPage&r=123, www.nzz.ch/issue?id=456
* @return string rendered file - please delete later
* @param string $logFile Optional pathfilename of a logfile, where to log exec calls
* @return string rendered file - please delete later
* @throws CodeException
* @throws UserFormException
* @throws \exception
*/
public function page2pdf($token, $url) {
public function page2pdf($token, $url, $logFile = '') {
$rcArgs = array();
$urlParamString = '';
$host = '';
......@@ -207,6 +210,9 @@ class Html2Pdf {
$this->session->close();
$cmd = "$wkhtmlToPdf $customHeader $cookieOptions $options $urlPrint $filenameEscape";
if ($logFile != '') {
Logger::logMessage("Html2Pdf: $cmd", $logFile);
}
$rc = 0;
$line = system($cmd, $rc);
......@@ -231,7 +237,6 @@ class Html2Pdf {
$this->setHeader('print.' . $pageId . '.pdf');
@readfile($filename);
@unlink($filename);
// @unlink($filename . '.log');
exit; // Do an extremely hard exit here to make sure there are no more additional bytes sent (makes the delivered PDF unusable).
......
......@@ -737,7 +737,7 @@ class Link {
$paramArray = $this->sip->queryStringToSip($urlNParam, RETURN_ARRAY);
$urlNParam = $paramArray['_url'];
if ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes') {
if ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === SYSTEM_SHOW_DEBUG_INFO_YES) {
$vars[NAME_TOOL_TIP] .= PHP_EOL . PHP_EOL . $this->sip->debugSip($paramArray);
}
}
......
......@@ -105,7 +105,7 @@ class Report {
$this->store = Store::getInstance();
$this->showDebugInfo = ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes');
$this->showDebugInfo = ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === SYSTEM_SHOW_DEBUG_INFO_YES);
$this->pageDefaults[DEFAULT_QUESTION]["pagec"] = "Please confirm!:info";
$this->pageDefaults[DEFAULT_QUESTION]["paged"] = "Do you really want to delete the record?:warning";
......
......@@ -100,7 +100,7 @@ class Config {
private static function setDefaults(array $config) {
// Defaults
Support::setIfNotSet($config, SYSTEM_DATE_FORMAT, 'yyyy-mm-dd');
Support::setIfNotSet($config, SYSTEM_SHOW_DEBUG_INFO, 'auto');
Support::setIfNotSet($config, SYSTEM_SHOW_DEBUG_INFO, SYSTEM_SHOW_DEBUG_INFO_AUTO);
Support::setIfNotSet($config, F_BS_COLUMNS, '12');
Support::setIfNotSet($config, F_BS_LABEL_COLUMNS, '3');
Support::setIfNotSet($config, F_BS_INPUT_COLUMNS, '6');
......
......@@ -237,7 +237,7 @@ class Store {
*/
private static function adjustConfig(array $config) {
// Adjust config
if ($config[SYSTEM_SHOW_DEBUG_INFO] === 'auto') {
if ($config[SYSTEM_SHOW_DEBUG_INFO] === SYSTEM_SHOW_DEBUG_INFO_AUTO) {
$rc = self::beUserLoggdIn();
if ($rc !== false) {
$config[SYSTEM_SHOW_DEBUG_INFO] = $rc;
......@@ -523,7 +523,7 @@ class Store {
// Disable TYPO3_DEBUG_SHOW_BODY_TEXT=1 if SYSTEM_SHOW_DEBUG_INFO!='yes'
if (self::getVar(TYPO3_DEBUG_SHOW_BODY_TEXT, STORE_TYPO3) === '1' &&
self::getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) !== 'yes'
self::getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) !== SYSTEM_SHOW_DEBUG_INFO_YES
) {
self::setVar(TYPO3_DEBUG_SHOW_BODY_TEXT, '0', STORE_TYPO3);
}
......@@ -777,7 +777,7 @@ class Store {
self::setStore($typo3VarsArray, STORE_TYPO3, true);
// If necessary, update SYSTEM_SHOW_DEBUG_INFO
if (self::getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) == 'auto') {
if (self::getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) == SYSTEM_SHOW_DEBUG_INFO_AUTO) {
$val = ($typo3VarsArray[TYPO3_BE_USER_LOGGED_IN] == 'yes') ? 'yes' : 'no';
self::setVar(SYSTEM_SHOW_DEBUG_INFO, $val, STORE_SYSTEM);
}
......
......@@ -230,7 +230,7 @@ EOT;
SYSTEM_DB_INIT => 'set names utf8',
SYSTEM_SQL_LOG_MODE => 'modify',
SYSTEM_DATE_FORMAT => 'yyyy-mm-dd',
SYSTEM_SHOW_DEBUG_INFO => 'auto',
SYSTEM_SHOW_DEBUG_INFO => SYSTEM_SHOW_DEBUG_INFO_AUTO,
F_BS_COLUMNS => '12',
F_BS_LABEL_COLUMNS => '3',
F_BS_INPUT_COLUMNS => '6',
......
Markdown is supported
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