Code

Added mechanisms to disable/deactivate plugins if requirements are not fulfilled.
[gosa.git] / gosa-core / include / functions.inc
index e09cc5ef8adf2a17e9c376192964779ad8c91d94..da98e1f39e56afda8c68a36086a29a6c2780d7bb 100644 (file)
@@ -124,14 +124,14 @@ function __gosa_autoload($class_name) {
     global $class_mapping, $BASE_DIR;
 
     if ($class_mapping === NULL){
-           echo sprintf(_("Fatal error: no class locations defined - please run '%s' to fix this"), "<b>update-gosa</b>");
+           echo sprintf(_("Fatal error: no class locations defined - please run %s to fix this"), bold("update-gosa"));
            exit;
     }
 
     if (isset($class_mapping["$class_name"])){
       require_once($BASE_DIR."/".$class_mapping["$class_name"]);
     } else {
-      echo sprintf(_("Fatal error: cannot instantiate class '%s' - try running '%s' to fix this"), $class_name, "<b>update-gosa</b>");
+      echo sprintf(_("Fatal error: cannot instantiate class %s - try running %s to fix this"), bold($class_name), bold("update-gosa"));
       exit;
     }
 }
@@ -144,8 +144,14 @@ spl_autoload_register('__gosa_autoload');
  */
 function class_available($name)
 {
-  global $class_mapping;
-  return(isset($class_mapping[$name]));
+  global $class_mapping, $config;
+    
+  $disabled = array();
+  if($config instanceOf config && $config->configRegistry instanceOf configRegistry){
+    $disabled = $config->configRegistry->getDisabledPlugins();
+  }
+
+  return(isset($class_mapping[$name]) && !isset($disabled[$name]));
 }
 
 
