Code

Added cn to class vars, to be able to use it within post_create etc
[gosa.git] / plugins / admin / systems / class_goKrbServer.inc
index 54456872894f67ad808143ef59d8a2eca8a10ec1..5c96c33629586ec8a08a29e62a7b34789cf4c7b6 100644 (file)
@@ -48,7 +48,7 @@ class goKrbServer extends plugin{
     $fields['Message']    = _("Kerberos kadmin access informations");
     $fields['AllowStart'] = true;
     $fields['AllowStop']  = true;
-    $fields['AllowReset'] = true;
+    $fields['AllowRestart'] = true;
     $fields['AllowRemove']= true;
     $fields['AllowEdit']  = true;
     return($fields);
@@ -69,6 +69,7 @@ class goKrbServer extends plugin{
       $ldap->add($this->attrs);
     }
     show_ldap_error($ldap->get_error());
+    $this->handle_post_events("remove");
   }
 
 
@@ -86,6 +87,11 @@ class goKrbServer extends plugin{
       $ldap->add($this->attrs);
     }
     show_ldap_error($ldap->get_error());
+    if($this->initially_was_account){
+      $this->handle_post_events("modify");
+    }else{
+      $this->handle_post_events("add");
+    }
   }
 
 
@@ -93,53 +99,39 @@ class goKrbServer extends plugin{
   function setStatus($value)
   {
     if($value == "none") return;
+    if(!$this->initially_was_account) return;
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->dn);
-    $ldap->cat($this->dn,array("objectClass","goKrbRealm","goKrbAdmin","goKrbPassword"));
-      
+    $ldap->cat($this->dn,array("objectClass"));
     if($ldap->count()){
-      $attrs =array();
-      foreach(array("goKrbRealm","goKrbAdmin","goKrbPassword") as $req) {
-        if(!isset($attrs[$req])){
-          if(empty($this->$req)){
-            print_red(sprintf(_("The required attribute '%s' is not set."),$req));
-          }else{
-            $attrs[$req] = $this->$req;
-          }
-        }else{
-          $attrs[$req] = $attrs[$req][0];
-        }
-      }
 
       $tmp = $ldap->fetch();
       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
         $attrs['objectClass'][] = $tmp['objectClass'][$i];
-      }    
-      if(!in_array("goKrbServer",$attrs['objectClass'])){
-        $attrs['objectClass'][] = "goKrbServer";
       }
-
       $flag = $this->StatusFlag;
       $attrs[$flag] = $value;
       $this->$flag = $value;
       $ldap->modify($attrs);
       show_ldap_error($ldap->get_error());
-    }    
+      $this->action_hook();
+    }
   }
-
-  
   function check()
   { 
     $message = plugin::check();
-    foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
-        if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
-          $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
-        }
-      }
-      /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
-      if ($this->goKrbPassword == "" ){
-        $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
-      }
+    /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
+    if (empty($this->goKrbPassword)){
+      $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
+    }
+    if (empty($this->goKrbAdmin)){
+      $message[]= sprintf(_("The specified kerberos admin is empty."), $attr);
+    }
+    if (empty($this->goKrbRealm)){
+      $message[]= sprintf(_("The specified kerberos realm is empty."), $attr);
+    }
 
     return($message);
   }
@@ -150,7 +142,39 @@ class goKrbServer extends plugin{
     if(isset($_POST['goKrbServerPosted'])){
       plugin::save_object();
     }
-  }  
+  } 
+
+   function action_hook($add_attrs= array())
+  {
+    /* Find postcreate entries for this class */
+    $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
+    if ($command == "" && isset($this->config->data['TABS'])){
+      $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
+    }
+    if ($command != ""){
+      /* Walk through attribute list */
+      foreach ($this->attributes as $attr){
+        if (!is_array($this->$attr)){
+          $command= preg_replace("/%$attr/", $this->$attr, $command);
+        }
+      }
+      $command= preg_replace("/%dn/", $this->dn, $command);
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+      if (check_command($command)){
+        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
+            $command, "Execute");
+
+        exec($command);
+      } else {
+        $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
+        print_red ($message);
+      }
+    }
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>