Code

Added acls to mimetype
[gosa.git] / plugins / admin / ogroups / class_termgroup.inc
index 49d099202667cf6422bb458a4f4a3e1791f3ad2a..855bfadeab90473bc5d25ac673abbaf76abfead2 100644 (file)
@@ -14,10 +14,16 @@ class termgroup extends plugin
   var $gotoNtpServers     = array();
   var $modes              = array();
   var $inheritTimeServer  = true;
-  var $acl                ;
-  var $is_account                = true; 
-  var $orig_dn               = "";
-  var $didAction                 = FALSE;
+  var $is_account                    = true; 
+  var $orig_dn            = "";
+  var $didAction          = FALSE;
+  var $mapActions         = array("reboot"          => "",
+                            "instant_update"  => "softupdate",
+                            "update"          => "sceduledupdate",
+                            "reinstall"       => "install",
+                            "rescan"          => "",
+                            "memcheck"        => "memcheck",
+                            "sysinfo"         => "sysinfo");
 
 
   function termgroup ($config, $dn= NULL)
@@ -31,14 +37,10 @@ class termgroup extends plugin
     $ldap= $config->get_ldap_link();
 
     $this->is_account = true;
-    $ui               = get_userinfo();
-    $acl              = get_permissions ($this->dn, $ui->subtreeACL);
-    $this->acl        = get_module_permission($acl, "group", $this->dn);
-
     $this->modes["active"]= _("Activated");
     $this->modes["locked"]= _("Locked");
-    $this->modes["memcheck"]= _("Memory test");
-    $this->modes["sysinfo"]= _("System analysis");
+//    $this->modes["memcheck"]= _("Memory test");
+//    $this->modes["sysinfo"]= _("System analysis");
 
     $this->orig_dn =   $this->dn;
 
@@ -102,13 +104,13 @@ class termgroup extends plugin
      /* Call common method to give check the hook */
     $message= plugin::check();
 
-    if (chkacl($this->acl, "create") != ""){
+    if ($this->acl_is_createable() && $this->dn == "new"){
       $message[]= _("You have no permissions to create a workstation on this 'Base'.");
     }
 
     /* Check for valid ntpServer selection */
     if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
-      $message[]= _("There must be at least one NTP server selected, or the inherit mode activated.");
+      $message[]= _("There must be at least one NTP server selected.");
     }
     return($message);
   }
@@ -150,6 +152,7 @@ class termgroup extends plugin
 
       if (isset($_POST['action'])){
         $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
+
         if ($cmd == ""){
           print_red(_("No ACTIONCMD definition found in your gosa.conf"));
         } else {
@@ -158,6 +161,45 @@ class termgroup extends plugin
             print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
           } else {
             $this->didAction= TRUE;
+
+            /* Get dns from member objects. Create ldap object  */
+            $member = $this->parent->by_object['ogroup']->member;
+            $ldap = $this->config->get_ldap_link();
+            $ldap->cd($this->config->current['BASE']);
+
+            /* walk trough members and add FAIstate */ 
+            foreach($member as $dn =>  $object){
+
+              /* Get object */
+              $ldap->cat($dn,array("objectClass"));
+              $res                = $ldap->fetch();
+              $attrs              = array();
+
+              /* Add FAI state */
+              $attrs['FAIstate']  = "";
+              if(isset($this->mapActions[$_POST['saction']])){
+                $attrs['FAIstate'] = $this->mapActions[$_POST ['saction']];
+              }
+
+              /* Fix objectClass index */
+              for($i = 0; $i < $res['objectClass']['count'] ; $i ++){
+                $attrs['objectClass'][] = $res['objectClass'][$i];
+              }
+
+              /* Check if we must add the objectClass */
+              if(($attrs['FAIstate'] != "") && (!in_array("FAIobject",$attrs['objectClass']))){
+                $attrs['objectClass'][] = "FAIobject";
+              }
+
+              if($attrs['FAIstate'] == ""){
+                $attrs['FAIstate'] = array();
+              }
+
+              $ldap->cd($dn);
+              $ldap->modify($attrs);
+              show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/generic (FAIstate) with dn '%s' failed."),$dn));
+            }
+            $this->didAction= TRUE;
           }
         }
       }
@@ -188,31 +230,39 @@ class termgroup extends plugin
     /* Set government mode */
     $smarty= get_smarty();
 
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translated) {
+      $smarty->assign($name."ACL",$this->getacl($name));
+    }
+
     foreach($this->attributes as $attr){
       $smarty->assign($attr,      $this->$attr);
-      $smarty->assign($attr."ACL",chkacl($this->acl,$this->$attr));
     }
 
     /* Variables */
     foreach(array("gotoMode","gotoNtpServer") as $val){
       $smarty->assign($val."_select", $this->$val);
-      $smarty->assign($val."ACL", chkacl($this->acl, $val));
     }
 
-    /* Check if workstation is online */
-    $smarty->assign("actions", array(
-          "halt" =>             _("Switch off"), 
-          "reboot" =>           _("Reboot"),
-          "instant_update" =>   _("Instant update"),
-          "update" =>           _("Scheduled update"),
-          "reinstall" =>        _("Reinstall"),
-          "rescan" =>           _("Rescan hardware")));
+    $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
+          "instant_update" => _("Instant update"),
+          "update" => _("Scheduled update"),
+          "reinstall" => _("Reinstall"),
+          "rescan" => _("Rescan hardware"),
+          "memcheck" => _("Memory test"),
+          "sysinfo"  => _("System analysis")));
 
     $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
     $smarty->assign("modes", $this->modes);
-    $smarty->assign("actions", array("wake" => _("Wake up"), "halt" => _("Switch off"), "reboot" => _("Reboot")));
-    $smarty->assign("actionACL", chkacl($this->acl, 'action'));
-    $smarty->assign("gotoNtpServers",$this->gotoNtpServers); 
+
+    $tmp = array();
+    foreach($this->gotoNtpServers as $server){
+      if(!in_array($server,$this->gotoNtpServer)){
+        $tmp[$server] = $server;
+      }
+    }
+
+    $smarty->assign("gotoNtpServers",$tmp); 
     $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']); 
     $smarty->assign("gotoSyslogServer_select", $this->gotoSyslogServer); 
 
@@ -267,28 +317,37 @@ class termgroup extends plugin
 
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
-    if ($this->orig_dn == 'new'){
-      $ldap->cd($this->config->current['BASE']);
-      $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
-      $ldap->cd($this->dn);
-      $ldap->add($this->attrs);
-      if(!$this->didAction){
-        $this->handle_post_events("add");
-      }
-    } else {
-      if ($this->orig_dn != $this->dn){
-        $this->move($this->orig_dn, $this->dn);
-      }
-      $ldap->cd($this->dn);
-      $this->cleanup();
-      $ldap->modify ($this->attrs);
+    $ldap->cd($this->dn);
+    $this->cleanup();
+    $ldap->modify ($this->attrs);
 
-      if(!$this->didAction){
-        $this->handle_post_events("modify");
-      }
+    if(!$this->didAction){
+      $this->handle_post_events("modify");
     }
     show_ldap_error($ldap->get_error(), _("Saving workstation failed"));
+
   }
+  
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("System"),
+          "plDescription" => _("System group"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 0,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("ogroups"),
+          "plProvidedAcls"=> array(
+            "gotoMode"          => _("Mode"),     
+            "gotoSyslogServer"  => _("Syslog server"), 
+            "FAIstate"          => _("Action flag"), 
+            "gotoNtpServer"     => _("Ntp server"))
+          ));
+  }
+
+
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: