Class: Firewalld::FirewalldBashAPI

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
library/network/src/lib/network/firewalld.rb

Overview

The firewalld bash API

Instance Method Summary collapse

Instance Method Details

#add_interface(zone, interface) ⇒ Boolean

Returns True if interface was added to zone

Parameters:

  • zone (String)

    The firewall zone

  • interface (String)

    The network interface

Returns:

  • (Boolean)

    True if interface was added to zone



187
188
189
# File 'library/network/src/lib/network/firewalld.rb', line 187

def add_interface(zone, interface)
  fwd_quiet_result("--permanent --zone=#{zone} --add-interface=#{interface}")
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



319
320
321
322
# File 'library/network/src/lib/network/firewalld.rb', line 319

def add_masquerade(zone)
  return true if masquerade_enabled?(zone)
  fwd_quiet_result("--permanent --zone=#{zone} --add-masquerade")
end

#add_port(zone, port) ⇒ Boolean

Returns True if port was added to zone

Parameters:

  • zone (String)

    The firewall zone

  • port (String)

    The firewall port

Returns:

  • (Boolean)

    True if port was added to zone



279
280
281
# File 'library/network/src/lib/network/firewalld.rb', line 279

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

#add_protocol(zone, protocol) ⇒ Boolean

Returns True if protocol was added to zone

Parameters:

  • zone (String)

    The firewall zone

  • protocol (String)

    The firewall protocol

Returns:

  • (Boolean)

    True if protocol was added to zone



286
287
288
# File 'library/network/src/lib/network/firewalld.rb', line 286

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

#add_service(zone, service) ⇒ Boolean

Returns True if service was added to zone

Parameters:

  • zone (String)

    The firewall zone

  • service (String)

    The firewall service

Returns:

  • (Boolean)

    True if service was added to zone



272
273
274
# File 'library/network/src/lib/network/firewalld.rb', line 272

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

#complete_reloadBoolean

Returns The firewalld complete-reload result (exit code)

Returns:

  • (Boolean)

    The firewalld complete-reload result (exit code)



124
125
126
# File 'library/network/src/lib/network/firewalld.rb', line 124

def complete_reload
  fwd_quiet_result("--complete-reload")
end

#info_service(service) ⇒ Array<String>

Returns list of all information for the given service

Parameters:

  • service (String)

    The firewall service

Returns:

  • (Array<String>)

    list of all information for the given service



207
208
209
# File 'library/network/src/lib/network/firewalld.rb', line 207

def info_service(service)
  fwd_result("--permanent --info-service #{service}").split("\n")
end

#interface_enabled?(zone, interface) ⇒ Boolean

Returns True if interface is assigned to zone

Parameters:

  • zone (String)

    The firewall zone

  • interface (String)

    The network interface

Returns:

  • (Boolean)

    True if interface is assigned to zone



180
181
182
# File 'library/network/src/lib/network/firewalld.rb', line 180

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

#list_all(zone) ⇒ Array<String>

Returns list of all information for given zone

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Array<String>)

    list of all information for given zone



166
167
168
# File 'library/network/src/lib/network/firewalld.rb', line 166

def list_all(zone)
  fwd_result("--permanent --zone=#{zone} --list-all").split(" ")
end

#list_all_zonesArray<String>

Returns list of all information for all firewall zones

Returns:

  • (Array<String>)

    list of all information for all firewall zones



171
172
173
# File 'library/network/src/lib/network/firewalld.rb', line 171

def list_all_zones
  fwd_result("--permanent --list-all-zones").split("\n")
end

#list_interfaces(zone) ⇒ Array<String>

Returns list of zone's interfaces

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Array<String>)

    list of zone's interfaces



142
143
144
# File 'library/network/src/lib/network/firewalld.rb', line 142

def list_interfaces(zone)
  fwd_result("--permanent --zone=#{zone} --list-interfaces").split(" ")
end

#list_ports(zone) ⇒ Array<String>

Returns list of zone's ports

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Array<String>)

    list of zone's ports



