diff --git a/html/autocomplete.php b/html/autocomplete.php index 0a263d9f9c10f66ca0e03893d6aeeabf0e8b05e8..430e3e5f746699aec3983e0682b612f30b6a4073 100644 --- a/html/autocomplete.php +++ b/html/autocomplete.php @@ -30,8 +30,8 @@ session::global_set('errorsAlreadyPosted', array()); /* Logged in? Simple security check */ if (!session::global_is_set('ui')) { - new log("security", "unknown", "", array(), "Error: autocomplete.php called without session"); - header ("Location: index.php"); + logging::log('security', 'unknown', '', array(), 'Error: autocomplete.php called without session'); + header ('Location: index.php'); exit; } diff --git a/html/getbin.php b/html/getbin.php index ce7f9846bbb9e3d64369e9d329e2a3e3f519378a..be08b95f36e991dd4ae631d35324294d33a54bfa 100644 --- a/html/getbin.php +++ b/html/getbin.php @@ -31,8 +31,8 @@ session::global_set('errorsAlreadyPosted', array()); /* Logged in? Simple security check */ if (!session::global_is_set('ui')) { - new log("security", "unknown", "", array(), "Error: getbin.php called without session"); - header ("Location: index.php"); + logging::log('security', 'unknown', '', array(), 'Error: getbin.php called without session'); + header ('Location: index.php'); exit; } diff --git a/html/index.php b/html/index.php index e5db9d2c795d74117c2df34488a010cdde55714d..edbae9c12b55096b4cd5ea026a274d926dc15eb6 100644 --- a/html/index.php +++ b/html/index.php @@ -293,9 +293,9 @@ class Index { $ui = ldap_login_user(self::$username, self::$password); if ($ui === NULL || !$ui) { if (isset($_SERVER['REMOTE_ADDR'])) { - new log('security', 'login', '', array(), 'Authentication failed for user "'.self::$username.'" [from '.$_SERVER['REMOTE_ADDR'].']'); + logging::log('security', 'login', '', array(), 'Authentication failed for user "'.self::$username.'" [from '.$_SERVER['REMOTE_ADDR'].']'); } else { - new log('security', 'login', '', array(), 'Authentication failed for user "'.self::$username.'"'); + logging::log('security', 'login', '', array(), 'Authentication failed for user "'.self::$username.'"'); } $message = _('Please check the username/password combination.'); $smarty->assign ('nextfield', 'password'); @@ -329,7 +329,7 @@ class Index { $expired = $ui->expired_status(); if ($expired == POSIX_ACCOUNT_EXPIRED) { - new log('security', 'login', '', array(), 'Account for user "'.self::$username.'" has expired'); + logging::log('security', 'login', '', array(), 'Account for user "'.self::$username.'" has expired'); $message = _('Account locked. Please contact your system administrator!'); $smarty->assign ('nextfield', 'password'); return FALSE; @@ -343,7 +343,7 @@ class Index { { global $config; /* Not account expired or password forced change go to main page */ - new log('security', 'login', '', array(), 'User "'.self::$username.'" logged in successfully.'); + logging::log('security', 'login', '', array(), 'User "'.self::$username.'" logged in successfully.'); session::global_set('connected', 1); $config->checkLdapConfig(); // check that newly installed plugins have their configuration in the LDAP session::global_set('DEBUGLEVEL', $config->get_cfg_value('DEBUGLEVEL')); diff --git a/html/main.php b/html/main.php index 464b779cb269e19d74df258bf35bc73107c49915..27e3a9b950980419a6ff4a443279638193f26df2 100644 --- a/html/main.php +++ b/html/main.php @@ -49,7 +49,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { /* Logged in? Simple security check */ if (!session::global_is_set('connected')) { - new log('security', 'login', '', array(), 'main.php called without session - logging out'); + logging::log('security', 'login', '', array(), 'main.php called without session - logging out'); header ('Location: index.php?message=nosession'); exit; } @@ -57,7 +57,7 @@ if (!session::global_is_set('connected')) { /* Check for uniqe ip address */ $ui = session::global_get('ui'); if ($_SERVER['REMOTE_ADDR'] != $ui->ip) { - new log('security', 'login', '', array(), 'main.php called with session which has a changed IP address.'); + logging::log('security', 'login', '', array(), 'main.php called with session which has a changed IP address.'); header ('Location: index.php?signout=1&message=newip'); exit; } @@ -84,7 +84,7 @@ if (session::global_get('_LAST_PAGE_REQUEST') != '') { */ if ($request_time > $max_life) { session::destroy(); - new log('security', 'login', '', array(), 'main.php called with expired session - logging out'); + logging::log('security', 'login', '', array(), 'main.php called with expired session - logging out'); header ('Location: index.php?signout=1&message=expired'); exit; } @@ -114,7 +114,7 @@ if (isset($global_check) && $config->get_cfg_value("forceglobals") == "TRUE") { _("Fatal error: Register globals is on. FusionDirectory will refuse to login unless this is fixed by an administrator."), FATAL_ERROR_DIALOG); - new log("security", "login", "", array(), "Register globals is on. For security reasons, this should be turned off."); + logging::log('security', 'login', '', array(), 'Register globals is on. For security reasons, this should be turned off.'); session::destroy (); exit; } @@ -133,11 +133,11 @@ $smarty->assign("hideMenus", FALSE); if ($config->get_cfg_value("handleExpiredAccounts") == "TRUE") { $expired = $ui->expired_status(); if (($expired == POSIX_WARN_ABOUT_EXPIRATION) && !session::is_set('POSIX_WARN_ABOUT_EXPIRATION__DONE')) { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, "This user account (".$ui->uid.") is about to expire"); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, 'This user account ('.$ui->uid.') is about to expire'); // The users password is about to xpire soon, display a warning message. - new log("security", "fusiondirectory", "", array(), "password for user '".$ui->uid."' is about to expire"); - msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG); + logging::log('security', 'fusiondirectory', '', array(), 'password for user "'.$ui->uid.'" is about to expire'); + msg_dialog::display(_('Password change'), _('Your password is about to expire, please change your password!'), INFO_DIALOG); session::set('POSIX_WARN_ABOUT_EXPIRATION__DONE', TRUE); } elseif ($expired == POSIX_FORCE_PASSWORD_CHANGE) { @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, "This user account expired"); @@ -165,7 +165,7 @@ if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])) { $plugin_dir = $plist->get_path($plug); session::global_set('plugin_dir', $plugin_dir); if ($plugin_dir == '') { - new log('security', 'fusiondirectory', '', array(), "main.php called with invalid plug parameter \"$plug\""); + logging::log('security', 'fusiondirectory', '', array(), "main.php called with invalid plug parameter \"$plug\""); header ('Location: index.php?signout=1&message=invalidparameter&plug='.$plug); exit; } diff --git a/include/class_log.inc b/include/class_logging.inc similarity index 57% rename from include/class_log.inc rename to include/class_logging.inc index b42d2fc625e196d12df0dd62411549f6c55e5ffb..b9a38c1469c22aa19f17bae48cfd3854cc23af8e 100644 --- a/include/class_log.inc +++ b/include/class_logging.inc @@ -33,9 +33,11 @@ * \version 2.6 * \date 11.04.2007 */ -class log { +class logging { + static $validActions = array('modify','create','remove','copy','snapshot','view','security','debug'); + /*! - * \brief logging constructor + * \brief logging method * * \param $action One of these values (modify|create|remove|snapshot|copy) * @@ -46,54 +48,40 @@ class log { * \param $changes_array An array containing names of all touched attributes * * \param $result A status message, containing errors or success messages - * - * \sa log() */ - function __construct($action, $objecttype, $object, $changes_array = array(), $result = "") + static function log ($action, $objecttype, $object, $changes_array = array(), $result = '') { + global $config, $ui; if (!is_array($changes_array)) { - trigger_error("log(string,string,string,array(),bool). Forth parameter must be an array."); + trigger_error('log(string,string,string,array(),bool). Forth parameter must be an array.'); $changes_array = array(); } - $entry = array(); - if (!session::global_is_set('config')) { - $entry['user'] = "unkown"; - } else { - $ui = get_userinfo(); - $entry['user'] = @$ui->dn; - } - - /* Create string out of changes */ - $changes = ""; - foreach ($changes_array as $str) { - $changes .= $str.","; - } - $changes = preg_replace("/,$/", "", $changes); - /* Create data object */ - $entry['timestamp'] = time(); - $entry['action'] = $action; - $entry['objecttype'] = $objecttype; - $entry['object'] = $object; - $entry['changes'] = $changes; - $entry['result'] = $result; - - global $config; - if (!isset($config) && empty($entry['user'])) { - $entry['user'] = "unknown"; + $entry = array( + 'timestamp' => time(), + 'action' => $action, + 'objecttype' => $objecttype, + 'object' => $object, + 'changes' => implode(',', $changes_array), + 'result' => $result + ); + if (isset($ui->dn) && !empty($ui->dn)) { + $entry['user'] = $ui->dn; + } else { + $entry['user'] = 'unknown'; } /* Check if all given values are valid */ - $msgs = @log::check($entry); + $msgs = static::check($entry); if (count($msgs)) { foreach ($msgs as $msg) { - trigger_error("Logging failed, reason was: ".$msg); - msg_dialog::display(_("Internal error"), sprintf(_("Logging failed: %s"), $msg), ERROR_DIALOG); + trigger_error('Logging failed, reason was: '.$msg); + msg_dialog::display(_('Internal error'), sprintf(_('Logging failed: %s'), $msg), ERROR_DIALOG); } } else { - if (is_object($config) && preg_match("/true/i", $config->get_cfg_value("logging", ""))) { - $this->log_into_syslog($entry); + if (is_object($config) && preg_match('/true/i', $config->get_cfg_value('logging', ''))) { + static::log_into_syslog($entry); } } } @@ -103,34 +91,33 @@ class log { * * \param Array $entry to be checked */ - function check($entry = array()) + static protected function check($entry = array()) { $msgs = array(); - if (!isset($entry['action']) || !in_array($entry['action'], array("modify","create","remove","copy","snapshot","view","security","debug"))) { - $msgs[] = sprintf(_("Invalid option '%s' specified!"), $entry['action']); + if (!isset($entry['action']) || !in_array($entry['action'], static::$validActions)) { + $msgs[] = sprintf(_('Invalid option "%s" specified!'), $entry['action']); } if (!isset($entry['objecttype']) || empty($entry['objecttype'])) { - $msgs[] = _("Specified objectType is empty or invalid!"); + $msgs[] = _('Specified objectType is empty or invalid!'); } return $msgs; } - /* * \brief This function is used to into the systems syslog * * \param Array $entry Entry to be loged */ - function log_into_syslog($entry) + static function protected log_into_syslog($entry) { - $str = ""; + $str = ''; if (empty($entry['object']) && empty($entry['changes'])) { - $str = "(".$entry['action'].") ".$entry['objecttype'].": ".$entry['result']; + $str = '('.$entry['action'].') '.$entry['objecttype'].': '.$entry['result']; } else { - $str = "(".$entry['action'].") ".$entry['object']." of type ".$entry['objecttype']." ".$entry['changes'].": ".$entry['result']; + $str = '('.$entry['action'].') '.$entry['object'].' of type '.$entry['objecttype'].' '.$entry['changes'].': '.$entry['result']; } fusiondirectory_log($str); } diff --git a/include/class_management.inc b/include/class_management.inc index 9ee6eccda0fe83933bbf598231ca26547ff0db95..b05f5b7f876935376fc6ec7678a844661fd82b27 100644 --- a/include/class_management.inc +++ b/include/class_management.inc @@ -403,8 +403,8 @@ class management // Remove the lock for the current object. del_lock($this->dn); } else { - msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG); - new log("security", "group/".get_class($this), $dn, array(), "Tried to trick deletion."); + msg_dialog::display(_('Permission error'), msgPool::permDelete(), ERROR_DIALOG); + logging::log('security', 'group/'.get_class($this), $dn, array(), 'Tried to trick deletion.'); } } diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 80f9b77720085d5e0dc46e394ec348facf61bbbb..0b3f77390d769d2f415861d15b6fc7aade447e70 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -907,7 +907,7 @@ class plugin $ldap->cd($config->current['BASE']); $ldap->create_missing_trees(preg_replace("/^[^,]+,/", '', $dst_dn)); if (!$ldap->rename_dn($src_dn, $dst_dn)) { - new log('debug', 'Ldap Protocol v3 implementation error, ldap_rename failed.', + logging::log('debug', 'Ldap Protocol v3 implementation error, ldap_rename failed.', "FROM: $src_dn -- TO: $dst_dn", array(), $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()); @@ -1491,7 +1491,7 @@ class plugin if ($ui->dn == $old_dn) { $ui->dn = $new_dn; session::global_set('ui', $ui); - new log("view", "acl/".get_class($this), $this->dn, array(), "Updated current object dn from '".$old_dn."' to '".$new_dn."'"); + logging::log('view', 'acl/'.get_class($this), $this->dn, array(), 'Updated current object dn from "'.$old_dn.'" to "'.$new_dn.'"'); } } diff --git a/include/functions.inc b/include/functions.inc index 1795e8ee3c02fff1242fba05b23574dca54b1043..34e6ec75e6e3aa6183c0c00b8c7a8d5b1eaec587 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -926,7 +926,7 @@ function get_sub_list($filter, $category, $sub_deps, $base = '', $attributes = a /* Log this fall back, it may be an unpredicted behaviour. */ if (!count($sub_bases) && !count($departments)) { - new log('debug', 'all', __FILE__, $attributes, + logging::log('debug', 'all', __FILE__, $attributes, sprintf("get_sub_list(): Falling back to get_list(), due to empty sub_bases parameter.". " This may slow down FusionDirectory. Search was: '%s'", $filter)); } @@ -2990,7 +2990,7 @@ function update_accessTo($from, $to) if (!$ldap->success()) { msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, "update_accessTo($from,$to)"), LDAP_ERROR); } - new log("modify", "update_accessTo($from,$to)", $dn, array_keys($new_attrs), $ldap->get_error()); + logging::log('modify', "update_accessTo($from,$to)", $dn, array_keys($new_attrs), $ldap->get_error()); } } diff --git a/include/php_setup.inc b/include/php_setup.inc index 9c0d29b17ca8504427f9402b3c04a2c6bcc9ba62..2b7dcc855366ae6efa4aae80fd57c94566a1a1e5 100644 --- a/include/php_setup.inc +++ b/include/php_setup.inc @@ -187,11 +187,11 @@ function gosaRaiseError($errno, $errstr, $errfile, $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") { + if (isset($config->data) && $config->get_cfg_value('displayerrors') != 'TRUE') { /* Write to syslog */ - if (class_exists("log") && !preg_match("/No such object/", $errstr)) { - new log("view", "error", "", array(), "PHP error: $errstr ($errfile, line $errline)"); + if (class_exists('log') && !preg_match('/No such object/', $errstr)) { + logging::log('view', 'error', '', array(), "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); @@ -199,8 +199,8 @@ function gosaRaiseError($errno, $errstr, $errfile, $errline) } /* Send all errors to logging class, except "Ldap : No such object" messages*/ - if (class_exists("log") && !preg_match("/No such object/", $errstr)) { - new log("debug", "all", $errfile, array(), "Type:".$errno.", Message:".$errstr.", File:".$errfile.", Line: ".$errline); + if (class_exists('log') && !preg_match('/No such object/', $errstr)) { + logging::log('debug', 'all', $errfile, array(), 'Type:'.$errno.', Message:'.$errstr.', File:'.$errfile.', Line: '.$errline); } /* Create header as needed */ diff --git a/include/simpleplugin/class_simpleManagement.inc b/include/simpleplugin/class_simpleManagement.inc index b53cff800b2808b2c9d9bb87b2368acd93ab90e3..75764214f22597778976808c85a0d494ad6221f5 100644 --- a/include/simpleplugin/class_simpleManagement.inc +++ b/include/simpleplugin/class_simpleManagement.inc @@ -717,8 +717,8 @@ class simpleManagement extends management // Remove the lock for the current object. del_lock($this->dn); } else { - msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG); - new log("security", "simpleManagement/".get_class($this), $dn, array(), "Tried to trick deletion."); + msg_dialog::display(_('Permission error'), msgPool::permDelete(), ERROR_DIALOG); + logging::log('security', 'simpleManagement/'.get_class($this), $dn, array(), 'Tried to trick deletion.'); } } diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index 028f7169f5f5d7b169c5aa46bce3fb2c7db245fa..75d266f04ca4c55735c5441b4e1fce3150a28aad 100644 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -592,10 +592,10 @@ class simplePlugin extends plugin protected function post_remove () { - new log("remove", "plugin/".get_class($this), $this->dn, array_keys($this->attrs), $this->ldap_error); + logging::log('remove', 'plugin/'.get_class($this), $this->dn, array_keys($this->attrs), $this->ldap_error); /* Optionally execute a command after we're done */ - $this->handle_post_events("remove"); + $this->handle_post_events('remove'); } /*! \brief This function handle $_POST informations @@ -714,10 +714,10 @@ class simplePlugin extends plugin /* Propagate and log the event */ if ($this->initially_was_account) { $this->handle_post_events('modify'); - new log('modify', 'plugin/'.get_class($this), $this->dn, array_keys($this->attrs), $this->ldap_error); + logging::log('modify', 'plugin/'.get_class($this), $this->dn, array_keys($this->attrs), $this->ldap_error); } else { $this->handle_post_events('add'); - new log('create', 'plugin/'.get_class($this), $this->dn, array_keys($this->attrs), $this->ldap_error); + logging::log('create', 'plugin/'.get_class($this), $this->dn, array_keys($this->attrs), $this->ldap_error); } } diff --git a/include/simpleplugin/class_simpleService.inc b/include/simpleplugin/class_simpleService.inc index 6001c616b6869672fac9f2a9c48cab2347c74b76..6075de437145eddb022dade2ec66fb8036f4d3da 100644 --- a/include/simpleplugin/class_simpleService.inc +++ b/include/simpleplugin/class_simpleService.inc @@ -54,7 +54,7 @@ class simpleService extends simplePlugin { { if ($this->is_account && !$this->view_logged) { $this->view_logged = TRUE; - new log("view", "server/".get_class($this), $this->dn); + logging::log('view', 'server/'.get_class($this), $this->dn); } $str = parent::execute(); diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc index de24e6cc175c3dbd5c9d8d4cde9a68c813aa9274..bdfbc4c06828d33538df1517d08431eb030c2459 100644 --- a/setup/class_setupStep_Migrate.inc +++ b/setup/class_setupStep_Migrate.inc @@ -494,7 +494,7 @@ class Step_Migrate extends setupStep $res = $ldap->add($testEntry); $ldap->cat($dn); if (!$ldap->count()) { - new log("view", "setup/".get_class($this), $dn, array(), $ldap->get_error()); + logging::log('view', 'setup/'.get_class($this), $dn, array(), $ldap->get_error()); throw new CheckFailedException( _('Failed'), sprintf(_('The specified user "%s" does not have full access to your LDAP database.'), $config->current['ADMINDN']) @@ -505,7 +505,7 @@ class Step_Migrate extends setupStep $res = $ldap->rmDir($dn); $ldap->cat($dn); if ($ldap->count()) { - new log("view", "setup/".get_class($this), $dn, array(), $ldap->get_error()); + logging::log('view', 'setup/'.get_class($this), $dn, array(), $ldap->get_error()); throw new CheckFailedException( _('Failed'), sprintf(_('The specified user "%s" does not have full access to your ldap database.'), $config->current['ADMINDN'])