Code

Updated a couple of values
[gosa.git] / gosa-core / include / functions.inc
index de39cbb65cef9fa3304768b635aa113db395e123..f58ed2a2e60ab73da2d552bd8bbf1711abc85f30 100644 (file)
@@ -86,6 +86,7 @@ define ("DEBUG_POST",   16);
 define ("DEBUG_SESSION",32);
 define ("DEBUG_CONFIG", 64);
 define ("DEBUG_ACL",    128);
+define ("DEBUG_SI",     256);
 
 /* Rewrite german 'umlauts' and spanish 'accents'
    to get better results */
@@ -192,8 +193,8 @@ function get_browser_language()
   }
 
   /* Check for global language settings in gosa.conf */
-  if(isset($config->data['MAIN']['LANG']) && !empty($config->data['MAIN']['LANG'])) {
-    $lang = $config->data['MAIN']['LANG'];
+  if (isset ($config) && $config->get_cfg_value('language') != ""){
+    $lang = $config->get_cfg_value('language');
     if(!preg_match("/utf/i",$lang)){
       $lang .= ".UTF-8";
     }
@@ -230,10 +231,11 @@ function get_template_path($filename= '', $plugin= FALSE, $path= "")
 {
   global $config, $BASE_DIR;
 
-  if (!@isset($config->data['MAIN']['THEME'])){
-    $theme= 'default';
+  /* Set theme */
+  if (isset ($config)){
+       $theme= $config->get_cfg_value("theme", "default");
   } else {
-    $theme= $config->data['MAIN']['THEME'];
+       $theme= "default";
   }
 
   /* Return path for empty filename */
@@ -292,6 +294,21 @@ function array_remove_entries($needles, $haystack)
 }
 
 
+function array_remove_entries_ics($needles, $haystack)
+{
+  $tmp= array();
+
+  /* Loop through entries to be removed */
+  foreach ($haystack as $entry){
+    if (!in_array_ics($entry, $needles)){
+      $tmp[]= $entry;
+    }
+  }
+
+  return ($tmp);
+}
+
+
 function gosa_array_merge($ar1,$ar2)
 {
   if(!is_array($ar1) || !is_array($ar2)){
@@ -332,7 +349,9 @@ function ldap_init ($server, $base, $binddn='', $pass='')
 
   /* Sadly we've no proper return values here. Use the error message instead. */
   if (!$ldap->success()){
-    echo sprintf(_("FATAL: Error when connecting the LDAP. Server said '%s'."), $ldap->get_error());
+    msg_dialog::display(_("Fatal error"),
+        sprintf(_("FATAL: Error when connecting the LDAP. Server said '%s'."), $ldap->get_error()),
+        FATAL_ERROR_DIALOG);
     exit();
   }
 
@@ -351,17 +370,16 @@ function process_htaccess ($username, $kerberos= FALSE)
   
     $config->set_current($name);
     $mode= "kerberos";
-    if (isset($config->current['KRBSASL']) && preg_match('/^true$/i', $config->current['KRBSASL'])){
+    if ($config->get_cfg_value("krbsasl") == "true"){
       $mode= "sasl";
     }
 
     /* Look for entry or realm */
     $ldap= $config->get_ldap_link();
     if (!$ldap->success()){
-      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "", LDAP_AUTH, ERROR_DIALOG));
-      $smarty= get_smarty();
-      $smarty->display(get_template_path('headers.tpl'));
-      echo "<body>".session::get('errors')."</body></html>";
+      msg_dialog::display(_("LDAP error"), 
+          msgPool::ldaperror($ldap->get_error(), "", LDAP_AUTH)."<br><br>".session::get('errors'), 
+          FATAL_ERROR_DIALOG);
       exit();
     }
     $ldap->search("(&(objectClass=gosaAccount)(|(uid=$username)(userPassword={$mode}$username)))", array("uid"));
@@ -385,10 +403,9 @@ function ldap_login_user_htaccess ($username)
   /* Look for entry or realm */
   $ldap= $config->get_ldap_link();
   if (!$ldap->success()){
-    msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "", LDAP_AUTH, FATAL_ERROR_DIALOG));
-    $smarty= get_smarty();
-    $smarty->display(get_template_path('headers.tpl'));
-    echo "<body>".session::get('errors')."</body></html>";
+    msg_dialog::display(_("LDAP error"), 
+        msgPool::ldaperror($ldap->get_error(), "", LDAP_AUTH)."<br><br>".session::get('errors'), 
+        FATAL_ERROR_DIALOG);
     exit();
   }
   $ldap->search("(&(objectClass=gosaAccount)(uid=$username))", array("uid"));
@@ -423,17 +440,16 @@ function ldap_login_user ($username, $password)
   /* look through the entire ldap */
   $ldap = $config->get_ldap_link();
   if (!$ldap->success()){
-    msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error()), FATAL_ERROR_DIALOG);
-    $smarty= get_smarty();
-    $smarty->display(get_template_path('headers.tpl'));
-    echo "<body>".session::get('errors')."</body></html>";
+    msg_dialog::display(_("LDAP error"), 
+        msgPool::ldaperror($ldap->get_error(), "", LDAP_AUTH)."<br><br>".session::get('errors'), 
+        FATAL_ERROR_DIALOG);
     exit();
   }
   $ldap->cd($config->current['BASE']);
   $allowed_attributes = array("uid","mail");
   $verify_attr = array();
