cloud-mu 3.6.10 → 3.6.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Berksfile +2 -3
  3. data/Berksfile.lock +11 -14
  4. data/bin/mu-aws-setup +16 -4
  5. data/bin/mu-configure +2 -1
  6. data/cloud-mu.gemspec +2 -2
  7. data/cookbooks/mu-firewall/Berksfile +1 -1
  8. data/cookbooks/mu-firewall/attributes/default.rb +2 -2
  9. data/cookbooks/mu-firewall/metadata.rb +3 -3
  10. data/cookbooks/mu-firewall/recipes/default.rb +11 -2
  11. data/cookbooks/mu-master/Berksfile +1 -1
  12. data/cookbooks/mu-master/attributes/default.rb +14 -1
  13. data/cookbooks/mu-master/files/default/389ds-perl/ASDialogs.pm +173 -0
  14. data/cookbooks/mu-master/files/default/389ds-perl/AdminMigration.pm +569 -0
  15. data/cookbooks/mu-master/files/default/389ds-perl/AdminServer.pm +952 -0
  16. data/cookbooks/mu-master/files/default/389ds-perl/AdminUtil.pm +983 -0
  17. data/cookbooks/mu-master/files/default/389ds-perl/ConfigDSDialogs.pm +449 -0
  18. data/cookbooks/mu-master/files/default/389ds-perl/DSCreate.pm +1551 -0
  19. data/cookbooks/mu-master/files/default/389ds-perl/DSDialogs.pm +233 -0
  20. data/cookbooks/mu-master/files/default/389ds-perl/DSMigration.pm +1175 -0
  21. data/cookbooks/mu-master/files/default/389ds-perl/DSUpdate.pm +534 -0
  22. data/cookbooks/mu-master/files/default/389ds-perl/DSUpdateDialogs.pm +152 -0
  23. data/cookbooks/mu-master/files/default/389ds-perl/DSUtil.pm +1710 -0
  24. data/cookbooks/mu-master/files/default/389ds-perl/Dialog.pm +249 -0
  25. data/cookbooks/mu-master/files/default/389ds-perl/DialogManager.pm +212 -0
  26. data/cookbooks/mu-master/files/default/389ds-perl/FileConn.pm +461 -0
  27. data/cookbooks/mu-master/files/default/389ds-perl/Inf.pm +268 -0
  28. data/cookbooks/mu-master/files/default/389ds-perl/Migration.pm +327 -0
  29. data/cookbooks/mu-master/files/default/389ds-perl/RegDSDialogs.pm +94 -0
  30. data/cookbooks/mu-master/files/default/389ds-perl/Resource.pm +137 -0
  31. data/cookbooks/mu-master/files/default/389ds-perl/Setup.pm +240 -0
  32. data/cookbooks/mu-master/files/default/389ds-perl/SetupDialogs.pm +243 -0
  33. data/cookbooks/mu-master/files/default/389ds-perl/SetupLog.pm +82 -0
  34. data/cookbooks/mu-master/files/default/setCertName.ldif +4 -0
  35. data/cookbooks/mu-master/libraries/mu.rb +2 -2
  36. data/cookbooks/mu-master/metadata.rb +1 -1
  37. data/cookbooks/mu-master/recipes/389ds.rb +71 -32
  38. data/cookbooks/mu-master/recipes/basepackages.rb +5 -0
  39. data/cookbooks/mu-master/recipes/default.rb +16 -5
  40. data/cookbooks/mu-master/recipes/init.rb +36 -3
  41. data/cookbooks/mu-master/recipes/ssl-certs.rb +6 -0
  42. data/cookbooks/mu-master/recipes/sssd.rb +85 -62
  43. data/cookbooks/mu-master/recipes/update_nagios_only.rb +7 -1
  44. data/cookbooks/mu-master/templates/default/389-directory-setup.inf.erb +11 -26
  45. data/cookbooks/mu-master/templates/default/sssd.conf.erb +18 -8
  46. data/cookbooks/mu-tools/files/default/Mu_CA.pem +33 -0
  47. data/cookbooks/mu-tools/metadata.rb +0 -1
  48. data/cookbooks/mu-tools/recipes/set_local_fw.rb +7 -1
  49. data/cookbooks/mu-tools/templates/amazon/sshd_config.erb +5 -1
  50. data/cookbooks/nagios/CHANGELOG.md +679 -0
  51. data/cookbooks/nagios/LICENSE +201 -0
  52. data/cookbooks/nagios/README.md +340 -0
  53. data/cookbooks/nagios/attributes/config.rb +163 -0
  54. data/cookbooks/nagios/attributes/default.rb +204 -0
  55. data/cookbooks/nagios/libraries/base.rb +311 -0
  56. data/cookbooks/nagios/libraries/command.rb +68 -0
  57. data/cookbooks/nagios/libraries/contact.rb +229 -0
  58. data/cookbooks/nagios/libraries/contactgroup.rb +111 -0
  59. data/cookbooks/{firewall/recipes/disable_firewall.rb → nagios/libraries/custom_option.rb} +20 -7
  60. data/cookbooks/nagios/libraries/data_bag_helper.rb +23 -0
  61. data/cookbooks/nagios/libraries/default.rb +90 -0
  62. data/cookbooks/nagios/libraries/helpers.rb +229 -0
  63. data/cookbooks/nagios/libraries/host.rb +410 -0
  64. data/cookbooks/nagios/libraries/hostdependency.rb +178 -0
  65. data/cookbooks/nagios/libraries/hostescalation.rb +170 -0
  66. data/cookbooks/nagios/libraries/hostgroup.rb +117 -0
  67. data/cookbooks/nagios/libraries/nagios.rb +277 -0
  68. data/cookbooks/nagios/libraries/resource.rb +59 -0
  69. data/cookbooks/nagios/libraries/service.rb +449 -0
  70. data/cookbooks/nagios/libraries/servicedependency.rb +213 -0
  71. data/cookbooks/nagios/libraries/serviceescalation.rb +193 -0
  72. data/cookbooks/nagios/libraries/servicegroup.rb +142 -0
  73. data/cookbooks/nagios/libraries/timeperiod.rb +159 -0
  74. data/cookbooks/nagios/libraries/users_helper.rb +54 -0
  75. data/cookbooks/nagios/metadata.json +44 -0
  76. data/cookbooks/nagios/metadata.rb +22 -0
  77. data/cookbooks/nagios/recipes/_load_databag_config.rb +153 -0
  78. data/cookbooks/nagios/recipes/_load_default_config.rb +241 -0
  79. data/cookbooks/nagios/recipes/apache.rb +114 -0
  80. data/cookbooks/nagios/recipes/default.rb +41 -0
  81. data/cookbooks/nagios/recipes/nginx.rb +114 -0
  82. data/cookbooks/nagios/recipes/pagerduty.rb +95 -0
  83. data/cookbooks/nagios/recipes/server.rb +182 -0
  84. data/cookbooks/nagios/recipes/server_package.rb +85 -0
  85. data/cookbooks/nagios/recipes/server_source.rb +137 -0
  86. data/cookbooks/nagios/resources/command.rb +34 -0
  87. data/cookbooks/nagios/resources/conf.rb +52 -0
  88. data/cookbooks/nagios/resources/contact.rb +34 -0
  89. data/cookbooks/nagios/resources/contactgroup.rb +35 -0
  90. data/cookbooks/nagios/resources/host.rb +35 -0
  91. data/cookbooks/nagios/resources/hostdependency.rb +35 -0
  92. data/cookbooks/nagios/resources/hostescalation.rb +36 -0
  93. data/cookbooks/nagios/resources/hostgroup.rb +35 -0
  94. data/cookbooks/nagios/resources/resource.rb +34 -0
  95. data/cookbooks/nagios/resources/service.rb +35 -0
  96. data/cookbooks/nagios/resources/servicedependency.rb +35 -0
  97. data/cookbooks/nagios/resources/serviceescalation.rb +35 -0
  98. data/cookbooks/nagios/resources/servicegroup.rb +35 -0
  99. data/cookbooks/nagios/resources/timeperiod.rb +35 -0
  100. data/cookbooks/nagios/templates/apache2.conf.erb +102 -0
  101. data/cookbooks/nagios/templates/cgi.cfg.erb +266 -0
  102. data/cookbooks/nagios/templates/commands.cfg.erb +13 -0
  103. data/cookbooks/nagios/templates/contacts.cfg.erb +37 -0
  104. data/cookbooks/nagios/templates/hostgroups.cfg.erb +25 -0
  105. data/cookbooks/nagios/templates/hosts.cfg.erb +15 -0
  106. data/cookbooks/nagios/templates/htpasswd.users.erb +6 -0
  107. data/cookbooks/nagios/templates/nagios.cfg.erb +22 -0
  108. data/cookbooks/nagios/templates/nginx.conf.erb +80 -0
  109. data/cookbooks/nagios/templates/pagerduty.cgi.erb +185 -0
  110. data/cookbooks/nagios/templates/resource.cfg.erb +27 -0
  111. data/cookbooks/nagios/templates/servicedependencies.cfg.erb +15 -0
  112. data/cookbooks/nagios/templates/servicegroups.cfg.erb +14 -0
  113. data/cookbooks/nagios/templates/services.cfg.erb +14 -0
  114. data/cookbooks/nagios/templates/spawn-fcgi.erb +10 -0
  115. data/cookbooks/nagios/templates/templates.cfg.erb +31 -0
  116. data/cookbooks/nagios/templates/timeperiods.cfg.erb +13 -0
  117. data/extras/platform_berksfile_base +3 -3
  118. data/extras/python_rpm/build.sh +4 -4
  119. data/extras/python_rpm/muthon.spec +2 -4
  120. data/extras/vault_tools/export_vaults.sh +11 -1
  121. data/install/installer +1 -1
  122. data/modules/mu/kittens.rb +27523 -0
  123. data/modules/mu/master/ldap.rb +48 -31
  124. data/modules/mu/master.rb +69 -0
  125. data/modules/mu/mu.yaml.rb +351 -0
  126. data/modules/mu/providers/aws/firewall_rule.rb +3 -1
  127. data/modules/mu/providers/aws.rb +11 -5
  128. data/modules/mu.rb +5 -4
  129. metadata +99 -48
  130. data/cookbooks/firewall/CHANGELOG.md +0 -488
  131. data/cookbooks/firewall/LICENSE +0 -202
  132. data/cookbooks/firewall/README.md +0 -366
  133. data/cookbooks/firewall/TODO.md +0 -6
  134. data/cookbooks/firewall/attributes/default.rb +0 -5
  135. data/cookbooks/firewall/attributes/firewalld.rb +0 -8
  136. data/cookbooks/firewall/attributes/iptables.rb +0 -17
  137. data/cookbooks/firewall/attributes/ufw.rb +0 -12
  138. data/cookbooks/firewall/attributes/windows.rb +0 -8
  139. data/cookbooks/firewall/libraries/helpers.rb +0 -105
  140. data/cookbooks/firewall/libraries/helpers_firewalld.rb +0 -116
  141. data/cookbooks/firewall/libraries/helpers_firewalld_dbus.rb +0 -72
  142. data/cookbooks/firewall/libraries/helpers_iptables.rb +0 -112
  143. data/cookbooks/firewall/libraries/helpers_nftables.rb +0 -170
  144. data/cookbooks/firewall/libraries/helpers_ufw.rb +0 -142
  145. data/cookbooks/firewall/libraries/helpers_windows.rb +0 -129
  146. data/cookbooks/firewall/libraries/provider_firewall_firewalld.rb +0 -179
  147. data/cookbooks/firewall/libraries/provider_firewall_iptables.rb +0 -171
  148. data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu.rb +0 -200
  149. data/cookbooks/firewall/libraries/provider_firewall_iptables_ubuntu1404.rb +0 -200
  150. data/cookbooks/firewall/libraries/provider_firewall_rule.rb +0 -34
  151. data/cookbooks/firewall/libraries/provider_firewall_ufw.rb +0 -138
  152. data/cookbooks/firewall/libraries/provider_firewall_windows.rb +0 -126
  153. data/cookbooks/firewall/libraries/resource_firewall.rb +0 -26
  154. data/cookbooks/firewall/libraries/resource_firewall_rule.rb +0 -52
  155. data/cookbooks/firewall/metadata.json +0 -40
  156. data/cookbooks/firewall/metadata.rb +0 -15
  157. data/cookbooks/firewall/recipes/default.rb +0 -76
  158. data/cookbooks/firewall/recipes/firewalld.rb +0 -87
  159. data/cookbooks/firewall/resources/firewalld.rb +0 -28
  160. data/cookbooks/firewall/resources/firewalld_config.rb +0 -39
  161. data/cookbooks/firewall/resources/firewalld_helpers.rb +0 -106
  162. data/cookbooks/firewall/resources/firewalld_icmptype.rb +0 -88
  163. data/cookbooks/firewall/resources/firewalld_ipset.rb +0 -104
  164. data/cookbooks/firewall/resources/firewalld_policy.rb +0 -115
  165. data/cookbooks/firewall/resources/firewalld_service.rb +0 -98
  166. data/cookbooks/firewall/resources/firewalld_zone.rb +0 -118
  167. data/cookbooks/firewall/resources/nftables.rb +0 -71
  168. data/cookbooks/firewall/resources/nftables_rule.rb +0 -113
  169. data/cookbooks/firewall/templates/default/ufw/default.erb +0 -13
  170. /data/cookbooks/{firewall → nagios}/chefignore +0 -0
  171. /data/cookbooks/{firewall → nagios}/renovate.json +0 -0
