Code

d32f26a64d41e27de24dc2c150bd47363a5deaee
[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 = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\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 = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\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 = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\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 = "<img src='images/empty.png' alt=' '  class='center'>";
416         if(isset($this->ConfiguredPackages[$usedName])){
417           $configured = "<img src='plugins/fai/images/package_configure.png' alt='"._("Configured")."'
418                       title='"._("Configured")."' class='center'>";
419         }
421         /* Adapt used name if we're marked for removal */
422         $removal = "<img src='images/empty.png' alt=' '  class='center'>";
423         if (preg_match('/\-$/', $name)){
424           $removal = "<img src='plugins/fai/images/removal_mark.png' alt='"._("Package marked for removal")."'
425                       title='"._("Package marked for removal")."' class='center'>";
426         }
428         /* Get Version */
429         $version = "&nbsp;";
430         if(isset($this->list[$usedName]['VERSION'])){
431           $version = $this->list[$usedName]['VERSION'];
432         }
433     
434         /* Get description */
435         $description = "&nbsp;";
436         if(isset($this->list[$usedName]['DESCRIPTION'])){
437           $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
438         }
439  
440         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
441           $actions = "<input type='image' class='center' title='"._("Mark package for removal")."' 
442             src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >";
443         }
445         if(isset($this->list[$usedName]['TEMPLATE']) && 
446            !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
447           $actions.= "&nbsp;<input type='image' class='center' title='"._("Configure this package")."' 
448             src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >";
449         }
450         if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
451           $actions.= "&nbsp;<input type='image' class='center' title='"._("Remove this package")."' 
452             src='images/lists/trash.png' name='remove_package_".base64_encode($usedName)."' >";
453         }
455         $field1 = array("string" => $configured."&nbsp;".$removal,"attach" => "style='width:40px;'");
456         $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
457         $field3 = array("string" => $version);
458         $field4 = array("string" => $description);
459         $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
460         $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
461       }
462     }
464     /* Assign variables */
465     foreach($this->attributes as $attrs){
466       $smarty->assign($attrs,$this->$attrs);
467     }
468     $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
470     /* Assign section to smarty */
471     $strsec = "";
472     foreach($this->FAIdebianSection as $sec){
473       $strsec .= $sec." ";
474     }
476     $tmp = $this->plInfo();
477     foreach($tmp['plProvidedAcls'] as $name => $translated){
478       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
479     }
480  
481     $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
482     $smarty->assign("divlist",$divlist->DrawList());
483     $smarty->assign("release" ,$this->FAIdebianRelease);
484     $smarty->assign("sections",$this->sections);
485     $smarty->assign("section" ,$strsec);
486     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
487     return($display);
488   }
491   /*! \brief  Removes this packageList from the ldap database 
492    */
493   function remove_from_parent()
494   {
495     $ldap = $this->config->get_ldap_link();
496     $ldap->cd ($this->dn);
497     $release = $this->parent->parent->fai_release;
498     $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
499     FAI::prepare_to_save_FAI_object($use_dn,array(),true);
500     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
501     foreach($this->ConfiguredPackages as $pkgname => $attrs){
502       foreach($attrs as $name => $attr){
503         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
504         $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
505         FAI::prepare_to_save_FAI_object($use_dn,array(),true);
506       }
507     }
508     $this->handle_post_events("remove");
509   }
512   /*! \brief  Collect all relevant POST vars for this plugin 
513    */
514   function save_object()
515   {
516     if(preg_match("/^freeze/", $this->FAIstate)) return;
517     plugin::save_object();
518   }
521   /*! \brief  Check given inputs for this package list
522       @return Array Containing all error messages, or an empty array if no error occured
523    */
524   function check()
525   {
526     /* Call common method to give check the hook */
527     $message= plugin::check();
529     if(count($this->usedPackages)==0){
530       $message[]= _("Please select a least one package!");
531     }
533     if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
534       $message[]=_("Please choose a valid release/section combination for your repository setup!");
535     }
537     /* Ensure that we do not overwrite an allready existing entry 
538      */
539     if($this->is_new){
540       $release = $this->parent->parent->fai_release;
541       $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
542       $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
543       if(isset($res[$this->cn])){
544         $message[] = msgPool::duplicated(_("Name"));
545       }
546     }
547     return ($message);
548   }
551   /*! \brief  Reload the list of cached packages.
552       @return Returns the currently cached list of packages. 
553    */
554   function genPkgs($force = false)
555   {
556     if(empty($this->FAIdebianRelease)) return;
558     if(!count($this->buffer) || $force){
559       $q = new gosaSupportDaemon();
560       $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
562       $packages = array_keys($this->usedPackages);
564       $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
565       if($q->is_error()){
566         msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
567       }else{
568         foreach($ret as $attr){
569           $this->buffer[$attr['PACKAGE']] = $attr;
570         }
571       }
572     }
573     return $this->buffer;
574   }
577   /*! \brief Save packages and their configuration to ldap 
578    */
579   function save()
580   {
582     /* Assemble release name */
583     if($this->FAIdebianRelease == "ClearFromCopyPaste"){
585       $current_release  = $this->parent->parent->fai_release;
586       $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/i', '', $current_release);
587       $tmp= preg_replace('/ou=/', '', $tmp);
588       $rev= array_reverse(explode(',', $tmp));
589       $this->FAIdebianRelease= "";
590       foreach ($rev as $part){
591         $this->FAIdebianRelease.= "/$part";
592       }
593       $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
594     }
596     plugin::save();
598     $ldap = $this->config->get_ldap_link();
600     $this->attrs['FAIpackage'] = array();
601     foreach($this->usedPackages as $pkg){
602       $this->attrs['FAIpackage'][] = $pkg;
603     } 
605     $this->attrs['FAIdebianSection'] = array();
606     foreach($this->FAIdebianSection as $sec){
607       $this->attrs['FAIdebianSection'][] = $sec;
608     }
610     FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
611     
612     if($this->initially_was_account){
613       new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
614     }else{
615       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
616     }
618     $ldap->cd($this->dn);
620     /* Save Package configurations */
621     foreach($this->ConfiguredPackages as $pkgname => $attrs){
622       foreach($attrs as $name => $attr){
623       
624         $pkgattrs = array();
626         foreach($attr as $n=>$v){
627           if(empty($v)) $v = array();
628         }
630         /* Set attributes */
631         $pkgattrs['objectClass'][]        = "FAIdebconfInfo";
633         $pkgattrs['FAIpackage']           = $pkgname;
634         $pkgattrs['FAIvariable']          = $name;
635         $pkgattrs['FAIvariableType']      = $attr['Type'];
636         $pkgattrs['FAIvariableContent']   = $attr['Value'];
637         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
639         /* Tag object */
640         $this->tag_attrs($pkgattrs, $pkgdn, $this->gosaUnitTag);
642         if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
644           if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
645             gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
646           }else{
647             FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
648           }
649         }
650       }
651     }
652   }
655   /*! \brief  Return plugin informations for acl handling 
656       @return Array ACL infos of this plugin.
657    */ 
658   static function plInfo()
659   {
660     return (array( 
661           "plShortName" => _("Package"),
662           "plDescription" => _("FAI Package list"),
663           "plSelfModify"  => FALSE,
664           "plDepends"     => array(),
665           "plPriority"    => 28,
666           "plSection"     => array("administration"),
667           "plCategory"    => array("fai"),
668           "plProvidedAcls" => array(
669             "cn"                => _("Name"),
670             "description"       => _("Description"),
671             "FAIpackage"        => _("Packages"),
672             "FAIdebianSection"  => _("Section")."&nbsp;("._("Readonly").")",
673             "FAIinstallMethod"  => _("Install Method"),
674             "FAIdebconfInfo"    => _("Package configuration"),
675             "FAIdebianRelease"  => _("Release")."&nbsp;("._("Readonly").")")
676           ));
677   }
680   /*! \brief prepares this plugin to be inserted after it was copied or cut.
681       @param Array  All attributes from the source object. 
682    */
683   function PrepareForCopyPaste($source)
684   {
685     plugin::PrepareForCopyPaste($source);
687     if(isset($source['FAIstate'][0])){
688       $this->FAIstate = $source['FAIstate'][0];
689     }
691     $this->FAIdebianRelease = "ClearFromCopyPaste";
693     if(isset($source['FAIpackage'])){
694       unset($source['FAIpackage']['count']);
695       foreach($source['FAIpackage'] as $pkg){
696         $this->usedPackages[$pkg] = $pkg;
697       }
698       ksort($this->usedPackages);
699     }else{
700       $this->usedPackages = array();
701     }
703     if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
704       $this->FAIdebianSection = array();
705       for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
706         $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
707       }
708     }
710     /* Create one filter with all package names, 
711        instead of calling $ldap->search for every single package 
712      */
713     $PackageFilter = "";
714     foreach($this->usedPackages as $name){
715       $PackageFilter .= "(FAIpackage=".$name.")";
716     }
717     $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
719     /* Search for configuration objects */ 
720     $ldap = $this->config->get_ldap_link();
721     $ldap->cd($source['dn']);
722     $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
724     /* Walk through configurations and append them to our list of ConfiguredPackages */
725     while($attr = $ldap->fetch()){
727       /* Skip objects, that are tagged as removed */
728       if(isset($object['FAIstate'][0])){
729         if(preg_match("/removed$/",$attr['FAIstate'][0])){
730           continue;
731         }
732       }
734       $tmp =array(); 
735       $tmp['Name']  = $attr['FAIvariable'][0];
736       $tmp['Type']  = $attr['FAIvariableType'][0];
738       if (isset($attr['FAIvariableContent'][0])){
739         if(!in_array($attr['FAIvariableType'],array("multiselect"))){
740           $tmp['Value'] = $attr['FAIvariableContent'][0];
741         }else{
742           $content = array();        
743           unset($attr['FAIvariableContent']['count']);
744           foreach($attr['FAIvariableContent'] as $attr){
745             $tmp['Value'][] = $attr;
746           }
747         }
748         $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
749       }
750     }
751   }
754   /*! \brief  Returns a list of all configured servers with repositories.
755       @return Array  All repository server 
756    */
757   function getServerInfos()
758   {
759     $ret = array();
760     $ldap = $this->config->get_ldap_link();
761     $ldap->cd($this->config->current['BASE']);
762     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
763     while($attrs = $ldap->fetch()){
764       if(isset($attrs['FAIrepository'])){
765         for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
766           $obj = $attrs['FAIrepository'][$i];
767           $tmp = explode("|",$obj);
768           if(count($tmp)==4){
769             foreach(explode(",",$tmp[3]) as $sec){
770               if(!empty($sec)){
771                 $ret[$tmp[2]][] =  $sec;
772               }
773             }
774           }
775         }
776       }
777     }
778     return($ret);
779   }
782   /*! \brief  Used for copy & paste.
783     Returns a HTML input mask, which allows to change the cn of this entry.
784     @param  Array   Array containing current status && a HTML template.
785    */
786   function getCopyDialog()
787   {
788     $vars = array("cn");
789     $smarty = get_smarty();
790     $smarty->assign("cn", htmlentities($this->cn));
791     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
792     $ret = array();
793     $ret['string'] = $str;
794     $ret['status'] = "";
795     return($ret);
796   }
799   /*! \brief  Used for copy & paste.
800     Some entries must be renamed to avaoid duplicate entries.
801    */
802   function saveCopyDialog()
803   {
804     if(isset($_POST['cn'])){
805       $this->cn = get_post('cn');
806     }
807   }
810 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
811 ?>