Cacti 1.2.2 + php 7.3 Email showing "you must provide at least one recipient email address"

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
peraltagaston
Posts: 2
Joined: Mon Jan 27, 2020 12:11 pm

Cacti 1.2.2 + php 7.3 Email showing "you must provide at least one recipient email address"

Post by peraltagaston »

Hi, I'm new to this forum and I would like to share my experience with this issue that couldn't let me send emails from Cacti.
I'm using Debian 10, php 7.3 and using exim4 to send emails from php. After upgrading, Cacti stopped sending emails to any destination and when I tried to send test message I received "Error: You must provide at least one recipient email address".
In /var/log/cacti/cacti.log I found "ERROR PHP WARNING: preg_match(): Compilation failed: invalid range in character class at offset 28 in file: /usr/share/cacti/site/lib/functions.php on line: 3684". I edited this file to dump the contents of the variables involved and it was true, nothing came from a preg_match function that uses a regular expression declared before. The regular expression is:

Code: Select all

$sPattern = '/([\w\s\'\"\+]+[\s]+)?(<)?(([\w-\.\+]+)@((?:[\w\-]+\.)+)([a-zA-Z]{2,4}))?(>)?/';
I have no advanced knowledge of regular expressions, so I've tested this on some tester online, no errors were founded.
Also I've read that this issue dissapeared when using php7.2 and lower versions, so I asked to myself (and to google, ;))"what's the difference in preg_match in php7.2 and php7.3?". The first result shows what I've been looking for!
PSRE2 is more strict in the pattern validations, so after the upgrade, some of your existing patterns could not compile anymore.

Here is the simple snippet used in php.net

preg_match('/[\w-.]+/', ''); // this will not work in PHP7.3
preg_match('/[\w\-.]+/', ''); // the hyphen need to be escaped

As you can see from the example above there is a little but substantial difference between the two lines.
Source: https://hackernoon.com/deprecations-and ... 5c4dbeaa8b

So I've changed the regular expression in line from

Code: Select all

$sPattern = '/([\w\s\'\"\+]+[\s]+)?(<)?(([\w-\.\+]+)@((?:[\w\-]+\.)+)([a-zA-Z]{2,4}))?(>)?/';
to

Code: Select all

$sPattern = '/([\w\s\'\"\+]+[\s]+)?(<)?(([\w\-\.\+]+)@((?:[\w\-]+\.)+)([a-zA-Z]{2,4}))?(>)?/';
The file I edited was /usr/share/cacti/site/functions.php, line 3684.
Hope it helps anyone as helped me.
Best regards.
cigamit
Developer
Posts: 3367
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Re: Cacti 1.2.2 + php 7.3 Email showing "you must provide at least one recipient email address"

Post by cigamit »

Actually, you just need to update your Cacti version. That particular bug was fixed 6 months ago.
https://github.com/Cacti/cacti/commit/2 ... fffd4b8fff
peraltagaston
Posts: 2
Joined: Mon Jan 27, 2020 12:11 pm

Re: Cacti 1.2.2 + php 7.3 Email showing "you must provide at least one recipient email address"

Post by peraltagaston »

Thanks cigamit!
I did not find that fix since I've installed cacti-spine from repositories and 1.2.2 is the latest version in that moment.

Best regards,
jbirch
Posts: 2
Joined: Sun Sep 20, 2020 3:25 pm

Re: Cacti 1.2.2 + php 7.3 Email showing "you must provide at least one recipient email address"

Post by jbirch »

peraltagaston wrote: I've changed the regular expression in line from

Code: Select all

$sPattern = '/([\w\s\'\"\+]+[\s]+)?(<)?(([\w-\.\+]+)@((?:[\w\-]+\.)+)([a-zA-Z]{2,4}))?(>)?/';
to

Code: Select all

$sPattern = '/([\w\s\'\"\+]+[\s]+)?(<)?(([\w\-\.\+]+)@((?:[\w\-]+\.)+)([a-zA-Z]{2,4}))?(>)?/';
The file I edited was /usr/share/cacti/site/functions.php, line 3684.
Hope it helps anyone as helped me.
Best regards.
peraltagaston

Thanks very much for posting this workaround.
Was dreading a Cacti update to fix this. That one character was it. You rock !!! :D
Slightly different line further down in my install but easy enough to find in my Raspberry PI install.

file location /usr/share/cacti/site/lib/functions.php line 3701

$sPattern = '/([\w\s\'\"\+]+[\s]+)?(<)?(([\w\-\.\+]+)@((?:[\w\-]+\.)+)([a-zA-Z]{2,4}))?(>)?/';

Need this to get emails for when my wireless security cameras go down.
Shots fired (drug/gang related) just across the street this week and the one camera with a view had been down for 3 days. :oops:

jbirch
Last edited by jbirch on Mon Jun 07, 2021 8:47 am, edited 1 time in total.
sticky
Posts: 1
Joined: Mon May 17, 2021 5:23 pm

Re: Cacti 1.2.2 + php 7.3 Email showing "you must provide at least one recipient email address"

Post by sticky »

jbirch wrote: Sun Sep 20, 2020 3:36 pm
peraltagaston wrote: I've changed the regular expression in line from

Code: Select all

$sPattern = '/([\w\s\'\"\+]+[\s]+)?(<)?(([\w-\.\+]+)@((?:[\w\-]+\.)+)([a-zA-Z]{2,4}))?(>)?/';
to

Code: Select all

$sPattern = '/([\w\s\'\"\+]+[\s]+)?(<)?(([\w\-\.\+]+)@((?:[\w\-]+\.)+)([a-zA-Z]{2,4}))?(>)?/';
The file I edited was /usr/share/cacti/site/functions.php, line 3684.
Hope it helps anyone as helped me.
Best regards.
peraltagaston

Thanks very much for posting this workaround.
Was dreading a Cacti update to fix this. That one character was it. You rock !!! :D
Slightly different line further down in my install but easy enough to find in my Raspberry PI install.

$sPattern = '/([\w\s\'\"\+]+[\s]+)?(<)?(([\w\-\.\+]+)@((?:[\w\-]+\.)+)([a-zA-Z]{2,4}))?(>)?/';

Need this to get emails for when my wireless security cameras go down.
Shots fired (drug/gang related) just across the street this week and the one camera with a view had been down for 3 days. :oops:

jbirch
thak you to all!! there is very funcionally for me too!!
regards!!
var2611
Posts: 1
Joined: Thu Jun 23, 2022 7:54 am

Re: Cacti 1.2.2 + php 7.3 Email showing "you must provide at least one recipient email address"

Post by var2611 »

Thanks for this solution it's worked.

But there is a small change in path of the function.php file.
New path for the function.php file is : /usr/share/cacti/site/lib/functions.php
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests