Rev 1185 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1185 | Rev 1197 | ||
---|---|---|---|
Line 43... | Line 43... | ||
43 | $reason = ''; |
43 | $reason = ''; |
44 | return true; |
44 | return true; |
45 | } |
45 | } |
46 | 46 | ||
47 | /** |
47 | /** |
48 | * @param string $event |
48 | * @param OIDplusLogEvent $event |
49 | * @param array $users |
- | |
50 | * @param array $objects |
- | |
51 | * @return bool |
49 | * @return bool |
52 | */ |
50 | */ |
53 | public function log(string $event, array $users, array $objects): bool { |
51 | public function log(OIDplusLogEvent $event): bool { |
54 | if (!is_dir(OIDplus::localpath().'userdata/logs/')) return false; |
52 | if (!is_dir(OIDplus::localpath().'userdata/logs/')) return false; |
55 | 53 | ||
56 | $users_names = array(); |
54 | $users_names = array(); |
57 | foreach ($users as list($severity, $username)) $users_names[] = $username; |
- | |
58 | $users_info = count($users_names) == 0 ? '' : ' ('._L('affected users: %1',implode(', ',$users_names)).')'; |
- | |
59 | - | ||
60 | $objects_names = array(); |
55 | $objects_names = array(); |
61 | foreach ($objects as list($severity, $objectname)) $objects_names[] = $objectname; |
56 | foreach ($event->getTargets() as $target) { |
- | 57 | if ($target instanceof OIDplusLogTargetUser) { |
|
- | 58 | $users_names[] = $target->getUsername(); |
|
- | 59 | } else if ($target instanceof OIDplusLogTargetObject) { |
|
- | 60 | $objects_names[] = $target->getObject(); |
|
- | 61 | } else { |
|
- | 62 | assert(false); |
|
- | 63 | } |
|
- | 64 | } |
|
- | 65 | $users_info = count($users_names) == 0 ? '' : ' ('._L('affected users: %1',implode(', ',$users_names)).')'; |
|
62 | $objects_info = count($objects_names) == 0 ? '' : ' ('._L('affected objects: %1',implode(', ',$objects_names)).')'; |
66 | $objects_info = count($objects_names) == 0 ? '' : ' ('._L('affected objects: %1',implode(', ',$objects_names)).')'; |
63 | 67 | ||
64 | $ts = date('Y-m-d H:i:s'); |
68 | $ts = date('Y-m-d H:i:s'); |
65 | $addr = $_SERVER['REMOTE_ADDR'] ?? _L('unknown'); |
69 | $addr = $_SERVER['REMOTE_ADDR'] ?? _L('unknown'); |
66 | 70 | ||
67 | // Note: $ts was put into brackets, because there is probably a bug in fail2ban that does not allow the date/time being at offset 0 |
71 | // Note: $ts was put into brackets, because there is probably a bug in fail2ban that does not allow the date/time being at offset 0 |
68 | // "WARNING Found a match for '020-05-11 22:50:58 [192.168.69.89] Failed login ..." |
72 | // "WARNING Found a match for '020-05-11 22:50:58 [192.168.69.89] Failed login ..." |
69 | $line = "[$ts] [$addr] $event$users_info$objects_info"; |
73 | $line = "[$ts] [$addr] ".$event->getMessage().$users_info.$objects_info; |
70 | 74 | ||
71 | return @file_put_contents(OIDplus::localpath().'userdata/logs/oidplus.log', "$line\n", FILE_APPEND) !== false; |
75 | return @file_put_contents(OIDplus::localpath().'userdata/logs/oidplus.log', "$line\n", FILE_APPEND) !== false; |
72 | } |
76 | } |
73 | } |
77 | } |
74 | 78 |