From 255d993832f2c7a3b0ea523a98da05f6e77f7fde Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Wed, 21 Nov 2012 00:46:38 +0000 Subject: This is a fix for an empty array condition that causes a dashboard error message: Warning: Invalid argument supplied for foreach() in /usr/local/www/widgets/widgets/snort_alerts.widget.php on line 36 --- config/widget-snort/snort_alerts.widget.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/config/widget-snort/snort_alerts.widget.php b/config/widget-snort/snort_alerts.widget.php index 6d6193d8..b7b60a07 100644 --- a/config/widget-snort/snort_alerts.widget.php +++ b/config/widget-snort/snort_alerts.widget.php @@ -32,7 +32,11 @@ function sksort(&$array, $subkey="id", $sort_ascending=false) { if (count($array)) { $temp_array[key($array)] = array_shift($array); }; - + /* an empty array causes sksort to fail - this test alleviates the error */ + if(empty($array)) + { + return false; + } foreach ($array as $key => $val){ $offset = 0; $found = false; @@ -49,6 +53,8 @@ function sksort(&$array, $subkey="id", $sort_ascending=false) { if ($sort_ascending) { $array = array_reverse($temp_array); } else $array = $temp_array; + /* below is the complement for empty array test */ + return true; }; /* check if firewall widget variable is set */ @@ -128,4 +134,4 @@ if (is_array($snort_alerts)) { }; ?> - \ No newline at end of file + -- cgit v1.2.3 From 81f6a4d63d9766712cc3e5693d899d7405030f96 Mon Sep 17 00:00:00 2001 From: Tigersharke Date: Wed, 21 Nov 2012 03:33:44 +0000 Subject: As suggested, test moved ahead of first instance array is used. The first 'for each' in sksort is where the error presents. --- config/widget-snort/snort_alerts.widget.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/widget-snort/snort_alerts.widget.php b/config/widget-snort/snort_alerts.widget.php index b7b60a07..bb51a387 100644 --- a/config/widget-snort/snort_alerts.widget.php +++ b/config/widget-snort/snort_alerts.widget.php @@ -29,14 +29,14 @@ global $config, $g; /* array sorting */ function sksort(&$array, $subkey="id", $sort_ascending=false) { - if (count($array)) { - $temp_array[key($array)] = array_shift($array); - }; /* an empty array causes sksort to fail - this test alleviates the error */ if(empty($array)) { return false; } + if (count($array)) { + $temp_array[key($array)] = array_shift($array); + }; foreach ($array as $key => $val){ $offset = 0; $found = false; -- cgit v1.2.3