Code

Updated application acls
[gosa.git] / gosa-plugins / goto / admin / applications / class_applicationGeneric.inc
index 247acf97278aac3f39452d5eadd6ca5fef353b35..97da83a3cb0b1a173b0226430340216ba9165f5c 100644 (file)
@@ -1,11 +1,6 @@
 <?php
 class application extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Handling of GOsa's application object";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* application attributes */
   var $cn= "";
   var $description= "";
@@ -25,23 +20,13 @@ class application extends plugin
   /* attribute list for save action */
   var $attributes= array("cn", "description", "gosaApplicationExecute", "gosaApplicationName","gosaApplicationIcon",
       "gosaApplicationFlags","gotoLogonScript");
-  var $objectclasses= array("top", "gosaApplication");
 
-  var $isReleaseApplikation = false;
+  var $objectclasses= array("top", "gosaApplication");
 
   function application (&$config, $dn= NULL, $parent= NULL)
   {
     plugin::plugin ($config, $dn, $parent);
 
-    $appfilter = session::get('appfilter')    ;
-
-    $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
-    if(!empty($tmp)) {
-      if(!preg_match("/^".get_ou('applicationou')."/",$appfilter['release'])){
-        $this->isReleaseApplikation = true;  
-      }
-    }
-
     /* Load icon */
     $ldap= $config->get_ldap_link();
     if ($dn != 'new'){
@@ -66,12 +51,7 @@ class application extends plugin
         $this->base= dn2base($ui->dn);
       }
     } else {
-
-      if($this->isReleaseApplikation){
-        $this->base = preg_replace("/^.*,".get_ou('applicationou')."/","",$this->dn);
-      }else{
-        $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
-      }
+      $this->base= preg_replace ("/^[^,]+,".get_ou('applicationou')."/", "", $this->dn);
     }
   }
 
@@ -132,8 +112,8 @@ class application extends plugin
  
     /* Do we represent a valid group? */
     if (!$this->is_account && $this->parent === NULL){
-      $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
-        _("This 'dn' is no application.")."</b>";
+      $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
+        msgPool::noValidExtension(_("application"))."</b>";
       return ($display);
     }
 
@@ -163,7 +143,11 @@ class application extends plugin
 
     /* Fill templating stuff */
     $smarty->assign("cn", $this->cn);
-    $smarty->assign("bases", $this->get_allowed_bases());
+    if(!$this->is_release()){
+      $smarty->assign("bases", $this->get_allowed_bases());
+    }else{
+      $smarty->assign("bases", array());
+    }
     if ($this->dn == "new"){
       $smarty->assign("selectmode", "");
       $smarty->assign("namemode", "");
@@ -222,7 +206,7 @@ class application extends plugin
       }
     }
 
-    $smarty->assign("isReleaseApplikation" , $this->isReleaseApplikation);
+    $smarty->assign("isReleaseApplikation" ,$this->is_release());
     $smarty->assign("gotoLogonScript",htmlentities($this->gotoLogonScript, ENT_COMPAT, 'UTF-8'));
     $smarty->assign("base_select", $this->base);
     /* Show main page */
@@ -232,10 +216,49 @@ class application extends plugin
 
   function remove_from_parent()
   {
+    restore_error_handler();
+
+    /* Parse release out of object dn */
+    $release = preg_replace("/".get_ou("applicationou").normalizePreg($this->base)."$/","",$this->dn);
+    $release = preg_replace("/^cn=[^,]+,/","",$release);
+
+    /* Get a list of all groups 
+     */
+    $groups = array();
     $ldap= $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(objectClass=posixGroup)",array("dn"));
+    while($attrs = $ldap->fetch()){
+      $groups[$attrs['dn']] = array();
+    }
+    
+    /* Check if there are groups, useing this application 
+     */
+    $found = array();
+    foreach($groups as $group => $data){
+      $ldap->cd($release.$group);
+      $ldap->search("(objectClass=gotoMenuEntry)",array("dn"));
+      while($attrs = $ldap->fetch()){
+        $info = preg_replace("/".normalizePreg($release.$group)."$/","",$attrs['dn']); 
+        if(preg_match("/^cn=".$this->cn."/",$info) && !preg_match("/ou=[^,]+,/",$info)){
+          $found[] = $attrs['dn'];
+        }
+      }
+    }
+
+    /* Create an error message an skip remove, if 
+        this application is still in use. 
+     */
+    if(count($found)){
+      msg_dialog::display(_("Error"), sprintf(_("Cannot remove application - it is still in use by these objects: %s"), "<br>".msgPool::buildList($found)), ERROR_DIALOG);
+      return(FALSE);
+    }
+
     $ldap->rmDir($this->dn);
     new log("remove","application/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of application with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()), ERROR_DIALOG);
+    }
 
     /* Optionally execute a command after we're done */
     $this->handle_post_events("remove");
@@ -247,16 +270,10 @@ class application extends plugin
       $og= new ogroup($this->config, $ldap->getDN());
       unset($og->member[$this->dn]);
       $og->save ();
-      show_ldap_error($ldap->get_error(), sprintf(_("Removing application from objectgroup '%s' failed"), $og->dn));
-    }
-    $ldap->search ("(&(objectClass=posixGroup)(gosaMemberApplication=".$this->cn."))", array("cn"));
-    while ($attrs= $ldap->fetch()){
-      $ag= new appgroup($this->config, $ldap->getDN());
-      $ag->removeApp($this->cn);
-      $ag->save ();
-      show_ldap_error($ldap->get_error(), sprintf(_("Removing application from group '%s' failed"), $ag->dn));
+      if (!$ldap->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()), ERROR_DIALOG);
+      }
     }
-
   }
 
 
