Code

Updated plugin creation && locking for all main.incs
[gosa.git] / gosa-plugins / goto / admin / devices / class_deviceGeneric.inc
index d9ab5bf762f9cd34edafafda4c19331af7f6bb1c..0448b3bde477c104852c65bfc142a2dcb5f575ea 100644 (file)
@@ -5,19 +5,20 @@ class deviceGeneric extends plugin
   public $dn            = "";
   public $cn            = "";
   public $orig_cn       = "";
+  public $orig_base     = "";
+  public $orig_dn       = "";
   public $description   = "";
   public $vendor        = "";
-  public $dev_id        = "";
+  public $devID        = "";
   public $serial        = "";
   public $base          = "";  
   public $types;
   public $type;
 
-  public $posts           = array("description","dev_id","serial","vendor", "type");
-  public $attributes      = array("cn");
+  public $attributes      = array("cn","description","devID","serial","vendor", "type");
   public $objectclasses   = array("top","gotoDevice");
 
-  public $CopyPasteVars   = array("orig_cn","description","vendor","dev_id","serial","base");
+  public $CopyPasteVars   = array("orig_cn","description","vendor","devID","serial","base");
 
   public function deviceGeneric(&$config,$dn = NULL)
   {
@@ -35,7 +36,7 @@ class deviceGeneric extends plugin
       $tmp = preg_split("/\|/",$this->attrs['gotoHotplugDevice'][0]);
       $this->cn         = $this->attrs['cn'][0];
       $this->description= $tmp[0];
-      $this->dev_id     = $tmp[1];
+      $this->devID     = $tmp[1];
       $this->serial     = $tmp[2];
       $this->vendor     = $tmp[3];
       if (isset($tmp[4])){
@@ -54,8 +55,10 @@ class deviceGeneric extends plugin
         $this->base= dn2base($ui->dn);
       }
     } else {
-      $this->base =preg_replace ("/^[^,]+,".get_ou('deviceou')."/","",$this->dn);
+      $this->base =preg_replace ("/^[^,]+,".get_ou('deviceRDN')."/","",$this->dn);
     }
+    $this->orig_base = $this->base;
+    $this->orig_dn   = $this->dn;
   }
 
 
@@ -67,13 +70,14 @@ class deviceGeneric extends plugin
     foreach($this->attributes as $attr){
       $smarty->assign($attr,$this->$attr);
     }
-    foreach($this->posts as $attr){
-      $smarty->assign($attr,$this->$attr);
+  
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $attr => $desc){
+      $smarty->assign($attr."ACL", $this->getacl($attr));
     }
 
     $smarty->assign("type",$this->type);
     $smarty->assign ("types", $this->types);
-
     return($smarty->fetch(get_template_path("deviceGeneric.tpl",TRUE,dirname(__FILE__))));
   }
 
@@ -82,7 +86,7 @@ class deviceGeneric extends plugin
   {
     $message = plugin::check();
 
-    if(empty($this->cn)||(preg_match("/[^a-z0-9]/i",$this->cn))){
+    if($this->cn == "" ||(preg_match("/[^a-z0-9]/i",$this->cn))){
       $message[]= msgPool::invalid(_("Name"),$this->cn,"/^[a-z0-9]*$/i");
     }
     if(preg_match("/[^a-z0-9!\"?.,;:-_\(\) ]/i",$this->description)){
@@ -90,8 +94,10 @@ class deviceGeneric extends plugin
     }
 
     /* Skip serial check if vendor and product id are given */
-    if(preg_match("/^\s+$/i",$this->dev_id)){
+    if(preg_match("/^\s+$/i",$this->devID)){
       $message[]= msgPool::invalid(_("iSerial"),"","01234");
+    }elseif(empty($this->devID) && $this->devID!="0"){
+      $message[]= msgPool::required(_("iSerial"));
     }
     if(empty($this->serial) || !$this->is_2byteHex($this->serial)){
       $message[]= msgPool::invalid(_("Serial"),"","","0x1234");
@@ -99,9 +105,9 @@ class deviceGeneric extends plugin
     if(empty($this->vendor) || !$this->is_2byteHex($this->vendor)){
       $message[]= msgPool::invalid(_("Vendor ID"),"","","0x1234");
     }
-   
+  
     /* Check if entry already exists */ 
-    if($this->cn != $this->orig_cn){
+    if($this->cn != $this->orig_cn || $this->dn == "new"){
       $ldap = $this->config->get_ldap_link();
       $ldap->search("(&(objectClass=gotoDevice)(cn=".$this->cn."*))",array("cn"));
       if($ldap->count()){
@@ -109,6 +115,14 @@ class deviceGeneric extends plugin
       }
     }
 
+    /* Check if we are allowed to create or move this object
+     */
+    if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
+      $message[] = msgPool::permCreate();
+    }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+      $message[] = msgPool::permMove();
+    }
+
     return($message);
   }
 
@@ -124,12 +138,6 @@ class deviceGeneric extends plugin
           $this->base = get_post("base");
         }
       }
-    
-      foreach($this->posts as $post){
-        if(isset($_POST[$post])){
-          $this->$post = get_post($post);
-        }
-      }
     }
   }
 
@@ -143,7 +151,7 @@ class deviceGeneric extends plugin
     $ldap->search("(&(objectClass=gotoEnvironment)(gotoHotplugDeviceDN=".$this->dn."))",array("cn","gotoHotplugDeviceDN"));
     $skip = FALSE;
     $obj = array();
-    while($cnt && $attrs = $ldap->fetch()){
+    while($attrs = $ldap->fetch()){
       $obj[$ldap->getDN()]= $attrs['cn'][0];
       $skip =TRUE;
     }
@@ -159,8 +167,16 @@ class deviceGeneric extends plugin
   {
     plugin::save();
 
+    /* Unset non ldap attributes 
+     */
+    foreach(array("devID","serial","vendor", "type", "description") as $name){
+      if(isset($this->attrs[$name])){
+        unset($this->attrs[$name]);
+      }
+    }
+
     $this->attrs['gotoHotplugDevice'] = "";
-    foreach($this->posts as $post){
+    foreach(array("description","devID","serial","vendor", "type") as $post){
       $this->attrs['gotoHotplugDevice'] .= $this->$post."|"; 
     }
     $this->attrs['gotoHotplugDevice'] = preg_replace("/\|$/","",$this->attrs['gotoHotplugDevice']);
@@ -233,7 +249,7 @@ class deviceGeneric extends plugin
   {
     return (array(
           "plShortName"   => _("Generic"),
-          "plDescription" => _("Device generic"),
+          "plDescription" => _("Device generic")." ("._("Hotplug").")",
           "plSelfModify"  => FALSE,
           "plDepends"     => array(),
           "plPriority"    => 0,
@@ -241,7 +257,13 @@ class deviceGeneric extends plugin
           "plCategory"    => array("devices" => array("description"  => _("Devices"),
                                                         "objectClass"  => "gotoHotplugDevice")),
           "plProvidedAcls"=> array(
-            "cn"                          => _("Name"))
+            "cn"            => _("Name"),
+            "base"          => _("Base"),
+            "description"   => _("Description"),
+            "type"          => _("Type"),
+            "serial"        => _("Serial"),
+            "vendor"        => _("Vendor"), 
+            "devID"        => _("Device ID"))
           ));
 
   }