Browse code

Adding password confirmation to the installer

Mahmoud Bassiouny authored on 2015/07/16 05:58:20
Showing 6 changed files
... ...
@@ -11,8 +11,11 @@ from actionresult import ActionResult
11 11
 
12 12
 class ConfirmWindow(Window):
13 13
 
14
-    def __init__(self, height, width, maxy, maxx, menu_starty, message):
15
-        items =   [
14
+    def __init__(self, height, width, maxy, maxx, menu_starty, message, info=False):
15
+        if info:
16
+            items =   [('OK',  self.exit_function, True)]
17
+        else:
18
+            items =   [
16 19
                         ('Yes',  self.exit_function, True),
17 20
                         ('No',  self.exit_function, False)
18 21
                     ]
... ...
@@ -116,12 +116,15 @@ class IsoInstaller(object):
116 116
             license_agreement = License(self.maxy, self.maxx)
117 117
             select_disk = SelectDisk(self.maxy, self.maxx, self.install_config)
118 118
             package_selector = PackageSelector(self.maxy, self.maxx, self.install_config, options_file)
119
-            hostname_reader = WindowStringReader(self.maxy, self.maxx, 10, 70, False,  'Choose the hostname for your system',
119
+            hostname_reader = WindowStringReader(self.maxy, self.maxx, 10, 70, False, False, 'Choose the hostname for your system',
120 120
                 'Hostname:', 
121 121
                 2, self.install_config)
122
-            root_password_reader = WindowStringReader(self.maxy, self.maxx, 10, 70, True,  'Set up root password',
122
+            root_password_reader = WindowStringReader(self.maxy, self.maxx, 10, 70, True, False,  'Set up root password',
123 123
                 'Root password:', 
124 124
                 2, self.install_config)
125
+            confirm_password_reader = WindowStringReader(self.maxy, self.maxx, 10, 70, True, True,  'Confirm root password',
126
+                'Confirm Root password:', 
127
+                2, self.install_config)
125 128
             
126 129
             items = items + [
127 130
                     (license_agreement.display, False),
... ...
@@ -129,6 +132,7 @@ class IsoInstaller(object):
129 129
                     (package_selector.display, True),
130 130
                     (hostname_reader.get_user_string, True),
131 131
                     (root_password_reader.get_user_string, True),
132
+                    (confirm_password_reader.get_user_string, False),
132 133
                  ]
133 134
         installer = Installer(self.install_config, self.maxy, self.maxx, True, rpm_path=rpm_path, log_path="/var/log", ks_config=ks_config)
134 135
         items = items + [(installer.install, False)]
... ...
@@ -11,19 +11,19 @@ import random
11 11
 import cracklib
12 12
 from actionresult import ActionResult
13 13
 from action import Action
14
+from confirmwindow import ConfirmWindow
14 15
 
15 16
 class ReadText(Action):
16
-    def __init__(self, textwin, y, install_config, ispassword):
17
+    def __init__(self, maxy, maxx, textwin, y, install_config, ispassword, confirm_pass):
17 18
         self.textwin = textwin
19
+        self.maxy = maxy
20
+        self.maxx = maxx
18 21
         self.y = y
19 22
         self.install_config = install_config
20 23
         self.ispassword = ispassword
21
-        self.x = 0
22
-
23
-        #initialize the ----
24
-        dashes = '_' * (self.textwin.getmaxyx()[1] - 1)
25
-        self.textwin.addstr(self.y, 0, dashes)
26
-        self.str = ''
24
+        self.confirm_pass = confirm_pass;
25
+        
26
+        self.init_text()        
27 27
 
28 28
         #initialize the accepted characters
29 29
         if self.ispassword:
... ...
@@ -46,21 +46,42 @@ class ReadText(Action):
46 46
     def hide(self):
47 47
         return
48 48
     
49
+    def init_text(self):
50
+        self.x = 0;
51
+        #initialize the ----
52
+        dashes = '_' * (self.textwin.getmaxyx()[1] - 1)
53
+        self.textwin.addstr(self.y, 0, dashes)
54
+        self.str = ''
55
+
56
+        #remove the error messages
57
+        spaces = ' ' * (self.textwin.getmaxyx()[1] - 1)
58
+        self.textwin.addstr(self.y + 2, 0, spaces)
59
+
49 60
     def do_action(self):
61
+        self.init_text()
50 62
         curses.curs_set(1)
51 63
 
52 64
         while True:
53 65
             ch = self.textwin.getch(self.y, self.x)
54 66
 
55 67
             if ch in [curses.KEY_ENTER, ord('\n')]:
56
-                if self.ispassword:
68
+                if self.confirm_pass:
69
+                    if self.str != self.install_config['password']:
70
+                        curses.curs_set(0)
71
+                        conf_message_height = 8
72
+                        conf_message_width = 40
73
+                        conf_message_button_y = (self.maxy - conf_message_height) / 2 + 5
74
+                        confrim_window = ConfirmWindow(conf_message_height, conf_message_width, self.maxy, self.maxx, conf_message_button_y, "passwords don't match, please try again.", True)
75
+                        confrim_window.do_action()
76
+                        return ActionResult(False, {'goBack': True})
77
+                    self.install_config['password'] = self.generate_password_hash(self.str)
78
+                elif self.ispassword:
57 79
                     err = self.validate_password(self.str)
58 80
                     if err != self.str:
59
-                        spaces = ' ' * (self.textwin.getmaxyx()[1] - 1)
60
-                        self.textwin.addstr(self.y + 2, 0, spaces)
81
+                        self.init_text()
61 82
                         self.textwin.addstr(self.y + 2, 0, "Error: " + err, curses.color_pair(4))
62 83
                         continue
63
-                    self.install_config['password'] = self.generate_password_hash(self.str);
84
+                    self.install_config['password'] = self.str;
64 85
                 else:
65 86
                     if not self.validate_hostname(self.str):
66 87
                         self.textwin.addstr(self.y + 2, 0, "It should start with alpha char and ends with alpha-numeric char", curses.color_pair(4))
... ...
@@ -87,6 +108,8 @@ class ReadText(Action):
87 87
                 self.x += 1
88 88
 
89 89
     def validate_hostname(self, hostname):
90
+        if (hostname == None or len(hostname) == 0):
91
+            return False;
90 92
         return (ord(hostname[0]) in self.alpha_chars) and (hostname[-1] not in ['.', '-'])
91 93
 
92 94
     def validate_password(self, text):
... ...
@@ -51,9 +51,14 @@ class Window(Action):
51 51
             self.hide_window()
52 52
             return action_result
53 53
         else:
54
-            #highlight the GoBack and keep going
55
-            self.contentwin.addstr(self.height - 3, 5, '<Go Back>', curses.color_pair(3))
56
-            self.contentwin.refresh()
54
+            if (action_result.result != None and 'goBack' in action_result.result and action_result.result['goBack']):
55
+                self.hide_window()
56
+                self.action_panel.hide()
57
+                return action_result
58
+            else:
59
+                #highlight the GoBack and keep going
60
+                self.contentwin.addstr(self.height - 3, 5, '<Go Back>', curses.color_pair(3))
61
+                self.contentwin.refresh()
57 62
 
58 63
         while action_result.success == False:
59 64
             key = self.contentwin.getch()
... ...
@@ -9,8 +9,7 @@ from window import Window
9 9
 from readtext import ReadText
10 10
 
11 11
 class WindowStringReader(object):
12
-    def __init__(self, maxy, maxx, height, width, ispassword, title, display_string, inputy, install_config):
13
-        self.ispassword = ispassword
12
+    def __init__(self, maxy, maxx, height, width, ispassword, confirm_password, title, display_string, inputy, install_config):
14 13
         self.title = title
15 14
         self.display_string = display_string
16 15
         self.inputy = inputy
... ...
@@ -24,7 +23,7 @@ class WindowStringReader(object):
24 24
         self.starty = (self.maxy - self.height) / 2
25 25
 
26 26
         self.window = Window(self.height, self.width, self.maxy, self.maxx, self.title, True)
27
-        self.read_text = ReadText(self.window.content_window(), self.inputy, install_config, self.ispassword)
27
+        self.read_text = ReadText(maxy, maxx, self.window.content_window(), self.inputy, install_config, ispassword, confirm_password)
28 28
         self.window.set_action_panel(self.read_text)
29 29
         self.window.addstr(0, 0, self.display_string)
30 30
 
... ...
@@ -33,6 +33,7 @@
33 33
         "<wait5><enter><enter><enter>",
34 34
         "<down><down><enter><wait>",
35 35
         "photon<enter><wait>",
36
+        "{{user `ssh_password`}}<enter><wait>",
36 37
         "{{user `ssh_password`}}<enter>",
37 38
         "<wait10><wait10><wait10><wait10><wait10><wait10><wait10>",
38 39
         "<enter>",
... ...
@@ -66,6 +67,7 @@
66 66
         "<wait5><enter><enter><enter>",
67 67
         "<down><down><enter><wait>",
68 68
         "photon<enter><wait>",
69
+        "{{user `ssh_password`}}<enter><wait>",
69 70
         "{{user `ssh_password`}}<enter>",
70 71
         "<wait10><wait10><wait10><wait10><wait10><wait10><wait10>",
71 72
         "<enter>",