-  if(isset($config->current['LOGIN_ATTRIBUTE'])){
-    $tmp = split(",",$config->current['LOGIN_ATTRIBUTE']); 
+  if($config->get_cfg_value("login_attribute") != ""){
+    $tmp = split(",", $config->get_cfg_value("login_attribute")); 
     foreach($tmp as $attr){
       if(in_array($attr,$allowed_attributes)){
         $verify_attr[] = $attr;
@@ -615,7 +631,7 @@ function add_lock ($object, $user)
 
   /* Check for existing entries in lock area */
   $ldap= $config->get_ldap_link();
-  $ldap->cd ($config->current['CONFIG']);
+  $ldap->cd ($config->get_cfg_value("config"));
   $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64_encode($object)."))",
       array("gosaUser"));
   if (!$ldap->success()){
@@ -627,14 +643,14 @@ function add_lock ($object, $user)
   if ($ldap->count() == 0){
     $attrs= array();
     $name= md5($object);
-    $ldap->cd("cn=$name,".$config->current['CONFIG']);
+    $ldap->cd("cn=$name,".$config->get_cfg_value("config"));
     $attrs["objectClass"] = "gosaLockEntry";
     $attrs["gosaUser"] = $user;
     $attrs["gosaObject"] = base64_encode($object);
     $attrs["cn"] = "$name";
     $ldap->add($attrs);
     if (!$ldap->success()){
-      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "cn=$name,".$config->current['CONFIG'], 0, ERROR_DIALOG));
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "cn=$name,".$config->get_cfg_value("config"), 0, ERROR_DIALOG));
       return;
     }
   }
@@ -659,7 +675,7 @@ function del_lock ($object)
 
   /* Check for existance and remove the entry */
   $ldap= $config->get_ldap_link();
-  $ldap->cd ($config->current['CONFIG']);
+  $ldap->cd ($config->get_cfg_value("config"));
   $ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaObject"));
   $attrs= $ldap->fetch();
   if ($ldap->getDN() != "" && $ldap->success()){
@@ -679,7 +695,7 @@ function del_user_locks($userdn)
 
   /* Get LDAP ressources */ 
   $ldap= $config->get_ldap_link();
-  $ldap->cd ($config->current['CONFIG']);
+  $ldap->cd ($config->get_cfg_value("config"));
 
   /* Remove all objects of this user, drop errors silently in this case. */
   $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$userdn))", array("gosaUser"));
@@ -702,7 +718,7 @@ function get_lock ($object)
   /* Get LDAP link, check for presence of the lock entry */
   $user= "";
   $ldap= $config->get_ldap_link();
-  $ldap->cd ($config->current['CONFIG']);
+  $ldap->cd ($config->get_cfg_value("config"));
   $ldap->search("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaUser"));
   if (!$ldap->success()){
     msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "", LDAP_SEARCH, ERROR_DIALOG));
@@ -747,7 +763,7 @@ function get_multiple_locks($objects)
   /* Get LDAP link, check for presence of the lock entry */
   $user= "";
   $ldap= $config->get_ldap_link();
-  $ldap->cd ($config->current['CONFIG']);
+  $ldap->cd ($config->get_cfg_value("config"));
   $ldap->search($filter, array("gosaUser","gosaObject"));
   if (!$ldap->success()){
     msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "", LDAP_SEARCH, ERROR_DIALOG));
