Code

Apply patch for #5572
[gosa.git] / trunk / gosa-plugins / goto / admin / systems / goto / class_workstationGeneric.inc
index 7246e559782671d88870fd27aa25bafab71a8fb7..7d516ab70879585ab604401e4a6622fab83c403c 100644 (file)
@@ -21,6 +21,8 @@ class workgeneric extends plugin
   var $ghScsiDev= array();
   var $ghGfxAdapter= "-";
   var $ghSoundAdapter= "-";
+  var $gotoHardwareChecksum = "";
+  var $gotoSysStatus = "";
   var $gotoLastUser= "-";
   var $FAIscript= "";
   var $view_logged = FALSE;
@@ -33,6 +35,7 @@ class workgeneric extends plugin
   var $orig_dn= "";
   var $orig_cn= "";
   var $orig_base= "";
+  var $ogroup=FALSE;
 
   /* Plugin side filled */
   var $modes= array();
@@ -46,7 +49,8 @@ class workgeneric extends plugin
   var $attributes= array("gotoMode", "gotoSyslogServer", "gotoNtpServer",
       "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
       "ghCpuType", "ghMemSize", "ghUsbSupport", "description",
-      "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l","FAIscript");
+      "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l","FAIscript",
+      "gotoHardwareChecksum", "gotoSysStatus");
   var $objectclasses= array("top", "gotoWorkstation", "GOhard");
 
   var $validActions   = array("reboot" => "", "localboot" => "", "halt" => "", "update" => "", "reinstall" => "",
@@ -182,6 +186,12 @@ class workgeneric extends plugin
     /* Call parent execute */
     plugin::execute();
 
+    if ($this->ogroup) {
+      $this->member_of_ogroup = TRUE;
+      $this->parent->by_object['workservice']->ogroup = $this->ogroup;
+      $this->set_everything_to_inherited();
+    }
+
     if($this->is_account && !$this->view_logged){
       $this->view_logged = TRUE;
       new log("view","workstation/".get_class($this),$this->dn);
@@ -463,21 +473,29 @@ class workgeneric extends plugin
 
     if ($this->orig_dn != $this->dn){
       $ldap= $this->config->get_ldap_link();
-      $ldap->cd ($this->base);
+      # Do not allow objects with the same name in other departments, either
+      $ldap->cd ($this->config->current['BASE']);
 
       if($this->cn == "wdefault"){
         $ldap->cat($this->dn);
       }else{
-        $ldap->search ("(&(cn=".$this->cn.")(objectClass=gotoWorkstation))", array("cn"));
+        $ldap->search ("(&(cn=".$this->cn.")(objectClass=gotoWorkstation))", array("cn", "gosaUnitTag"));
       }
       if ($ldap->count() != 0){
         while ($attrs= $ldap->fetch()){
           if (preg_match("/cn=dhcp,/",$attrs['dn']) || preg_match ("/,".get_ou('systemIncomingRDN')."/", $ldap->getDN())){
             continue;
           } else {
-            if ($attrs['dn'] != $this->orig_dn){
-              $message[]= msgPool::duplicated(_("Name"));
-              break;
+            if ($attrs['dn'] != $this->orig_dn) {
+              if (isset($this->config->current['HONOURUNITTAGS']) &&
+                  preg_match('/true/i', $this->config->current['HONOURUNITTAGS']) &&
+                  $attrs['gosaUnitTag'][0] != $this->get_gosaUnitTag()) {
+                # the new/moved object is in a different administrative unit, this is not a duplicate 
+                continue;
+              } else {
+                $message[]= msgPool::duplicated(_("Name"));
+                break;
+              }
             }
           }
         }
@@ -636,6 +654,13 @@ class workgeneric extends plugin
         }
       }
     }
+
+    /* If $this->ogroup is set add the new system to the requested ogroup */
+    if ($this->ogroup) {
+      $og = new ogroup($this->config, $this->ogroup);
+      $og->AddDelMembership($this->dn);
+      $og->save();
+    }
   }
 
 
@@ -687,6 +712,24 @@ class workgeneric extends plugin
       $this->inheritTimeServer = true;
       $this->gotoNtpServer=array();
     }
+
+    $source_o = new workgeneric($this->config, $source['dn']);
+    foreach (array('ghIdeDev', 'ghNetNic', 'ghScsiDev') as $attr) {
+      if (isset($source_o->$attr)) {
+        $this->$attr = $source_o->$attr;
+      }
+    }
+
+    $ldap = $this->config->get_ldap_link();
+    $res = $ldap->cat($source['dn'], array('gotoHardwareChecksum', 'gotoSysStatus'));
+    if ($res) {
+      $attrs = $ldap->fetch();
+      foreach(array('gotoHardwareChecksum', 'gotoSysStatus') as $attr) {
+        if (isset($attrs[$attr])) {
+            $this->$attr = $attrs[$attr][0];
+        }
+      }
+    }
   }
 
 
@@ -719,16 +762,53 @@ class workgeneric extends plugin
 
   function set_everything_to_inherited()
   {
+    /* Find out what is set in the object group as XDriver */
+    $inherit_xdriver = 0;
+    $inherit_xy_sync = 0;
+    if ($this->dn != 'new' || $this->ogroup) {
+        $ldap = $this->config->get_ldap_link();
+        $entry = NULL;
+        /* If initialized with an object group we need to use this instead of
+         * an object group we'll become a member in */
+        if ($this->ogroup) {
+            $entry = $ldap->cat($this->ogroup, array("gotoXDriver", "gotoXHsync", "gotoXVsync"));
+        }else {
+          $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("gotoXDriver", "gotoXHsync", "gotoXVsync"));
+          if ($ldap->count() == 1) {
+            $entry = $ldap->fetch();
+          }
+        }
+        if ($entry) {
+            /* Get list of valid XDrivers */
+            $xdrivers = $this->parent->by_object['workservice']->getListOfXDrivers();
+            /* Only inherit if driver in object group is set to something in the list of
+             * valid XDrivers */
+            if (in_array($entry['gotoXDriver'][0], $xdrivers)) {
+              $inherit_xdriver = 1;
+            }
+            if (isset($entry['gotoXHsync']) and isset($entry['gotoXVsync'])) {
+              $inherit_xy_sync = 1;
+            }
+        } 
+    }
+
     $this->gotoSyslogServer  = "default";
     $this->inheritTimeServer = TRUE;
 
     /* Set workstation service attributes to inherited */
     if($this->member_of_ogroup && isset($this->parent->by_object['workservice'])){
-      foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant",
-            "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){
-        if($this->parent->by_object['workservice']->acl_is_writeable($name)){
-          $this->parent->by_object['workservice']->$name = "default"; 
-        }
+      foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant", "gotoXDriver",
+        "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){
+          if(!(($name == 'gotoXDriver') && ($inherit_xdriver == 0))) {
+              if($this->parent->by_object['workservice']->acl_is_writeable($name)){
+                $this->parent->by_object['workservice']->$name = "default"; 
+              }
+          }
+      }
+      
+      /* Inherit VSync/HSync if defined in the object group */
+      if ($inherit_xy_sync) {
+        $this->parent->by_object['workservice']->InheritXYSync = TRUE;
       }
     }