Commit b71577ab authored by Marc Egger's avatar Marc Egger
Browse files

Refs #11035 replace log paths from store with ones from PATH::

parent cf4c7b56
Pipeline #3731 failed with stages
in 1 minute and 57 seconds
......@@ -495,11 +495,13 @@ const SYSTEM_DB_NAME_DATA = 'dbNameData';
const SYSTEM_DB_NAME_QFQ = 'dbNameQfq';
const SYSTEM_DB_NAME_T3 = 'dbNameT3';
const SYSTEM_QFQ_LOG_ABSOLUTE = 'qfqLog'; // Logging to file
const SYSTEM_QFQ_LOG_PATH = 'logPath'; // absolute or relative to app
const SYSTEM_MAIL_LOG_ABSOLUTE = 'mailLog';
const SYSTEM_QFQ_LOG_PATHFILENAME = 'qfqLog'; // absolute or relative to app
const SYSTEM_SQL_LOG_ABSOLUTE = 'sqlLog'; // Logging to file
const SYSTEM_MAIL_LOG_PATHFILENAME = 'mailLog'; // absolute or relative to app
const SYSTEM_SQL_LOG_PATHFILENAME = 'sqlLog'; // absolute or relative to app
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.
......
......@@ -75,7 +75,7 @@ class Database {
$this->store = Store::getInstance();
$storeSystem = $this->store->getStore(STORE_SYSTEM);
$this->sqlLogAbsolute = $storeSystem[SYSTEM_SQL_LOG_ABSOLUTE];
$this->sqlLogAbsolute = Path::absoluteSqlLogFile();
$dbInit = $storeSystem[SYSTEM_DB_INIT];
$config = $this->getConnectionDetails($dbIndex, $storeSystem);
......@@ -1041,11 +1041,10 @@ class Database {
/**
* @return string
* @throws \CodeException
* @throws \UserFormException
*/
public function getQfqLogFile() {
return ($this->store == null) ? Path::cwdToApp(Path::APP_TO_QFQ_LOG_FILE) : $this->store->getVar(SYSTEM_QFQ_LOG_ABSOLUTE, STORE_SYSTEM);
return Path::absoluteQfqLogFile();
}
/**
......
......@@ -294,7 +294,7 @@ class DatabaseUpdate {
if ($actionSpecialColumn === ACTION_SPECIAL_COLUMN_DO_REPLACE) {
// save log file
$message = '<h1>Special column names replaced</h1>The following special column names were replaced.<hr>' . $message;
Logger::logMessage($message, Path::cwdToApp(Path::APP_TO_LOG) . '/' . date("YmdHi") . '_special_columns_auto_update.html');
Logger::logMessage($message, Path::absoluteLog() . '/' . date("YmdHi") . '_special_columns_auto_update.html');
} elseif ($actionSpecialColumn === ACTION_SPECIAL_COLUMN_DO_SKIP_REPLACE) {
// do nothing
} else {
......@@ -306,7 +306,7 @@ class DatabaseUpdate {
. 'Click <a href="?' . http_build_query(array_merge($_GET, array(ACTION_SPECIAL_COLUMN_UPDATE => ACTION_SPECIAL_COLUMN_DO_REPLACE))) . '">Auto-Replace</a>'
. ' to automatically prepend the found column names with an underscore.'
. ' In the report below the missing underscores are marked by "<span style="font-weight: bold; color: red;">>>>_</span>".'
. ' This report will be saved in ' . Path::cwdToApp(Path::APP_TO_LOG) . ' after the automatic replacement.'
. ' This report will be saved in ' . Path::absoluteLog() . ' after the automatic replacement.'
. ' <br><br>To update qfq without changing the special columns (your app will probably be broken): '
. '<a href="?' . http_build_query(array_merge($_GET, array(ACTION_SPECIAL_COLUMN_UPDATE => ACTION_SPECIAL_COLUMN_DO_SKIP_REPLACE))) . '">Skip Auto-Replace</a>'
. '<h2>Report</h2>'
......
......@@ -192,7 +192,7 @@ class AbstractException extends \Exception {
}
}
$qfqLog = ($store == null) ? Path::cwdToApp(Path::APP_TO_QFQ_LOG_FILE) : $store->getVar(SYSTEM_QFQ_LOG_ABSOLUTE, STORE_SYSTEM);
$qfqLog = Path::absoluteQfqLogFile();
$arrDebugHidden[EXCEPTION_STACKTRACE] = PHP_EOL . implode($arrTrace, PHP_EOL);
$arrLogAll = array_merge($arrMsg, $arrShow, $arrDebugShow, $arrDebugHidden);
$logAll = OnArray::arrayToLog($arrLogAll);
......
......@@ -10,6 +10,7 @@ namespace IMATHUZH\Qfq\Core;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Store\Session;
use IMATHUZH\Qfq\Core\Store\Store;
......@@ -47,7 +48,7 @@ class File {
$this->session = Session::getInstance($phpUnit);
$this->store = Store::getInstance('', $phpUnit);
$this->qfqLogPathFilenameAbsolute = $this->store->getVar(SYSTEM_QFQ_LOG_ABSOLUTE, STORE_SYSTEM);
$this->qfqLogPathFilenameAbsolute = Path::absoluteQfqLogFile();
$this->uploadErrMsg = [
UPLOAD_ERR_INI_SIZE => "The uploaded file exceeds the upload_max_filesize directive in php.ini",
......
......@@ -86,13 +86,14 @@ class Path
// Log files
private static $cwdToLog = null; // TODO: does it make sense to have it rel to CWD? to broad?
const APP_TO_LOG = 'fileadmin/protected/log';
const APP_TO_QFQ_LOG_FILE = 'fileadmin/protected/log/qfq.log';
const APP_TO_MAIL_LOG_FILE = 'fileadmin/protected/log/mail.log';
const APP_TO_SQL_LOG_FILE = 'fileadmin/protected/log/sql.log';
private static $overloadAbsoluteQfqLogFile = null;
private static $overloadAbsoluteMailLogFile = null;
private static $overloadAbsoluteSqlLogFile = null;
private const LOG_TO_QFQ_LOG_FILE_DEFAULT = 'qfq.log';
private const LOG_TO_MAIL_LOG_FILE_DEFAULT = 'mail.log';
private const LOG_TO_SQL_LOG_FILE_DEFAULT = 'sql.log';
private const PROJECT_TO_LOG_DEFAULT = 'log';
private const APP_TO_DEPRECATED_LOG = 'fileadmin/protected/log';
private const APP_TO_LOG_DEPRECATED = 'fileadmin/protected/log';
// Thumbnail
const APP_TO_SYSTEM_THUMBNAIL_DIR_SECURE_DEFAULT = 'fileadmin/protected/qfqThumbnail';
......@@ -111,6 +112,51 @@ class Path
self::findAndSetLogPath();
}
/**
* @return string
* @throws \UserFormException
*/
public static function absoluteLog(/* path parts to append */): string
{
return realpath(self::cwdToLog(func_get_args()));
}
/**
* @return string
* @throws \UserFormException
*/
public static function absoluteSqlLogFile(): string
{
if (is_null(self::$overloadAbsoluteSqlLogFile)) {
return self::absoluteLog(self::LOG_TO_SQL_LOG_FILE_DEFAULT);
}
return self::$overloadAbsoluteSqlLogFile;
}
/**
* @return string
* @throws \UserFormException
*/
public static function absoluteQfqLogFile(): string
{
if (is_null(self::$overloadAbsoluteQfqLogFile)) {
return self::absoluteLog(self::LOG_TO_QFQ_LOG_FILE_DEFAULT);
}
return self::$overloadAbsoluteQfqLogFile;
}
/**
* @return string
* @throws \UserFormException
*/
public static function absoluteMailLogFile(): string
{
if (is_null(self::$overloadAbsoluteMailLogFile)) {
return self::absoluteLog(self::LOG_TO_MAIL_LOG_FILE_DEFAULT);
}
return self::$overloadAbsoluteMailLogFile;
}
/**
* @return string
* @throws \UserFormException
......@@ -177,6 +223,36 @@ class Path
return self::cwdToExt(self::extToApi(func_get_args()));
}
/**
* @param string $newPath
* @throws \UserFormException
*/
public static function setAbsoluteSqlLogFile(string $newPath)
{
self::enforcePathIsAbsolute($newPath);
self::$overloadAbsoluteSqlLogFile = $newPath;
}
/**
* @param string $newPath
* @throws \UserFormException
*/
public static function setAbsoluteQfqLogFile(string $newPath)
{
self::enforcePathIsAbsolute($newPath);
self::$overloadAbsoluteQfqLogFile = $newPath;
}
/**
* @param string $newPath
* @throws \UserFormException
*/
public static function setAbsoluteMailLogFile(string $newPath)
{
self::enforcePathIsAbsolute($newPath);
self::$overloadAbsoluteMailLogFile = $newPath;
}
/**
* Join the arguments together as a path.
* The second argument may be an array of parts. (further arguments are ignored in that case)
......@@ -256,8 +332,8 @@ class Path
self::setCwdToLog($cwdToLog);
// search log dir in fileadmin/protected
} elseif (file_exists(self::cwdToApp(self::APP_TO_DEPRECATED_LOG))) {
self::setCwdToLog(self::cwdToApp(self::APP_TO_DEPRECATED_LOG));
} elseif (file_exists(self::cwdToApp(self::APP_TO_LOG_DEPRECATED))) {
self::setCwdToLog(self::cwdToApp(self::APP_TO_LOG_DEPRECATED));
// create default log dir
} else {
......@@ -327,4 +403,14 @@ EOF;
Thrower::userFormException('Path accessed before set.', 'Make sure Path::setMainPaths() is called before.');
}
}
/**
* @param $path
* @throws \UserFormException
*/
private static function enforcePathIsAbsolute($path) {
if($path[0] !== '/') {
Thrower::userFormException('Path is not absolute', "Path does not start with '/' : $path");
}
}
}
\ No newline at end of file
......@@ -123,7 +123,7 @@ class Support {
throw new \CodeException('Unknown mode: ' . $formLogMode, ERROR_UNKNOWN_TOKEN);
}
$filename = Path::cwdToApp(Path::APP_TO_LOG) . '/' . $formName . "." . $perBeSession . "log";
$filename = Path::absoluteLog() . '/' . $formName . "." . $perBeSession . "log";
return sanitize::safeFilename($filename, false, true);
}
......
......@@ -104,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->downloadDebugLogAbsolute = $this->store->getVar(SYSTEM_SQL_LOG_ABSOLUTE, STORE_SYSTEM);
$this->downloadDebugLogAbsolute = Path::absoluteSqlLogFile();
}
}
......
......@@ -15,6 +15,7 @@ namespace IMATHUZH\Qfq\Core\Report;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\OnString;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Store\Config;
use IMATHUZH\Qfq\Core\Store\Session;
......@@ -86,7 +87,7 @@ class Html2Pdf {
$this->sessionCookie = new SessionCookie($config);
$this->sip = new Sip($phpUnit);
$this->logFilePathAbsolute = $config[SYSTEM_QFQ_LOG_ABSOLUTE];
$this->logFilePathAbsolute = Path::absoluteQfqLogFile();
}
/**
......
......@@ -193,8 +193,8 @@ class Report {
$sqlLog = $this->store->getVar(TYPO3_SQL_LOG_ABSOLUTE, STORE_TYPO3);
if (false !== $sqlLog) {
$sqlLog = HelperFile::joinPathFilename($this->store->getVar(SYSTEM_SITE_PATH_ABSOLUTE, STORE_SYSTEM), $sqlLog);
$this->store->setVar(SYSTEM_SQL_LOG_ABSOLUTE, $sqlLog, STORE_SYSTEM);
$sqlLogAbsolute = HelperFile::joinPathFilename(realpath(Path::cwdToApp()), $sqlLog);
Path::setAbsoluteSqlLogFile($sqlLogAbsolute);
}
$sqlLogMode = $this->store->getVar(TYPO3_SQL_LOG_MODE, STORE_TYPO3);
......
......@@ -5,6 +5,7 @@ namespace IMATHUZH\Qfq\Core\Report;
use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Core\Helper\Sanitize;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
......@@ -170,7 +171,7 @@ class SendMail {
$args[] = '-t "' . $mailConfig[SENDMAIL_TOKEN_RECEIVER] . '"';
$args[] = '-o message-charset="utf-8"';
$logFilePathAbsolute = $this->store->getVar(SYSTEM_MAIL_LOG_ABSOLUTE, STORE_SYSTEM);
$logFilePathAbsolute = Path::absoluteMailLogFile();
if ($logFilePathAbsolute != '' && $logFilePathAbsolute !== false) {
$args[] = '-l "' . $logFilePathAbsolute . '"';
}
......
......@@ -15,6 +15,7 @@ use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
use IMATHUZH\Qfq\Core\Helper\KeyValueStringParser;
use IMATHUZH\Qfq\Core\Helper\Logger;
use IMATHUZH\Qfq\Core\Helper\OnArray;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Helper\Sanitize;
use IMATHUZH\Qfq\Core\Helper\SqlQuery;
use IMATHUZH\Qfq\Core\Helper\Support;
......@@ -73,9 +74,7 @@ class Save {
$this->evaluate = new Evaluate($this->store, $this->db);
$this->formAction = new FormAction($formSpec, $this->db);
$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));
$this->qfqLogFilename = Path::absoluteQfqLogFile();
}
/**
......
......@@ -274,8 +274,7 @@ class Config {
$config = self::readConfig();
}
Logger::logMessage(Logger::linePre() . 'Security: attack detected' . PHP_EOL . $reason,
$config[SYSTEM_QFQ_LOG_ABSOLUTE] ?? Path::cwdToApp(Path::APP_TO_QFQ_LOG_FILE));
Logger::logMessage(Logger::linePre() . 'Security: attack detected' . PHP_EOL . $reason, Path::absoluteQfqLogFile());
// In case of an attack: log out the current user.
Session::destroy();
......@@ -323,9 +322,10 @@ 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_ABSOLUTE => Path::APP_TO_MAIL_LOG_FILE, // Will be made absolute automatically by Store->adjustConfig()
SYSTEM_QFQ_LOG_ABSOLUTE => Path::APP_TO_QFQ_LOG_FILE, // Will be made absolute automatically by Store->adjustConfig()
SYSTEM_SQL_LOG_ABSOLUTE => Path::APP_TO_SQL_LOG_FILE, // Will be made absolute automatically by Store->adjustConfig()
SYSTEM_QFQ_LOG_PATH => '',
SYSTEM_MAIL_LOG_PATHFILENAME => '',
SYSTEM_QFQ_LOG_PATHFILENAME => '',
SYSTEM_SQL_LOG_PATHFILENAME => '',
SYSTEM_SQL_LOG_MODE => 'modify',
SYSTEM_SQL_LOG_MODE_AUTOCRON => 'error',
F_BS_COLUMNS => 'col-md-12 col-lg-10',
......
......@@ -296,13 +296,6 @@ class Store {
$config[SYSTEM_SEND_E_MAIL_ABSOLUTE] = $config[SYSTEM_EXT_PATH_ABSOLUTE] . '/Classes/External/sendEmail';
// Make path absolute
foreach ([SYSTEM_MAIL_LOG_ABSOLUTE, SYSTEM_QFQ_LOG_ABSOLUTE, SYSTEM_SQL_LOG_ABSOLUTE] AS $key) {
if (!empty($config[$key]) && $config[$key][0] != '/') {
$config[$key] = HelperFile::joinPathFilename($config[SYSTEM_SITE_PATH_ABSOLUTE], $config[$key]);
}
}
// In case the database credentials are given in the old style: copy them to the new style
if (!isset($config[SYSTEM_DB_1_USER]) && isset($config[SYSTEM_DB_USER])) {
$config[SYSTEM_DB_1_USER] = $config[SYSTEM_DB_USER];
......@@ -354,7 +347,7 @@ class Store {
private static function checkMandatoryParameter(array $config) {
// Check mandatory config vars.
$names = array_merge([SYSTEM_SQL_LOG_ABSOLUTE, SYSTEM_SQL_LOG_MODE],
$names = array_merge([SYSTEM_SQL_LOG_PATHFILENAME, SYSTEM_SQL_LOG_MODE],
self::dbCredentialName($config[SYSTEM_DB_INDEX_DATA]),
self::dbCredentialName($config[SYSTEM_DB_INDEX_QFQ]));
......@@ -640,7 +633,7 @@ class Store {
// Switch FeUser: log this to qfq.log
if ($storeName === STORE_USER && $key == TYPO3_FE_USER) {
$qfqLogPathAbsolute = self::getVar(SYSTEM_QFQ_LOG_ABSOLUTE, STORE_SYSTEM);
$qfqLogPathAbsolute = Path::absoluteQfqLogFile();
$feUserOld = isset($data[$key]) ? $data[$key] : self::getVar($key, STORE_TYPO3 . STORE_EMPTY);
Logger::logMessage(date('Y.m.d H:i:s ') . ": Switch feUser '$feUserOld' to '$value'", $qfqLogPathAbsolute);
}
......
......@@ -10,7 +10,14 @@ use http\Exception;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\QuickFormQuery;
// TODO: replace my own sanitize function with Sanitize::safeFilename
// TODO: define bootstrap function which sets paths and reads config
// TODO: set log + qfq,mail,sql log paths if they are set in config (use empty()) ATTENTION: input might be absolute or relatvie to app
// TODO: after adjusting log paths make sure that SYSTEM_QFQ_LOG_ABSOLUTE usw. are not used anywhere + SYSTEM_EXT_PATH_ABSOLUTE + SYSTEM_SEND_E_MAIL_ABSOLUTE
// TODO: read config before setting log path and read path vars from config when setting. SYSTEM_QFQ_LOG_ABSOLUTE usw.
// TODO: check all cwdToLog() uses. should it not be absolute paths?
// TODO: remove all config related code from Store
// TODO: set setAppRelToCwd() in every api file.
// TODO: Replace all calls to T3Handler::... and Store/T3Info.php with abstraction
// TODO: AS _pagee macht link auf .../index.php . entweder datei umbenennen oder link klasse aendern
......@@ -29,11 +36,18 @@ use IMATHUZH\Qfq\Core\QuickFormQuery;
// TODO: create filePathToQfqConfig() and replace config references with this
// TODO: replace all paths with typo3conf/ (usw.) and /../ and fileadmin/ with correct path computing function.
// TODO: Compare Support::joinPath with Path::join
// TODO: go through all variables/keywords that can be set by user in docs.qfq.io
// Config out of store
// TODO: follow every SYSTEM variable an replace store call with Config getter
// Testing
// TODO: Fix Unittests
// TODO: test if Logger::makePathAbsolute() actually still does what it should (I have changed it)
// Changenotes
// TODO: add breaking change: if sql/qfq/mail log paths were set in Typo3, this info will be lost.
// Misc.
// TODO: TablesorterController.js: pass API url as data attribute instead of hardcode (this.tablesorterApiUrl = 'typo3conf/ext/qfq/Classes/Api/setting.php';)
......
......@@ -443,8 +443,8 @@ class StoreTest extends TestCase {
$config = $this->store->getStore(STORE_SYSTEM);
# The following won't be checked by content, cause they will change on different installations.
foreach ([SYSTEM_SITE_PATH_ABSOLUTE, SYSTEM_EXT_PATH_ABSOLUTE, SYSTEM_SEND_E_MAIL_ABSOLUTE, SYSTEM_SESSION_TIMEOUT_SECONDS, SYSTEM_QFQ_LOG_ABSOLUTE,
SYSTEM_SQL_LOG_ABSOLUTE, SYSTEM_MAIL_LOG_ABSOLUTE, SYSTEM_FILE_MAX_FILE_SIZE] as $key) {
foreach ([SYSTEM_SITE_PATH_ABSOLUTE, SYSTEM_EXT_PATH_ABSOLUTE, SYSTEM_SEND_E_MAIL_ABSOLUTE, SYSTEM_SESSION_TIMEOUT_SECONDS, SYSTEM_QFQ_LOG_PATHFILENAME,
SYSTEM_SQL_LOG_PATHFILENAME, SYSTEM_MAIL_LOG_PATHFILENAME, SYSTEM_FILE_MAX_FILE_SIZE] as $key) {
$this->assertTrue(isset($config[$key]), "Missing default value for '$key' ");
unset ($config[$key]);
}
......
......@@ -80,14 +80,17 @@ sqlLogMode = modify
# cat=debug/sql; type=string; label=SQL log mode for AutoCron:Default is 'error'. Modes see 'sqlLogMode'.
sqlLogModeAutoCron = error
# cat=debug/sql; type=string; label=SQL log file:Default is 'fileadmin/protected/log/sql.log'. A logfile of fired SQL statements. PathFile is absolute or relative to '<site path>'.
sqlLog = fileadmin/protected/log/sql.log
# cat=debug/sql; type=string; label=log directory:Default is '<qfq project path>/log'. Contains all log files. Path is absolute or relative to '<site path>'.
logPath =
# cat=debug/qfq; type=string; label=QFQ log file:Default is 'fileadmin/protected/log/qfq.log'. A logfile of fired SQL statements. PathFile is absolute or relative to '<site path>'.
qfqLog = fileadmin/protected/log/qfq.log
# cat=debug/sql; type=string; label=SQL log file:By default in log directory. A logfile of fired SQL statements. PathFile is absolute or relative to '<site path>'.
sqlLog =
# cat=debug/mail; type=string; label=Mail log file:Default is 'fileadmin/protected/log/mail.log'. A logfile of sent mail. PathFile is absolute or relative to '<site path>'.
mailLog = fileadmin/protected/log/mail.log
# cat=debug/qfq; type=string; label=QFQ log file:By default in log directory. A logfile of fired SQL statements. PathFile is absolute or relative to '<site path>'.
qfqLog =
# cat=debug/mail; type=string; label=Mail log file:By default in log directory. A logfile of sent mail. PathFile is absolute or relative to '<site path>'.
mailLog =
# cat=debug/info; type=string; label=Show debug info:Default is 'auto'. Possible values: [yes|no|auto][,download]. For 'auto': If a BE User is logged in, a debug information will be shown on the FE.
showDebugInfo = auto
......
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