Class: Yast::SuSEFirewall4NetworkClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/SuSEFirewall4Network.rb

Instance Method Summary (collapse)

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.

Returns:

  • (Boolean)

    if any interface is handled by firewall



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File '../../src/modules/SuSEFirewall4Network.rb', line 145

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)

Parameters:

  • boolean

    whether proposal was changed by user



213
214
215
216
217
# File '../../src/modules/SuSEFirewall4Network.rb', line 213

def ChangedByUser(changed)
  SuSEFirewallProposal.SetChangedByUser(changed) if Stage.cont

  nil
end

- (Boolean) Enabled1stStage

Returns whether firewall is supposed to be enabled

Returns:

  • (Boolean)

    whether enabled



235
236
237
# File '../../src/modules/SuSEFirewall4Network.rb', line 235

def Enabled1stStage
  @firewall_enabled_1st_stage
end

- (Object) EnabledSsh1stStage

Returns whether SSH port is supposed to be open in firewall



248
249
250
# File '../../src/modules/SuSEFirewall4Network.rb', line 248

def EnabledSsh1stStage
  @ssh_enabled_1st_stage
end

- (Object) EnabledVnc1stStage

Returns whether VNC ports are supposed to be open in firewall



261
262
263
# File '../../src/modules/SuSEFirewall4Network.rb', line 261

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).

Returns:

  • item list for CWM



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
# File '../../src/modules/SuSEFirewall4Network.rb', line 76

def FirewallZonesComboBoxItems
  list_items = []
  protected_from_internal = SuSEFirewall.GetProtectFromInternalZone
  nozone = IsOn() ?
    # item in combo box Firewall Zone
    _("Automatically Assigned Zone") :
    # item in combo box Firewall Zone
    _("Firewall Disabled")
  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),
      zone_shortname == "INT" && !protected_from_internal ?
        # TRANSLATORS: Part of combo box item -> "Internal Zone (Unprotected)"
        " " +
          _("(Unprotected)") :
        ""
    )
    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.

Parameters:

  • interface (String)

Returns:

  • (String)

    zone



133
134
135
136
137
# File '../../src/modules/SuSEFirewall4Network.rb', line 133

def GetZoneOfInterface(interface)
  return "" if !IsOn()
  zoi = SuSEFirewall.GetZoneOfInterface(interface)
  zoi == nil ? "" : zoi
end

- (Boolean) IsInstalled

Returns whether the firewall package is installed

Returns:

  • (Boolean)

    if installed



221
222
223
# File '../../src/modules/SuSEFirewall4Network.rb', line 221

def IsInstalled
  SuSEFirewall.SuSEFirewallIsInstalled
end

- (Boolean) IsOn

Returns whether enabled and started

Returns:

  • (Boolean)

    whether enabled and started



67
68
69
# File '../../src/modules/SuSEFirewall4Network.rb', line 67

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).

Parameters:

  • interface (String)

Returns:

  • (Boolean)

    if it is protected



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File '../../src/modules/SuSEFirewall4Network.rb', line 110

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



38
39
40
41
42
43
44
45
46
47
48
# File '../../src/modules/SuSEFirewall4Network.rb', line 38

def main
  textdomain "network"

  Yast.import "SuSEFirewall"
  Yast.import "SuSEFirewallProposal"
  Yast.import "Stage"

  @firewall_enabled_1st_stage = false
  @ssh_enabled_1st_stage = false
  @vnc_enabled_1st_stage = false
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.

Parameters:

  • interface (String)
  • zone (String)

    (makes sense for protect_status==true)

  • protect_status (Boolean)

Returns:

  • (Boolean)

    if successful



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
# File '../../src/modules/SuSEFirewall4Network.rb', line 173

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.

Returns:

  • (Boolean)

    if successful



53
54
55
56
# File '../../src/modules/SuSEFirewall4Network.rb', line 53

def Read
  Builtins.y2milestone("Reading the firewall configuration")
  SuSEFirewall.Read
end

- (Object) SetEnabled1stStage(enabled)

Sets whether firewall should be enabled

Parameters:

  • boolean

    new state



227
228
229
230
231
# File '../../src/modules/SuSEFirewall4Network.rb', line 227

def SetEnabled1stStage(enabled)
  @firewall_enabled_1st_stage = enabled

  nil
end

- (Object) SetSshEnabled1stStage(enabled)

Sets whether SSH port should be opened in firewall

Parameters:

  • boolean

    new state



241
242
243
244
245
# File '../../src/modules/SuSEFirewall4Network.rb', line 241

def SetSshEnabled1stStage(enabled)
  @ssh_enabled_1st_stage = enabled

  nil
end

- (Object) SetVncEnabled1stStage(enabled)

Sets whether VNC ports should be opened in firewall

Parameters:

  • boolean

    new state



254
255
256
257
258
# File '../../src/modules/SuSEFirewall4Network.rb', line 254

def SetVncEnabled1stStage(enabled)
  @vnc_enabled_1st_stage = enabled

  nil
end

- (Object) UnconfiguredIsBlocked

that are not in any zone

Returns:

  • Whether the UI should warn about interfaces



205
206
207
# File '../../src/modules/SuSEFirewall4Network.rb', line 205

def UnconfiguredIsBlocked
  !SuSEFirewall.IsAnyNetworkInterfaceSupported
end

- (Boolean) Write

Function writes configuration of SuSEFirewall.

Returns:

  • (Boolean)

    if successful



61
62
63
64
# File '../../src/modules/SuSEFirewall4Network.rb', line 61

def Write
  Builtins.y2milestone("Writing the firewall configuration")
  SuSEFirewall.Write
end