Code

Update workstation startup
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_workstationStartup.inc
index 9571b208bed97e52380b986e4cbac60ec4237ddd..5485aaafb4550816e3d6976513b4ec7395c22b56 100644 (file)
@@ -1,11 +1,6 @@
 <?php
 class workstartup extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Manage terminal startup options";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* Ldap server list */
   var $gotoLdapServers    = array();
   var $gotoLdapServerList = array();
@@ -239,8 +234,7 @@ class workstartup extends plugin
        */
       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
         if(count($this->FAIclass)){
-          print_red(sprintf(_("The selected FAI mirror '%s' is no longer available, the mirror was set to 'auto'."),
-                $this->FAIdebianMirror));
+          msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
         }
         $this->FAIdebianMirror = "auto";
         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
@@ -254,8 +248,7 @@ class workstartup extends plugin
       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
         $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]); 
         if(count($this->FAIclass)){
-          print_red(sprintf(_("The selected FAI release '%s' is not available for mirror '%s', the release was set to '%s'."),
-                $this->FAIrelease,$this->FAIdebianMirror,$new_release));
+          msg_dialog::display(_("Error"), sprintf(_("FAI release '%s' is not available on mirror '%s' - setting to release '%s'!"), $this->FAIrelease, $this->FAIdebianmirror), ERROR_DIALOG);
         }
         $this->FAIrelease = $new_release;
         $this->cache =array();
@@ -332,7 +325,7 @@ class workstartup 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>".
-        _("This 'dn' has no terminal features.")."</b>";
+        msgPool::noValidExtension(_("workstation"))."</b>";
       return ($display);
     }
 
@@ -371,7 +364,7 @@ class workstartup extends plugin
         }
 
         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
-          print_red(_("There is already a profile in your selection that contain partition table configurations."));
+          msg_dialog(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
         }else{
           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
         }
@@ -479,7 +472,7 @@ class workstartup 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']))){
-        print_red(_("You must specify a valid mount point."));
+        msg_dialog(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
       }else{
         if(count($this->gotoAvailableShares)){
           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
@@ -550,13 +543,22 @@ class workstartup extends plugin
       } 
     }
   
