Code

initial commit for package configurations
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 22 Nov 2005 11:27:28 +0000 (11:27 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 22 Nov 2005 11:27:28 +0000 (11:27 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2005 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/fai/class_faiPackage.inc
plugins/admin/fai/class_faiPackageConfiguration.inc
plugins/admin/fai/faiPackage.tpl
plugins/admin/fai/faiPackageConfiguration.tpl

index a00c1fdcfffd2e5138d0cc1d5086dd795d3efe6b..2c78f60acf8d578f09afe32a01ef30fa0b70c025 100644 (file)
@@ -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*/
index ddf7577eaaa80ff39b9cd788d9a8bb098ee4f141..bebd828679bed97845ced3e62b88eb28050de52a 100644 (file)
@@ -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:
index 90e1b4f294b4af6a279c09d42aa1abbaf646db08..61d76f2568b3bdbb0f1fd1f71710799323052ef2 100644 (file)
@@ -73,7 +73,7 @@
                        <br>
                        <input type="submit" name="Addpkg" value="{t}Add{/t}" {$OptionsACL}>
                        <input type="submit" name="Delpkg" value="{t}Remove{/t}"  {$OptionsACL}>
-                       <input type="submit" name="Conpkg" value="{t}Configure{/t}"  {$OptionsACL} disabled>
+                       <input type="submit" name="Conpkg" value="{t}Configure{/t}"  {$OptionsACL} >
                </td>
        </tr>
 </table>
index 8b39901d8fece1d208b6ab1a1fd66f0ea2be39e6..2745c1d0b07f443a3e28a75ddf1dee01047ad96e 100644 (file)
@@ -1,5 +1,6 @@
 <h2><img alt="" src="images/forward.png" align="middle" title="{t}Generic{/t}">&nbsp;{t}Generic{/t}</h2>
 
+{$Config}
 <div align="right" style="align:right;">
     <input name="SaveObjectConfig" value="Use" type="submit">
     <input name="CancelObjectConfig" value="Cancel" type="submit">