Code

Updated loading of kernel packages
[gosa.git] / gosa-plugins / goto / admin / systems / goto / Device / class_InstallRecipe.inc
index bd6a5c07570efde450808d7c08d459e4acc1d2d6..c3908a4054b6a7e992bd51c7ebdc854fa0e0dd19 100644 (file)
@@ -4,42 +4,61 @@ class InstallRecipe extends plugin
 {
 
     public $rpcErrorMessage = "";
+    public $deviceUUID = "";
 
-    /* Plugin attributes
-     */
+    // Template options
     public $installTemplate = "";
+    public $installationTemplateNames = array();
+    public $templateToRelease = array();
+    public $installationTemplates = array();
+    
+    // The selected installation release
     public $installRelease = "";
+
+    // Selected config management variant
     public $installConfigManagement = '';
-    public $installConfigManagementList = NULL;
+    public $installConfigManagementList = array();
+
+    // Bootstrap method
     public $installBootstrapMethod = '';
-    public $installBootstrapMethodList = NULL;
+    public $installBootstrapMethodList = array();
+
+    // Timezone settings
     public $installTimezone = "";
     public $installTimeUTC = "";
 
+    // Kernel packages
     public $installKernelPackage = "";
     public $installKernelPackageList = array();
 
+    // System Locale
     public $installSystemLocale = "";
     public $installSystemLocaleList = array();
 
+    // Selected NTP Server
     public $installNTPServer = array();
-    private $installNTPServerList = NULL;
+    public $installNTPServerList = NULL;
 
+    // Root password
     public $installRootEnabled = "";
     public $installRootPasswordHash = "";
     public $setPasswordHash = FALSE;
 
+    // Partition table variables
     public $installPartitionTable = "";
+    private $partitionEdit = NULL;
 
+    // Keyboard-layout attribute
     public $installKeyboardlayout = "";
     public $installKeyboardlayoutList = array();
 
-    public $installMirrorDN = "";
-    public $installMirrorDNList = array();
+    // Mirror related attribute
+    public $installMirror = "";
+    public $installMirrorList = array();
 
     public $objectclasses = array();
     public $attributes = array("installRelease", "installTemplate","installKeyboardlayout","installSystemLocale",
-            "installTimezone","installTimeUTC","installNTPServer","installMirrorDN",
+            "installTimezone","installTimeUTC","installNTPServer","installMirror",
             "installRootEnabled","installRootPasswordHash","installKernelPackage",
             "installPartitionTable","installConfigManagement","installBootstrapMethod");
 
@@ -49,15 +68,20 @@ class InstallRecipe extends plugin
      */
     public $view_logged = FALSE;
     public $ignore_account = FALSE;
-
+    public $parent = NULL;
 
     /*! \brief  Initialize the plugin and its widgets. 
      *          Finally call init() to load values from the backend.
      */ 
-    function __construct(&$config, $dn)
+    function __construct(&$config, $dn, $parent)
     {
         plugin::plugin($config, $dn);
 
+        $this->is_account = $this->initially_was_account = FALSE;
+
+        $this->_device = &$parent;
+        $this->deviceUUID = $parent->deviceUUID;
+
         // Set default password hash
         $this->hash = $this->config->get_cfg_value("core","passwordDefaultHash"); 
 
@@ -68,8 +92,14 @@ class InstallRecipe extends plugin
             $this->hashes[$name] = $name;
         }
 
-        // Init the object values.
+        // Initialize plugin
         $this->init_static_info();
+        $this->init($initially = TRUE); 
+    }
+
+    function init($initially = FALSE)
+    {
+        // Init the object values.
         $this->init_client_info();
 
         // Prepare NTP servers list 
@@ -85,52 +115,110 @@ class InstallRecipe extends plugin
             $this->installTemplate = key($this->installationTemplates);
             $this->installRelease = key($this->templateToRelease[$this->installTemplate]);
         }else{
+
             if(!isset($this->installationTemplates[$this->installTemplate])){
-                print "<br>Invalid template selected {$this->installTemplate}";
-                $this->installTemplate = key($this->installationTemplates);
+
+                // The selected template is no longer available, select the next selectable template.
+                $new = key($this->installationTemplates);
+
+                if($initially){
+                    $message = sprintf(_("The selected template '%s' is no longer available. Selecting '%s' as replacement!"), 
+                            $this->installTemplate, $new);
+                    msg_dialog::display(_("Warning"), $message, WARNING_DIALOG);
+                }
+                $this->installTemplate = $new;
+                $installRelease = key($this->templateToRelease[$this->installTemplate]); 
+
             }elseif(!isset($this->installationTemplates[$this->installTemplate]['method'])){
-                print "<br>No bootstrap method found!";
-                
+
+                // Not necessary to warn the user here, the input fields will be empty and thus
+                //  avoid saving.
+
             }elseif(!in_array($this->installRelease, $this->templateToRelease[$this->installTemplate])){
-                print "<br>Invalid release selected {$this->installRelease}";
-                $this->installRelease = key($this->templateToRelease[$this->installTemplate]);
+
+                // The selected release is no longer available for the current template
+                // Warn the user and select the next selectable release.
+                $new = key($this->templateToRelease[$this->installTemplate]); 
+                if($initially){
+                    $message = sprintf(_("The selected release '%s' is no longer available. Selecting '%s' as replacement!"),
+                            $this->installRelease, $new);
+                }
+                $this->installRelease = $new;
+                msg_dialog::display(_("Warning"), $message, WARNING_DIALOG);
             }
         } 
+
+        // Update selectable items like kernels and mirrors depending on the current setup (relase)
         $this->installBootstrapMethod = $this->installationTemplates[$this->installTemplate]['method'];
-        $this->reloadInstallationKernelPackages();
-        $this->reloadInstallationMirrors();
+        $this->reloadInstallationKernelPackages($initially);
+        $this->reloadInstallationMirrors($initially);
+
+        // Preset the config management method.
+        if(!isset($this->installConfigManagementList[$this->installBootstrapMethod][$this->installConfigManagement])){
+            if(isset($this->installConfigManagementList[$this->installBootstrapMethod]) && 
+                count($this->installConfigManagementList[$this->installBootstrapMethod])){
+                $this->installConfigManagement = key($this->installConfigManagementList[$this->installBootstrapMethod]);
+            }
+        }
     }
 
    
-    /*! \brief   Load attribute values from the GOsa-backend using jsonRPC 
+    /*! \brief   Loads client-information values from the GOsa-backend using jsonRPC 
      */ 
     function init_client_info()
     {
-        $uuid = "a0d17918-cfb2-11df-acbd-5452005f1250";
+        if(empty($this->deviceUUID)){
+            return;
+        }
+
         $rpc = $this->config->getRpcHandle();
-        $res = $rpc->systemGetBaseInstallParameters($uuid);
+        $res = $rpc->systemGetBaseInstallParameters($this->deviceUUID);
        
         // Failed to load backend values, keep reported error and return with FALSE; 
         $this->rpcError = !$rpc->success();
         if(!$rpc->success()){
             $this->rpcErrorMessage = $rpc->get_error();
+            msg_dialog::display(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
             return(NULL);
         }
-
+   
         // Apply received options
         $this->is_account = $res == True;
         if($this->is_account){
-            $this->installNTPServer = $res['ntp-servers'];
-            $this->installTemplate = $res['template'];
-            $this->installRelease = $res['release'][0];
-            $this->installTimezone = array_search($res['timezone'][0], $this->timezones);
-            $this->installTimeUTC = $res['utc'][0];
-            $this->installKernelPackage = $res['kernel'][0];;
-            $this->installSystemLocale = $res['system-locale'][0];
-            $this->installRootEnabled = $res['root-user'][0];
-            $this->installRootPasswordHash = $res['root-hash'][0];
-            $this->installPartitionTable = $res['disk-setup'][0];
-            $this->installKeyboardlayout = $res['keyboard-layout'];
+
+            $map = array(
+                    'ntp-servers' => "installNTPServer", 
+                    'template' => "installTemplate", 
+                    'keyboard-layout' => "installKeyboardlayout");
+
+            // We receive an array for these attributes, but require a string instead
+            //  we just use the first element of the array.
+            $mapArray = array(
+                    'release' => "installRelease", 
+                    'timezone' => "installTimezone", 
+                    'utc' => "installTimeUTC", 
+                    'kernel' => "installKernelPackage", 
+                    'system-locale' => "installSystemLocale", 
+                    'root-user' => "installRootEnabled", 
+                    'root-hash' => "installRootPasswordHash", 
+                    'disk-setup' => "installPartitionTable");
+            foreach($res as $name => $data){
+                if(isset($map[$name])){
+                    $target = $map[$name];
+                    $value = $res[$name];
+                }elseif(isset($mapArray[$name])){
+                    $target = $mapArray[$name];
+                    $value = $res[$name][0];
+                }
+                $this->$target = $value;
+            }
+
+            // Convert Bool values to Bool.
+            $boolean = array("installRootEnabled", "installTimeUTC");
+            foreach($boolean as $attr){
+                $this->$attr = ($this->$attr != FALSE && !preg_match("/false/i", $this->$attr));
+            }
         }
 
         return;
@@ -193,6 +281,16 @@ class InstallRecipe extends plugin
         }
     }
 
