Code

Added RDN support for users
[gosa.git] / plugins / admin / systems / class_terminalService.inc
index e1c3d6f9b8ff43e02f86d847c4cd03b0be22ed7c..76c58af78831a3f7983c40b96d84787ae5e17e2f 100644 (file)
@@ -2,11 +2,6 @@
 
 class termservice extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Manage terminal service aspects";
-  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 $gotoLpdEnable= FALSE;
   var $gotoXMonitor= "";
@@ -29,6 +24,7 @@ class termservice extends plugin
   var $gotoScannerClients= "";
   var $gotoScannerBackend= "";
   var $goFonHardware= "automatic";
+  var $AutoSync = false;
 
   /* Needed values and lists */
   var $ignore_account= TRUE;
@@ -36,22 +32,17 @@ class termservice extends plugin
   var $cn= "";
   var $orig_dn= "";
   var $XMethods= array();
-  var $XDrivers= array("unknown", "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
+  var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
-  var $XResolutions= array("default", "640x480", "800x600", "1024x768", "1152x864", "1280x1024",
-      "1400x1050", "1600x1200");
-  var $XColordepths= array("default", "8", "15", "16", "24");
-  var $XKbModels= array ("default", "btc9000", "chicony", "compaq", "dell", "dell101", "everex",
-      "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
-      "logiinetnav", "logiinternet", "macintosh", "microsoft",
-      "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
-      "pc105", "rapidaccess", "rapidaccess2", "winbook");
-  var $XKbLayouts= array ("default"=>"default","de"=> "de","intl" =>"intl","us" =>"us");
-  var $XKbVariants= array ("default", "nodeadkeys", "basic");
-  var $MouseTypes= array("AUTO", "ImPS/2", "PS/2", "Microsoft", "Logitech");
-  var $MousePorts= array("AUTO", "/dev/ttyS0", "/dev/ttyS1", "/dev/psaux", "/dev/input/mice");
+  var $XResolutions= array();
+  var $XColordepths= array();
+  var $XKbModels= array ();
+  var $XKbLayouts= array ();
+  var $XKbVariants= array ();
+  var $MouseTypes= array();
+  var $MousePorts= array();
   var $gotoScannerModels= array();
   var $hardware_list= array();
   var $used_hardware= array();
@@ -67,11 +58,69 @@ class termservice extends plugin
   var $objectclasses= array("GOhard");
 
 
-  function termservice ($config, $dn= NULL)
+  function termservice ($config, $dn= NULL, $parent= NULL)
   {
-    plugin::plugin ($config, $dn);
-
+    plugin::plugin ($config, $dn, $parent);
+    
+    array_unshift($this->XDrivers, "["._("unknown")."]");
     
+    $this->XResolutions= array(
+        "default"   =>  "["._("inherited")."]"  ,
+        "640x480"   =>  "640x480",
+        "800x600"   =>  "800x600",
+        "1024x768"  =>  "1024x768",
+        "1152x864"  =>  "1152x864",
+        "1280x1024" =>  "1280x1024",
+        "1400x1050" =>  "1400x1050",
+        "1600x1200" =>  "1600x1200");
+
+    if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
+      $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
+
+      if(is_readable($file)){
+        $str = file_get_contents($file);
+        $lines = split("\n",$str);
+        foreach($lines as $line){
+          $line = trim($line);
+          if(!empty($line)){
+            $this->XResolutions[$line]=$line;
+          }
+        }
+        //natcasesort($this->gotoXResolutions);
+      }else{
+        print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
+      }
+    }
+
+    $this->XColordepths= array(
+        "default"  => "["._("inherited")."]",
+        "8"        => "8 " ._("bit"),
+        "15"       => "15 "._("bit"),
+        "16"       => "16 "._("bit"),
+        "24"       => "24 "._("bit"));
+
+    $this->XKbModels['default']= "["._("inherited")."]";
+    foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
+          "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
+          "logiinetnav", "logiinternet", "macintosh", "microsoft",
+          "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
+          "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
+      $this->XKbModels[$type] = $type;
+    }
+
+    /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */
+    $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
+    $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
+
+    $this->MouseTypes= array( "AUTO"      =>  "["._("inherited")."]" ,  "ImPS/2"      => "ImPS/2", 
+                              "PS/2"      =>  "PS/2"                 ,  "Microsoft"   => "Microsoft", 
+                              "Logitech"  =>  "Logitech");
+
+    $this->MousePorts= array("AUTO"             =>"["._("inherited")."]"   , "/dev/ttyS0"  => "/dev/ttyS0", 
+                             "/dev/ttyS1"       => "/dev/ttyS1"            , "/dev/psaux"  => "/dev/psaux", 
+                             "/dev/input/mice"  =>"/dev/input/mice");
+
     /* try to read additional keyboard layouts
      */
     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
@@ -140,6 +189,54 @@ class termservice extends plugin
 
     $this->hardware_list["automatic"]= _("automatic");
     ksort($this->hardware_list);
+
+    /* 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']);
+    $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
+    if ($ldap->count() == 1){
+      $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
+                  "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
+      $attrs= $ldap->fetch();
+
+      foreach ($map as $name){
+        if (!isset($attrs[$name][0])){
+          continue;
+        }
+
+        switch ($name){
+          case 'gotoXResolution':
+            $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
+            break;
+          case 'gotoXColordepth':
+            $this->XColordepths['default'] =  _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
+            break;
+          case 'gotoXKbModel':
+            $this->XKbModels['default'] =  _("inherited").' ['.$attrs[$name][0].']';
+            break;
+          case 'gotoXKbLayout':
+            $this->XKbLayouts['default'] =  _("inherited").' ['.$attrs[$name][0].']';
+            break;
+          case 'gotoXKbVariant':
+            $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
+            break;
+          case 'gotoXMouseType':
+            $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
+            break;
+          case 'gotoXMouseport':
+            $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
+            break;
+        }
+      }
+    }
+    if(preg_match("/\+/",$this->gotoXHsync)){
+      $this->AutoSync = true;
+      $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
+      $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
+    }
   }
 
   function execute()
@@ -225,6 +322,17 @@ class termservice extends plugin
     $smarty->assign ("hardware_list", $hl);
     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
 
+    $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
+  
+    if($this->AutoSync){
+      $smarty->assign("AutoSyncCHK"," checked ");
+      $smarty->assign("hiddenState"," disabled ");
+    }else{
+      $smarty->assign("AutoSyncCHK"," ");
+      $smarty->assign("hiddenState","");
+    }
+
+  
     /* Show main page */
     return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
   }
@@ -250,7 +358,15 @@ class termservice extends plugin
           $this->$val= TRUE;
         }
       }
+    } 
+    if(isset($_POST['gotoXDriver'])){
+      if(isset($_POST['AutoSync'])){
+        $this->AutoSync = true;
+      }else{
+        $this->AutoSync = false;
+      }
     }
+
   }
 
 
@@ -261,38 +377,43 @@ class termservice extends plugin
     $message= plugin::check();
 
     /* Default entries can use blank hsync/vsync entries */
-    if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
-
-      /* Check vsync for correct usage */
-      $val= preg_replace ("/\s/", "", $this->gotoXVsync);
-      if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
-          && chkacl ($this->acl, "gotoXVsync") == ""){
-
-        $message[]= _("Please specify a valid VSync range.");
-      } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
-        list($v1,$v2)= split ("-", $val);
-        if ($v2 != ""){
-          if ($v1 > $v2){
-            $message[]= _("Please specify a valid VSync range.");
+    if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){
+
+      /* But only if no auto sync is enabled... */
+      if (!$this->AutoSync){
+
+        /* Check vsync for correct usage */
+        $val= preg_replace ("/\s/", "", $this->gotoXVsync);
+        if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
+            && chkacl ($this->acl, "gotoXVsync") == ""){
+
+          $message[]= _("Please specify a valid VSync range.");
+        } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
+          list($v1,$v2)= preg_split ("/[-+]/", $val);
+          if ($v2 != ""){
+            if ($v1 > $v2){
+              $message[]= _("Please specify a valid VSync range.");
+            }
           }
         }
-      }
 
-      /* Check hsync for correct usage */
-      $val= preg_replace ("/\s/", "", $this->gotoXHsync);
-      if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
-          && chkacl ($this->acl, "gotoXHsync") == ""){
-
-        $message[]= _("Please specify a valid HSync range.");
-      } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
-        list($v1,$v2)= split ("-", $val);
-        if ($v2 != ""){
-          if ($v1 > $v2){
-            $message[]= _("Please specify a valid HSync range.");
+        /* Check hsync for correct usage */
+        $val= preg_replace ("/\s/", "", $this->gotoXHsync);
+        if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
+            && chkacl ($this->acl, "gotoXHsync") == ""){
+
+          $message[]= _("Please specify a valid HSync range.");
+        } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
+          list($v1,$v2)= preg_split ("/[-+]/", $val);
+          if ($v2 != ""){
+            if ($v1 > $v2){
+              $message[]= _("Please specify a valid HSync range.");
+            }
           }
         }
       }
     }
+
     return ($message);
   }
 
@@ -300,6 +421,9 @@ class termservice extends plugin
   /* Save to LDAP */
   function save()
   {
+    /* Convert to string */
+    $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
+
     plugin::save();
 
     /* Strip out 'default' values */
@@ -313,6 +437,11 @@ class termservice extends plugin
       }
     }
 
+    if($this->AutoSync){
+      $this->attrs['gotoXHsync'] = "30+55";
+      $this->attrs['gotoXVsync'] = "50+70";
+    }
+
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->dn);