/
firewall_stage1_proposal.rb
370 lines (326 loc) · 12.3 KB
/
firewall_stage1_proposal.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# encoding: utf-8
#***************************************************************************
#
# Copyright (c) 2008 - 2012 Novell, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#
#**************************************************************************
# File: firewall_stage1_proposal.ycp
# Summary: Configuration of fw in 1st stage
# Author: Bubli <kmachalkova@suse.cz>
#
module Yast
class FirewallStage1ProposalClient < Client
def main
Yast.import "UI"
textdomain "network"
Yast.import "Label"
Yast.import "Linuxrc"
Yast.import "PackagesProposal"
Yast.import "ProductControl"
Yast.import "ProductFeatures"
Yast.import "SuSEFirewall4Network"
Yast.import "SuSEFirewallProposal"
Yast.import "Wizard"
@PROPOSAL_ID = "fw_1ststage"
@LINK_ENABLE_FIREWALL = "firewall--enable_firewall_in_proposal"
@LINK_DISABLE_FIREWALL = "firewall--disable_firewall_in_proposal"
@LINK_ENABLE_SSH = "firewall--enable_ssh_port_in_proposal"
@LINK_DISABLE_SSH = "firewall--disable_ssh_port_in_proposal"
@LINK_ENABLE_SSHD = "firewall--enable_sshd_in_proposal"
@LINK_DISABLE_SSHD = "firewall--disable_sshd_in_proposal"
@LINK_ENABLE_VNC = "firewall--enable_vnc_in_proposal"
@LINK_DISABLE_VNC = "firewall--disable_vnc_in_proposal"
@LINK_FIREWALL_DIALOG = "firewall_stage1"
# run this only once
if !SuSEFirewallProposal.GetProposalInitialized
# variables from control file
Builtins.y2milestone(
"Default firewall values: enable_firewall=%1, enable_ssh=%2 enable_sshd=%3",
ProductFeatures.GetBooleanFeature("globals", "enable_firewall"),
ProductFeatures.GetBooleanFeature("globals", "firewall_enable_ssh"),
ProductFeatures.GetBooleanFeature("globals", "enable_sshd")
)
SuSEFirewall4Network.SetEnabled1stStage(
ProductFeatures.GetBooleanFeature("globals", "enable_firewall")
)
#we're installing over SSH, propose opening SSH port (bnc#535206)
if Linuxrc.usessh
SuSEFirewall4Network.SetSshEnabled1stStage(true)
SuSEFirewall4Network.SetSshdEnabled(true)
else
SuSEFirewall4Network.SetSshEnabled1stStage(
ProductFeatures.GetBooleanFeature("globals", "firewall_enable_ssh")
)
SuSEFirewall4Network.SetSshdEnabled1stStage(
ProductFeatures.GetBooleanFeature("globals", "enable_sshd")
)
end
#we're installing over VNC, propose opening VNC port (bnc#734264)
SuSEFirewall4Network.SetVncEnabled1stStage(true) if Linuxrc.vnc
SuSEFirewallProposal.SetProposalInitialized(true)
end
@func = Convert.to_string(WFM.Args(0))
@param = Convert.to_map(WFM.Args(1))
@ret = {}
if @func == "MakeProposal"
# Summary is visible only if installing over VNC
# and if firewall is enabled - otherwise port could not be blocked
vnc_proposal_element = ""
if Linuxrc.vnc && SuSEFirewall4Network.Enabled1stStage
vnc_proposal = SuSEFirewall4Network.EnabledVnc1stStage ?
_("VNC ports will be open (<a href=\"%s\">close</a>)") %
@LINK_DISABLE_VNC
: _("VNC ports will be blocked (<a href=\"%s\">open</a>)") %
@LINK_ENABLE_VNC
vnc_proposal_element = "<li>#{vnc_proposal}</li>"
end
firewall_proposal = SuSEFirewall4Network.Enabled1stStage ?
_(
"Firewall will be enabled (<a href=\"%s\">disable</a>)"
) % @LINK_DISABLE_FIREWALL
:
_(
"Firewall will be disabled (<a href=\"%s\">enable</a>)"
) % @LINK_ENABLE_FIREWALL
ssh_proposal = SuSEFirewall4Network.EnabledSsh1stStage ?
_(
"SSH port will be open (<a href=\"%s\">close</a>)"
) % @LINK_DISABLE_SSH
:
_(
"SSH port will be blocked (<a href=\"%s\">open</a>)"
) % @LINK_ENABLE_SSH
sshd_proposal = SuSEFirewall4Network.EnabledSsh ?
_(
"SSH service will be enabled (<a href=\"%s\">disable</a>)"
) % @LINK_DISABLE_SSHD
:
_(
"SSH service will be disabled (<a href=\"%s\">enable</a>)"
) % @LINK_ENABLE_SSHD
@output = "<ul>\n<li>#{firewall_proposal}</li>\n" +
"<li>#{ssh_proposal}</li>\n" +
"<li>#{sshd_proposal}</li>\n" +
vnc_proposal_element +
"</ul>\n"
@ret = {
"preformatted_proposal" => @output,
"warning_level" => :warning,
"links" => [
@LINK_ENABLE_FIREWALL,
@LINK_DISABLE_FIREWALL,
@LINK_ENABLE_SSH,
@LINK_DISABLE_SSH,
@LINK_ENABLE_SSHD,
@LINK_DISABLE_SSHD,
@LINK_ENABLE_VNC,
@LINK_DISABLE_VNC
]
}
elsif @func == "AskUser"
@chosen_link = Ops.get(@param, "chosen_id")
@result = :next
Builtins.y2milestone("User clicked %1", @chosen_link)
if @chosen_link == @LINK_ENABLE_FIREWALL
Builtins.y2milestone("Enabling FW")
SuSEFirewall4Network.SetEnabled1stStage(true)
PackagesProposal.AddResolvables(
@PROPOSAL_ID,
:package,
["SuSEfirewall2"]
)
elsif @chosen_link == @LINK_DISABLE_FIREWALL
Builtins.y2milestone("Disabling FW")
SuSEFirewall4Network.SetEnabled1stStage(false)
PackagesProposal.RemoveResolvables(
@PROPOSAL_ID,
:package,
["SuSEfirewall2"]
)
elsif @chosen_link == @LINK_ENABLE_SSH
Builtins.y2milestone("Enabling SSH")
SuSEFirewall4Network.SetSshEnabled1stStage(true)
elsif @chosen_link == @LINK_DISABLE_SSH
Builtins.y2milestone("Disabling SSH")
SuSEFirewall4Network.SetSshEnabled1stStage(false)
elsif @chosen_link == @LINK_ENABLE_SSHD
Builtins.y2milestone("Enabling SSHD")
PackagesProposal.AddResolvables(@PROPOSAL_ID, :package, ["openssh"])
SuSEFirewall4Network.SetSshdEnabled(true)
elsif @chosen_link == @LINK_DISABLE_SSHD
Builtins.y2milestone("Disabling SSHD")
SuSEFirewall4Network.SetSshdEnabled(false)
PackagesProposal.RemoveResolvables(
@PROPOSAL_ID,
:package,
["openssh"]
)
elsif @chosen_link == @LINK_ENABLE_VNC
Builtins.y2milestone("Enabling VNC")
SuSEFirewall4Network.SetVncEnabled1stStage(true)
elsif @chosen_link == @LINK_DISABLE_VNC
Builtins.y2milestone("Disabling VNC")
SuSEFirewall4Network.SetVncEnabled1stStage(false)
elsif @chosen_link == @LINK_FIREWALL_DIALOG
@result = FirewallDialogSimple()
end
SuSEFirewallProposal.SetChangedByUser(true)
@ret = { "workflow_sequence" => @result }
elsif @func == "Description"
@ret = {
# Proposal title
"rich_text_title" => _("Firewall and SSH"),
# Menu entry label
"menu_title" => _("&Firewall and SSH"),
"id" => @LINK_FIREWALL_DIALOG
}
elsif @func == "Write"
@ret = { "success" => true }
end
deep_copy(@ret)
end
def FirewallDialogSimple
title = _("Basic Firewall and SSH Configuration")
vnc_support = Left(
CheckBox(
Id("open_vnc_port"),
# TRANSLATORS: check-box label
_("Open &VNC Ports"),
SuSEFirewall4Network.EnabledVnc1stStage
)
)
contents = VBox(
Frame(
# frame label
_("Firewall and SSH service"),
HSquash(
MarginBox(
0.5,
0.5,
VBox(
Left(
CheckBox(
Id("enable_fw"),
Opt(:notify),
# TRANSLATORS: check-box label
_("Enable Firewall"),
SuSEFirewall4Network.Enabled1stStage
)
),
Left(
CheckBox(
Id("open_ssh_port"),
# TRANSLATORS: check-box label
_("Open SSH Port"),
SuSEFirewall4Network.EnabledSsh1stStage
)
),
Left(
CheckBox(
Id("enable_sshd"),
# TRANSLATORS: check-box label
_("Enable SSH Service"),
SuSEFirewall4Network.EnabledSshd
)
),
Linuxrc.vnc ? vnc_support : Empty()
)
)
)
)
)
help = _(
"<p><b><big>Firewall and SSH</big></b><br>\n" +
"Firewall is a defensive mechanism that protects your computer from network attacks.\n" +
"SSH is a service that allows logging into this computer remotely via dedicated\n" +
"SSH client</p>"
) +
_(
"<p>Here you can choose whether the firewall will be enabled or disabled after\nthe installation. It is recommended to keep it enabled.</p>"
) +
_(
"<p>With enabled firewall, you can decide whether to open firewall port for SSH\n" +
"service and allow remote SSH logins. Independentlu you can also enable SSH service (i.e. it\n" +
"will be started on computer boot).</p>"
) +
(Linuxrc.vnc ?
# TRANSLATORS: help text
_(
"<p>You can also open VNC ports in firewall. It will not enable\n" +
"the remote administration service on a running system but it is\n" +
"started by the installer automatically if needed.</p>"
) :
"")
Wizard.CreateDialog
Wizard.SetTitleIcon("yast-firewall")
Wizard.SetContentsButtons(
title,
contents,
help,
Label.BackButton,
Label.OKButton
)
Wizard.SetAbortButton(:cancel, Label.CancelButton)
Wizard.HideBackButton
UI.ChangeWidget(
Id("open_ssh_port"),
:Enabled,
SuSEFirewall4Network.Enabled1stStage
)
UI.ChangeWidget(
Id("open_vnc_port"),
:Enabled,
SuSEFirewall4Network.Enabled1stStage
)
dialog_ret = nil
while true
dialog_ret = UI.UserInput
enable_firewall = Convert.to_boolean(
UI.QueryWidget(Id("enable_fw"), :Value)
)
if dialog_ret == "enable_fw"
UI.ChangeWidget(Id("open_ssh_port"), :Enabled, enable_firewall)
UI.ChangeWidget(Id("open_vnc_port"), :Enabled, enable_firewall)
next
elsif dialog_ret == :next || dialog_ret == :ok
open_ssh_port = Convert.to_boolean(
UI.QueryWidget(Id("open_ssh_port"), :Value)
)
open_vnc_port = Convert.to_boolean(
UI.QueryWidget(Id("open_vnc_port"), :Value)
)
SuSEFirewall4Network.SetEnabled1stStage(enable_firewall)
if enable_firewall
SuSEFirewall4Network.SetSshEnabled1stStage(open_ssh_port)
SuSEFirewall4Network.SetVncEnabled1stStage(open_vnc_port)
end
SuSEFirewall4Network.SetSshdEnabled(
UI::QueryWidget(Id("enable_sshd"), :Value)
)
end
# anything but enabling the firewall closes this dialog
# (VNC and SSH checkboxes do nothing)
break
end
Wizard.CloseDialog
Convert.to_symbol(dialog_ret)
end
end
end
Yast::FirewallStage1ProposalClient.new.main