154
155
156
# File 'library/network/src/lib/network/firewalld.rb', line 154

def list_ports(zone)
  fwd_result("--permanent --zone=#{zone} --list-ports").split(" ")
end

#list_protocols(zone) ⇒ Array<String>

Returns list of zone's protocols

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Array<String>)

    list of zone's protocols



160
161
162
# File 'library/network/src/lib/network/firewalld.rb', line 160

def list_protocols(zone)
  fwd_result("--permanent --zone=#{zone} --list-protocols").split(" ")
end

#list_services(zone) ⇒ Arrray<String>

Returns list of zone's services

Parameters:

  • zone (String)

    The firewall zone

Returns:

  • (Arrray<String>)

    list of zone's services



148
149
150
# File 'library/network/src/lib/network/firewalld.rb', line 148

def list_services(zone)
  fwd_result("--permanent --zone=#{zone} --list-services").split(" ")
end

#log_denied_packetsString

Returns packet type which is being logged when denied

Returns:

  • (String)

    packet type which is being logged when denied



349
350
351
# File 'library/network/src/lib/network/firewalld.rb', line 349

def log_denied_packets
  fwd_result("--get-log-denied").strip
end

#log_denied_packets=(kind) ⇒ Boolean

all, unicast, broadcast, multicast and off when denied

Parameters:

  • kind (String)

    Denied packets to log. Possible values are:

Returns:

  • (Boolean)

    True if desired packet type was set to being logged



344
345
346
# File 'library/network/src/lib/network/firewalld.rb', line 344

def log_denied_packets=(kind)
  fwd_quiet_result("--set-log-denied=#{kind}")
end

#log_denied_packets?(kind) ⇒ Boolean

all, unicast, broadcast, multicast and off

Parameters:

  • kind (String)

    Denied packets to log. Possible values are:

Returns:

  • (Boolean)

    True if desired packet type is being logged when denied



336
337
338
# File 'library/network/src/lib/network/firewalld.rb', line 336

def log_denied_packets?(kind)
  fwd_result("--get-log-denied").strip == kind ? true : false
end

#make_permanentBoolean

Returns The firewalld runtime-to-permanent result (exit code)

Returns:

  • (Boolean)

    The firewalld runtime-to-permanent result (exit code)



129
130
131
# File 'library/network/src/lib/network/firewalld.rb', line 129

def make_permanent
  fwd_quiet_result("--runtime-to-permanent")
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



313
314
315
# File 'library/network/src/lib/network/firewalld.rb', line 313