@@ -0,0 +1,249 @@
1
+ # BEGIN COPYRIGHT BLOCK
2
+ # Copyright (C) 2007 Red Hat, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # License: GPL (version 3 or any later version).
6
+ # See LICENSE for details.
7
+ # END COPYRIGHT BLOCK
8
+ #
9
+
10
+ package Dialog;
11
+
12
+ use DialogManager;
13
+
14
+ #require Exporter;
15
+ #@ISA = qw(Exporter);
16
+ #@EXPORT = qw();
17
+
18
+ # NOTE: This "class" is an "abstract" class. There are two methods which
19
+ # must be provided by subclasses:
20
+ # $ans = $dialog->defaultAns($promptindex);
21
+ # where $promptindex is the index into the array of prompts given when
22
+ # constructing the Dialog object
23
+ # The dialog will typically use a default answer either hardcoded in
24
+ # or from some key in the setup cache (.inf) file
25
+ #
26
+ # $resp = $dialog->handleResponse($ans, $index);
27
+ # The dialog uses this method to perform validation of the input, set the value
28
+ # in the setup cache, display errors or warnings, and tell the dialog manager
29
+ # if the prompt needs to be redisplayed, or if there was an unrecoverable error
30
+ # $resp should be $SAME to reprompt, $ERR to abort, or $NEXT to continue
31
+ # the $ans and defaultAns should be in the native charset, so the dialog
32
+ # may have to convert to/from utf8 as needed.
33
+
34
+ # a dialog consists of a title, some explanatory text, and one or more prompts
35
+ # each prompt has a default value. An example of a dialog with more than
36
+ # one prompt would be a dialog asking the user for the new root DN and password -
37
+ # in that case, there would be 3 prompts - one for the DN, one for the password,
38
+ # and one to verify the password
39
+ # The text and prompts are given as resource keys. Usually the resource value
40
+ # will be a simple string, in which case the resource key is passed in as a simple
41
+ # string. However, if the resource string contains replaceable parameters, the
42
+ # resource key is passed as an array ref consisting of the resource key as the
43
+ # first element and the parameters to use for replacement as the subsequent
44
+ # array elements e.g.
45
+ # $foo = new Dialog(['RESOURCE_KEY_CONFIG_LDAP_URL', $secure, $host, $port, $suffix], ...);
46
+ # but usually for simple cases like this:
47
+ # $foo = new Dialog('RESOURCE_KEY_WELCOME', ...);
48
+ # The manager contains the context for all of the dialogs - the setup type, the resource
49
+ # file, setup log, other context shared among the dialogs
50
+ # the type is the setup type - 1, 2, or 3 for express, typical, or custom
51
+ # type is used to say which types use this dialog
52
+ sub new {
53
+ my $type = shift;
54
+ my $self = {};
55
+
56
+ $self->{type} = shift;
57
+ $self->{text} = shift;
58
+ $self->{defaultAns} = shift;
59
+ $self->{handleResp} = shift;
60
+ $self->{prompts} = \@_;
61
+
62
+ $self = bless $self, $type;
63
+
64
+ return $self;
65
+ }
66
+
67
+ sub setManager {
68
+ my $self = shift;
69
+ $self->{"manager"} = shift;
70
+ }
71
+
72
+ # returns true if this dialog is to be displayed for the current setup type
73
+ # false otherwise
74
+ sub isDisplayed {
75
+ my $self = shift;
76
+
77
+ return $self->{type} <= $self->{"manager"}->{type};
78
+ }
79
+
80
+ sub isEnabled {
81
+ my $self = shift;
82
+ return !defined($self->{disabled});
83
+ }
84
+
85
+ sub enable {
86
+ my $self = shift;
87
+ delete $self->{disabled};
88
+ }
89
+
90
+ sub disable {
91
+ my $self = shift;
92
+ $self->{disabled} = 1;
93
+ }
94
+
95
+ # each prompt looks like this:
96
+ # [ 'resource key', is pwd, hide ]
97
+ # The resource key is the string key of the resource
98
+ # is pwd is optional - if present, the prompt is for a password
99
+ # and should not echo the answer
100
+ # hide is optional - if present and true, the prompt will not be displayed - this
101
+ # is useful in cases where you may want to display or hide a subprompt depending
102
+ # on the response to a main prompt
103
+ # e.g.
104
+ # ['RESOURCE_USERNAME'], ['RESOURCE_PASSWORD', 1], ['RESOURCE_PASSWORD_AGAIN', 1]
105
+ # e.g.
106
+ # ['USE_SECURITY'], ['CA_CERTIFICATE', 0, 0]
107
+ # you can set the 0 to a 1 if the user has chosen to use security
108
+ sub run {
109
+ my $self = shift;
110
+ my $direction = shift;
111
+ my $resp = $DialogManager::SAME;
112
+
113
+ # display the dialog text
114
+ if ($self->isDisplayed()) {
115
+ $self->{manager}->showText($self->{text});
116
+ }
117
+
118
+ # display each prompt for this dialog
119
+ my $index = 0;
120
+ my @prompts = @{$self->{prompts}};
121
+ for (my $index = 0; $index < @prompts; ++$index) {
122
+ my $prompt = $prompts[$index];
123
+ my $defaultans = $self->{defaultAns}($self, $index);
124
+ my $ans;
125
+ if ($self->isDisplayed() && !$prompt->[2]) {
126
+ $ans = $self->{manager}->showPrompt($prompt->[0], $defaultans, $prompt->[1]);
127
+ } else {
128
+ $ans = $defaultans;
129
+ }
130
+
131
+ # see if this is the special BACK response, and finish if so
132
+ if ($self->{"manager"}->isBack($ans)) {
133
+ $resp = $DialogManager::BACK;
134
+ last;
135
+ }
136
+
137
+ # figure out what action to take based on the users response
138
+ # this will set values in the setup info file
139
+ # this will also validate input, and display errors if the
140
+ # input is not correct - in that case, the resp will be
141
+ # SAME to reprompt, or ERR if unrecoverable
142
+ # NOTE: user cannot BACK from prompt to prompt - BACK
143
+ # always means BACK to the previous dialog
144
+ $resp = $self->{handleResp}($self, $ans, $index);
145
+ if (($resp == $DialogManager::SAME) or ($resp == $DialogManager::FIRST)) {
146
+ if (!$self->isDisplayed()) {
147
+ $self->{manager}->alert('dialog_use_different_type');
148
+ $resp = $DialogManager::ERR;
149
+ } elsif ($resp == $DialogManager::SAME) {
150
+ $index--; # reprompt
151
+ } else {
152
+ $index = -1; # reshow first prompt on dialog
153
+ }
154
+ } elsif ($resp == $DialogManager::ERR) {
155
+ last;
156
+ } elsif (!$self->isDisplayed() && ($direction < 0) &&
157
+ ($resp == $DialogManager::NEXT)) {
158
+ # we did not display this dialog, and the current navigation
159
+ # direction is BACK, so we should return BACK, to allow
160
+ # the user to go back through several dialogs
161
+ $resp = $DialogManager::BACK;
162
+ }
163
+ }
164
+
165
+ return $resp;
166
+ }
167
+
168
+ package DialogYesNo;
169
+
170
+ @ISA = qw(Dialog);
171
+
172
+ sub new {
173
+ my $type = shift;
174
+ my $setuptype = shift;
175
+ my $text = shift;
176
+ my $defaultIsYes = shift;
177
+ my $handler = shift || \&handleResponse;
178
+ my $prompt = shift || ['prompt_yes_no'];
179
+ my $self = Dialog->new($setuptype, $text,
180
+ \&defaultAns, $handler, $prompt);
181
+
182
+ $self->{defaultIsYes} = $defaultIsYes;
183
+
184
+ $self = bless $self, $type;
185
+
186
+ return $self;
187
+ }
188
+
189
+ sub setDefaultYes {
190
+ my $self = shift;
191
+ $self->{default} = $self->{"manager"}->getText("yes");
192
+ }
193
+
194
+ sub setDefaultNo {
195
+ my $self = shift;
196
+ $self->{default} = $self->{"manager"}->getText("no");
197
+ }
198
+
199
+ sub defaultAns {
200
+ my $self = shift;
201
+ if (exists($self->{ans})) {
202
+ return $self->{ans};
203
+ }
204
+ if (!exists($self->{default})) {
205
+ my $isyes;
206
+ if (ref($self->{defaultIsYes}) eq 'CODE') {
207
+ $isyes = &{$self->{defaultIsYes}}($self);
208
+ } else {
209
+ $isyes = $self->{defaultIsYes};
210
+ }
211
+ if ($isyes) {
212
+ $self->{default} = $self->{"manager"}->getText("yes");
213
+ } else {
214
+ $self->{default} = $self->{"manager"}->getText("no");
215
+ }
216
+ }
217
+ return $self->{default};
218
+ }
219
+
220
+ sub isYes {
221
+ my $self = shift;
222
+ return $self->{ans} eq $self->{"manager"}->getText("yes");
223
+ }
224
+
225
+ sub handleResponse {
226
+ my $self = shift;
227
+ my $ans = shift;
228
+ my $resp = $DialogManager::SAME;
229
+ my $yes = $self->{"manager"}->getText("yes");
230
+ my $nno = $self->{"manager"}->getText("no");
231
+
232
+ # the regexp allows us to use y or ye or yes for "yes"
233
+ if ($nno =~ /^$ans/i) {
234
+ $resp = $DialogManager::NEXT;
235
+ $self->{ans} = $nno;
236
+ } elsif ($yes =~ /^$ans/i) {
237
+ $resp = $DialogManager::NEXT;
238
+ $self->{ans} = $yes;
239
+ } else {
240
+ $self->{"manager"}->alert("yes_no_error");
241
+ }
242
+
243
+ return $resp;
244
+ }
245
+
246
+ #############################################################################
247
+ # Mandatory TRUE return value.
248
+ #
249
+ 1;
@@ -0,0 +1,212 @@
1
+ # BEGIN COPYRIGHT BLOCK
2
+ # Copyright (C) 2007 Red Hat, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # License: GPL (version 3 or any later version).
6
+ # See LICENSE for details.
7
+ # END COPYRIGHT BLOCK
8
+ #
9
+
10
+ package DialogManager;
11
+ use Exporter ();
12
+ @ISA = qw(Exporter);
13
+ @EXPORT = qw($BACK $SAME $NEXT $ERR);
14
+ @EXPORT_OK = qw($BACK $SAME $NEXT $ERR);
15
+
16
+ use Dialog;
17
+ use SetupLog;
18
+
19
+ # Dialog responses
20
+ $FIRST = -2; # go back to first prompt on a dialog
21
+ $BACK = -1; # go back to previous dialog
22
+ $SAME = 0; # reshow the same prompt or dialog
23
+ $NEXT = 1; # go to the next dialog
24
+ $ERR = 2; # fatal error
25
+
26
+ # The DialogManager controls the flow of the dialogs and contains context shared
27
+ # among all of the dialogs (resources, logs, current setup type, etc.)
28
+ # all of these are optional
29
+ sub new {
30
+ my $type = shift;
31
+ my $self = {};
32
+
33
+ $self->{setup} = shift;
34
+ $self->{res} = shift;
35
+ $self->{type} = shift;
36
+
37
+ $self->{log} = $self->{setup}->{log};
38
+ $self->{inf} = $self->{setup}->{inf};
39
+
40
+ $self = bless $self, $type;
41
+
42
+ return $self;
43
+ }
44
+
45
+ sub getType {
46
+ my $self = shift;
47
+ return $self->{type};
48
+ }
49
+
50
+ sub setType {
51
+ my $self = shift;
52
+ $self->{type} = shift;
53
+ }
54
+
55
+ sub addDialog {
56
+ my $self = shift;
57
+ for my $dialog (@_) {
58
+ $dialog->setManager($self);
59
+ push @{$self->{dialogs}}, $dialog;
60
+ }
61
+ }
62
+
63
+ sub resetDialog {
64
+ my $self = shift;
65
+ @{$self->{dialogs}} = ();
66
+ }
67
+
68
+ # see if the user answered with the special BACK answer
69
+ sub isBack {
70
+ my $self = shift;
71
+ my $ans = shift;
72
+
73
+ if (!$ans) {
74
+ return 0;
75
+ }
76
+
77
+ # the word "back"
78
+ if ($ans =~ /^\s*back\s*$/i) {
79
+ return 1;
80
+ }
81
+ # a Ctrl-B sequence
82
+ if ($ans eq '') {
83
+ return 1;
84
+ }
85
+
86
+ return 0;
87
+ }
88
+
89
+ sub log {
90
+ my $self = shift;
91
+ if (!$self->{log}) {
92
+ print @_;
93
+ } else {
94
+ $self->{log}->logMessage($INFO, "Setup", @_);
95
+ }
96
+ }
97
+
98
+ sub getText {
99
+ my $self = shift;
100
+ return $self->{res}->getText(@_);
101
+ }
102
+
103
+ sub handleError {
104
+ my $self = shift;
105
+ my $msg = $self->{res}->getText('setup_err_exit');
106
+ $self->{log}->logMessage($FATAL, "Setup", $msg);
107
+ }
108
+
109
+ sub showText {
110
+ my $self = shift;
111
+ my $msg = shift;
112
+ my $text = $self->getText($msg);
113
+ print "\n", ("=" x 78), "\n";
114
+ # display it,
115
+ print $text;
116
+ # log it
117
+ $self->log($text);
118
+ }
119
+
120
+ sub showPrompt {
121
+ my $self = shift;
122
+ my $msg = shift;
123
+ my $defaultans = shift;
124
+ my $ispwd = shift;
125
+
126
+ my $text = $self->getText($msg);
127
+ # display it,
128
+ print $text;
129
+ # log it
130
+ $self->log($text . "\n");
131
+ # display the default answer
132
+ if ($defaultans) {
133
+ print " [$defaultans]";
134
+ }
135
+ print ": ";
136
+ # if we are prompting for a password, disable console echo
137
+ if ($ispwd) {
138
+ system("/bin/stty -echo");
139
+ }
140
+ # read the answer
141
+ my $ans = <STDIN>;
142
+ # if we are prompting for a password, enable console echo
143
+ if ($ispwd) {
144
+ system("/bin/stty echo");
145
+ print "\n";
146
+ }
147
+ chop($ans); # trim trailing newline
148
+
149
+ # see if this is the special BACK response, and finish if so
150
+ if ($self->isBack($ans)) {
151
+ $self->log("BACK\n");
152
+ return $ans;
153
+ }
154
+
155
+ if (!length($ans)) {
156
+ $ans = $defaultans;
157
+ }
158
+
159
+ # log the response, if not a password
160
+ if (!$ispwd) {
161
+ $self->log($ans . "\n");
162
+ }
163
+
164
+ return $ans;
165
+ }
166
+
167
+ sub alert {
168
+ my $self = shift;
169
+ my $msg = $self->{res}->getText(@_);
170
+ print $msg;
171
+ $self->{log}->logMessage($WARN, "Setup", $msg);
172
+ }
173
+
174
+ sub run {
175
+ my $self = shift;
176
+ my $done;
177
+ my $index = 0;
178
+ my $incr = 1;
179
+ my $rc = 0;
180
+
181
+ while (!$done) {
182
+ my $dialog = $self->{dialogs}->[$index];
183
+ if ($dialog->isEnabled()) {
184
+ my $resp = $NEXT;
185
+ $resp = $dialog->run($incr);
186
+ if ($resp == $BACK) {
187
+ $incr = -1;
188
+ } elsif ($resp == $NEXT) {
189
+ $incr = 1;
190
+ } elsif (($resp == $SAME) or ($resp == $FIRST)) {
191
+ $incr = 0;
192
+ } else {
193
+ $self->handleError($resp);
194
+ $done = 1;
195
+ $rc = 1;
196
+ }
197
+ }
198
+ $index += $incr;
199
+ if ($index < 0) {
200
+ $index = 0;
201
+ } elsif ($index >= @{$self->{dialogs}}) {
202
+ $done = 1;
203
+ }
204
+ }
205
+
206
+ return $rc;
207
+ }
208
+
209
+ #############################################################################
210
+ # Mandatory TRUE return value.
211
+ #
212
+ 1;