Code

<h2> => </h3>
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_terminalStartup.inc
index e8d18072655d02a6dda9cb06184c32a3f01b8e85..15cd3bdfe762397aeb7844867d1c71e0a2bd3694 100644 (file)
@@ -3,9 +3,9 @@ class termstartup extends plugin
 {
   /* Generic terminal attributes */
   var $goLdapServerList= array();
-  var $gotoBootKernel= "default";
+  var $gotoBootKernel= "default-inherited";
   var $gotoKernelParameters= "";
-  var $gotoLdapServer= "";
+  var $gotoLdapServer= "default-inherited";
   var $gotoModules= array();
   var $gotoTerminalPath= "";
   var $gotoBootKernels= array();
@@ -26,9 +26,10 @@ class termstartup extends plugin
   var $attributes= array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters","gotoModules");
   var $objectclasses= array("GOhard");
   var $view_logged = FALSE;
+  var $member_of_ogroup = FALSE;
+  var $o_group_dn       = "";
 
   /* Helper */
-  var $customParameters= "";
   var $orig_dn= "";
   var $ignore_account= TRUE;
 
@@ -52,18 +53,12 @@ class termstartup extends plugin
       $this->$val= array_unique($this->$val);
     }
 
-    if (preg_match("/ o /", $this->gotoKernelParameters)){
-      $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
-    } else {
-      $this->customParameters= "";
-    }
-
     /* Prepare Shares */
     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
       unset($this->attrs['gotoShare']['count']);
       foreach($this->attrs['gotoShare'] as $share){
         $tmp = $tmp2 = array();
-        $tmp = split("\|",$share);
+        $tmp = explode("|",$share);
         $tmp2['server']      =$tmp[0];
         $tmp2['name']        =$tmp[1];
         $tmp2['mountPoint']  =$tmp[2];
@@ -76,39 +71,21 @@ class termstartup extends plugin
 
     $this->orig_dn= $this->dn;
 
-    /* Get list of boot kernels */
-    if (isset($this->config->data['TABS'])){
-      $command= $this->config->search(get_class($this), "KERNELS",array('tabs'));
-
-      if (!check_command($command)){
-        $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
-            get_class($this));
-      } else {
-        $fh= popen($command, "r");
-        while (!feof($fh)) {
-          $buffer= trim(fgets($fh, 256));
-          
-          if(!empty($buffer)){
-          
-            $name=$value = $buffer;
-
-            if(preg_match("/:/",$buffer)){
-              $name = preg_replace("/:.*$/","",$buffer);
-              $value= preg_replace("/^.*:/","",$buffer);
-              $this->gotoBootKernels[$name]= $name.":".$value;
-            }else{
-              $this->gotoBootKernels[$name]= $value;
-            }
-          }
+    /* Creating a list of valid Mirrors
+     * none will not be saved to ldap.
+     */
+    $ldap   = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ui = get_userinfo();
+    foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){
+      if($ui->get_category_permissions($data['dn'],"server",TRUE)){
+        for($i = 0; $i < $data['goLdapBase']['count']; $i ++){
+          $name = $data["cn"][0].":".$data["goLdapBase"][$i];
+          $this->gotoLdapServerList[]= $name;
         }
-        pclose($fh);
       }
-
-    }
-    
-    foreach($this->config->data['SERVERS']['LDAP'] as $server) {
-      $this->gotoLdapServerList[]= $server;
     }
+
     if(isset($this->attrs['gotoLdapServer'])){
       unset($this->attrs['gotoLdapServer']['count']);
       sort($this->attrs['gotoLdapServer']);
@@ -116,17 +93,17 @@ class termstartup extends plugin
         $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
       }
     }
-    if(!count($this->gotoLdapServers)){
-      $this->gotoLdap_inherit = TRUE;
-    }
+    natcasesort($this->gotoLdapServerList);
 
     /* Load hardware list */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
+    $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))");
     if ($ldap->count() == 1){
       $map= array("gotoLdapServer","gotoBootKernel");
       $attrs= $ldap->fetch();
+      $this->member_of_ogroup = TRUE;
+      $this->o_group_dn = $attrs['dn'];
 
       foreach ($map as $name){
         if (!isset($attrs[$name][0])){
@@ -134,7 +111,10 @@ class termstartup extends plugin
         }
         switch ($name){
           case 'gotoBootKernel':
-            $this->gotoBootKernels["default"] = "["._("inherited")."]"; 
+                 /* Handle inheritance value "default" */
+                 if ($this->member_of_ogroup){
+                         $this->gotoBootKernels["default-inherited"]= _("inherited")." [".$attrs['gotoBootKernel'][0]."]";
+                 }
           break;
           case 'gotoLdapServer':
             $this->goLdapServerList= array_merge(array('default-inherit' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
@@ -142,6 +122,41 @@ class termstartup extends plugin
         }
       }
     }
+
+    if(!count($this->gotoLdapServers) && $this->member_of_ogroup){
+      $this->gotoLdap_inherit = TRUE;
+    }
+
+    /* Get list of boot kernels */
+    if (isset($this->config->data['TABS'])){
+      $command= $this->config->search(get_class($this), "systemKernelsHook",array('tabs'));
+
+      if (!check_command($command)){
+        $message[]= sprintf(_("Command '%s', specified as systemKernelsHook for plugin '%s' doesn't seem to exist."), $command,
+            get_class($this));
+      } else {
+        $fh= popen($command, "r");
+        while (!feof($fh)) {
+          $buffer= trim(fgets($fh, 256));
+          
+          if(!empty($buffer)){
+          
+            $name=$value = $buffer;
+
+            if(preg_match("/:/",$buffer)){
+              $name = preg_replace("/:.*$/","",$buffer);
+              $value= preg_replace("/^.*:/","",$buffer);
+              $this->gotoBootKernels[$name]= $name.":".$value;
+            }else{
+              $this->gotoBootKernels[$name]= $value;
+            }
+          }
+        }
+        pclose($fh);
+      }
+
+    }
+    
   }
 
   function execute()
@@ -161,7 +176,7 @@ class termstartup extends plugin
 
     /* Do we represent a valid terminal? */
     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(_("terminal"))."</b>";
       return ($display);
     }