-    /* Add Entries 
-     */
+    /* Add Entries */
     foreach($this->gotoLdapServers as $key => $server){
+      /* Announce missing entries */
       if(!in_array($server,$this->gotoLdapServerList)){
         $server = $server."&nbsp;<font style='color:red'>(missing)</font>";
       }
 
+      /* Convert old style entry */
+      if (!preg_match('%:ldap://%', $server)){
+        $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
+
+      /* Beautify new style entries */
+      } else {
+        $server= preg_replace("/^[^:]+:/", "", $server);
+      }
+
       $SelectBoxLdapServer->AddEntry(
           array(array("string" => $server),
             array("string" => 
@@ -575,6 +577,16 @@ class workstartup extends plugin
     $list = array();
     foreach($this->gotoLdapServerList as $key => $entry){
       if(!in_array($entry,$this->gotoLdapServers)){
+
+        /* Convert old style entry */
+        if (!preg_match('%:ldap://%', $entry)){
+          $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
+
+        /* Beautify new style entries */
+        } else {
+          $entry= preg_replace("/^[^:]+:/", "", $entry);
+        }
+
         $list[$key] = $entry;
       }
     }
@@ -813,27 +825,25 @@ class workstartup extends plugin
     plugin::save();
 
     unset( $this->attrs['FAIrelease'] );
-    
     $str = "";
 
     /* Skip FAI attribute handling if not necessary */
     if($this->fai_activated){
       if($this->FAIdebianMirror == "inherited"){
-        $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
+        $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array();
       }else{
         foreach($this->FAIclass as $class){
           $str .= $class." ";
         }
-        $str .= ":" . $this->FAIrelease;
-        $this->attrs['FAIclass']= "";
-        $this->attrs['FAIclass']= trim($str);
-
+        $str = trim($str);
         if(empty($this->attrs['FAIclass'])){
           $this->attrs['FAIclass'] = array();
+        }else{
+          $this->attrs['FAIclass']= $str.":".$this->FAIrelease;
         }
       }
     }
-  
+
     /* Add missing arrays */
     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
       if (isset ($this->$val) && count ($this->$val) != 0){
@@ -854,9 +864,16 @@ class workstartup extends plugin
     }
 
     /* Check if LDAP server has changed */
-    $ldap_changed= (isset($this->attrs['gotoLdapServer'])) && 
-                   (isset($this->saved_attributes['gotoLdapServer'])) &&
-                   ($this->attrs['gotoLdapServer'] != $this->saved_attributes['gotoLdapServer']);
+    $ldap_changed= false;
+    if (isset($this->saved_attributes['gotoLdapServer'])){
+      if (isset($this->attrs['gotoLdapServer']) && $this->attrs['gotoLdapServer'] != $this->saved_attributes['gotoLdapServer']){
+        $ldap_changed= true;
+      }
+    } else {
+      if (isset($this->attrs['gotoLdapServer'])){
+        $ldap_changed= true;
+      }
+    }
 
     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
       $this->attrs['gotoBootKernel']= array();
@@ -898,21 +915,50 @@ class workstartup extends plugin
     $ldap->modify ($this->attrs); 
     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      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 ($ldap_changed){
-      $events = DaemonEvent::get_event_types();
+    if ($ldap_changed && class_available("DaemonEvent")){
+      $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
       $o_queue = new gosaSupportDaemon();
-      if(isset($events['BY_CLASS']['DaemonEvent_reload_ldap_config'])){
-        $evt = $events['BY_CLASS']['DaemonEvent_reload_ldap_config'];
-        $tmp = new $evt['CLASS_NAME']($this->config);
-        $tmp->set_type(TRIGGERED_EVENT);
-        $tmp->add_targets(array($this->netConfigDNS->macAddress));
-        if(!$o_queue->append($tmp)){
-          msg_dialog::display(_("Daemon"),sprintf(_("Something went wrong while talking to the daemon: %s."),
-                $o_queue->get_error()),ERROR_DIALOG);
+      if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
+        $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
+        $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(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)){
+            $macs[] = $mac;
+          }          
+        }
+
+        /* 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);
+          }
         }
       }
     }
@@ -1025,49 +1071,29 @@ class workstartup extends plugin
   {
     $force = FALSE;
 
+    $start = microtime(TRUE);  
+
     /* Get the list of available servers and their releases. 
      */
     if($force || !isset($this->cache['SERVERS'])){
-      $ldap = $this->config->get_ldap_link();
-      $ldap->cd($this->config->current['BASE']);
 
-      $server_list = get_sub_list("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",
-                      "",get_ou("serverou"),$this->config->current['BASE'],array("FAIrepository"),GL_NO_ACL_CHECK);
-     
       /* Only add inherit option, if we are part in an object group
        */
       if($this->member_of_ogroup){
         $this->cache['SERVERS']['inherited']=array();
       }
 
-      /* Add auto value  
-       */
-      $this->cache['SERVERS']['auto'] = array();
-      $sort_by = array("auto");
-      $server_tmp = array("auto"=>array());
-      foreach($server_list as $attr){
-        if(isset($attr['FAIrepository'])){
-          for($i = 0 ; $i < $attr['FAIrepository']['count'] ; $i ++ ){
-            $rep = $attr['FAIrepository'][$i];
-            $tmp = split("\|",$rep);
-            if(count($tmp)==4){
-              $sections = split(",",$tmp[3]);
-              $release  = $tmp[2];
-              $server   = $tmp[1];
-              $url      = $tmp[0];
-              $server_tmp[$url][$release]=$release;
-              $server_tmp['auto'][$release]=$release;
-              $sort_by[$url] = $url;
-            }
-          }
+      $o_queue = new gosaSupportDaemon();
+      $tmp = $o_queue->FAI_get_server(); 
+      if($o_queue->is_error()){
+        msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
+      }else{
+        foreach($tmp as $entry){
+          $rel = $entry['RELEASE'];
+          $this->cache['SERVERS']['auto'][$rel] = $rel;
+          $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
         }
       }
-      natcasesort($sort_by);
-      foreach($sort_by as $name){
-        $releases = $server_tmp[$name];
-        natcasesort($releases);
-        $this->cache['SERVERS'][$name] = $releases; 
-      }
     }
 
     /* Build up arrays, without checks */
@@ -1095,46 +1121,21 @@ class workstartup extends plugin
     }else{
       $release = $this->FAIrelease;
     }
-    if($force || !isset($this->cache['CLASSES'][$release])){
 
-      /*  Create a list of available releases.
-       *  $this->cache['RELEASE_DNS'][ou=siga...,c=de]         = "siga";
-       *  $this->cache['RELEASE_DNS'][ou=siga,ou=rc1,...,c=de] = "siga/rc1";
-       */
-      if($force || !isset($this->cache['RELEASE_DNS'])){
-        $this->cache['RELEASE_DNS'] = array();
-        $fai_ou_parts = preg_replace("/\/.*$/","",$this->FAIrelease);
-
-        $tmp = get_sub_list("(objectClass=FAIbranch)","",get_ou("faiou"),
-                $this->config->current['BASE'],array("ou"),GL_NO_ACL_CHECK | GL_SUBSEARCH);
-
-        foreach($tmp as $attrs){
-          if(preg_match("/".normalizePreg(get_ou("faiou"))."/",$attrs['dn'])){
-            $this->cache['RELEASE_DNS'][$attrs['dn']] = $this->dn_to_release_name($attrs['dn']);
-          }
-        }
-      }
+    if($force || !isset($this->cache['CLASSES'][$release])){
 
-      /* Create list of available classes for the currenlty selected release.
+      /* Get the list of available servers and their releases.
        */
-      $base = array_search($release,$this->cache['RELEASE_DNS']);
+      $o_queue = new gosaSupportDaemon();
+      $tmp = $o_queue->FAI_get_classes($release);
       $this->cache['CLASSES'][$release] = array();
-
-      if(class_exists("FAI")){
-        if(!empty($base)){
-          $filter = "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)".
-            "(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)".
-            "(objectClass=FAIpartitionTable))";
-          $list = FAI::get_all_objects_for_given_base($base,$filter,TRUE);
-          foreach($list as $attrs){
-            $info = $this->analyse_fai_object($attrs);
-            if(count($info)){
-              $this->cache['CLASSES'][$release][$attrs['cn'][0]][] = $info;
-            }
-          }
-        }
+      if($o_queue->is_error()){
+        msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
       }else{
-        print_red(_("Could not load available classes, the fai extension plugin seems not to be installed."));
+        foreach($tmp as $entry){
+          $class = $entry['CLASS'];
+          $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry); 
+        }
       }
 
       /* Add object caught from external hook
@@ -1145,20 +1146,23 @@ class workstartup extends plugin
         $server = $entries['0'];
         $url    = $entries['1'];
         if (!empty($url)){
-          
+
           /* Split releases */
           if (isset($entries[2])){
             $releases= split(",", $entries[2]);
 
             foreach ($releases as $release_data){
-              $release= preg_replace('/:.*$/', '', $release_data);
-              $sections = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
-              $classes  = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
-              $this->cache['SERVERS'][$url][$release]=$release;
-              $this->cache['SERVERS']['auto'][$release]=$release; 
-              foreach ($classes as $class){
-                if ($class != ""){
-                  $this->cache['CLASSES'][$release][$class]= array();
+              $release_c  = preg_replace('/:.*$/', '', $release_data);
+              $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
+              $classes_c  = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
+
+              if($release_c == $release){
+                $this->cache['SERVERS'][$url][$release_c]=$release_c;
+                $this->cache['SERVERS']['auto'][$release_c]=$release_c; 
+                foreach ($classes_c as $class){
+                  if ($class != ""){
+                    $this->cache['CLASSES'][$release_c][$class]= array();
+                  }
                 }
               }
             }
@@ -1166,6 +1170,7 @@ class workstartup extends plugin
         }
       }
     }
+#    echo sprintf("Took %.6f <br> ",microtime(1) - $start);
   }
 
 
@@ -1229,46 +1234,40 @@ class workstartup extends plugin
    */
   function analyse_fai_object($attr)
   {
-    $tmp2 = array();
-    if(!isset($attr['description'])){
-      $attr['description'][0] ="";
-    }
-    if(in_array('FAIpackageList',$attr['objectClass'])){
-      $tmp2["Type"]   = 'FAIpackageList'; 
-      $tmp2["Abbr"]   = 'Pl';
-      $tmp2["Desc"]  = $attr['description'][0];
-    }
-    if(in_array('FAItemplate',$attr['objectClass'])){
-      $tmp2["Type"]      = 'FAItemplate'; 
-      $tmp2["Abbr"]      = 'T'; 
-      $tmp2["Desc"]  = $attr['description'][0];
-    }
-    if(in_array('FAIvariable',$attr['objectClass'])){
-      $tmp2["Type"]      = 'FAIvariable'; 
-      $tmp2["Abbr"]      = 'V'; 
-      $tmp2["Desc"]  = $attr['description'][0];
-    }
-    if(in_array('FAIscript',$attr['objectClass'])){
-      $tmp2["Type"]        = 'FAIscript'; 
-      $tmp2["Abbr"]        = 'S'; 
-      $tmp2["Desc"]  = $attr['description'][0];
-    }
-    if(in_array('FAIhook',$attr['objectClass'])){
-      $tmp2["Type"]          = 'FAIhook'; 
-      $tmp2["Abbr"]          = 'H'; 
-      $tmp2["Desc"]  = $attr['description'][0];
-    }
-    if(in_array('FAIpartitionTable',$attr['objectClass'])){
-      $tmp2["Type"]= 'FAIpartitionTable'; 
-      $tmp2["Abbr"]= 'Pt'; 
-      $tmp2["Desc"]  = $attr['description'][0];
-    }
-    if(in_array('FAIprofile',$attr['objectClass'])){
-      $tmp2["Type"]= 'FAIprofile'; 
-      $tmp2["Abbr"]= 'P'; 
-      $tmp2["Desc"]  = $attr['description'][0];
-    }
-    return($tmp2);
+    $tmp = array();
+    switch($attr['TYPE']){
+
+      case 'FAIpackageList':
+        $tmp["Type"]= 'FAIpackageList';
+        $tmp["Abbr"]= 'Pl';
+        break;
+      case 'FAItemplate': 
+        $tmp["Type"]= 'FAItemplate'; 
+        $tmp["Abbr"]= 'T'; 
+        break;
+      case 'FAIvariable':
+        $tmp["Type"]= 'FAIvariable'; 
+        $tmp["Abbr"]= 'V'; 
+        break;
+      case 'FAIscript':
+        $tmp["Type"]= 'FAIscript'; 
+        $tmp["Abbr"]= 'S'; 
+        break;
+      case 'FAIhook':
+        $tmp["Type"]= 'FAIhook'; 
+        $tmp["Abbr"]= 'H'; 
+        break;
+      case 'FAIpartitionTable':
+        $tmp["Type"]= 'FAIpartitionTable'; 
+        $tmp["Abbr"]= 'Pt'; 
+        break;
+      case 'FAIprofile':
+        $tmp["Type"]= 'FAIprofile'; 
+        $tmp["Abbr"]= 'P'; 
+        break;
+      default: trigger_error("Unknown FAI object type!");;
+    }
+    return($tmp);
   }
 
 
@@ -1282,9 +1281,9 @@ class workstartup extends plugin
       $res = shell_exec($cmd);
       $res2 = trim($res);
       if((!$res)){
-        print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
+        msg_dialog(_("Configuration error"), msgPool::cmdexecfailed("REPOSITORY_HOOK", $cmd), ERROR_DIALOG);
       }elseif(empty($res2)){
-        print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
+        msg_dialog(_("Configuration error"), _("REPOSITORY_HOOK returned no result!"), ERROR_DIALOG);
       }else{
         $tmp = split("\n",$res);
         foreach($tmp as $line){