From 8a571cb3e6a39eff0fd37a6244914520321f21fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Thu, 4 May 2017 12:22:18 +0200
Subject: [PATCH] Fixes #5509 Catching LDAP exceptions in dashboard tabs

---
 plugins/addons/dashboard/class_dashBoard.inc          |  6 +++++-
 plugins/addons/dashboard/class_dashBoardPasswords.inc | 11 ++++++++++-
 plugins/addons/dashboard/class_dashBoardUsers.inc     | 11 ++++++++++-
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/plugins/addons/dashboard/class_dashBoard.inc b/plugins/addons/dashboard/class_dashBoard.inc
index cb9ec8c49..70ca58bff 100644
--- a/plugins/addons/dashboard/class_dashBoard.inc
+++ b/plugins/addons/dashboard/class_dashBoard.inc
@@ -70,7 +70,11 @@ class dashboard extends simplePlugin
         $nb = objects::count($type);
       } catch (FusionDirectoryException $e) {
         $nb = 0;
-        trigger_error("Problem with $type:".$e->getMessage());
+        msg_dialog::display(
+          _('LDAP error'),
+          sprintf(_('Statistics for type "%s" could not be computed because of the following error: %s'), $type, $e->getMessage()),
+          ERROR_DIALOG
+        );
       }
       if ($nb == 0) {
         continue;
diff --git a/plugins/addons/dashboard/class_dashBoardPasswords.inc b/plugins/addons/dashboard/class_dashBoardPasswords.inc
index 62bccae29..bc95b0c64 100644
--- a/plugins/addons/dashboard/class_dashBoardPasswords.inc
+++ b/plugins/addons/dashboard/class_dashBoardPasswords.inc
@@ -55,7 +55,16 @@ class dashboardPassword extends simplePlugin
 
     $defaultMethod = $config->get_cfg_value('passwordDefaultHash', 'ssha');
     $forceDefault = ($config->get_cfg_value('forcePasswordDefaultHash', 'FALSE') == 'TRUE');
-    $users = objects::ls('user', 'userPassword');
+    try {
+      $users = objects::ls('user', 'userPassword');
+    } catch (LDAPFailureException $e) {
+      msg_dialog::display(
+        _('LDAP error'),
+        sprintf(_('Password statistics could not be computed because of the following LDAP error: %s'), $e->getMessage()),
+        ERROR_DIALOG
+      );
+      $users = array();
+    }
     $nb_accounts = count($users);
     $nb_locked_accounts = 0;
     $methods_stats = array();
diff --git a/plugins/addons/dashboard/class_dashBoardUsers.inc b/plugins/addons/dashboard/class_dashBoardUsers.inc
index 79a637fa4..65aefce18 100644
--- a/plugins/addons/dashboard/class_dashBoardUsers.inc
+++ b/plugins/addons/dashboard/class_dashBoardUsers.inc
@@ -66,7 +66,16 @@ class dashboardUsers extends simplePlugin
   {
     global $config;
     /* User statistics */
-    $nb_accounts = objects::count('user');
+    try {
+      $nb_accounts = objects::count('user');
+    } catch (LDAPFailureException $e) {
+      msg_dialog::display(
+        _('LDAP error'),
+        sprintf(_('Total user number could not be computed because of the following LDAP error: %s'), $e->getMessage()),
+        ERROR_DIALOG
+      );
+      $nb_accounts = 0;
+    }
 
     $ldap = $config->get_ldap_link();
     $ldap->cd($config->current['BASE']);
-- 
GitLab