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 $Removal = 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;
58 var $debconf_configurations = FALSE;
60 function faiPackage (&$config, $dn= NULL)
61 {
62 /* Load Attributes */
63 plugin::plugin ($config, $dn);
65 /* If "dn==new" we try to create a new entry
66 * Else we must read all objects from ldap which belong to this entry.
67 * First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
68 */
69 if($dn != "new"){
70 $this->dn =$dn;
72 /* Check if there are already some packages in this list
73 */
74 $this->usedPackages = array();
75 if(isset($this->attrs['FAIpackage'])){
76 unset($this->attrs['FAIpackage']['count']);
77 foreach($this->attrs['FAIpackage'] as $pkg){
78 $name = preg_replace("/\-$/","",$pkg);
79 $this->usedPackages[$name] = $pkg;
80 }
81 ksort($this->usedPackages);
82 }
84 /* Fetch package configurations from LDAP */
85 $this->ConfiguredPackages = $this->get_configured_packages($this->usedPackages, $this->dn);
87 $this->FAIdebianSection = array();
88 if(isset($this->attrs['FAIdebianSection'])){
89 for($i = 0 ; $i < $this->attrs['FAIdebianSection']['count'] ; $i++ ){
90 $sec = $this->attrs['FAIdebianSection'][$i];
91 $this->FAIdebianSection[$sec]=$sec;
92 }
93 }
94 $this->FAIpackage = array();
96 } // ENDE dn != new
98 $methods = array();
99 foreach($this->FAIinstallMethods as $method){
100 $methods[$method] = $method;
101 }
102 $this->FAIinstallMethods = $methods;
104 /* Check if we exist already - no need to ask for revisions, etc. then */
105 if ($this->dn != "new"){
106 $this->newDialogShown= true;
107 }
108 $this->is_new = FALSE;
109 if($this->dn == "new"){
110 $this->is_new =TRUE;
111 }
112 /* Check weither its allowed to directly add packages */
113 $direct_packages_add = $config->search("faiManagement","direct_packages_add",array("menu"));
114 if (preg_match("/^true$/i", $direct_packages_add) || preg_match("/yes/i", $direct_packages_add)) {
115 $this->direct_packages_add = TRUE;
116 }
118 /* Generate package list */
119 $this->list= $this->genPkgs(TRUE);
120 }
122 function get_configured_packages($packages, $base)
123 {
124 /* Fetch all package configurations from ldap
125 */
126 $PackageFilter = "";
127 foreach($packages as $name => $value){
128 $PackageFilter .= "(FAIpackage=".$name.")";
129 }
130 /* Also fetch d-i */
131 $PackageFilter .= "(FAIpackage=d-i)";
133 $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
135 /* Search for configuration objects */
136 $ldap = $this->config->get_ldap_link();
137 $ldap->cd($base);
138 $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
139 "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
141 $configured_packages = array();
143 /* Walk through configurations and append them to our list of ConfiguredPackages
144 */
145 while($attr = $ldap->fetch()){
147 /* Skip objects, that are tagged as removed */
148 if(isset($object['FAIstate'][0])){
149 if(preg_match("/removed$/",$attr['FAIstate'][0])){
150 continue;
151 }
152 }
154 $tmp =array();
155 $tmp['Name'] = $attr['FAIvariable'][0];
156 $tmp['Type'] = $attr['FAIvariableType'][0];
157 $tmp['Save'] = TRUE;
159 if (isset($attr['FAIvariableContent'][0])){
160 if(!in_array($attr['FAIvariableType'],array("multiselect"))){
161 $tmp['Value'] = $attr['FAIvariableContent'][0];
162 }else{
163 $content = array();
164 unset($attr['FAIvariableContent']['count']);
165 foreach($attr['FAIvariableContent'] as $attr){
166 $tmp['Value'][] = $attr;
167 }
168 }
169 $configured_packages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
170 }
171 else {
172 $tmp['Value'] = "";
173 $configured_packages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
174 }
175 }
177 return $configured_packages;
178 }
181 function execute()
182 {
183 /* Call parent execute */
184 plugin::execute();
186 if($this->is_account && !$this->view_logged){
187 $this->view_logged = TRUE;
188 new log("view","fai/".get_class($this),$this->dn);
189 }
191 /* Fill templating stuff */
192 $smarty= get_smarty();
193 $display= "";
195 /******
196 * Initialize a new Package List with release and section name
197 ******/
199 if(!$this->is_account){
201 /* Assemble release name */
202 $release = $this->parent->parent->fai_release;
203 $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $release);
204 $tmp= preg_replace('/ou=/', '', $tmp);
205 $rev= array_reverse(split(',', $tmp));
206 $this->FAIdebianRelease= "/";
207 foreach ($rev as $part){
208 $this->FAIdebianRelease.= "/$part";
209 }
210 $this->FAIdebianRelease= preg_replace('#^[/]*#', '', $this->FAIdebianRelease);
212 /* Assemble sections */
213 $repos= $this->getServerInfos();
214 if(isset($repos[$this->FAIdebianRelease])){
215 $this->FAIdebianSection= $repos[$this->FAIdebianRelease];
216 $this->FAIdebianSection= array_unique($this->FAIdebianSection);
217 }
219 /* Assign Repository settings*/
220 $this->is_account = true;
221 }
224 /******
225 * Add
226 ******/
228 if(isset($_POST['AddManualpkg']) &&
229 isset($_POST['addPpkgsText']) &&
230 strlen($_POST['addPpkgsText']) &&
231 $this->acl_is_writeable("FAIpackage") &&
232 !preg_match("/freeze/",$this->FAIstate)){
234 // Check all splitted packages for valid package names
235 $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
236 $valid_packages = array();
237 if( is_array($add_packages) ) {
238 $invalid_packages = array();
239 foreach ($add_packages as $value) {
240 if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
241 $invalid_packages[] = trim($value);
242 }else{
243 $valid_packages[] = trim($value);
244 }
245 }
246 if(count($invalid_packages)){
247 $str = implode(", ",$invalid_packages);
248 msg_dialog::display(_("Invalid package names"),
249 sprintf(_("The following package names don't match the Debian policy: %s"),$str),
250 ERROR_DIALOG);
251 }
254 // If we have a complete list of valid packages, add them
255 if(count($valid_packages)){
257 foreach($valid_packages as $key => $value){
258 if(array_key_exists($value,$this->usedPackages)) {
259 unset($valid_packages[$key]);
260 }
261 }
263 // Query SI-Deamon for additional package information
264 $daemon = new gosaSupportDaemon();
265 $query_attrs = array("distribution", "package","version", "section", "description", "timestamp");
266 $do_si_query = true;
269 foreach ($valid_packages as $value) {
270 if( $do_si_query == true ) {
271 $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
272 if( ! $daemon->is_error()){
274 if(count($res)){
276 // We just use the last answer - there shouldn't be multiple
277 $res_attrs = array_pop( $res );
278 $this->list[$value] = $res_attrs;
279 $this->usedPackages[$value] = $res_attrs['PACKAGE'];
281 }else{
282 $this->usedPackages[$value] = $value;
283 }
284 }else{
285 msg_dialog::display(_("Service infrastructure"),
286 msgPool::siError($daemon->get_error()),
287 ERROR_DIALOG);
288 $do_si_query = false;
289 }
290 }
291 }
293 ksort($this->usedPackages);
295 /* Generate package list */
296 $this->list= $this->genPkgs(TRUE);
297 }
298 }
299 }
301 if(isset($_POST['EditConfigurations']) &&
302 $this->acl_is_writeable("FAIdebconfInfo")) {
303 $this->dialog = new faiDebconfConfigurations($this->config, $this->dn, $this);
304 $this->dialog->set_acl_base($this->acl_base);
305 $this->is_dialog = true;
306 }
308 /* + was pressed to open the package dialog */
309 if(isset($_POST['Addpkg']) &&
310 $this->acl_is_writeable("FAIpackage") &&
311 !preg_match("/freeze/",$this->FAIstate)){
312 $this->dialog = new faiPackageEntry($this->config, $this->FAIdebianRelease,$this->usedPackages);
313 $this->is_dialog =true;
314 }
317 /* Check image Posts
318 */
319 foreach($_POST as $name => $value){
321 /*****
322 * Remove configuration
323 *****/
324 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match('/^remove_configuration_/', $name)){
325 $id = base64_decode(preg_replace("/^remove_configuration_(.*)_[xy]*$/","\\1",$name));
326 if(isset($this->ConfiguredPackages[$id])) {
327 $this->Removal[$id] = $this->ConfiguredPackages[$id];
328 unset($this->ConfiguredPackages[$id]);
329 }
330 }
332 /******
333 * Mark as removed
334 ******/
335 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
336 $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
337 if(isset($this->usedPackages[$id])){
338 $pkg = $this->usedPackages[$id];
339 if (preg_match('/\-$/', $pkg)){
340 $pkg= preg_replace('/\-$/', '', $pkg);
341 } else {
342 $pkg= preg_replace('/$/', '-', $pkg);
343 }
344 $this->usedPackages[$id] = $pkg;
345 }
346 break;
347 }
349 /******
350 * Delete Pkgs
351 ******/
352 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
353 $id = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\1",$name));
354 if(isset($this->usedPackages[$id])){
355 unset($this->usedPackages[$id]);
356 }
357 break;
358 }
360 /******
361 * Configure Pkgs
362 ******/
363 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
364 $pkg = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\1",$name));
366 if(isset($this->usedPackages[$pkg])){
368 /* Configuration dialog open*/
369 $pkg_config = array();
370 if(isset($this->ConfiguredPackages[$pkg])){
371 $pkg_config = $this->ConfiguredPackages[$pkg];
372 }
373 $this->configure_dialog_shown = TRUE;
374 $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
375 $this->is_dialog =true;
376 }
377 break;
378 }
379 }
381 /* Abort package selection dialog */
382 if(isset($_POST['CancelSubObject'])){
383 $this->dialog = false;
384 $this->is_dialog=false;
385 }
387 /* attach new packages */
388 if(isset($_POST['SaveSubObject'])) {
389 if(!preg_match("/freeze/i", $this->FAIstate)){
390 $this->dialog->save_object();
391 if(count($this->dialog->check())){
392 foreach($this->dialog->check() as $msgs){
393 msg_dialog::display(_("Error"), $msgs, ERROR_DIALOG);
394 }
395 }else{
396 $use = $this->dialog->save();
397 $this->usedPackages = $use;
398 $this->dialog = false;
399 $this->is_dialog=false;
400 ksort($this->usedPackages);
402 /* Generate package list */
403 $this->list= $this->genPkgs(TRUE);
404 }
405 }else{
406 $this->dialog = false;
407 $this->is_dialog=false;
408 }
409 }
411 /* Save Configuration */
412 if(isset($_POST['SaveObjectConfig']) && $this->configure_dialog_shown){
413 if(!preg_match("/^freeze/", $this->FAIstate)){
414 $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
415 }
416 $this->dialog = false;
417 $this->is_dialog=false;
418 $this->configure_dialog_shown=false;
419 }
421 if (isset($_POST['SaveDebconfConfig'])){
422 $this->dialog->save_object();
423 $msgs = $this->dialog->check();
424 if(count($msgs)>0) {
425 foreach($msgs as $msg){
426 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
427 }
428 } else {
429 if(!preg_match("/^freeze/", $this->FAIstate)){
430 $this->ConfiguredPackages= $this->dialog->save();
431 foreach($this->ConfiguredPackages as $package => $attrs) {
432 foreach($attrs as $name => $data) {
433 if (isset($data['Save']) && !($data['Save'])) {
434 $dn = "FAIvariable=".$name.",".$this->dn;
435 $ldap = $this->config->get_ldap_link();
436 $ldap->cat($dn);
437 if (!$ldap->count()) {
438 unset($this->ConfiguredPackages[$package][$name]);
439 }
440 }
441 }
442 if (is_array($this->ConfiguredPackages[$package])) {
443 if (count($this->ConfiguredPackages[$package]) == 0) {
444 unset($this->ConfiguredPackages[$package]);
445 }
446 }
447 }
448 }
449 $this->dialog = false;
450 $this->is_dialog = false;
451 }
452 }
454 /* cancel configuration */
455 if(isset($_POST['CancelObjectConfig']) && $this->configure_dialog_shown){
456 $this->dialog = false;
457 $this->is_dialog=false;
458 $this->configure_dialog_shown=false;
459 }
461 /* Display dialog */
462 if($this->is_dialog){
463 $this->dialog->save_object();
464 return $this->dialog->execute();
465 }
468 /******
469 * Display UI / HTML / smarty
470 ******/
472 /* Create divlist to display a list of all currently used packages
473 */
474 $divlist = new divSelectBox("faiPackages");
475 $divlist->setHeight(600);
477 ksort($this->usedPackages);
478 if(is_array($this->usedPackages)){
479 foreach($this->usedPackages as $usedName => $name){
481 $actions = "";
483 /* Append message if package is configured */
484 $configured = "<img src='images/empty.png' alt=' ' class='center'>";
485 if(isset($this->ConfiguredPackages[$usedName])){
486 $configured = "<input type='image' name='remove_configuration_".base64_encode($usedName)."' src='plugins/fai/images/package_configure.png' title='"._("Remove configuration")."'
487 title='"._("Remove configuration")."' class='center'>";
488 }
490 /* Adapt used name if we're marked for removal */
491 $removal = "<img src='images/empty.png' alt=' ' class='center'>";
492 if (preg_match('/\-$/', $name)){
493 $removal = "<img src='plugins/fai/images/removal_mark.png' alt='"._("Package marked for removal")."'
494 title='"._("Package marked for removal")."' class='center'>";
495 }
497 /* Get Version */
498 $version = " ";
499 if(isset($this->list[$usedName]['VERSION'])){
500 $version = $this->list[$usedName]['VERSION'];
501 }
503 /* Get description */
504 $description = " ";
505 if(isset($this->list[$usedName]['DESCRIPTION'])){
506 $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
507 }
509 if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
510 $actions = "<input type='image' class='center' title='"._("Mark package for removal")."'
511 src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >";
512 }
514 if(isset($this->list[$usedName]['TEMPLATE']) &&
515 !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
516 $actions.= " <input type='image' class='center' title='"._("Configure this package")."'
517 src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >";
518 }
519 if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
520 $actions.= " <input type='image' class='center' title='"._("Remove this package")."'
521 src='images/lists/trash.png' name='remove_package_".base64_encode($usedName)."' >";
522 }
524 $field1 = array("string" => $configured." ".$removal,"attach" => "style='width:40px;'");
525 $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
526 $field3 = array("string" => $version);
527 $field4 = array("string" => $description);
528 $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
529 $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
530 }
531 }
533 /* Assign variables */
534 foreach($this->attributes as $attrs){
535 $smarty->assign($attrs,$this->$attrs);
536 }
537 $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
539 /* Assign section to smarty */
540 $strsec = "";
541 foreach($this->FAIdebianSection as $sec){
542 $strsec .= $sec." ";
543 }
545 $tmp = $this->plInfo();
546 foreach($tmp['plProvidedAcls'] as $name => $translated){
547 $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
548 }
550 if ($this->acl_is_writeable("FAIdebconfInfo")) {
551 $this->debconf_configurations = TRUE;
552 }
554 $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
555 $smarty->assign("divlist",$divlist->DrawList());
556 $smarty->assign("release" ,$this->FAIdebianRelease);
557 $smarty->assign("sections",$this->sections);
558 $smarty->assign("section" ,$strsec);
559 $smarty->assign("direct_packages_add", $this->direct_packages_add);
560 $smarty->assign("debconf_configurations", $this->debconf_configurations);
561 $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
562 return($display);
563 }
566 /*! \brief Removes this packageList from the ldap database
567 */
568 function remove_from_parent()
569 {
570 $ldap = $this->config->get_ldap_link();
571 $ldap->cd ($this->dn);
572 $release = $this->parent->parent->fai_release;
573 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
574 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
575 new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
576 foreach($this->ConfiguredPackages as $pkgname => $attrs){
577 foreach($attrs as $name => $attr){
578 $pkgdn = "FAIvariable=".$name.",".$this->dn;
579 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
580 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
581 }
582 }
583 $this->handle_post_events("remove");
584 }
587 /*! \brief Collect all relevant POST vars for this plugin
588 */
589 function save_object()
590 {
591 if(preg_match("/^freeze/", $this->FAIstate)) return;
592 plugin::save_object();
593 }
596 /*! \brief Check given inputs for this package list
597 @return Array Containing all error messages, or an empty array if no error occured
598 */
599 function check()
600 {
601 /* Call common method to give check the hook */
602 $message= plugin::check();
604 if(count($this->usedPackages)==0){
605 $message[]= _("Please select a least one package!");
606 }
608 if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
609 $message[]=_("Please choose a valid release/section combination for your repository setup!");
610 }
612 /* Ensure that we do not overwrite an allready existing entry
613 */
614 if($this->is_new){
615 $release = $this->parent->parent->fai_release;
616 $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
617 $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
618 if(isset($res[$this->cn])){
619 $message[] = msgPool::duplicated(_("Name"));
620 }
621 }
623 if (preg_match("/^-/", $this->cn)) {
624 $message[] = sprintf(_("The specified classname '%s' is invalid. Classnames must not start with a dash."), $this->cn);
625 }
627 if($this->cn != preg_replace("/ /","",trim($this->cn))){
628 $message[] = msgPool::invalid(_("Name"),preg_replace("/ /","_",$this->cn),"/[^_]/");
629 }
631 return ($message);
632 }
635 /*! \brief Reload the list of cached packages.
636 @return Returns the currently cached list of packages.
637 */
638 function genPkgs($force = false)
639 {
640 if(empty($this->FAIdebianRelease)) return;
642 if(!count($this->buffer) || $force){
643 $q = new gosaSupportDaemon();
644 $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
646 $packages = array_keys($this->usedPackages);
648 $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
649 if($q->is_error()){
650 msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
651 }else{
652 foreach($ret as $attr){
653 $this->buffer[$attr['PACKAGE']] = $attr;
654 }
655 }
656 }
657 return $this->buffer;
658 }
661 /*! \brief Save packages and their configuration to ldap
662 */
663 function save()
664 {
666 /* Assemble release name */
667 if($this->FAIdebianRelease == "ClearFromCopyPaste"){
669 $current_release = $this->parent->parent->fai_release;
670 $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $current_release);
671 $tmp= preg_replace('/ou=/', '', $tmp);
672 $rev= array_reverse(split(',', $tmp));
673 $this->FAIdebianRelease= "";
674 foreach ($rev as $part){
675 $this->FAIdebianRelease.= "/$part";
676 }
677 $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
678 }
680 plugin::save();
682 $ldap = $this->config->get_ldap_link();
684 $this->attrs['FAIpackage'] = array();
685 foreach($this->usedPackages as $pkg){
686 $this->attrs['FAIpackage'][] = $pkg;
687 }
689 $this->attrs['FAIdebianSection'] = array();
690 foreach($this->FAIdebianSection as $sec){
691 $this->attrs['FAIdebianSection'][] = $sec;
692 }
694 FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
696 if($this->initially_was_account){
697 new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
698 }else{
699 new log("create","fai/".get_class($this),$this->dn,$this->attributes);
700 }
702 $ldap->cd($this->dn);
704 /* Save Package configurations */
705 foreach($this->Removal as $pkgname => $attrs){
706 /* Skip entries which are back in the ConfiguredPackages array */
707 if (isset($this->ConfiguredPackages[$pkgname])) {
708 continue;
709 }
710 foreach($attrs as $name => $attr){
711 $dn = "FAIvariable=".$name.",".$this->dn;
712 $ldap = $this->config->get_ldap_link();
713 $ldap->cat($dn);
714 if ($ldap->count()) {
715 FAI::prepare_to_save_FAI_object($dn,array(),true);
716 }
717 }
718 }
720 foreach($this->ConfiguredPackages as $pkgname => $attrs){
721 foreach($attrs as $name => $attr){
722 $pkgattrs = array();
724 foreach($attr as $n=>$v){
725 if(empty($v)) $v = array();
726 }
728 /* Set attributes */
729 $pkgattrs['objectClass'][] = "FAIdebconfInfo";
731 $pkgattrs['FAIpackage'] = $pkgname;
732 $pkgattrs['FAIvariable'] = $name;
733 $pkgattrs['FAIvariableType'] = $attr['Type'];
734 $pkgattrs['FAIvariableContent'] = $attr['Value'];
735 $pkgdn = "FAIvariable=".$name.",".$this->dn;
737 if (!$attr['Save']) {
738 $ldap = $this->config->get_ldap_link();
739 $ldap->cat($pkgdn);
740 if ($ldap->count()) {
741 FAI::prepare_to_save_FAI_object($pkgdn,array(),true);
742 }
743 else {
744 unset($this->ConfiguredPackages[$pkgname][$name]);
745 }
746 if (is_array($this->ConfiguredPackages[$pkgname]) && count($this->ConfiguredPackages[$pkgname]) == 0) {
747 unset($this->ConfiguredPackages[$pkgname]);
748 }
750 continue;
752 }
754 if (empty($pkgattrs['FAIvariableContent'])) {
755 $pkgattrs['FAIvariableContent'] = array();
756 }
758 if (is_array($pkgattrs['FAIvariableContent'])) {
759 $ldap = $this->config->get_ldap_link();
760 $ldap->cat($pkgdn);
761 if (!$ldap->count()) {
762 /* Do not try to set FAIvariableContent to empty array if this
763 * debconfInfo object is new */
764 unset($pkgattrs['FAIvariableContent']);
765 }
766 }
768 /* Tag object */
769 $ui= get_userinfo();
770 $this->tag_attrs($pkgattrs, $pkgdn, $ui->gosaUnitTag);
772 if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
774 if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
775 gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
776 }else{
777 FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
778 }
779 }
780 }
781 }
782 }
785 /*! \brief Return plugin informations for acl handling
786 @return Array ACL infos of this plugin.
787 */
788 static function plInfo()
789 {
790 return (array(
791 "plShortName" => _("Package"),
792 "plDescription" => _("FAI Package list"),
793 "plSelfModify" => FALSE,
794 "plDepends" => array(),
795 "plPriority" => 28,
796 "plSection" => array("administration"),
797 "plCategory" => array("fai"),
798 "plProvidedAcls" => array(
799 "cn" => _("Name"),
800 "description" => _("Description"),
801 "FAIpackage" => _("Packages"),
802 "FAIdebianSection" => _("Section")." ("._("Readonly").")",
803 "FAIinstallMethod" => _("Install Method"),
804 "FAIdebconfInfo" => _("Package configuration"),
805 "FAIdebianRelease" => _("Release")." ("._("Readonly").")")
806 ));
807 }
810 /*! \brief prepares this plugin to be inserted after it was copied or cut.
811 @param Array All attributes from the source object.
812 */
813 function PrepareForCopyPaste($source)
814 {
815 plugin::PrepareForCopyPaste($source);
817 if(isset($source['FAIstate'][0])){
818 $this->FAIstate = $source['FAIstate'][0];
819 }
821 $this->FAIdebianRelease = "ClearFromCopyPaste";
823 if(isset($source['FAIpackage'])){
824 unset($source['FAIpackage']['count']);
825 foreach($source['FAIpackage'] as $pkg){
826 $this->usedPackages[$pkg] = $pkg;
827 }
828 ksort($this->usedPackages);
829 }else{
830 $this->usedPackages = array();
831 }
833 if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
834 $this->FAIdebianSection = array();
835 for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
836 $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
837 }
838 }
839 $this->ConfiguredPackages = $this->get_configured_packages($this->usedPackages, $source['dn']);
841 }
844 /*! \brief Returns a list of all configured servers with repositories.
845 @return Array All repository server
846 */
847 function getServerInfos()
848 {
849 $ret = array();
850 $ldap = $this->config->get_ldap_link();
851 $ldap->cd($this->config->current['BASE']);
852 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
853 while($attrs = $ldap->fetch()){
854 if(isset($attrs['FAIrepository'])){
855 for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
856 $obj = $attrs['FAIrepository'][$i];
857 $tmp = split("\|",$obj);
858 if(count($tmp)==4){
859 foreach(split(",",$tmp[3]) as $sec){
860 if(!empty($sec)){
861 $ret[$tmp[2]][] = $sec;
862 }
863 }
864 }
865 }
866 }
867 }
868 return($ret);
869 }
872 /*! \brief Used for copy & paste.
873 Returns a HTML input mask, which allows to change the cn of this entry.
874 @param Array Array containing current status && a HTML template.
875 */
876 function getCopyDialog()
877 {
878 $vars = array("cn");
879 $smarty = get_smarty();
880 $smarty->assign("cn", htmlentities($this->cn));
881 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
882 $ret = array();
883 $ret['string'] = $str;
884 $ret['status'] = "";
885 return($ret);
886 }
889 /*! \brief Used for copy & paste.
890 Some entries must be renamed to avaoid duplicate entries.
891 */
892 function saveCopyDialog()
893 {
894 if(isset($_POST['cn'])){
895 $this->cn = get_post('cn');
896 }
897 }
898 }
900 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
901 ?>