Code

Updated acl checks
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_printGeneric.inc
index 1c974684ecd3e7323135651725079f2a91a8e491..68cc78273a1351486ef4d6cfeb4b3c05c38b64d8 100644 (file)
@@ -15,6 +15,8 @@ class printgeneric extends plugin
   var $gotoPrinterPPD   = "";
   var $initial_PPD      = "";
   var $orig_dn          = "";
+  var $orig_cn          = "";
+  var $orig_base        = "";
 
   var $UserMember       ="";
   var $UserMembers      =array();
@@ -40,7 +42,7 @@ class printgeneric extends plugin
 
   /* attribute list for save action */
   var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress", 
-                              "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
+                              "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter","gosaUnitTag");
   var $objectclasses  = array("top", "gotoPrinter");
   var $view_logged    = FALSE;
   var $parent;
@@ -101,7 +103,7 @@ class printgeneric extends plugin
       }
 
       if(!isset($this->config->idepartments[$this->base])){
-        print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),session::get('CurrentMainBase'));
+        msg_dialog::display(_("Internal error"), sprintf(_("Cannot determine a valid department for this object. Setting base to '%s'!"), session::get('CurrentMainBase')) , WARNING_DIALOG);
         $this->base  = session::get('CurrentMainBase');
       }
     }
@@ -122,12 +124,11 @@ class printgeneric extends plugin
       /* $this->members contains all members */
       $this->member[$type]=array();
 
-      if (isset($this->attrs[$attr]['count'])) {
-        unset($this->attrs[$attr]['count']);
-      }
-
       if(isset($this->attrs[$attr])){
-        foreach($this->attrs[$attr] as $mem){
+        $ldap->cd($this->config->current['BASE']) ;
+        for($i = 0 ;  $i < $this->attrs[$attr]['count']; $i++){
+        
+          $mem = $this->attrs[$attr][$i];
           if(preg_match("/Group/",$type)){
             $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
             if($ldap->count()){
@@ -144,6 +145,8 @@ class printgeneric extends plugin
         }
       }
     }
+    $this->orig_cn    = $this->cn;
+    $this->orig_base  = $this->base;
   }
 
   function set_acl_base($base)
@@ -310,7 +313,7 @@ class printgeneric extends plugin
 
     /* Do we represent a valid printer? */
     if (!$this->is_account && $this->parent === NULL){
-      $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
+      $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
         msgPool::noValidExtension(_("printer"))."</b>";
       return($display);
     }
@@ -429,7 +432,7 @@ class printgeneric extends plugin
       $this->dialog->save_object();
       if(count($this->dialog->check())){
         foreach($this->dialog->check() as $msg){
-          print_red($msg);
+          msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
         }
       }else{
         $this->gotoPrinterPPD = array();
@@ -476,7 +479,7 @@ class printgeneric extends plugin
       $this->dialog->save_object();
       if(count($this->dialog->check())){
         foreach($this->dialog->check() as $msg){
-          print_red($msg);
+          msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
         }
       }else{
         $data= $new = $this->dialog->save();
@@ -578,14 +581,14 @@ class printgeneric extends plugin
       $ldap= $this->config->get_ldap_link();
       $ldap->cat($this->dn, array('dn',"objectClass"));
       if(!$ldap->count()){
-        print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
+        msg_dialog::display(_("Error"), _("Object is no printer!"), ERROR_DIALOG);
         return;
       }
 
       /* Check if obejct is a printer */
       $CheckPrinter = $ldap->fetch();
       if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
-        print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
+        msg_dialog::display(_("Error"), _("Object is no printer!"), ERROR_DIALOG);
         return;
       }
 
@@ -696,6 +699,14 @@ class printgeneric 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->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+      $message[] = msgPool::permMove();
+    }
+
     return ($message);
   }
 
@@ -718,10 +729,19 @@ class printgeneric extends plugin
       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
         return;
       }
