Code

Fixed broken fetch() call on non existing resources.
[gosa.git] / include / class_config.inc
index da6ca043213d14d660e4afb4c24ed13699dc093f..92c87511716d8da745d968cd700fa5d413b3c131 100644 (file)
@@ -38,7 +38,7 @@ class config  {
 
   /* Configuration data */
   var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
-      'MAIN' => array( 'FAXFORMATS' => array() ),
+      'MAIN' => array(),
       'MENU' => array(), 'SERVICE' => array());
   var $basedir= "";
 
@@ -47,6 +47,8 @@ class config  {
   var $idepartments= array();
   var $adepartments= array();
   var $tdepartments= array();
+  var $filename = "";
+  var $last_modified = 0;
 
   function config($filename, $basedir= "")
   {
@@ -62,16 +64,47 @@ class config  {
     }
   }
 
+  
+  function check_and_reload()
+  {
+    if($this->filename != "" && filemtime($this->filename) != $this->last_modified){
+
+      $this->config_found= FALSE;
+      $this->tags= array();
+      $this->level= 0;
+      $this->gpc= 0;
+      $this->section= "";
+      $this->currentLocation= "";
+
+      $this->parser = xml_parser_create();
+      xml_set_object($this->parser, $this);
+      xml_set_element_handler($this->parser, "tag_open", "tag_close");
+      $this->parse($this->filename);
+      if(isset($_SESSION['plist'])){
+        unset($_SESSION['plist']);
+      }
+      if(isset($_SESSION['plug'])){
+        unset($_SESSION['plug']);
+      }
+      if(isset($_GET['plug'])){
+        unset($_GET['plug']);
+      }
+    }
+  }  
+
+
   function parse($filename)
   { 
+    $this->last_modified = filemtime($filename);
+    $this->filename = $filename;
     $fh= fopen($filename, "r"); 
     $xmldata= fread($fh, 100000);
     fclose($fh); 
     if(!xml_parse($this->parser, chop($xmldata))){
-      print_red(sprintf(_("XML error in gosa.conf: %s at line %d"),
+      $msg = sprintf(_("XML error in gosa.conf: %s at line %d"),
             xml_error_string(xml_get_error_code($this->parser)),
-            xml_get_current_line_number($this->parser)));
-      echo $_SESSION['errors'];
+            xml_get_current_line_number($this->parser));
+      msg_dialog::display(_("Config file parsing"), $msg, FATAL_ERROR_DIALOG);
       exit;
     }
   }
@@ -143,14 +176,6 @@ class config  {
                   }
                   break;
 
-                  /* Handle faxformat */
-      case 'FAXFORMAT':        
-                  if ($this->tags[$this->level-2] == 'MAIN'){
-                    /* Add fax formats */
-                    $this->data['MAIN']['FAXFORMATS'][]= $attrs['TYPE'];
-                  }
-                  break;
-
                   /* Load main parameters */
       case 'MAIN':
                   $this->data['MAIN']= array_merge ($this->data['MAIN'], $attrs);
@@ -315,19 +340,34 @@ class config  {
     /* Fill imap servers */
     $ldap= $this->get_ldap_link();
     $ldap->cd ($this->current['BASE']);
-    $ldap->search ("(objectClass=goImapServer)");
+    if (!isset($this->current['MAILMETHOD'])){
+      $this->current['MAILMETHOD']= "";
+    }
+    if ($this->current['MAILMETHOD'] == ""){
+      $ldap->search ("(objectClass=goMailServer)", array('cn'));
+      $this->data['SERVERS']['IMAP']= array();
+      error_reporting(0);
+      while ($attrs= $ldap->fetch()){
+        $name= $attrs['cn'][0];
+        $this->data['SERVERS']['IMAP'][$name]= $name;
+      }
+      error_reporting(E_ALL);
+    } else {
+      $ldap->search ("(objectClass=goImapServer)", array('goImapName', 'goImapConnect', 'goImapAdmin', 'goImapPassword',
+            'goImapSieveServer', 'goImapSievePort'));
 
-    $this->data['SERVERS']['IMAP']= array();
-    error_reporting(0);
-    while ($attrs= $ldap->fetch()){
-      $name= $attrs['goImapName'][0];
-      $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
-          "admin" => $attrs['goImapAdmin'][0],
-          "password" => $attrs['goImapPassword'][0],
-          "sieve_server" => $attrs['goImapSieveServer'][0],
-          "sieve_port" => $attrs['goImapSievePort'][0]);
+      $this->data['SERVERS']['IMAP']= array();
+      error_reporting(0);
+      while ($attrs= $ldap->fetch()){
+        $name= $attrs['goImapName'][0];
+        $this->data['SERVERS']['IMAP'][$name]= array( "connect" => $attrs['goImapConnect'][0],
+            "admin" => $attrs['goImapAdmin'][0],
+            "password" => $attrs['goImapPassword'][0],
+            "sieve_server" => $attrs['goImapSieveServer'][0],
+            "sieve_port" => $attrs['goImapSievePort'][0]);
+      }
+      error_reporting(E_ALL);
     }
-    error_reporting(E_ALL | E_STRICT);
 
     /* Get kerberos server. FIXME: only one is supported currently */
     $ldap->cd ($this->current['BASE']);
@@ -757,7 +797,7 @@ class config  {
     $return= strtoupper($return);
     if (is_array($arr)){
       foreach ($arr as &$a){
-        if (isset($a['CLASS']) && preg_match("/^$name$/i", $a['CLASS'])){
+        if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
           return(isset($a[$return])?$a[$return]:"");
         } else {
           $res= $this->__search ($a, $name, $return);
@@ -791,6 +831,20 @@ class config  {
     return ("");
   }
 
+
+  /* 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
+   *  defined by session.gc_maxlifetime.
+   */
+  function check_session_lifetime()
+  {
+    $cfg_lifetime = $this->data['MAIN']['SESSION_LIFETIME'];
+    $ini_lifetime = ini_get('session.gc_maxlifetime');
+    $deb_system   = file_exists('/etc/debian_version');
+    return(!($deb_system && ($ini_lifetime < $cfg_lifetime)));  
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: