Code

Removed a couple of normalize_preg calls
[gosa.git] / gosa-plugins / goto / admin / applications / class_applicationGeneric.inc
index dffce7a49d032a267829e90e6b1caede90a98206..f8364a09999fc3dd0ae42a310269a1fce468605c 100644 (file)
@@ -17,28 +17,24 @@ class application extends plugin
   var $last_sorting= "invalid";
   var $applications= array();
 
+  var $orig_base = "";
+  var $orig_cn = "";
+  var $orig_dn = "";
+
   /* 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");
+  var $FAIstate ="";
 
   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();
+    $this->orig_dn = $dn;
     if ($dn != 'new'){
       $this->iconData= $ldap->get_attribute($dn, "gosaApplicationIcon");
       $this->saved_attributes['gosaApplicationIcon'] = $this->iconData;
@@ -61,13 +57,11 @@ 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('applicationRDN')."/", "", $this->dn);
     }
+
+    $this->orig_cn = $this->cn;
+    $this->orig_base = $this->base;
   }
 
 
@@ -122,12 +116,13 @@ class application extends plugin
 
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translation){
-      $smarty->assign($name."ACL",$this->getacl($name));
+      $smarty->assign($name."ACL",$this->getacl($name, preg_match("/freeze/i",$this->FAIstate)));
     }
+    $smarty->assign("IconReadable", $this->acl_is_readable("gosaApplicationIcon"));
  
     /* Do we represent a valid group? */
     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(_("application"))."</b>";
       return ($display);
     }
@@ -151,14 +146,18 @@ class application extends plugin
     $head = $this->generateTemplate();
     $this->gotoLogonScript= $this->generateTemplate().preg_replace('/.*### END HEADER ###/s', '', $this->gotoLogonScript);
 
