Subversion Repositories oidplus

Rev

Rev 1185 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1185 Rev 1197
Line 48... Line 48...
48
                $reason = '';
48
                $reason = '';
49
                return true;
49
                return true;
50
        }
50
        }
51
 
51
 
52
        /**
52
        /**
53
         * @param string $event
53
         * @param OIDplusLogEvent $event
54
         * @param array $users
-
 
55
         * @param array $objects
-
 
56
         * @return bool
54
         * @return bool
57
         */
55
         */
58
        public function log(string $event, array $users, array $objects): bool {
56
        public function log(OIDplusLogEvent $event): bool {
59
                if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') return false;
57
                if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') return false;
60
 
58
 
61
                if (!@file_exists('/var/log/syslog')) return false;
59
                if (!@file_exists('/var/log/syslog')) return false;
62
 
60
 
63
                $users_names = array();
61
                $users_names = array();
64
                foreach ($users as list($severity, $username)) $users_names[] = $username;
-
 
65
                $users_info = count($users_names) == 0 ? '' : ' ('._L('affected users: %1',implode(', ',$users_names)).')';
-
 
66
 
-
 
67
                $objects_names = array();
62
                $objects_names = array();
68
                foreach ($objects as list($severity, $objectname)) $objects_names[] = $objectname;
63
                foreach ($event->getTargets() as $target) {
-
 
64
                        if ($target instanceof OIDplusLogTargetUser) {
-
 
65
                                $users_names[] = $target->getUsername();
-
 
66
                        } else if ($target instanceof OIDplusLogTargetObject) {
-
 
67
                                $objects_names[] = $target->getObject();
-
 
68
                        } else {
-
 
69
                                assert(false);
-
 
70
                        }
-
 
71
                }
-
 
72
                $users_info = count($users_names) == 0 ? '' : ' ('._L('affected users: %1',implode(', ',$users_names)).')';
69
                $objects_info = count($objects_names) == 0 ? '' : ' ('._L('affected objects: %1',implode(', ',$objects_names)).')';
73
                $objects_info = count($objects_names) == 0 ? '' : ' ('._L('affected objects: %1',implode(', ',$objects_names)).')';
70
 
74
 
71
                $ts = date('Y-m-d H:i:s');
75
                $ts = date('Y-m-d H:i:s');
72
                $addr = $_SERVER['REMOTE_ADDR'] ?? _L('unknown');
76
                $addr = $_SERVER['REMOTE_ADDR'] ?? _L('unknown');
73
                $line = "[$ts] [$addr] $event$users_info$objects_info";
77
                $line = "[$ts] [$addr] ".$event->getMessage().$users_info.$objects_info;
74
 
78
 
75
                return @file_put_contents('/var/log/syslog', "$line\n", FILE_APPEND) !== false;
79
                return @file_put_contents('/var/log/syslog', "$line\n", FILE_APPEND) !== false;
76
        }
80
        }
77
}
81
}
78
82