Subversion Repositories oidplus

Rev

Rev 325 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
289 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 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
 
20
class OIDplusLoggerPluginDatabase extends OIDplusLoggerPlugin {
21
 
22
        public static function available(&$reason)/*: bool*/ {
23
                $reason = '';
24
                return true;
25
        }
26
 
27
        public static function log($event, $users, $objects)/*: bool*/ {
325 daniel-mar 28
                $addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
295 daniel-mar 29
                OIDplus::dbIsolated()->query("insert into ###log (addr, unix_ts, event) values (?, ?, ?)", array($addr, time(), $event));
30
                $log_id = OIDplus::dbIsolated()->insert_id();
289 daniel-mar 31
                if ($log_id === false) {
295 daniel-mar 32
                        $res = OIDplus::dbIsolated()->query("select max(id) as last_id from ###log");
360 daniel-mar 33
                        if ($res->num_rows() == 0) throw new OIDplusException(_L('Could not log event'));
289 daniel-mar 34
                        $row = $res->fetch_array();
35
                        $log_id = $row['last_id'];
360 daniel-mar 36
                        if ($log_id == 0) throw new OIDplusException(_L('Could not log event'));
289 daniel-mar 37
                }
38
 
39
                $object_dupe_check = array();
40
                foreach ($objects as list($severity, $object)) {
41
                        if (in_array($object, $object_dupe_check)) continue;
42
                        $object_dupe_check[] = $object;
295 daniel-mar 43
                        OIDplus::dbIsolated()->query("insert into ###log_object (log_id, severity, object) values (?, ?, ?)", array($log_id, $severity, $object));
289 daniel-mar 44
                }
45
 
46
                $user_dupe_check = array();
47
                foreach ($users as list($severity, $username)) {
48
                        if (in_array($username, $user_dupe_check)) continue;
49
                        $user_dupe_check[] = $username;
295 daniel-mar 50
                        OIDplus::dbIsolated()->query("insert into ###log_user (log_id, severity, username) values (?, ?, ?)", array($log_id, $severity, $username));
289 daniel-mar 51
                }
52
 
53
                return true;
54
        }
55
 
360 daniel-mar 56
}