Code

Added missing class var.
[gosa.git] / gosa-plugins / systems / admin / systems / class_servGeneric.inc
index 94a4d67c9a2793b325338af2ef012e3ca43189e9..dd5a5e2c2070d7cf4fdc5b47126c171b5ac237ae 100644 (file)
@@ -1,12 +1,27 @@
 <?php
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id$$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 class servgeneric extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Manage server base objects";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* Generic terminal attributes */
   var $ignore_account= TRUE;
   var $interfaces= array();
@@ -17,7 +32,7 @@ class servgeneric extends plugin
   var $l= "";
   var $description= "";
   var $orig_dn= "";
-  var $didAction= FALSE;
+  var $orig_cn= "";
 
   /* attribute list for save action */
   var $attributes= array("cn", "description","gotoMode");
@@ -28,19 +43,15 @@ class servgeneric extends plugin
   var $netConfigDNS;
   var $modes = array();
   var $ui   ;
-  var $mapActions   = array("reboot"          => "",
-                            "instant_update"  => "softupdate",
-                            "localboot"       => "localboot",
-                            "update"          => "sceduledupdate",
-                            "reinstall"       => "install",
-                            "rescan"          => "",
-                            "wake"            => "",
-                            "memcheck"        => "memcheck",
-                            "sysinfo"         => "sysinfo");
+  var $validActions   = array("reboot" => "", "update" => "", "localboot" => "", "reinstall" => "", "rescan" => "",
+                            "wake" => "", "memcheck" => "", "sysinfo" => "");
 
   var $fai_activated  =FALSE;
   var $view_logged = FALSE;
 
+  var $currently_installing = FALSE;
+  var $currently_installing_warned = FALSE;
+
   function servgeneric (&$config, $dn= NULL, $parent= NULL)
   {
     /* Check if FAI is activated */
@@ -62,14 +73,28 @@ class servgeneric extends plugin
       $this->base= dn2base($ui->dn);
       $this->cn= "";
     } else {
-      $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
+      $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_ou("serverou"))."/", "", $this->dn);
     }
     $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
     $this->netConfigDNS->set_acl_category("server");
     $this->netConfigDNS->set_acl_base($this->base);
+
+    /* Check if this host is currently in installation process*/
+    if(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));
+      foreach($evts as $evt){
+        if(isset($e_types['QUEUED'][$evt['HEADERTAG']]) && $evt['STATUS'] == "processing" && 
+            $e_types['QUEUED'][$evt['HEADERTAG']] == "DaemonEvent_reinstall"){
+          $this->currently_installing =TRUE;
+        }
+      }
+    }
        
     /* Save dn for later references */
     $this->orig_dn= $this->dn;
+    $this->orig_cn= $this->cn;
   }
 
 
@@ -99,54 +124,30 @@ 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>".
-        _("This 'dn' has no server features.")."</b>";
+      $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
+        msgPool::noValidExtension(_("server"))."</b>"; 
       return($display);
     }
 
-    /* Check for action */
     if ((isset($_POST['action'])) && ($this->acl_is_writeable("FAIstate")) && isset($this->mapActions[$_POST['saction']]) ){
-        $method= "gosa";
-        $action= $_POST['saction'];
-        if ($action == "reinstall" || $action == "softupdate"){
-                $method= "job";
-        }
-        gosaSupportDaemon::send("${method}_trigger_action_".$action, $this->netConfigDNS->macAddress, array("macAddress" => $this->netConfigDNS->macAddress));
-
-      $this->didAction= TRUE;
-
-      if ($_POST['saction'] != "wake") {
-
-          /* Set FAIstate */
-          if($this->fai_activated && $this->dn != "new"){
-            $ldap = $this->config->get_ldap_link();
-            $ldap->cd($this->config->current['BASE']);
-            $ldap->cat($this->dn,array("objectClass"));
-            $res = $ldap->fetch();
-
-            $attrs = array();
-            $attrs['FAIstate'] = "";
-            if(isset($this->mapActions[$_POST['saction']])){
-              $attrs['FAIstate'] = $this->mapActions[$_POST ['saction']];
-            }
-
-            for($i = 0; $i < $res['objectClass']['count'] ; $i ++){
-              $attrs['objectClass'][] = $res['objectClass'][$i];
-            }
-
-            if(($attrs['FAIstate'] != "") && (!in_array("FAIobject",$attrs['objectClass']))){
-              $attrs['objectClass'][] = "FAIobject";
-            }
-
-            if($attrs['FAIstate'] == ""){
-             #FIXME we should check if FAIobject is used anymore
-              $attrs['FAIstate'] = array();
-            }
-
-            $ldap->cd($this->dn);
-            $ldap->modify($attrs);
+      $action = $_POST['saction'];
+      
+      /* Check if we have an DaemonEvent for this action */
+      if(class_available("DaemonEvent")){
+        $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
+        if(isset($events['TRIGGERED']["DaemonEvent_".$action])){
+          $evt = $events['TRIGGERED']["DaemonEvent_".$action];
+          $tmp = new $evt['CLASS_NAME']($this->config);
+          $tmp->add_targets(array($this->netConfigDNS->macAddress));
+          $tmp->set_type(TRIGGERED_EVENT);
+          $o_queue = new gosaSupportDaemon();
+          if(!$o_queue->append($tmp)){
+            msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
           }
-         show_ldap_error($ldap->get_error(), sprintf(_("Saving of system server/generic (FAIstate) with dn '%s' failed."),$this->dn)); 
+        }
+      }else{
+        msg_dialog::display(_("Event error"),
+                    sprintf(_("Event '%s' is not available!"),$action),ERROR_DIALOG);
       }
     }
 
@@ -200,14 +201,9 @@ class servgeneric extends plugin
     $smarty->assign("base_select", $this->base);
 
     /* Assign status */
-    $query= "fping -q -r 1 -t 500 ".$this->cn;
-    exec ($query, $dummy, $retval);
-
-    /* Offline */
-    if ($retval == 0){
+    if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){
       $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
-                                       "instant_update" => _("Instant update"),
-                                       "update" => _("Scheduled update"),
+                                       "update" => _("System update"),
                                        "reinstall" => _("Reinstall"),
                                        "rescan" => _("Rescan hardware"),
                                        "memcheck" => _("Memory test"),
@@ -216,7 +212,7 @@ class servgeneric extends plugin
     } else {
       $smarty->assign("actions", array("wake" => _("Wake up"),
                                        "reinstall" => _("Reinstall"),
-                                       "update" => _("Scheduled update"),
+                                       "update" => _("System update"),
                                        "memcheck" => _("Memory test"),
                                        "localboot" => _("Force localboot"),
                                        "sysinfo"  => _("System analysis")));
@@ -231,6 +227,7 @@ class servgeneric extends plugin
     }
     $smarty->assign("netconfig", $str);
     $smarty->assign("modes", $this->modes);
+    $smarty->assign("currently_installing", $this->currently_installing);
 
     return($smarty->fetch (get_template_path('server.tpl', TRUE)));
   }
@@ -246,9 +243,13 @@ class servgeneric extends plugin
     $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());
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of system server/generic with dn '%s' failed."),$this->dn)); 
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
+    }
 
     /* Delete references to object groups */
     $ldap->cd ($this->config->current['BASE']);
