X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_config.inc;h=daad80f35cdb78633093374f283f65346964460e;hb=43b7d67048ad0adbd30a1bec9320c337d71151d5;hp=667cc1abf79479fa3ddb39fdf75101eac8e202c4;hpb=8449bbe15c331d6af1f3511f5c6cf9b7971465f1;p=gosa.git diff --git a/gosa-core/include/class_config.inc b/gosa-core/include/class_config.inc index 667cc1abf..daad80f35 100644 --- a/gosa-core/include/class_config.inc +++ b/gosa-core/include/class_config.inc @@ -20,6 +20,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/*! \brief Configuration class + * \ingroup coreclasses + * + * The configuration class, responsible for parsing and querying the + * gosa configuration file. + */ + class config { /* XML parser */ @@ -31,14 +38,17 @@ class config { var $section= ""; var $currentLocation= ""; - /* Selected connection */ - var $current= array(); + /*! \brief Store configuration for current location */ + var $current= array(); /* Link to LDAP-server */ var $ldap= NULL; var $referrals= array(); - /* Configuration data */ + /* \brief Configuration data + * + * - $data['SERVERS'] contains server informations. + * */ var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(), 'MAIN' => array(), 'MENU' => array(), 'SERVICE' => array()); @@ -53,6 +63,12 @@ class config { var $filename = ""; var $last_modified = 0; + /*! \brief Class constructor of the config class + * + * \param string 'filename' path to the configuration file + * \param string 'basedir' base directory + * + * */ function config($filename, $basedir= "") { $this->parser = xml_parser_create(); @@ -67,7 +83,14 @@ class config { } } - + + /*! \brief Check and reload the configuration + * + * This function checks if the configuration has changed, since it was + * read the last time and reloads it. It uses the file mtime to check + * weither the file changed or not. + * + * */ function check_and_reload() { global $ui; @@ -102,9 +125,16 @@ class config { } + /*! \brief Parse the given configuration file + * + * Parses the configuration file and displays errors if there + * is something wrong with it. + * + * \param string 'filename' The filename of the configuration file. + * */ + function parse($filename) { - $this->data = array( "TABS" => array(), "LOCATIONS" => array(), @@ -124,6 +154,11 @@ class config { msg_dialog::display(_("Configuration error"), $msg, FATAL_ERROR_DIALOG); exit; } + + // Default schemacheck to "true" + if(!isset($this->data['MAIN']['SCHEMACHECK'])){ + $this->data['MAIN']['SCHEMACHECK'] = "true"; + } } function tag_open($parser, $tag, $attrs) @@ -238,12 +273,36 @@ class config { function get_credentials($creds) { if (isset($_SERVER['HTTP_GOSA_KEY'])){ - return (cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY'])); + if (!session::global_is_set('HTTP_GOSA_KEY_CACHE')){ + session::global_set('HTTP_GOSA_KEY_CACHE',array()); + } + $cache = session::global_get('HTTP_GOSA_KEY_CACHE'); + if(!isset($cache[$creds])){ + $cache[$creds] = cred_decrypt($creds, $_SERVER['HTTP_GOSA_KEY']); + session::global_set('HTTP_GOSA_KEY_CACHE',$cache); + } + return ($cache[$creds]); } return ($creds); } + /*! \brief Get a LDAP link object + * + * This function can be used to get an ldap object, which in turn can + * be used to query the LDAP. See the LDAP class for more information + * on how to use it. + * + * Example usage: + * \code + * $ldap = $this->config->get_ldap_link(); + * \endcode + * + * \param boolean sizelimit Weither to impose a sizelimit on the LDAP object or not. + * Defaults to false. If set to true, the size limit in the configuration + * file will be used to set the option LDAP_OPT_SIZELIMIT. + * \return ldapMultiplexer object + */ function get_ldap_link($sizelimit= FALSE) { if($this->ldap === NULL || !is_resource($this->ldap->cid)){ @@ -281,13 +340,14 @@ class config { return($obj); } + /*! \brief Set the current location + * + * \param string name the name of the location + */ function set_current($name) { $this->current= $this->data['LOCATIONS'][$name]; - if (!isset($this->current['SAMBAVERSION'])){ - $this->current['SAMBAVERSION']= 3; - } if (!isset($this->current['USERRDN'])){ $this->current['USERRDN']= "ou=people"; } @@ -364,6 +424,13 @@ class config { $this->load_servers(); } + + /*! \brief Load server information from config/LDAP + * + * This function searches the LDAP for servers (e.g. goImapServer, goMailServer etc.) + * and stores information about them $this->data['SERVERS']. In the case of mailservers + * the main section of the configuration file is searched, too. + */ function load_servers () { /* Only perform actions if current is set */ @@ -522,12 +589,12 @@ class config { $ldap->search ("(objectClass=goLogDBServer)"); if ($ldap->count()){ $attrs= $ldap->fetch(); - if(!isset($attrs['goLogDB'][0])){ - $attrs['goLogDB'][0] = "gomon"; + if(!isset($attrs['gosaLogDB'][0])){ + $attrs['gosaLogDB'][0] = "gomon"; } $this->data['SERVERS']['LOG']= array( 'SERVER' => $attrs['cn'][0], 'LOGIN' => $attrs['goLogAdmin'][0], - 'DB' => $attrs['goLogDB'][0], + 'DB' => $attrs['gosaLogDB'][0], 'PASSWORD' => $attrs['goLogPassword'][0]); } @@ -608,31 +675,30 @@ class config { } /* Get samba servers from LDAP, in case of samba3 */ - if ($this->current['SAMBAVERSION'] == 3){ - $this->data['SERVERS']['SAMBA']= array(); - $ldap->cd ($this->current['BASE']); - $ldap->search ("(objectClass=sambaDomain)"); - while ($attrs= $ldap->fetch()){ - $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>""); - if(isset($attrs["sambaSID"][0])){ - $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0]; - } - if(isset($attrs["sambaAlgorithmicRidBase"][0])){ - $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0]; - } + $this->data['SERVERS']['SAMBA']= array(); + $ldap->cd ($this->current['BASE']); + $ldap->search ("(objectClass=sambaDomain)"); + while ($attrs= $ldap->fetch()){ + $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]= array( "SID" =>"","RIDBASE" =>""); + if(isset($attrs["sambaSID"][0])){ + $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["SID"] = $attrs["sambaSID"][0]; + } + if(isset($attrs["sambaAlgorithmicRidBase"][0])){ + $this->data['SERVERS']['SAMBA'][$attrs['sambaDomainName'][0]]["RIDBASE"] = $attrs["sambaAlgorithmicRidBase"][0]; } + } - /* If no samba servers are found, look for configured sid/ridbase */ - if (count($this->data['SERVERS']['SAMBA']) == 0){ - if (!isset($this->current["SAMBASID"]) || !isset($this->current["SAMBARIDBASE"])){ - msg_dialog::display(_("Configuration error"), _("sambaSID and/or sambaRidBase missing in the configuration!"), ERROR_DIALOG); - } else { - $this->data['SERVERS']['SAMBA']['DEFAULT']= array( - "SID" => $this->current["SAMBASID"], - "RIDBASE" => $this->current["SAMBARIDBASE"]); - } + /* If no samba servers are found, look for configured sid/ridbase */ + if (count($this->data['SERVERS']['SAMBA']) == 0){ + if (!isset($this->current["SAMBASID"]) || !isset($this->current["SAMBARIDBASE"])){ + msg_dialog::display(_("Configuration error"), _("sambaSID and/or sambaRidBase missing in the configuration!"), ERROR_DIALOG); + } else { + $this->data['SERVERS']['SAMBA']['DEFAULT']= array( + "SID" => $this->current["SAMBASID"], + "RIDBASE" => $this->current["SAMBARIDBASE"]); } } + } @@ -817,10 +883,13 @@ class config { return($ret); } - /* This function returns all available Shares defined in this ldap - * There are two ways to call this function, if listboxEntry is true - * only name and path are attached to the array, in it is false, the whole - * entry will be parsed an atached to the result. + /*! \brief Get all available shares defined in the current LDAP + * + * This function returns all available Shares defined in this ldap + * + * \param boolean listboxEntry If set to TRUE, only name and path are + * attached to the array. If FALSE, the whole entry will be parsed an atached to the result. + * \return array */ function getShareList($listboxEntry = false) { @@ -853,7 +922,12 @@ class config { } - /* This function returns all available ShareServer */ + /*! \brief Return al available share servers + * + * This function returns all available ShareServers. + * + * \return array + * */ function getShareServerList() { global $config; @@ -885,7 +959,24 @@ class config { } - /* Check if there's the specified bool value set in the configuration */ + /*! \brief Check if there's the specified bool value set in the configuration + * + * The function checks, weither the specified bool value is set to a true + * value in the configuration file. Considered true are either true or yes, + * case-insensitive. + * + * Example usage: + * \code + * if ($this->config->boolValueIsTrue("main", "copyPaste")) { + * echo "Copy Paste Handling is enabled"; + * } + * \endcode + * + * \param string 'section' Section in the configuration file. + * \param string 'value' Key in the given section, which is subject to check + * + * + * */ function boolValueIsTrue($section, $value) { $section= strtoupper($section); @@ -922,6 +1013,18 @@ class config { } + /*! Search for a configuration setting in different categories + * + * Searches for the value of a given key in the configuration data. + * Optionally the list of categories to search (tabs, main, locations) can + * be specified. The first value that matches is returned. + * + * Example usage: + * \code + * $postcmd = $this->config->search(get_class($this), "POSTCOMMAND", array("menu", "tabs")); + * \endcode + * + * */ function search($class, $value, $categories= "") { if (is_array($categories)){ @@ -943,6 +1046,21 @@ class config { } + /*! \brief Get a configuration value from the config + * + * This returns a configuration value from the config. It either + * uses the data of the current location ($this->current), + * if it contains the value (e.g. current['BASE']) or otherwise + * uses the data from the main configuration section. + * + * If no value is found and an optional default has been specified, + * then the default is returned. + * + * \param string 'name' the configuration key (case-insensitive) + * \param string 'default' a default that is returned, if no value is found + * + * + */ function get_cfg_value($name, $default= "") { $name= strtoupper($name); @@ -960,6 +1078,13 @@ class config { } + /*! \brief Check if current configuration version matches the GOsa version + * + * This function checks if the configuration file version matches the + * version of the gosa version, by comparing it with the configuration + * file version of the example gosa.conf that comes with GOsa. + * If a version mismatch occurs an error is triggered. + * */ function check_config_version() { /* Skip check, if we've already mentioned the mismatch @@ -980,11 +1105,17 @@ class config { } - /* On debian systems the session files are deleted with + /*! \brief Check if session lifetime matches session.gc_maxlifetime + * + * On debian systems the session files are deleted with * a cronjob, which detects all files older than specified * in php.ini:'session.gc_maxlifetime' and removes them. - * This function checks if the gosa.conf value matches the range + * This function checks if the gosa.conf value matches the range * defined by session.gc_maxlifetime. + * + * \return boolean TRUE or FALSE depending on weither the settings match + * or not. If SESSIONLIFETIME is not configured in GOsa it always returns + * TRUE. */ function check_session_lifetime() { @@ -997,6 +1128,63 @@ class config { return(TRUE); } } + + /* Returns true if snapshots are enabled, and false if it is disalbed + There will also be some errors psoted, if the configuration failed */ + function snapshotEnabled() + { + if($this->get_cfg_value("enableSnapshots") == "true"){ + + /* Check if the snapshot_base is defined */ + if ($this->get_cfg_value("snapshotBase") == ""){ + + /* Send message if not done already */ + if(!session::is_set("snapshotFailMessageSend")){ + session::set("snapshotFailMessageSend",TRUE); + msg_dialog::display(_("Configuration error"), + sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."), + "snapshotBase"), ERROR_DIALOG); + } + return(FALSE); + } + + /* Check if the snapshot_base is defined */ + if (!is_callable("gzcompress")){ + + /* Send message if not done already */ + if(!session::is_set("snapshotFailMessageSend")){ + session::set("snapshotFailMessageSend",TRUE); + msg_dialog::display(_("Configuration error"), + sprintf(_("The snapshot functionality is enabled, but the required compression module is missing. Please install '%s'."),"php5-zip / php5-gzip"), ERROR_DIALOG); + } + return(FALSE); + } + + /* check if there are special server configurations for snapshots */ + if ($this->get_cfg_value("snapshotURI") != ""){ + + /* check if all required vars are available to create a new ldap connection */ + $missing = ""; + foreach(array("snapshotURI","snapshotAdminDn","snapshotAdminPassword","snapshotBase") as $var){ + if($this->get_cfg_value($var) == ""){ + $missing .= $var." "; + + /* Send message if not done already */ + if(!session::is_set("snapshotFailMessageSend")){ + session::set("snapshotFailMessageSend",TRUE); + msg_dialog::display(_("Configuration error"), + sprintf(_("The snapshot functionality is enabled, but the required variable '%s' is not set."), + $missing), ERROR_DIALOG); + } + return(FALSE); + } + } + } + return(TRUE); + } + return(FALSE); + } + } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: