Code

Added password hash generation to recipe tab
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 29 Sep 2010 13:12:37 +0000 (13:12 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 29 Sep 2010 13:12:37 +0000 (13:12 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19849 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/Device/InstallRecipe.tpl
gosa-plugins/goto/admin/systems/goto/Device/class_InstallRecipe.inc

index 9bc45d78fa402fbefe24c3d92ac26c5ce4dbf137..d095003909f4566f409791aae1c8ca743fd497c0 100644 (file)
@@ -1,20 +1,53 @@
-<table>
+
+<h3>{t}Installation type{/t}</h3>
+<table style='width:100%;'>
     <tr>
-        <td><LABEL for="kickstartRootEnabled">{t}Root enabled{/t}</LABEL></td>
-        <td>
-            <input type='checkbox' value='1' {if $kickstartRootEnabled} checked {/if}
-                onClick="changeState('kickstartRootPasswordHash');"
-                name="kickstartRootEnabled" id="kickstartRootEnabled" 
-               >
+        <td style='width:50%; vertical-align: top;'>
+            <h3>{t}Bootstrap settings{/t}</h3>
+    
+            <table>
+            </table>
+        </td>
+        <td style='width:50%; vertical-align: top;padding-left:5px;' class='left-border'>
+            <h3>{t}Login{/t}</h3>
+
+            <table>
+                <tr>
+                    <td>
+                        <input type='checkbox' value='1' {if $kickstartRootEnabled} checked {/if}
+                            onClick="changeState('setKickstartRootPasswordHash');"
+                            name="kickstartRootEnabled" id="kickstartRootEnabled" 
+                           >
+                        <LABEL for="kickstartRootEnabled">{t}Use root-user{/t}</LABEL>&nbsp;
+                        <button name='setKickstartRootPasswordHash'
+                            {if !$kickstartRootEnabled} disabled {/if}
+                            id="setKickstartRootPasswordHash">{t}Set password{/t}</button>
+                    </td>
+                </tr>
+            </table>
         </td>
     </tr>
     <tr>
-        <td><LABEL for="kickstartRootPasswordHash">{t}Root password hash{/t}</LABEL></td>
-        <td>
-            <input type='text' name="kickstartRootPasswordHash" id="kickstartRootPasswordHash"
-                {if !$kickstartRootEnabled} disabled {/if} value="{$kickstartRootPasswordHash}">
+        <td colspan=2><hr></td>
+    </tr>
+    <tr>
+        <td style='width:50%; vertical-align: top;'>
+            <h3>{t}Locale{/t}</h3>
+
+            <table>
+            </table>
+        </td>
+        <td style='width:50%; vertical-align: top;padding-left:5px;' class='left-border'>
+            <h3>{t}Time{/t}</h3>
+
+            <table>
+            </table>
         </td>
     </tr>
+</table>
+
+
+<table>
     <tr>
         <td><LABEL for="kickstartTemplateDN">{t}Kickstart template{/t}</LABEL></td>
         <td>
     </tr>
 </table>
 
+<input type='hidden' name='InstallRecipePosted' value=1>
index 15a95f1ebdfb63c2b90d5c616a73412f694eb12f..64bdd2029d1835994bc23a7be539d6b23e7e37b8 100644 (file)
@@ -19,6 +19,8 @@ class InstallRecipe extends plugin
             "kickstartTimezone","kickstartTimeUTC","kickstartNTPServer","kickstartMirrorDN",
             "kickstartRootEnabled","kickstartRootPasswordHash","kickstartKernelPackage","kickstartPartitionTable");
 
+    public $setKickstartRootPasswordHash = FALSE;
+
     function __construct(&$config, $dn)
     {
         plugin::plugin($config, $dn);
@@ -44,29 +46,75 @@ class InstallRecipe extends plugin
         }  
         uksort($list, 'strnatcasecmp'); 
         $this->timezones = $list;
+
+        // Get list of password hashes
+        $tmp = passwordMethod::get_available_methods();
+        $this->hashes = array();
+        foreach($tmp['name'] as $name){
+            $this->hashes[$name] = $name;
+        }
+        $this->hash = $this->config->get_cfg_value("core","passwordDefaultHash"); 
     }
 
     function execute()
     {
+        
+
+        if($this->setKickstartRootPasswordHash){
+            $this->dialog = TRUE;
+            $smarty = get_smarty();
+            $smarty->assign('hashes', set_post($this->hashes));
+            $smarty->assign('hash', set_post($this->hash));
+            return($smarty->fetch(get_template_path('goto/Device/SetPassword.tpl', TRUE)));
+        }
+
+
         plugin::execute();    
         $smarty = get_smarty();
         $smarty->assign('timezones', $this->timezones);
         foreach($this->attributes as $attr){
             $smarty->assign($attr, $this->$attr);
         }
+        $this->dialog = false;
         return($smarty->fetch(get_template_path('goto/Device/InstallRecipe.tpl', TRUE)));
     }
 
-    
+
     function save_object()
     {
-        plugin::save_object();
-        $this->kickstartRootEnabled = isset($_POST['kickstartRootEnabled']);
+        if(isset($_POST['InstallRecipePosted'])){
+            plugin::save_object();
+            $this->kickstartRootEnabled = isset($_POST['kickstartRootEnabled']);
+
+
+            if(isset($_POST['setKickstartRootPasswordHash'])){
+                $this->setKickstartRootPasswordHash = true;
+            }
+        }
+        if(isset($_POST['cancelPassword'])) $this->setKickstartRootPasswordHash =false;
+        if(isset($_POST['setPassword'])) {
+            $this->setKickstartRootPasswordHash =false;
+            $hash = get_post('passwordHash');
+
+            // Not sure, why this is here, but maybe some encryption methods require it.
+            mt_srand((double) microtime()*1000000);
+
+            // Generate the requested hash
+            $methods = new passwordMethod($this->config, $this->dn);
+            $available = $methods->get_available_methods();
+            $test = new $available[$hash]($this->config,$this->dn);
+            $this->kickstartRootPasswordHash = @$test->generate_hash(get_post('rootPassword'));
+        }
     }
 
 
     function save()
     {
+        // 
+        if(!$this->kickstartRootEnabled) $this->kickstartRootPasswordHash = "";
+        $this->kickstartRootEnabled = ($this->kickstartRootEnabled)?'TRUE':'FALSE';
+        
+
         plugin::save();
 
         $this->cleanup();