@@ -305,12 +322,12 @@ class application extends plugin
       if (isset($_FILES['picture_file']['name']) && $_FILES['picture_file']['name'] != ""){
 
         if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
-          print_red (_("The specified picture has not been uploaded correctly."));
+          msg_dialog::display(_("Error"), msgPool::incorrectUpload(), ERROR_DIALOG);
         }
 
         if (!function_exists("imagick_blob2image")){
           /* Get temporary file name for conversation */
-          $fname = tempnam ("/tmp", "GOsa");
+          $fname = tempnam (TEMP_DIR, "GOsa");
 
           /* Open file and write out photoData */
           $fp = fopen ($fname, "w");
@@ -337,21 +354,21 @@ class application extends plugin
 
           /* Load the new uploaded Photo */
           if(!$handle  =  imagick_ReadImage($_FILES['picture_file']['tmp_name'])){
-            print_red(_("Can't access uploaded image."));
+            msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("no read permission")), ERROR_DIALOG);
           }
 
           /* Resizing image to 147x200 and blur */
           if(!imagick_resize($handle,48,48,IMAGICK_FILTER_GAUSSIAN,0)){
-            print_red(_("Uploaded image could not be resized, possilby the image magick extension is missing."));
+            msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("cannot resize image")), ERROR_DIALOG);
           }
 
           /* Converting image to JPEG */
           if(!imagick_convert($handle,"PNG")) {
-            print_red(_("Could not convert image to png, possilby the image magick extension is missing."));
+            msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("cannot convert image")), ERROR_DIALOG);
           }
 
           if(!imagick_writeimage($handle,$_FILES['picture_file']['tmp_name'])){
-            print_red(sprintf(_("Could not save uploaded image to %s."),$_FILES['picture_file']['tmp_name']));
+            msg_dialog::display(_("Error"), msgPool::incorrectUpload(sprintf(_("cannot save image to '%s'"), $_FILES['picture_file']['tmp_name'])), ERROR_DIALOG);
           }
 
           imagick_free($handle);
@@ -361,7 +378,7 @@ class application extends plugin
         $this->set_picture($_FILES['picture_file']['tmp_name']);
       }        
 
-      if(!$this->isReleaseApplikation){
+      if(!$this->is_release()){
         $tmp = $this->get_allowed_bases();
         if(isset($_POST['base'])){
           if(isset($tmp[$_POST['base']])){
@@ -380,7 +397,7 @@ class application extends plugin
     $message= plugin::check();
 
     if(!preg_match("#^/#",$this->gosaApplicationExecute)){
-      $message[]=(_("Specified execute path must start with '/'."));
+      $message[]=msgPool::invalid(_("Execute path"),"","","/some/path");
     }
 
     /* Permissions for that base? */
@@ -397,15 +414,15 @@ class application extends plugin
 
     /* All required fields are set? */
     if ($this->cn == ""){
-      $message[]= _("Required field 'Name' is not filled.");
+      $message[]= msgPool::required(_("Name"));
     }
 
     if(preg_match("/[^a-z0-9]/",$this->cn))    {
-      $message[]=_("Invalid character in application name. Only a-z 0-9 are allowed.");
+      $message[]=msgPool::invalid(_("Name"),$this->cn,"/^[a-z0-9]*$/");
     }
 
     if ($this->gosaApplicationExecute == ""){
-      $message[]= _("Required field 'Execute' is not filled.");
+      $message[]= msgPool::required(_("Execute"));
     }
 
     /* Check for existing application */
@@ -413,24 +430,18 @@ class application extends plugin
     $ldap->cd($this->config->current["BASE"]);
 
     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
-    $appfilter = session::get('appfilter');
-    if((!empty($tmp)) && (isset($appfilter['release']))){
-      $baseDn = str_replace($this->config->current['BASE'],$this->base,$appfilter['release']);
-      $baseDn = preg_replace("/".get_ou('applicationou').".*/",get_ou('applicationou').$this->base,$appfilter['release']);
-      $ldap->ls("(&(objectClass=gosaApplication)(cn=".$this->cn."))",$baseDn,array("cn"));
-      if($ldap->count()){
-        $attrs = $ldap->fetch();
-        if($this->dn != $attrs['dn']) {
-          $message[]= _("There's already an application with this 'Name'.");
-        }
-      }
+
+    if($this->is_release()){
+      $base = $this->parent->parent->app_release;
     }else{
-      $ldap->ls("(&(objectClass=gosaApplication)(cn=".$this->cn."))",get_ou('applicationou').$this->base,array("cn"));
-      if ($ldap->count()){
-        $attrs = $ldap->fetch();
-        if($this->dn != $attrs['dn']) {
-          $message[]= _("There's already an application with this 'Name'.");
-        }
+      $base = get_ou('applicationou').$this->base;
+    }
+
+    $ldap->ls("(&(objectClass=gosaApplication)(cn=".$this->cn."))",$base,array("cn"));
+    if($ldap->count()){
+      $attrs = $ldap->fetch();
+      if($this->dn != $attrs['dn']) {
+        $message[]= msgPool::duplicated("cn");
       }
     }
     return $message;
@@ -477,9 +488,27 @@ class application extends plugin
       new log("create","application/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
       $this->handle_post_events("add");
     }
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of application with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()), ERROR_DIALOG);
+    }
+  }
+
+  
+  function is_release()
+  {
+    if(isset($this->parent->parent)){
+      return($this->parent->parent->IsReleaseManagementActivated());
+    }else{
+      /* Check if we should enable the release selection */
+      $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
+      if(!empty($tmp)){
+        return(true);
+      }
+    }
+    return(FALSE);
   }
 
+
   function set_picture($filename)
   {
     if (!is_file($filename)){