Code

Added fix to avoid undefined index
[gosa.git] / plugins / admin / systems / class_servGeneric.inc
index bd66de5c9fc7ee3371c820be14d4576ad3d3882f..1a4cc14f29f5293127fa1e40d06d0c3306833770 100644 (file)
@@ -17,17 +17,26 @@ class servgeneric extends plugin
   var $l= "";
   var $description= "";
   var $orig_dn= "";
+  var $didAction= FALSE;
 
   /* attribute list for save action */
-  var $attributes= array("cn", "description");
-  var $objectclasses= array("top", "goServer");
+  var $attributes= array("cn", "description","gotoMode");
+  var $objectclasses= array("top", "GOhard", "goServer");
+
+  var $gotoMode= "locked";
 
   var $netConfigDNS;
+  var $modes = array();
 
   function servgeneric ($config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
 
+    $this->modes["active"]= _("Activated");
+    $this->modes["locked"]= _("Locked");
+    $this->modes["memcheck"]= _("Memory test");
+    $this->modes["sysinfo"]= _("System analysis");
+
     /* Set base */
     if ($this->dn == "new"){
       $ui= get_userinfo();
@@ -43,8 +52,8 @@ class servgeneric extends plugin
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
     /* Do we represent a valid server? */
     if (!$this->is_account && $this->parent == NULL){
@@ -55,42 +64,16 @@ class servgeneric extends plugin
 
     /* Check for action */
     if (isset($_POST['action'])){
-      switch($_POST['action']){
-        case 'wake':
-          $cmd= search_config($this->config->data['TABS'], "servgeneric", "WAKECMD");
-          if ($cmd == ""){
-            print_red(_("No WAKECMD definition found in your gosa.conf"));
-          } else {
-            exec ($cmd." ".$this->netConfigDNS->macAddress, $dummy, $retval);
-            if ($retval != 0){
-              print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
-            }
-          }
-          break;
-
-        case 'reboot':
-          $cmd= search_config($this->config->data['TABS'], "servgeneric", "REBOOTCMD");
-          if ($cmd == ""){
-            print_red(_("No REBOOTCMD definition found in your gosa.conf"));
-          } else {
-            exec ($cmd." ".$this->cn, $dummy, $retval);
-            if ($retval != 0){
-              print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
-            }
-          }
-          break;
-
-        case 'halt':
-          $cmd= search_config($this->config->data['TABS'], "servgeneric", "HALTCMD");
-          if ($cmd == ""){
-            print_red(_("No HALTCMD definition found in your gosa.conf"));
-          } else {
-            exec ($cmd." ".$this->cn, $dummy, $retval);
-            if ($retval != 0){
-              print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
-            }
-          }
-          break;
+      $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
+      if ($cmd == ""){
+        print_red(_("No ACTIONCMD definition found in your gosa.conf"));
+      } else {
+        exec ($cmd." ".$this->netConfigDNS->macAddress." ".escapeshellarg($_POST['saction']), $dummy, $retval);
+        if ($retval != 0){
+          print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
+        } else {
+          $this->didAction= TRUE;
+        }
       }
     }
 
@@ -128,6 +111,8 @@ class servgeneric extends plugin
       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
       $smarty->assign("$attr", $this->$attr);
     }
+    $smarty->assign("baseACL", chkacl($this->acl, "base"));
+
     $smarty->assign("staticAddress", "");
     $smarty->assign("base_select", $this->base);
 
@@ -137,14 +122,20 @@ class servgeneric extends plugin
 
     /* Offline */
     if ($retval == 0){
-      $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot")));
+      $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
+                                       "instant_update" => _("Instant update"),
+                                       "update" => _("Scheduled update"),
+                                       "reinstall" => _("Reinstall"),
+                                       "rescan" => _("Rescan hardware")));
     } else {
-      $smarty->assign("actions", array("wake" => _("Wake up")));
+      $smarty->assign("actions", array("wake" => _("Wake up"),
+                                       "reinstall" => _("Reinstall"),
+                                       "update" => _("Scheduled update")));
     }
 
-
     /* Show main page */
     $smarty->assign("netconfig", $this->netConfigDNS->execute());
+    $smarty->assign("modes", $this->modes);
 
     return($smarty->fetch (get_template_path('server.tpl', TRUE)));
   }
@@ -154,7 +145,7 @@ class servgeneric extends plugin
     $this->netConfigDNS->remove_from_parent();
     $ldap= $this->config->get_ldap_link();
     $ldap->rmdir($this->dn);
-    show_ldap_error($ldap->get_error());
+    show_ldap_error($ldap->get_error(), _("Removing server failed"));
 
     /* Delete references to object groups */
     $ldap->cd ($this->config->current['BASE']);
@@ -164,7 +155,7 @@ class servgeneric extends plugin
       unset($og->member[$this->dn]);
       $og->save ();
     }
-    $this->handle_post_events("remove");
+    $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress));
   }
 
 
@@ -262,16 +253,18 @@ class servgeneric extends plugin
   
       $ldap->cd($this->dn);
       $this->cleanup();
-$ldap->modify ($this->attrs); 
+      $ldap->modify ($this->attrs); 
 
       $mode= "modify";
     }
+    show_ldap_error($ldap->get_error(), _("Saving server failed"));
     $this->netConfigDNS->cn = $this->cn;
     $this->netConfigDNS->save($this->dn);
-    show_ldap_error($ldap->get_error());
 
     /* Optionally execute a command after we're done */
-    $this->handle_post_events($mode);
+    if(!$this->didAction){
+      $this->handle_post_events($mode);
+    }
   }
 
 }