Code

Fixed images in FAI list
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_terminalService.inc
index a43e53a7f85b491f3e9cd2ddbefa056bad1ccc96..360054533daadc85a204f2a33386a8c3ad761dc9 100644 (file)
@@ -3,7 +3,6 @@
 class termservice extends plugin
 {
   /* Generic terminal attributes */
-  var $gotoLpdEnable= FALSE;
   var $gotoXMonitor= "";
   var $gotoXMethod= "default";
   var $gotoXdmcpServer= "";
@@ -24,6 +23,8 @@ class termservice extends plugin
   var $gotoScannerBackend= "";
   var $goFonHardware= "automatic";
 
+  var $gotoLpdEnable = array();
+
   var $AutoSync = false;
   var $view_logged = FALSE;
 
@@ -48,7 +49,7 @@ class termservice extends plugin
   /* attribute list for save action */
   var $attributes= array("gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
       "gotoXDriver", "gotoXResolution", "gotoXColordepth",
-      "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
+      "gotoXHsync", "gotoXVsync", "gotoLpdServer",
       "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
@@ -76,11 +77,21 @@ class termservice extends plugin
      */
     $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()){
       $this->is_ogroup_member = TRUE;
     }
 
+    /* Load gotoLpdEnable
+     */
+    $this->gotoLpdEnable = array();
+    if(isset($this->attrs['gotoLpdEnable']['count'])){
+      for($i = 0 ; $i < $this->attrs['gotoLpdEnable']['count']; $i ++){
+        $this->gotoLpdEnable[] = $this->attrs['gotoLpdEnable'][$i];
+      }
+    }
+    $this->gotoLpdEnable_dialog = new gotoLpdEnable($this->config,$this->gotoLpdEnable,$this); 
+
     /* Get list of available xdrivers */
     $this->XDrivers = $this->getListOfXDrivers();
 
@@ -99,7 +110,7 @@ class termservice extends plugin
       $file = $this->config->get_cfg_value("resolutions");
       if(is_readable($file)){
         $str = file_get_contents($file);
-        $lines = split("\n",$str);
+        $lines = preg_split("/\n/",$str);
         foreach($lines as $line){
           $line = trim($line);
           if(!empty($line)){
@@ -134,23 +145,30 @@ class termservice extends plugin
     /* Additional values will be extracted from CONFIG_DIR.keyboardLayouts */
     $this->XKbLayouts = array("de"=> "de","en" =>"en", "es" => "es", "us" =>"us", "fr" => "fr");
     $this->XKbVariants= array("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
-    $this->MouseTypes = array("ImPS/2"=>"ImPS/2","PS/2"=>"PS/2", "explorerps/2"=>"explorerps/2",
-                              "Microsoft"=>"Microsoft","Logitech"=>"Logitech");
-    $this->MousePorts = array("/dev/ttyS0"=>"/dev/ttyS0",
-                              "/dev/ttyS1"=>"/dev/ttyS1","/dev/psaux"=>"/dev/psaux", 
-                              "/dev/input/mice"=>"/dev/input/mice");
+
+    $this->MouseTypes= array("auto" => "auto", 
+                             "explorerps/2" => "explorerps/2",
+                             "ImPS/2" => "ImPS/2",
+                             "PS/2" => "PS/2", 
+                             "Microsoft" => "Microsoft",
+                             "Logitech" => "Logitech",);
+
+    $this->MousePorts= array("/dev/input/mice" => "/dev/input/mice",
+                             "/dev/mouse" => "/dev/mouse",
+                             "/dev/psaux" => "/dev/psaux",
+                             "/dev/ttyS0" => "/dev/ttyS0",
+                             "/dev/ttyS1" => "/dev/ttyS1");
 
     /* Try to read additional keyboard layouts
      */
     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
-        $tmp = split("\n",$str);
+        $tmp = preg_split("/\n/",$str);
         foreach($tmp as $entry){
           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
             $entry = trim($entry);
-            $tmp2 = split ("\:",$entry);
+            $tmp2 = explode(":",$entry);
             $la =   trim($tmp2[0]);   // What would be saved to ldap
             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
             $this->XKbLayouts [ $la] = $da;
@@ -163,11 +181,11 @@ class termservice extends plugin
     if($this->is_ogroup_member){
       $this->XMethods["default"]= _("inherited");
     }
-    $this->XMethods["xdmcp"]  = _("XDMCP");
-    $this->XMethods["ldm"]    = _("LDM");
-    $this->XMethods["shell"]    = _("Shell");
-    $this->XMethods["telnet"]    = _("Telnet");
-    #$this->XMethods["rdp"]    = _("Windows RDP");
+    $this->XMethods["xdmcp"]   = _("XDMCP");
+    $this->XMethods["ldm"]     = _("LDM");
+    $this->XMethods["shell"]   = _("Shell");
+    $this->XMethods["telnet"]  = _("Telnet");
+    $this->XMethods["rdp"]     = _("Windows RDP");
     #$this->XMethods["citrix"] = _("ICA client");
 
     /* Get selected gotoXdmcpServer */
@@ -215,10 +233,6 @@ class termservice extends plugin
       }
     }
 
-    /* Convert gotoLpdEnable 
-     */
-    $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
-
     /* Load hardware list */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
@@ -227,13 +241,13 @@ class termservice extends plugin
         "gotoXColordepth", 
         "gotoXKbModel", 
         "gotoXKbLayout",
-#        "gotoXDriver",
+        "gotoXDriver",
         "gotoXdmcpServer",
         "gotoXKbVariant",
         "gotoXMouseType", 
         "gotoXMethod",
         "gotoXMouseport");
-    $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",$map);
+    $ldap->search("(&(|(objectClass=gotoTerminalTemplate)(objectClass=gotoWorkstationTemplate))(member=".LDAP::prepare4filter($this->dn)."))",$map);
     if ($ldap->count() == 1){
       $attrs= $ldap->fetch();
       foreach ($map as $name){
@@ -242,9 +256,9 @@ class termservice extends plugin
         }
 
         switch ($name){
-#         case 'gotoXDriver': 
-#           $this->XDrivers = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers;
-#           break;
+         case 'gotoXDriver': 
+           $this->XDrivers = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers;
+           break;
           case 'gotoXMethod': 
             $this->XMethods = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XMethods;
             if(isset($attrs['gotoXdmcpServer'])){
@@ -269,10 +283,10 @@ class termservice extends plugin
             $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
             break;
           case 'gotoXMouseType':
-            $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
+            $this->MouseTypes= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
             break;
           case 'gotoXMouseport':
-            $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
+            $this->MousePorts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
             break;
         }
       }
@@ -310,6 +324,7 @@ class termservice extends plugin
 
     /* Show main page */
     $smarty= get_smarty();
+    $smarty->assign("gotoLpdEnable_dialog", $this->gotoLpdEnable_dialog->execute());
 
     /* Assign acls */
     $tmp= $this->plInfo();
@@ -389,10 +404,9 @@ class termservice extends plugin
     foreach(array("gotoXHsync", "gotoXVsync") as $val){
       $smarty->assign($val, $this->$val);
     }
-    $smarty->assign("staticAddress", "");
 
     /* Checkboxes */
-    foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
+    foreach(array("gotoScannerEnable") as $val){
       if ($this->$val == TRUE) {
         $smarty->assign("$val", "checked");
       } else {
@@ -446,9 +460,16 @@ class termservice extends plugin
   {
     plugin::save_object();
 
+    $this->gotoLpdEnable_dialog->save_object();
+    if($this->gotoLpdEnable_dialog->is_account){
+      $this->gotoLpdEnable = $this->gotoLpdEnable_dialog->save();
+    }else{
+      $this->gotoLpdEnable = array();
+    }
+
     /* Save checkbox state */
     if (isset ($_POST['gotoXMethod'])){
-      foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
+      foreach (array("gotoScannerEnable") as $val){
 
         if($this->acl_is_writeable($val)){
           if (!isset ($_POST["$val"])){
@@ -509,6 +530,7 @@ class termservice extends plugin
   {
     /* Call common method to give check the hook */
     $message= plugin::check();
+    $message = array_merge($message,$this->gotoLpdEnable_dialog->check());
 
     if($this->gotoXMethod != "default"){
       $xdmcp_types =  $this->config->data['SERVERS']['TERMINAL_SESSION_TYPES'];
@@ -533,13 +555,9 @@ class termservice extends plugin
   /* Save to LDAP */
   function save()
   {
-    /* Convert to string */
-    $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
-
-    if($this->is_ogroup){
-      $this->objectclasses = array("gotoWorkstationTemplate");
-    }else{
-      $this->objectclasses = array("GOhard");
+    /* remove objectclass GOhard if this is an ogroup tab */
+    if(isset($this->parent->by_object['ogroup'])){
+           $this->objectclasses = array();
     }
 
     plugin::save();
@@ -578,6 +596,11 @@ class termservice extends plugin
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
     }
     $this->handle_post_events("modify");
+
+    /* Send goto reload event to gosaSupportDaemon */
+    if(count($this->attrs)){
+           $this->send_goto_reload();
+    }
   }
 
 
@@ -602,10 +625,76 @@ class termservice extends plugin
         $drivers[] = $driver;
       }
     }
-    return($drivers);
+
+    $tmp = array();
+    foreach($drivers as $name){
+      $tmp[$name] = $name;
+    }
+    return($tmp);
+  }
+
+  function send_goto_reload()
+  {
+    if(count($this->attrs) && class_available("DaemonEvent")){
+      $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
+      $o_queue = new gosaSupportDaemon();
+      if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){
+        $evt = $events['TRIGGERED']['DaemonEvent_goto_reload'];
+        $macs = array();
+
+        /* Get list of macAddresses
+         */
+        if(isset($this->parent->by_object['ogroup'])){
+
+          /* If we are an object group, add all member macs
+           */
+          $p = $this->parent->by_object['ogroup'];
+          foreach($p->memberList as $dn => $obj){
+            if(preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$dn)) continue;
+            if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
+              $macs[] = $p->objcache[$dn]['macAddress'];
+            }
+          }
+        }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
+
+          /* We are a workstation. Add current mac.
+           */
+          $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
+          if(!empty($mac) && !preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->orig_dn)){
+            $macs[] = $mac;
+          }
+        }
+
+        /* Trigger event for all member objects
+         */
+        if(count($macs)){
+          $tmp = new $evt['CLASS_NAME']($this->config);
+          $tmp->set_type(TRIGGERED_EVENT);
+          $target = $o_queue->get_host().":".$o_queue->get_port();
+          $tmp->add_targets(array($target));
+          $tmp->set_macs($macs);
+          if(!$o_queue->append($tmp,TRUE)){
+            msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
+          }
+        }
+      }
+    }
+  }
+
+
+  function PrepareForCopyPaste($source)
+  {
+    plugin::PrepareForCopyPaste($source);
+
+    $source_o = new termservice ($this->config, $source['dn']);
+
+    foreach(array("gotoXdmcpServer","selected_xdmcp_servers") as $attr){
+      $this->$attr = $source_o->$attr;
+    }
   }
 
 
+
   /* Return plugin informations for acl handling */
   static function plInfo()
   {
@@ -619,6 +708,7 @@ class termservice extends plugin
           "plCategory"    => array("terminal"),
 
           "plProvidedAcls"=> array(
+          
             "gotoXMonitor"            => _("Monitor"),
             "gotoXMethod"             => _("Method"),
             "gotoXdmcpServer"         => _("Remote desktop"),
@@ -628,14 +718,14 @@ class termservice extends plugin
             "gotoXHsync"              => _("HSync"),
             "gotoXVsync"              => _("VSync"),
             "AutoSync"                => _("Auto-Sync"),
-            "gotoLpdEnable"           => _("Printer service enabled"),
-            "gotoLpdServer"           => _("Spool server"),
             "gotoScannerEnable"       => _("Scanner enabled"),
+            "gotoLpdEnable"           => _("Printer enabled"),
             "gotoXKbModel"            => _("Keyboard model"),
             "gotoXKbLayout"           => _("Keyboard layout"),
             "gotoXKbVariant"          => _("Keyboard variant"),
             "gotoXMouseType"          => _("Mouse type"),
             "gotoXMouseport"          => _("Mouse port"),
+            "gotoLpdEnable"         => _("Printer enabled"),
             "goFonHardware"           => _("Telephone hardware"))
           ));
   }