@@ -258,6 +259,13 @@ class servgeneric extends plugin
       unset($og->member[$this->dn]);
       $og->save ();
     }
+
+    /* Clean queue form entries with this mac 
+     */
+    if(class_available("gosaSupportDaemon") && tests::is_mac($this->netConfigDNS->orig_macAddress)){
+      $q = new gosaSupportDaemon();
+      $q->clean_queue_from_mac($this->netConfigDNS->orig_macAddress);
+    }
     $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
   }
 
@@ -293,12 +301,12 @@ class servgeneric extends plugin
 
     /* must: cn */
     if ($this->cn == ""){
-      $message[]= _("The required field 'Server name' is not set.");
+      msgPool::required(_("Server name"));
     }
     
     /* Check if given name is a valid host/dns name */
     if(!tests::is_dns_name($this->cn)){
-      $message[] = _("Please specify a valid name for this object.");
+      $message[]= msgPool::invalid(_("Server name"), $this->cn, "/[a-z0-9\.\-]/i");
     }
 
     if ($this->orig_dn != $this->dn){
@@ -309,7 +317,7 @@ class servgeneric extends plugin
         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'])){
-              $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
+              $message[]= msgPool::duplicated(_("Server name"));
               break;
             }
           }
@@ -317,6 +325,17 @@ 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)){
+
+      /* Force aborting without message dialog */
+      $message[] = "";
+      $this->currently_installing_warned = TRUE;
+      msg_dialog::display(_("Software deployment"), 
+          _("This host is currently installing, if you really want to save it, press 'OK'."),
+          CONFIRM_DIALOG);
+    }
+
     return ($message);
   }
 
@@ -354,38 +373,43 @@ class servgeneric extends plugin
       new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
       $mode= "add";
     } else {
-   
-      /* cn is not case sensitive for ldap, but for php it is!! */ 
-      if($this->config->current['DNMODE'] == "cn"){
-        if (strtolower($this->orig_dn) != (strtolower($this->dn))){
-          $this->recursive_move($this->orig_dn, $this->dn);
-          plugin::save();
-        }
-      }else{
-        if ($this->orig_dn != $this->dn){
-          $this->recursive_move($this->orig_dn, $this->dn);
-          plugin::save();
-        }
-      }
   
       $ldap->cd($this->dn);
       $this->cleanup();
       $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";
     }
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of system server/generic 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()));
+    }
     $this->netConfigDNS->cn = $this->cn;
     $this->netConfigDNS->save();
 
     /* Optionally execute a command after we're done */
-    if(!$this->didAction){
-      $this->handle_post_events($mode,array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
-    }
+    $this->handle_post_events($mode,array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
 
     if ($activate){
-      gosaSupportDaemon::send("gosa_set_activated_for_installation", $this->netConfigDNS->ipHostNumber);
+
+      /* Send installation activation 
+       */
+      $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
+      $o_queue = new gosaSupportDaemon();
+      if(isset($events['TRIGGERED']['DaemonEvent_installation_activation'])){
+        $evt = $events['TRIGGERED']['DaemonEvent_installation_activation'];
+        $tmp = new $evt['CLASS_NAME']($this->config);
+        $tmp->set_type(TRIGGERED_EVENT);
+        $tmp->add_targets(array($this->netConfigDNS->macAddress));
+        if(!$o_queue->append($tmp)){
+          msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
+        }
+      }
     }
 
   }