Code

Moved to new base selector
[gosa.git] / gosa-plugins / systems / admin / systems / class_servGeneric.inc
index 02f6106a30c7e8e1c55361f5c302266494a7e283..83cba2f758cc1651935eff036bbf9baa428f775e 100644 (file)
@@ -32,6 +32,8 @@ class servgeneric extends plugin
   var $l= "";
   var $description= "";
   var $orig_dn= "";
+  var $orig_cn= "";
+  var $orig_base= "";
 
   /* attribute list for save action */
   var $attributes= array("cn", "description","gotoMode");
@@ -43,7 +45,7 @@ class servgeneric extends plugin
   var $modes = array();
   var $ui   ;
   var $validActions   = array("reboot" => "", "update" => "", "localboot" => "", "reinstall" => "", "rescan" => "",
-                            "wake" => "", "memcheck" => "", "sysinfo" => "");
+                            "wakeup" => "", "memcheck" => "", "sysinfo" => "");
 
   var $fai_activated  =FALSE;
   var $view_logged = FALSE;
@@ -51,6 +53,20 @@ class servgeneric extends plugin
   var $currently_installing = FALSE;
   var $currently_installing_warned = FALSE;
 
+  var $kerberos_key_service = NULL;
+  var $baseSelector;
+
+  var $mapActions   = array("reboot"          => "",
+                            "instant_update"  => "softupdate",
+                            "localboot"       => "localboot",
+                            "update"          => "sceduledupdate",
+                            "reinstall"       => "install",
+                            "rescan"          => "",
+                            "wakeup"            => "",
+                            "memcheck"        => "memcheck",
+                            "sysinfo"         => "sysinfo");
+
+
   function servgeneric (&$config, $dn= NULL, $parent= NULL)
   {
     /* Check if FAI is activated */
@@ -62,6 +78,7 @@ class servgeneric extends plugin
 
     plugin::plugin ($config, $dn, $parent);
 
+    /* Initialize */
     $this->ui = get_userinfo();
     $this->modes["active"]= _("Activated");
     $this->modes["locked"]= _("Locked");
@@ -72,14 +89,20 @@ class servgeneric extends plugin
       $this->base= dn2base($ui->dn);
       $this->cn= "";
     } else {
-      $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_ou("serverou"))."/", "", $this->dn);
+      $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("serverRDN"), '/')."/i", "", $this->dn);
     }
     $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
     $this->netConfigDNS->set_acl_category("server");
     $this->netConfigDNS->set_acl_base($this->base);
+    $this->netConfigDNS->MACisMust =TRUE;
+
+    /* Initialize kerberos host key plugin */
+    if(class_available("krbHostKeys")){
+      $this->kerberos_key_service = new krbHostKeys($this->config,$this);
+    }
 
     /* Check if this host is currently in installation process*/
-    if(class_available("gosaSupportDaemon") && class_available("DaemonEvent")){
+    if($this->dn != "new" && class_available("gosaSupportDaemon") && class_available("DaemonEvent")){
       $o = new gosaSupportDaemon();
       $e_types = DaemonEvent::get_event_types(USER_EVENT | SYSTEM_EVENT | HIDDEN_EVENT);
       $evts = $o->get_entries_by_mac(array($this->netConfigDNS->macAddress));
@@ -92,7 +115,15 @@ class servgeneric extends plugin
     }
        
     /* Save dn for later references */
-    $this->orig_dn= $this->dn;
+    $this->orig_dn   = $this->dn;
+    $this->orig_cn   = $this->cn;
+    $this->orig_base = $this->base;
+
+    /* Instanciate base selector */
+    $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
+    $this->baseSelector->setSubmitButton(false);
+    $this->baseSelector->setHeight(300);
+    $this->baseSelector->update(true);
   }
 
 
@@ -122,7 +153,7 @@ class servgeneric extends plugin
 
     /* Do we represent a valid server? */
     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(_("server"))."</b>"; 
       return($display);
     }
@@ -149,38 +180,9 @@ class servgeneric extends plugin
       }
     }
 
-    /* Base select dialog */
-    $once = true;
-    foreach($_POST as $name => $value){
-      if(preg_match("/^chooseBase/",$name) && $once ){
-        $once = false;
-        $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
-        $this->dialog->setCurrentBase($this->base);
-      }
-    }
-
-    /* Dialog handling */
-    if(is_object($this->dialog)){
-      /* Must be called before save_object */
-      $this->dialog->save_object();
-
-      if($this->dialog->isClosed()){
-        $this->dialog = false;
-      }elseif($this->dialog->isSelected()){
-  
-        /* Only accept allowed bases */
-        $tmp = $this->get_allowed_bases();
-        if($tmp[$this->dialog->isSelected()]){
-          $this->base = $this->dialog->isSelected();
-        }
-        $this->dialog= false;
-      }else{
-        return($this->dialog->execute());
-      }
-    }
-
     /* Fill templating stuff */
     $smarty= get_smarty();
+    $smarty->assign("usePrototype", "true");
 
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translated){
@@ -188,7 +190,7 @@ class servgeneric extends plugin
     }
 
     /* Assign base ACL */
-    $smarty->assign("bases"   , $this->get_allowed_bases());
+    $smarty->assign("base", $this->baseSelector->render());
 
     /* Assign attributes */
     foreach ($this->attributes as $attr){
@@ -196,7 +198,6 @@ class servgeneric extends plugin
     }
 
     $smarty->assign("staticAddress", "");