@@ -189,8 +204,9 @@ class termstartup extends plugin
       $smarty->assign($name."ACL",$this->getacl($name));
     }
 
+    $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
 
-       /* In this section server shares will be defined
+    /* In this section server shares will be defined
      * A user can select one of the given shares and a mount point
      *  and attach this combination to his setup.
      */
@@ -204,8 +220,8 @@ class termstartup extends plugin
     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
       /* We assign a share to this user, if we don't know where to mount the share */
       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
-        msg_dialog(_("Error"), msgPool::invalid(_("Mount point")), WARNING_DIALOG);
-      }else{
+        msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), WARNING_DIALOG);
+      }elseif(isset($_POST['gotoShareSelection']) && isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
         $s_mount = $_POST['gotoShareMountPoint'];
         /* Preparing the new assignment */
@@ -280,8 +296,8 @@ class termstartup extends plugin
       $SelectBoxLdapServer->AddEntry(
           array(array("string" => $server),
             array("string" =>
-              "<input class='center' type='image' src='images/sort_up.png' name='sort_ldap_up_".$key."'>&nbsp;".
-              "<input class='center' type='image' src='images/sort_down.png' name='sort_ldap_down_".$key."'>&nbsp;".
+              "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'>&nbsp;".
+              "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'>&nbsp;".
               "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
               "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
     }
@@ -308,7 +324,7 @@ class termstartup extends plugin
     }
 
     /* Values */
-    foreach(array("gotoBootKernel", "customParameters") as $val){
+    foreach(array("gotoBootKernel", "gotoKernelParameters") as $val){
       $smarty->assign($val, $this->$val);
     }
 
@@ -336,11 +352,6 @@ class termstartup extends plugin
       }else{
         $this->gotoLdap_inherit = FALSE;
       }
-
-      /* Save kernel parameters */
-      if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
-        $this->customParameters= $_POST["customParameters"];
-      }
     }
   }
 
