Subversion Repositories oidplus

Rev

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

Rev 360 Rev 496
Line 18... Line 18...
18
 */
18
 */
19
 
19
 
20
class OIDplusLoggerPluginUserdataLogfile extends OIDplusLoggerPlugin {
20
class OIDplusLoggerPluginUserdataLogfile extends OIDplusLoggerPlugin {
21
 
21
 
22
        public static function available(&$reason)/*: bool*/ {
22
        public static function available(&$reason)/*: bool*/ {
23
                if (!is_dir(OIDplus::basePath().'/userdata/logs/')) {
23
                if (!is_dir(OIDplus::localpath().'userdata/logs/')) {
24
                        $reason = _L('Directory userdata/logs/ not existing');
24
                        $reason = _L('Directory userdata/logs/ not existing');
25
                        return false;
25
                        return false;
26
                }
26
                }
27
 
27
 
28
                if (@file_put_contents(OIDplus::basePath().'/userdata/logs/oidplus.log', '', FILE_APPEND) === false) {
28
                if (@file_put_contents(OIDplus::localpath().'userdata/logs/oidplus.log', '', FILE_APPEND) === false) {
29
                        $reason = _L('File userdata/logs/oidplus.log not writeable');
29
                        $reason = _L('File userdata/logs/oidplus.log not writeable');
30
                        return false;
30
                        return false;
31
                }
31
                }
32
 
32
 
33
                $reason = '';
33
                $reason = '';
34
                return true;
34
                return true;
35
        }
35
        }
36
 
36
 
37
        public static function log($event, $users, $objects)/*: bool*/ {
37
        public static function log($event, $users, $objects)/*: bool*/ {
38
                if (!is_dir(OIDplus::basePath().'/userdata/logs/')) return false;
38
                if (!is_dir(OIDplus::localpath().'userdata/logs/')) return false;
39
 
39
 
40
                $users_names = array();
40
                $users_names = array();
41
                foreach ($users as list($severity, $username)) $users_names[] = $username;
41
                foreach ($users as list($severity, $username)) $users_names[] = $username;
42
                $users_info = count($users_names) == 0 ? '' : ' ('._L('affected users: %1',implode(', ',$users_names)).')';
42
                $users_info = count($users_names) == 0 ? '' : ' ('._L('affected users: %1',implode(', ',$users_names)).')';
43
 
43
 
Line 50... Line 50...
50
 
50
 
51
                // Note: $ts was put into brackets, because there is probably a bug in fail2ban that does not allow the date/time being at offset 0
51
                // Note: $ts was put into brackets, because there is probably a bug in fail2ban that does not allow the date/time being at offset 0
52
                // "WARNING Found a match for '020-05-11 22:50:58 [192.168.69.89] Failed login ..."
52
                // "WARNING Found a match for '020-05-11 22:50:58 [192.168.69.89] Failed login ..."
53
                $line = "[$ts] [$addr] $event$users_info$objects_info";
53
                $line = "[$ts] [$addr] $event$users_info$objects_info";
54
 
54
 
55
                return @file_put_contents(OIDplus::basePath().'/userdata/logs/oidplus.log', "$line\n", FILE_APPEND) !== false;
55
                return @file_put_contents(OIDplus::localpath().'userdata/logs/oidplus.log', "$line\n", FILE_APPEND) !== false;
56
        }
56
        }
57
}
57
}
58
58