-    if((isset($_POST['upLoad']))&&(isset($_FILES['ScriptFile']))){
+    if((isset($_POST['upLoad']))&&(isset($_FILES['ScriptFile'])) && !preg_match("/freeze/i",$this->FAIstate)){
       $str = file_get_contents($_FILES['ScriptFile']['tmp_name']);
       $this->gotoLogonScript = $str;
     }
 
     /* 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", "");
@@ -170,7 +169,7 @@ class application extends plugin
     /* Base select dialog */
     $once = true;
     foreach($_POST as $name => $value){
-      if(preg_match("/^chooseBase/",$name) && $once){
+      if(preg_match("/^chooseBase/",$name) && $once && !preg_match("/freeze/i",$this->FAIstate)){
         $once = false;
         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
         $this->dialog->setCurrentBase($this->base);
@@ -207,17 +206,17 @@ class application extends plugin
     }
 
     /* Checkboxes */
-    foreach (array("G" => "exec_for_groupmembers", "O" => "overwrite_config",
-          "L" => "place_on_kicker",
-          "D" => "place_on_desktop", "M" => "place_in_startmenu") as $key => $val){
-      if (preg_match("/$key/", $this->gosaApplicationFlags)){
+    foreach (array("G" => "execForGroupmembers", "O" => "overwriteConfig",
+          "L" => "placeOnKicker",
+          "D" => "placeOnDesktop", "M" => "placeInStartmenu") as $key => $val){
+      if (preg_match("/$key/", $this->gosaApplicationFlags) && $this->acl_is_readable("$val")){
         $smarty->assign("$val", "checked");
       } else {
         $smarty->assign("$val", "");
       }
     }
 
-    $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 */
@@ -230,7 +229,7 @@ class application extends plugin
     restore_error_handler();
 
     /* Parse release out of object dn */
-    $release = preg_replace("/".get_ou("applicationou").normalizePreg($this->base)."$/","",$this->dn);
+    $release = preg_replace("/".get_ou("applicationRDN").preg_quote($this->base)."$/","",$this->dn);
     $release = preg_replace("/^cn=[^,]+,/","",$release);
 
     /* Get a list of all groups 
@@ -250,7 +249,7 @@ class application extends plugin
       $ldap->cd($release.$group);
       $ldap->search("(objectClass=gotoMenuEntry)",array("dn"));
       while($attrs = $ldap->fetch()){
-        $info = preg_replace("/".normalizePreg($release.$group)."$/","",$attrs['dn']); 
+        $info = preg_replace("/".preg_quote($release.$group)."$/","",$attrs['dn']); 
         if(preg_match("/^cn=".$this->cn."/",$info) && !preg_match("/ou=[^,]+,/",$info)){
           $found[] = $attrs['dn'];
         }
@@ -291,6 +290,10 @@ class application extends plugin
   /* Save data to object */
   function save_object()
   {
+    if(preg_match("/freeze/i",$this->FAIstate)){
+      return;
+    }
+
     if (isset($_POST['cn'])){
 
       /* Create a base backup and reset the
@@ -303,25 +306,22 @@ class application extends plugin
       /* Save attributes */
       parent::save_object();
 
+      $checks = array("execForGroupmembers" => "G",
+                      "placeOnDesktop"      => "D",
+                      "placeOnKicker"       => "L",
+                      "placeInStartmenu"    => "M",
+                      "overwriteConfig"     => "O");
+
       /* Save application flags */
-      $flag= "";
-      if (isset($_POST['exec_for_groupmembers']) && $_POST['exec_for_groupmembers'] == 1){
-        $flag.= "G";
-      }
-      if (isset($_POST['place_on_desktop']) && $_POST['place_on_desktop'] == 1){
-        $flag.= "D";
-      }
-      if (isset($_POST['place_on_kicker']) && $_POST['place_on_kicker'] == 1){
-        $flag.= "L";
-      }
-      if (isset($_POST['place_in_startmenu']) && $_POST['place_in_startmenu'] == 1){
-        $flag.= "M";
-      }
-      if (isset($_POST['overwrite_config']) && $_POST['overwrite_config'] == 1){
-        $flag.= "O";
-      }
-      if ($this->acl_is_writeable("gosaApplicationFlags")){
-        $this->gosaApplicationFlags= "[$flag]";
+      foreach($checks as $name => $flag){
+        if($this->acl_is_writeable($name)){
+          $set = isset($_POST[$name]) && $_POST[$name] == 1;
+          if(!$set && preg_match("/".$flag."/",$this->gosaApplicationFlags)){
+            $this->gosaApplicationFlags = preg_replace("/".$flag."/","",$this->gosaApplicationFlags);  
+          }elseif($set && !preg_match("/".$flag."/",$this->gosaApplicationFlags)){
+            $this->gosaApplicationFlags = preg_replace("/]/",$flag."]",$this->gosaApplicationFlags); 
+          }
+        }  
       }
 
       /* Remove current picture */
@@ -338,7 +338,7 @@ class application extends plugin
 
         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");
@@ -389,7 +389,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']])){
@@ -413,7 +413,7 @@ class application extends plugin
 
     /* Permissions for that base? */
     if ($this->base != ""){
-      $new_dn= "cn=".$this->cn.",".get_ou('applicationou').$this->base;
+      $new_dn= "cn=".$this->cn.",".get_ou('applicationRDN').$this->base;
     } else {
       $new_dn= $this->dn;
     }
@@ -428,8 +428,8 @@ class application extends plugin
       $message[]= msgPool::required(_("Name"));
     }
 
-    if(preg_match("/[^a-z0-9]/",$this->cn))    {
-      $message[]=msgPool::invalid(_("Name"),$this->cn,"/^[a-z0-9]*$/");
+    if(preg_match("/[^a-z0-9_-]/",$this->cn))  {
+      $message[]=msgPool::invalid(_("Name"),$this->cn,"/^[a-z0-9_-]*$/");
     }
 
     if ($this->gosaApplicationExecute == ""){
@@ -441,26 +441,29 @@ 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[]= msgPool::duplicate("cn");
-        }
-      }
+
+    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[]= msgPool::duplicate("cn");
-        }
+      $base = get_ou('applicationRDN').$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");
       }
     }
+
+    /* 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;
   }
 
@@ -510,10 +513,26 @@ class application extends plugin
     }
   }
 
+  
+  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)){
-      $filename= "./images/default_icon.png";
+      $filename= "./plugins/goto/images/default_icon.png";
       $this->gosaApplicationIcon= "*removed*";
     }
 
@@ -587,14 +606,13 @@ class application extends plugin
             "gosaApplicationExecute"  => _("Execute"),
             "gosaApplicationName"     => _("Name"),
             "gosaApplicationIcon"     => _("Icon"),
-            "gosaApplicationFlags"    => _("Flag"),
             "gotoLogonScript"         => _("Script content"),
 
-            "exec_for_groupmembers" => _("Only executable for members"),              // G
-            "place_on_desktop"      => _("Place icon on members desktop"),            // D
-            "place_on_kicker"       => _("Place entry in members launch bar"),        // L
-            "place_in_startmenu"    => _("Place entry in members startmenu"),         // M
-            "overwrite_config"      => _("Replace user configuration on startup"))  // O
+            "execForGroupmembers" => _("Only executable for members"),              // G
+            "placeOnDesktop"      => _("Place icon on members desktop"),            // D
+            "placeOnKicker"       => _("Place entry in members launch bar"),        // L
+            "placeInStartmenu"    => _("Place entry in members startmenu"),         // M
+            "overwriteConfig"      => _("Replace user configuration on startup"))  // O
             ));
   }
 }