Newer
Older
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
*
* This file is part of Maarch Framework.
*
* Maarch Framework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Maarch Framework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @brief Contains all the function to manage the history table
*
* <ul>
* <li>Connexion logs and events history management</li>
* </ul>
* @file
* @author Claire Figueras <dev@maarch.org>
* @author Cyril Vazquez <dev@maarch.org>
* @author Arnaud Veber <dev@maarch.org>
* @date $date$
* @version $Revision$
* @ingroup core
*/
/**
* @brief Contains all the function to manage the history table
*
* @ingroup core
*/
if (!defined('_LOG4PHP')) {
if (!defined('_BDD')) {
if (!defined('_LOGGER_NAME_TECH_DEFAULT')) {
define(
'_LOGGER_NAME_TECH_DEFAULT',
'loggerTechnique'
);
if (!defined('_LOGGER_NAME_FUNC_DEFAULT')) {
define(
'_LOGGER_NAME_FUNC_DEFAULT',
'loggerFonctionnel'
);
require_once('core/class/class_functions.php');
require_once('core/class/class_db_pdo.php');
require_once('apps/maarch_entreprise/tools/log4php/Logger.php');
require_once('core/core_tables.php');
{
/**
* Inserts a record in the history table
*
* @param $table_name
* @param $record_id
* @param $event_type
* @param $event_id
* @param $info
* @param $databasetype
* @param $id_module = 'admin'
* @param $isTech = false
* @param $result = _OK
* @param $level = _LEVEL_DEBUG
* @param $user = ''
*/
public function add(
$table_name,
$record_id,
$event_type,
$event_id,
$info,
$databasetype,
$id_module = 'admin',
$isTech = false,
if ($_SERVER['REMOTE_ADDR'] == '::1') {
$REMOTE_ADDR = 'localhost';
} else {
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
}
$remote_ip = $REMOTE_ADDR;
if (empty($user)) {
$user = '';
}
if (isset($_SESSION['user']['UserId'])) {
$user = $_SESSION['user']['UserId'];
}
\SrcCore\models\ValidatorModel::notEmpty(['user' => $user], ['user']);
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
$traceInformations = array(
'WHERE' => $table_name,
'ID' => $record_id,
'HOW' => $event_type,
'USER' => $user,
'WHAT' => $event_id,
'ID_MODULE' => $id_module,
'REMOTE_IP' => $remote_ip,
'DATABASE_TYPE' => $databasetype,
'RESULT' => $result,
'LEVEL' => $level
);
$this->build_logging_method();
foreach ($_SESSION['logging_method_memory'] as $logging_method) {
if ($logging_method['ACTIVATED'] == true) {
if ($logging_method['ID'] == _LOG4PHP) {
if ($logging_method['LOGGER_NAME_TECH'] == "") {
$logging_method['LOGGER_NAME_TECH'] = _LOGGER_NAME_TECH_DEFAULT;
}
if ($logging_method['LOGGER_NAME_FUNC'] == "") {
$logging_method['LOGGER_NAME_FUNC'] = _LOGGER_NAME_FUNC_DEFAULT;
}
$this->addToLog4php(
$traceInformations,
$logging_method,
$isTech
);
}
}
}
if (!$isTech) {
.$_SESSION['tablename']['history']." ("
."table_name, "
."record_id, "
."event_type, "
."event_id, "
."user_id, "
."event_date, "
."info, "
."id_module, "
."remote_ip"
.") "
."VALUES (?, ?, ?, ?, ?, "
. $db->current_datetime()
. ", ?, ?, ?)";
$db->query(
$queryHist,
array(
$table_name,
$record_id,
$event_type,
$event_id,
$user,
$info,
$id_module,
$remote_ip
)
echo $info;
exit;
* @param $str string
* @param $charset = 'utf-8' (string)
*/
private function wd_remove_accents(
$str,
$charset ='utf-8'
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
$str = htmlentities(
$str,
ENT_NOQUOTES,
"utf-8"
);
$str = preg_replace(
'#\&([A-za-z])(?:uml|circ|tilde|acute|grave|cedil|ring)\;#',
'\1',
$str
);
$str = preg_replace(
'#\&([A-za-z]{2})(?:lig)\;#',
'\1',
$str
);
$str = preg_replace(
'#\&[^;]+\;#',
'',
$str
);
return $str;
}
/**
* Get the logging method in the configuration file
*/
private function build_logging_method()
{
$xmlFileName = 'logging_method.xml';
$pathToXmlLogin = '';
if (!isset($_SESSION['logging_method_memory'])) {
if (file_exists(
$_SESSION['config']['corepath'].'custom'
.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
.DIRECTORY_SEPARATOR . 'apps'
.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id']
.DIRECTORY_SEPARATOR.'xml'
.DIRECTORY_SEPARATOR.$xmlFileName
)) {
$pathToXmlLogin = $_SESSION['config']['corepath'].'custom'
.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
.DIRECTORY_SEPARATOR.'apps'
.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id']
.DIRECTORY_SEPARATOR.'xml'
.DIRECTORY_SEPARATOR.$xmlFileName;
} elseif (file_exists(
'apps'
.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id']
.DIRECTORY_SEPARATOR.'xml'
.DIRECTORY_SEPARATOR.$xmlFileName
)) {
$pathToXmlLogin = 'apps'
.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id']
.DIRECTORY_SEPARATOR.'xml'
.DIRECTORY_SEPARATOR.$xmlFileName;
} else {
$noXml = true;
$logging_methods[0]['ID'] = 'database';
$logging_methods[0]['ACTIVATED'] = true;
$logging_methods[1]['ID'] = 'log4php';
$logging_methods[1]['ACTIVATED'] = true;
$logging_methods[1]['LOGGER_NAME_TECH'] = 'loggerTechnique';
$logging_methods[1]['LOGGER_NAME_FUNC'] = 'loggerFonctionnel';
$logging_methods[1]['LOG_FORMAT'] = '[%RESULT%][%CODE_METIER%][%WHERE%][%ID%][%HOW%][%USER%][%WHAT%][%ID_MODULE%][%REMOTE_IP%]';
$logging_methods[1]['CODE_METIER'] = 'MAARCH';
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
}
if (!isset($noXml)) {
$logging_methods = array();
$xmlConfig = simplexml_load_file($pathToXmlLogin);
if (! $xmlConfig) {
exit();
}
foreach ($xmlConfig->METHOD as $METHOD) {
$id = ((string)$METHOD->ID);
$activated = ((boolean)$METHOD->ENABLED);
$loggerNameTech = ((string)$METHOD->LOGGER_NAME_TECH);
$loggerNameFunc = ((string)$METHOD->LOGGER_NAME_FUNC);
$logFormat = ((string)$METHOD->APPLI_LOG_FORMAT);
$codeMetier = ((string)$METHOD->CODE_METIER);
array_push(
$logging_methods,
array(
'ID' => $id,
'ACTIVATED' => $activated,
'LOGGER_NAME_TECH' => $loggerNameTech,
'LOGGER_NAME_FUNC' => $loggerNameFunc,
'LOG_FORMAT' => $logFormat,
'CODE_METIER' => $codeMetier
)
);
}
}
$_SESSION['logging_method_memory'] = $logging_methods;
}
}
/**
* Write a log entry with a specific log level
*
* @param $logger (object) => Log4php logger
* @param $logLine (string) => Line we want to trace
* @param $level (enum) => Log level
*/
private function writeLog(
$logger,
$logLine,
$level
$formatter = new functions();
$logLine = $formatter->wash_html(
$logLine,
''
);
$logLine = $this->wd_remove_accents(
$logLine
);
switch ($level) {
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
$logger->debug(
$logLine
);
break;
case _LEVEL_INFO:
$logger->info(
$logLine
);
break;
case _LEVEL_WARN:
$logger->warn(
$logLine
);
break;
case _LEVEL_ERROR:
$logger->error(
$logLine
);
break;
case _LEVEL_FATAL:
$logger->fatal(
$logLine
);
break;
}
}
/**
* Insert a log line into log4php
*
* @param $traceInformations (array) => Informations to trace
* @param $logging_method (string) => Array of XML attributes
* @param $isTech (boolean) => Says if the log is technical (true) or functional (false)
*/
private function addToLog4php(
$traceInformations,
$logging_method,
$isTech
if (!isset($_SESSION['user']['loginmode'])) {
$_SESSION['user']['loginmode'] = '';
}
if (!isset($_SESSION['user']['department'])) {
$_SESSION['user']['department'] = '';
}
. DIRECTORY_SEPARATOR . $_SESSION['custom_override_id']
. DIRECTORY_SEPARATOR . "apps"
. DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
. DIRECTORY_SEPARATOR . "xml"
. DIRECTORY_SEPARATOR . "log4php.xml"
)) {
$configFileLog4PHP = 'custom'
. DIRECTORY_SEPARATOR . $_SESSION['custom_override_id']
. DIRECTORY_SEPARATOR . "apps"
. DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
. DIRECTORY_SEPARATOR . "xml"
. DIRECTORY_SEPARATOR . "log4php.xml";
} elseif (file_exists(
. DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
. DIRECTORY_SEPARATOR . "xml"
. DIRECTORY_SEPARATOR . "log4php.xml"
)) {
$configFileLog4PHP = "apps"
. DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
. DIRECTORY_SEPARATOR . "xml"
. DIRECTORY_SEPARATOR . "log4php.xml";
} else {
$configFileLog4PHP = "apps"
. DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
. DIRECTORY_SEPARATOR . "xml"
. DIRECTORY_SEPARATOR . "log4php.default.xml";
}
Logger::configure(
$configFileLog4PHP
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
);
if ($isTech) {
$logger = Logger::getLogger(
$logging_method['LOGGER_NAME_TECH']
);
} else {
$logger = Logger::getLogger(
$logging_method['LOGGER_NAME_FUNC']
);
}
$connexionMode = '';
if (isset($_SESSION['user_sso']['dggn']['connection_mode'])) {
$connexionMode = $_SESSION['user_sso']['dggn']['connection_mode'];
}
$department = '';
if (isset($_SESSION['user']['department'])) {
$department = $_SESSION['user']['department'];
}
$primaryGroup = '';
if (isset($_SESSION['user_sso']['dggn']['userGroup'])) {
$primaryGroup = $_SESSION['user_sso']['dggn']['userGroup'];
}
$searchPatterns = array(
'%RESULT%',
'%CODE_METIER%',
'%WHERE%',
'%ID%',
'%HOW%',
'%USER%',
'%WHAT%',
'%ID_MODULE%',
'%REMOTE_IP%'
);
$replacePatterns = array(
$traceInformations['RESULT'],
$logging_method['CODE_METIER'],
$traceInformations['WHERE'],
$traceInformations['ID'],
$traceInformations['HOW'],
$traceInformations['USER'],
$traceInformations['WHAT'],
$traceInformations['ID_MODULE'],
$traceInformations['REMOTE_IP']
);
$logLine = str_replace(
$searchPatterns,
$replacePatterns,
$logging_method['LOG_FORMAT']
);
$this->writeLog(
$logger,
$logLine,
$traceInformations['LEVEL']
);
}
}