Code

Prepared for multiple asterisk servers
[gosa.git] / plugins / admin / fai / class_faiProfile.inc
index c3c6d052bdf2760e0cb7cbb7e33dd5c89b41bc5a..568d120f2b3e55c9da471de7ae8284cba3cc6a43 100644 (file)
@@ -16,10 +16,6 @@ class faiProfile extends plugin
   /* ObjectClasses for this Object*/
   var $objectclasses    = array("top","FAIclass","FAIprofile");
 
-  /* Class name of the Ldap ObjectClass for the Sub Object */
-  var $subClass         = "FAIscriptEntry";
-  var $subClasses       = array("top","FAIclass","FAIscriptEntry");
-
   /* Specific attributes */
   var $old_cn           = "";
   var $cn               = "";       // The class name for this object
@@ -29,6 +25,8 @@ class faiProfile extends plugin
   var $FAIclass         = "";       // Classnames used for this profile
   var $FAIclasses       = array();  // Contains classname seperated in an array
   var $FAIAllclasses    = array();  // Contains all possible Classnames
+  var $ui               ;
+  var $FAIstate      = "";
 
   function faiProfile($config, $dn= NULL)
   {
@@ -36,6 +34,8 @@ class faiProfile extends plugin
     plugin::plugin ($config, $dn);
     $ldap=$this->config->get_ldap_link();
 
+    $this->ui = get_userinfo();
+
     /* Parse ldap attribute to get all assigned classes */
     $tmp = split(" ",$this->FAIclass);
     $tmp2 = array();
@@ -44,7 +44,11 @@ class faiProfile extends plugin
         $tmp2[trim($class)] = trim($class);
       }
     }
-   
+
+    if(isset($this->attrs['FAIstate'][0])){
+      $this->FAIstate = $this->attrs['FAIstate'][0];
+    }
+
     /* Sort assigned classes */ 
     if(is_array($tmp2)){
       foreach($tmp2 as $class){
@@ -61,7 +65,7 @@ class faiProfile extends plugin
     }
     
     /* Get ldap connection */ 
-    $base = $_SESSION['faifilter']['base'];
+    $base = $_SESSION['CurrentMainBase'];
     $ldap->cd($base);
     $sort = array();
 
@@ -120,6 +124,20 @@ class faiProfile extends plugin
     return($ret);
   }
 
