rbicelli / pfsense-zabbix-template

Zabbix Template for pfSense
Apache License 2.0
238 stars 107 forks source link

PHP Error on PFSense 23.01 #135

Closed stephanehofman closed 7 months ago

stephanehofman commented 1 year ago

Hello, Following https://github.com/rbicelli/pfsense-zabbix-template/issues/132 I have updated the script to last version, but I still have an error PHP errors

PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1131, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1131
Stack trace:
#0 /root/scripts/pfsense_zbx.php(1131): in_array('62399625c19f2', NULL)
#1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validFrom.max')
#2 {main}
thrown @ 2023-03-07 09:45:37
PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1139, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1139
Stack trace:
#0 /root/scripts/pfsense_zbx.php(1139): in_array('62399625c19f2', NULL)
#1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validTo.min')
#2 {main}
thrown @ 2023-03-07 09:45:38
edeckers commented 1 year ago

Hi @stephanehofman , I've analyzed this code, but I fail to see how this specific error can occur. Are you absolutely sure you're using the latest version of the script? I'll share my observations below so maybe someone else can chime in with new insights.

Observations

The error occurs on lines 1131 and 1139 where the value of $revoked_cert_refs appears to be NULL, that issue was supposed to be fixed by initializing $revoked_cert_refs with an empty array on line 1119. So, since it is initialized with value [] it has to be set to NULL explicitly somewhere down the line to cause the errors you're experiencing. However, there are only four usages of $revoked_cert_refs in the entire script, two of which are assignments:

image

On line 1119 you'll find the initial assignment I mentioned earlier, and the other mutation of the array is on line 1122 where an item is pushed to the end of it. So if there is a bug in the latest version of the script, then I expect this to be the culprit. I fail to see how though, because I've tried to upset PHP with some possible troublesome inputs but to no avail:

<?php 
$xs = [];
var_dump($xs);
// array(0) {
// }

$xs[] = 1;
var_dump($xs);
// array(1) {
//   [0]=>
//   int(1)
// }

$xs[] = NULL;
var_dump($xs);
// array(2) {
//   [0]=>
//   int(1)
//   [1]=>
//   NULL
// }

var_dump(in_array("62399625c19f2", $xs));
// bool(false)
var_dump(in_array("62399625c19f2", [NULL]));
// bool(false)
stephanehofman commented 1 year ago

I have downloaded this version : https://raw.githubusercontent.com/rbicelli/pfsense-zabbix-template/master/pfsense_zbx.php

edeckers commented 1 year ago

That is the correct url; I'm not sure how to reproduce the problem then unfortunately :(

Hopefully somebody else can help.

jysl commented 1 year ago

I am just a system admin that don't know how to code, and not sure what i am doing but hope this help

That pfsense_zbx.php work for me but I do need to make the change that LegsAJimbo sugguested on the fix

With that said, I managed to suppress the error by changing line 978 from: if (count($leases) > 0) { to if (is_countable($leases) && count($leases) > 0) {

And line 982 from: if (count($pools) > 0) { to if (is_countable($pools) && count($pools) > 0) {

Also I need to make the change on openvpn for the status on the openvpn to work, thanks hvdhelm on that

// Value mappings // Each value map is represented by an associative array function pfz_valuemap($valuename, $value, $default="0"){ switch ($valuename){

      case "openvpn.server.status":          
                $valuemap = array(
                     "down" => "0",
                     "up" => "1",
                     "connected (success)" => "1",
                     "none" => "2",
                     "reconnecting; ping-restart" => "3",
                     "waiting" => "4",
                     "server_user_listening" => "5");          
      break;

      case "openvpn.client.status":          
                $valuemap = array(
                     "up" => "1",
                     "connected (success)" => "1",
                     "down" => "0",
                     "none" => "0",
                     "reconnecting; ping-restart" => "2");          
      break;
Yarli commented 1 year ago

I had this same problem today, and just copied the raw code and replaced my existing content of the pfsense_zbx.php file and it fixed my problem.

Ignore the version comment at the top of the code in that file. I don't think it's been updated for a while. There was a change to the file a month ago, so not sure if that fixed this issue or not.