Module: Y2Firewall::Firewalld::Api::Zones

Included in:
Y2Firewall::Firewalld::Api
Defined in:
library/network/src/lib/y2firewall/firewalld/api/zones.rb

Overview

This module contains specific api methods for handling zones configuration.

Instance Method Summary collapse

Instance Method Details

#add_interface(zone, interface, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • interface (String)

    The network interface

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if interface was added to zone



113
114
115
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 113

def add_interface(zone, interface, permanent: permanent?)
  run_command("--zone=#{zone}", "--add-interface=#{interface}", permanent: permanent)
end

#add_masquerade(zone) ⇒ Boolean

Returns True if masquerade was enabled in zone

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Boolean)

    True if masquerade was enabled in zone



249
250
251
252
253
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 249

def add_masquerade(zone)
  return true if masquerade_enabled?(zone)

  run_command("--zone=#{zone}", "--add-masquerade")
end

#add_port(zone, port, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • port (String)

    The firewall port

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if port was added to zone



197
198
199
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 197

def add_port(zone, port, permanent: permanent?)
  run_command("--zone=#{zone}", "--add-port=#{port}", permanent: permanent)
end

#add_protocol(zone, protocol, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • protocol (String)

    The firewall protocol

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if protocol was added to zone



206
207
208
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 206

def add_protocol(zone, protocol, permanent: permanent?)
  run_command("--zone=#{zone}", "--add-protocol=#{protocol}", permanent: permanent)
end

#add_service(zone, service, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • service (String)

    The firewall service

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if service was added to zone



188
189
190
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 188

def add_service(zone, service, permanent: permanent?)
  run_command("--zone=#{zone}", "--add-service=#{service}", permanent: permanent)
end

#add_source(zone, source, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • source (String)

    The network source

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if source was added



140
141
142
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 140

def add_source(zone, source, permanent: permanent?)
  run_command("--zone=#{zone}", "--add-source=#{source}", permanent: permanent)
end

#change_interface(zone, interface, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • interface (String)

    The network interface

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if interface was changed



131
132
133
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 131

def change_interface(zone, interface, permanent: permanent?)
  run_command("--zone=#{zone}", "--change-interface=#{interface}", permanent: permanent)
end

#change_source(zone, source, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • source (String)

    The network source

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if source was changed



158
159
160
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 158

def change_source(zone, source, permanent: permanent?)
  run_command("--zone=#{zone}", "--change-source=#{source}", permanent: permanent)
end

#interface_enabled?(zone, interface, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • interface (String)

    The network interface

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if interface is assigned to zone



104
105
106
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 104

def interface_enabled?(zone, interface, permanent: permanent?)
  query_command("--zone=#{zone} --query-interface=#{interface}", permanent: permanent)
end

#interface_zone(interface, permanent: permanent?) ) ⇒ String?

Return the name of the zone the interface belongs to or nil.

command to be executed

Parameters:

  • interface (String)

    interface name

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (String, nil)

    the interface zone or nil



95
96
97
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 95

def interface_zone(interface, permanent: permanent?)
  string_command("--get-zone-of-interface=#{interface}", permanent: permanent)
end

#list_all(zone, permanent: permanent?) ) ⇒ Array<String>

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Array<String>)

    list of all information for given zone



76
77
78
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 76

def list_all(zone, permanent: permanent?)
  string_command("--zone=#{zone}", "--list-all", permanent: permanent).split(" ")
end

#list_all_zones(permanent: permanent?) ) ⇒ Array<String>

command to be executed

Parameters:

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Array<String>)

    list of all information for all firewall zones



83
84
85
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 83

def list_all_zones(permanent: permanent?)
  string_command("--list-all-zones", permanent: permanent).split("\n")
end

#list_interfaces(zone, permanent: permanent?) ) ⇒ Array<String>

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Array<String>)

    list of zone's interfaces



40
41
42
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 40

def list_interfaces(zone, permanent: permanent?)
  string_command("--zone=#{zone}", "--list-interfaces", permanent: permanent).split(" ")
end

#list_ports(zone, permanent: permanent?) ) ⇒ Array<String>

Returns list of zone's ports

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Array<String>)

    list of zone's ports



54
55
56
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 54

def list_ports(zone, permanent: permanent?)
  string_command("--zone=#{zone}", "--list-ports", permanent: permanent).split(" ")
end

#list_protocols(zone, permanent: permanent?) ) ⇒ Array<String>

Returns list of zone's protocols

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Array<String>)

    list of zone's protocols



60
61
62
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 60

