Code

Replaced print_red with msg_dialog, for testing
[gosa.git] / include / class_config.inc
index fa1823503c2786c6d0adaa39f61a5d2d93cf2b63..036872656097e5a8e376521e14ff64081267e1d1 100644 (file)
@@ -38,7 +38,7 @@ class config  {
 
   /* Configuration data */
   var $data= array( 'TABS' => array(), 'LOCATIONS' => array(), 'SERVERS' => array(),
-      'MAIN' => array( 'LANGUAGES' => array(), 'FAXFORMATS' => array() ),
+      'MAIN' => array( 'FAXFORMATS' => array() ),
       'MENU' => array(), 'SERVICE' => array());
   var $basedir= "";
 
@@ -46,6 +46,7 @@ class config  {
   var $departments= array();
   var $idepartments= array();
   var $adepartments= array();
+  var $tdepartments= array();
 
   function config($filename, $basedir= "")
   {
@@ -91,9 +92,19 @@ class config  {
       return;
     }
 
+    /* yes/no to true/false and upper case TRUE to true and so on*/
+    foreach($attrs as $name => $value){
+      if(preg_match("/^(true|yes)$/i",$value)){
+        $attrs[$name] = "true";
+      }elseif(preg_match("/^(false|no)$/i",$value)){
+        $attrs[$name] = "false";
+      } 
+    }
+
     /* Look through attributes */
     switch ($this->tags[$this->level-1]){
 
+
       /* Handle tab section */
       case 'TAB':      $name= $this->tags[$this->level-2];
 
@@ -113,8 +124,8 @@ class config  {
                     $this->currentLocation= $name;
 
                     /* Add location elements */
-                    $this->data['LOCATIONS'][$name]= $attrs;
-                  }
+                      $this->data['LOCATIONS'][$name]= $attrs;
+                    }
                   break;
 
                   /* Handle referral tags */
@@ -132,15 +143,6 @@ class config  {
                   }
                   break;
 
-                  /* Handle language */
-      case 'LANGUAGE':
-                  if ($this->tags[$this->level-2] == 'MAIN'){
-                    /* Add languages */
-                    $this->data['MAIN']['LANGUAGES'][$attrs['NAME']]= 
-                      $attrs['TAG'];
-                  }
-                  break;
-
                   /* Handle faxformat */
       case 'FAXFORMAT':        
                   if ($this->tags[$this->level-2] == 'MAIN'){
@@ -193,9 +195,11 @@ class config  {
 
     /* Check for connection */
     if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)){
+      $smarty= get_smarty();
       print_red (_("Can't bind to LDAP. Please contact the system administrator."));
-      echo $_SESSION['errors'];
-      exit;
+      $smarty->display (get_template_path('headers.tpl'));
+      echo '<body style="background-image:none">'.$_SESSION['errors'].'</body></html>';
+      exit();
     }
 
     if (!isset($_SESSION['size_limit'])){
@@ -228,6 +232,15 @@ class config  {
     if (!isset($this->current['GROUPS'])){
       $this->current['GROUPS']= "ou=groups";
     }
+
+    if (isset($this->current['INITIAL_BASE'])){
+      $_SESSION['CurrentMainBase']= $this->current['INITIAL_BASE'];
+    }
+  
+    /* Remove possibly added ',' from end of group and people ou */
+    $this->current['GROUPS'] = preg_replace("/,*$/","",$this->current['GROUPS']);
+    $this->current['PEOPLE'] = preg_replace("/,*$/","",$this->current['PEOPLE']);
+
     if (!isset($this->current['WINSTATIONS'])){
       $this->current['WINSTATIONS']= "ou=winstations,ou=systems";
     }
@@ -295,7 +308,7 @@ class config  {
   function load_servers ()
   {
     /* Only perform actions if current is set */
-    if ($this->current == NULL){
+    if ($this->current === NULL){
       return;
     }
 
@@ -314,7 +327,7 @@ class config  {
           "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']);
@@ -345,34 +358,61 @@ class config  {
           'PASSWORD' => $attrs['goFaxPassword'][0]);
     }
 
+
     /* Get asterisk servers */
     $ldap->cd ($this->current['BASE']);
     $ldap->search ("(objectClass=goFonServer)");
+    $this->data['SERVERS']['FON']= array();
     if ($ldap->count()){
-      $attrs= $ldap->fetch();
-      $this->data['SERVERS']['FON']= array( 
-          'SERVER'     => $attrs['cn'][0],
-          'LOGIN'      => $attrs['goFonAdmin'][0],
-          'PASSWORD'   => $attrs['goFonPassword'][0],
-          'DB'         => "gophone",
-          'SIP_TABLE'          => "sip_users",
-          'EXT_TABLE'  => "extensions",
-          'VOICE_TABLE'        => "voicemail_users",
-          'QUEUE_TABLE'        => "queues",
-          'QUEUE_MEMBER_TABLE' => "queue_members");
+      while ($attrs= $ldap->fetch()){
+
+        /* Add 0 entry for development */
+        if(count($this->data['SERVERS']['FON']) == 0){
+          $this->data['SERVERS']['FON'][0]= array(
+              'DN'      => $attrs['dn'],
+              'SERVER'  => $attrs['cn'][0],
+              'LOGIN'   => $attrs['goFonAdmin'][0],
+              'PASSWORD'  => $attrs['goFonPassword'][0],
+              'DB'    => "gophone",
+              'SIP_TABLE'   => "sip_users",
+              'EXT_TABLE'   => "extensions",
+              'VOICE_TABLE' => "voicemail_users",
+              'QUEUE_TABLE' => "queues",
+              'QUEUE_MEMBER_TABLE'  => "queue_members");
+        }
+
+        /* Add entry with 'dn' as index */
+        $this->data['SERVERS']['FON'][$attrs['dn']]= array(
+            'DN'      => $attrs['dn'],
+            'SERVER'  => $attrs['cn'][0],
+            'LOGIN'   => $attrs['goFonAdmin'][0],
+            'PASSWORD'  => $attrs['goFonPassword'][0],
+            'DB'    => "gophone",
+            'SIP_TABLE'   => "sip_users",
+            'EXT_TABLE'   => "extensions",
+            'VOICE_TABLE' => "voicemail_users",
+            'QUEUE_TABLE' => "queues",
+            'QUEUE_MEMBER_TABLE'  => "queue_members");
+      }
     }
 
-    /* Get asterisk servers */
+
+    /* Get glpi server */
     $ldap->cd ($this->current['BASE']);
-    $ldap->search ("(objectClass=goGlpiServer)");
+    $ldap->search ("(&(objectClass=goGlpiServer)(cn=*)(goGlpiAdmin=*)(goGlpiDatabase=*))",array("cn","goGlpiPassword","goGlpiAdmin","goGlpiDatabase"));
     if ($ldap->count()){
       $attrs= $ldap->fetch();
+      if(!isset($attrs['goGlpiPassword'])){
+        $attrs['goGlpiPassword'][0] ="";
+      }
       $this->data['SERVERS']['GLPI']= array( 
           'SERVER'     => $attrs['cn'][0],
           'LOGIN'      => $attrs['goGlpiAdmin'][0],
           'PASSWORD'   => $attrs['goGlpiPassword'][0],
           'DB'         => $attrs['goGlpiDatabase'][0]);
     }
+
+
     /* Get logdb server */
     $ldap->cd ($this->current['BASE']);
     $ldap->search ("(objectClass=goLogDBServer)");
@@ -383,19 +423,37 @@ class config  {
           'PASSWORD' => $attrs['goLogPassword'][0]);
     }
 
+
+    /* GOsa logging databases */
+    $ldap->cd ($this->current['BASE']);
+    $ldap->search ("(objectClass=gosaLogServer)");
+    if ($ldap->count()){
+      while($attrs= $ldap->fetch()){
+      $this->data['SERVERS']['LOGGING'][$attrs['cn'][0]]= 
+          array(
+          'DN'    => $attrs['dn'],
+          'USER'  => $attrs['goLogDBUser'][0],
+          'DB'    => $attrs['goLogDB'][0],
+          'PWD'   => $attrs['goLogDBPassword'][0]);
+      }
+    }
+
+
     /* Get NFS server lists */
     $tmp= array("default");
     $ldap->cd ($this->current['BASE']);
     $ldap->search ("(&(objectClass=goShareServer)(goExportEntry=*))");
     while ($attrs= $ldap->fetch()){
       for ($i= 0; $i<$attrs["goExportEntry"]["count"]; $i++){
-        $path= preg_replace ("/\s.*$/", "", $attrs["goExportEntry"][$i]);
+        if(!preg_match('/^[^|]+\|[^|]+\|NFS\|.*$/', $attrs["goExportEntry"][$i])){
+          continue;
+        }
+        $path= preg_replace ("/^[^|]+\|[^|]+\|[^|]+\|[^|]+\|([^|]+).*$/", '\1', $attrs["goExportEntry"][$i]);
         $tmp[]= $attrs["cn"][0].":$path";
       }
     }
     $this->data['SERVERS']['NFS']= $tmp;
 
-
     /* Load Terminalservers */
     $ldap->cd ($this->current['BASE']);
     $ldap->search ("(objectClass=goTerminalServer)");
@@ -412,7 +470,7 @@ class config  {
     }
 
     /* Ldap Server */
-    $this->data['SERVERS']['LDAP']= array("default");
+    $this->data['SERVERS']['LDAP']= array();
     $ldap->cd ($this->current['BASE']);
     $ldap->search ("(objectClass=goLdapServer)");
     while ($attrs= $ldap->fetch()){
@@ -472,6 +530,7 @@ class config  {
     $result= array();
     $administrative= array();
     $result['/']= $this->current['BASE'];
+    $this->tdepartments= array();
 
     /* Get list of department objects */
     $ldap= $this->get_ldap_link();
@@ -479,11 +538,18 @@ class config  {
     $ldap->search ("(objectClass=gosaDepartment)", array("ou", "objectClass", "gosaUnitTag"));
     while ($attrs= $ldap->fetch()){
       $dn= $ldap->getDN();
+      $this->tdepartments[$dn]= "";
 
       /* Save administrative departments */
       if (in_array_ics("gosaAdministrativeUnit", $attrs['objectClass']) &&
           isset($attrs['gosaUnitTag'][0])){
-        $administrative[$dn]= $attrs['gosaUnitTag'];
+        $administrative[$dn]= $attrs['gosaUnitTag'][0];
+        $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
+      }
+    
+      if (in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass']) &&
+          isset($attrs['gosaUnitTag'][0])){
+        $this->tdepartments[$dn]= $attrs['gosaUnitTag'][0];
       }
     
       if ($dn == $ignore_dn){
@@ -507,12 +573,21 @@ class config  {
     $base = $config->current['BASE'];
 
     $arr = array();
+    $ui= get_userinfo();
 
     $this->idepartments= array();
 
     /* Create multidimensional array, with all departments. */
     foreach ($this->departments as $key => $val){
 
+      /* When using strict_units, filter non relevant parts */
+      if (isset($config->current['STRICT_UNITS']) && preg_match('/true/i', $config->current['STRICT_UNITS'])){
+        if ($ui->gosaUnitTag != "" && isset($this->tdepartments[$val]) &&
+            $this->tdepartments[$val] != $ui->gosaUnitTag){
+          continue;
+        }
+      }
+
       /* remove base from dn */
       $val2 = str_replace($base,"",$val);
 
@@ -560,6 +635,7 @@ class config  {
     $depth ++;
 
     /* Walk through array */   
+    ksort($arr);
     foreach($arr as $name => $entries){
 
       /* If this department is the last in the current tree position 
@@ -580,7 +656,7 @@ class config  {
       if(isset($entries['ENTRY'])){
         $a = "";
         for($i = 0 ; $i < $depth ; $i ++){
-          $a.="&nbsp;";
+          $a.=".";
         }
         $ret[$entries['ENTRY']]=$a."&nbsp;".$name;
       }        
@@ -602,46 +678,57 @@ class config  {
   function getShareList($listboxEntry = false)
   {
     $ldap= $this->get_ldap_link();
-    $a_res = $ldap->search("(objectClass=goShareServer)",array("goExportEntry","cn"));
-    $return= array();
-    while($entry = $ldap->fetch($a_res)){
-      if(isset($entry['goExportEntry']['count'])){
-        unset($entry['goExportEntry']['count']);
-      }
-      if(isset($entry['goExportEntry'])){
-        foreach($entry['goExportEntry'] as $export){
-          $shareAttrs = split("\|",$export);
-          if($listboxEntry) {
-            $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
-          }else{
-            $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
-            $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
-            $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
-            $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
-            $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
-            $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
-            $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
+    $base =  $this->current['BASE'];
+    $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))","server",$base,array("goExportEntry","cn"),GL_SUBSEARCH);
+    $return = array();
+
+    foreach($res as $entry){
+      if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
+
+        if(isset($entry['goExportEntry']['count'])){
+          unset($entry['goExportEntry']['count']);
+        }
+        if(isset($entry['goExportEntry'])){
+          foreach($entry['goExportEntry'] as $export){
+            $shareAttrs = split("\|",$export);
+            if($listboxEntry) {
+              $return[$shareAttrs[0]."|".$entry['cn'][0]] = $shareAttrs[0]." - ".$entry['cn'][0];
+            }else{
+              $return[$shareAttrs[0]."|".$entry['cn'][0]]['server']       = $entry['cn'][0];
+              $return[$shareAttrs[0]."|".$entry['cn'][0]]['name']         = $shareAttrs[0];
+              $return[$shareAttrs[0]."|".$entry['cn'][0]]['description']  = $shareAttrs[1];
+              $return[$shareAttrs[0]."|".$entry['cn'][0]]['type']         = $shareAttrs[2];
+              $return[$shareAttrs[0]."|".$entry['cn'][0]]['charset']      = $shareAttrs[3];
+              $return[$shareAttrs[0]."|".$entry['cn'][0]]['path']         = $shareAttrs[4];
+              $return[$shareAttrs[0]."|".$entry['cn'][0]]['option']       = $shareAttrs[5];
+            }
           }
         }
-      }
+      } 
     }
+
     return($return);
   }
 
   /* This function returns all available ShareServer */
   function getShareServerList()
   {
-    $ldap= $this->get_ldap_link();
-    $a_res = $ldap->search("(&(objectClass=goShareServer)(goExportEntry=*))",array("goExportEntry","cn"));
-    $return= array();
-    while($entry = $ldap->fetch($a_res)){
-      if(isset($entry['goExportEntry']['count'])){
-        unset($entry['goExportEntry']['count']);
-      }
-      foreach($entry['goExportEntry'] as $share){
-        $a_share = split("\|",$share);
-        $sharename = $a_share[0];
-        $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
+    global $config;
+    $return = array();
+    $ui = get_userinfo();
+    $base = $config->current['BASE'];
+
+    $res= get_list("(&(objectClass=goShareServer)(goExportEntry=*))", "server", $base,array("goExportEntry","cn"),GL_SUBSEARCH);
+    foreach($res as $entry){
+      if(obj_is_readable($entry['dn'], "server/goShareServer","goExportEntry")){
+        if(isset($entry['goExportEntry']['count'])){
+          unset($entry['goExportEntry']['count']);
+        }
+        foreach($entry['goExportEntry'] as $share){
+          $a_share = split("\|",$share);
+          $sharename = $a_share[0];
+          $return[$entry['cn'][0]."|".$sharename] = $entry['cn'][0]." [".$sharename."]";
+        }
       }
     }
     return($return);
@@ -664,6 +751,46 @@ class config  {
     return FALSE;
   }
 
+
+  function __search(&$arr, $name, $return)
+  {
+    $return= strtoupper($return);
+    if (is_array($arr)){
+      foreach ($arr as &$a){
+        if (isset($a['CLASS']) && strcasecmp($name, $a['CLASS']) == 0){
+          return(isset($a[$return])?$a[$return]:"");
+        } else {
+          $res= $this->__search ($a, $name, $return);
+          if ($res != ""){
+            return $res;
+          }
+        }
+      }
+    }
+    return ("");
+  }
+
+
+  function search($class, $value, $categories= "")
+  {
+    if (is_array($categories)){
+      foreach ($categories as $category){
+        $res= $this->__search($this->data[strtoupper($category)], $class, $value);
+        if ($res != ""){
+          return $res;
+        }
+      }
+    } else {
+      if ($categories == "") {
+        return $this->__search($this->data, $class, $value);
+      } else {
+        return $this->__search($this->data[strtoupper($categories)], $class, $value);
+      }
+    } 
+
+    return ("");
+  }
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: