@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @access protected |
50 | 50 | * @var array |
51 | 51 | */ |
52 | - protected $patterns = []; |
|
52 | + protected $patterns = [ ]; |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Constructor |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function addPattern(string $placeholder, string $pattern): void |
79 | 79 | { |
80 | - $this->patterns[$placeholder] = $pattern; |
|
80 | + $this->patterns[ $placeholder ] = $pattern; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | public function setFormat(string $format): void |
104 | 104 | { |
105 | 105 | // store log format update IP pattern |
106 | - $this->logFormat = $format ; |
|
106 | + $this->logFormat = $format; |
|
107 | 107 | $this->updateIpPatterns(); |
108 | 108 | |
109 | 109 | // strtr won't work for "complex" header patterns |
@@ -54,47 +54,47 @@ |
||
54 | 54 | $this->addFile('apache.log'); |
55 | 55 | $this->addFile('apache_access.log'); |
56 | 56 | |
57 | - $this->addFormat('apache_common', '%h %l %u %t \"%r\" %>s %O"'); |
|
58 | - $this->addFormat('apache_combined_vhost', '%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"'); |
|
59 | - $this->addFormat('apache_combined', '%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"'); |
|
57 | + $this->addFormat('apache_common', '%h %l %u %t \"%r\" %>s %O"'); |
|
58 | + $this->addFormat('apache_combined_vhost', '%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"'); |
|
59 | + $this->addFormat('apache_combined', '%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"'); |
|
60 | 60 | |
61 | - $this->addColumn('%%' , 'percent', '', '(?P<percent>\%)'); |
|
62 | - $this->addColumn('%t' , 'time', 'Date', '\[(?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})\]'); |
|
63 | - $this->addColumn('%v' , 'serverName', 'ServerName', '(?P<serverName>([a-zA-Z0-9]+)([a-z0-9.-]*))'); |
|
64 | - $this->addColumn('%V' , 'canonicalServerName', 'Canonical ServerName', '(?P<canonicalServerName>([a-zA-Z0-9]+)([a-z0-9.-]*))'); |
|
65 | - $this->addColumn('%p' , 'port', 'Port', '(?P<port>\d+)'); |
|
61 | + $this->addColumn('%%', 'percent', '', '(?P<percent>\%)'); |
|
62 | + $this->addColumn('%t', 'time', 'Date', '\[(?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})\]'); |
|
63 | + $this->addColumn('%v', 'serverName', 'ServerName', '(?P<serverName>([a-zA-Z0-9]+)([a-z0-9.-]*))'); |
|
64 | + $this->addColumn('%V', 'canonicalServerName', 'Canonical ServerName', '(?P<canonicalServerName>([a-zA-Z0-9]+)([a-z0-9.-]*))'); |
|
65 | + $this->addColumn('%p', 'port', 'Port', '(?P<port>\d+)'); |
|
66 | 66 | |
67 | 67 | // Client IP address of the request |
68 | - $this->addColumn('%a', 'remoteIp', 'IP', '(?P<remoteIp>{{PATTERN_IP_ALL}})'); |
|
68 | + $this->addColumn('%a', 'remoteIp', 'IP', '(?P<remoteIp>{{PATTERN_IP_ALL}})'); |
|
69 | 69 | |
70 | 70 | // Remote hostname |
71 | - $this->addColumn('%h' , 'host', 'Remote Host', '(?P<host>[a-zA-Z0-9\-\._:]+)'); |
|
71 | + $this->addColumn('%h', 'host', 'Remote Host', '(?P<host>[a-zA-Z0-9\-\._:]+)'); |
|
72 | 72 | |
73 | 73 | // Local IP-address |
74 | - $this->addColumn('%A', 'localIp', 'Local IP', '(?P<localIp>{{PATTERN_IP_ALL}})'); |
|
74 | + $this->addColumn('%A', 'localIp', 'Local IP', '(?P<localIp>{{PATTERN_IP_ALL}})'); |
|
75 | 75 | |
76 | 76 | // Remote user if the request was authenticated. May be bogus if return status (%s) is 401 (unauthorized). |
77 | - $this->addColumn('%u', 'user', 'User', '(?P<user>(?:-|[\w\-\.]+))'); |
|
78 | - |
|
79 | - $this->addColumn('%l', 'logname', 'Log Name', '(?P<logname>(?:-|[\w-]+))'); |
|
80 | - $this->addColumn('%m', 'requestMethod', 'Method', '(?P<requestMethod>OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PATCH|PROPFIND)'); |
|
81 | - $this->addColumn('%U', 'URL', 'URL', '(?P<URL>.+?)'); |
|
82 | - $this->addColumn('%H', 'requestProtocol', 'Protocol', '(?P<requestProtocol>HTTP/(1\.0|1\.1|2\.0))'); |
|
83 | - $this->addColumn('%r', 'request', 'Request', '(?P<request>(?:(?:[A-Z]+) .+? HTTP/(1\.0|1\.1|2\.0))|-|)'); |
|
84 | - $this->addColumn('%>s','statuts', 'Status', '(?P<status>\d{3}|-)'); |
|
85 | - $this->addColumn('%O', 'sentBytes', 'Size', '(?P<sentBytes>[0-9]+)'); |
|
77 | + $this->addColumn('%u', 'user', 'User', '(?P<user>(?:-|[\w\-\.]+))'); |
|
78 | + |
|
79 | + $this->addColumn('%l', 'logname', 'Log Name', '(?P<logname>(?:-|[\w-]+))'); |
|
80 | + $this->addColumn('%m', 'requestMethod', 'Method', '(?P<requestMethod>OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PATCH|PROPFIND)'); |
|
81 | + $this->addColumn('%U', 'URL', 'URL', '(?P<URL>.+?)'); |
|
82 | + $this->addColumn('%H', 'requestProtocol', 'Protocol', '(?P<requestProtocol>HTTP/(1\.0|1\.1|2\.0))'); |
|
83 | + $this->addColumn('%r', 'request', 'Request', '(?P<request>(?:(?:[A-Z]+) .+? HTTP/(1\.0|1\.1|2\.0))|-|)'); |
|
84 | + $this->addColumn('%>s', 'statuts', 'Status', '(?P<status>\d{3}|-)'); |
|
85 | + $this->addColumn('%O', 'sentBytes', 'Size', '(?P<sentBytes>[0-9]+)'); |
|
86 | 86 | |
87 | 87 | // Size of response in bytes, excluding HTTP headers. In CLF format, i.e. a '-' rather than a 0 when no bytes are sent. |
88 | - $this->addColumn('%b', 'responseBytes', 'Response Size', '(?P<responseBytes>(\d+|-))'); |
|
88 | + $this->addColumn('%b', 'responseBytes', 'Response Size', '(?P<responseBytes>(\d+|-))'); |
|
89 | 89 | |
90 | 90 | //The time taken to serve the request, in seconds. |
91 | - $this->addColumn('%T', 'requestTime', 'Request Time', '(?P<requestTime>(\d+\.?\d*))'); |
|
92 | - $this->addColumn('%D', 'timeServeRequest', 'Time Server Request', '(?P<timeServeRequest>[0-9]+)'); |
|
93 | - $this->addColumn('%I', 'receivedBytes', 'Received Bytes', '(?P<receivedBytes>[0-9]+)'); |
|
91 | + $this->addColumn('%T', 'requestTime', 'Request Time', '(?P<requestTime>(\d+\.?\d*))'); |
|
92 | + $this->addColumn('%D', 'timeServeRequest', 'Time Server Request', '(?P<timeServeRequest>[0-9]+)'); |
|
93 | + $this->addColumn('%I', 'receivedBytes', 'Received Bytes', '(?P<receivedBytes>[0-9]+)'); |
|
94 | 94 | |
95 | 95 | // common named columns (no pattern, use generic pattern bellow) |
96 | - $this->addColumn('%{Referer}i', 'headerReferer', 'Referer', ''); |
|
97 | - $this->addColumn('%{User-Agent}i', 'headerUserAgent', 'User Agent', ''); |
|
96 | + $this->addColumn('%{Referer}i', 'headerReferer', 'Referer', ''); |
|
97 | + $this->addColumn('%{User-Agent}i', 'headerUserAgent', 'User Agent', ''); |
|
98 | 98 | |
99 | 99 | // dymanic named columns |
100 | 100 | $this->addPattern('\%\{(?P<name>[a-zA-Z]+)(?P<name2>[-]?)(?P<name3>[a-zA-Z]+)\}i', '(?P<header\\1\\3>.*?)'); |
@@ -41,15 +41,15 @@ |
||
41 | 41 | $this->software = 'Fail2ban'; |
42 | 42 | $this->prettyName = 'Fail2ban'; |
43 | 43 | $this->addFormat('default', '%t %s %p %l %m'); |
44 | - $this->defaultFormat = '%t %s %p %l %m'; |
|
44 | + $this->defaultFormat = '%t %s %p %l %m'; |
|
45 | 45 | $this->addPath("/var/log/"); |
46 | 46 | $this->addFile("fail2ban.log"); |
47 | 47 | // '%d' => '(?P<date>[\d \-,:]+)', |
48 | - $this->addColumn('%t', 'time', 'Date', '(?P<time>[\d \-:]+)(,\d+)'); |
|
49 | - $this->addColumn('%s', 'service', 'Service', '(?P<service>[\w\d\. :]+(|\s+))'); |
|
50 | - $this->addColumn('%p', 'pid', 'PID', '\[(?P<pid>\d+)\]:'); |
|
51 | - $this->addColumn('%l', 'level', 'Level', '(?P<level>(Level \d+|DEBUG|INFO|NOTICE|WARNING|ERROR|CRITICAL)(|\s+))'); |
|
52 | - $this->addColumn('%m', 'message', 'Message', '(?P<message>.+)'); |
|
48 | + $this->addColumn('%t', 'time', 'Date', '(?P<time>[\d \-:]+)(,\d+)'); |
|
49 | + $this->addColumn('%s', 'service', 'Service', '(?P<service>[\w\d\. :]+(|\s+))'); |
|
50 | + $this->addColumn('%p', 'pid', 'PID', '\[(?P<pid>\d+)\]:'); |
|
51 | + $this->addColumn('%l', 'level', 'Level', '(?P<level>(Level \d+|DEBUG|INFO|NOTICE|WARNING|ERROR|CRITICAL)(|\s+))'); |
|
52 | + $this->addColumn('%m', 'message', 'Message', '(?P<message>.+)'); |
|
53 | 53 | |
54 | 54 | parent::__construct($format, $factory); |
55 | 55 | } |
@@ -40,16 +40,16 @@ |
||
40 | 40 | $this->prettyName = 'Syslog'; |
41 | 41 | |
42 | 42 | $this->addFormat('default', '%t %h %s %m'); |
43 | - $this->defaultFormat = '%t %h %s %m'; |
|
43 | + $this->defaultFormat = '%t %h %s %m'; |
|
44 | 44 | |
45 | 45 | $this->addPath("/var/log/"); |
46 | 46 | $this->addFile("syslog"); |
47 | 47 | //todo |
48 | 48 | |
49 | - $this->addColumn('%t', 'time', 'Date', '(?P<time>(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{2} \d{2}:\d{2}:\d{2})'); |
|
50 | - $this->addColumn('%h', 'hostaname', 'Hostname', '(?P<hostname>.+?)'); |
|
51 | - $this->addColumn('%s', 'service', 'Service', '(?P<service>(\S+|\[\d+\])):'); |
|
52 | - $this->addColumn('%m', 'message', 'Message', '(?P<message>.+)'); |
|
49 | + $this->addColumn('%t', 'time', 'Date', '(?P<time>(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{2} \d{2}:\d{2}:\d{2})'); |
|
50 | + $this->addColumn('%h', 'hostaname', 'Hostname', '(?P<hostname>.+?)'); |
|
51 | + $this->addColumn('%s', 'service', 'Service', '(?P<service>(\S+|\[\d+\])):'); |
|
52 | + $this->addColumn('%m', 'message', 'Message', '(?P<message>.+)'); |
|
53 | 53 | |
54 | 54 | parent::__construct($format, $factory); |
55 | 55 | } |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @var array |
55 | 55 | */ |
56 | - protected $knownFormats = []; |
|
56 | + protected $knownFormats = [ ]; |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @var array |
60 | 60 | */ |
61 | - protected $columns = []; |
|
61 | + protected $columns = [ ]; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * The log file names |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @access protected |
67 | 67 | * @var array |
68 | 68 | */ |
69 | - protected $files = []; |
|
69 | + protected $files = [ ]; |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * The log file paths |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @access protected |
75 | 75 | * @var array |
76 | 76 | */ |
77 | - protected $paths = []; |
|
77 | + protected $paths = [ ]; |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Constructor |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | protected function addFormat(string $name, string $format): void |
127 | 127 | { |
128 | - $this->knownFormats[$name] = $format; |
|
128 | + $this->knownFormats[ $name ] = $format; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | protected function addFile(string $fileName): void |
152 | 152 | { |
153 | - $this->files[] = $fileName; |
|
153 | + $this->files[ ] = $fileName; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | protected function addPath(string $path): void |
178 | 178 | { |
179 | - $this->paths[] = $path; |
|
179 | + $this->paths[ ] = $path; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | protected function addColumn(string $placeholder, string $propertyName, string $prettyName, string $pattern, bool $required = true): void |
207 | 207 | { |
208 | - $this->columns[] = [ |
|
208 | + $this->columns[ ] = [ |
|
209 | 209 | 'placeholder' => $placeholder, |
210 | 210 | 'propertyName' => $propertyName, |
211 | 211 | 'prettyName' => $prettyName, |
@@ -213,15 +213,15 @@ discard block |
||
213 | 213 | 'required' => $required, |
214 | 214 | ]; |
215 | 215 | |
216 | - if (!empty($pattern)){ |
|
216 | + if (!empty($pattern)) { |
|
217 | 217 | |
218 | 218 | // optional columns ? |
219 | 219 | // adjust pattern for nullable columns and add space after placeholder |
220 | 220 | // - $format = '%t %l %P %E: %a %M'; |
221 | 221 | // + $format = '%t %l (%P )?(%E: )?(%a )?%M'; |
222 | 222 | $this->addPattern( |
223 | - $required ? $placeholder : $placeholder . ' ' , |
|
224 | - $required ? $pattern : '(' . $pattern . ' )?' |
|
223 | + $required ? $placeholder : $placeholder.' ', |
|
224 | + $required ? $pattern : '('.$pattern.' )?' |
|
225 | 225 | ); |
226 | 226 | } |
227 | 227 | } |
@@ -235,10 +235,10 @@ discard block |
||
235 | 235 | */ |
236 | 236 | public function getColumns() |
237 | 237 | { |
238 | - $cols = []; |
|
239 | - foreach ($this->columns as $column){ |
|
240 | - if (strpos($this->getFormat(), $column['placeholder']) !== false){ |
|
241 | - $cols[] = $column; |
|
238 | + $cols = [ ]; |
|
239 | + foreach ($this->columns as $column) { |
|
240 | + if (strpos($this->getFormat(), $column[ 'placeholder' ]) !== false) { |
|
241 | + $cols[ ] = $column; |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | return $cols; |
@@ -69,22 +69,22 @@ |
||
69 | 69 | $this->addFile('error_log'); |
70 | 70 | $this->addFile("apache_error.log"); |
71 | 71 | |
72 | - $this->addColumn('%%' , 'percent', '', '(?P<percent>\%)'); |
|
73 | - $this->addColumn('%t' , 'time', 'Date', '\[(?P<time>(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{2} \d{2}:\d{2}:\d{2}(\.\d{6}|) \d{4})\]'); |
|
72 | + $this->addColumn('%%', 'percent', '', '(?P<percent>\%)'); |
|
73 | + $this->addColumn('%t', 'time', 'Date', '\[(?P<time>(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{2} \d{2}:\d{2}:\d{2}(\.\d{6}|) \d{4})\]'); |
|
74 | 74 | |
75 | 75 | // %a Client IP address and port of the request |
76 | - $this->addColumn('%a' , 'remoteIP', 'IP', '\[client (?P<remoteIp>{{PATTERN_IP_ALL}})(:[\d]+|)\]', false); |
|
76 | + $this->addColumn('%a', 'remoteIP', 'IP', '\[client (?P<remoteIp>{{PATTERN_IP_ALL}})(:[\d]+|)\]', false); |
|
77 | 77 | |
78 | - $this->addColumn('%A', 'localIP', 'Local IP', '(?P<localIp>{{PATTERN_IP_ALL}})', false); |
|
78 | + $this->addColumn('%A', 'localIP', 'Local IP', '(?P<localIp>{{PATTERN_IP_ALL}})', false); |
|
79 | 79 | |
80 | 80 | // %l Loglevel of the message |
81 | - $this->addColumn('%l', 'level', 'Level', '\[(?P<level>[\w:]+)\]'); |
|
81 | + $this->addColumn('%l', 'level', 'Level', '\[(?P<level>[\w:]+)\]'); |
|
82 | 82 | |
83 | 83 | // %P Process ID of current process (since apache 2.4?) |
84 | - $this->addColumn('%P', 'pid', 'PID', '\[pid (?P<pid>\d+)\]', false); |
|
84 | + $this->addColumn('%P', 'pid', 'PID', '\[pid (?P<pid>\d+)\]', false); |
|
85 | 85 | |
86 | 86 | // %E APR/OS error status code and string |
87 | - $this->addColumn('%E:' , 'errorCode', 'Error', '(?P<errorCode>[\w\d\s:]+):', false); |
|
87 | + $this->addColumn('%E:', 'errorCode', 'Error', '(?P<errorCode>[\w\d\s:]+):', false); |
|
88 | 88 | |
89 | 89 | // %M The actual log message |
90 | 90 | $this->addColumn('%M', 'message', 'Message', '(?P<message>.+?)'); |
@@ -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); |