+
+  function acl_base_for_current_object($dn)
+  {
+    if($dn == "new"){
+      if($this->dn == "new"){
+        $dn= $_SESSION['CurrentMainBase'];
+      }else{
+        $dn = $this->dn;
+      }
+    }
+    return($dn);
+  }
+
+
   /* returns position in array */
   function getpos($atr,$attrs)
   {
@@ -196,21 +214,21 @@ class faiProfile extends plugin
     /* Remove class name From list */
     $sort_once = false;
     foreach($_POST as $name => $post){
-      if(preg_match("/DEL_/i",$name)){
+      if(preg_match("/DEL_/i",$name) && $this->acl_is_writeable("FAIclass")){
         $s_action = "delete";
         $s_entry  = preg_replace("/DEL_/","",$name);
         $s_entry  = base64_decode(preg_replace("/_.*$/","",$s_entry));
-      }elseif(preg_match("/Add_class/i",$name)){
+      }elseif(preg_match("/Add_class/i",$name)&& $this->acl_is_writeable("FAIclass")){
         $s_action  = "add";
-      }elseif(preg_match("/DelClass/i",$name)){
+      }elseif(preg_match("/DelClass/i",$name) && $this->acl_is_writeable("FAIclass")){
         $s_action  = "delete";
         $s_entry = $_POST['FAIclass'];
-      }elseif(preg_match("/AddClass/i",$name)){
+      }elseif(preg_match("/AddClass/i",$name) && $this->acl_is_writeable("FAIclass")){
         $s_action  = "add";
       }
 
       /* Check if a list element should be pushed one position up */
-      if((preg_match("/sortup_/",$name))&&(!$sort_once)){
+      if((preg_match("/sortup_/",$name))&&(!$sort_once) && $this->acl_is_writeable("FAIclass")){
         $sort_once = true;
         $val = preg_replace("/sortup_/","",$name);
         $val = preg_replace("/_.*$/","",$val);
@@ -219,7 +237,7 @@ class faiProfile extends plugin
       }
       
       /* Check if a list element should be pushed one position down */
-      if((preg_match("/sortdown_/",$name))&&(!$sort_once)){
+      if((preg_match("/sortdown_/",$name))&&(!$sort_once) && $this->acl_is_writeable("FAIclass")){
         $sort_once = true;
         $val = preg_replace("/sortdown_/","",$name);
         $val = preg_replace("/_.*$/","",$val);
@@ -229,11 +247,11 @@ class faiProfile extends plugin
 
     }
 
-    if($s_action == "delete"){
+    if($s_action == "delete" && $this->acl_is_writeable("FAIclass")){
       unset($this->FAIclasses[$s_entry]);
     }
 
-    if($s_action == "add"){
+    if($s_action == "add" && $this->acl_is_writeable("FAIclass")){
       $this->dialog = new faiProfileEntry($this->config,$this->dn,$this->FAIclasses);
       $this->is_dialog  =true;
     }
@@ -287,19 +305,28 @@ class faiProfile extends plugin
     $linkupdown.= "<input type='image' name='sortdown_%s' alt='down'  title='"._("Down")."' src='images/sort_down.png' >";
 
     /* Append fai classes to divlist */
-    foreach($this->FAIclasses as $usedClass){
-      $str = "&nbsp;";
+    if($this->acl_is_readable("FAIclass")){
+      foreach($this->FAIclasses as $usedClass){
+        $str = "&nbsp;";
+        $act = "";
+
+        if(isset($this->FAIAllclasses[$usedClass])){
+          foreach($this->FAIAllclasses[$usedClass] as $class => $obj){
+            $str.= $objTypes[$class]; 
+          }
+        }
 
-      if(isset($this->FAIAllclasses[$usedClass])){
-        foreach($this->FAIAllclasses[$usedClass] as $class => $obj){
-          $str.= $objTypes[$class]; 
+        $field1 = array("string"=> $usedClass,"attach"=>"");
+        $field2 = array("string"=> $str,"attach"=>"");
+        if(($this->FAIstate != "freeze") && $this->acl_is_writeable("FAIclass")){
+          $field3 = array("string"=> preg_replace("/%KEY%/",base64_encode($usedClass),$actions).
+              preg_replace("/%s/",base64_encode($usedClass),$linkupdown),
+              "attach"=>"style='border-right:none;'");
+        }else{
+          $field3 = array("string"=>"&nbsp;", "attach"=>"style='border-right:none;'");
         }
+        $divlist->AddEntry(array($field1,$field2,$field3));
       }
-  
-      $field1 = array("string"=> $usedClass,"attach"=>"");
-      $field2 = array("string"=> $str,"attach"=>"");
-      $field3 = array("string"=> preg_replace("/%KEY%/",base64_encode($usedClass),$actions).preg_replace("/%s/",base64_encode($usedClass),$linkupdown),"attach"=>"style='border-right:none;'");
-      $divlist->AddEntry(array($field1,$field2,$field3));
     }
 
     $smarty->assign("FAIclasses"  ,$this->FAIclasses);
@@ -316,6 +343,16 @@ class faiProfile extends plugin
       }
     }
 
+    
+    $dn = $this->acl_base_for_current_object($this->dn);
+    $smarty->assign("sub_object_is_addable",
+        preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiScriptEntry")) &&
+        !preg_match("/freeze/",$this->FAIstate));
+
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translated){
+      $smarty->assign($name."ACL",$this->getacl($name));
+    }
 
     $display.= $smarty->fetch(get_template_path('faiProfile.tpl', TRUE));
     return($display);
@@ -325,27 +362,31 @@ class faiProfile extends plugin
   {
     $ldap = $this->config->get_ldap_link();
     $ldap->cd ($this->dn);
-    $ldap->rmdir_recursive($this->dn);
+
+#    $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $this->dn);
+    $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $this->dn);
+    if($_SESSION['faifilter']['branch'] == "main"){
+      $use_dn = $this->dn;
+    }
+
+    prepare_to_save_FAI_object($use_dn,array(),true);
     $this->handle_post_events("remove");    
   }
 
+
   /* Save data to object 
    */
   function save_object()
   {
     plugin::save_object();
-    foreach($this->attributes as $attrs){
-      if(isset($_POST[$attrs])){
-        $this->$attrs = $_POST[$attrs];
-      }
-    }
   }
 
 
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     if(count($this->FAIclasses) == 0){
       $message[]=_("Please assign at least one class to this  profile.");
@@ -356,8 +397,12 @@ class faiProfile extends plugin
     }
 
     $ldap = $this->config->get_ldap_link();
-    $ldap->cd($_SESSION['faifilter']['base']);
-    $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",array("*"));
+    $ldap->cd($_SESSION['CurrentMainBase']);
+    if ($this->old_cn == ""){
+      $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn."))",array("*"));
+    } else {
+      $ldap->search("(&(objectClass=FAIprofile)(cn=".$this->cn.")(!cn=".$this->old_cn."))",array("*"));
+    }
 
     if($ldap->count()){
       $message[]=_("There is already a profile with this class name defined.");
@@ -381,21 +426,32 @@ class faiProfile extends plugin
 
     $this->attrs['FAIclass']=trim($this->FAIclass);
 
-    $ldap->cat($this->dn);
-    if($ldap->count()!=0){
-      /* Write FAIscript to ldap*/
-      $ldap->cd($this->dn);
-      $this->cleanup();
-$ldap->modify ($this->attrs); 
-
-    }else{
-      /* Write FAIscript to ldap*/
-      $ldap->cd($this->config->current['BASE']);
-      $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
-      $ldap->cd($this->dn);
-      $ldap->add($this->attrs);
-    }
-    show_ldap_error($ldap->get_error());
+    prepare_to_save_FAI_object($this->dn,$this->attrs);
+    
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/profile with dn '%s' failed."),$this->dn));
+
+    /* Do object tagging */
+    $this->handle_object_tagging();
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/profile with dn '%s' failed."),$this->dn));
+  }
+
+
+  /* Return plugin informations for acl handling */ 
+  function plInfo()
+  {
+    return (array( 
+          "plShortName" => _("Profile"),
+          "plDescription" => _("FAI profile"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 30,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("fai"),
+          "plProvidedAcls" => array(
+            "cn"                => _("Name"),
+            "description"       => _("Description"),
+            "FAIclass"          => _("FAI classes"))
+          ));
   }
 }