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();
26 var $ConfigurationsToRemove = array();
28 /* Specific attributes */
29 var $cn = ""; // The class name for this object
30 var $description = ""; // The description for this set of partitions
31 var $is_dialog = false; // specifies which buttons will be shown to save or abort
32 var $SubObjects = array(); // All leafobjects of this object
34 var $FAIdebianRelease = ""; // The selected release
35 var $FAIdebianSection = array(); // selected section
36 var $FAIinstallMethod = "aptitude"; // hard coded
38 var $sections = array(); // All section types
40 var $list = NULL;
42 var $usedPackages = array();
43 var $buffer = NULL;
44 var $newDialogShown = false;
46 var $FAIstate = "";
47 var $view_logged = FALSE;
48 var $base;
49 var $FAIpackage ;
51 var $FAIinstallMethods = array( "install", "ninstall", "remove",
52 "dselect-upgrade", "taskinst", "taskrm",
53 "hold", "clean", "aptitude", "aptitude-r",
54 "pending", "dpkgc" );
56 var $direct_packages_add = FALSE;
57 var $configure_dialog_shown = FALSE;
59 function faiPackage (&$config, $dn= NULL)
60 {
61 /* Load Attributes */
62 plugin::plugin ($config, $dn);
64 /* If "dn==new" we try to create a new entry
65 * Else we must read all objects from ldap which belong to this entry.
66 * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
67 */
68 if($dn != "new"){
69 $this->dn =$dn;
71 /* Check if there are already some packages in this list
72 */
73 $this->usedPackages = array();
74 if(isset($this->attrs['FAIpackage'])){
75 unset($this->attrs['FAIpackage']['count']);
76 foreach($this->attrs['FAIpackage'] as $pkg){
77 $name = preg_replace("/\-$/","",$pkg);
78 $this->usedPackages[$name] = $pkg;
79 }
80 ksort($this->usedPackages);
81 }
83 /* Fetch all package configurations from ldap
84 */
85 $PackageFilter = "";
86 foreach($this->usedPackages as $name => $value){
87 $PackageFilter .= "(FAIpackage=".$name.")";
88 }
89 /* Also fetch d-i */
90 $PackageFilter .= "(FAIpackage=d-i)";
92 $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
94 /* Search for configuration objects */
95 $ldap = $this->config->get_ldap_link();
96 $ldap->cd($this->dn);
97 $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
98 "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
100 /* Walk through configurations and append them to our list of ConfiguredPackages
101 */
102 while($attr = $ldap->fetch()){
104 /* Skip objects, that are tagged as removed */
105 if(isset($object['FAIstate'][0])){
106 if(preg_match("/removed$/",$attr['FAIstate'][0])){
107 continue;
108 }
109 }
111 $tmp =array();
112 $tmp['Name'] = $attr['FAIvariable'][0];
113 $tmp['Type'] = $attr['FAIvariableType'][0];
115 if (isset($attr['FAIvariableContent'][0])){
116 if(!in_array($attr['FAIvariableType'],array("multiselect"))){
117 $tmp['Value'] = $attr['FAIvariableContent'][0];
118 }else{
119 $content = array();
120 unset($attr['FAIvariableContent']['count']);
121 foreach($attr['FAIvariableContent'] as $attr){
122 $tmp['Value'][] = $attr;
123 }
124 }
125 $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
126 }
127 else {
128 $tmp['Value'] = "";
129 $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
130 }
131 }
133 $this->FAIdebianSection = array();
134 if(isset($this->attrs['FAIdebianSection'])){
135 for($i = 0 ; $i < $this->attrs['FAIdebianSection']['count'] ; $i++ ){
136 $sec = $this->attrs['FAIdebianSection'][$i];
137 $this->FAIdebianSection[$sec]=$sec;
138 }
139 }
140 $this->FAIpackage = array();
142 } // ENDE dn != new
144 $methods = array();
145 foreach($this->FAIinstallMethods as $method){
146 $methods[$method] = $method;
147 }
148 $this->FAIinstallMethods = $methods;
150 /* Check if we exist already - no need to ask for revisions, etc. then */
151 if ($this->dn != "new"){
152 $this->newDialogShown= true;
153 }
154 $this->is_new = FALSE;
155 if($this->dn == "new"){
156 $this->is_new =TRUE;
157 }
158 /* Check weither its allowed to directly add packages */
159 $direct_packages_add = $config->search("faiManagement","direct_packages_add",array("menu"));
160 if (preg_match("/^true$/i", $direct_packages_add) || preg_match("/yes/i", $direct_packages_add)) {
161 $this->direct_packages_add = TRUE;
162 }
164 /* Generate package list */
165 $this->list= $this->genPkgs(TRUE);
166 }
169 function execute()
170 {
171 /* Call parent execute */
172 plugin::execute();
174 if($this->is_account && !$this->view_logged){
175 $this->view_logged = TRUE;
176 new log("view","fai/".get_class($this),$this->dn);
177 }
179 /* Fill templating stuff */
180 $smarty= get_smarty();
181 $display= "";
183 /******
184 * Initialize a new Package List with release and section name
185 ******/
187 if(!$this->is_account){
189 /* Assemble release name */
190 $release = $this->parent->parent->fai_release;
191 $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $release);
192 $tmp= preg_replace('/ou=/', '', $tmp);
193 $rev= array_reverse(split(',', $tmp));
194 $this->FAIdebianRelease= "/";
195 foreach ($rev as $part){
196 $this->FAIdebianRelease.= "/$part";
197 }
198 $this->FAIdebianRelease= preg_replace('#^[/]*#', '', $this->FAIdebianRelease);
200 /* Assemble sections */
201 $repos= $this->getServerInfos();
202 if(isset($repos[$this->FAIdebianRelease])){
203 $this->FAIdebianSection= $repos[$this->FAIdebianRelease];
204 $this->FAIdebianSection= array_unique($this->FAIdebianSection);
205 }
207 /* Assign Repository settings*/
208 $this->is_account = true;
209 }
212 /******
213 * Add
214 ******/
216 if(isset($_POST['AddManualpkg']) &&
217 isset($_POST['addPpkgsText']) &&
218 strlen($_POST['addPpkgsText']) &&
219 $this->acl_is_writeable("FAIpackage") &&
220 !preg_match("/freeze/",$this->FAIstate)){
222 // Check all splitted packages for valid package names
223 $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
224 $valid_packages = array();
225 if( is_array($add_packages) ) {
226 $invalid_packages = array();
227 foreach ($add_packages as $value) {
228 if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
229 $invalid_packages[] = trim($value);
230 }else{
231 $valid_packages[] = trim($value);
232 }
233 }
234 if(count($invalid_packages)){
235 $str = implode(", ",$invalid_packages);
236 msg_dialog::display(_("Invalid package names"),
237 sprintf(_("The following package names don't match the Debian policy: %s"),$str),
238 ERROR_DIALOG);
239 }
242 // If we have a complete list of valid packages, add them
243 if(count($valid_packages)){
245 foreach($valid_packages as $key => $value){
246 if(array_key_exists($value,$this->usedPackages)) {
247 unset($valid_packages[$key]);
248 }
249 }
251 // Query SI-Deamon for additional package information
252 $daemon = new gosaSupportDaemon();
253 $query_attrs = array("distribution", "package","version", "section", "description", "timestamp");
254 $do_si_query = true;
257 foreach ($valid_packages as $value) {
258 if( $do_si_query == true ) {
259 $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
260 if( ! $daemon->is_error()){
262 if(count($res)){
264 // We just use the last answer - there shouldn't be multiple
265 $res_attrs = array_pop( $res );
266 $this->list[$value] = $res_attrs;
267 $this->usedPackages[$value] = $res_attrs['PACKAGE'];
269 }else{
270 $this->usedPackages[$value] = $value;
271 }
272 }else{
273 msg_dialog::display(_("Service infrastructure"),
274 msgPool::siError($daemon->get_error()),
275 ERROR_DIALOG);
276 $do_si_query = false;
277 }
278 }
279 }
281 ksort($this->usedPackages);
283 /* Generate package list */
284 $this->list= $this->genPkgs(TRUE);
285 }
286 }
287 }
289 if(isset($_POST['EditConfigurations']) &&
290 $this->acl_is_writeable("FAIpackage")) {
291 $this->dialog = new faiDebconfConfigurations($this->config, $this->dn, $this);
292 $this->dialog->set_acl_base($this->acl_base);
293 $this->is_dialog = true;
294 }
296 /* + was pressed to open the package dialog */
297 if(isset($_POST['Addpkg']) &&
298 $this->acl_is_writeable("FAIpackage") &&
299 !preg_match("/freeze/",$this->FAIstate)){
300 $this->dialog = new faiPackageEntry($this->config, $this->FAIdebianRelease,$this->usedPackages);
301 $this->is_dialog =true;
302 }
305 /* Check image Posts
306 */
307 foreach($_POST as $name => $value){
309 /******
310 * Mark as removed
311 ******/
313 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
314 $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
315 if(isset($this->usedPackages[$id])){
316 $pkg = $this->usedPackages[$id];
317 if (preg_match('/\-$/', $pkg)){
318 $pkg= preg_replace('/\-$/', '', $pkg);
319 } else {
320 $pkg= preg_replace('/$/', '-', $pkg);
321 }
322 $this->usedPackages[$id] = $pkg;
323 }
324 break;
325 }
327 /******
328 * Delete Pkgs
329 ******/
330 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
331 $id = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\1",$name));
332 if(isset($this->usedPackages[$id])){
333 unset($this->usedPackages[$id]);
334 }
335 break;
336 }
338 /******
339 * Configure Pkgs
340 ******/
341 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
342 $pkg = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\1",$name));
344 if(isset($this->usedPackages[$pkg])){
346 /* Configuration dialog open*/
347 $pkg_config = array();
348 if(isset($this->ConfiguredPackages[$pkg])){
349 $pkg_config = $this->ConfiguredPackages[$pkg];
350 }
351 $this->configure_dialog_shown = TRUE;
352 $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
353 $this->is_dialog =true;
354 }
355 break;
356 }
357 }
359 /* Abort package selection dialog */
360 if(isset($_POST['CancelSubObject'])){
361 $this->dialog = false;
362 $this->is_dialog=false;
363 }
365 /* attach new packages */
366 if(isset($_POST['SaveSubObject'])) {
367 if(!preg_match("/freeze/i", $this->FAIstate)){
368 $this->dialog->save_object();
369 if(count($this->dialog->check())){
370 foreach($this->dialog->check() as $msgs){
371 msg_dialog::display(_("Error"), $msgs, ERROR_DIALOG);
372 }
373 }else{
374 $use = $this->dialog->save();
375 $this->usedPackages = $use;
376 $this->dialog = false;
377 $this->is_dialog=false;
378 ksort($this->usedPackages);
380 /* Generate package list */
381 $this->list= $this->genPkgs(TRUE);
382 }
383 }else{
384 $this->dialog = false;
385 $this->is_dialog=false;
386 }
387 }
389 /* Save Configuration */
390 if(isset($_POST['SaveObjectConfig']) && $this->configure_dialog_shown){
391 if(!preg_match("/^freeze/", $this->FAIstate)){
392 $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
393 }
394 $this->dialog = false;
395 $this->is_dialog=false;
396 $this->configure_dialog_shown=false;
397 }
399 if (isset($_POST['SaveDebconfConfig'])){
400 $this->dialog->save_object();
401 $msgs = $this->dialog->check();
402 if(count($msgs)>0) {
403 foreach($msgs as $msg){
404 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
405 }
406 } else {
407 if(!preg_match("/^freeze/", $this->FAIstate)){
408 $this->ConfiguredPackages= $this->dialog->save();
409 $this->ConfigurationsToRemove = $this->dialog->to_remove;
410 }
411 $this->dialog = false;
412 $this->is_dialog = false;
413 }
414 }
416 /* cancel configuration */
417 if(isset($_POST['CancelObjectConfig']) && $this->configure_dialog_shown){
418 $this->dialog = false;
419 $this->is_dialog=false;
420 $this->configure_dialog_shown=false;
421 }
423 /* Display dialog */
424 if($this->is_dialog){
425 $this->dialog->save_object();
426 return $this->dialog->execute();
427 }
430 /******
431 * Display UI / HTML / smarty
432 ******/
434 /* Create divlist to display a list of all currently used packages
435 */
436 $divlist = new divSelectBox("faiPackages");
437 $divlist->setHeight(600);
439 ksort($this->usedPackages);
440 if(is_array($this->usedPackages)){
441 foreach($this->usedPackages as $usedName => $name){
443 $actions = "";
445 /* Append message if package is configured */
446 $configured = "<img src='images/empty.png' alt=' ' class='center'>";
447 if(isset($this->ConfiguredPackages[$usedName])){
448 $configured = "<img src='plugins/fai/images/package_configure.png' alt='"._("Configured")."'
449 title='"._("Configured")."' class='center'>";
450 }
452 /* Adapt used name if we're marked for removal */
453 $removal = "<img src='images/empty.png' alt=' ' class='center'>";
454 if (preg_match('/\-$/', $name)){
455 $removal = "<img src='plugins/fai/images/removal_mark.png' alt='"._("Package marked for removal")."'
456 title='"._("Package marked for removal")."' class='center'>";
457 }
459 /* Get Version */
460 $version = " ";
461 if(isset($this->list[$usedName]['VERSION'])){
462 $version = $this->list[$usedName]['VERSION'];
463 }
465 /* Get description */
466 $description = " ";
467 if(isset($this->list[$usedName]['DESCRIPTION'])){
468 $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
469 }
471 if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
472 $actions = "<input type='image' class='center' title='"._("Mark package for removal")."'
473 src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >";
474 }
476 if(isset($this->list[$usedName]['TEMPLATE']) &&
477 !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
478 $actions.= " <input type='image' class='center' title='"._("Configure this package")."'
479 src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >";
480 }
481 if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
482 $actions.= " <input type='image' class='center' title='"._("Remove this package")."'
483 src='images/lists/trash.png' name='remove_package_".base64_encode($usedName)."' >";
484 }
486 $field1 = array("string" => $configured." ".$removal,"attach" => "style='width:40px;'");
487 $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
488 $field3 = array("string" => $version);
489 $field4 = array("string" => $description);
490 $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
491 $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
492 }
493 }
495 /* Assign variables */
496 foreach($this->attributes as $attrs){
497 $smarty->assign($attrs,$this->$attrs);
498 }
499 $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
501 /* Assign section to smarty */
502 $strsec = "";
503 foreach($this->FAIdebianSection as $sec){
504 $strsec .= $sec." ";
505 }
507 $tmp = $this->plInfo();
508 foreach($tmp['plProvidedAcls'] as $name => $translated){
509 $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
510 }
512 $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
513 $smarty->assign("divlist",$divlist->DrawList());
514 $smarty->assign("release" ,$this->FAIdebianRelease);
515 $smarty->assign("sections",$this->sections);
516 $smarty->assign("section" ,$strsec);
517 $smarty->assign("direct_packages_add", $this->direct_packages_add);
518 $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
519 return($display);
520 }
523 /*! \brief Removes this packageList from the ldap database
524 */
525 function remove_from_parent()
526 {
527 $ldap = $this->config->get_ldap_link();
528 $ldap->cd ($this->dn);
529 $release = $this->parent->parent->fai_release;
530 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
531 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
532 new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
533 foreach($this->ConfiguredPackages as $pkgname => $attrs){
534 foreach($attrs as $name => $attr){
535 $pkgdn = "FAIvariable=".$name.",".$this->dn;
536 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
537 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
538 }
539 }
540 $this->handle_post_events("remove");
541 }
544 /*! \brief Collect all relevant POST vars for this plugin
545 */
546 function save_object()
547 {
548 if(preg_match("/^freeze/", $this->FAIstate)) return;
549 plugin::save_object();
550 }
553 /*! \brief Check given inputs for this package list
554 @return Array Containing all error messages, or an empty array if no error occured
555 */
556 function check()
557 {
558 /* Call common method to give check the hook */
559 $message= plugin::check();
561 if(count($this->usedPackages)==0){
562 $message[]= _("Please select a least one package!");
563 }
565 if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
566 $message[]=_("Please choose a valid release/section combination for your repository setup!");
567 }
569 /* Ensure that we do not overwrite an allready existing entry
570 */
571 if($this->is_new){
572 $release = $this->parent->parent->fai_release;
573 $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
574 $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
575 if(isset($res[$this->cn])){
576 $message[] = msgPool::duplicated(_("Name"));
577 }
578 }
579 return ($message);
580 }
583 /*! \brief Reload the list of cached packages.
584 @return Returns the currently cached list of packages.
585 */
586 function genPkgs($force = false)
587 {
588 if(empty($this->FAIdebianRelease)) return;
590 if(!count($this->buffer) || $force){
591 $q = new gosaSupportDaemon();
592 $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
594 $packages = array_keys($this->usedPackages);
596 $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
597 if($q->is_error()){
598 msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
599 }else{
600 foreach($ret as $attr){
601 $this->buffer[$attr['PACKAGE']] = $attr;
602 }
603 }
604 }
605 return $this->buffer;
606 }
609 /*! \brief Save packages and their configuration to ldap
610 */
611 function save()
612 {
614 /* Assemble release name */
615 if($this->FAIdebianRelease == "ClearFromCopyPaste"){
617 $current_release = $this->parent->parent->fai_release;
618 $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $current_release);
619 $tmp= preg_replace('/ou=/', '', $tmp);
620 $rev= array_reverse(split(',', $tmp));
621 $this->FAIdebianRelease= "";
622 foreach ($rev as $part){
623 $this->FAIdebianRelease.= "/$part";
624 }
625 $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
626 }
628 plugin::save();
630 $ldap = $this->config->get_ldap_link();
632 $this->attrs['FAIpackage'] = array();
633 foreach($this->usedPackages as $pkg){
634 $this->attrs['FAIpackage'][] = $pkg;
635 }
637 $this->attrs['FAIdebianSection'] = array();
638 foreach($this->FAIdebianSection as $sec){
639 $this->attrs['FAIdebianSection'][] = $sec;
640 }
642 FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
644 if($this->initially_was_account){
645 new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
646 }else{
647 new log("create","fai/".get_class($this),$this->dn,$this->attributes);
648 }
650 $ldap->cd($this->dn);
652 /* Save Package configurations */
653 foreach($this->ConfiguredPackages as $pkgname => $attrs){
654 foreach($attrs as $name => $attr){
655 $pkgattrs = array();
657 foreach($attr as $n=>$v){
658 if(empty($v)) $v = array();
659 }
661 /* Set attributes */
662 $pkgattrs['objectClass'][] = "FAIdebconfInfo";
664 $pkgattrs['FAIpackage'] = $pkgname;
665 $pkgattrs['FAIvariable'] = $name;
666 $pkgattrs['FAIvariableType'] = $attr['Type'];
667 $pkgattrs['FAIvariableContent'] = $attr['Value'];
668 $pkgdn = "FAIvariable=".$name.",".$this->dn;
670 if (is_array($pkgattrs['FAIvariableContent'])) {
671 $ldap = $this->config->get_ldap_link();
672 $ldap->cat($pkgdn);
673 if (!$ldap->count()) {
674 /* Do not try to set FAIvariableContent to empty array if this
675 * debconfInfo object is new */
676 unset($pkgattrs['FAIvariableContent']);
677 }
678 }
680 /* Tag object */
681 $ui= get_userinfo();
682 $this->tag_attrs($pkgattrs, $pkgdn, $ui->gosaUnitTag);
684 if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
686 if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
687 gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
688 }else{
689 FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
690 }
691 }
692 }
693 }
695 /* Remove obsolete configurations */
696 foreach($this->ConfigurationsToRemove as $package => $attr) {
697 foreach($attr as $name => $attr) {
698 $dn = "FAIvariable=".$name.",".$this->dn;
699 $ldap = $this->config->get_ldap_link();
700 $ldap->cd($dn);
701 $ldap->rmdir($dn);
702 }
703 }
704 }
707 /*! \brief Return plugin informations for acl handling
708 @return Array ACL infos of this plugin.
709 */
710 static function plInfo()
711 {
712 return (array(
713 "plShortName" => _("Package"),
714 "plDescription" => _("FAI Package list"),
715 "plSelfModify" => FALSE,
716 "plDepends" => array(),
717 "plPriority" => 28,
718 "plSection" => array("administration"),
719 "plCategory" => array("fai"),
720 "plProvidedAcls" => array(
721 "cn" => _("Name"),
722 "description" => _("Description"),
723 "FAIpackage" => _("Packages"),
724 "FAIdebianSection" => _("Section")." ("._("Readonly").")",
725 "FAIinstallMethod" => _("Install Method"),
726 "FAIdebconfInfo" => _("Package configuration"),
727 "FAIdebianRelease" => _("Release")." ("._("Readonly").")")
728 ));
729 }
732 /*! \brief prepares this plugin to be inserted after it was copied or cut.
733 @param Array All attributes from the source object.
734 */
735 function PrepareForCopyPaste($source)
736 {
737 plugin::PrepareForCopyPaste($source);
739 if(isset($source['FAIstate'][0])){
740 $this->FAIstate = $source['FAIstate'][0];
741 }
743 $this->FAIdebianRelease = "ClearFromCopyPaste";
745 if(isset($source['FAIpackage'])){
746 unset($source['FAIpackage']['count']);
747 foreach($source['FAIpackage'] as $pkg){
748 $this->usedPackages[$pkg] = $pkg;
749 }
750 ksort($this->usedPackages);
751 }else{
752 $this->usedPackages = array();
753 }
755 if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
756 $this->FAIdebianSection = array();
757 for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
758 $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
759 }
760 }
762 /* Create one filter with all package names,
763 instead of calling $ldap->search for every single package
764 */
765 $PackageFilter = "";
766 foreach($this->usedPackages as $name){
767 $PackageFilter .= "(FAIpackage=".$name.")";
768 }
770 /* Search for configuration objects */
771 $ldap = $this->config->get_ldap_link();
772 $ldap->cd($source['dn']);
773 $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
775 /* Walk through configurations and append them to our list of ConfiguredPackages */
776 while($attr = $ldap->fetch()){
778 /* Skip objects, that are tagged as removed */
779 if(isset($object['FAIstate'][0])){
780 if(preg_match("/removed$/",$attr['FAIstate'][0])){
781 continue;
782 }
783 }
785 $tmp =array();
786 $tmp['Name'] = $attr['FAIvariable'][0];
787 $tmp['Type'] = $attr['FAIvariableType'][0];
789 if (isset($attr['FAIvariableContent'][0])){
790 if(!in_array($attr['FAIvariableType'],array("multiselect"))){
791 $tmp['Value'] = $attr['FAIvariableContent'][0];
792 }else{
793 $content = array();
794 unset($attr['FAIvariableContent']['count']);
795 foreach($attr['FAIvariableContent'] as $attr){
796 $tmp['Value'][] = $attr;
797 }
798 }
799 $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
800 }
801 }
802 }
805 /*! \brief Returns a list of all configured servers with repositories.
806 @return Array All repository server
807 */
808 function getServerInfos()
809 {
810 $ret = array();
811 $ldap = $this->config->get_ldap_link();
812 $ldap->cd($this->config->current['BASE']);
813 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
814 while($attrs = $ldap->fetch()){
815 if(isset($attrs['FAIrepository'])){
816 for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
817 $obj = $attrs['FAIrepository'][$i];
818 $tmp = split("\|",$obj);
819 if(count($tmp)==4){
820 foreach(split(",",$tmp[3]) as $sec){
821 if(!empty($sec)){
822 $ret[$tmp[2]][] = $sec;
823 }
824 }
825 }
826 }
827 }
828 }
829 return($ret);
830 }
833 /*! \brief Used for copy & paste.
834 Returns a HTML input mask, which allows to change the cn of this entry.
835 @param Array Array containing current status && a HTML template.
836 */
837 function getCopyDialog()
838 {
839 $vars = array("cn");
840 $smarty = get_smarty();
841 $smarty->assign("cn", htmlentities($this->cn));
842 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
843 $ret = array();
844 $ret['string'] = $str;
845 $ret['status'] = "";
846 return($ret);
847 }
850 /*! \brief Used for copy & paste.
851 Some entries must be renamed to avaoid duplicate entries.
852 */
853 function saveCopyDialog()
854 {
855 if(isset($_POST['cn'])){
856 $this->cn = get_post('cn');
857 }
858 }
859 }
861 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
862 ?>