From afcd9360f4151507d19801555f862f7588df0f14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org>
Date: Tue, 12 Nov 2019 10:46:25 +0100
Subject: [PATCH] :ambulance: fix(logging) Remove view action, replace debug by
 error in logging

issue #6046
---
 include/class_logging.inc                      |  8 ++++----
 include/php_setup.inc                          | 16 +++++-----------
 include/simpleplugin/class_simplePlugin.inc    |  7 ++-----
 plugins/admin/groups/class_groupManagement.inc |  1 -
 setup/class_setupStepMigrate.inc               |  4 ++--
 5 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/include/class_logging.inc b/include/class_logging.inc
index 93ea2a05c..dbc06eede 100644
--- a/include/class_logging.inc
+++ b/include/class_logging.inc
@@ -35,16 +35,16 @@
  */
 class logging
 {
-  static $validActions = ['modify','create','remove','copy','snapshot','view','security','debug'];
+  static $validActions = ['modify','create','remove','copy','snapshot','security','error'];
 
   /*!
    * \brief logging method
    *
-   * \param $action         One of these values (modify|create|remove|snapshot|copy|view|security|debug)
+   * \param $action         One of these values (modify|create|remove|copy|snapshot|security|error)
    *
-   * \param $objecttype     represents the current edited objecttype, like user/user
+   * \param $objecttype     represents the current edited objecttype, like user/user, or the event, like logout
    *
-   * \param $object         represents the current edited object dn
+   * \param $object         represents the current edited object dn, or the target of the operation
    *
    * \param $changes_array  An array containing names of all touched attributes
    *
diff --git a/include/php_setup.inc b/include/php_setup.inc
index 3d73b54f6..3d327e15d 100644
--- a/include/php_setup.inc
+++ b/include/php_setup.inc
@@ -189,23 +189,17 @@ function gosaRaiseError ($errno, $errstr, $errfile, $errline)
     return;
   }
 
+  /* Send all errors to logging class, except "Ldap : No such object" messages*/
+  if (class_exists('logging') && !preg_match('/No such object/', $errstr)) {
+    logging::log('error', 'php', $errfile, [], 'Type:'.$errno.', Message:'.$errstr.', File:'.$errfile.', Line: '.$errline);
+  }
+
   /* Error messages are hidden in FusionDirectory, so we only send them to the logging class and abort here */
   if (isset($config->data) && $config->get_cfg_value('displayerrors') != 'TRUE') {
-
-    /* Write to syslog */
-    if (class_exists('logging') && !preg_match('/No such object/', $errstr)) {
-      logging::log('view', 'error', '', [], "PHP error: $errstr ($errfile, line $errline)");
-    }
-
     set_error_handler('gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT);
     return;
   }
 
-  /* Send all errors to logging class, except "Ldap : No such object" messages*/
-  if (class_exists('logging') && !preg_match('/No such object/', $errstr)) {
-    logging::log('debug', 'all', $errfile, [], 'Type:'.$errno.', Message:'.$errstr.', File:'.$errfile.', Line: '.$errline);
-  }
-
   /* Create header as needed */
   if ($error_collector == "") {
 
diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc
index 7cf1d579f..458af6dcd 100644
--- a/include/simpleplugin/class_simplePlugin.inc
+++ b/include/simpleplugin/class_simplePlugin.inc
@@ -593,8 +593,7 @@ class simplePlugin implements SimpleTab
     $ldap->cd($config->current['BASE']);
     $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dst_dn));
     if (!$ldap->rename_dn($src_dn, $dst_dn)) {
-      logging::log('debug', 'Ldap Protocol v3 implementation error, ldap_rename failed.',
-        "FROM: $src_dn  -- TO: $dst_dn", [], $ldap->get_error());
+      logging::log('error', 'ldap', "FROM: $src_dn -- TO: $dst_dn", [], 'Ldap Protocol v3 implementation error, ldap_rename failed: '.$ldap->get_error());
       @DEBUG(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, "Rename failed FROM: $src_dn  -- TO:  $dst_dn",
         'Ldap Protocol v3 implementation error. Error:'.$ldap->get_error());
       return $ldap->get_error();
@@ -602,9 +601,7 @@ class simplePlugin implements SimpleTab
 
     /* Update userinfo if necessary */
     if (preg_match('/'.preg_quote($src_dn, '/').'$/i', $ui->dn)) {
-      $ui_dn = preg_replace('/'.preg_quote($src_dn, '/').'$/i', $dst_dn, $ui->dn);
-      logging::log('view', 'acl/'.get_class($this), $this->dn, [], 'Updated userinfo dn from "'.$ui->dn.'" to "'.$ui_dn.'"');
-      $ui->dn = $ui_dn;
+      $ui->dn = preg_replace('/'.preg_quote($src_dn, '/').'$/i', $dst_dn, $ui->dn);
     }
 
     /* Check if departments were moved. If so, force the reload of $config departments cache */
diff --git a/plugins/admin/groups/class_groupManagement.inc b/plugins/admin/groups/class_groupManagement.inc
index 1ffc6dfcd..f35fd40ba 100644
--- a/plugins/admin/groups/class_groupManagement.inc
+++ b/plugins/admin/groups/class_groupManagement.inc
@@ -154,7 +154,6 @@ class groupManagement extends management
         if ($o_queue->is_currently_installing($mac_address)) {
           msg_dialog::display(_('Action canceled'), sprintf(_('System %s is currently installing'), $dn), ERROR_DIALOG);
           unset($mac[$key]);
-          logging::log('security', 'systems/'.get_class($this), '', [], 'Skip adding "argonautAction::'.$event.'" for mac "'.$mac_address.'", there is already a job in progress.');
         }
       }
     }
diff --git a/setup/class_setupStepMigrate.inc b/setup/class_setupStepMigrate.inc
index 7c46ceae4..8897217b6 100644
--- a/setup/class_setupStepMigrate.inc
+++ b/setup/class_setupStepMigrate.inc
@@ -509,7 +509,7 @@ class setupStepMigrate extends setupStep
     $res = $ldap->add($testEntry);
     $ldap->cat($dn);
     if (!$ldap->count()) {
-      logging::log('view', 'setup/'.get_class($this), $dn, [], $ldap->get_error());
+      logging::log('error', 'setup/'.get_class($this), $dn, [], $ldap->get_error());
       throw new CheckFailedException(
         _('Failed'),
         sprintf(_('The specified user "%s" does not have full access to your LDAP database.'), $config->current['ADMINDN'])
@@ -520,7 +520,7 @@ class setupStepMigrate extends setupStep
     $res = $ldap->rmDir($dn);
     $ldap->cat($dn);
     if ($ldap->count()) {
-      logging::log('view', 'setup/'.get_class($this), $dn, [], $ldap->get_error());
+      logging::log('error', 'setup/'.get_class($this), $dn, [], $ldap->get_error());
       throw new CheckFailedException(
         _('Failed'),
         sprintf(_('The specified user "%s" does not have full access to your ldap database.'), $config->current['ADMINDN'])
-- 
GitLab