def list_protocols(zone, permanent: permanent?)
  string_command("--zone=#{zone}", "--list-protocols", permanent: permanent).split(" ")
end

#list_services(zone, permanent: permanent?) ) ⇒ Arrray<String>

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Arrray<String>)

    list of zone's services



48
49
50
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 48

def list_services(zone, permanent: permanent?)
  string_command("--zone=#{zone}", "--list-services", permanent: permanent).split(" ")
end

#list_sources(zone, permanent: permanent?) ) ⇒ Array<String>

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Array<String>)

    list of zone's sources



68
69
70
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 68

def list_sources(zone, permanent: permanent?)
  string_command("--zone=#{zone}", "--list-sources", permanent: permanent).split(" ")
end

#masquerade_enabled?(zone) ⇒ Boolean

Returns True if masquerade is enabled in zone

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Boolean)

    True if masquerade is enabled in zone



243
244
245
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 243

def masquerade_enabled?(zone)
  query_command("--zone=#{zone}", "--query-masquerade")
end

#port_enabled?(zone, port) ⇒ Boolean

Returns True if port is enabled in zone

Parameters:

  • zone (String)

    The firewall zone

  • port (String)

    The firewall port

Returns:

  • (Boolean)

    True if port is enabled in zone



172
173
174
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 172

def port_enabled?(zone, port)
  query_command("--zone=#{zone}", "--query-port=#{port}")
end

#protocol_enabled?(zone, protocol) ⇒ Boolean

Returns True if protocol is enabled in zone

Parameters:

  • zone (String)

    The firewall zone

  • protocol (String)

    The zone protocol

Returns:

  • (Boolean)

    True if protocol is enabled in zone



179
180
181
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 179

def protocol_enabled?(zone, protocol)
  query_command("--zone=#{zone}", "--query-protocol=#{protocol}")
end

#remove_interface(zone, interface, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • interface (String)

    The network interface

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if interface was removed from zone



122
123
124
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 122

def remove_interface(zone, interface, permanent: permanent?)
  run_command("--zone=#{zone}", "--remove-interface=#{interface}", permanent: permanent)
end

#remove_masquerade(zone) ⇒ Boolean

Returns True if masquerade was removed in zone

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Boolean)

    True if masquerade was removed in zone



257
258
259
260
261
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 257

def remove_masquerade(zone)
  return true if !masquerade_enabled?(zone)

  run_command("--zone=#{zone}", "--remove-masquerade")
end

#remove_port(zone, port, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • port (String)

    The firewall port

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if port was removed from zone



228
229
230
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 228

def remove_port(zone, port, permanent: permanent?)
  run_command("--zone=#{zone}", "--remove-port=#{port}", permanent: permanent)
end

#remove_protocol(zone, protocol, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • protocol (String)

    The firewall protocol

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if protocol was removed from zone



237
238
239
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 237

def remove_protocol(zone, protocol, permanent: permanent?)
  run_command("--zone=#{zone}", "--remove-protocol=#{protocol}", permanent: permanent)
end

#remove_service(zone, service, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • service (String)

    The firewall service

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if service was removed from zone



215
216
217
218
219
220
221
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 215

def remove_service(zone, service, permanent: permanent?)
  if offline?
    run_command("--zone=#{zone}", "--remove-service-from-zone=#{service}")
  else
    run_command("--zone=#{zone}", "--remove-service=#{service}", permanent: permanent)
  end
end

#remove_source(zone, source, permanent: permanent?) ) ⇒ Boolean

command to be executed

Parameters:

  • zone (String)

    The firewall zone

  • source (String)

    The network source

  • permanent (Boolean)

    if true it adds the –permanent option the

Returns:

  • (Boolean)

    True if source was removed



149
150
151
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 149

def remove_source(zone, source, permanent: permanent?)
  run_command("--zone=#{zone}", "--remove-source=#{source}", permanent: permanent)
end

#service_enabled?(zone, service) ⇒ Boolean

Returns True if service is enabled in zone

Parameters:

  • zone (String)

    The firewall zone

  • service (String)

    The firewall service

Returns:

  • (Boolean)

    True if service is enabled in zone



165
166
167
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 165

def service_enabled?(zone, service)
  query_command("--zone=#{zone}", "--query-service=#{service}")
end

#zonesArray<String>

Returns List of firewall zones

Returns:

  • (Array<String>)

    List of firewall zones



32
33
34
# File 'library/network/src/lib/y2firewall/firewalld/api/zones.rb', line 32

def zones
  string_command("--get-zones").split(" ")
end