Class: Yast::SuSEFirewallServicesClass

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

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


57
58
59
# File 'library/network/src/lib/network/susefirewallservices.rb', line 57

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


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

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

#GetDescription(service) ⇒ String

Function returns description of a firewall service


133
134
135
# File 'library/network/src/lib/network/susefirewallservices.rb', line 133

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

200
201
202
203
204
205
206
207
# File 'library/network/src/lib/network/susefirewallservices.rb', line 200

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)


93
94
95
# File 'library/network/src/lib/network/susefirewallservices.rb', line 93

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.


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
240
241
242
243
244
245
246
247
# File 'library/network/src/lib/network/susefirewallservices.rb', line 214

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


174
175
176
# File 'library/network/src/lib/network/susefirewallservices.rb', line 174

def GetModified
  @sfws_modified
end

#GetNeededIPProtocols(service) ⇒ Array<String>

Function returns needed IP protocols for service


125
126
127
# File 'library/network/src/lib/network/susefirewallservices.rb', line 125

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" ],
}

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

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

#GetNeededRPCPorts(service) ⇒ Array<String>

Function returns needed RPC ports for service


117
118
119
# File 'library/network/src/lib/network/susefirewallservices.rb', line 117

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

#GetNeededTCPPorts(service) ⇒ Array<String>

Function returns needed TCP ports for service


101
102
103
# File 'library/network/src/lib/network/susefirewallservices.rb', line 101

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

#GetNeededUDPPorts(service) ⇒ Array<String>

Function returns needed UDP ports for service


109
110
111
# File 'library/network/src/lib/network/susefirewallservices.rb', line 109

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",
}

72
73
74
75
76
77
78
79
# File 'library/network/src/lib/network/susefirewallservices.rb', line 72

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


85
86
87
# File 'library/network/src/lib/network/susefirewallservices.rb', line 85

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

#ResetModifiedObject

Sets that configuration was not modified


165
166
167
168
169
# File 'library/network/src/lib/network/susefirewallservices.rb', line 165

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

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

def ServiceDefinedByPackage(service)
  service.start_with? DEFINED_BY_PKG_PREFIX
end