Commit 03b7dcbf authored by Carsten  Rose's avatar Carsten Rose
Browse files

F6289: formLog 'per session' does not work in API calls - BE_USER is unknown.

parent 483a18c1
......@@ -196,6 +196,12 @@ Download
See PROTOCOL.md > Download
Monitor
-------
Shows files instantly in the browser. Via AJAX request a user defined HTML element will be replaced by the content of the
file. 'frequency' and mode 'replace' / 'append' can be configured. Only files in document root are acessible.
Print
-----
......@@ -249,6 +255,30 @@ Debug / Log
* Check to display debug info:
$this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes'
Form Log
--------
On request (by user in FormEditor) a 'formLog' mode can be activated per individual form. The mode will be disabled after
FORM_LOG_EXPIRE (typically 1800 seconds).
* The formLog button (top of FormEditor) open's the same page with SIP parameter:
* form=<formName>
* _formLogMode=logAll|logSession
* If a form is opened with '_formLogMode' SIP parameter, the form is not shown.
* Instead:
* An empty formLogFile ist created
* Filename: $this->formSpec[formLogFileSession|formLogFileAll]='fileadmin/protected/log/form.<formname>.log' (all) or
form.<formname>.<beuser>log is set.
* A HTML element with htmlid='formLog-1' is rendered together with the AJAX monitor code to the current logFile.
* If a form is instantiated (load, save, udpate, delete), the system checks if corresponding lock files exist.
* Correspondig expired logfiles will be deleted.
* Active logfiles will be filled.
Errormessages & Exceptions
==========================
......
......@@ -51,32 +51,35 @@ $answer[API_STATUS] = API_ANSWER_STATUS_ERROR;
$answer[API_MESSAGE] = '';
try {
$qfq = new QuickFormQuery(['bodytext' => '']);
try {
$qfq = new QuickFormQuery(['bodytext' => '']);
$data = $qfq->updateForm();
$data = $qfq->updateForm();
// $answer[API_REDIRECT] = $qfq->getForwardMode($answer[API_REDIRECT_URL]);
$answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS;
$answer[API_MESSAGE] = 'load: success';
$answer[API_FORM_UPDATE] = $data[API_FORM_UPDATE];
$answer[API_ELEMENT_UPDATE] = $data[API_ELEMENT_UPDATE];
$answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS;
$answer[API_MESSAGE] = 'load: success';
$answer[API_FORM_UPDATE] = $data[API_FORM_UPDATE];
$answer[API_ELEMENT_UPDATE] = $data[API_ELEMENT_UPDATE];
// unset($answer[API_FORM_UPDATE][API_ELEMENT_UPDATE]);
} catch (qfq\UserFormException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
} catch (qfq\UserFormException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
$val = Store::getVar(SYSTEM_FORM_ELEMENT, STORE_SYSTEM);
if ($val !== false)
$answer[API_FIELD_NAME] = $val;
$val = Store::getVar(SYSTEM_FORM_ELEMENT, STORE_SYSTEM);
if ($val !== false)
$answer[API_FIELD_NAME] = $val;
$val = Store::getVar(SYSTEM_FORM_ELEMENT_MESSAGE, STORE_SYSTEM);
if ($val !== false)
$answer[API_FIELD_MESSAGE] = $val;
$val = Store::getVar(SYSTEM_FORM_ELEMENT_MESSAGE, STORE_SYSTEM);
if ($val !== false)
$answer[API_FIELD_MESSAGE] = $val;
} catch (qfq\CodeException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
} catch (qfq\DbException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
}
} catch (qfq\CodeException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
} catch (qfq\DbException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
} catch (\Exception $e) {
$answer[API_MESSAGE] = "Generic Exception: " . $e->getMessage();
}
......
......@@ -24,6 +24,7 @@ const SESSION_NAME = 'qfq';
const SESSION_FE_USER_UID = 'feUserUid';
const SESSION_FE_USER = 'feUser';
const SESSION_FE_USER_GROUP = 'feUserGroup';
const SESSION_BE_USER = 'beUser';
const TABLE_NAME_FORM = 'Form';
const TABLE_NAME_FORM_ELEMENT = 'FormElement';
......@@ -154,7 +155,7 @@ const ERROR_MISSING_MESSAGE_FAIL = 1037;
const ERROR_MISSING_EXPECT_RECORDS = 1038;
const ERROR_MISSING_HIDDEN_FIELD_IN_SIP = 1039;
const ERROR_MISSING_PARAMETER_FILE = 1040;
const ERROR_NO_BE_USER_LOGGED = 1041;
const ERROR_UNKNOWN_CHECKTYPE = 1042;
const ERROR_PATTERN_VIOLATION = 1043;
const ERROR_RECORDID_0_FORBIDDEN = 1044;
......@@ -1306,7 +1307,7 @@ const FORM_LOG_FILE = 'formLogFile';
const FORM_LOG_FILE_SESSION = FORM_LOG_FILE . '_' . FORM_LOG_SESSION;
const FORM_LOG_FILE_ALL = FORM_LOG_FILE . '_' . FORM_LOG_ALL;
const FORM_LOG_FILE_EXPIRE = 1800; // time in seconds after the last
const FORM_LOG_ACTIVE = 'formLogActive';
// DOWNLOAD
const DOWNLOAD_MODE = 'mode';
......
......@@ -715,6 +715,7 @@ class QuickFormQuery {
unlink($file);
} else {
$form[FORM_LOG_FILE . '_' . $mode] = $file;
$form[FORM_LOG_ACTIVE]=1;
}
}
}
......@@ -826,11 +827,16 @@ class QuickFormQuery {
// Set F_FINAL_DELETE_FORM
$formSpec[F_FINAL_DELETE_FORM] = ($formSpec[F_EXTRA_DELETE_FORM] != '') ? $formSpec[F_EXTRA_DELETE_FORM] : $formSpec[F_NAME];
// LOG
!empty($form[FORM_LOG_ACTIVE]) && Logger::logFormLine($form, "F:$mode:evaluated:" . date('Y-m-d H:i:s'), $form, true);
// Fire FE_FILL_STORE_VAR after the primary form record has been loaded
if (!empty($fillStoreVar)) {
$rows = $this->eval->parse($fillStoreVar);
if (is_array($rows)) {
$this->store->appendToStore($rows[0], STORE_VAR);
// LOG
!empty($form[FORM_LOG_ACTIVE]) && Logger::logFormLine($form, "F:add to STORE_VAR", $rows[0]);
} else {
if (!empty($rows)) {
throw new UserFormException("Invalid statement for '" . FE_FILL_STORE_VAR . "': " . $formSpec[FE_FILL_STORE_VAR], ERROR_INVALID_OR_MISSING_PARAMETER);
......
......@@ -45,6 +45,7 @@ class Save {
* @throws CodeException
* @throws DbException
* @throws UserFormException
* @throws UserReportException
*/
public function __construct(array $formSpec, array $feSpecAction, array $feSpecNative, array $feSpecNativeRaw) {
$this->formSpec = $formSpec;
......
......@@ -34,10 +34,13 @@ class AbstractException extends \Exception {
protected $line = '';
/**
* There are 3+1 different messages:
* 'toUser' - shown in the client to the user - no details here!!!
* 'support' - help for the developer
* 'os' - message from the OS, like 'file not found'
* $this->getMessage() might give a) a simple string or b) an JSON String.
*
* JSON String: There are 3+1 different messages:
* [ERROR_MESSAGE_TO_USER] 'toUser' - shown in the client to the user - no details here!!!
* [ERROR_MESSAGE_SUPPORT] 'support' - help for the developer
* [ERROR_MESSAGE_OS] 'os' - message from the OS, like 'file not found'
*
* Stacktrace, Form, FormElement, Report level, T3 page, T3 tt_content uid, ...
*
* @return string
......
......@@ -19,11 +19,15 @@ require_once(__DIR__ . '/AbstractException.php');
*/
class CodeException extends AbstractException {
/*
* @return string HTML formatted error string
*/
/**
* @return string
* $this->getMessage() might give a) a simple string or b) an JSON String.
*
* JSON String: There are 3+1 different messages:
* [ERROR_MESSAGE_TO_USER] 'toUser' - shown in the client to the user - no details here!!!
* [ERROR_MESSAGE_SUPPORT] 'support' - help for the developer
* [ERROR_MESSAGE_OS] 'os' - message from the OS, like 'file not found'
*
* @return string HTML formatted error string
* @throws CodeException
* @throws UserFormException
*/
......
......@@ -20,10 +20,15 @@ require_once(__DIR__ . '/AbstractException.php');
*/
class DbException extends AbstractException {
/*
* @return string HTML formatted error string
*/
/**
* $this->getMessage() might give a) a simple string or b) an JSON String.
*
* JSON String: There are 3+1 different messages:
* [ERROR_MESSAGE_TO_USER] 'toUser' - shown in the client to the user - no details here!!!
* [ERROR_MESSAGE_SUPPORT] 'support' - help for the developer
* [ERROR_MESSAGE_OS] 'os' - message from the OS, like 'file not found'
*
* @return string HTML formatted error string
* @return string
* @throws CodeException
* @throws UserFormException
......
......@@ -19,10 +19,15 @@ require_once(__DIR__ . '/AbstractException.php');
*/
class DownloadException extends AbstractException {
/*
* @return string HTML formatted error string
*/
/**
* $this->getMessage() might give a) a simple string or b) an JSON String.
*
* JSON String: There are 3+1 different messages:
* [ERROR_MESSAGE_TO_USER] 'toUser' - shown in the client to the user - no details here!!!
* [ERROR_MESSAGE_SUPPORT] 'support' - help for the developer
* [ERROR_MESSAGE_OS] 'os' - message from the OS, like 'file not found'
*
* @return string HTML formatted error string
* @return string
* @throws CodeException
* @throws UserFormException
......
......@@ -19,10 +19,15 @@ require_once(__DIR__ . '/AbstractException.php');
*/
class ShellException extends AbstractException {
/*
* @return string HTML formatted error string
*/
/**
* $this->getMessage() might give a) a simple string or b) an JSON String.
*
* JSON String: There are 3+1 different messages:
* [ERROR_MESSAGE_TO_USER] 'toUser' - shown in the client to the user - no details here!!!
* [ERROR_MESSAGE_SUPPORT] 'support' - help for the developer
* [ERROR_MESSAGE_OS] 'os' - message from the OS, like 'file not found'
*
* @return string HTML formatted error string
* @return string
* @throws CodeException
* @throws UserFormException
......
......@@ -21,6 +21,13 @@ require_once(__DIR__ . '/AbstractException.php');
class UserFormException extends AbstractException {
/**
* $this->getMessage() might give a) a simple string or b) an JSON String.
*
* JSON String: There are 3+1 different messages:
* [ERROR_MESSAGE_TO_USER] 'toUser' - shown in the client to the user - no details here!!!
* [ERROR_MESSAGE_SUPPORT] 'support' - help for the developer
* [ERROR_MESSAGE_OS] 'os' - message from the OS, like 'file not found'
*
* @return string
* @throws CodeException
* @throws UserFormException
......
......@@ -19,10 +19,15 @@ require_once(__DIR__ . '/AbstractException.php');
*/
class UserReportException extends AbstractException {
/*
* @return string HTML formatted error string
*/
/**
* $this->getMessage() might give a) a simple string or b) an JSON String.
*
* JSON String: There are 3+1 different messages:
* [ERROR_MESSAGE_TO_USER] 'toUser' - shown in the client to the user - no details here!!!
* [ERROR_MESSAGE_SUPPORT] 'support' - help for the developer
* [ERROR_MESSAGE_OS] 'os' - message from the OS, like 'file not found'
*
* @return string HTML formatted error string
* @return string
* @throws CodeException
* @throws UserFormException
......
......@@ -19,7 +19,7 @@ require_once(__DIR__ . '/../helper/Support.php');
class Logger {
/**
* Haengt $msg an $filename an
* Append $msg to $filename.
*
* @param $msg
* @param $filename
......@@ -56,7 +56,7 @@ class Logger {
*/
public static function linePre() {
$str = '=== [' . date('Y-m-d H:i:s');
$str .= ' / ' . htmlentities(empty($_SERVER['REMOTE_ADDR'])? '<no ip>' : $_SERVER['REMOTE_ADDR']);
$str .= ' / ' . htmlentities(empty($_SERVER['REMOTE_ADDR']) ? '<no ip>' : $_SERVER['REMOTE_ADDR']);
$str .= ' / ' . htmlentities(empty($_SERVER['HTTP_USER_AGENT']) ? '<no user agent>' : $_SERVER['HTTP_USER_AGENT']);
$str .= '] ';
......@@ -75,4 +75,29 @@ class Logger {
return $fe['id'] . ' / ' . $fe[FE_NAME] . ' / ' . $fe[FE_LABEL];
}
/**
* Logs a line to all of the given logfiles.
* If $data is an array, it will be json encoded.
*
* @param array $form
* @param $pre
* @param $data
* @throws UserFormException
*/
public static function logFormLine(array $form, $pre, $data, $flagNewLineFirst = false) {
$line = (is_array($data)) ? json_encode($data) : $data;
$line = '[' . $pre . '] ' . $line;
if($flagNewLineFirst){
$line = PHP_EOL . $line;
}
foreach ([FORM_LOG_FILE_ALL, FORM_LOG_FILE_SESSION] as $filename) {
if (!empty($form[$filename])) {
Logger::logMessage($line, $form[$filename]);
}
}
}
}
\ No newline at end of file
......@@ -78,6 +78,9 @@ class Support {
break;
case FORM_LOG_SESSION:
$perBeSession = self::$store->getVar(TYPO3_BE_USER, STORE_TYPO3) . '.';
if(empty($perBeSession)){
throw new UserFormException('formLog: no BE User logged in', ERROR_NO_BE_USER_LOGGED);
}
break;
default:
throw new CodeException('Unknown mode: ' . $formLogMode, ERROR_UNKNOWN_TOKEN);
......
......@@ -64,7 +64,8 @@ class Session {
/**
* Extract the SitePath of the current T3 installation.
*
* return: <path> with a trailing '/'
* @return bool|string - <path> with a trailing '/'
* @throws CodeException
*/
private static function getSitePath() {
......@@ -158,6 +159,7 @@ class Session {
$feUidLoggedIn = isset($GLOBALS["TSFE"]->fe_user->user["uid"]) ? $GLOBALS["TSFE"]->fe_user->user["uid"] : false;
$feUserSession = isset($GLOBALS["TSFE"]->fe_user->user["username"]) ? $GLOBALS["TSFE"]->fe_user->user["username"] : false;
$feUserGroup = isset($GLOBALS["TSFE"]->fe_user->user["usergroup"]) ? $GLOBALS["TSFE"]->fe_user->user["usergroup"] : false;
$beUser = isset($GLOBALS["BE_USER"]->user["username"]) ? $GLOBALS["BE_USER"]->user["username"] : false;
} else {
// If we are called through API there is no T3 environment. Assume nothing has changed, and fake the following check to always 'no change'.
$feUidLoggedIn = $feUserUidSession;
......@@ -171,6 +173,7 @@ class Session {
Session::set(SESSION_FE_USER_UID, $feUidLoggedIn);
Session::set(SESSION_FE_USER, $feUserSession);
Session::set(SESSION_FE_USER_GROUP, $feUserGroup);
Session::set(SESSION_BE_USER, $beUser);
// throw new UserFormException("FYI: Session has been cleared. Reload this page. ".
// "feUserUidSession:'$feUserUidSession', feUserSession:'$feUserSession' isset(TSFE):'" . isset($GLOBALS["TSFE"]) ? 'true' : 'false' );
......
......@@ -373,7 +373,7 @@ class Store {
} else {
// No T3 environment (called by API): restore from SESSION
foreach ([SESSION_FE_USER, SESSION_FE_USER_UID, SESSION_FE_USER_GROUP] as $key) {
foreach ([SESSION_FE_USER, SESSION_FE_USER_UID, SESSION_FE_USER_GROUP, SESSION_BE_USER] as $key) {
if (isset($_SESSION[SESSION_NAME][$key])) {
$arr[$key] = $_SESSION[SESSION_NAME][$key];
}
......
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