Code

Updated phoneAccount.
[gosa.git] / include / functions.inc
index cc724f8a62807467cc5b295ac272ba36fa7dbcac..cebbb4a3f9c3e82321775d45d97a90c015869d42 100644 (file)
@@ -153,17 +153,19 @@ function get_browser_language()
   /* Try to use users primary language */
   global $config;
   $ui= get_userinfo();
-  if ($ui != NULL){
+  if (isset($ui) && $ui !== NULL){
     if ($ui->language != ""){
       return ($ui->language.".UTF-8");
     }
   }
 
-  /* Try to use users primary language */
-  if ($ui != NULL){
-    if ($ui->language != ""){
-      return ($ui->language.".UTF-8");
+  /* 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(!preg_match("/utf/i",$lang)){
+      $lang .= ".UTF-8";
     }
+    return($lang);
   }
 
   /* Load supported languages */
@@ -314,7 +316,7 @@ function ldap_login_user ($username, $password)
 
   /* Check if mail address is also a valid auth name */
   $auth_mail = FALSE;
-  if(isset($config->current['AUTH_MAIL']) && preg_match("/true/",$config->current['AUTH_MAIL'])){
+  if(isset($config->current['AUTH_MAIL']) && preg_match("/^true$/i",$config->current['AUTH_MAIL'])){
     $auth_mail = TRUE;
   }
 
@@ -344,7 +346,7 @@ function ldap_login_user ($username, $password)
   /* LDAP schema is not case sensitive. Perform additional check. */
   $attrs= $ldap->fetch();
   if($auth_mail){
-    if ($attrs['uid'][0] != $username && $attrs['mail'][0] != $username){
+    if ($attrs['uid'][0] != $username && strcasecmp($attrs['mail'][0], $username) != 0){
       return(NULL);
     }
   }else{
@@ -2309,7 +2311,7 @@ function get_base_from_hook($dn, $attrib)
     $command= $config->current['BASE_HOOK'];
 
     if ($command != ""){
-      $command.= " '$dn' $attrib";
+      $command.= " '".LDAP::fix($dn)."' $attrib";
       if (check_command($command)){
         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
         exec($command, $output);
@@ -2478,48 +2480,6 @@ function get_base_from_hook($dn, $attrib)
   }
 
 
-function prepare4mailbody($string)
-{
-  $string = html_entity_decode($string);
-
-  $from = array(
-                "/%/",
-                "/ /",
-                "/\n/",  
-                "/\r/",
-                "/!/",
-                "/#/",
-                "/\*/",
-                "/\//",
-                "/</",
-                "/>/",
-                "/\?/",
-                "/\&/",
-                "/\(/",
-                "/\)/",
-                "/\"/");
-  
-  $to = array(  
-                "%25",
-                "%20",
-                "%0A",
-                "%0D",
-                "%21",
-                "%23",
-                "%2A",
-                "%2F",
-                "%3C",
-                "%3E",
-                "%3F",
-                "%38",
-                "%28",
-                "%29",
-                "%22");
-
-  $string = preg_replace($from,$to,$string);
-
-  return($string);
-}
 
 
 function mac2company($mac)
@@ -2644,6 +2604,62 @@ function is_in_network($network, $netmask, $address)
 }
 
 
+/* Add a given objectClass to an attrs entry */
+function add_objectClass($classes, &$attrs)
+{
+       if (is_array($classes)){
+               $list= $classes;
+       } else {
+               $list= array($classes);
+       }
+
+       foreach ($list as $class){
+               $attrs['objectClass'][]= $class;
+       }
+}
+
+
+/* Removes a given objectClass from the attrs entry */
+function remove_objectClass($classes, &$attrs)
+{
+       if (isset($attrs['objectClass'])){
+               /* Array? */
+               if (is_array($classes)){
+                       $list= $classes;
+               } else {
+                       $list= array($classes);
+               }
+
+               $tmp= array();
+               foreach ($attrs['objectClass'] as $oc) {
+                       foreach ($list as $class){
+                               if ($oc != $class){
+                                       $tmp[]= $oc;
+                               }
+                       }
+               }
+               $attrs['objectClass']= $tmp;
+       }
+}
+
+
+function cred_encrypt($input, $password) {
+
+  $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
+  $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
+
+  return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $password, $input, MCRYPT_MODE_ECB, $iv));
+}
+
+
+function cred_decrypt($input,$password) {
+  $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
+  $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
+
+  return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, pack("H*", $input), MCRYPT_MODE_ECB, $iv);
+}
+
+
 /* Returns contents of the given POST variable and check magic quotes settings */
 function get_post($name)
 {