@@ -905,16 +921,14 @@ function get_sub_list($filter, $category,$sub_deps, $base= "", $attributes= arra
       }else{
 
         /* Sort in every value that fits the permissions */
-        if (is_array($category)){
-          foreach ($category as $o){
-            if ($ui->get_category_permissions($dn, $o) != ""){
-              $result[]= $attrs;
-              break;
-            }
-          }
-        } else {
-          if ( $ui->get_category_permissions($dn, $category) != ""){
+        if (!is_array($category)){
+          $category = array($category);
+        }
+        foreach ($category as $o){
+          if((preg_match("/\//",$o) && preg_match("/r/",$ui->get_permissions($dn,$o))) ||
+              (!preg_match("/\//",$o) && preg_match("/r/",$ui->get_category_permissions($dn, $o)))){
             $result[]= $attrs;
+            break;
           }
         }
       }
@@ -975,19 +989,14 @@ function get_list($filter, $category, $base= "", $attributes= array(), $flags= G
     }else{
 
       /* Sort in every value that fits the permissions */
-      if (is_array($category)){
-        foreach ($category as $o){
-          if ($ui->get_category_permissions($dn, $o) != ""){
-
-            /* We found what we were looking for, break speeds things up */
-            $result[]= $attrs;
-          }
-        }
-      } else {
-        if ($ui->get_category_permissions($dn, $category) != ""){
-
-          /* We found what we were looking for, break speeds things up */
+      if (!is_array($category)){
+        $category = array($category);
+      }
+      foreach ($category as $o){
+        if((preg_match("/\//",$o) && preg_match("/r/",$ui->get_permissions($dn,$o))) || 
+            (!preg_match("/\//",$o) && preg_match("/r/",$ui->get_category_permissions($dn, $o)))){
           $result[]= $attrs;
+          break;
         }
       }
     }
@@ -1141,6 +1150,8 @@ function get_ou($name)
 {
   global $config;
 
+  $name= strtolower($name);
+
   $map = array( 
                 "ogroupou"      => "ou=groups,",
                 "applicationou" => "ou=apps,",
@@ -1151,6 +1162,8 @@ function get_ou($name)
                 "printerou"     => "ou=printers,ou=systems,",
                 "phoneou"       => "ou=phones,ou=systems,",
                 "componentou"   => "ou=netdevices,ou=systems,",
+                "winstations"   => "ou=winstation,",
+
                 "blocklistou"   => "ou=gofax,ou=systems,",
                 "incomingou"    => "ou=incoming,",
                 "aclroleou"     => "ou=aclroles,",
@@ -1170,8 +1183,8 @@ function get_ou($name)
                 "mimetypeou"    => "ou=mime,");
 
   /* Preset ou... */
-  if (isset($config->current[strtoupper($name)])){
-    $ou= $config->current[strtoupper($name)];
+  if ($config->get_cfg_value($name, "_not_set_") != "_not_set_"){
+    $ou= $config->get_cfg_value($name);
   } elseif (isset($map[$name])) {
     $ou = $map[$name];
     return($ou);
@@ -1202,7 +1215,7 @@ function get_ou($name)
 
 function get_people_ou()
 {
-  return (get_ou("PEOPLE"));
+  return (get_ou("USERRDN"));
 }
 
 
@@ -1238,7 +1251,10 @@ function strict_uid_mode()
 {
   global $config;
 
-  return !(isset($config->current['STRICT']) && preg_match('/^(no|false)$/i', $config->current['STRICT']));
+  if (isset($config)){
+    return ($config->get_cfg_value("strict") == "true");
+  }
+  return (TRUE);
 }
 
 
@@ -1969,34 +1985,32 @@ function progressbar($percentage,$width=100,$height=15,$showvalue=false)
 
   $progress = (int)(($percentage /100)*$width);
 
-  /* Abort printing out percentage, if divs are to small */
-
-
   /* If theres a better solution for this, use it... */
-  $str = "
-    <div style=\" width:".($width)."px; 
-    height:".($height)."px;
-  background-color:#000000;
-padding:1px;\">
-
-          <div style=\" width:".($width)."px;
-        background-color:#$bgcolor;
-height:".($height)."px;\">
-
-         <div style=\" width:".$progress."px;
-height:".$height."px;
-       background-color:#".$color2.$color2.$color."; \">";
+  $str = "\n   <div style=\" width:".($width)."px; ";
+  $str.= "\n       height:".($height)."px; ";
+  $str.= "\n       background-color:#000000; ";
+  $str.= "\n       padding:1px;\" > ";
+
+  $str.= "\n     <div style=\" width:".($width)."px; ";
+  $str.= "\n         background-color:#$bgcolor; ";
+  $str.= "\n         height:".($height)."px;\" > ";
+
+  if(($height >10)&&($showvalue)){
+    $str.= "\n   <font style=\"font-size:".($height-2)."px; ";
+    $str.= "\n     color:#FF0000; align:middle; ";
+    $str.= "\n     padding-left:".((int)(($width*0.4)))."px; \"> ";
+    $str.= "\n     <b>".$percentage."%</b> ";
+    $str.= "\n   </font> ";
+  }
+
+  $str.= "\n       <div style=\" width:".$progress."px; ";
+  $str.= "\n         height:".$height."px; ";
+  $str.= "\n         background-color:#".$color2.$color2.$color."; \" >";
+  $str.= "\n       </div>";
+  $str.= "\n     </div>";
+  $str.= "\n   </div>";
 
-
-       if(($height >10)&&($showvalue)){
-         $str.=                 "<font style=\"font-size:".($height-2)."px;color:#FF0000;align:middle;padding-left:".((int)(($width*0.4)))."px;\">
-           <b>".$percentage."%</b>
-           </font>";
-       }
-
-       $str.= "</div></div></div>";
-
-       return($str);
+  return($str);
 }
 
 
@@ -2178,10 +2192,10 @@ function get_base_from_hook($dn, $attrib)
 {
   global $config;
 
-  if (isset($config->current['BASE_HOOK'])){
+  if ($config->get_cfg_value("base_hook") != ""){
     
     /* Call hook script - if present */
-    $command= $config->current['BASE_HOOK'];
+    $command= $config->get_cfg_value("base_hook");
 
     if ($command != ""){
       $command.= " '".LDAP::fix($dn)."' $attrib";
@@ -2192,17 +2206,17 @@ function get_base_from_hook($dn, $attrib)
           return ($output[0]);
         } else {
           msg_dialog::display(_("Warning"), _("'base_hook' is not available. Using default base!"), WARNING_DIALOG);
-          return ($config->current['UIDBASE']);
+          return ($config->get_cfg_value("uidbase"));
         }
       } else {
         msg_dialog::display(_("Warning"), _("'base_hook' is not available. Using default base!"), WARNING_DIALOG);
-        return ($config->current['UIDBASE']);
+        return ($config->get_cfg_value("uidbase"));
       }
 
     } else {
 
       msg_dialog::display(_("Warning"), _("'base_hook' is not available. Using default base!"), WARNING_DIALOG);
-      return ($config->current['UIDBASE']);
+      return ($config->get_cfg_value("uidbase"));
 
     }
   }
@@ -2571,7 +2585,7 @@ function generate_smb_nt_hash($password)
   global $config;
 
   # Try to use gosa-si?
-  if (isset($config->current['GOSA_SI'])){
+  if ($config->get_cfg_value("gosa_si") != ""){
        $res= gosaSupportDaemon::send("gosa_gen_smb_hash", "GOSA", array("password" => $password), TRUE);
     if (isset($res['XML']['HASH'])){
        $hash= $res['XML']['HASH'];
@@ -2579,7 +2593,7 @@ function generate_smb_nt_hash($password)
       $hash= "";
     }
   } else {
-         $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
+         $tmp= $config->get_cfg_value('sambaHashHook')." ".escapeshellarg($password);
          @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
 
          exec($tmp, $ar);
@@ -2595,7 +2609,7 @@ function generate_smb_nt_hash($password)
 
   list($lm,$nt)= split (":", trim($hash));
 
-  if ($config->current['SAMBAVERSION'] == 3) {
+  if ($config->get_cfg_value("sambaversion") == 3) {
          $attrs['sambaLMPassword']= $lm;
          $attrs['sambaNTPassword']= $nt;
          $attrs['sambaPwdLastSet']= date('U');
@@ -2618,12 +2632,8 @@ function getEntryCSN($dn)
   }
 
   /* Get attribute that we should use as serial number */
-  if(isset($config->current['UNIQ_IDENTIFIER'])){
-    $attr = $config->current['UNIQ_IDENTIFIER'];
-  }elseif(isset($config->data['MAIN']['UNIQ_IDENTIFIER'])){
-    $attr = $config->data['MAIN']['UNIQ_IDENTIFIER'];
-  }
-  if(!empty($attr)){
+  $attr= $config->get_cfg_value("modificationDetectionAttribute");
+  if($attr != ""){
     $ldap = $config->get_ldap_link();
     $ldap->cat($dn,array($attr));
     $csn = $ldap->fetch();
@@ -2664,7 +2674,7 @@ function remove_objectClass($classes, &$attrs)
     $tmp= array();
     foreach ($attrs['objectClass'] as $oc) {
       foreach ($list as $class){
-        if ($oc != $class){
+        if (strtolower($oc) != strtolower($class)){
           $tmp[]= $oc;
         }
       }