def masquerade_enabled?(zone)
  fwd_quiet_result("--permanent --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



258
259
260
# File 'library/network/src/lib/network/firewalld.rb', line 258

def port_enabled?(zone, port)
  fwd_quiet_result("--permanent --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



265
266
267
# File 'library/network/src/lib/network/firewalld.rb', line 265

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

#reloadBoolean

Returns The firewalld reload result (exit code)

Returns:

  • (Boolean)

    The firewalld reload result (exit code)



119
120
121
# File 'library/network/src/lib/network/firewalld.rb', line 119

def reload
  fwd_quiet_result("--reload")
end

#remove_interface(zone, interface) ⇒ Boolean

Returns True if interface was removed from zone

Parameters:

  • zone (String)

    The firewall zone

  • interface (String)

    The network interface

Returns:

  • (Boolean)

    True if interface was removed from zone



194
195
196
# File 'library/network/src/lib/network/firewalld.rb', line 194

def remove_interface(zone, interface)
  fwd_quiet_result("--permanent --zone=#{zone} --remove-interface=#{interface}")
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



326
327
328
329
# File 'library/network/src/lib/network/firewalld.rb', line 326

def remove_masquerade(zone)
  return true if !masquerade_enabled?(zone)
  fwd_quiet_result("--permanent --zone=#{zone} --remove-masquerade")
end

#remove_port(zone, port) ⇒ Boolean

Returns True if port was removed from zone

Parameters:

  • zone (String)

    The firewall zone

  • port (String)

    The firewall port

Returns:

  • (Boolean)

    True if port was removed from zone



300
301
302
# File 'library/network/src/lib/network/firewalld.rb', line 300

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

#remove_protocol(zone, protocol) ⇒ Boolean

Returns True if protocol was removed from zone

Parameters:

  • zone (String)

    The firewall zone

  • protocol (String)

    The firewall protocol

Returns:

  • (Boolean)

    True if protocol was removed from zone



307
308
309
# File 'library/network/src/lib/network/firewalld.rb', line 307

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

#remove_service(zone, service) ⇒ Boolean

Returns True if service was removed from zone

Parameters:

  • zone (String)

    The firewall zone

  • service (String)

    The firewall service

Returns:

  • (Boolean)

    True if service was removed from zone



293
294
295
# File 'library/network/src/lib/network/firewalld.rb', line 293

def remove_service(zone, service)
  fwd_quiet_result("--permanent --zone=#{zone} --remove-service=#{service}")
end

#running?Boolean

Returns The firewalld service state (exit code)

Returns:

  • (Boolean)

    The firewalld service state (exit code)



114
115
116
# File 'library/network/src/lib/network/firewalld.rb', line 114

def running?
  fwd_quiet_result("--state")
end

#service_description(service) ⇒ String

Returns Description for service

Parameters:

  • service (String)

    the firewall service

Returns:

  • (String)

    Description for service



220
221
222
# File 'library/network/src/lib/network/firewalld.rb', line 220

def service_description(service)
  fwd_result("--permanent --service=#{service} --get-description").rstrip
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



233
234
235
# File 'library/network/src/lib/network/firewalld.rb', line 233

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

#service_modules(service) ⇒ Array<String>

Returns The firewall service modules

Parameters:

  • service (String)

    The firewall service

Returns:

  • (Array<String>)

    The firewall service modules



251
252
253
# File 'library/network/src/lib/network/firewalld.rb', line 251

def service_modules(service)
  fwd_result("--permanent --service=#{service} --get-modules").strip
end

#service_ports(service) ⇒ Array<String>

Returns The firewall service ports

Parameters:

  • service (String)

    The firewall service

Returns:

  • (Array<String>)

    The firewall service ports



239
240
241
# File 'library/network/src/lib/network/firewalld.rb', line 239

def service_ports(service)
  fwd_result("--permanent --service=#{service} --get-ports").strip
end

#service_protocols(service) ⇒ Array<String>

Returns The firewall service protocols

Parameters:

  • service (String)

    The firewall service

Returns:

  • (Array<String>)

    The firewall service protocols



245
246
247
# File 'library/network/src/lib/network/firewalld.rb', line 245

def service_protocols(service)
  fwd_result("--permanent --service=#{service} --get-protocols").strip
end

#service_short(service) ⇒ String

Returns Short description for service

Parameters:

  • service (String)

    The firewall service

Returns:

  • (String)

    Short description for service



213
214
215
216
# File 'library/network/src/lib/network/firewalld.rb', line 213

def service_short(service)
  # these may not exist on early firewalld releases
  fwd_result("--permanent --service=#{service} --get-short").rstrip
end

#service_supported?(service) ⇒ Boolean

Returns True if service definition exists

Parameters:

  • service (String)

    The firewall service

Returns:

  • (Boolean)

    True if service definition exists



226
227
228
# File 'library/network/src/lib/network/firewalld.rb', line 226

def service_supported?(service)
  services.include?(service)
end

#servicesArray<String>

Returns List of firewall services

Returns:

  • (Array<String>)

    List of firewall services



201
202
203
# File 'library/network/src/lib/network/firewalld.rb', line 201

def services
  fwd_result("--permanent --get-services").split(" ")
end

#zonesArray<String>

Returns List of firewall zones

Returns:

  • (Array<String>)

    List of firewall zones



136
137
138
# File 'library/network/src/lib/network/firewalld.rb', line 136

def zones
  fwd_result("--permanent --get-zones").split(" ")
end