@@ -203,7 +209,7 @@ function make_seed() {
  * */
 function DEBUG($level, $line, $function, $file, $data, $info="")
 {
-  if (session::global_get('DEBUGLEVEL') & $level){
+  if (session::global_get('debugLevel') & $level){
     $output= "DEBUG[$level] ";
     if ($function != ""){
       $output.= "($file:$function():$line) - $info: ";
@@ -245,8 +251,8 @@ function get_browser_language()
   }
 
   /* Check for global language settings in gosa.conf */
-  if (isset ($config) && $config->get_cfg_value('language') != ""){
-    $lang = $config->get_cfg_value('language');
+  if (isset ($config) && $config->get_cfg_value("core",'language') != ""){
+    $lang = $config->get_cfg_value("core",'language');
     if(!preg_match("/utf/i",$lang)){
       $lang .= ".UTF-8";
     }
@@ -308,7 +314,7 @@ function get_template_path($filename= '', $plugin= FALSE, $path= "")
 
   /* Set theme */
   if (isset ($config)){
-       $theme= $config->get_cfg_value("theme", "default");
+       $theme= $config->get_cfg_value("core","theme");
   } else {
        $theme= "default";
   }
@@ -466,7 +472,7 @@ function process_htaccess ($username, $kerberos= FALSE)
   
     $config->set_current($name);
     $mode= "kerberos";
-    if ($config->get_cfg_value("useSaslForKerberos") == "true"){
+    if ($config->get_cfg_value("core","useSaslForKerberos") == "true"){
       $mode= "sasl";
     }
 
@@ -570,8 +576,8 @@ function ldap_login_user ($username, $password)
   $ldap->cd($config->current['BASE']);
   $allowed_attributes = array("uid","mail");
   $verify_attr = array();
-  if($config->get_cfg_value("loginAttribute") != ""){
-    $tmp = explode(",", $config->get_cfg_value("loginAttribute")); 
+  if($config->get_cfg_value("core","loginAttribute") != ""){
+    $tmp = explode(",", $config->get_cfg_value("core","loginAttribute")); 
     foreach($tmp as $attr){
       if(in_array($attr,$allowed_attributes)){
         $verify_attr[] = $attr;
@@ -795,7 +801,7 @@ function add_lock($object, $user)
 
   /* Check for existing entries in lock area */
   $ldap= $config->get_ldap_link();
-  $ldap->cd ($config->get_cfg_value("config"));
+  $ldap->cd ($config->get_cfg_value("core","config"));
   $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$user)(gosaObject=".base64_encode($object)."))",
       array("gosaUser"));
   if (!$ldap->success()){
@@ -807,14 +813,14 @@ function add_lock($object, $user)
   if ($ldap->count() == 0){
     $attrs= array();
     $name= md5($object);
-    $ldap->cd("cn=$name,".$config->get_cfg_value("config"));
+    $ldap->cd("cn=$name,".$config->get_cfg_value("core","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->get_cfg_value("config"), 0, ERROR_DIALOG));
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "cn=$name,".$config->get_cfg_value("core","config"), 0, ERROR_DIALOG));
       return;
     }
   }
@@ -856,7 +862,7 @@ function del_lock ($object)
 
   /* Check for existance and remove the entry */
   $ldap= $config->get_ldap_link();
-  $ldap->cd ($config->get_cfg_value("config"));
+  $ldap->cd ($config->get_cfg_value("core","config"));
   $ldap->search ("(&(objectClass=gosaLockEntry)(gosaObject=".base64_encode($object)."))", array("gosaObject"));
   $attrs= $ldap->fetch();
   if ($ldap->getDN() != "" && $ldap->success()){
@@ -883,7 +889,7 @@ function del_user_locks($userdn)
 
   /* Get LDAP ressources */ 
   $ldap= $config->get_ldap_link();
-  $ldap->cd ($config->get_cfg_value("config"));
+  $ldap->cd ($config->get_cfg_value("core","config"));
 
   /* Remove all objects of this user, drop errors silently in this case. */
   $ldap->search("(&(objectClass=gosaLockEntry)(gosaUser=$userdn))", array("gosaUser"));
@@ -917,7 +923,7 @@ function get_lock ($object)
   /* Get LDAP link, check for presence of the lock entry */
   $user= "";
   $ldap= $config->get_ldap_link();
-  $ldap->cd ($config->get_cfg_value("config"));
+  $ldap->cd ($config->get_cfg_value("core","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));
@@ -967,7 +973,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->get_cfg_value("config"));
+  $ldap->cd ($config->get_cfg_value("core","config"));
   $ldap->search($filter, array("gosaUser","gosaObject"));
   if (!$ldap->success()){
     msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), "", LDAP_SEARCH, ERROR_DIALOG));
@@ -1051,7 +1057,7 @@ function get_sub_list($filter, $category,$sub_deps, $base= "", $attributes= arra
       // log($action,$objecttype,$object,$changes_array = array(),$result = "") 
       new log("debug","all",__FILE__,$attributes,
           sprintf("get_sub_list(): Falling back to get_list(), due to empty sub_bases parameter.".
-            " This may slow down GOsa. Search was: '%s'",$filter));
+            " This may slow down GOsa. Used filter: %s", $filter));
     }
     $tmp = get_list($filter, $category,$base,$attributes,$flags);
     return($tmp);
@@ -1396,74 +1402,40 @@ function get_sub_department($value)
  * Example:
  * \code
  * # Determine LDAP base where systems are stored
- * $base = get_ou('systemRDN') . $this->config->current['BASE'];
+ * $base = get_ou("systemManagement", "systemRDN") . $this->config->current['BASE'];
  * $ldap->cd($base);
  * \endcode
  * */
-function get_ou($name)
+function get_ou($class,$name)
 {
-  global $config;
+    global $config;
 
-  $map = array( 
-                "roleRDN"      => "ou=roles,",
-                "ogroupRDN"      => "ou=groups,",
-                "applicationRDN" => "ou=apps,",
-                "systemRDN"     => "ou=systems,",
-                "serverRDN"      => "ou=servers,ou=systems,",
-                "terminalRDN"    => "ou=terminals,ou=systems,",
-                "workstationRDN" => "ou=workstations,ou=systems,",
-                "printerRDN"     => "ou=printers,ou=systems,",
-                "phoneRDN"       => "ou=phones,ou=systems,",
-                "componentRDN"   => "ou=netdevices,ou=systems,",
-                "sambaMachineAccountRDN"   => "ou=winstation,",
-
-                "faxBlocklistRDN"   => "ou=gofax,ou=systems,",
-                "systemIncomingRDN"    => "ou=incoming,",
-                "aclRoleRDN"     => "ou=aclroles,",
-                "phoneMacroRDN"       => "ou=macros,ou=asterisk,ou=configs,ou=systems,",
-                "phoneConferenceRDN"  => "ou=conferences,ou=asterisk,ou=configs,ou=systems,",
-
-                "faiBaseRDN"         => "ou=fai,ou=configs,ou=systems,",
-                "faiScriptRDN"   => "ou=scripts,",
-                "faiHookRDN"     => "ou=hooks,",
-                "faiTemplateRDN" => "ou=templates,",
-                "faiVariableRDN" => "ou=variables,",
-                "faiProfileRDN"  => "ou=profiles,",
-                "faiPackageRDN"  => "ou=packages,",
-                "faiPartitionRDN"=> "ou=disk,",
-
-                "sudoRDN"       => "ou=sudoers,",
-
-                "deviceRDN"      => "ou=devices,",
-                "mimetypeRDN"    => "ou=mime,");
-
-  /* Preset ou... */
-  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);
-  } else {
-    trigger_error("No department mapping found for type ".$name);
-    return "";
-  }
-  if ($ou != ""){
-    if (!preg_match('/^[^=]+=[^=]+/', $ou)){
-      $ou = @LDAP::convert("ou=$ou");
-    } else {
-      $ou = @LDAP::convert("$ou");
+    if(!$config->configRegistry->propertyExists($class,$name)){
+        trigger_error("No department mapping found for type ".$name);
+        return "";
     }
 
-    if(preg_match("/".preg_quote($config->current['BASE'], '/')."$/",$ou)){
-      return($ou);
-    }else{
-      return("$ou,");
+    $ou = $config->configRegistry->getPropertyValue($class,$name);
+    if ($ou != ""){
+        if (!preg_match('/^[^=]+=[^=]+/', $ou)){
+            $ou = @LDAP::convert("ou=$ou");
+        } else {
+            $ou = @LDAP::convert("$ou");
+        }
+
+        if(preg_match("/".preg_quote($config->current['BASE'], '/')."$/",$ou)){
+            return($ou);
+        }else{
+            if(!preg_match("/,$/", $ou)){
+                return("$ou,");
+            }else{
+                return($ou);
+            }
+        }
+
+    } else {
+        return "";
     }
-  
-  } else {
-    return "";
-  }
 }
 
 
@@ -1473,7 +1445,7 @@ function get_ou($name)
  * */
 function get_people_ou()
 {
-  return (get_ou("userRDN"));
+  return (get_ou("core", "userRDN"));
 }
 
 
@@ -1483,7 +1455,7 @@ function get_people_ou()
  */
 function get_groups_ou()
 {
-  return (get_ou("groupRDN"));
+  return (get_ou("core", "groupRDN"));
 }
 
 
@@ -1493,7 +1465,7 @@ function get_groups_ou()
  */
 function get_winstations_ou()
 {
-  return (get_ou("sambaMachineAccountRDN"));
+  return (get_ou("wingeneric", "sambaMachineAccountRDN"));
 }
 
 
@@ -1535,7 +1507,7 @@ function strict_uid_mode()
   global $config;
 
   if (isset($config)){
-    return ($config->get_cfg_value("strictNamingRules") == "true");
+    return ($config->get_cfg_value("core","strictNamingRules") == "true");
   }
   return (TRUE);
 }
@@ -2218,7 +2190,7 @@ function get_gosa_version()
 
   /* Release or development? */
   if (preg_match('%/gosa/trunk/%', $svn_path)){
-    return (sprintf(_("GOsa development snapshot (Rev %s)"), $revision));
+    return (sprintf(_("GOsa development snapshot (Rev %s)"), bold($revision)));
   } else {
     $release= preg_replace('%^.*/([^/]+)/include/functions.inc.*$%', '\1', $svn_path);
     return (sprintf(_("GOsa $release"), $revision));
@@ -2315,7 +2287,7 @@ function clean_smarty_compile_dir($directory)
               is_writable($directory."/".$file)) {
             // delete file
             if(!unlink($directory."/".$file)) {
-              msg_dialog::display(_("Internal error"), sprintf(_("File '%s' cannot be deleted!"), $directory."/".$file), ERROR_DIALOG);
+              msg_dialog::display(_("Internal error"), sprintf(_("File %s cannot be deleted!"), bold($directory."/".$file)), ERROR_DIALOG);
               // This should never be reached
             }
           } elseif(is_dir($directory."/".$file) &&
@@ -2627,10 +2599,10 @@ function get_base_from_hook($dn, $attrib)
 {
   global $config;
 
-  if ($config->get_cfg_value("baseIdHook") != ""){
+  if ($config->get_cfg_value("core","baseIdHook") != ""){
     
     /* Call hook script - if present */
-    $command= $config->get_cfg_value("baseIdHook");
+    $command= $config->get_cfg_value("core","baseIdHook");
 
     if ($command != ""){
       $command.= " '".LDAP::fix($dn)."' $attrib";
@@ -2641,17 +2613,17 @@ function get_base_from_hook($dn, $attrib)
           return ($output[0]);
         } else {
           msg_dialog::display(_("Warning"), _("'baseIdHook' is not available. Using default base!"), WARNING_DIALOG);
-          return ($config->get_cfg_value("uidNumberBase"));
+          return ($config->get_cfg_value("core","uidNumberBase"));
         }
       } else {
         msg_dialog::display(_("Warning"), _("'baseIdHook' is not available. Using default base!"), WARNING_DIALOG);
-        return ($config->get_cfg_value("uidNumberBase"));
+        return ($config->get_cfg_value("core","uidNumberBase"));
       }
 
     } else {
 
       msg_dialog::display(_("Warning"), _("'baseIdHook' is not available. Using default base!"), WARNING_DIALOG);
-      return ($config->get_cfg_value("uidNumberBase"));
+      return ($config->get_cfg_value("core","uidNumberBase"));
 
     }
   }
@@ -2752,15 +2724,15 @@ function check_schema($cfg,$rfc2307bis = FALSE)
       if(!isset($objectclasses[$name])){
         if($value['IS_MUST_HAVE']){
           $checks[$name]['STATUS'] = FALSE;
-          $checks[$name]['MSG']    = sprintf(_("Required object class '%s' is missing!"),$class);
+          $checks[$name]['MSG']    = sprintf(_("Required object class %s is missing!"), bold($class));
         } else {
           $checks[$name]['STATUS'] = TRUE;
-          $checks[$name]['MSG']    = sprintf(_("Optional object class '%s' is missing!"),$class);
+          $checks[$name]['MSG']    = sprintf(_("Optional object class %s is missing!"), bold($class));
         }
       }elseif(!check_schema_version($objectclasses[$name],$value['REQUIRED_VERSION'])){
         $checks[$name]['STATUS'] = FALSE;
 
-        $checks[$name]['MSG'] = sprintf(_("Wrong version of required object class '%s' (!=%s) detected!"), $class, $value['REQUIRED_VERSION']);
+        $checks[$name]['MSG'] = sprintf(_("Wrong version of required object class %s (!=%s) detected!"), bold($class), bold($value['REQUIRED_VERSION']));
       }else{
         $checks[$name]['STATUS'] = TRUE;
         $checks[$name]['MSG'] = sprintf(_("Class available"));
@@ -3011,7 +2983,7 @@ function change_password ($dn, $password, $mode=0, $hash= "")
       }
 
       /* Find postmodify entries for this class */
-      $command= $config->search("password", "POSTMODIFY",array('menu'));
+      $command= $config->get_cfg_value("password","postmodify");
 
       if ($command != ""){
         /* Walk through attribute list */
@@ -3022,7 +2994,7 @@ function change_password ($dn, $password, $mode=0, $hash= "")
           @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
           exec($command);
         } else {
-          $message= sprintf(_("Command '%s' specified as post modify action for plugin '%s' does not exist!"), $command, "password");
+          $message= sprintf(_("Command %s specified as post modify action for plugin %s does not exist!"), bold($command), bold("password"));
           msg_dialog::display(_("Configuration error"), $message, ERROR_DIALOG);
         }
       }
@@ -3046,7 +3018,7 @@ function generate_smb_nt_hash($password)
   global $config;
 
   # Try to use gosa-si?
-  if ($config->get_cfg_value("gosaSupportURI") != ""){
+  if ($config->get_cfg_value("core","gosaSupportURI") != ""){
        $res= gosaSupportDaemon::send("gosa_gen_smb_hash", "GOSA", array("password" => $password), TRUE);
     if (isset($res['XML']['HASH'])){
        $hash= $res['XML']['HASH'];
@@ -3059,7 +3031,7 @@ function generate_smb_nt_hash($password)
       return ("");
     }
   } else {
-         $tmp= $config->get_cfg_value('sambaHashHook')." ".escapeshellarg($password);
+         $tmp= $config->get_cfg_value("core",'sambaHashHook')." ".escapeshellarg($password);
          @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
 
          exec($tmp, $ar);
@@ -3068,7 +3040,7 @@ function generate_smb_nt_hash($password)
          $hash= current($ar);
 
     if ($hash == "") {
-      msg_dialog::display(_("Configuration error"), sprintf(_("Generating SAMBA hash by running '%s' failed: check 'sambaHashHook'!"),$config->get_cfg_value('sambaHashHook')), ERROR_DIALOG);
+      msg_dialog::display(_("Configuration error"), sprintf(_("Generating SAMBA hash by running %s failed: check %s!"), bold($config->get_cfg_value("core",'sambaHashHook'), bold("sambaHashHook"))), ERROR_DIALOG);
       return ("");
     }
   }
@@ -3102,7 +3074,7 @@ function getEntryCSN($dn)
   }
 
   /* Get attribute that we should use as serial number */
-  $attr= $config->get_cfg_value("modificationDetectionAttribute");
+  $attr= $config->get_cfg_value("core","modificationDetectionAttribute");
   if($attr != ""){
     $ldap = $config->get_ldap_link();
     $ldap->cat($dn,array($attr));
@@ -3342,7 +3314,7 @@ function get_next_id($attrib, $dn)
 {
   global $config;
 
-  switch ($config->get_cfg_value("idAllocationMethod", "traditional")){
+  switch ($config->get_cfg_value("core","idAllocationMethod")){
     case "pool":
       return get_next_id_pool($attrib);
     case "traditional":
@@ -3358,12 +3330,12 @@ function get_next_id_pool($attrib) {
   global $config;
 
   /* Fill informational values */
-  $min= $config->get_cfg_value("${attrib}PoolMin", 10000);
-  $max= $config->get_cfg_value("${attrib}PoolMax", 40000);
+  $min= $config->get_cfg_value("core","${attrib}PoolMin");
+  $max= $config->get_cfg_value("core","${attrib}PoolMax");
 
   /* Sanity check */
   if ($min >= $max) {
-    msg_dialog::display(_("Error"), _("Cannot allocate free ID:")." ".sprintf(_("%sPoolMin >= %sPoolMax!"), $attrib, $attrib), ERROR_DIALOG);
+    msg_dialog::display(_("Error"), _("Cannot allocate free ID:")." ".sprintf(_("%sPoolMin >= %sPoolMax!"), bold($attrib), bold($attrib)), ERROR_DIALOG);
     return null;
   }
 
@@ -3382,8 +3354,8 @@ function get_next_id_pool($attrib) {
     /* If it does not exist, create one with these defaults */
     if ($ldap->count() == 0) {
       /* Fill informational values */
-      $minUserId= $config->get_cfg_value("uidPoolMin", 10000);
-      $minGroupId= $config->get_cfg_value("gidPoolMin", 10000);
+      $minUserId= $config->get_cfg_value("core","uidNumberPoolMin");
+      $minGroupId= $config->get_cfg_value("core","gidNumberPoolMin");
 
       /* Add as default */
       $attrs= array("objectClass" => array("organizationalUnit", "sambaUnixIdPool"));
@@ -3473,10 +3445,10 @@ function get_next_id_traditional($attrib, $dn)
 
   /* get the ranges */
   $tmp = array('0'=> 1000);
-  if (preg_match('/posixAccount/', $oc) && $config->get_cfg_value("uidNumberBase") != ""){
-    $tmp= explode('-',$config->get_cfg_value("uidNumberBase"));
-  } elseif($config->get_cfg_value("gidNumberBase") != ""){
-    $tmp= explode('-',$config->get_cfg_value("gidNumberBase"));
+  if (preg_match('/posixAccount/', $oc) && $config->get_cfg_value("core","uidNumberBase") != ""){
+    $tmp= explode('-',$config->get_cfg_value("core","uidNumberBase"));
+  } elseif($config->get_cfg_value("core","gidNumberBase") != ""){
+    $tmp= explode('-',$config->get_cfg_value("core","gidNumberBase"));
   }
 
   /* Set hwm to max if not set - for backward compatibility */
@@ -3487,7 +3459,7 @@ function get_next_id_traditional($attrib, $dn)
     $hwm= pow(2,32);
   }
   /* Find out next free id near to UID_BASE */
-  if ($config->get_cfg_value("baseIdHook") == ""){
+  if ($config->get_cfg_value("core","baseIdHook") == ""){
     $base= $lwm;
   } else {
     /* Call base hook */
@@ -3533,10 +3505,10 @@ function image($path, $action= "", $title= "", $align= "middle")
 
     // Get theme
     if (isset ($config)){
-      $theme= $config->get_cfg_value("theme", "default");
+      $theme= $config->get_cfg_value("core","theme");
     } else {
-      # For debuging - avoid that there's no theme set
-      die("config not set!");
+
+      // Fall back to default theme
       $theme= "default";
     }
 
@@ -3597,11 +3569,11 @@ function postDecode($str)
 }
 
 
-/*! \brief    Generate bold output
+/*! \brief    Generate styled output
  */
 function bold($str)
 {
-  return "<b>$str</b>";
+  return "<span class='highlight'>$str</span>";
 }