PHP Warning: Use of undefined constant LOG_LOCAL0

Hi,
PHP 7.4, Wordpress 5.7, WP-Fail2ban: 4.3.0.9

I’m developing WP localy on Windows. On /wp-login.php page I have following warnings:

Warning: Use of undefined constant LOG_LOCAL0 - assumed 'LOG_LOCAL0' (this will throw an Error in a future version of PHP) in **\wp-content\plugins\wp-fail2ban\lib\convert-data.php on line 125
Warning: Use of undefined constant LOG_LOCAL1 - assumed 'LOG_LOCAL1' (this will throw an Error in a future version of PHP) in **\wp-content\plugins\wp-fail2ban\lib\convert-data.php on line 125
Warning: Use of undefined constant LOG_LOCAL2 - assumed 'LOG_LOCAL2' (this will throw an Error in a future version of PHP) in **\wp-content\plugins\wp-fail2ban\lib\convert-data.php on line 125
Warning: Use of undefined constant LOG_LOCAL3 - assumed 'LOG_LOCAL3' (this will throw an Error in a future version of PHP) in **\wp-content\plugins\wp-fail2ban\lib\convert-data.php on line 125
Warning: Use of undefined constant LOG_LOCAL4 - assumed 'LOG_LOCAL4' (this will throw an Error in a future version of PHP) in **\wp-content\plugins\wp-fail2ban\lib\convert-data.php on line 125
Warning: Use of undefined constant LOG_LOCAL5 - assumed 'LOG_LOCAL5' (this will throw an Error in a future version of PHP) in **\wp-content\plugins\wp-fail2ban\lib\convert-data.php on line 125
Warning: Use of undefined constant LOG_LOCAL6 - assumed 'LOG_LOCAL6' (this will throw an Error in a future version of PHP) in **\wp-content\plugins\wp-fail2ban\lib\convert-data.php on line 125
Warning: Use of undefined constant LOG_LOCAL7 - assumed 'LOG_LOCAL7' (this will throw an Error in a future version of PHP) in **\wp-content\plugins\wp-fail2ban\lib\convert-data.php on line 125

According to https://www.php.net/manual/en/network.constants.php
LOG_LOCAL0 … LOG_LOCAL7 are not available in Windows

I don’t expect the plugin to work properly on Windows. Just after copying the site from the server, I have to remove the plugin locally to log into the admin panel.

Hope you will find a moment to look at it. Thanks!

That’s an interesting problem…

I don’t have a Windows install to test on atm (probably something to sort out), so can you try this:

    public static $FacilityName2Value = array(
        'LOG_AUTH'        => LOG_AUTH,
        'LOG_AUTHPRIV'    => LOG_AUTHPRIV,
        'LOG_CRON'        => LOG_CRON,
        'LOG_DAEMON'      => LOG_DAEMON,
        'LOG_KERN'        => LOG_KERN,
        'LOG_LOCAL0'      => @LOG_LOCAL0,
        'LOG_LOCAL1'      => @LOG_LOCAL1,
        'LOG_LOCAL2'      => @LOG_LOCAL2,
        'LOG_LOCAL3'      => @LOG_LOCAL3,
        'LOG_LOCAL4'      => @LOG_LOCAL4,
        'LOG_LOCAL5'      => @LOG_LOCAL5,
        'LOG_LOCAL6'      => @LOG_LOCAL6,
        'LOG_LOCAL7'      => @LOG_LOCAL7,
        'LOG_LPR'         => LOG_LPR,
        'LOG_MAIL'        => LOG_MAIL,
        'LOG_NEWS'        => LOG_NEWS,
        'LOG_SYSLOG'      => LOG_SYSLOG,
        'LOG_USER'        => LOG_USER,
        'LOG_UUCP'        => LOG_UUCP,
    );

If it works it’s probably the best solution for now to stay compatible with PHP 5.6; the next full version will bump the minimum version to 7.3 so there can be a nicer fix.

Let me know how you get on.

Unfortunately it doesn’t work. I prepared patch inspired by a monolog lib
https://github.com/Seldaek/monolog/blob/main/src/Monolog/Handler/AbstractSyslogHandler.php#L65
which works fine on all PHP versions:

diff --git a/admin/lib/logging.php b/admin/lib/logging.php
index 17c34b29..58dab2be 100644
--- a/admin/lib/logging.php
+++ b/admin/lib/logging.php
@@ -31,7 +31,7 @@ abstract class TabLoggingBase extends TabBase
         $default = Config::get_default($def);
         $value = Config::get($def);
 
