@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @access protected |
| 52 | 52 | * @var array |
| 53 | 53 | */ |
| 54 | - protected $patterns = []; |
|
| 54 | + protected $patterns = [ ]; |
|
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * The time format |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | public function addNamedPattern(string $placeholder, string $propertyName, string $pattern, bool $required = true): void |
| 92 | 92 | { |
| 93 | 93 | // First field must be a required field |
| 94 | - if ($required === false && count($this->patterns) === 0){ |
|
| 94 | + if ($required === false && count($this->patterns) === 0) { |
|
| 95 | 95 | throw new \Kristuff\Parselog\InvalidArgumentException( |
| 96 | 96 | "Invalid value 'false' for argument 'required' given: First pattern must be a required pattern."); |
| 97 | 97 | } |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | // Adjust pattern for nullable columns and add space before placeholder |
| 101 | 101 | // - $format = '%t %l %P %E: %a %M'; |
| 102 | 102 | // + $format = '%t %l( %P)?( %E:)?(%a)? %M'; |
| 103 | - $key = $required ? $placeholder : ' ' . $placeholder ; |
|
| 104 | - $val = '(?P<'. $propertyName . '>' . ($required ? $pattern : '( ' . $pattern . ')?') . ')'; |
|
| 103 | + $key = $required ? $placeholder : ' '.$placeholder; |
|
| 104 | + $val = '(?P<'.$propertyName.'>'.($required ? $pattern : '( '.$pattern.')?').')'; |
|
| 105 | 105 | |
| 106 | 106 | $this->addPattern($key, $val); |
| 107 | 107 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | public function addPattern(string $placeholder, string $pattern): void |
| 120 | 120 | { |
| 121 | - $this->patterns[$placeholder] = $pattern; |
|
| 121 | + $this->patterns[ $placeholder ] = $pattern; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | public function setFormat(string $format): void |
| 145 | 145 | { |
| 146 | 146 | // store log format update IP pattern |
| 147 | - $this->logFormat = $format ; |
|
| 147 | + $this->logFormat = $format; |
|
| 148 | 148 | $this->updateIpPatterns(); |
| 149 | 149 | |
| 150 | 150 | // strtr won't work for "complex" header patterns |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | protected function getTimestamp($time): ?int |
| 205 | 205 | { |
| 206 | 206 | // try to get stamp from string |
| 207 | - if (isset($this->timeFormat)){ |
|
| 207 | + if (isset($this->timeFormat)) { |
|
| 208 | 208 | $dateTime = DateTime::createFromFormat($this->timeFormat, $time); |
| 209 | 209 | |
| 210 | 210 | if (false !== $dateTime) { |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | // Set IPv4 & IPv6 recognition patterns |
| 233 | 233 | $ipPatterns = implode('|', [ |
| 234 | 234 | 'ipv4' => self::PATTERN_IP_V4, |
| 235 | - 'ipv6full' => self::PATTERN_IP_V6_FULL, // 1:1:1:1:1:1:1:1 |
|
| 236 | - 'ipv6null' => self::PATTERN_IP_V6_NULL, // :: |
|
| 237 | - 'ipv6leading' => self::PATTERN_IP_V6_LEADING, // ::1:1:1:1:1:1:1 |
|
| 238 | - 'ipv6mid' => self::PATTERN_IP_V6_MID, // 1:1:1::1:1:1 |
|
| 239 | - 'ipv6trailing' => self::PATTERN_IP_V6_TRAILING, // 1:1:1:1:1:1:1:: |
|
| 235 | + 'ipv6full' => self::PATTERN_IP_V6_FULL, // 1:1:1:1:1:1:1:1 |
|
| 236 | + 'ipv6null' => self::PATTERN_IP_V6_NULL, // :: |
|
| 237 | + 'ipv6leading' => self::PATTERN_IP_V6_LEADING, // ::1:1:1:1:1:1:1 |
|
| 238 | + 'ipv6mid' => self::PATTERN_IP_V6_MID, // 1:1:1::1:1:1 |
|
| 239 | + 'ipv6trailing' => self::PATTERN_IP_V6_TRAILING, // 1:1:1:1:1:1:1:: |
|
| 240 | 240 | ]); |
| 241 | 241 | |
| 242 | 242 | foreach ($this->patterns as &$value) { |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | public static function getParser(string $logType, string $format = null, LogEntryFactoryInterface $factory = null): ?SoftwareLogParser |
| 46 | 46 | { |
| 47 | - switch ($logType){ |
|
| 47 | + switch ($logType) { |
|
| 48 | 48 | |
| 49 | 49 | case self::TYPE_APACHE_ACCESS: |
| 50 | 50 | return new \Kristuff\Parselog\Software\ApacheAccessLogParser($format, $factory); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @access protected |
| 55 | 55 | * @var array |
| 56 | 56 | */ |
| 57 | - protected $knownFormats = []; |
|
| 57 | + protected $knownFormats = [ ]; |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * The log files names |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @access protected |
| 63 | 63 | * @var array |
| 64 | 64 | */ |
| 65 | - protected $files = []; |
|
| 65 | + protected $files = [ ]; |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * The log files paths |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @access protected |
| 71 | 71 | * @var array |
| 72 | 72 | */ |
| 73 | - protected $paths = []; |
|
| 73 | + protected $paths = [ ]; |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * Constructor |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | protected function addFormat(string $name, string $format): void |
| 123 | 123 | { |
| 124 | - $this->knownFormats[$name] = $format; |
|
| 124 | + $this->knownFormats[ $name ] = $format; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | protected function addFile(string $fileName): void |
| 148 | 148 | { |
| 149 | - $this->files[] = $fileName; |
|
| 149 | + $this->files[ ] = $fileName; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | protected function addPath(string $path): void |
| 174 | 174 | { |
| 175 | - $this->paths[] = $path; |
|
| 175 | + $this->paths[ ] = $path; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -69,50 +69,50 @@ |
||
| 69 | 69 | $this->addFile('apache.log'); |
| 70 | 70 | $this->addFile('apache_access.log'); |
| 71 | 71 | |
| 72 | - $this->addFormat('apache_common', '%h %l %u %t \"%r\" %>s %O"'); |
|
| 73 | - $this->addFormat('apache_combined_vhost', '%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"'); |
|
| 74 | - $this->addFormat('apache_combined', '%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"'); |
|
| 75 | - $this->addFormat('apache_common_vhost', '%v %l %u %t \"%r\" %>s %b'); |
|
| 72 | + $this->addFormat('apache_common', '%h %l %u %t \"%r\" %>s %O"'); |
|
| 73 | + $this->addFormat('apache_combined_vhost', '%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"'); |
|
| 74 | + $this->addFormat('apache_combined', '%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"'); |
|
| 75 | + $this->addFormat('apache_common_vhost', '%v %l %u %t \"%r\" %>s %b'); |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - $this->addNamedPattern('%%' , 'percent', '\%'); |
|
| 78 | + $this->addNamedPattern('%%', 'percent', '\%'); |
|
| 79 | 79 | |
| 80 | 80 | // time |
| 81 | - $this->addPattern('%t' , '\[(?P<time>\d{2}/(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/\d{4}:\d{2}:\d{2}:\d{2} (?:-|\+)\d{4})\]'); |
|
| 81 | + $this->addPattern('%t', '\[(?P<time>\d{2}/(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/\d{4}:\d{2}:\d{2}:\d{2} (?:-|\+)\d{4})\]'); |
|
| 82 | 82 | |
| 83 | - $this->addNamedPattern('%v' , 'serverName', '([a-zA-Z0-9]+)([a-z0-9.-]*)'); |
|
| 84 | - $this->addNamedPattern('%V' , 'canonicalServerName', '([a-zA-Z0-9]+)([a-z0-9.-]*)'); |
|
| 83 | + $this->addNamedPattern('%v', 'serverName', '([a-zA-Z0-9]+)([a-z0-9.-]*)'); |
|
| 84 | + $this->addNamedPattern('%V', 'canonicalServerName', '([a-zA-Z0-9]+)([a-z0-9.-]*)'); |
|
| 85 | 85 | |
| 86 | 86 | // port |
| 87 | - $this->addNamedPattern('%p' , 'port', '\d+'); |
|
| 87 | + $this->addNamedPattern('%p', 'port', '\d+'); |
|
| 88 | 88 | |
| 89 | 89 | // Client IP address of the request |
| 90 | - $this->addNamedPattern('%a', 'remoteIp', self::PATTERN_IP_ALL); |
|
| 90 | + $this->addNamedPattern('%a', 'remoteIp', self::PATTERN_IP_ALL); |
|
| 91 | 91 | |
| 92 | 92 | // Remote hostname |
| 93 | - $this->addNamedPattern('%h' , 'host', '[a-zA-Z0-9\-\._:]+'); |
|
| 93 | + $this->addNamedPattern('%h', 'host', '[a-zA-Z0-9\-\._:]+'); |
|
| 94 | 94 | |
| 95 | 95 | // Local IP-address |
| 96 | - $this->addNamedPattern('%A', 'localIp', self::PATTERN_IP_ALL); |
|
| 96 | + $this->addNamedPattern('%A', 'localIp', self::PATTERN_IP_ALL); |
|
| 97 | 97 | |
| 98 | 98 | // Remote user if the request was authenticated. May be bogus if return status (%s) is 401 (unauthorized). |
| 99 | - $this->addNamedPattern('%u', 'user', '(?:-|[\w\-\.]+)'); |
|
| 99 | + $this->addNamedPattern('%u', 'user', '(?:-|[\w\-\.]+)'); |
|
| 100 | 100 | |
| 101 | - $this->addNamedPattern('%l', 'logname', '(?:-|[\w-]+)'); |
|
| 102 | - $this->addNamedPattern('%m', 'requestMethod', 'OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PATCH|PROPFIND'); |
|
| 103 | - $this->addNamedPattern('%U', 'URL', '.+?'); |
|
| 101 | + $this->addNamedPattern('%l', 'logname', '(?:-|[\w-]+)'); |
|
| 102 | + $this->addNamedPattern('%m', 'requestMethod', 'OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PATCH|PROPFIND'); |
|
| 103 | + $this->addNamedPattern('%U', 'URL', '.+?'); |
|
| 104 | 104 | $this->addNamedPattern('%H', 'requestProtocol', 'HTTP/(1\.0|1\.1|2\.0)'); |
| 105 | - $this->addNamedPattern('%r', 'request', '(?:(?:[A-Z]+) .+? HTTP/(1\.0|1\.1|2\.0))|-|'); |
|
| 105 | + $this->addNamedPattern('%r', 'request', '(?:(?:[A-Z]+) .+? HTTP/(1\.0|1\.1|2\.0))|-|'); |
|
| 106 | 106 | |
| 107 | 107 | // Status of the final request |
| 108 | 108 | $this->addNamedPattern('%>s', 'status', '\d{3}|-'); |
| 109 | 109 | |
| 110 | 110 | // Bytes sent, including headers. May be zero in rare cases such as when a request is aborted before a |
| 111 | 111 | // response is sent. You need to enable mod_logio to use this. |
| 112 | - $this->addNamedPattern('%O', 'sentBytes', '[0-9]+'); |
|
| 112 | + $this->addNamedPattern('%O', 'sentBytes', '[0-9]+'); |
|
| 113 | 113 | |
| 114 | 114 | // Size of response in bytes, excluding HTTP headers. In CLF format, i.e. a '-' rather than a 0 when no bytes are sent. |
| 115 | - $this->addNamedPattern('%b', 'responseBytes', '(\d+|-)'); |
|
| 115 | + $this->addNamedPattern('%b', 'responseBytes', '(\d+|-)'); |
|
| 116 | 116 | |
| 117 | 117 | //The time taken to serve the request, in seconds. |
| 118 | 118 | $this->addNamedPattern('%T', 'requestTime', '(\d+\.?\d*)'); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $this->defaultFormat = self::FORMAT_DEFAULT_APACHE_2_4; |
| 99 | 99 | |
| 100 | 100 | // 2.2 / 2.4 |
| 101 | - $this->timeFormat = 'D M d H:i:s Y'; |
|
| 101 | + $this->timeFormat = 'D M d H:i:s Y'; |
|
| 102 | 102 | //$this->timeFormat = 'D M d H:i:s.u Y'; |
| 103 | 103 | |
| 104 | 104 | $this->addFormat('default', self::FORMAT_DEFAULT_APACHE_2_4); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | // define patterns |
| 124 | 124 | // *************** |
| 125 | 125 | |
| 126 | - $this->addNamedPattern('%%' , 'percent', '\%'); |
|
| 126 | + $this->addNamedPattern('%%', 'percent', '\%'); |
|
| 127 | 127 | |
| 128 | 128 | // %t The current time |
| 129 | 129 | // %{u}t The current time including micro-seconds |
@@ -134,29 +134,29 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | // %a Client IP address and port of the request (port is not registered by parser). |
| 136 | 136 | // That column may be missing depending of error |
| 137 | - $clientIpPattern = '( \[client (?P<remoteIp>' . self::PATTERN_IP_ALL . ')(:[\d]+|)?\])?'; |
|
| 138 | - $this->addPattern(' \[client %a\]' , $clientIpPattern); |
|
| 139 | - $this->addPattern(' \[%a\]' , $clientIpPattern); |
|
| 140 | - $this->addPattern(' %a' , $clientIpPattern); |
|
| 137 | + $clientIpPattern = '( \[client (?P<remoteIp>'.self::PATTERN_IP_ALL.')(:[\d]+|)?\])?'; |
|
| 138 | + $this->addPattern(' \[client %a\]', $clientIpPattern); |
|
| 139 | + $this->addPattern(' \[%a\]', $clientIpPattern); |
|
| 140 | + $this->addPattern(' %a', $clientIpPattern); |
|
| 141 | 141 | |
| 142 | 142 | // %A Local IP-address and port |
| 143 | 143 | // That column may be missing depending of error |
| 144 | - $this->addNamedPattern('%A', 'localIP', self::PATTERN_IP_ALL, false); |
|
| 144 | + $this->addNamedPattern('%A', 'localIP', self::PATTERN_IP_ALL, false); |
|
| 145 | 145 | |
| 146 | 146 | // %m Name of the module logging the message |
| 147 | 147 | // %l Loglevel of the message |
| 148 | - $this->addPattern('\[%m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); |
|
| 148 | + $this->addPattern('\[%m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); |
|
| 149 | 149 | $this->addPattern('\[%-m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); |
| 150 | - $this->addPattern('\[%l\]', '\[(?P<level>[\w:]+)\]'); |
|
| 151 | - $this->addPattern('%l', '\[(?P<level>[\w:]+)\]'); |
|
| 150 | + $this->addPattern('\[%l\]', '\[(?P<level>[\w:]+)\]'); |
|
| 151 | + $this->addPattern('%l', '\[(?P<level>[\w:]+)\]'); |
|
| 152 | 152 | |
| 153 | 153 | // %P Process ID of current process (since apache 2.4?) |
| 154 | 154 | // %T Thread ID of current thread |
| 155 | 155 | $this->addPattern('\[pid %P:tid %T\]', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); |
| 156 | - $this->addPattern('%P %T', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); |
|
| 156 | + $this->addPattern('%P %T', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); |
|
| 157 | 157 | $this->addPattern('\[pid %P\]', '\[pid (?P<pid>\d+)\]'); |
| 158 | - $this->addPattern('\[%P\]', '\[pid (?P<pid>\d+)\]'); |
|
| 159 | - $this->addPattern('%P', '\[pid (?P<pid>\d+)\]'); |
|
| 158 | + $this->addPattern('\[%P\]', '\[pid (?P<pid>\d+)\]'); |
|
| 159 | + $this->addPattern('%P', '\[pid (?P<pid>\d+)\]'); |
|
| 160 | 160 | |
| 161 | 161 | // %E APR/OS error status code and string |
| 162 | 162 | // That column may be missing depending of error |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $this->addPattern(' %F:', '( (?P<fileName>[^\*\s\|><\?]*[\/][^\*\s\|><\?]*):)?'); |
| 168 | 168 | |
| 169 | 169 | // %M The actual log message |
| 170 | - $this->addNamedPattern('%M', 'message', '.+?'); |
|
| 170 | + $this->addNamedPattern('%M', 'message', '.+?'); |
|
| 171 | 171 | |
| 172 | 172 | // now let default constructor |
| 173 | 173 | parent::__construct($format, $factory); |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | parent::setFormat($format); |
| 187 | 187 | |
| 188 | 188 | // set the correct time format |
| 189 | - if (strpos($this->logFormat, '%{u}t') !== false){ |
|
| 189 | + if (strpos($this->logFormat, '%{u}t') !== false) { |
|
| 190 | 190 | $this->timeFormat = 'D M d H:i:s.u Y'; |
| 191 | 191 | } |
| 192 | 192 | |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | const PATTERN_IP_V4 = '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9]))'; |
| 33 | 33 | |
| 34 | 34 | /** IPV6 full pattern */ |
| 35 | - const PATTERN_IP_V6_FULL ='([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){7})'; // 1:1:1:1:1:1:1:1 |
|
| 35 | + const PATTERN_IP_V6_FULL = '([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){7})'; // 1:1:1:1:1:1:1:1 |
|
| 36 | 36 | |
| 37 | 37 | /** IPV6 null pattern */ |
| 38 | 38 | const PATTERN_IP_V6_NULL = '(::)'; |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | $entry = new LogEntry(); |
| 34 | 34 | |
| 35 | 35 | foreach (array_filter(array_keys($data), 'is_string') as $key) { |
| 36 | - $entry->{$key} = trim($data[$key]); |
|
| 36 | + $entry->{$key} = trim($data[ $key ]); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | return $entry; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $this->prettyName = 'Syslog'; |
| 44 | 44 | |
| 45 | 45 | $this->addFormat('default', '%t %h %s%p: %m'); |
| 46 | - $this->defaultFormat = '%t %h %s%p: %m'; |
|
| 46 | + $this->defaultFormat = '%t %h %s%p: %m'; |
|
| 47 | 47 | |
| 48 | 48 | $this->addPath("/var/log/"); |
| 49 | 49 | $this->addFile("syslog"); |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | $this->addFile("user"); |
| 57 | 57 | $this->addFile("messages"); |
| 58 | 58 | |
| 59 | - $this->addPattern('%t', '(?P<time>(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\s\d|\d{2}) \d{2}:\d{2}:\d{2})'); |
|
| 60 | - $this->addPattern('%h', '(?P<hostname>.+?)'); |
|
| 61 | - $this->addPattern('%s', '(?P<service>[^\[:]+)'); |
|
| 62 | - $this->addPattern('%p', '(\[(?P<pid>\d+)\])?'); |
|
| 63 | - $this->addPattern('%m', '(?P<message>.+)'); |
|
| 59 | + $this->addPattern('%t', '(?P<time>(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\s\d|\d{2}) \d{2}:\d{2}:\d{2})'); |
|
| 60 | + $this->addPattern('%h', '(?P<hostname>.+?)'); |
|
| 61 | + $this->addPattern('%s', '(?P<service>[^\[:]+)'); |
|
| 62 | + $this->addPattern('%p', '(\[(?P<pid>\d+)\])?'); |
|
| 63 | + $this->addPattern('%m', '(?P<message>.+)'); |
|
| 64 | 64 | |
| 65 | 65 | parent::__construct($format, $factory); |
| 66 | 66 | } |
@@ -41,8 +41,8 @@ |
||
| 41 | 41 | $this->software = 'Fail2ban'; |
| 42 | 42 | $this->prettyName = 'Fail2ban'; |
| 43 | 43 | $this->addFormat('default', '%t %s %p %l %j %m'); |
| 44 | - $this->defaultFormat = '%t %s %p %l %j %m'; |
|
| 45 | - $this->timeFormat = 'Y-m-d'; |
|
| 44 | + $this->defaultFormat = '%t %s %p %l %j %m'; |
|
| 45 | + $this->timeFormat = 'Y-m-d'; |
|
| 46 | 46 | |
| 47 | 47 | $this->addPath("/var/log/"); |
| 48 | 48 | $this->addFile("fail2ban.log"); |