3cf8cc46da98c0a16e46950c0ce7fc4886f7af82
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 all package configurations from ldap
85 */
86 $PackageFilter = "";
87 foreach($this->usedPackages as $name => $value){
88 $PackageFilter .= "(FAIpackage=".$name.")";
89 }
90 /* Also fetch d-i */
91 $PackageFilter .= "(FAIpackage=d-i)";
93 $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
95 /* Search for configuration objects */
96 $ldap = $this->config->get_ldap_link();
97 $ldap->cd($this->dn);
98 $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
99 "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
101 /* Walk through configurations and append them to our list of ConfiguredPackages
102 */
103 while($attr = $ldap->fetch()){
105 /* Skip objects, that are tagged as removed */
106 if(isset($object['FAIstate'][0])){
107 if(preg_match("/removed$/",$attr['FAIstate'][0])){
108 continue;
109 }
110 }
112 $tmp =array();
113 $tmp['Name'] = $attr['FAIvariable'][0];
114 $tmp['Type'] = $attr['FAIvariableType'][0];
115 $tmp['Save'] = TRUE;
117 if (isset($attr['FAIvariableContent'][0])){
118 if(!in_array($attr['FAIvariableType'],array("multiselect"))){
119 $tmp['Value'] = $attr['FAIvariableContent'][0];
120 }else{
121 $content = array();
122 unset($attr['FAIvariableContent']['count']);
123 foreach($attr['FAIvariableContent'] as $attr){
124 $tmp['Value'][] = $attr;
125 }
126 }
127 $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
128 }
129 else {
130 $tmp['Value'] = "";
131 $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
132 }
133 }
135 $this->FAIdebianSection = array();
136 if(isset($this->attrs['FAIdebianSection'])){
137 for($i = 0 ; $i < $this->attrs['FAIdebianSection']['count'] ; $i++ ){
138 $sec = $this->attrs['FAIdebianSection'][$i];
139 $this->FAIdebianSection[$sec]=$sec;
140 }
141 }
142 $this->FAIpackage = array();
144 } // ENDE dn != new
146 $methods = array();
147 foreach($this->FAIinstallMethods as $method){
148 $methods[$method] = $method;
149 }
150 $this->FAIinstallMethods = $methods;
152 /* Check if we exist already - no need to ask for revisions, etc. then */
153 if ($this->dn != "new"){
154 $this->newDialogShown= true;
155 }
156 $this->is_new = FALSE;
157 if($this->dn == "new"){
158 $this->is_new =TRUE;
159 }
160 /* Check weither its allowed to directly add packages */
161 $direct_packages_add = $config->search("faiManagement","direct_packages_add",array("menu"));
162 if (preg_match("/^true$/i", $direct_packages_add) || preg_match("/yes/i", $direct_packages_add)) {
163 $this->direct_packages_add = TRUE;
164 }
166 /* Generate package list */
167 $this->list= $this->genPkgs(TRUE);
168 }
171 function execute()
172 {
173 /* Call parent execute */
174 plugin::execute();
176 if($this->is_account && !$this->view_logged){
177 $this->view_logged = TRUE;
178 new log("view","fai/".get_class($this),$this->dn);
179 }
181 /* Fill templating stuff */
182 $smarty= get_smarty();
183 $display= "";
185 /******
186 * Initialize a new Package List with release and section name
187 ******/
189 if(!$this->is_account){
191 /* Assemble release name */
192 $release = $this->parent->parent->fai_release;
193 $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $release);
194 $tmp= preg_replace('/ou=/', '', $tmp);
195 $rev= array_reverse(split(',', $tmp));
196 $this->FAIdebianRelease= "/";
197 foreach ($rev as $part){
198 $this->FAIdebianRelease.= "/$part";
199 }
200 $this->FAIdebianRelease= preg_replace('#^[/]*#', '', $this->FAIdebianRelease);
202 /* Assemble sections */
203 $repos= $this->getServerInfos();
204 if(isset($repos[$this->FAIdebianRelease])){
205 $this->FAIdebianSection= $repos[$this->FAIdebianRelease];
206 $this->FAIdebianSection= array_unique($this->FAIdebianSection);
207 }
209 /* Assign Repository settings*/
210 $this->is_account = true;
211 }
214 /******
215 * Add
216 ******/
218 if(isset($_POST['AddManualpkg']) &&
219 isset($_POST['addPpkgsText']) &&
220 strlen($_POST['addPpkgsText']) &&
221 $this->acl_is_writeable("FAIpackage") &&
222 !preg_match("/freeze/",$this->FAIstate)){
224 // Check all splitted packages for valid package names
225 $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY );
226 $valid_packages = array();
227 if( is_array($add_packages) ) {
228 $invalid_packages = array();
229 foreach ($add_packages as $value) {
230 if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){
231 $invalid_packages[] = trim($value);
232 }else{
233 $valid_packages[] = trim($value);
234 }
235 }
236 if(count($invalid_packages)){
237 $str = implode(", ",$invalid_packages);
238 msg_dialog::display(_("Invalid package names"),
239 sprintf(_("The following package names don't match the Debian policy: %s"),$str),
240 ERROR_DIALOG);
241 }
244 // If we have a complete list of valid packages, add them
245 if(count($valid_packages)){
247 foreach($valid_packages as $key => $value){
248 if(array_key_exists($value,$this->usedPackages)) {
249 unset($valid_packages[$key]);
250 }
251 }
253 // Query SI-Deamon for additional package information
254 $daemon = new gosaSupportDaemon();
255 $query_attrs = array("distribution", "package","version", "section", "description", "timestamp");
256 $do_si_query = true;
259 foreach ($valid_packages as $value) {
260 if( $do_si_query == true ) {
261 $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
262 if( ! $daemon->is_error()){
264 if(count($res)){
266 // We just use the last answer - there shouldn't be multiple
267 $res_attrs = array_pop( $res );
268 $this->list[$value] = $res_attrs;
269 $this->usedPackages[$value] = $res_attrs['PACKAGE'];
271 }else{
272 $this->usedPackages[$value] = $value;
273 }
274 }else{
275 msg_dialog::display(_("Service infrastructure"),
276 msgPool::siError($daemon->get_error()),
277 ERROR_DIALOG);
278 $do_si_query = false;
279 }
280 }
281 }
283 ksort($this->usedPackages);
285 /* Generate package list */
286 $this->list= $this->genPkgs(TRUE);
287 }
288 }
289 }
291 if(isset($_POST['EditConfigurations']) &&
292 $this->acl_is_writeable("FAIdebconfInfo")) {
293 $this->dialog = new faiDebconfConfigurations($this->config, $this->dn, $this);
294 $this->dialog->set_acl_base($this->acl_base);
295 $this->is_dialog = true;
296 }
298 /* + was pressed to open the package dialog */
299 if(isset($_POST['Addpkg']) &&
300 $this->acl_is_writeable("FAIpackage") &&
301 !preg_match("/freeze/",$this->FAIstate)){
302 $this->dialog = new faiPackageEntry($this->config, $this->FAIdebianRelease,$this->usedPackages);
303 $this->is_dialog =true;
304 }
307 /* Check image Posts
308 */
309 foreach($_POST as $name => $value){
311 /*****
312 * Remove configuration
313 *****/
314 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match('/^remove_configuration_/', $name)){
315 $id = base64_decode(preg_replace("/^remove_configuration_(.*)_[xy]*$/","\\1",$name));
316 if(isset($this->ConfiguredPackages[$id])) {
317 $this->Removal[$id] = $this->ConfiguredPackages[$id];
318 unset($this->ConfiguredPackages[$id]);
319 }
320 }
322 /******
323 * Mark as removed
324 ******/
325 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
326 $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
327 if(isset($this->usedPackages[$id])){
328 $pkg = $this->usedPackages[$id];
329 if (preg_match('/\-$/', $pkg)){
330 $pkg= preg_replace('/\-$/', '', $pkg);
331 } else {
332 $pkg= preg_replace('/$/', '-', $pkg);
333 }
334 $this->usedPackages[$id] = $pkg;
335 }
336 break;
337 }
339 /******
340 * Delete Pkgs
341 ******/
342 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){
343 $id = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\1",$name));
344 if(isset($this->usedPackages[$id])){
345 unset($this->usedPackages[$id]);
346 }
347 break;
348 }
350 /******
351 * Configure Pkgs
352 ******/
353 if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){
354 $pkg = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\1",$name));
356 if(isset($this->usedPackages[$pkg])){
358 /* Configuration dialog open*/
359 $pkg_config = array();
360 if(isset($this->ConfiguredPackages[$pkg])){
361 $pkg_config = $this->ConfiguredPackages[$pkg];
362 }
363 $this->configure_dialog_shown = TRUE;
364 $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
365 $this->is_dialog =true;
366 }
367 break;
368 }
369 }
371 /* Abort package selection dialog */
372 if(isset($_POST['CancelSubObject'])){
373 $this->dialog = false;
374 $this->is_dialog=false;
375 }
377 /* attach new packages */
378 if(isset($_POST['SaveSubObject'])) {
379 if(!preg_match("/freeze/i", $this->FAIstate)){
380 $this->dialog->save_object();
381 if(count($this->dialog->check())){
382 foreach($this->dialog->check() as $msgs){
383 msg_dialog::display(_("Error"), $msgs, ERROR_DIALOG);
384 }
385 }else{
386 $use = $this->dialog->save();
387 $this->usedPackages = $use;
388 $this->dialog = false;
389 $this->is_dialog=false;
390 ksort($this->usedPackages);
392 /* Generate package list */
393 $this->list= $this->genPkgs(TRUE);
394 }
395 }else{
396 $this->dialog = false;
397 $this->is_dialog=false;
398 }
399 }
401 /* Save Configuration */
402 if(isset($_POST['SaveObjectConfig']) && $this->configure_dialog_shown){
403 if(!preg_match("/^freeze/", $this->FAIstate)){
404 $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
405 }
406 $this->dialog = false;
407 $this->is_dialog=false;
408 $this->configure_dialog_shown=false;
409 }
411 if (isset($_POST['SaveDebconfConfig'])){
412 $this->dialog->save_object();
413 $msgs = $this->dialog->check();
414 if(count($msgs)>0) {
415 foreach($msgs as $msg){
416 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
417 }
418 } else {
419 if(!preg_match("/^freeze/", $this->FAIstate)){
420 $this->ConfiguredPackages= $this->dialog->save();
421 foreach($this->ConfiguredPackages as $package => $attrs) {
422 foreach($attrs as $name => $data) {
423 if (isset($data['Save']) && !($data['Save'])) {
424 $dn = "FAIvariable=".$name.",".$this->dn;
425 $ldap = $this->config->get_ldap_link();
426 $ldap->cat($dn);
427 if (!$ldap->count()) {
428 unset($this->ConfiguredPackages[$package][$name]);
429 }
430 }
431 }
432 if (is_array($this->ConfiguredPackages[$package])) {
433 if (count($this->ConfiguredPackages[$package]) == 0) {
434 unset($this->ConfiguredPackages[$package]);
435 }
436 }
437 }
438 }
439 $this->dialog = false;
440 $this->is_dialog = false;
441 }
442 }
444 /* cancel configuration */
445 if(isset($_POST['CancelObjectConfig']) && $this->configure_dialog_shown){
446 $this->dialog = false;
447 $this->is_dialog=false;
448 $this->configure_dialog_shown=false;
449 }
451 /* Display dialog */
452 if($this->is_dialog){
453 $this->dialog->save_object();
454 return $this->dialog->execute();
455 }
458 /******
459 * Display UI / HTML / smarty
460 ******/
462 /* Create divlist to display a list of all currently used packages
463 */
464 $divlist = new divSelectBox("faiPackages");
465 $divlist->setHeight(600);
467 ksort($this->usedPackages);
468 if(is_array($this->usedPackages)){
469 foreach($this->usedPackages as $usedName => $name){
471 $actions = "";
473 /* Append message if package is configured */
474 $configured = "<img src='images/empty.png' alt=' ' class='center'>";
475 if(isset($this->ConfiguredPackages[$usedName])){
476 $configured = "<input type='image' name='remove_configuration_".base64_encode($usedName)."' src='plugins/fai/images/package_configure.png' title='"._("Remove configuration")."'
477 title='"._("Remove configuration")."' class='center'>";
478 }
480 /* Adapt used name if we're marked for removal */
481 $removal = "<img src='images/empty.png' alt=' ' class='center'>";
482 if (preg_match('/\-$/', $name)){
483 $removal = "<img src='plugins/fai/images/removal_mark.png' alt='"._("Package marked for removal")."'
484 title='"._("Package marked for removal")."' class='center'>";
485 }
487 /* Get Version */
488 $version = " ";
489 if(isset($this->list[$usedName]['VERSION'])){
490 $version = $this->list[$usedName]['VERSION'];
491 }
493 /* Get description */
494 $description = " ";
495 if(isset($this->list[$usedName]['DESCRIPTION'])){
496 $description = base64_decode($this->list[$usedName]['DESCRIPTION']);
497 }
499 if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
500 $actions = "<input type='image' class='center' title='"._("Mark package for removal")."'
501 src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >";
502 }
504 if(isset($this->list[$usedName]['TEMPLATE']) &&
505 !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){
506 $actions.= " <input type='image' class='center' title='"._("Configure this package")."'
507 src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >";
508 }
509 if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){
510 $actions.= " <input type='image' class='center' title='"._("Remove this package")."'
511 src='images/lists/trash.png' name='remove_package_".base64_encode($usedName)."' >";
512 }
514 $field1 = array("string" => $configured." ".$removal,"attach" => "style='width:40px;'");
515 $field2 = array("string" => $usedName ,"attach" => "style='width:200px;'");
516 $field3 = array("string" => $version);
517 $field4 = array("string" => $description);
518 $field5 = array("string" => $actions ,"attach" => "style='width:60px; border-right:0px;'");
519 $divlist->AddEntry(array($field1,$field2,$field3,$field4,$field5));
520 }
521 }
523 /* Assign variables */
524 foreach($this->attributes as $attrs){
525 $smarty->assign($attrs,$this->$attrs);
526 }
527 $smarty->assign( "FAIinstallMethods", $this->FAIinstallMethods );
529 /* Assign section to smarty */
530 $strsec = "";
531 foreach($this->FAIdebianSection as $sec){
532 $strsec .= $sec." ";
533 }
535 $tmp = $this->plInfo();
536 foreach($tmp['plProvidedAcls'] as $name => $translated){
537 $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
538 }
540 if ($this->acl_is_writeable("FAIdebconfInfo")) {
541 $this->debconf_configurations = TRUE;
542 }
544 $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
545 $smarty->assign("divlist",$divlist->DrawList());
546 $smarty->assign("release" ,$this->FAIdebianRelease);
547 $smarty->assign("sections",$this->sections);
548 $smarty->assign("section" ,$strsec);
549 $smarty->assign("direct_packages_add", $this->direct_packages_add);
550 $smarty->assign("debconf_configurations", $this->debconf_configurations);
551 $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
552 return($display);
553 }
556 /*! \brief Removes this packageList from the ldap database
557 */
558 function remove_from_parent()
559 {
560 $ldap = $this->config->get_ldap_link();
561 $ldap->cd ($this->dn);
562 $release = $this->parent->parent->fai_release;
563 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
564 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
565 new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
566 foreach($this->ConfiguredPackages as $pkgname => $attrs){
567 foreach($attrs as $name => $attr){
568 $pkgdn = "FAIvariable=".$name.",".$this->dn;
569 $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn);
570 FAI::prepare_to_save_FAI_object($use_dn,array(),true);
571 }
572 }
573 $this->handle_post_events("remove");
574 }
577 /*! \brief Collect all relevant POST vars for this plugin
578 */
579 function save_object()
580 {
581 if(preg_match("/^freeze/", $this->FAIstate)) return;
582 plugin::save_object();
583 }
586 /*! \brief Check given inputs for this package list
587 @return Array Containing all error messages, or an empty array if no error occured
588 */
589 function check()
590 {
591 /* Call common method to give check the hook */
592 $message= plugin::check();
594 if(count($this->usedPackages)==0){
595 $message[]= _("Please select a least one package!");
596 }
598 if((empty($this->FAIdebianRelease))||(empty($this->FAIdebianSection))){
599 $message[]=_("Please choose a valid release/section combination for your repository setup!");
600 }
602 /* Ensure that we do not overwrite an allready existing entry
603 */
604 if($this->is_new){
605 $release = $this->parent->parent->fai_release;
606 $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release;
607 $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn);
608 if(isset($res[$this->cn])){
609 $message[] = msgPool::duplicated(_("Name"));
610 }
611 }
613 if (preg_match("/^-/", $this->cn)) {
614 $message[] = sprintf(_("The specified classname '%s' is invalid. Classnames must not start with a dash."), $this->cn);
615 }
617 if($this->cn != preg_replace("/ /","",trim($this->cn))){
618 $message[] = msgPool::invalid(_("Name"),preg_replace("/ /","_",$this->cn),"/[^_]/");
619 }
621 return ($message);
622 }
625 /*! \brief Reload the list of cached packages.
626 @return Returns the currently cached list of packages.
627 */
628 function genPkgs($force = false)
629 {
630 if(empty($this->FAIdebianRelease)) return;
632 if(!count($this->buffer) || $force){
633 $q = new gosaSupportDaemon();
634 $attrs = array("distribution", "package","version", "section", "description", "timestamp","template");
636 $packages = array_keys($this->usedPackages);
638 $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$packages);
639 if($q->is_error()){
640 msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
641 }else{
642 foreach($ret as $attr){
643 $this->buffer[$attr['PACKAGE']] = $attr;
644 }
645 }
646 }
647 return $this->buffer;
648 }
651 /*! \brief Save packages and their configuration to ldap
652 */
653 function save()
654 {
656 /* Assemble release name */
657 if($this->FAIdebianRelease == "ClearFromCopyPaste"){
659 $current_release = $this->parent->parent->fai_release;
660 $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/', '', $current_release);
661 $tmp= preg_replace('/ou=/', '', $tmp);
662 $rev= array_reverse(split(',', $tmp));
663 $this->FAIdebianRelease= "";
664 foreach ($rev as $part){
665 $this->FAIdebianRelease.= "/$part";
666 }
667 $this->FAIdebianRelease= preg_replace('#^/#', '', $this->FAIdebianRelease);
668 }
670 plugin::save();
672 $ldap = $this->config->get_ldap_link();
674 $this->attrs['FAIpackage'] = array();
675 foreach($this->usedPackages as $pkg){
676 $this->attrs['FAIpackage'][] = $pkg;
677 }
679 $this->attrs['FAIdebianSection'] = array();
680 foreach($this->FAIdebianSection as $sec){
681 $this->attrs['FAIdebianSection'][] = $sec;
682 }
684 FAI::prepare_to_save_FAI_object($this->dn,$this->attrs);
686 if($this->initially_was_account){
687 new log("modify","fai/".get_class($this),$this->dn,$this->attributes);
688 }else{
689 new log("create","fai/".get_class($this),$this->dn,$this->attributes);
690 }
692 $ldap->cd($this->dn);
694 /* Save Package configurations */
695 foreach($this->Removal as $pkgname => $attrs){
696 /* Skip entries which are back in the ConfiguredPackages array */
697 if (isset($this->ConfiguredPackages[$pkgname])) {
698 continue;
699 }
700 foreach($attrs as $name => $attr){
701 $dn = "FAIvariable=".$name.",".$this->dn;
702 $ldap = $this->config->get_ldap_link();
703 $ldap->cat($dn);
704 if ($ldap->count()) {
705 FAI::prepare_to_save_FAI_object($dn,array(),true);
706 }
707 }
708 }
710 foreach($this->ConfiguredPackages as $pkgname => $attrs){
711 foreach($attrs as $name => $attr){
712 $pkgattrs = array();
714 foreach($attr as $n=>$v){
715 if(empty($v)) $v = array();
716 }
718 /* Set attributes */
719 $pkgattrs['objectClass'][] = "FAIdebconfInfo";
721 $pkgattrs['FAIpackage'] = $pkgname;
722 $pkgattrs['FAIvariable'] = $name;
723 $pkgattrs['FAIvariableType'] = $attr['Type'];
724 $pkgattrs['FAIvariableContent'] = $attr['Value'];
725 $pkgdn = "FAIvariable=".$name.",".$this->dn;
727 if (!$attr['Save']) {
728 $ldap = $this->config->get_ldap_link();
729 $ldap->cat($pkgdn);
730 if ($ldap->count()) {
731 FAI::prepare_to_save_FAI_object($pkgdn,array(),true);
732 }
733 else {
734 unset($this->ConfiguredPackages[$pkgname][$name]);
735 }
736 if (is_array($this->ConfiguredPackages[$pkgname]) && count($this->ConfiguredPackages[$pkgname]) == 0) {
737 unset($this->ConfiguredPackages[$pkgname]);
738 }
740 continue;
742 }
744 if (empty($pkgattrs['FAIvariableContent'])) {
745 $pkgattrs['FAIvariableContent'] = array();
746 }
748 if (is_array($pkgattrs['FAIvariableContent'])) {
749 $ldap = $this->config->get_ldap_link();
750 $ldap->cat($pkgdn);
751 if (!$ldap->count()) {
752 /* Do not try to set FAIvariableContent to empty array if this
753 * debconfInfo object is new */
754 unset($pkgattrs['FAIvariableContent']);
755 }
756 }
758 /* Tag object */
759 $ui= get_userinfo();
760 $this->tag_attrs($pkgattrs, $pkgdn, $ui->gosaUnitTag);
762 if(in_array($pkgattrs['FAIvariableType'],array("boolean","multiselect","password","select","string","text"))){
764 if($pkgattrs['FAIvariableType'] == "text" && $pkgattrs['FAIvariableContent'] == ""){
765 gosa_log("Skipped saving FAIvariable '$name' empty string can't be saved.");
766 }else{
767 FAI::prepare_to_save_FAI_object($pkgdn,$pkgattrs);
768 }
769 }
770 }
771 }
772 }
775 /*! \brief Return plugin informations for acl handling
776 @return Array ACL infos of this plugin.
777 */
778 static function plInfo()
779 {
780 return (array(
781 "plShortName" => _("Package"),
782 "plDescription" => _("FAI Package list"),
783 "plSelfModify" => FALSE,
784 "plDepends" => array(),
785 "plPriority" => 28,
786 "plSection" => array("administration"),
787 "plCategory" => array("fai"),
788 "plProvidedAcls" => array(
789 "cn" => _("Name"),
790 "description" => _("Description"),
791 "FAIpackage" => _("Packages"),
792 "FAIdebianSection" => _("Section")." ("._("Readonly").")",
793 "FAIinstallMethod" => _("Install Method"),
794 "FAIdebconfInfo" => _("Package configuration"),
795 "FAIdebianRelease" => _("Release")." ("._("Readonly").")")
796 ));
797 }
800 /*! \brief prepares this plugin to be inserted after it was copied or cut.
801 @param Array All attributes from the source object.
802 */
803 function PrepareForCopyPaste($source)
804 {
805 plugin::PrepareForCopyPaste($source);
807 if(isset($source['FAIstate'][0])){
808 $this->FAIstate = $source['FAIstate'][0];
809 }
811 $this->FAIdebianRelease = "ClearFromCopyPaste";
813 if(isset($source['FAIpackage'])){
814 unset($source['FAIpackage']['count']);
815 foreach($source['FAIpackage'] as $pkg){
816 $this->usedPackages[$pkg] = $pkg;
817 }
818 ksort($this->usedPackages);
819 }else{
820 $this->usedPackages = array();
821 }
823 if((isset($source['FAIdebianSection']))&&(is_array($source['FAIdebianSection']))){
824 $this->FAIdebianSection = array();
825 for($i = 0 ; $i < $source['FAIdebianSection']['count'] ; $i ++){
826 $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
827 }
828 }
830 /* Create one filter with all package names,
831 instead of calling $ldap->search for every single package
832 */
833 $PackageFilter = "";
834 foreach($this->usedPackages as $name){
835 $PackageFilter .= "(FAIpackage=".$name.")";
836 }
838 /* Search for configuration objects */
839 $ldap = $this->config->get_ldap_link();
840 $ldap->cd($source['dn']);
841 $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
843 /* Walk through configurations and append them to our list of ConfiguredPackages */
844 while($attr = $ldap->fetch()){
846 /* Skip objects, that are tagged as removed */
847 if(isset($object['FAIstate'][0])){
848 if(preg_match("/removed$/",$attr['FAIstate'][0])){
849 continue;
850 }
851 }
853 $tmp =array();
854 $tmp['Name'] = $attr['FAIvariable'][0];
855 $tmp['Type'] = $attr['FAIvariableType'][0];
857 if (isset($attr['FAIvariableContent'][0])){
858 if(!in_array($attr['FAIvariableType'],array("multiselect"))){
859 $tmp['Value'] = $attr['FAIvariableContent'][0];
860 }else{
861 $content = array();
862 unset($attr['FAIvariableContent']['count']);
863 foreach($attr['FAIvariableContent'] as $attr){
864 $tmp['Value'][] = $attr;
865 }
866 }
867 $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
868 }
869 }
870 }
873 /*! \brief Returns a list of all configured servers with repositories.
874 @return Array All repository server
875 */
876 function getServerInfos()
877 {
878 $ret = array();
879 $ldap = $this->config->get_ldap_link();
880 $ldap->cd($this->config->current['BASE']);
881 $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
882 while($attrs = $ldap->fetch()){
883 if(isset($attrs['FAIrepository'])){
884 for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){
885 $obj = $attrs['FAIrepository'][$i];
886 $tmp = split("\|",$obj);
887 if(count($tmp)==4){
888 foreach(split(",",$tmp[3]) as $sec){
889 if(!empty($sec)){
890 $ret[$tmp[2]][] = $sec;
891 }
892 }
893 }
894 }
895 }
896 }
897 return($ret);
898 }
901 /*! \brief Used for copy & paste.
902 Returns a HTML input mask, which allows to change the cn of this entry.
903 @param Array Array containing current status && a HTML template.
904 */
905 function getCopyDialog()
906 {
907 $vars = array("cn");
908 $smarty = get_smarty();
909 $smarty->assign("cn", htmlentities($this->cn));
910 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
911 $ret = array();
912 $ret['string'] = $str;
913 $ret['status'] = "";
914 return($ret);
915 }
918 /*! \brief Used for copy & paste.
919 Some entries must be renamed to avaoid duplicate entries.
920 */
921 function saveCopyDialog()
922 {
923 if(isset($_POST['cn'])){
924 $this->cn = get_post('cn');
925 }
926 }
927 }
929 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
930 ?>