-        foreach (ConvertData::$FacilityName2Value as $name => $facility) {
+        foreach (ConvertData::facilityName2Value() as $name => $facility) {
             $str .= sprintf(
                 '<option value="%s" %s>%s%s</option>',
                 $facility,
diff --git a/lib/convert-data.php b/lib/convert-data.php
index 24e68e0f..5ab5ffe1 100644
--- a/lib/convert-data.php
+++ b/lib/convert-data.php
@@ -90,27 +90,43 @@ abstract class ConvertData
     /**
      * @var int[] Map syslog facility name to value.
      */
-    public static $FacilityName2Value = array(
-        'LOG_AUTH'        => LOG_AUTH,
-        'LOG_AUTHPRIV'    => LOG_AUTHPRIV,
-        'LOG_CRON'        => LOG_CRON,
-        'LOG_DAEMON'      => LOG_DAEMON,
-        'LOG_KERN'        => LOG_KERN,
-        'LOG_LOCAL0'      => LOG_LOCAL0,
-        'LOG_LOCAL1'      => LOG_LOCAL1,
-        'LOG_LOCAL2'      => LOG_LOCAL2,
-        'LOG_LOCAL3'      => LOG_LOCAL3,
-        'LOG_LOCAL4'      => LOG_LOCAL4,
-        'LOG_LOCAL5'      => LOG_LOCAL5,
-        'LOG_LOCAL6'      => LOG_LOCAL6,
-        'LOG_LOCAL7'      => LOG_LOCAL7,
-        'LOG_LPR'         => LOG_LPR,
-        'LOG_MAIL'        => LOG_MAIL,
-        'LOG_NEWS'        => LOG_NEWS,
-        'LOG_SYSLOG'      => LOG_SYSLOG,
-        'LOG_USER'        => LOG_USER,
-        'LOG_UUCP'        => LOG_UUCP,
-    );
+    public static function facilityName2Value()
+    {
+        return array(
+                'LOG_AUTH'       => LOG_AUTH,
+                'LOG_AUTHPRIV'   => LOG_AUTHPRIV,
+                'LOG_CRON'       => LOG_CRON,
+                'LOG_DAEMON'     => LOG_DAEMON,
+                'LOG_KERN'       => LOG_KERN,
+            ) + (!defined('PHP_WINDOWS_VERSION_BUILD') ?
+                array(
+                    'LOG_LOCAL0' => LOG_LOCAL0,
+                    'LOG_LOCAL1' => LOG_LOCAL1,
+                    'LOG_LOCAL2' => LOG_LOCAL2,
+                    'LOG_LOCAL3' => LOG_LOCAL3,
+                    'LOG_LOCAL4' => LOG_LOCAL4,
+                    'LOG_LOCAL5' => LOG_LOCAL5,
+                    'LOG_LOCAL6' => LOG_LOCAL6,
+                    'LOG_LOCAL7' => LOG_LOCAL7,
+                ) : array(
+                    'LOG_LOCAL0' => 128, // LOG_LOCAL0
+                    'LOG_LOCAL1' => 136, // LOG_LOCAL1
+                    'LOG_LOCAL2' => 144, // LOG_LOCAL2
+                    'LOG_LOCAL3' => 152, // LOG_LOCAL3
+                    'LOG_LOCAL4' => 160, // LOG_LOCAL4
+                    'LOG_LOCAL5' => 168, // LOG_LOCAL5
+                    'LOG_LOCAL6' => 176, // LOG_LOCAL6
+                    'LOG_LOCAL7' => 184, // LOG_LOCAL7
+                )
+            ) + array(
+                'LOG_LPR'        => LOG_LPR,
+                'LOG_MAIL'       => LOG_MAIL,
+                'LOG_NEWS'       => LOG_NEWS,
+                'LOG_SYSLOG'     => LOG_SYSLOG,
+                'LOG_USER'       => LOG_USER,
+                'LOG_UUCP'       => LOG_UUCP,
+            );
+    }
 
     /**
      * Convert: Syslog Priority value to slug.

And here are positive test results on PHP 5.x, 7.x, 8.x https://3v4l.org/MKvY1

This will be fixed in v4.3.4.0 which should be released very soon.

1 Like