X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FUtils.php;h=10d606987c826990e94fad0489f36aad66f6a969;hb=ce354bf1a61ce2478529ad558b24cdf9678c398a;hp=a9a10ece572a02e36c151931c719be739894faaa;hpb=1abe655597da7b3c5b59146c4351eef59f69514c;p=github%2Fshaarli%2FShaarli.git diff --git a/application/Utils.php b/application/Utils.php index a9a10ece..10d60698 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -6,14 +6,19 @@ /** * Logs a message to a text file * + * The log format is compatible with fail2ban. + * * @param string $logFile where to write the logs * @param string $clientIp the client's remote IPv4/IPv6 address * @param string $message the message to log */ function logm($logFile, $clientIp, $message) { - $line = strval(date('Y/m/d_H:i:s')).' - '.$clientIp.' - '.strval($message).'\n'; - file_put_contents($logFile, $line, FILE_APPEND); + file_put_contents( + $logFile, + date('Y/m/d H:i:s').' - '.$clientIp.' - '.strval($message).PHP_EOL, + FILE_APPEND + ); } /** @@ -56,14 +61,6 @@ function endsWith($haystack, $needle, $case=true) return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0); } -/** - * Same as nl2br(), but escapes < and > - */ -function nl2br_escaped($html) -{ - return str_replace('>', '>', str_replace('<', '<', nl2br($html))); -} - /** * htmlspecialchars wrapper */