Rev 790 | Rev 1086 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
||
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 | |||
1050 | daniel-mar | 20 | namespace ViaThinkSoft\OIDplus; |
635 | daniel-mar | 21 | |
22 | class OIDplusLoggerPluginDatabase extends OIDplusLoggerPlugin { |
||
23 | |||
24 | public static function available(&$reason)/*: bool*/ { |
||
25 | $reason = ''; |
||
26 | return true; |
||
27 | } |
||
28 | |||
29 | public static function log($event, $users, $objects)/*: bool*/ { |
||
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)); |
||
32 | $log_id = OIDplus::dbIsolated()->insert_id(); |
||
33 | if ($log_id === false) { |
||
34 | $res = OIDplus::dbIsolated()->query("select max(id) as last_id from ###log"); |
||
790 | daniel-mar | 35 | if (!$res->any()) throw new OIDplusException(_L('Could not log event')); |
635 | daniel-mar | 36 | $row = $res->fetch_array(); |
37 | $log_id = $row['last_id']; |
||
38 | if ($log_id == 0) throw new OIDplusException(_L('Could not log event')); |
||
39 | } |
||
40 | |||
41 | $object_dupe_check = array(); |
||
42 | foreach ($objects as list($severity, $object)) { |
||
43 | if (in_array($object, $object_dupe_check)) continue; |
||
44 | $object_dupe_check[] = $object; |
||
45 | OIDplus::dbIsolated()->query("insert into ###log_object (log_id, severity, object) values (?, ?, ?)", array($log_id, $severity, $object)); |
||
46 | } |
||
47 | |||
48 | $user_dupe_check = array(); |
||
49 | foreach ($users as list($severity, $username)) { |
||
50 | if (in_array($username, $user_dupe_check)) continue; |
||
51 | $user_dupe_check[] = $username; |
||
52 | OIDplus::dbIsolated()->query("insert into ###log_user (log_id, severity, username) values (?, ?, ?)", array($log_id, $severity, $username)); |
||
53 | } |
||
54 | |||
55 | return true; |
||
56 | } |
||
57 | |||
786 | daniel-mar | 58 | } |