mirror of https://github.com/MISP/MISP
chg: [internal] Code cleanup for logging
parent
786becad1a
commit
6eb5a66878
|
@ -25,11 +25,7 @@ class AuditLog extends AppModel
|
|||
ACTION_REMOVE_GALAXY = 'remove_galaxy',
|
||||
ACTION_REMOVE_GALAXY_LOCAL = 'remove_local_galaxy',
|
||||
ACTION_PUBLISH = 'publish',
|
||||
ACTION_PUBLISH_SIGHTINGS = 'publish_sightings',
|
||||
ACTION_LOGIN = 'login',
|
||||
ACTION_PASSWDCHANGE = 'password_change',
|
||||
ACTION_LOGOUT = 'logout',
|
||||
ACTION_LOGIN_FAILED = 'login_failed';
|
||||
ACTION_PUBLISH_SIGHTINGS = 'publish_sightings';
|
||||
|
||||
const REQUEST_TYPE_DEFAULT = 0,
|
||||
REQUEST_TYPE_API = 1,
|
||||
|
|
|
@ -159,11 +159,6 @@ class Log extends AppModel
|
|||
if (!in_array($this->data['Log']['model'], ['Log', 'Workflow'])) {
|
||||
$trigger_id = 'log-after-save';
|
||||
$workflowErrors = [];
|
||||
$logging = [
|
||||
'model' => 'Log',
|
||||
'action' => 'execute_workflow',
|
||||
'id' => $this->data['Log']['user_id']
|
||||
];
|
||||
$this->executeTrigger($trigger_id, $this->data, $workflowErrors);
|
||||
}
|
||||
return true;
|
||||
|
@ -206,7 +201,7 @@ class Log extends AppModel
|
|||
$validDates = $this->query($sql);
|
||||
}
|
||||
$data = array();
|
||||
foreach ($validDates as $k => $date) {
|
||||
foreach ($validDates as $date) {
|
||||
$data[$date[0]['Date']] = intval($date[0]['count']);
|
||||
}
|
||||
return $data;
|
||||
|
@ -286,7 +281,7 @@ class Log extends AppModel
|
|||
public function validationError($user, $action, $model, $title, array $validationErrors, array $fullObject)
|
||||
{
|
||||
$this->log($title, LOG_WARNING);
|
||||
$change = 'Validation errors: ' . json_encode($validationErrors) . ' Full ' . $model . ': ' . json_encode($fullObject);
|
||||
$change = 'Validation errors: ' . JsonTool::encode($validationErrors) . ' Full ' . $model . ': ' . JsonTool::encode($fullObject);
|
||||
$this->createLogEntry($user, $action, $model, 0, $title, $change);
|
||||
}
|
||||
|
||||
|
@ -365,7 +360,7 @@ class Log extends AppModel
|
|||
}
|
||||
}
|
||||
|
||||
public function logData($data)
|
||||
private function logData(array $data)
|
||||
{
|
||||
if ($this->pubToZmq('audit')) {
|
||||
$this->getPubSubTool()->publish($data, 'audit', 'log');
|
||||
|
@ -386,6 +381,13 @@ class Log extends AppModel
|
|||
}
|
||||
|
||||
// write to syslogd as well if enabled
|
||||
$this->sendToSyslog($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function sendToSyslog(array $data)
|
||||
{
|
||||
if ($this->syslog === null) {
|
||||
if (Configure::read('Security.syslog')) {
|
||||
$options = [];
|
||||
|
@ -424,7 +426,6 @@ class Log extends AppModel
|
|||
}
|
||||
$this->syslog->write($action, $entry);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function filterSiteAdminSensitiveLogs($list)
|
||||
|
|
|
@ -1265,37 +1265,44 @@ class User extends AppModel
|
|||
return $newkey;
|
||||
}
|
||||
|
||||
public function extralog($user, $action = null, $description = null, $fieldsResult = null, $modifiedUser = null)
|
||||
/**
|
||||
* @param string|array $user
|
||||
* @param string $action
|
||||
* @param string $description
|
||||
* @param string $fieldsResult
|
||||
* @param array|null $modifiedUser
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function extralog($user, $action, $description = null, $fieldsResult = null, $modifiedUser = null)
|
||||
{
|
||||
if (!is_array($user) && $user === 'SYSTEM') {
|
||||
if ($user === 'SYSTEM') {
|
||||
$user = [
|
||||
'id' => 0,
|
||||
'email' => 'SYSTEM',
|
||||
'Organisation' => [
|
||||
'name' => 'SYSTEM'
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
// new data
|
||||
$model = 'User';
|
||||
$modelId = $user['id'];
|
||||
if (!empty($modifiedUser)) {
|
||||
$modelId = $modifiedUser['User']['id'];
|
||||
}
|
||||
if ($action == 'login') {
|
||||
if ($action === 'login') {
|
||||
$description = "User (" . $user['id'] . "): " . $user['email'];
|
||||
$fieldsResult = json_encode($this->UserLoginProfile->_getUserProfile());
|
||||
} elseif ($action == 'logout') {
|
||||
$fieldsResult = JsonTool::encode($this->UserLoginProfile->_getUserProfile());
|
||||
} else if ($action === 'logout') {
|
||||
$description = "User (" . $user['id'] . "): " . $user['email'];
|
||||
} elseif ($action == 'edit') {
|
||||
} else if ($action === 'edit') {
|
||||
$description = "User (" . $modifiedUser['User']['id'] . "): " . $modifiedUser['User']['email'];
|
||||
} elseif ($action == 'change_pw') {
|
||||
} else if ($action === 'change_pw') {
|
||||
$description = "User (" . $modifiedUser['User']['id'] . "): " . $modifiedUser['User']['email'];
|
||||
$fieldsResult = "Password changed.";
|
||||
}
|
||||
|
||||
// query
|
||||
$result = $this->loadLog()->createLogEntry($user, $action, $model, $modelId, $description, $fieldsResult);
|
||||
$result = $this->loadLog()->createLogEntry($user, $action, 'User', $modelId, $description, $fieldsResult);
|
||||
// write to syslogd as well
|
||||
if ($result) {
|
||||
App::import('Lib', 'SysLog.SysLog');
|
||||
|
|
Loading…
Reference in New Issue