Class: Yast::SuSEFirewall4NetworkClass
- Inherits:
-
Module
- Object
- Module
- Yast::SuSEFirewall4NetworkClass
- Includes:
- Logger
- Defined in:
- ../../src/modules/SuSEFirewall4Network.rb
Constant Summary
- SSH_PACKAGE =
"openssh"
- SSH_SERVICES =
["service:sshd"]
- VNC_SERVICES =
["service:vnc-httpd", "service:vnc-server"]
Instance Method Summary (collapse)
-
- (Boolean) AnyInterfacesHandledByFirewall
Returns whether any network interfaces are handled firewall either explicitly mentioning them in any firewall zone or implicitly by using string 'any' in firewall zones that would assign any interface unassigned to any zone to that zone as a fallback.
-
- (Object) ChangedByUser(changed)
Function sets that a firewall proposal was changed by user by editing firewall zone of network interface (applicable during 2nd stage of installation only).
-
- (Boolean) Enabled1stStage
Returns whether firewall is supposed to be enabled.
-
- (Object) EnabledSsh1stStage
Returns whether SSH port is supposed to be open in firewall.
-
- (Object) EnabledSshd
Returns whether sshd will be enabled.
-
- (Object) EnabledVnc1stStage
Returns whether VNC ports are supposed to be open in firewall.
-
- (Object) FirewallZonesComboBoxItems
Function returns list of items for combo box with all known firewall zones.
-
- (String) GetZoneOfInterface(interface)
Function returns the firewall zone of interface, “” if no zone includes the interface.
-
- (Boolean) IsInstalled
Returns whether the firewall package is installed.
-
- (Boolean) IsOn
Whether enabled and started.
-
- (Boolean) IsProtectedByFirewall(interface)
Function returns if interface is protected by firewall.
- - (Object) main
-
- (Object) prepare_proposal
Sets the values of the initial proposal based on the product features, the packages selected for installation and the installation method.
-
- (Boolean) ProtectByFirewall(interface, zone, protect_status)
Functions sets protection of interface by the protect-status.
-
- (Boolean) Read
Function reads configuration of SuSEFirewall.
-
- (Object) SetEnabled1stStage(enabled)
Sets whether firewall should be enabled.
-
- (Object) SetSshdEnabled(enabled)
Sets whether start sshd.
-
- (Object) SetSshEnabled1stStage(enabled)
Sets whether SSH port should be opened in firewall.
-
- (Object) SetVncEnabled1stStage(enabled)
Sets whether VNC ports should be opened in firewall.
-
- (Object) UnconfiguredIsBlocked
that are not in any zone.
-
- (Boolean) Write
Function writes configuration of SuSEFirewall.
Instance Method Details
- (Boolean) AnyInterfacesHandledByFirewall
Returns whether any network interfaces are handled firewall either explicitly mentioning them in any firewall zone or implicitly by using string 'any' in firewall zones that would assign any interface unassigned to any zone to that zone as a fallback.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 191 def AnyInterfacesHandledByFirewall interfaces = [] Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone| interfaces = Convert.convert( Builtins.union( interfaces, SuSEFirewall.GetInterfacesInZoneSupportingAnyFeature(zone) ), from: "list", to: "list <string>" ) end Ops.greater_than(Builtins.size(interfaces), 0) end |
- (Object) ChangedByUser(changed)
Function sets that a firewall proposal was changed by user by editing firewall zone of network interface (applicable during 2nd stage of installation only)
259 260 261 262 263 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 259 def ChangedByUser(changed) SuSEFirewallProposal.SetChangedByUser(changed) if Stage.cont nil end |
- (Boolean) Enabled1stStage
Returns whether firewall is supposed to be enabled
281 282 283 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 281 def Enabled1stStage @firewall_enabled_1st_stage end |
- (Object) EnabledSsh1stStage
Returns whether SSH port is supposed to be open in firewall
294 295 296 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 294 def EnabledSsh1stStage @ssh_enabled_1st_stage end |
- (Object) EnabledSshd
Returns whether sshd will be enabled
315 316 317 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 315 def EnabledSshd @sshd_enabled end |
- (Object) EnabledVnc1stStage
Returns whether VNC ports are supposed to be open in firewall
328 329 330 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 328 def EnabledVnc1stStage @vnc_enabled_1st_stage end |
- (Object) FirewallZonesComboBoxItems
Function returns list of items for combo box with all known firewall zones. There's also an item for “” (no zone or fw off).
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 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 119 def FirewallZonesComboBoxItems list_items = [] protected_from_internal = SuSEFirewall.GetProtectFromInternalZone nozone = if IsOn() # item in combo box Firewall Zone _("Automatically Assigned Zone") else # item in combo box Firewall Zone _("Firewall Disabled") end list_items = Builtins.add(list_items, ["", nozone]) # Listing all known zones Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone_shortname| # Getting zone name for zone # Informing user about Unprotected inetrnal zone zone_name = Ops.add( SuSEFirewall.GetZoneFullName(zone_shortname), if zone_shortname == "INT" && !protected_from_internal # TRANSLATORS: Part of combo box item -> "Internal Zone (Unprotected)" " " + _("(Unprotected)") else "" end ) list_items = Builtins.add(list_items, [zone_shortname, zone_name]) end deep_copy(list_items) end |
- (String) GetZoneOfInterface(interface)
Function returns the firewall zone of interface, “” if no zone includes the interface. Error is reported when interface is found in multiple firewall zones, then the first appearance is returned. If firewall is off, “” is returned.
179 180 181 182 183 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 179 def GetZoneOfInterface(interface) return "" if !IsOn() zoi = SuSEFirewall.GetZoneOfInterface(interface) zoi.nil? ? "" : zoi end |
- (Boolean) IsInstalled
Returns whether the firewall package is installed
267 268 269 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 267 def IsInstalled SuSEFirewall.SuSEFirewallIsInstalled end |
- (Boolean) IsOn
Returns whether enabled and started
78 79 80 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 78 def IsOn SuSEFirewall.GetEnableService && SuSEFirewall.GetStartService end |
- (Boolean) IsProtectedByFirewall(interface)
Function returns if interface is protected by firewall. It means: Firewall is Running and Enabled. Interface is included in any protected firewall zone (means EXT, DMZ or INT).
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 156 def IsProtectedByFirewall(interface) interface_zone = SuSEFirewall.GetZoneOfInterface(interface) # interface is mentioned in uprotected zone if interface_zone == "INT" && !SuSEFirewall.GetProtectFromInternalZone Builtins.y2warning( "Interface '%1' is mentioned in uprotected zone '%2'", interface, "INT" ) end # firewall must be running and enabled, interface must be in any zone IsOn() && !interface_zone.nil? end |
- (Object) main
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 44 def main textdomain "network" Yast.import "SuSEFirewall" Yast.import "SuSEFirewallProposal" Yast.import "Stage" Yast.import "ServicesProposal" Yast.import "Linuxrc" Yast.import "ProductFeatures" Yast.import "Pkg" @firewall_enabled_1st_stage = false @ssh_enabled_1st_stage = false @sshd_enabled = false @vnc_enabled_1st_stage = false end |
- (Object) prepare_proposal
Sets the values of the initial proposal based on the product features, the packages selected for installation and the installation method
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 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 84 def prepare_proposal # variables from control file default_firewall = ProductFeatures.GetBooleanFeature("globals", "enable_firewall") default_fw_ssh = ProductFeatures.GetBooleanFeature("globals", "firewall_enable_ssh") default_sshd = ProductFeatures.GetBooleanFeature("globals", "enable_sshd") log.info "Default firewall values: enable_firewall=#{default_firewall}, "\ "enable_ssh=#{default_fw_ssh}, enable_sshd=#{default_sshd}" # Enabling SuSEFirewall only makes sense if it's going to be # installed (bnc#881250) if Pkg.IsSelected(SuSEFirewall.FIREWALL_PACKAGE) SuSEFirewall4Network.SetEnabled1stStage(default_firewall) else SuSEFirewall4Network.SetEnabled1stStage(false) end # we're installing over SSH, propose opening SSH port (bnc#535206) if Linuxrc.usessh SuSEFirewall4Network.SetSshEnabled1stStage(true) SuSEFirewall4Network.SetSshdEnabled(true) else SuSEFirewall4Network.SetSshEnabled1stStage(default_fw_ssh) SuSEFirewall4Network.SetSshdEnabled(default_sshd) end # we're installing over VNC, propose opening VNC port (bnc#734264) SuSEFirewall4Network.SetVncEnabled1stStage(true) if Linuxrc.vnc end |
- (Boolean) ProtectByFirewall(interface, zone, protect_status)
Functions sets protection of interface by the protect-status.
protect==true -> add interface into selected firewall zone, sets
firewall to be started and enabled when booting.
protect==false ->
removes interface from all firewall zones, if there are no other
interfaces protected by firewall, stops it and removes it from boot
process.
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 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 219 def ProtectByFirewall(interface, zone, protect_status) # Adding protection if protect_status == true Builtins.y2milestone( "Enabling firewall because of '%1' interface", interface ) SuSEFirewall.AddInterfaceIntoZone(interface, zone) SuSEFirewall.SetEnableService(true) SuSEFirewall.SetStartService(true) # Removing protection else # removing from all known zones Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |remove_from_zone| SuSEFirewall.RemoveInterfaceFromZone(interface, remove_from_zone) end # if there are no other interfaces in configuration, stop firewall # and remove it from boot process if !AnyInterfacesHandledByFirewall() Builtins.y2milestone( "Disabling firewall, no interfaces are protected." ) SuSEFirewall.SetEnableService(false) SuSEFirewall.SetStartService(false) end end true end |
- (Boolean) Read
Function reads configuration of SuSEFirewall.
64 65 66 67 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 64 def Read Builtins.y2milestone("Reading the firewall configuration") SuSEFirewall.Read end |
- (Object) SetEnabled1stStage(enabled)
Sets whether firewall should be enabled
273 274 275 276 277 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 273 def SetEnabled1stStage(enabled) @firewall_enabled_1st_stage = enabled nil end |
- (Object) SetSshdEnabled(enabled)
Sets whether start sshd
300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 300 def SetSshdEnabled(enabled) @sshd_enabled = enabled # bnc#887688 Needed for AutoYast export functionality at the end # of installation (clone_finish) if enabled ServicesProposal.enable_service("sshd") else ServicesProposal.disable_service("sshd") end nil end |
- (Object) SetSshEnabled1stStage(enabled)
Sets whether SSH port should be opened in firewall
287 288 289 290 291 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 287 def SetSshEnabled1stStage(enabled) @ssh_enabled_1st_stage = enabled nil end |
- (Object) SetVncEnabled1stStage(enabled)
Sets whether VNC ports should be opened in firewall
321 322 323 324 325 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 321 def SetVncEnabled1stStage(enabled) @vnc_enabled_1st_stage = enabled nil end |
- (Object) UnconfiguredIsBlocked
that are not in any zone
251 252 253 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 251 def UnconfiguredIsBlocked !SuSEFirewall.IsAnyNetworkInterfaceSupported end |
- (Boolean) Write
Function writes configuration of SuSEFirewall.
72 73 74 75 |
# File '../../src/modules/SuSEFirewall4Network.rb', line 72 def Write Builtins.y2milestone("Writing the firewall configuration") SuSEFirewall.Write end |