Rev 790 | Rev 1086 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 790 | 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 OIDplusLoggerPluginDatabase extends OIDplusLoggerPlugin { |
22 | class OIDplusLoggerPluginDatabase extends OIDplusLoggerPlugin { |
23 | 23 | ||
24 | public static function available(&$reason)/*: bool*/ { |
24 | public static function available(&$reason)/*: bool*/ { |
25 | $reason = ''; |
25 | $reason = ''; |
26 | return true; |
26 | return true; |
27 | } |
27 | } |
28 | 28 | ||
29 | public static function log($event, $users, $objects)/*: bool*/ { |
29 | public static function log($event, $users, $objects)/*: bool*/ { |
30 | $addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; |
30 | $addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; |
31 | OIDplus::dbIsolated()->query("insert into ###log (addr, unix_ts, event) values (?, ?, ?)", array($addr, time(), $event)); |
31 | OIDplus::dbIsolated()->query("insert into ###log (addr, unix_ts, event) values (?, ?, ?)", array($addr, time(), $event)); |
32 | $log_id = OIDplus::dbIsolated()->insert_id(); |
32 | $log_id = OIDplus::dbIsolated()->insert_id(); |
33 | if ($log_id === false) { |
33 | if ($log_id === false) { |
34 | $res = OIDplus::dbIsolated()->query("select max(id) as last_id from ###log"); |
34 | $res = OIDplus::dbIsolated()->query("select max(id) as last_id from ###log"); |
35 | if (!$res->any()) throw new OIDplusException(_L('Could not log event')); |
35 | if (!$res->any()) throw new OIDplusException(_L('Could not log event')); |
36 | $row = $res->fetch_array(); |
36 | $row = $res->fetch_array(); |
37 | $log_id = $row['last_id']; |
37 | $log_id = $row['last_id']; |
38 | if ($log_id == 0) throw new OIDplusException(_L('Could not log event')); |
38 | if ($log_id == 0) throw new OIDplusException(_L('Could not log event')); |
39 | } |
39 | } |
40 | 40 | ||
41 | $object_dupe_check = array(); |
41 | $object_dupe_check = array(); |
42 | foreach ($objects as list($severity, $object)) { |
42 | foreach ($objects as list($severity, $object)) { |
43 | if (in_array($object, $object_dupe_check)) continue; |
43 | if (in_array($object, $object_dupe_check)) continue; |
44 | $object_dupe_check[] = $object; |
44 | $object_dupe_check[] = $object; |
45 | OIDplus::dbIsolated()->query("insert into ###log_object (log_id, severity, object) values (?, ?, ?)", array($log_id, $severity, $object)); |
45 | OIDplus::dbIsolated()->query("insert into ###log_object (log_id, severity, object) values (?, ?, ?)", array($log_id, $severity, $object)); |
46 | } |
46 | } |
47 | 47 | ||
48 | $user_dupe_check = array(); |
48 | $user_dupe_check = array(); |
49 | foreach ($users as list($severity, $username)) { |
49 | foreach ($users as list($severity, $username)) { |
50 | if (in_array($username, $user_dupe_check)) continue; |
50 | if (in_array($username, $user_dupe_check)) continue; |
51 | $user_dupe_check[] = $username; |
51 | $user_dupe_check[] = $username; |
52 | OIDplus::dbIsolated()->query("insert into ###log_user (log_id, severity, username) values (?, ?, ?)", array($log_id, $severity, $username)); |
52 | OIDplus::dbIsolated()->query("insert into ###log_user (log_id, severity, username) values (?, ?, ?)", array($log_id, $severity, $username)); |
53 | } |
53 | } |
54 | 54 | ||
55 | return true; |
55 | return true; |
56 | } |
56 | } |
57 | 57 | ||
58 | } |
58 | } |
59 | 59 |