X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FUtils.php;fp=application%2FUtils.php;h=10d606987c826990e94fad0489f36aad66f6a969;hb=893338f0d407a0989454d5e3c0e43c97f7eface5;hp=ac8bfbfc07dab77e40261c5b146479ec474ac44d;hpb=1be4afacf98e0124258199ec416dc1c4b4948305;p=github%2Fshaarli%2FShaarli.git diff --git a/application/Utils.php b/application/Utils.php index ac8bfbfc..10d60698 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -3,6 +3,24 @@ * Shaarli utilities */ +/** + * 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) +{ + file_put_contents( + $logFile, + date('Y/m/d H:i:s').' - '.$clientIp.' - '.strval($message).PHP_EOL, + FILE_APPEND + ); +} + /** * Returns the small hash of a string, using RFC 4648 base64url format * @@ -64,12 +82,14 @@ function sanitizeLink(&$link) /** * Checks if a string represents a valid date + + * @param string $format The expected DateTime format of the string + * @param string $string A string-formatted date + * + * @return bool whether the string is a valid date * - * @param string a string-formatted date - * @param format the expected DateTime format of the string - * @return whether the string is a valid date - * @see http://php.net/manual/en/class.datetime.php - * @see http://php.net/manual/en/datetime.createfromformat.php + * @see http://php.net/manual/en/class.datetime.php + * @see http://php.net/manual/en/datetime.createfromformat.php */ function checkDateFormat($format, $string) {