+
+      /* Adapt IP & mac from parent object */
+      $this->netConfigDNS->ipHostNumber = $this->parent->by_object['workgeneric']->netConfigDNS->ipHostNumber;
+      $this->netConfigDNS->macAddress = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
+
     }elseif(isset($this->parent->by_object['termgeneric'])){
       if($this->parent->by_object['termgeneric']->cn == "default"){
         return;
       }
+    
+      /* Adapt IP & mac from parent object */
+      $this->netConfigDNS->ipHostNumber = $this->parent->by_object['termgeneric']->netConfigDNS->ipHostNumber;
+      $this->netConfigDNS->macAddress = $this->parent->by_object['termgeneric']->netConfigDNS->macAddress;
     }
 
     /* If type is still unknown, the initialisation of this printer failed, abort. */
@@ -755,21 +775,30 @@ class printgeneric extends plugin
     }else{
       $method="http://";
     }
+   
+    /* Get servername */
+    $server = $_SERVER['SERVER_NAME'];
+    if(tests::is_ip($server)){  
+      $server_name = gethostbyaddr($server);
+    }else{
+      $server_name = gethostbyaddr(gethostbyname($server));
+    }
 
     /* If no ppd is selected, remove this attribute */
     if(!empty($this->gotoPrinterPPD) && $this->initially_was_account) {
-      $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
+      $this->gotoPrinterPPD = $method.str_replace("//","/",$server_name."/ppd/".$this->gotoPrinterPPD);
     }else{
       $this->gotoPrinterPPD = array();
     }
 
     $dn= $this->dn;
-    plugin::save();
-    $ldap= $this->config->get_ldap_link();
 
     /* reduce objectClasses to minimun */
     $this->attrs['objectClass']= $this->objectclasses;
 
+    plugin::save();
+    $ldap= $this->config->get_ldap_link();
+
     /* Remove all empty values */
     if ($this->orig_dn == 'new'){
       $attrs= array();
@@ -857,11 +886,11 @@ class printgeneric extends plugin
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
     }
 
-    if(preg_match("/printer/i",$this->BelongsTo)){
+    #if(preg_match("/printer/i",$this->BelongsTo)){
       $this->netConfigDNS->cn = $this->cn;
       $this->netConfigDNS->dn = $this->dn;
       $this->netConfigDNS->save();
-    }
+    #}
   }
 
   function generateList(){
@@ -920,7 +949,7 @@ class printgeneric extends plugin
     }
   
     if(!$this->acl_is_writeable("gotoUserPrinter")){
-      print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
+      msg_dialog::display(_("Permission error"), msgPool::permDelete(_("printer user"), $id), INFO_DIALOG);
       return(FALSE);
     }
  
@@ -937,12 +966,12 @@ class printgeneric extends plugin
   {
     $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
     if(!in_array_ics($type, $types)){
-      print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
+      msg_dialog::display(_("Internal error"), sprintf(_("Illegal member type '%s'!"), $type), ERROR_DIALOG);
       return(FALSE);
     }
 
     if(!$this->acl_is_writeable("gotoUserPrinter")){
-      print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
+      msg_dialog::display(_("Permission error"), msgPool::permModify(_("printer user"), $this->dn), INFO_DIALOG);
       return(FALSE);
     }
 
@@ -977,7 +1006,7 @@ class printgeneric extends plugin
           }
 
           if(isset(  $this->member[$ctype][$name])){
-            print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
+            msg_dialog::display(_("Error"), sprintf(_("'%s' is already used!"), $attrs[$var][0]), ERROR_DIALOG);
             return(FALSE);
           }
         }
@@ -988,7 +1017,7 @@ class printgeneric extends plugin
         print_a($attrs);
       }
     }else{
-      print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
+      msg_dialog::display(_("Error"), sprintf(_("'%s' does not exist!"), $dn), ERROR_DIALOG);
       return(FALSE);
     }
     return(TRUE);