@@ -348,47 +359,23 @@ class termstartup extends plugin
   /* Save to LDAP */
   function save()
   {
-    /* Find proper terminal path for tftp configuration
-       FIXME: This is suboptimal when the default has changed to
-       another location! */
-    if ($this->gotoTerminalPath == "default-inherit"){
-      $ldap= $this->config->get_ldap_link();
-
-      /* Strip relevant part from dn, keep trailing ',' */
-      $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalou')."/i", "", $this->dn);
-      $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
-
-      /* Walk from top to base and try to load default values for
-         'gotoTerminalPath'. Abort when an entry is found. */
-      while (TRUE){
-        $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
-
-        $ldap->cat("cn=default,".get_ou('terminalou').$tmp.
-            $this->config->current['BASE'], array('gotoTerminalPath'));
-        $attrs= $ldap->fetch();
-        if (isset($attrs['gotoTerminalPath'])){
-          $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
-          break;
-        }
-
-        /* Nothing left? */
-        if ($tmp == ""){
-          break;
-        }
-      }
-    }
-    
-    /* Add semi automatic values */
-    // FIXME: LDAP Server may not be set here...
-    $this->gotoKernelParameters= "root=/dev/nfs nfsroot=".
-      $this->gotoTerminalPath.
-      ",ro,hard,nolock,fg,rsize=8192 ".
-      "ip=::::::dhcp ldap=".base64_encode($this->gotoLdapServer);
-
-    if ($this->customParameters != ""){
-      $this->gotoKernelParameters.= " o ".$this->customParameters;
+   /* Depending on the baseobject (Ogroup / WS) we
+     *  use another set of objectClasses
+     * In case of TS itself, we use  "array("GOhard");"
+     * if we are currently editing from ogroup menu we use (array("goTerminalTemplate"))
+     */
+    if(isset($this->parent->by_object['ogroup'])){
+      $this->objectclasses = array("gotoTerminalTemplate");
+    }elseif(isset($this->parent->by_object['termgeneric'])){
+      $this->objectclasses = array("GOhard");
+    }else{
+      msg_dialog::display(_("Fatal error"),
+          "Object Type Configuration is unknown. Please contact the GOsa developers.",
+          FATAL_ERROR_DIALOG);
+      exit();
     }
 
+    
     plugin::save();
 
     /* Add missing arrays */
@@ -413,16 +400,14 @@ class termstartup extends plugin
     }
 
     /* Strip out 'default' values */
-    foreach(array("gotoBootKernel") as $value){
-      if (!isset($this->attrs[$value]) || $this->attrs[$value] == "default"){
-        $this->attrs[$value] = array();
-      } 
+    if ($this->attrs['gotoBootKernel'] == "default-inherited"){
+           $this->attrs['gotoBootKernel']= array();
     }
 
      /* prepare share settings */
     $tmp = array();
     foreach($this->gotoShares as $name => $settings){
-      $tmp2 = split("\|",$name);
+      $tmp2 = explode("|",$name);
       $name = $tmp2[0];
       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
     }
@@ -441,27 +426,6 @@ class termstartup extends plugin
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
     }
     $this->handle_post_events("modify");
-
-    /* Check if LDAP server has changed */
-    if (isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")){
-      $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
-      $o_queue = new gosaSupportDaemon();
-      if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
-        $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
-        $macs = array($this->parent->by_object['termgeneric']->netConfigDNS->macAddress);
-  
-        /* Trigger event for all member objects 
-         */
-        foreach($macs as $mac){
-          $tmp = new $evt['CLASS_NAME']($this->config);
-          $tmp->set_type(TRIGGERED_EVENT);
-          $tmp->add_targets(array($mac));
-          if(!$o_queue->append($tmp)){
-            msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
-          }
-        }
-      }
-    }
   }
 
   /* Add value to array, check if unique */
@@ -508,7 +472,12 @@ class termstartup extends plugin
 
     $source_o = new termstartup ($this->config, $source['dn']);
 
-    foreach(array("gotoModules", "gotoKernelParameters","gotoShares","customParameters","gotoTerminalPath","gotoShares","goLdapServerList","gotoBootKernel","gotoLdapServer","gotoBootKernels") as $attr){
+    foreach(array("gotoModules", "gotoKernelParameters","gotoShare",
+                  "gotoKernelParameters","gotoShares",
+                  "goLdapServerList","gotoBootKernel","gotoLdapServer",
+                  "gotoBootKernels","gotoLdapServers","gotoLdapServers",
+                  "gotoLdapServerList","gotoLdap_inherit","gotoShareSelections",
+                  "gotoAvailableShares") as $attr){
       $this->$attr = $source_o->$attr;
     }
   }