Code

Made packages w3c conform
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiPackage.inc
1 <?php
3 class faiPackage extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account   = TRUE;
8   /* Attributes for this Object */
9   var $attributes       = array("cn","description","FAIpackage","FAIdebianRelease","FAIdebianSection", "FAIinstallMethod");
11   /* ObjectClasses for this Object*/
12   var $objectclasses    = array("top","FAIclass","FAIpackageList","FAIrepository");
14   /* Class name of the Ldap ObjectClass for the Sub Object */
15   var $subClass         = "";
16   var $subClasses       = array("top","FAIclass","FAIscriptEntry");
18   /* Class name of the php class which allows us to edit a Sub Object */
19   var $subClassName     = "";      
21   /* Attributes to initialise for each subObject */
22   var $subAttributes    = array("cn","description"); 
23   var $sub64coded       = array();
25   var $ConfiguredPackages = array();
27   /* Specific attributes */
28   var $cn               = "";       // The class name for this object
29   var $description      = "";       // The description for this set of partitions
30   var $is_dialog        = false;    // specifies which buttons will be shown to save or abort
31   var $SubObjects       = array();  // All leafobjects of this object
33   var $FAIdebianRelease          = ""; // The selected release
34   var $FAIdebianSection          = array(); // selected section
35   var $FAIinstallMethod          = "aptitude"; // hard coded
37   var $sections         = array();  // All section types
39   var $list             = NULL;
41   var $usedPackages     = array();
42   var $buffer           = NULL; 
43   var $newDialogShown   = false;
45   var $FAIstate         = "";
46   var $view_logged      = FALSE;
47   var $base;
48   var $FAIpackage ;
50   var $packageSelect ;
52   var $FAIinstallMethods  = array( "install", "ninstall", "remove", 
53       "dselect-upgrade", "taskinst", "taskrm",
54       "hold", "clean", "aptitude", "aptitude-r",
55       "pending", "dpkgc" );
58   function faiPackage (&$config, $dn= NULL)
59   {
60     /* Load Attributes */
61     plugin::plugin ($config, $dn);
63     /* If "dn==new" we try to create a new entry
64      * Else we must read all objects from ldap which belong to this entry.
65      * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
66      */
67     if($dn != "new"){
68       $this->dn =$dn;
70       /* Check if there are already some packages in this list 
71        */
72       $this->usedPackages = array();
73       if(isset($this->attrs['FAIpackage'])){
74         unset($this->attrs['FAIpackage']['count']);
75         foreach($this->attrs['FAIpackage'] as $pkg){
76           $name = preg_replace("/\-$/","",$pkg);
77           $this->usedPackages[$name] = $pkg;
78         }
79         ksort($this->usedPackages);
80       }  
82       /* Fetch all package configurations from ldap 
83        */
84       $PackageFilter = "";
85       foreach($this->usedPackages as $name => $value){
86         $PackageFilter .= "(FAIpackage=".$name.")";
87       }
88       $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
90       /* Search for configuration objects */ 
91       $ldap = $this->config->get_ldap_link();
92       $ldap->cd($this->dn);
93       $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
94             "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
96       /* Walk through configurations and append them to our list of ConfiguredPackages 
97        */
98       while($attr = $ldap->fetch()){
100         /* Skip objects, that are tagged as removed */
101         if(isset($object['FAIstate'][0])){
102           if(preg_match("/removed$/",$attr['FAIstate'][0])){
103             continue;
104           }
105         }
107         $tmp =array(); 
108         $tmp['Name']  = $attr['FAIvariable'][0];
109         $tmp['Type']  = $attr['FAIvariableType'][0];
111         if (isset($attr['FAIvariableContent'][0])){
112           if(!in_array($attr['FAIvariableType'],array("multiselect"))){
113             $tmp['Value'] = $attr['FAIvariableContent'][0];
114           }else{
115             $content = array();        
116             unset($attr['FAIvariableContent']['count']);
117             foreach($attr['FAIvariableContent'] as $attr){
118               $tmp['Value'][] = $attr;
119             }
120           }
121           $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
122         }
123       }
125       $this->FAIdebianSection = array();
126       if(isset($this->attrs['FAIdebianSection'])){
127         for($i = 0 ; $i < $this->attrs['FAIdebianSection']['count'] ; $i++ ){ 
128           $sec = $this->attrs['FAIdebianSection'][$i];
129           $this->FAIdebianSection[$sec]=$sec;
130         }
131       }
132       $this->FAIpackage = array();
134     } // ENDE  dn != new  
136     $methods = array();
137     foreach($this->FAIinstallMethods as $method){
138       $methods[$method] = $method;
139     }
140     $this->FAIinstallMethods = $methods;
142     /* Check if we exist already - no need to ask for revisions, etc. then */
143     if ($this->dn != "new"){
144       $this->newDialogShown= true;
145     }
146     $this->is_new = FALSE;
147     if($this->dn == "new"){
148       $this->is_new =TRUE;
149     }
151     /* Generate package list */
152     $this->list= $this->genPkgs(TRUE);
153   }
156   function execute()
157   {
158     /* Call parent execute */
159     plugin::execute();
161     if($this->is_account && !$this->view_logged){
162       $this->view_logged = TRUE;
163       new log("view","fai/".get_class($this),$this->dn);
164     }
166     /* Fill templating stuff */
167     $smarty= get_smarty();
168     $display= "";
170     /******
171      * Initialize a new Package List with release and section name
172      ******/
173     
174     if(!$this->is_account){
176       /* Assemble release name */
177       $release = $this->parent->parent->fai_release;
178       $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/i', '', $release);
179       $tmp= preg_replace('/ou=/', '', $tmp);
180       $rev= array_reverse(explode(',', $tmp));
181       $this->FAIdebianRelease= "/";
182       foreach ($rev as $part){
183         $this->FAIdebianRelease.= "/$part";
184       }
185       $this->FAIdebianRelease= preg_replace('#^[/]*#', '', $this->FAIdebianRelease);
187       /* Assemble sections */
188       $repos= $this->getServerInfos();
189       if(isset($repos[$this->FAIdebianRelease])){
190         $this->FAIdebianSection= $repos[$this->FAIdebianRelease];
191         $this->FAIdebianSection= array_unique($this->FAIdebianSection);
192       }
194       /* Assign Repository settings*/ 
195       $this->is_account     = true;
196     }
197   
199     /******
200      * Add 
201      ******/
203     if(isset($_POST['AddManualpkg']) && 
204         isset($_POST['addPpkgsText']) &&
205         strlen($_POST['addPpkgsText']) && 
206         $this->acl_is_writeable("FAIpackage") && 
207         !preg_match("/freeze/",$this->FAIstate)){
209       // Check all splitted packages for valid package names
210       $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
211       if( is_array($add_packages) ) {
212         $invalid_packages = array();
213         foreach ($add_packages as $value) {
214           if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
215             $invalid_packages[] = trim($value);
216           }else{
217             $valid_packages[] = trim($value);
218           }
219         }
220         if(count($invalid_packages)){
221           $str = implode(", ",$invalid_packages);
222           msg_dialog::display(_("Invalid package names"), 
223               sprintf(_("The following package names don't match the Debian policy: %s"),$str),
224               ERROR_DIALOG);
225         }
228         // If we have a complete list of valid packages, add them
229         if(count($valid_packages)){
231           foreach($valid_packages as $key =>  $value){
232             if(array_key_exists($value,$this->usedPackages)) {
233               unset($valid_packages[$key]);
234             }
235           }
237           // Query SI-Deamon for additional package information
238           $daemon       = new gosaSupportDaemon();
239           $query_attrs  = array("distribution", "package","version", "section", "description", "timestamp");
240           $do_si_query  = true;
243           foreach ($valid_packages as $value) {
244             
245             if( $do_si_query == true ) {
246               $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
247               if( ! $daemon->is_error()){
248                 
249                 if(count($res)){
251                   // We just use the last answer - there shouldn't be multiple
252                   $res_attrs = array_pop( $res );
253                   $this->list[$value] = $res_attrs;
254                   $this->usedPackages[$value] = $res_attrs['PACKAGE'];
256                 }else{
257                   $this->usedPackages[$value] = $value;
258                 }
259               }else{
260                 msg_dialog::display(_("Service infrastructure"),
261                     msgPool::siError($daemon->get_error()),
262                     ERROR_DIALOG);
263                 $do_si_query = false;
264               }
265             }
266           }
268           ksort($this->usedPackages);
270           /* Generate package list */
271           $this->list= $this->genPkgs(TRUE);
272         }
273       }
274     }
276     // Open the packageSelect dialog to allow adding packages out of a list.
277     if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage") && !preg_match("/freeze/",$this->FAIstate)){
278       $this->packageSelect = new packageSelect($this->config, get_userinfo());
279       session::set('packageSelect_Release',$this->FAIdebianRelease);
280       $this->dialog =true;
281     }
283     // Close packageSelect dialog.
284     if(isset($_POST['packageSelect_cancel'])){
285       $this->packageSelect = FALSE;
286       $this->dialog =FALSE;
287     }
289     // Close packageSelect dialog and add the selected packages.
290     if(isset($_POST['packageSelect_save']) && $this->packageSelect instanceOf packageSelect){
291       if(!preg_match("/freeze/i", $this->FAIstate)){
292         $use = $this->packageSelect->save();
294         foreach($use as $pkg){
295           $item = array();
296           for($i =0; $i < $pkg['count']; $i++){
297             $item[$pkg[$i]] = $pkg[$pkg[$i]][0];
298           }
299           $this->usedPackages[$item['PACKAGE']] = $item['PACKAGE']; 
300         }
302         ksort($this->usedPackages);
304         /* Generate package list */
305         $this->list= $this->genPkgs(TRUE);
306       }
307       $this->packageSelect = FALSE;
308       $this->dialog =FALSE;
309     }
311     // Display package add dialog 
312     if($this->packageSelect instanceOf packageSelect){
314       session::set('filterBlacklist', array('PACKAGE' => $this->usedPackages));
315       return $this->packageSelect->execute();
316     }
319     /* Check image Posts 
320      */
321     foreach($_POST as $name => $value){
323       /******
324        * Mark as removed  
325        ******/
326       
327       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
328         $id = @postDecode(preg_replace("/^removal_package_(.*)$/","\\1",$name));
329         if(isset($this->usedPackages[$id])){
330           $pkg = $this->usedPackages[$id]; 
331           if (preg_match('/\-$/', $pkg)){
332             $pkg= preg_replace('/\-$/', '', $pkg);
333           } else {
334             $pkg= preg_replace('/$/', '-', $pkg);
335           }
336           $this->usedPackages[$id] = $pkg;
337         }
338         break;
339       }
341       /******
342        * Delete Pkgs   
343        ******/
344       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
345         $id = @postDecode(preg_replace("/^remove_package_(.*)$/","\\1",$name));
346         if(isset($this->usedPackages[$id])){
347           unset($this->usedPackages[$id]);
348         }
349         break;
350       }
352       /******
353        * Configure Pkgs   
354        ******/
355       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
356         $pkg = @postDecode(preg_replace("/^configure_package_(.*)$/","\\1",$name));
357          
358         if(isset($this->usedPackages[$pkg])){
360           /* Configuration dialog open*/
361           $pkg_config = array();
362           if(isset($this->ConfiguredPackages[$pkg])){
363             $pkg_config = $this->ConfiguredPackages[$pkg];
364           }
365           $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
366           $this->is_dialog =true;
367         }
368         break;
369       }
370     }
372     /* Abort package selection dialog */ 
373     if(isset($_POST['CancelSubObject'])){
374       $this->dialog = false;
375       $this->is_dialog=false;
376     }
378     /* Save Configuration */
379     if(isset($_POST['SaveObjectConfig'])){
380       if(!preg_match("/^freeze/", $this->FAIstate)){
381         $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
382       }
383       $this->dialog = false;
384       $this->is_dialog=false;
385     }
387     /* cancel configuration */     
388     if(isset($_POST['CancelObjectConfig'])){
389       $this->dialog = false;
390       $this->is_dialog=false;
391     }
393     /* Display dialog */ 
394     if($this->is_dialog){
395       $this->dialog->save_object();
396       return $this->dialog->execute();
397     }
400     /******
401      * Display UI / HTML / smarty 
402      ******/
404     /* Create divlist to display a list of all currently used packages
405      */
406     $divlist = new divSelectBox("faiPackages");
408     ksort($this->usedPackages);
409     if(is_array($this->usedPackages)){
410       foreach($this->usedPackages as $usedName => $name){
411     
412         $actions = "";
414         /* Append message if package is configured */
415         $configured = image('images/empty.png');
416         if(isset($this->ConfiguredPackages[$usedName])){
417           $configured = image('plugins/fai/images/package_configure.png','',_("Configured"));
418         }
420         /* Adapt used name if we're marked for removal */
421         $removal = image('images/empty.png');
422         if (preg_match('/\-$/', $name)){
423           $removal = image('plugins/fai/images/removal_mark.png','',_("Package marked for removal"));
424         }
426         /* Get Version */
427         $version = "&nbsp;";
428         if(isset($this->list[$usedName]['VERSION'])){
429           $version = $this->list[$usedName]['VERSION'];
430         }
431     
432         /* Get description */
433         $description = "&nbsp;";
434         if(isset($this->list[$usedName]['DESCRIPTION'])){
435           $description = postDecode($this->list[$usedName]['DESCRIPTION']);
436         }
437  
438         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
439           $actions.= image('plugins/fai/images/removal_mark.png',
440               'removal_package_'.postEncode($usedName),
441               _("Mark package for removal"));
442         }
444         if(isset($this->list[$usedName]['TEMPLATE']) && 
445            !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
446           $actions.= image('plugins/fai/images/package_configure.png',
447               'configure_package_'.postEncode($usedName),
448               _("Configure this package"));
449         }
450         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
451           $actions.= image('images/lists/trash.png',
452               'remove_package_'.postEncode($usedName),
453               _("Remove this package"));
454         }
456         $field1 = array("string" => $configured."&nbsp;".$removal,"attach" => "style='width:40px;'");
457         $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
458         $field3 = array("string" => $version);
459         $field4 = array("string" => htmlentities($description));
460         $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
461         $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
462       }
463     }
465     /* Assign variables */
466     foreach($this->attributes as $attrs){
467       $smarty->assign($attrs,$this->$attrs);
468     }
469     $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
471     /* Assign section to smarty */
472     $strsec = "";
473     foreach($this->FAIdebianSection as $sec){
474       $strsec .= $sec." ";
475     }
477     $tmp = $this->plInfo();
478     foreach($tmp['plProvidedAcls'] as $name => $translated){
479       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
480     }
481  
482     $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
483     $smarty->assign("divlist",$divlist->DrawList());
484     $smarty->assign("release" ,$this->FAIdebianRelease);
485     $smarty->assign("sections",$this->sections);
486     $smarty->assign("section" ,$strsec);
487     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
488     return($display);
489   }
492   /*! \brief  Removes this packageList from the ldap database 
493    */
494   function remove_from_parent()
495   {
496     $ldap = $this->config->get_ldap_link();
497     $ldap->cd ($this->dn);
498     $release = $this->parent->parent->fai_release;
499     $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
500     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
501     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
502     foreach($this->ConfiguredPackages as $pkgname => $attrs){
503       foreach($attrs as $name => $attr){
504         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
505         $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
506         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
507       }
508     }
509     $this->handle_post_events("remove");
510   }
513   /*! \brief  Collect all relevant POST vars for this plugin 
514    */
515   function save_object()
516   {
517     if(preg_match("/^freeze/", $this->FAIstate)) return;
518     plugin::save_object();
519   }
522   /*! \brief  Check given inputs for this package list
523       @return Array Containing all error messages, or an empty array if no error occured
524    */
525   function check()
526   {
527     /* Call common method to give check the hook */
528     $message= plugin::check();
530     if(count($this->usedPackages)==0){
531       $message[]= _("Please select a least one package!");
532     }
534     if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
535       $message[]=_("Please choose a valid release/section combination for your repository setup!");
536     }
538     /* Ensure that we do not overwrite an allready existing entry 
539      */
540     if($this->is_new){
541       $release = $this->parent->parent->fai_release;
542       $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
543       $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
544       if(isset($res[$this->cn])){
545         $message[] = msgPool::duplicated(_("Name"));
546       }
547     }
548     return ($message);
549   }
552   /*! \brief  Reload the list of cached packages.
553       @return Returns the currently cached list of packages. 
554    */
555   function genPkgs($force = false)
556   {
557     if(empty($this->FAIdebianRelease)) return;
559     if(!count($this->buffer) || $force){
560       $q = new gosaSupportDaemon();
561       $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
563       $packages = array_keys($this->usedPackages);
565       $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
566       if($q->is_error()){
567         msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
568       }else{
569         foreach($ret as $attr){
570           $this->buffer[$attr['PACKAGE']] = $attr;
571         }
572       }
573     }
574     return $this->buffer;
575   }
578   /*! \brief Save packages and their configuration to ldap 
579    */
580   function save()
581   {
583     /* Assemble release name */
584     if($this->FAIdebianRelease == "ClearFromCopyPaste"){
586       $current_release  = $this->parent->parent->fai_release;
587       $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/i', '', $current_release);
588       $tmp= preg_replace('/ou=/', '', $tmp);
589       $rev= array_reverse(explode(',', $tmp));
590       $this->FAIdebianRelease= "";
591       foreach ($rev as $part){
592         $this->FAIdebianRelease.= "/$part";
593       }
594       $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
595     }
597     plugin::save();
599     $ldap = $this->config->get_ldap_link();
601     $this->attrs['FAIpackage'] = array();
602     foreach($this->usedPackages as $pkg){
603       $this->attrs['FAIpackage'][] = $pkg;
604     } 
606     $this->attrs['FAIdebianSection'] = array();
607     foreach($this->FAIdebianSection as $sec){
608       $this->attrs['FAIdebianSection'][] = $sec;
609     }
611     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
612     
613     if($this->initially_was_account){
614       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
615     }else{
616       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
617     }
619     $ldap->cd($this->dn);
621     /* Save Package configurations */
622     foreach($this->ConfiguredPackages as $pkgname => $attrs){
623       foreach($attrs as $name => $attr){
624       
625         $pkgattrs = array();
627         foreach($attr as $n=>$v){
628           if(empty($v)) $v = array();
629         }
631         /* Set attributes */
632         $pkgattrs['objectClass'][]        = "FAIdebconfInfo";
634         $pkgattrs['FAIpackage']           = $pkgname;
635         $pkgattrs['FAIvariable']          = $name;
636         $pkgattrs['FAIvariableType']      = $attr['Type'];
637         $pkgattrs['FAIvariableContent']   = $attr['Value'];
638         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
640         /* Tag object */
641         $this->tag_attrs($pkgattrs, $pkgdn, $this->gosaUnitTag);
643         if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
645           if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
646             gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
647           }else{
648             FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
649           }
650         }
651       }
652     }
653   }
656   /*! \brief  Return plugin informations for acl handling 
657       @return Array ACL infos of this plugin.
658    */ 
659   static function plInfo()
660   {
661     return (array( 
662           "plShortName" => _("Package"),
663           "plDescription" => _("FAI Package list"),
664           "plSelfModify"  => FALSE,
665           "plDepends"     => array(),
666           "plPriority"    => 28,
667           "plSection"     => array("administration"),
668           "plCategory"    => array("fai"),
669           "plProvidedAcls" => array(
670             "cn"                => _("Name"),
671             "description"       => _("Description"),
672             "FAIpackage"        => _("Packages"),
673             "FAIdebianSection"  => _("Section")."&nbsp;("._("Readonly").")",
674             "FAIinstallMethod"  => _("Install Method"),
675             "FAIdebconfInfo"    => _("Package configuration"),
676             "FAIdebianRelease"  => _("Release")."&nbsp;("._("Readonly").")")
677           ));
678   }
681   /*! \brief prepares this plugin to be inserted after it was copied or cut.
682       @param Array  All attributes from the source object. 
683    */
684   function PrepareForCopyPaste($source)
685   {
686     plugin::PrepareForCopyPaste($source);
688     if(isset($source['FAIstate'][0])){
689       $this->FAIstate = $source['FAIstate'][0];
690     }
692     $this->FAIdebianRelease = "ClearFromCopyPaste";
694     if(isset($source['FAIpackage'])){
695       unset($source['FAIpackage']['count']);
696       foreach($source['FAIpackage'] as $pkg){
697         $this->usedPackages[$pkg] = $pkg;
698       }
699       ksort($this->usedPackages);
700     }else{
701       $this->usedPackages = array();
702     }
704     if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
705       $this->FAIdebianSection = array();
706       for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
707         $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
708       }
709     }
711     /* Create one filter with all package names, 
712        instead of calling $ldap->search for every single package 
713      */
714     $PackageFilter = "";
715     foreach($this->usedPackages as $name){
716       $PackageFilter .= "(FAIpackage=".$name.")";
717     }
718     $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
720     /* Search for configuration objects */ 
721     $ldap = $this->config->get_ldap_link();
722     $ldap->cd($source['dn']);
723     $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
725     /* Walk through configurations and append them to our list of ConfiguredPackages */
726     while($attr = $ldap->fetch()){
728       /* Skip objects, that are tagged as removed */
729       if(isset($object['FAIstate'][0])){
730         if(preg_match("/removed$/",$attr['FAIstate'][0])){
731           continue;
732         }
733       }
735       $tmp =array(); 
736       $tmp['Name']  = $attr['FAIvariable'][0];
737       $tmp['Type']  = $attr['FAIvariableType'][0];
739       if (isset($attr['FAIvariableContent'][0])){
740         if(!in_array($attr['FAIvariableType'],array("multiselect"))){
741           $tmp['Value'] = $attr['FAIvariableContent'][0];
742         }else{
743           $content = array();        
744           unset($attr['FAIvariableContent']['count']);
745           foreach($attr['FAIvariableContent'] as $attr){
746             $tmp['Value'][] = $attr;
747           }
748         }
749         $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
750       }
751     }
752   }
755   /*! \brief  Returns a list of all configured servers with repositories.
756       @return Array  All repository server 
757    */
758   function getServerInfos()
759   {
760     $ret = array();
761     $ldap = $this->config->get_ldap_link();
762     $ldap->cd($this->config->current['BASE']);
763     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
764     while($attrs = $ldap->fetch()){
765       if(isset($attrs['FAIrepository'])){
766         for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
767           $obj = $attrs['FAIrepository'][$i];
768           $tmp = explode("|",$obj);
769           if(count($tmp)==4){
770             foreach(explode(",",$tmp[3]) as $sec){
771               if(!empty($sec)){
772                 $ret[$tmp[2]][] =  $sec;
773               }
774             }
775           }
776         }
777       }
778     }
779     return($ret);
780   }
783   /*! \brief  Used for copy & paste.
784     Returns a HTML input mask, which allows to change the cn of this entry.
785     @param  Array   Array containing current status && a HTML template.
786    */
787   function getCopyDialog()
788   {
789     $vars = array("cn");
790     $smarty = get_smarty();
791     $smarty->assign("cn", htmlentities($this->cn));
792     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
793     $ret = array();
794     $ret['string'] = $str;
795     $ret['status'] = "";
796     return($ret);
797   }
800   /*! \brief  Used for copy & paste.
801     Some entries must be renamed to avaoid duplicate entries.
802    */
803   function saveCopyDialog()
804   {
805     if(isset($_POST['cn'])){
806       $this->cn = get_post('cn');
807     }
808   }
811 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
812 ?>