Code

Fixed wrong existance check
[gosa.git] / gosa-plugins / systems / admin / systems / class_serverService.inc
index 338052b7e3b4a6e6b8b681d64ace29ab7cb4c64e..4bd58ed1894d29ca7ff73227e0b95b6f0595615e 100644 (file)
@@ -1,4 +1,24 @@
 <?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
+ */
 
 define("START_SERVICE",1);
 define("STOP_SERVICE",2);
@@ -12,11 +32,6 @@ define("ALL_SERVICES",100);
 
 class ServerService extends plugin
 {
-  /* CLI vars */
-  var $cli_summary      = "Manage server services";
-  var $cli_description  = "Managing services by adding,removing and configuring services. Allows to start/stop used services.";
-  var $cli_parameters   = array("config"=>"Config object" , "dn"=>"Object dn");
-
   /* attribute list for save action */
   var $ignore_account   = TRUE;
   var $attributes       = array();
@@ -31,21 +46,40 @@ class ServerService extends plugin
   var $backup           = NULL;
   var $acl              ;
   var $cn;
+  var $parent           ;
 
-  function ServerService (&$config, $dn)
+  function ServerService (&$config, $dn,$parent)
   {
     plugin::plugin($config);
+    $this->parent = $parent;
     $this->dn= $dn;
+
+    /* Adapt parent attributes */
+    if(isset($this->parent->attrs)){
+      $this->attrs = $this->parent->attrs;
+    }
+
     foreach ($config->data['TABS']['SERVERSERVICE'] as $plug){
-      $name= $plug['CLASS'];
-      $this->plugin_names[]= $name;
-      $this->plugins[$name]= new $name($config, $dn);
-      /* Capture all service objectClases, necessary for acl handling */ 
-      if(isset($this->plugins[$name]->objectclasses)){
-        foreach($this->plugins[$name]->objectclasses as $oc){
-          $this->objectclasses[] = $oc;
+
+      if(class_available($plug['CLASS'])){
+
+        $name= $plug['CLASS'];
+        $this->plugin_names[]= $name;
+        $this->plugins[$name]= new $name($config, $dn, $this);
+
+        /* Initialize kerberos key support */ 
+        if(isset($this->plugins[$name]->krb_service_prefix) && !empty($this->plugins[$name]->krb_service_prefix)){
+          $this->plugins[$name]->krb_host_key = &$this->parent->kerberos_key_service;
         }
+
+        /* Capture all service objectClases, necessary for acl handling */ 
+        if(isset($this->plugins[$name]->objectclasses)){
+          foreach($this->plugins[$name]->objectclasses as $oc){
+            $this->objectclasses[] = $oc;
+          }
+        }
+      }else{
+        #trigger_error("Service class missing: ".$plug['CLASS']);
       }
     }
     $this->divList = new divListSystemService($config,$this);
@@ -134,7 +168,7 @@ class ServerService extends plugin
     if($s_action == "RemoveSingleService"){
 
       /* Create resetted obj */
-      $new_obj = new $s_entry($this->config,$this->dn);
+      $new_obj = new $s_entry($this->config,$this->dn, $this);
       $new_obj -> set_acl_base($this->acl_base);
       $new_obj -> set_acl_category(preg_replace("/\/$/","",$this->acl_category));
       $tmp     = $new_obj->getListEntry();
@@ -149,7 +183,7 @@ class ServerService extends plugin
           $this->plugins[$s_entry] = $new_obj;
           $this->plugins[$s_entry]->is_account = false;
         }else{
-          print_red($str);
+          msg_dialog::display(_("Error"), $str, ERROR_DIALOG);
         }
       }
     }
@@ -158,9 +192,11 @@ class ServerService extends plugin
     /* Edit a service and make a backup from all attributes, 
        to be able to restore old values after aborting dialog */ 
     if($s_action == "EditSingleService"){
-      $this->backup   = get_object_vars($this->plugins[$s_entry]);
-      $this->dialog   = $this->plugins[$s_entry];
-      $this->current  = $s_entry;
+      if($this->plugins[$s_entry]->acl_is_readable("")){
+        $this->backup   = get_object_vars($this->plugins[$s_entry]);
+        $this->dialog   = $this->plugins[$s_entry];
+        $this->current  = $s_entry;
+      }
     }
 
    
@@ -176,7 +212,7 @@ class ServerService extends plugin
        Restore vars with values before editing */
     if(isset($_POST['CancelService']) && !empty($this->current)){
       if($this->backup == NULL){
-        $this->plugins[$this->current] = new $this->current($this->config,$this->dn);
+        $this->plugins[$this->current] = new $this->current($this->config,$this->dn,$this);
         $this->plugins[$this->current]-> set_acl_base($this->acl_base);
         $this->plugins[$this->current]-> set_acl_category(preg_replace("/\/$/","",$this->acl_category));
 
@@ -193,11 +229,11 @@ class ServerService extends plugin
 
     /* Abort dialog */
     if(isset($_POST['SaveService']) && is_object($this->dialog)){
-      $this->dialog->save_object();
+#      $this->dialog->save_object();
       $msgs = $this->dialog->check();
       if(count($msgs)){
         foreach($msgs as $msg){
-          print_red($msg);
+          msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
         }
       }else{
         $this->plugins[$this->current] = $this->dialog;
@@ -223,8 +259,12 @@ class ServerService extends plugin
 
     /* There is currently a subdialog open, display this dialog */
     if(is_object($this->dialog)){
-      $this->dialog->save_object();
-      return($this->dialog->execute());
+      $add ="";
+      if(isset($this->dialog->krb_host_key) && $this->dialog->krb_host_key instanceof krbHostKeys){
+        $add = $this->dialog->krb_host_key->save_object_by_prefix($this->dialog->krb_service_prefix);
+        $add = $this->dialog->krb_host_key->execute_by_prefix($this->dialog->krb_service_prefix,TRUE);
+      }
+      return($add.$this->dialog->execute());
     }
 
 
@@ -308,7 +348,7 @@ class ServerService extends plugin
   {
     /* Skip if this is a new server */
     if($this->dn == "new"){
-      print_red(_("Can't set status while this server is not saved."));
+      msg_dialog::display(_("Information"), _("Cannot update service status until it has been saved!"), INFO_DIALOG);
       return;
     }
 
@@ -320,7 +360,7 @@ class ServerService extends plugin
     }elseif($method == RESTART_SERVICE){
       $action = SERVICE_RESTARTED;
     }else{
-      print_red(sprintf(_("The specified method '%s' can't executed for services."),$action));
+      msg_dialog::display(_("Error"), _("Cannot update service status!"), ERROR_DIALOG);
       return;
     }
     
@@ -342,7 +382,7 @@ class ServerService extends plugin
         $tmp = $this->plugins[$name]->getListEntry();
 
         /* Check if given action is allowed for this service */
-        if($tmp[$map[$action]]){
+        if($tmp[$map[$action]] && !empty($this->plugins[$name]->StatusFlag)){
           if($this->plugins[$name]->initially_was_account && $this->plugins[$name]->is_account){
             $this->plugins[$name]->setStatus($action);
           }
@@ -388,6 +428,9 @@ class ServerService extends plugin
         }
       }
       if($this->plugins[$name]->initially_was_account){
+        if(isset($this->plugins[$name]->krb_host_key) && $this->plugins[$name]->krb_host_key instanceof krbHostKeys){
+          $this->plugins[$name]->krb_host_key->remove_from_parent_by_prefix($this->plugins[$name]->krb_service_prefix);
+        }
         $this->plugins[$name]->remove_from_parent();
       }
     }