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