From 4944dfc9a7e4bcd9a5c3aa63078f0514bc975131 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 22 Nov 2005 11:27:28 +0000 Subject: [PATCH] initial commit for package configurations git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2005 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/fai/class_faiPackage.inc | 69 ++++++++++++++++++- .../fai/class_faiPackageConfiguration.inc | 36 ++++++++-- plugins/admin/fai/faiPackage.tpl | 2 +- plugins/admin/fai/faiPackageConfiguration.tpl | 1 + 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/plugins/admin/fai/class_faiPackage.inc b/plugins/admin/fai/class_faiPackage.inc index a00c1fdcf..2c78f60ac 100644 --- a/plugins/admin/fai/class_faiPackage.inc +++ b/plugins/admin/fai/class_faiPackage.inc @@ -27,6 +27,8 @@ class faiPackage extends plugin var $subAttributes = array("cn","description"); var $sub64coded = array(); + var $ConfiguredPackages = array(); + /* Specific attributes */ var $cn = ""; // The class name for this object var $description = ""; // The description for this set of partitions @@ -74,6 +76,28 @@ class faiPackage extends plugin }else{ $this->usedPackages = array(); } + + $ldap = $this->config->get_ldap_link(); + foreach($this->usedPackages as $name){ + $ldap->search("(&(objectClass=FAIdebconfInfo)(FAIpackage=".$name."))"); + while($attr = $ldap->fetch()){ + + $tmp =array(); + $tmp['Name'] = $attr['FAIvariable'][0]; + $tmp['Type'] = $attr['FAIvariableType'][0]; + + if(!in_array($attr['FAIvariableType'],array("multiselect"))){ + $tmp['Value'] = $attr['FAIvariableContent'][0]; + }else{ + $content = array(); + unset($attr['FAIvariableContent']['count']); + foreach($attr['FAIvariableContent'] as $attr){ + $tmp['Value'][] = $attr; + } + } + $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; + } + } if (isset($this->attrs['FAIdebianSection']['count'])){ unset($this->attrs['FAIdebianSection']['count']); @@ -98,6 +122,7 @@ class faiPackage extends plugin function execute() { /* Call parent execute */ + plugin::execute(); /* Fill templating stuff */ @@ -211,13 +236,20 @@ class faiPackage extends plugin } /* Configuration dialog open*/ - if(isset($_POST['Conpkg'])){ - $this->dialog = new faiPackageConfiguration($this->config, $this->dn,"none"); + if((isset($_POST['Conpkg']))&&(isset($_POST['usedPackages']))&&(!empty($_POST['usedPackages']))){ + $path = "/etc/gosa/fai/".preg_replace("#^[^/]+//([^/]+).*$#","\\1",$this->FAIdebianMirror)."/".$this->FAIdebianRelease."/".$sec; + $pkg_config = array(); + if(isset($this->ConfiguredPackages[$_POST['usedPackages']])){ + $pkg_config = $this->ConfiguredPackages[$_POST['usedPackages']]; + } + + $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$_POST['usedPackages'], $path, $pkg_config); $this->is_dialog =true; } - + /* Save Configuration */ if(isset($_POST['SaveObjectConfig'])){ + $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save()); $this->dialog = false; $this->is_dialog=false; } @@ -419,6 +451,37 @@ class faiPackage extends plugin $this->attrs['FAIdebianSection'][] = $sec; } + /* Save Package configurations */ + foreach($this->ConfiguredPackages as $pkgname => $attrs){ + foreach($attrs as $name => $attr){ + + foreach($attr as $n=>$v){ + if(empty($v)) $v = array(); + } + + /* Set attributes */ + $pkgattrs['objectClass'] = "FAIdebconfInfo"; + $pkgattrs['FAIpackage'] = $pkgname; + $pkgattrs['FAIvariable'] = $name; + $pkgattrs['FAIvariableType'] = $attr['Type']; + $pkgattrs['FAIvariableContent'] = $attr['Value']; + $pkgdn = "FAIvariable=".$name.",".$this->dn; + + /* cehck if object already exists */ + $ldap->cat($pkgdn); + if($ldap->count()!=0){ + $ldap->cd($pkgdn); + $ldap->modify($pkgattrs); + }else{ + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $pkgdn)); + $ldap->cd($pkgdn); + $ldap->add($pkgattrs); + } + show_ldap_error($ldap->get_error()); + } + } + $ldap->cat($this->dn); if($ldap->count()!=0){ /* Write FAIscript to ldap*/ diff --git a/plugins/admin/fai/class_faiPackageConfiguration.inc b/plugins/admin/fai/class_faiPackageConfiguration.inc index ddf7577ea..bebd82867 100644 --- a/plugins/admin/fai/class_faiPackageConfiguration.inc +++ b/plugins/admin/fai/class_faiPackageConfiguration.inc @@ -12,22 +12,38 @@ class faiPackageConfiguration extends plugin var $attributes = array(); var $objectclasses = array(); + var $path; + + var $Debconf_handle = NULL; + var $pkg_config ; var $obj; - function faiPackageConfiguration ($config, $dn= NULL,$obj) + function faiPackageConfiguration ($config, $dn= NULL,$obj,$path,$pkg_config) { plugin::plugin ($config, $dn); $this->obj = $obj; + $this->Debconf_handle = new debconf($this->obj, "de"); + $this->Debconf_handle->set_template_directory($this->path); + $this->pkg_config = $pkg_config; + + foreach($this->pkg_config as $var){ + $this->Debconf_handle->SetDefault($var['Name'],$var['Value']); + } } function execute() { - /* Call parent execute */ - plugin::execute(); + /* Call parent execute */ + plugin::execute(); /* Fill templating stuff */ $smarty = get_smarty(); - $display = ""; + $display = "$this->obj"; + + $this->Debconf_handle -> PostCheck(); + + $smarty->assign("Config",$this->Debconf_handle->get_dialog()); + $display.= $smarty->fetch(get_template_path('faiPackageConfiguration.tpl', TRUE)); return($display); } @@ -46,6 +62,18 @@ class faiPackageConfiguration extends plugin function save() { + $this->Debconf_handle->set_template_directory($this->path); + + $this->Debconf_handle -> PostCheck(); + $pkgs = $this->Debconf_handle->template; + + $tmp = array(); + foreach($pkgs as $pkg){ + $tmp[$this->obj][$pkg['Name']]['Value']= $pkg['Default']; + $tmp[$this->obj][$pkg['Name']]['Name'] = $pkg['Name']; + $tmp[$this->obj][$pkg['Name']]['Type'] = $pkg['Type']; + } + return($tmp); } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/plugins/admin/fai/faiPackage.tpl b/plugins/admin/fai/faiPackage.tpl index 90e1b4f29..61d76f256 100644 --- a/plugins/admin/fai/faiPackage.tpl +++ b/plugins/admin/fai/faiPackage.tpl @@ -73,7 +73,7 @@
- + diff --git a/plugins/admin/fai/faiPackageConfiguration.tpl b/plugins/admin/fai/faiPackageConfiguration.tpl index 8b39901d8..2745c1d0b 100644 --- a/plugins/admin/fai/faiPackageConfiguration.tpl +++ b/plugins/admin/fai/faiPackageConfiguration.tpl @@ -1,5 +1,6 @@

 {t}Generic{/t}

+{$Config}
-- 2.30.2