diff --git a/trunk/gosa-plugins/fai/admin/fai/class_faiPackage.inc b/trunk/gosa-plugins/fai/admin/fai/class_faiPackage.inc
index f801ece82281382189d3ebc78f5e0efd5ef0ce86..796b72da70d7ab1277adb0e8d25e75b4e136dcf4 100644 (file)
var $sub64coded = array();
var $ConfiguredPackages = array();
- var $ConfigurationsToRemove = array();
+ var $Removal = array();
/* Specific attributes */
var $cn = ""; // The class name for this object
var $direct_packages_add = FALSE;
var $configure_dialog_shown = FALSE;
+ var $debconf_configurations = FALSE;
function faiPackage (&$config, $dn= NULL)
{
ksort($this->usedPackages);
}
- /* Fetch all package configurations from ldap
- */
- $PackageFilter = "";
- foreach($this->usedPackages as $name => $value){
- $PackageFilter .= "(FAIpackage=".$name.")";
- }
- /* Also fetch d-i */
- $PackageFilter .= "(FAIpackage=d-i)";
-
- $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
-
- /* Search for configuration objects */
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($this->dn);
- $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
- "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
-
- /* Walk through configurations and append them to our list of ConfiguredPackages
- */
- while($attr = $ldap->fetch()){
-
- /* Skip objects, that are tagged as removed */
- if(isset($object['FAIstate'][0])){
- if(preg_match("/removed$/",$attr['FAIstate'][0])){
- continue;
- }
- }
-
- $tmp =array();
- $tmp['Name'] = $attr['FAIvariable'][0];
- $tmp['Type'] = $attr['FAIvariableType'][0];
-
- if (isset($attr['FAIvariableContent'][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;
- }
- else {
- $tmp['Value'] = "";
- $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
- }
- }
+ /* Fetch package configurations from LDAP */
+ $this->ConfiguredPackages = $this->get_configured_packages($this->usedPackages, $this->dn);
$this->FAIdebianSection = array();
if(isset($this->attrs['FAIdebianSection'])){
$this->list= $this->genPkgs(TRUE);
}
+ function get_configured_packages($packages, $base)
+ {
+ /* Fetch all package configurations from ldap
+ */
+ $PackageFilter = "";
+ foreach($packages as $name => $value){
+ $PackageFilter .= "(FAIpackage=".$name.")";
+ }
+ /* Also fetch d-i */
+ $PackageFilter .= "(FAIpackage=d-i)";
+
+ $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
+
+ /* Search for configuration objects */
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($base);
+ $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
+ "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
+
+ $configured_packages = array();
+
+ /* Walk through configurations and append them to our list of ConfiguredPackages
+ */
+ while($attr = $ldap->fetch()){
+
+ /* Skip objects, that are tagged as removed */
+ if(isset($object['FAIstate'][0])){
+ if(preg_match("/removed$/",$attr['FAIstate'][0])){
+ continue;
+ }
+ }
+
+ $tmp =array();
+ $tmp['Name'] = $attr['FAIvariable'][0];
+ $tmp['Type'] = $attr['FAIvariableType'][0];
+ $tmp['Save'] = TRUE;
+
+ if (isset($attr['FAIvariableContent'][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;
+ }
+ }
+ $configured_packages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
+ }
+ else {
+ $tmp['Value'] = "";
+ $configured_packages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
+ }
+ }
+
+ return $configured_packages;
+ }
+
function execute()
{
}
if(isset($_POST['EditConfigurations']) &&
- $this->acl_is_writeable("FAIpackage")) {
+ $this->acl_is_writeable("FAIdebconfInfo")) {
$this->dialog = new faiDebconfConfigurations($this->config, $this->dn, $this);
$this->dialog->set_acl_base($this->acl_base);
$this->is_dialog = true;
*/
foreach($_POST as $name => $value){
+ /*****
+ * Remove configuration
+ *****/
+ if(!preg_match('/freeze/i', $this->FAIstate) && preg_match('/^remove_configuration_/', $name)){
+ $id = base64_decode(preg_replace("/^remove_configuration_(.*)_[xy]*$/","\\1",$name));
+ if(isset($this->ConfiguredPackages[$id])) {
+ $this->Removal[$id] = $this->ConfiguredPackages[$id];
+ unset($this->ConfiguredPackages[$id]);
+ }
+ }
+
/******
* Mark as removed
******/
-
if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
$id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
if(isset($this->usedPackages[$id])){
} else {
if(!preg_match("/^freeze/", $this->FAIstate)){
$this->ConfiguredPackages= $this->dialog->save();
- $this->ConfigurationsToRemove = $this->dialog->to_remove;
+ foreach($this->ConfiguredPackages as $package => $attrs) {
+ foreach($attrs as $name => $data) {
+ if (isset($data['Save']) && !($data['Save'])) {
+ $dn = "FAIvariable=".$name.",".$this->dn;
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cat($dn);
+ if (!$ldap->count()) {
+ unset($this->ConfiguredPackages[$package][$name]);
+ }
+ }
+ }
+ if (is_array($this->ConfiguredPackages[$package])) {
+ if (count($this->ConfiguredPackages[$package]) == 0) {
+ unset($this->ConfiguredPackages[$package]);
+ }
+ }
+ }
}
$this->dialog = false;
$this->is_dialog = false;
/* Append message if package is configured */
$configured = "<img src='images/empty.png' alt=' ' class='center'>";
if(isset($this->ConfiguredPackages[$usedName])){
- $configured = "<img src='plugins/fai/images/package_configure.png' alt='"._("Configured")."'
- title='"._("Configured")."' class='center'>";
+ $configured = "<input type='image' name='remove_configuration_".base64_encode($usedName)."' src='plugins/fai/images/package_configure.png' title='"._("Remove configuration")."'
+ title='"._("Remove configuration")."' class='center'>";
}
/* Adapt used name if we're marked for removal */
foreach($tmp['plProvidedAcls'] as $name => $translated){
$smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
}
+
+ if ($this->acl_is_writeable("FAIdebconfInfo")) {
+ $this->debconf_configurations = TRUE;
+ }
$smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
$smarty->assign("divlist",$divlist->DrawList());
$smarty->assign("sections",$this->sections);
$smarty->assign("section" ,$strsec);
$smarty->assign("direct_packages_add", $this->direct_packages_add);
+ $smarty->assign("debconf_configurations", $this->debconf_configurations);
$display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
return($display);
}
$message[] = msgPool::duplicated(_("Name"));
}
}
+
+ if (preg_match("/^-/", $this->cn)) {
+ $message[] = sprintf(_("The specified classname '%s' is invalid. Classnames must not start with a dash."), $this->cn);
+ }
+
+ if($this->cn != preg_replace("/ /","",trim($this->cn))){
+ $message[] = msgPool::invalid(_("Name"),preg_replace("/ /","_",$this->cn),"/[^_]/");
+ }
+
return ($message);
}
$ldap->cd($this->dn);
/* Save Package configurations */
+ foreach($this->Removal as $pkgname => $attrs){
+ /* Skip entries which are back in the ConfiguredPackages array */
+ if (isset($this->ConfiguredPackages[$pkgname])) {
+ continue;
+ }
+ foreach($attrs as $name => $attr){
+ $dn = "FAIvariable=".$name.",".$this->dn;
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cat($dn);
+ if ($ldap->count()) {
+ FAI::prepare_to_save_FAI_object($dn,array(),true);
+ }
+ }
+ }
+
foreach($this->ConfiguredPackages as $pkgname => $attrs){
foreach($attrs as $name => $attr){
$pkgattrs = array();
$pkgattrs['FAIvariableContent'] = $attr['Value'];
$pkgdn = "FAIvariable=".$name.",".$this->dn;
+ if (!$attr['Save']) {
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cat($pkgdn);
+ if ($ldap->count()) {
+ FAI::prepare_to_save_FAI_object($pkgdn,array(),true);
+ }
+ else {
+ unset($this->ConfiguredPackages[$pkgname][$name]);
+ }
+ if (is_array($this->ConfiguredPackages[$pkgname]) && count($this->ConfiguredPackages[$pkgname]) == 0) {
+ unset($this->ConfiguredPackages[$pkgname]);
+ }
+
+ continue;
+
+ }
+
+ if (empty($pkgattrs['FAIvariableContent'])) {
+ $pkgattrs['FAIvariableContent'] = array();
+ }
+
if (is_array($pkgattrs['FAIvariableContent'])) {
$ldap = $this->config->get_ldap_link();
$ldap->cat($pkgdn);
}
}
}
-
- /* Remove obsolete configurations */
- foreach($this->ConfigurationsToRemove as $package => $attr) {
- foreach($attr as $name => $attr) {
- $dn = "FAIvariable=".$name.",".$this->dn;
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($dn);
- $ldap->rmdir($dn);
- }
- }
}
$this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
}
}
+ $this->ConfiguredPackages = $this->get_configured_packages($this->usedPackages, $source['dn']);
- /* Create one filter with all package names,
- instead of calling $ldap->search for every single package
- */
- $PackageFilter = "";
- foreach($this->usedPackages as $name){
- $PackageFilter .= "(FAIpackage=".$name.")";
- }
-
- /* Search for configuration objects */
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($source['dn']);
- $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
-
- /* Walk through configurations and append them to our list of ConfiguredPackages */
- while($attr = $ldap->fetch()){
-
- /* Skip objects, that are tagged as removed */
- if(isset($object['FAIstate'][0])){
- if(preg_match("/removed$/",$attr['FAIstate'][0])){
- continue;
- }
- }
-
- $tmp =array();
- $tmp['Name'] = $attr['FAIvariable'][0];
- $tmp['Type'] = $attr['FAIvariableType'][0];
-
- if (isset($attr['FAIvariableContent'][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;
- }
- }
}