-    $smarty->assign("base_select", $this->base);
 
     /* Assign status */
     if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){
@@ -208,7 +209,7 @@ class servgeneric extends plugin
                                        "localboot" => _("Force localboot"),
                                        "sysinfo"  => _("System analysis")));
     } else {
-      $smarty->assign("actions", array("wake" => _("Wake up"),
+      $smarty->assign("actions", array("wakeup" => _("Wake up"),
                                        "reinstall" => _("Reinstall"),
                                        "update" => _("System update"),
                                        "memcheck" => _("Memory test"),
@@ -227,6 +228,11 @@ class servgeneric extends plugin
     $smarty->assign("modes", $this->modes);
     $smarty->assign("currently_installing", $this->currently_installing);
 
+    $smarty->assign("host_key","");
+    if(is_object($this->kerberos_key_service)){
+      $smarty->assign("host_key",$this->kerberos_key_service->execute_by_prefix("host/"));
+    }
+
     return($smarty->fetch (get_template_path('server.tpl', TRUE)));
   }
 
@@ -237,10 +243,17 @@ class servgeneric extends plugin
       return;
     }
 
+    /* Remove kerberos key dependencies too */
+    if(is_object($this->kerberos_key_service)){
+      $this->kerberos_key_service->remove_from_parent_by_prefix("host/");
+    }
+
     $this->netConfigDNS->remove_from_parent();
     $ldap= $this->config->get_ldap_link();
     $ldap->rmdir($this->dn);
 
+    update_accessTo($this->orig_cn,"");
+
     new log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
     if (!$ldap->success()){
@@ -275,15 +288,22 @@ class servgeneric extends plugin
     plugin::save_object();
     $this->netConfigDNS->save_object();
 
-    /* Get base selection */
-    $tmp = $this->get_allowed_bases();
-    if(isset($_POST['base'])){
-      if($tmp[$_POST['base']]){
-        $this->base = $_POST['base'];
-      }else{
-        $this->base = $base_tmp;
+    /* Refresh base */
+    if ($this->acl_is_moveable($this->base)){
+      if (!$this->baseSelector->update()) {
+        msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
+      }
+      if ($this->base != $this->baseSelector->getBase()) {
+        $this->base= $this->baseSelector->getBase();
+        $this->is_modified= TRUE;
       }
     }
+
+
+    /* Hanle kerberos host key plugin */
+    if(is_object($this->kerberos_key_service)){
+      $this->kerberos_key_service->save_object_by_prefix("host/");
+    }
   }
 
 
@@ -293,7 +313,7 @@ class servgeneric extends plugin
     /* Call common method to give check the hook */
     $message= plugin::check();
     $message= array_merge($message, $this->netConfigDNS->check());
-    $this->dn= "cn=".$this->cn.",".get_ou('serverou').$this->base;
+    $this->dn= "cn=".$this->cn.",".get_ou('serverRDN').$this->base;
 
     /* must: cn */
     if ($this->cn == ""){
@@ -312,7 +332,7 @@ class servgeneric extends plugin
       if ($ldap->count() != 0){
         while ($attrs= $ldap->fetch()){
           if ($attrs['dn'] != $this->orig_dn){
-            if(!preg_match("/cn=dhcp,/",$attrs['dn']) && !preg_match("/,".get_ou('incomingou')."/",$attrs['dn']) && preg_match("/,".get_ou('serverou')."/",$attrs['dn'])){
+            if(!preg_match("/cn=dhcp,/",$attrs['dn']) && !preg_match("/,".preg_quote(get_ou('systemIncomingRDN'), '/')."/i",$attrs['dn']) && preg_match("/,".preg_quote(get_ou('serverRDN'), '/')."/i",$attrs['dn'])){
               $message[]= msgPool::duplicated(_("Server name"));
               break;
             }
@@ -322,9 +342,22 @@ class servgeneric extends plugin
     }
 
     /* Warn the user, that this host is currently installing */
-    if($this->currently_installing && !$this->currently_installing_warned && !preg_match("/".normalizePreg(get_ou("incomingou"))."/",$this->orig_dn)){
+    if($this->currently_installing && !$this->currently_installing_warned && !preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/i",$this->orig_dn)){
+
+      /* Force aborting without message dialog */
+      $message[] = "";
       $this->currently_installing_warned = TRUE;
-      $message[] = _("This host is currently installing, if you really want to save it, save again.");
+      msg_dialog::display(_("Software deployment"), 
+          _("This host is currently installing, if you really want to save it, press 'OK'."),
+          CONFIRM_DIALOG);
+    }
+
+    /* 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);
@@ -370,6 +403,11 @@ class servgeneric extends plugin
       $ldap->modify ($this->attrs); 
       new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
+      /* Update all accessTo/trust dependencies */
+      if($this->orig_cn != $this->cn){
+        update_accessTo($this->orig_cn,$this->cn);
+      }
+
       $mode= "modify";
     }
     if (!$ldap->success()){
@@ -452,13 +490,22 @@ class servgeneric extends plugin
           "plCategory"    => array("server" => array("description"  => _("Server"),
                                                      "objectClass"  => "goServer")),
           "plProvidedAcls"=> array(
-            "cn"           => _("Name"),
-            "description"  => _("Description"),
-            "gotoMode"     => _("Goto mode"),
-            "base"         => _("Base"),
-            "FAIstate"     => _("Action flag"))
+            "cn"            => _("Name"),
+            "description"   => _("Description"),
+            "base"          => _("Base"),
+
+            "gotoMode"      => _("Goto mode"),
+            "userPassword"=> _("Root password"),
+            "FAIstate"      => _("Action flag"))
           ));
   }
+
+
+  function is_modal_dialog()
+  {
+    return((isset($this->dialog) && $this->dialog) || (isset($this->netConfigDNS->dialog) && $this->netConfigDNS->dialog));
+  }
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: