Code

Added rendering for action menu
[gosa.git] / gosa-core / include / password-methods / class_password-methods.inc
index 039886d5679257b9e2468b9903811fab6ecafe3d..cde47c38ee56f835040f0626c086058172ea29f1 100644 (file)
@@ -24,19 +24,124 @@ class passwordMethod
 {
   var $config = false;
   var $attrs= array();
+  var $display = FALSE;
   var $hash= "";
+  var $lockable = TRUE;
 
   // Konstructor
   function passwordMethod($config)
   {
   }
 
+  function create_template_hash($attrs)
+  {
+    if($this->get_hash_name() == ""){
+      return("{crypt}N0T$3T4N0W");
+    }else{
+      return('{'.$this->get_hash().'}').'N0T$3T4N0W';
+    }
+  }
 
   function get_hash_name()
   {
   }
 
 
+  function is_locked($config,$dn = "")
+  {
+    if(!$this->lockable) return FALSE;
+
+    /* Get current password hash */
+    $pwd ="";
+    if(!empty($dn)){
+      $ldap = $config->get_ldap_link();
+      $ldap->cd($config->current['BASE']);
+      $ldap->cat($dn);
+      $attrs = $ldap->fetch();
+      if(isset($attrs['userPassword'][0])){
+        $pwd = $attrs['userPassword'][0];
+      }
+    }elseif(isset($this->attrs['userPassword'][0])){
+      $pwd = $this->attrs['userPassword'][0];
+    }
+    return(preg_match("/^[^\}]*+\}!/",$pwd));
+  }
+
+
+  function lock_account($config,$dn = "")
+  {
+    if(!$this->lockable) return FALSE;
+
+    /* Get current password hash */
+    $pwd ="";
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    if(!empty($dn)){
+      $ldap->cat($dn);
+      $attrs = $ldap->fetch();
+      if(isset($attrs['userPassword'][0])){
+        $pwd = $attrs['userPassword'][0];
+      }
+    }elseif(isset($this->attrs['userPassword'][0])){
+      $pwd = $this->attrs['userPassword'][0];
+      $dn = $this->attrs['dn'];
+    }
+
+    /* We can only lock/unlock non-empty passwords */
+    if(!empty($pwd)){
+
+      /* Check if this entry is already locked. */
+      if(preg_match("/^[^\}]*+\}!/",$pwd)){
+        return(TRUE);
+      }     
+      
+      /* Lock entry */
+      $pwd = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$pwd);
+      $ldap->cd($dn);
+      $ldap->modify(array("userPassword" => $pwd));
+      return($ldap->success());
+    }
+    return(FALSE);
+  }
+
+
+  function unlock_account($config,$dn = "")
+  {
+    if(!$this->lockable) return FALSE;
+
+    /* Get current password hash */
+    $pwd ="";
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    if(!empty($dn)){
+      $ldap->cat($dn);
+      $attrs = $ldap->fetch();
+      if(isset($attrs['userPassword'][0])){
+        $pwd = $attrs['userPassword'][0];
+      }
+    }elseif(isset($this->attrs['userPassword'][0])){
+      $pwd = $this->attrs['userPassword'][0];
+      $dn = $this->attrs['dn'];
+    }
+
+    /* We can only lock/unlock non-empty passwords */
+    if(!empty($pwd)){
+
+      /* Check if this entry is already locked. */
+      if(!preg_match("/^[^\}]*+\}!/",$pwd)){
+        return (TRUE);
+      }     
+      
+      /* Lock entry */
+      $pwd = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$pwd);
+      $ldap->cd($dn);
+      $ldap->modify(array("userPassword" => $pwd));
+      return($ldap->success());
+    }
+    return(FALSE);
+  }
+
+
   // this function returns all loaded classes for password encryption
   static function get_available_methods()
   {
@@ -181,6 +286,10 @@ class passwordMethod
     return $this->hash;
   }
 
+  function adapt_from_template($dn)
+  {
+    return($this);
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>