Commit 611d0131 authored by Marc Egger's avatar Marc Egger
Browse files

Refs #11035 use Path:: for paths that are defined in config. Except for Log &...

Refs #11035 use Path:: for paths that are defined in config. Except for Log & absolute paths... they need more work.
parent 65501a4c
Pipeline #3715 failed with stages
in 2 minutes and 38 seconds
......@@ -4,8 +4,6 @@
// TEST FILE TO RUN QFQ REPORT WITHOUT TYPO3 //
///////////////////////////////////////////////
echo $_SERVER['DOCUMENT_ROOT'];
require_once(__DIR__ . '/../../vendor/autoload.php');
use http\Exception;
......@@ -13,7 +11,6 @@ use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\QuickFormQuery;
// TODO: use Path:: for paths that are defined in config
// TODO: replace the above change of constants with better method
// TODO: replace all paths with typo3conf/ and /../ and fileadmin/ with correct path computing function.
// TODO: replace HelperFile::correctRelativePathFileName() everywhere with the corresponding path function.
// TODO: replace Logger::makePathAbsolute()
......@@ -29,13 +26,17 @@ use IMATHUZH\Qfq\Core\QuickFormQuery;
// TODO: BuildFormBootstrap.php Zeile 666 ff. : API pfad automatisch anpassen
// TODO: Link.php 1776: API pfad automatisch anpassen
// TODO: Monitor.php 77: Wird path. I don't know relativ to what it should be
// TODO: In QFQ Config one can define "CSS class QFQ container", it says that this should be set to "container" if QFQ element is not yet in Bootstrap container. Why? Seems to work without it
// TODO: (?) move computation of SYSTEM_EXT_PATH_ABSOLUTE and SYSTEM_SITE_PATH_ABSOLUTE into Path.php. Currently Sotre->doSystemPath
// TODO: (?) replace all log path computations: SYSTEM_QFQ_LOG_ABSOLUTE, SYSTEM_SQL_LOG_ABSOLUTE,
// TODO: Test if qfq, sql and mail logs still work
// Misc.
// TODO: TablesorterController.js: pass API url as data attribute instead of hardcode (this.tablesorterApiUrl = 'typo3conf/ext/qfq/Classes/Api/setting.php';)
////
Path::setExtRelToCwd('../../');
Path::setAppRelToCwd('../../../../../');
class User {
public $user;
......
......@@ -253,6 +253,8 @@ const ERROR_IO_CHMOD = 1314;
const ERROR_IO_READ_FILE = 1315;
const ERROR_IO_WRITE_FILE = 1316;
const ERROR_PATH_INVALID = 1317;
const ERROR_PDF2SVG = 1320;
const ERROR_PDF2JPEG = 1321;
......@@ -461,7 +463,7 @@ const TYPO3_PAGE_TYPE = 'pageType';
const TYPO3_PAGE_LANGUAGE = 'pageLanguage';
const TYPO3_DEBUG_SHOW_BODY_TEXT = 'debugShowBodyText';
const TYPO3_SQL_LOG = 'sqlLog';
const TYPO3_SQL_LOG_ABSOLUTE = 'sqlLog';
const TYPO3_SQL_LOG_MODE = 'sqlLogMode';
// Deprecated: legacy config - still used to read old configuration file.
......@@ -489,11 +491,11 @@ const SYSTEM_DB_NAME_DATA = 'dbNameData';
const SYSTEM_DB_NAME_QFQ = 'dbNameQfq';
const SYSTEM_DB_NAME_T3 = 'dbNameT3';
const SYSTEM_QFQ_LOG = 'qfqLog'; // Logging to file
const SYSTEM_QFQ_LOG_ABSOLUTE = 'qfqLog'; // Logging to file
const SYSTEM_MAIL_LOG = 'mailLog';
const SYSTEM_MAIL_LOG_ABSOLUTE = 'mailLog';
const SYSTEM_SQL_LOG = 'sqlLog'; // Logging to file
const SYSTEM_SQL_LOG_ABSOLUTE = 'sqlLog'; // Logging to file
const SYSTEM_SQL_LOG_MODE = 'sqlLogMode'; // Mode, which statements to log.
const SYSTEM_SQL_LOG_MODE_AUTOCRON = 'sqlLogModeAutoCron'; // Mode, which statements to log in AutoCron Environments.
......@@ -540,14 +542,14 @@ const SYSTEM_FORM_BS_NOTE_COLUMNS = 'formBsNoteColumns';
const SYSTEM_BASE_URL = 'baseUrl';
const SYSTEM_SEND_E_MAIL = 'sendEmail';
const SYSTEM_SEND_E_MAIL_ABSOLUTE = 'sendEmail';
const SYSTEM_SEND_E_MAIL_OPTIONS = 'sendEMailOptions';
const SYSTEM_EDIT_FORM_PAGE = 'editFormPage';
// computed automatically during runtime
const SYSTEM_EXT_PATH = 'extPath';
const SYSTEM_SITE_PATH = 'sitePath';
const SYSTEM_EXT_PATH_ABSOLUTE = 'extPath';
const SYSTEM_SITE_PATH_ABSOLUTE = 'sitePath';
const SYSTEM_LDAP_1_RDN = 'LDAP_1_RDN'; // Credentials to access LDAP
const SYSTEM_LDAP_1_PASSWORD = 'LDAP_1_PASSWORD'; // Credentials to access LDAP
......@@ -641,11 +643,11 @@ const SYSTEM_CMD_GS = 'cmdGs';
const SYSTEM_CMD_PDFUNITE = 'cmdPdfunite';
// Thumbnail
const SYSTEM_THUMBNAIL_DIR_SECURE = 'thumbnailDirSecure';
const SYSTEM_THUMBNAIL_DIR_PUBLIC = 'thumbnailDirPublic';
const SYSTEM_THUMBNAIL_DIR_SECURE_REL_TO_APP = 'thumbnailDirSecure';
const SYSTEM_THUMBNAIL_DIR_PUBLIC_REL_TO_APP = 'thumbnailDirPublic';
// Form/Report as file
const SYSTEM_QFQ_PROJECT_DIR_SECURE = 'qfqProjectDir'; // where form and report files are saved
const SYSTEM_QFQ_PROJECT_DIR_SECURE_REL_TO_APP = 'qfqProjectDir'; // where form and report files are saved
const SYSTEM_DOCUMENTATION_QFQ = 'documentation';
const SYSTEM_DOCUMENTATION_QFQ_URL = 'https://docs.qfq.io';
......
......@@ -46,7 +46,7 @@ class Database {
/**
* @var string
*/
private $sqlLog = '';
private $sqlLogAbsolute = '';
/**
* @var array
......@@ -75,7 +75,7 @@ class Database {
$this->store = Store::getInstance();
$storeSystem = $this->store->getStore(STORE_SYSTEM);
$this->sqlLog = $storeSystem[SYSTEM_SQL_LOG];
$this->sqlLogAbsolute = $storeSystem[SYSTEM_SQL_LOG_ABSOLUTE];
$dbInit = $storeSystem[SYSTEM_DB_INIT];
$config = $this->getConnectionDetails($dbIndex, $storeSystem);
......@@ -588,7 +588,7 @@ class Database {
}
$msg .= '[' . $status . $sql . ']';
Logger::logMessage($msg, $this->sqlLog);
Logger::logMessage($msg, $this->sqlLogAbsolute);
}
/**
......@@ -1045,7 +1045,7 @@ class Database {
* @throws \UserFormException
*/
public function getQfqLogFile() {
return ($this->store == null) ? Path::appRelToCwd(Path::SYSTEM_QFQ_LOG_FILE_REL_TO_APP) : $this->store->getVar(SYSTEM_QFQ_LOG, STORE_SYSTEM);
return ($this->store == null) ? Path::appRelToCwd(Path::SYSTEM_QFQ_LOG_FILE_REL_TO_APP) : $this->store->getVar(SYSTEM_QFQ_LOG_ABSOLUTE, STORE_SYSTEM);
}
/**
......
......@@ -70,7 +70,7 @@ class Delete {
// Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
......
......@@ -190,7 +190,7 @@ class AbstractException extends \Exception {
}
}
$qfqLog = ($store == null) ? Path::appRelToCwd(Path::SYSTEM_QFQ_LOG_FILE_REL_TO_APP) : $store->getVar(SYSTEM_QFQ_LOG, STORE_SYSTEM);
$qfqLog = ($store == null) ? Path::appRelToCwd(Path::SYSTEM_QFQ_LOG_FILE_REL_TO_APP) : $store->getVar(SYSTEM_QFQ_LOG_ABSOLUTE, STORE_SYSTEM);
$arrDebugHidden[EXCEPTION_STACKTRACE] = PHP_EOL . implode($arrTrace, PHP_EOL);
$arrLogAll = array_merge($arrMsg, $arrShow, $arrDebugShow, $arrDebugHidden);
$logAll = OnArray::arrayToLog($arrLogAll);
......
......@@ -33,7 +33,7 @@ class File {
*/
private $session = null;
private $qfqLogFilename = '';
private $qfqLogPathFilenameAbsolute = '';
/**
* @param bool|false $phpUnit
......@@ -47,7 +47,7 @@ class File {
$this->session = Session::getInstance($phpUnit);
$this->store = Store::getInstance('', $phpUnit);
$this->qfqLogFilename = $this->store->getVar(SYSTEM_QFQ_LOG, STORE_SYSTEM);
$this->qfqLogPathFilenameAbsolute = $this->store->getVar(SYSTEM_QFQ_LOG_ABSOLUTE, STORE_SYSTEM);
$this->uploadErrMsg = [
UPLOAD_ERR_INI_SIZE => "The uploaded file exceeds the upload_max_filesize directive in php.ini",
......@@ -138,7 +138,7 @@ class File {
ERROR_UPLOAD);
}
Logger::logMessageWithPrefix(UPLOAD_LOG_PREFIX . ': File under ' . $statusUpload['tmp_name'], $this->qfqLogFilename);
Logger::logMessageWithPrefix(UPLOAD_LOG_PREFIX . ': File under ' . $statusUpload['tmp_name'], $this->qfqLogPathFilenameAbsolute);
$this->checkMaxFileSize($statusUpload['size']);
......@@ -174,7 +174,7 @@ class File {
if (isset($statusUpload[FILES_TMP_NAME]) && $statusUpload[FILES_TMP_NAME] != '') {
$file = Support::extendFilename($statusUpload[FILES_TMP_NAME], UPLOAD_CACHED);
if (file_exists($file)) {
HelperFile::unlink($file, $this->qfqLogFilename);
HelperFile::unlink($file, $this->qfqLogPathFilenameAbsolute);
}
$statusUpload[FILES_TMP_NAME] = '';
}
......
......@@ -6,6 +6,7 @@ namespace IMATHUZH\Qfq\Core\Form;
use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\OnString;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Helper\SqlQuery;
use IMATHUZH\Qfq\Core\Store\Store;
......@@ -312,7 +313,7 @@ class FormAsFile
* @param string $tableName
* @return string
*/
public static function errorHintFormImport (string $tableName = 'Form'): string
public static function errorHintFormImport (string $tableName = TABLE_NAME_FORM): string
{
$message = '';
if (in_array($tableName, [TABLE_NAME_FORM, TABLE_NAME_FORM_ELEMENT])) {
......@@ -609,8 +610,8 @@ class FormAsFile
*/
private static function formPath(Database $database): string
{
$systemQfqProjectDir = Store::getInstance()->getVar(SYSTEM_QFQ_PROJECT_DIR_SECURE, STORE_SYSTEM);
$formPath = HelperFile::correctRelativePathFileName(HelperFile::joinPathFilename($systemQfqProjectDir, 'form'));
$qfqProjectDirRelToCwd = Path::appRelToCwd(Store::getInstance()->getVar(SYSTEM_QFQ_PROJECT_DIR_SECURE_REL_TO_APP, STORE_SYSTEM));
$formPath = Path::join($qfqProjectDirRelToCwd, Path::FORM_REL_TO_PROJECT_DIR);
if (!is_dir($formPath)) {
// create path
......
......@@ -29,12 +29,23 @@ Path::appRelToCwd(SYSTEM_THUMBNAIL_DIR_PUBLIC_DEFAULT_REL_TO_APP) === SYSTEM_THU
Path::appRelToCwd(THUMBNAIL_UNKNOWN_TYPE_REL_TO_APP) === THUMBNAIL_UNKNOWN_TYPE
Path::appRelToCwd(DIR_HIGHLIGHT_JSON_REL_TO_APP) === DIR_HIGHLIGHT_JSON
$qfqProjectDirRelToCwd = Path::appRelToCwd(Store::getInstance()->getVar(SYSTEM_QFQ_PROJECT_DIR_SECURE_REL_TO_APP, STORE_SYSTEM));
Path::join($qfqProjectDirRelToCwd, Path::REPORT_REL_TO_PROJECT_DIR) === "../../../../../fileadmin/protected/qfqProject/report"
*/
class Path
{
private static $extRelToCwd = 'typo3conf/ext/qfq';
// Default path relative to CWD
private static $appRelToCwd = '';
// Extension
const EXT_REL_TO_APP = 'typo3conf/ext/qfq';
// QFQ Project dir
const FORM_REL_TO_PROJECT_DIR = 'form';
const REPORT_REL_TO_PROJECT_DIR = 'report';
// API
const API_REL_TO_EXT = 'Classes/Api';
......@@ -57,25 +68,20 @@ class Path
// Annotate
const DIR_HIGHLIGHT_JSON_REL_TO_APP = 'typo3conf/ext/qfq/Resources/Public/Json';
public static function setExtRelToCwd(string $newPath)
public static function setAppRelToCwd(string $newPath)
{
self::$extRelToCwd = $newPath;
self::$appRelToCwd = $newPath;
}
/**
* Return path relative to CWD
*
* Path::pathRelToExt("Classes/Api")
* Path::relToExt("Classes/Api")
* Path::extRelToCwd("Classes/Api")
*
*
* @param string $pathRelToExt
* @return string
*/
public static function extRelToCwd(string $pathRelToExt = ''): string
{
return self::join(self::$extRelToCwd, $pathRelToExt);
return self::join(self::appRelToCwd(self::EXT_REL_TO_APP), $pathRelToExt);
}
public static function apiRelToExt(string $pathRelToApi = ''): string
......@@ -90,23 +96,36 @@ class Path
public static function appRelToCwd(string $pathRelToExt = ''): string
{
$appPathRelToCwd = '';
return self::join($appPathRelToCwd, $pathRelToExt);
return self::join(self::$appRelToCwd, $pathRelToExt);
}
public static function join(/* path pieces */): string
public static function join(/* path parts */): string
{
// Filter out empty string and null arguments
$pieces = array_filter(func_get_args(), function($value) { return !is_null($value) && $value !== ''; });
$parts = array_filter(func_get_args(), function($value) { return !is_null($value) && $value !== ''; });
if (empty($pieces)) {
if (empty($parts)) {
return '';
}
$firstPiece = array_shift($pieces);
if (empty($pieces)) {
return $firstPiece;
$firstPart = array_shift($parts);
if (empty($parts)) {
return $firstPart;
}
return $firstPiece . '/' . implode($pieces,'/');
// Trailing path parts may not be absolute
foreach ($parts as $part) {
if ($part[0] === '/') {
throw new \UserFormException(json_encode([
ERROR_MESSAGE_TO_USER => 'Failed: Join path.',
ERROR_MESSAGE_TO_DEVELOPER => "Trailing path parts may not start with '/'. Trailing part: '$part'."]),
ERROR_PATH_INVALID);
}
}
$path = $firstPart . '/' . implode($parts,'/');
// remove multiple occurances of '/'
return preg_replace('/\/{2,}/','/', $path);
}
/*
......
......@@ -17,6 +17,7 @@ use IMATHUZH\Qfq\Core\Helper\KeyValueStringParser;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\OnString;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Helper\Sanitize;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\QuickFormQuery;
......@@ -61,7 +62,7 @@ class Download {
/**
* @var string Filename where to write download Information
*/
private $downloadDebugLog = '';
private $downloadDebugLogAbsolute = '';
/**
* @var string Name of command
......@@ -103,7 +104,7 @@ class Download {
$this->pdfunite = $this->store->getVar(SYSTEM_CMD_PDFUNITE, STORE_SYSTEM);
if (Support::findInSet(SYSTEM_SHOW_DEBUG_INFO_DOWNLOAD, $this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM))) {
$this->downloadDebugLog = $this->store->getVar(SYSTEM_SQL_LOG, STORE_SYSTEM);
$this->downloadDebugLogAbsolute = $this->store->getVar(SYSTEM_SQL_LOG_ABSOLUTE, STORE_SYSTEM);
}
}
......@@ -161,8 +162,8 @@ class Download {
// $cmd = "qpdf --empty --pages $inputFiles -- $concatFile 2>&1"; # Fails to merge identical files, if they contain references.
$cmd = $this->pdfunite . " $inputFiles $concatFile 2>&1"; // Based on poppler. URLs are preserved. Orientation and size are preserved.
if ($this->downloadDebugLog != '') {
Logger::logMessage("Download: $cmd", $this->downloadDebugLog);
if ($this->downloadDebugLogAbsolute != '') {
Logger::logMessage("Download: $cmd", $this->downloadDebugLogAbsolute);
}
$rc = $this->concatPdfFilesPdfUnite($cmd, $output);
......@@ -501,7 +502,7 @@ class Download {
$tmpFiles = array();
$workDir = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
$workDir = $this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM);
HelperFile::chdir($workDir);
$downloadMode = $vars[DOWNLOAD_MODE];
......
......@@ -53,7 +53,7 @@ class Html2Pdf {
/**
* @var string
*/
private $logFile = '';
private $logFilePathAbsolute = '';
/**
* Read QFQ config. Only SYSTEM_BASE_URL_PRINT and SYSTEM_WKHTMLTOPDF will be used.
......@@ -86,7 +86,7 @@ class Html2Pdf {
$this->sessionCookie = new SessionCookie($config);
$this->sip = new Sip($phpUnit);
$this->logFile = $config[SYSTEM_QFQ_LOG];
$this->logFilePathAbsolute = $config[SYSTEM_QFQ_LOG_ABSOLUTE];
}
/**
......@@ -186,8 +186,8 @@ class Html2Pdf {
$this->session->close();
$cmd = "$wkhtmlToPdf $customHeader $cookieOptions $options $urlPrint $filenameEscape";
if ($this->logFile != '') {
Logger::logMessage("Html2Pdf: $cmd", $this->logFile);
if ($this->logFilePathAbsolute != '') {
Logger::logMessage("Html2Pdf: $cmd", $this->logFilePathAbsolute);
}
$rc = 0;
......
......@@ -190,10 +190,10 @@ class Report {
*/
private function checkUpdateSqlLog() {
$sqlLog = $this->store->getVar(TYPO3_SQL_LOG, STORE_TYPO3);
$sqlLog = $this->store->getVar(TYPO3_SQL_LOG_ABSOLUTE, STORE_TYPO3);
if (false !== $sqlLog) {
$sqlLog = HelperFile::joinPathFilename($this->store->getVar(SYSTEM_EXT_PATH, STORE_SYSTEM), $sqlLog);
$this->store->setVar(SYSTEM_SQL_LOG, $sqlLog, STORE_SYSTEM);
$sqlLog = HelperFile::joinPathFilename($this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM), $sqlLog);
$this->store->setVar(SYSTEM_SQL_LOG_ABSOLUTE, $sqlLog, STORE_SYSTEM);
}
$sqlLogMode = $this->store->getVar(TYPO3_SQL_LOG_MODE, STORE_TYPO3);
......
......@@ -12,6 +12,7 @@ namespace IMATHUZH\Qfq\Core\Report;
use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Store\Store;
class ReportAsFile
......@@ -172,8 +173,8 @@ class ReportAsFile
*/
private static function reportPath(): string
{
$systemQfqProjectDir = Store::getInstance()->getVar(SYSTEM_QFQ_PROJECT_DIR_SECURE, STORE_SYSTEM);
$reportPath = HelperFile::correctRelativePathFileName(HelperFile::joinPathFilename($systemQfqProjectDir, 'report'));
$qfqProjectDirRelToCwd = Path::appRelToCwd(Store::getInstance()->getVar(SYSTEM_QFQ_PROJECT_DIR_SECURE_REL_TO_APP, STORE_SYSTEM));
$reportPath = Path::join($qfqProjectDirRelToCwd, Path::REPORT_REL_TO_PROJECT_DIR);
HelperFile::createPathRecursive($reportPath);
return $reportPath;
}
......
......@@ -170,9 +170,9 @@ class SendMail {
$args[] = '-t "' . $mailConfig[SENDMAIL_TOKEN_RECEIVER] . '"';
$args[] = '-o message-charset="utf-8"';
$logFile = $this->store->getVar(SYSTEM_MAIL_LOG, STORE_SYSTEM);
if ($logFile != '' && $logFile !== false) {
$args[] = '-l "' . $logFile . '"';
$logFilePathAbsolute = $this->store->getVar(SYSTEM_MAIL_LOG_ABSOLUTE, STORE_SYSTEM);
if ($logFilePathAbsolute != '' && $logFilePathAbsolute !== false) {
$args[] = '-l "' . $logFilePathAbsolute . '"';
}
if (!empty($mailConfig[SENDMAIL_TOKEN_RECEIVER_CC])) {
......@@ -220,7 +220,7 @@ class SendMail {
$args[] = '-o message-header="' . $mailConfig[SENDMAIL_TOKEN_HEADER] . '"';
}
$sendEmail = $this->store->getVar(SYSTEM_SEND_E_MAIL, STORE_SYSTEM);
$sendEmail = $this->store->getVar(SYSTEM_SEND_E_MAIL_ABSOLUTE, STORE_SYSTEM);
if (empty($sendEmail)) {
throw new \UserFormException("Missing 'sendEmail'", ERROR_SENDMAIL);
}
......
......@@ -33,8 +33,8 @@ class Thumbnail {
private $inkscape = '';
private $convert = '';
private $thumbnailDirSecure = '';
private $thumbnailDirPublic = '';
private $thumbnailDirSecureRelToCwd = '';
private $thumbnailDirPublicRelToCwd = '';
/**
* @param bool|false $phpUnit
......@@ -49,8 +49,8 @@ class Thumbnail {
$this->inkscape = $this->store->getVar(SYSTEM_CMD_INKSCAPE, STORE_SYSTEM);
$this->convert = $this->store->getVar(SYSTEM_CMD_CONVERT, STORE_SYSTEM);
$this->thumbnailDirSecure = $this->store->getVar(SYSTEM_THUMBNAIL_DIR_SECURE, STORE_SYSTEM);
$this->thumbnailDirPublic = $this->store->getVar(SYSTEM_THUMBNAIL_DIR_PUBLIC, STORE_SYSTEM);
$this->thumbnailDirSecureRelToCwd = Path::appRelToCwd($this->store->getVar(SYSTEM_THUMBNAIL_DIR_SECURE_REL_TO_APP, STORE_SYSTEM));
$this->thumbnailDirPublicRelToCwd = Path::appRelToCwd($this->store->getVar(SYSTEM_THUMBNAIL_DIR_PUBLIC_REL_TO_APP, STORE_SYSTEM));
}
/**
......@@ -84,7 +84,7 @@ class Thumbnail {
$pathFilenameSource = $control[TOKEN_THUMBNAIL];
$dir = ($control[TOKEN_SIP] == "1") ? $this->thumbnailDirSecure : $this->thumbnailDirPublic;
$dir = ($control[TOKEN_SIP] == "1") ? $this->thumbnailDirSecureRelToCwd : $this->thumbnailDirPublicRelToCwd;
$pathFilenameThumbnail = Support::joinPath($dir, md5($pathFilenameSource . $control[TOKEN_THUMBNAIL_DIMENSION]) . '.png');
// Check if the file has to exist now.
......
......@@ -73,9 +73,9 @@ class Save {
$this->evaluate = new Evaluate($this->store, $this->db);
$this->formAction = new FormAction($formSpec, $this->db);
$this->qfqLogFilename = HelperFile::joinPathFilename(
$this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM),
$this->store->getVar(SYSTEM_QFQ_LOG, STORE_SYSTEM));
$this->qfqLogFilename = HelperFile::joinPathFilename( // Will only join if second part does not start with '/'
$this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM),
$this->store->getVar(SYSTEM_QFQ_LOG_ABSOLUTE, STORE_SYSTEM));
}
/**
......@@ -663,7 +663,7 @@ class Save {
// Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
......@@ -768,7 +768,7 @@ class Save {
// Upload - Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
......
......@@ -267,7 +267,7 @@ class Config {
}
Logger::logMessage(Logger::linePre() . 'Security: attack detected' . PHP_EOL . $reason,
$config[SYSTEM_QFQ_LOG] ?? Path::appRelToCwd(Path::SYSTEM_QFQ_LOG_FILE_REL_TO_APP));
$config[SYSTEM_QFQ_LOG_ABSOLUTE] ?? Path::appRelToCwd(Path::SYSTEM_QFQ_LOG_FILE_REL_TO_APP));
// In case of an attack: log out the current user.
Session::destroy();
......@@ -315,9 +315,9 @@ class Config {
SYSTEM_RENDER => SYSTEM_RENDER_SINGLE,
SYSTEM_DATE_FORMAT => 'yyyy-mm-dd',
SYSTEM_SHOW_DEBUG_INFO => SYSTEM_SHOW_DEBUG_INFO_AUTO,
SYSTEM_MAIL_LOG => Path::appRelToCwd(Path::SYSTEM_MAIL_LOG_FILE_REL_TO_APP),
SYSTEM_QFQ_LOG => Path::appRelToCwd(Path::SYSTEM_QFQ_LOG_FILE_REL_TO_APP),
SYSTEM_SQL_LOG => Path::appRelToCwd(Path::SYSTEM_SQL_LOG_FILE_REL_TO_APP),
SYSTEM_MAIL_LOG_ABSOLUTE => Path::SYSTEM_MAIL_LOG_FILE_REL_TO_APP, // Will be made absolute automatically by Store->adjustConfig()
SYSTEM_QFQ_LOG_ABSOLUTE => Path::SYSTEM_QFQ_LOG_FILE_REL_TO_APP, // Will be made absolute automatically by Store->adjustConfig()
SYSTEM_SQL_LOG_ABSOLUTE => Path::SYSTEM_SQL_LOG_FILE_REL_TO_APP, // Will be made absolute automatically by Store->adjustConfig()
SYSTEM_SQL_LOG_MODE => 'modify',
SYSTEM_SQL_LOG_MODE_AUTOCRON => 'error',
F_BS_COLUMNS => 'col-md-12 col-lg-10',
......@@ -379,8 +379,8 @@ class Config {
SYSTEM_CMD_GS => 'gs',
SYSTEM_CMD_PDFUNITE => 'pdfunite',
SYSTEM_THUMBNAIL_DIR_SECURE => Path::appRelToCwd(Path::SYSTEM_THUMBNAIL_DIR_SECURE_DEFAULT_REL_TO_APP),
SYSTEM_THUMBNAIL_DIR_PUBLIC => Path::appRelToCwd(Path::SYSTEM_THUMBNAIL_DIR_PUBLIC_DEFAULT_REL_TO_APP),
SYSTEM_THUMBNAIL_DIR_SECURE_REL_TO_APP => Path::SYSTEM_THUMBNAIL_DIR_SECURE_DEFAULT_REL_TO_APP,
SYSTEM_THUMBNAIL_DIR_PUBLIC_REL_TO_APP => Path::SYSTEM_THUMBNAIL_DIR_PUBLIC_DEFAULT_REL_TO_APP,
F_FE_DATA_REQUIRED_ERROR => F_FE_DATA_REQUIRED_ERROR_DEFAULT,
F_FE_DATA_MATCH_ERROR => F_FE_DATA_MATCH_ERROR_DEFAULT,
......
......@@ -250,7 +250,7 @@ class Store {
private static function doSystemPath(array $config) {
// SYSTEM_PATH_EXT: compute only if not already defined.
if (!isset($config[SYSTEM_EXT_PATH]) || $config[SYSTEM_EXT_PATH] === '' || $config[SYSTEM_EXT_PATH][0] !== '/') {
if (!isset($config[SYSTEM_EXT_PATH_ABSOLUTE]) || $config[SYSTEM_EXT_PATH_ABSOLUTE] === '' || $config[SYSTEM_EXT_PATH_ABSOLUTE][0] !== '/') {
$relExtDir = '/typo3conf/ext/' . EXT_KEY;
if (defined('PHPUNIT_QFQ')) {
......@@ -258,8 +258,8 @@ class Store {
$pos = strpos($cwd, '/typo3conf/');
// this means phpUnit.
$config[SYSTEM_SITE_PATH] = substr($cwd, 0, $pos);
$config[SYSTEM_EXT_PATH] = $config[SYSTEM_SITE_PATH] . $relExtDir;
$config[SYSTEM_SITE_PATH_ABSOLUTE] = substr($cwd, 0, $pos);
$config[SYSTEM_EXT_PATH_ABSOLUTE] = $config[SYSTEM_SITE_PATH_ABSOLUTE] . $relExtDir;
} else {
// If we are called through AJAX API (e.g. api/save.php), there is no TYPO3 environment.
......@@ -267,17 +267,17 @@ class Store {
if ($pos === false && isset($GLOBALS['TYPO3_LOADED_EXT'][EXT_KEY]['ext_localconf.php'])) {
// Typo3 extension: probably index.php
$config[SYSTEM_EXT_PATH] = dirname($GLOBALS['TYPO3_LOADED_EXT'][EXT_KEY]['ext_localconf.php']);
$config[SYSTEM_SITE_PATH] = dirname($_SERVER['SCRIPT_FILENAME'] ?? '');
$config[SYSTEM_EXT_PATH_ABSOLUTE] = dirname($GLOBALS['TYPO3_LOADED_EXT'][EXT_KEY]['ext_localconf.php']);
$config[SYSTEM_SITE_PATH_ABSOLUTE] = dirname($_SERVER['SCRIPT_FILENAME'] ?? '');
} else {
// API
$config[SYSTEM_EXT_PATH] = substr($_SERVER['SCRIPT_FILENAME'] ?? '', 0, $pos + strlen($relExtDir));
$config[SYSTEM_SITE_PATH] = substr($_SERVER['SCRIPT_FILENAME'] ?? '', 0, $pos);
$config[SYSTEM_EXT_PATH_ABSOLUTE] = substr($_SERVER['SCRIPT_FILENAME'] ?? '', 0, $pos + strlen($relExtDir));
$config[SYSTEM_SITE_PATH_ABSOLUTE] = substr($_SERVER['SCRIPT_FILENAME'] ?? '', 0, $pos);
}
}
}
Logger::setSystemSitePath($config[SYSTEM_SITE_PATH]);
Logger::setSystemSitePath($config[SYSTEM_SITE_PATH_ABSOLUTE]);
return $config;
}
......@@ -293,12 +293,12 @@ class Store {
$config[SYSTEM_SHOW_DEBUG_INFO] = self::adjustConfigShowDebugInfo($config[SYSTEM_SHOW_DEBUG_INFO], self::beUserLoggdIn());
$config[SYSTEM_SEND_E_MAIL] = $config[SYSTEM_EXT_PATH] . '/Classes/External/sendEmail';
$config[SYSTEM_SEND_E_MAIL_ABSOLUTE] = $config[SYSTEM_EXT_PATH_ABSOLUTE] . '/Classes/External/sendEmail';
// Make path absolute