Rev 496 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
295 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
295 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
511 | daniel-mar | 20 | if (!defined('INSIDE_OIDPLUS')) die(); |
21 | |||
295 | daniel-mar | 22 | class OIDplusLoggerPluginUserdataLogfile extends OIDplusLoggerPlugin { |
23 | |||
24 | public static function available(&$reason)/*: bool*/ { |
||
496 | daniel-mar | 25 | if (!is_dir(OIDplus::localpath().'userdata/logs/')) { |
360 | daniel-mar | 26 | $reason = _L('Directory userdata/logs/ not existing'); |
295 | daniel-mar | 27 | return false; |
28 | } |
||
29 | |||
496 | daniel-mar | 30 | if (@file_put_contents(OIDplus::localpath().'userdata/logs/oidplus.log', '', FILE_APPEND) === false) { |
360 | daniel-mar | 31 | $reason = _L('File userdata/logs/oidplus.log not writeable'); |
295 | daniel-mar | 32 | return false; |
33 | } |
||
34 | |||
35 | $reason = ''; |
||
36 | return true; |
||
37 | } |
||
38 | |||
39 | public static function log($event, $users, $objects)/*: bool*/ { |
||
496 | daniel-mar | 40 | if (!is_dir(OIDplus::localpath().'userdata/logs/')) return false; |
295 | daniel-mar | 41 | |
42 | $users_names = array(); |
||
43 | foreach ($users as list($severity, $username)) $users_names[] = $username; |
||
360 | daniel-mar | 44 | $users_info = count($users_names) == 0 ? '' : ' ('._L('affected users: %1',implode(', ',$users_names)).')'; |
295 | daniel-mar | 45 | |
46 | $objects_names = array(); |
||
310 | daniel-mar | 47 | foreach ($objects as list($severity, $objectname)) $objects_names[] = $objectname; |
360 | daniel-mar | 48 | $objects_info = count($objects_names) == 0 ? '' : ' ('._L('affected objects: %1',implode(', ',$objects_names)).')'; |
295 | daniel-mar | 49 | |
50 | $ts = date('Y-m-d H:i:s'); |
||
360 | daniel-mar | 51 | $addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : _L('unknown'); |
295 | daniel-mar | 52 | |
298 | daniel-mar | 53 | // 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 |
54 | // "WARNING Found a match for '020-05-11 22:50:58 [192.168.69.89] Failed login ..." |
||
55 | $line = "[$ts] [$addr] $event$users_info$objects_info"; |
||
56 | |||
496 | daniel-mar | 57 | return @file_put_contents(OIDplus::localpath().'userdata/logs/oidplus.log', "$line\n", FILE_APPEND) !== false; |
295 | daniel-mar | 58 | } |
360 | daniel-mar | 59 | } |