Class: Yast::SuSEFirewallServicesClass

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

Overview

Global Definition of Firewall Services Manages services for SuSEFirewall2 and FirewallD

Constant Summary collapse

DEFINED_BY_PKG_PREFIX =

this is how services defined by package are distinguished

"service:".freeze
DEFAULT_SERVICE =
{
  "tcp_ports"       => [],
  "udp_ports"       => [],
  "rpc_ports"       => [],
  "ip_protocols"    => [],
  "broadcast_ports" => [],
  "name"            => "",
  "description"     => ""
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeSuSEFirewallServicesClass

Returns a new instance of SuSEFirewallServicesClass.


51
52
53
# File 'library/network/src/lib/network/susefirewallservices.rb', line 51

def initialize
  textdomain "base"
end

Instance Method Details

#all_servicesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns all known services loaded from disk on-the-fly


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

def all_services
  ReadServicesDefinedByRPMPackages() if @services.nil?
  @services
end

#GetDescription(service) ⇒ String

Function returns description of a firewall service

Parameters:

  • service (String)

    (including the "service:" prefix)

Returns:

  • (String)

    service description


127
128
129
# File 'library/network/src/lib/network/susefirewallservices.rb', line 127

def GetDescription(service)
  service_details(service)["description"] || []
end

#GetFilenameFromServiceDefinedByPackage(service) ⇒ String

Creates a file name from service name defined by package. Service MUST be defined by package, otherwise it returns 'nil'.

Examples:

GetFilenameFromServiceDefinedByPackage ("service:abc") -> "abc"
GetFilenameFromServiceDefinedByPackage ("abc") -> nil

Parameters:

  • service (String)

    name (e.g., 'service:abc')

Returns:

  • (String)

    file name (e.g., 'abc')


194
195
196
197
198
199
200
201
# File 'library/network/src/lib/network/susefirewallservices.rb', line 194

def GetFilenameFromServiceDefinedByPackage(service)
  if !ServiceDefinedByPackage(service)
    log.error "Service #{service} is not defined by package"
    return nil
  end

  service[/\A#{DEFINED_BY_PKG_PREFIX}(.*)/, 1]
end

#GetListOfServicesAddedByPackageArray<String>

Returns list of service-ids defined by packages. (including the "service:" prefix)

Returns:

  • (Array<String>)

    service ids


87
88
89
# File 'library/network/src/lib/network/susefirewallservices.rb', line 87

def GetListOfServicesAddedByPackage
  all_services.keys
end

#GetMetadataAgent(filefullpath) ⇒ Yast::Term

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns SCR Agent definition.

Parameters:

  • filefullpath (String)

    full filename path (to read by this agent)

Returns:

  • (Yast::Term)

    with agent definition


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
# File 'library/network/src/lib/network/susefirewallservices.rb', line 208

def GetMetadataAgent(filefullpath)
  term(
    :IniAgent,
    filefullpath,
    "options"  => [
      "global_values",
      "flat",
      "read_only",
      "ignore_case_regexps"
    ],
    "comments" => [
      # jail followed by anything but jail (immediately)
      "^[ \t]*#[^#].*$",
      # comments that are not commented key:value pairs (see "params")
      # they always use two jails
      "^[ \t]*##[ \t]*[^([a-zA-Z0-9_]+:.*)]$",
      # comments with three jails and more
      "^[ \t]*###.*$",
      # jail alone
      "^[ \t]*#[ \t]*$",
      # (empty space)
      "^[ \t]*$",
      # sysconfig entries
      "^[ \t]*[a-zA-Z0-9_]+.*"
    ],
    "params"   => [
      # commented key:value pairs
      # e.g.: ## Name: service name
      { "match" => ["^##[ \t]*([a-zA-Z0-9_]+):[ \t]*(.*)[ \t]*$", "%s: %s"] }
    ]
  )
end

#GetModifiedBoolean

Returns whether configuration was modified

Returns:

  • (Boolean)

    modified


168
169
170
# File 'library/network/src/lib/network/susefirewallservices.rb', line 168

def GetModified
  @sfws_modified
end

#GetNeededIPProtocols(service) ⇒ Array<String>

Function returns needed IP protocols for service

Parameters:

  • service (String)

    (including the "service:" prefix)

Returns:

  • (Array<String>)

    of needed IP protocols


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

def GetNeededIPProtocols(service)
  service_details(service)["ip_protocols"] || []
end

#GetNeededPortsAndProtocols(service) ⇒ Hash{String => Array<String>}

Function returns needed ports and protocols for service. Service needs to be known (installed in the system). Function throws an exception SuSEFirewalServiceNotFound if service is not known (undefined).

Examples:

GetNeededPortsAndProtocols ("service:aaa") -> {
        "tcp_ports"      => [ "122", "ftp-data" ],
        "udp_ports"      => [ "427" ],
        "rpc_ports"      => [ "portmap", "ypbind" ],
        "ip_protocols"   => [],
        "broadcast_ports"=> [ "427" ],
}

Parameters:

  • service (String)

    (including the "service:" prefix)

Returns:

  • (Hash{String => Array<String>})

    of needed ports and protocols


147
148
149
# File 'library/network/src/lib/network/susefirewallservices.rb', line 147

def GetNeededPortsAndProtocols(service)
  DEFAULT_SERVICE.merge(service_details(service))
end

#GetNeededRPCPorts(service) ⇒ Array<String>

Function returns needed RPC ports for service

Parameters:

  • service (String)

    (including the "service:" prefix)

Returns:

  • (Array<String>)

    of needed RPC ports


111
112
113
# File 'library/network/src/lib/network/susefirewallservices.rb', line 111

def GetNeededRPCPorts(service)
  service_details(service)["rpc_ports"] || []
end

#GetNeededTCPPorts(service) ⇒ Array<String>

Function returns needed TCP ports for service

Parameters:

  • service (String)

    (including the "service:" prefix)

Returns:

  • (Array<String>)

    of needed TCP ports


95
96
97
# File 'library/network/src/lib/network/susefirewallservices.rb', line 95

def GetNeededTCPPorts(service)
  service_details(service)["tcp_ports"] || []
end

#GetNeededUDPPorts(service) ⇒ Array<String>

Function returns needed UDP ports for service

Parameters:

  • service (String)

    (including the "service:" prefix)

Returns:

  • (Array<String>)

    of needed UDP ports


103
104
105
# File 'library/network/src/lib/network/susefirewallservices.rb', line 103

def GetNeededUDPPorts(service)
  service_details(service)["udp_ports"] || []
end

#GetSupportedServicesHash{String => String}

Function returns the map of supported (known) services.

Structure:

{ service_id => localized_service_name }
{
    "service:dns-server" => "DNS Server",
    "service:vnc" => "Remote Administration",
}

Returns:


66
67
68
69
70
71
72
73
# File 'library/network/src/lib/network/susefirewallservices.rb', line 66

def GetSupportedServices
  supported_services = {}
  all_services.each do |service_id, service_definition|
    # TRANSLATORS: Name of unknown service. %1 is a requested service id like nfs-server
    supported_services[service_id] = service_definition["name"] || Builtins.sformat(_("Unknown service '%1'"), service_id)
  end
  supported_services
end

#IsKnownService(service_id) ⇒ Boolean

Function returns if the service_id is a known (defined) service

Parameters:

  • service_id (String)

    (including the "service:" prefix)

Returns:

  • (Boolean)

    if is known (defined)


79
80
81
# File 'library/network/src/lib/network/susefirewallservices.rb', line 79

def IsKnownService(service_id)
  !service_details(service_id, true).nil?
end

#ResetModifiedObject

Sets that configuration was not modified


159
160
161
162
163
# File 'library/network/src/lib/network/susefirewallservices.rb', line 159

def ResetModified
  @sfws_modified = false

  nil
end

#ServiceDefinedByPackage(service) ⇒ Boolean

Returns whether the service ID is defined by package. Returns 'false' if it isn't.

Examples:

ServiceDefinedByPackage ("http-server") -> false
ServiceDefinedByPackage ("service:http-server") -> true

Parameters:

Returns:

  • (Boolean)

    whether service is defined by package


181
182
183
# File 'library/network/src/lib/network/susefirewallservices.rb', line 181

def ServiceDefinedByPackage(service)
  service.start_with? DEFINED_BY_PKG_PREFIX
end