+
+    function check()
+    {
+            // Check if the parents deviceUUID has changed
+            if($this->deviceUUID != $this->_device->deviceUUID){
+                $this->deviceUUID = $this->_device->deviceUUID;
+                print "The device uuid has changed.";
+            }
+    }
+    
     
     function execute()
     {
@@ -219,11 +317,11 @@ class InstallRecipe extends plugin
         $display = "";
         if ($this->parent !== NULL){
             if ($this->is_account){
-                $display= $this->show_disable_header(_("Remove install profile"),
-                        msgPool::featuresEnabled(_("Install profile")));
+                $display= $this->show_disable_header(_("Remove base installation"),
+                        msgPool::featuresEnabled(_("Base installation")));
             } else {
-                $display= $this->show_enable_header(_("Add install profile"),
-                        msgPool::featuresDisabled(_("Install profile")));
+                $display= $this->show_enable_header(_("Add base installation"),
+                        msgPool::featuresDisabled(_("Base installation")));
                 return ($display);
             }
         }
@@ -232,6 +330,7 @@ class InstallRecipe extends plugin
           Root password hash dialog
          ***************/
 
+        $this->dialog = FALSE;
         if($this->setPasswordHash){
             $this->dialog = TRUE;
             $smarty = get_smarty();
@@ -240,6 +339,28 @@ class InstallRecipe extends plugin
             return($smarty->fetch(get_template_path('goto/Device/SetPassword.tpl', TRUE)));
         }
 
+        /***************
+          Partition dialog
+         ***************/
+
+        if(isset($_POST['partition_finish']) && $this->partitionEdit){
+            $this->installPartitionTable = $this->partitionEdit->save();
+            $this->partitionEdit = NULL;
+        }
+        if(isset($_POST['partition_cancel']) && $this->partitionEdit){
+            $this->partitionEdit = NULL;
+        }
+        if(isset($_POST['edit_installPartitionTable'])){
+            $this->partitionEdit = new DevicePartition($this->config, $this->installPartitionTable);
+        }
+        if($this->partitionEdit){
+            $this->partitionEdit->save_object();
+            $this->dialog = TRUE;
+            return($this->partitionEdit->execute());
+        }
+
+
+
         /***************
           Generate HTML content
          ***************/
@@ -249,14 +370,18 @@ class InstallRecipe extends plugin
 
         plugin::execute();    
         $smarty = get_smarty();
-        $smarty->assign('installTemplateList', $this->installationTemplateNames);
-        $smarty->assign('installReleaseList', $this->templateToRelease[$this->installTemplate]);
 
+        // Assign ACLs
+        foreach($this->attributes as $attr){
+            $smarty->assign("{$attr}ACL", $this->getacl($attr));
+        }
 
+        $smarty->assign('installTemplateList', $this->installationTemplateNames);
+        $smarty->assign('installReleaseList', $this->templateToRelease[$this->installTemplate]);
         $smarty->assign('timezones', $this->timezones);
         $smarty->assign('installKeyboardlayoutList', $this->installKeyboardlayoutList);
         $smarty->assign('installKernelPackageList', $this->installKernelPackageList);
-        $smarty->assign('installMirrorDNList', $this->installMirrorDNList);
+        $smarty->assign('installMirrorList', $this->installMirrorList);
         $smarty->assign('installSystemLocaleList', $this->installSystemLocaleList);
         $smarty->assign('installNTPServerList', $this->installNTPServerList->render());
 
@@ -306,6 +431,11 @@ class InstallRecipe extends plugin
             $this->installNTPServerList->setListData($this->installNTPServer);
             $this->installBootstrapMethod = $this->installationTemplates[$this->installTemplate]['method'];
 
+            // The selected release is no longer available for the current template
+            if(!in_array($this->installRelease, $this->templateToRelease[$this->installTemplate])){
+                $this->installRelease = key($this->templateToRelease[$this->installTemplate]);
+            }
+
             // Reload list of kernel packages and mirrors
             if($oldRelease != $this->installRelease){
                 $this->reloadInstallationKernelPackages();
@@ -333,23 +463,48 @@ class InstallRecipe extends plugin
     function save()
     {
         if(!$this->installRootEnabled) $this->installRootPasswordHash = "";
-        
-        $uuid = "a0d17918-cfb2-11df-acbd-5452005f1250";
-        $rpc = $this->config->getRpcHandle();
 
+        $map = array(
+            "installNTPServer"=>'ntp-servers',
+            "installTemplate"=>'template',
+            "installRelease"=>'release',
+            "installTimezone"=>'timezone',
+            "installTimeUTC"=>'utc',
+            "installKernelPackage"=>'kernel',
+            "installSystemLocale"=>'system-locale',
+            "installRootEnabled"=>'root-user',
+            "installRootPasswordHash"=>'root-hash',
+            "installPartitionTable"=>'disk-setup',
+            "installKeyboardlayout"=>'keyboard-layout',
+            );
+
+        // Collect values to be saved.
         $data = array();
-        $res = $rpc->systemSetBaseInstallParameters($uuid, $data);
+        foreach($map as $source => $dest){
+            if(!empty($this->$source)){
+                $data[$dest] = $this->$source;
+             }
+        } 
+
+        // Enforce an array for ntp-servers
+        $data['ntp-servers'] = array_values($data['ntp-servers']);
 
-        
+        // Save Boolean like a String 
+        $boolean = array("root-user" => "installRootEnabled", "utc" => "installTimeUTC");
+        foreach($boolean as $attr => $source){
+            $data[$attr] = ($this->$source) ? $data[$attr] = "TRUE" : $data[$attr] = "FALSE";
+        }
 
+        $rpc = $this->config->getRpcHandle();
+        $res = $rpc->systemSetBaseInstallParameters($this->deviceUUID, $data);
        
         // Failed to load backend values, keep reported error and return with FALSE; 
         $this->rpcError = !$rpc->success();
         if(!$rpc->success()){
             $this->rpcErrorMessage = $rpc->get_error();
+            msg_dialog::display(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
             return(NULL);
         }
-        return($res);
 
     }
 
@@ -362,11 +517,18 @@ class InstallRecipe extends plugin
     
     /*! \brief  Refreshes the list of selectable kernel packages.
      */
-    function reloadInstallationKernelPackages()
+    function reloadInstallationKernelPackages($initially = FALSE)
     {
+        // Do nothing if no release is given.
+        if(empty($this->installRelease)){
+            $this->installKernelPackageList = array();
+            return;
+        }
+
+        $release = preg_replace("/^[^\/]*\//","", $this->installRelease);
         $rpc = $this->config->getRpcHandle();
-        $res = $rpc->getKernelPackages($this->installRelease);
-      
+        $res = $rpc->getKernelPackages($release);
+     
         // Failed to load backend values, keep reported error and return with FALSE; 
         $this->rpcError = !$rpc->success();
         if(!$rpc->success()){
@@ -374,13 +536,16 @@ class InstallRecipe extends plugin
             msg_dialog::display(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
         }else{
             $this->installKernelPackageList = array();
-            foreach($res as $name){
+            foreach($res as $data){
+                $name = $data['name'];
                 $this->installKernelPackageList[$name] = $name;
             }
 
             if(!isset($this->installKernelPackageList[$this->installKernelPackage])){
                 $new = key($this->installKernelPackageList);
-                msg_dialog::display(_("Warning"), sprintf(_("The selected kernel package '%s' is no longer available! The kernel package '%s' was selected as replacement!"), $this->installKernelPackage, $new), WARNING_DIALOG);
+                if($initially){
+                    msg_dialog::display(_("Warning"), sprintf(_("The selected kernel package '%s' is no longer available! The kernel package '%s' was selected as replacement!"), $this->installKernelPackage, $new), WARNING_DIALOG);
+                }
                 $this->installKernelPackage = $new;
             }
         }
@@ -426,12 +591,12 @@ class InstallRecipe extends plugin
     /*! \brief  Returns a list of installation mirrors on success.
      *          In case of an error, it returns NULL.
      */
-    function reloadInstallationMirrors()
+    function reloadInstallationMirrors($initially = FALSE)
     {
         $res = array(
                 'dc=intranet,dc=gonicus,dc=de' => 'Intranet',
                 'ou=systems,dc=intranet,dc=gonicus,dc=de' => 'System');
-        $this->installMirrorDNList =$res;
+        $this->installMirrorList =$res;
     }
 
 
@@ -488,6 +653,7 @@ class InstallRecipe extends plugin
         $this->rpcError = !$rpc->success();
         if(!$rpc->success()){
             $this->rpcErrorMessage = $rpc->get_error();
+            msg_dialog::display(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
             return(NULL);
         }
 
@@ -533,21 +699,20 @@ class InstallRecipe extends plugin
                     "plSection"     => array("administration"),
                     "plCategory"    => array("Device"),
                     "plProvidedAcls" => array(
-                        "member" => _("Member"),
-                        "installTemplate" => _("Installation template"),
-                        "installRelease" => _("Installation release"),
 
-                        "installBootstrapMethod" => _("Bootstrap method"),
-                        "installConfigManagement" => _("Config management"),
+                        "installRelease" => _("Release"),
+                        "installTemplate" => _("Template"),
                         "installKeyboardlayout" => _("Keyboard layout"),
-                        "installSystemLocale" => _("System locale"),
+                        "installSystemLocale" => _("Locale"),
                         "installTimezone" => _("Timezone"),
-                        "installTimeUTC" => _("Time"),
-                        "installNTPServer" => _("NTP-Server"),
-                        "installMirrorDN" => _("Mirror"),
+                        "installTimeUTC" => _("Utc"),
+                        "installNTPServer" => _("Ntp server"),
+                        "installMirror" => _("Mirror"),
                         "installRootEnabled" => _("Root login enabled"),
                         "installRootPasswordHash" => _("Root password hash"),
                         "installKernelPackage" => _("Kernel package"),
+                        "installConfigManagement" => _("Config mangement"),
+                        "installBootstrapMethod" => _("Bootstrap method"),
                         "installPartitionTable" => _("Partition table")
                         )
                         )