Code

Removed debug output
[gosa.git] / gosa-core / include / functions.inc
index 1234a6d44cf6090ad67c60779b3c0da574ae019b..df32e69ea857864c9cb278cefa02afef3b14d365 100644 (file)
@@ -120,7 +120,7 @@ $REWRITE= array( "รค" => "ae",
  *
  *  \param  string 'class_name' The currently requested class
  */
-function __autoload($class_name) {
+function __gosa_autoload($class_name) {
     global $class_mapping, $BASE_DIR;
 
     if ($class_mapping === NULL){
@@ -135,6 +135,7 @@ function __autoload($class_name) {
       exit;
     }
 }
+spl_autoload_register('__gosa_autoload');
 
 
 /*! \brief Checks if a class is available. 
@@ -320,7 +321,7 @@ function get_template_path($filename= '', $plugin= FALSE, $path= "")
   /* Return plugin dir or root directory? */
   if ($plugin){
     if ($path == ""){
-      $nf= preg_replace("!^".$BASE_DIR."/!", "", session::global_get('plugin_dir'));
+      $nf= preg_replace("!^".$BASE_DIR."/!", "", preg_replace('/^\.\.\//', '', session::global_get('plugin_dir')));
     } else {
       $nf= preg_replace("!^".$BASE_DIR."/!", "", $path);
     }
@@ -527,6 +528,7 @@ function ldap_login_user_htaccess ($username)
   /* Bail out if we have login restrictions set, for security reasons
      the message is the same than failed user/pw */
   if (!$ui->loginAllowed()){
+    new log("security","login","",array(),"Login restriction for user \"$username\", login not permitted");
     return (NULL);
   }
 
@@ -569,7 +571,7 @@ function ldap_login_user ($username, $password)
   $allowed_attributes = array("uid","mail");
   $verify_attr = array();
   if($config->get_cfg_value("loginAttribute") != ""){
-    $tmp = split(",", $config->get_cfg_value("loginAttribute")); 
+    $tmp = explode(",", $config->get_cfg_value("loginAttribute")); 
     foreach($tmp as $attr){
       if(in_array($attr,$allowed_attributes)){
         $verify_attr[] = $attr;
@@ -623,6 +625,7 @@ function ldap_login_user ($username, $password)
   /* Bail out if we have login restrictions set, for security reasons
      the message is the same than failed user/pw */
   if (!$ui->loginAllowed()){
+    new log("security","login","",array(),"Login restriction for user \"$username\", login not permitted");
     return (NULL);
   }
 
@@ -1357,7 +1360,7 @@ function convert_department_dn($dn, $base = NULL)
 
 
   $dep= "";
-  foreach (split(',', $dn) as $rdn){
+  foreach (explode(',', $dn) as $rdn){
     $dep = preg_replace("/^[^=]+=/","",$rdn)."/".$dep;
   }
 
@@ -1978,7 +1981,7 @@ function normalize_netmask($netmask)
  */
 function netmask_to_bits($netmask)
 {
-  list($nm0, $nm1, $nm2, $nm3)= split('\.', $netmask);
+  list($nm0, $nm1, $nm2, $nm3)= explode('.', $netmask);
   $res= 0;
 
   for ($n= 0; $n<4; $n++){
@@ -2977,13 +2980,12 @@ function change_password ($dn, $password, $mode=0, $hash= "")
 
     // Not for groups
     if ($mode == 0){
+      // Create SMB Password
+      $attrs= generate_smb_nt_hash($password);
 
       if ($shadow != 0){
         $attrs['shadowLastChange']= $shadow;
       }
-
-      // Create SMB Password
-      $attrs= generate_smb_nt_hash($password);
     }
 
     $attrs['userPassword']= array();
@@ -3070,7 +3072,7 @@ function generate_smb_nt_hash($password)
     }
   }
 
-  list($lm,$nt)= split (":", trim($hash));
+  list($lm,$nt)= explode(":", trim($hash));
 
   $attrs['sambaLMPassword']= $lm;
   $attrs['sambaNTPassword']= $nt;
@@ -3471,9 +3473,9 @@ 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= split('-',$config->get_cfg_value("uidNumberBase"));
+    $tmp= explode('-',$config->get_cfg_value("uidNumberBase"));
   } elseif($config->get_cfg_value("gidNumberBase") != ""){
-    $tmp= split('-',$config->get_cfg_value("gidNumberBase"));
+    $tmp= explode('-',$config->get_cfg_value("gidNumberBase"));
   }
 
   /* Set hwm to max if not set - for backward compatibility */
@@ -3504,5 +3506,82 @@ function get_next_id_traditional($attrib, $dn)
 }
 
 
+/* Mark the occurance of a string with a span */
+function mark($needle, $haystack, $ignorecase= true)
+{
+  $result= "";
+
+  while (preg_match('/^(.*)('.preg_quote($needle).')(.*)$/i', $haystack, $matches)) {
+    $result.= $matches[1]."<span class='mark'>".$matches[2]."</span>";
+    $haystack= $matches[3];
+  }
+
+  return $result.$haystack;
+}
+
+
+/* Return an image description using the path */
+function image($path, $action= "", $title= "", $align= "middle")
+{
+  global $config;
+  global $BASE_DIR;
+  $label= null;
+
+  // Bail out, if there's no style file
+  if(!session::global_is_set("img-styles")){
+
+    // Get theme
+    if (isset ($config)){
+      $theme= $config->get_cfg_value("theme", "default");
+    } else {
+      # For debuging - avoid that there's no theme set
+      die("config not set!");
+      $theme= "default";
+    }
+
+    if (!file_exists("$BASE_DIR/ihtml/themes/$theme/img.styles")){
+      die ("No img.style for this theme found!");
+    }
+
+    session::global_set('img-styles', unserialize(file_get_contents("$BASE_DIR/ihtml/themes/$theme/img.styles")));
+  }
+  $styles= session::global_get('img-styles');
+
+  /* Extract labels from path */
+  if (preg_match("/\.png\[(.*)\]$/", $path, $matches)) {
+    $label= $matches[1];
+  }
+
+  $lbl= "";
+  if ($label) {
+    if (isset($styles["images/label-".$label.".png"])) {
+      $lbl= "<div style='".$styles["images/label-".$label.".png"]."'></div>";
+    } else {
+      die("Invalid label specified: $label\n");
+    }
+
+    $path= preg_replace("/\[.*\]$/", "", $path);
+  }
+
+  // Non middle layout?
+  if ($align == "middle") {
+    $align= "";
+  } else {
+    $align= ";vertical-align:$align";
+  }
+
+  // Clickable image or not?
+  if ($title != "") {
+    $title= "title='$title'";
+  }
+  if ($action == "") {
+    return "<div class='img' $title style='".$styles[$path]."$align'>$lbl</div>";
+  } else {
+    return "<input type='submit' class='img' id='$action' value='' name='$action' $title style='".$styles[$path]."$align'>";
+  }
+}
+
+
+
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>