Class: Yast::SuSEFirewallServicesClass
- Inherits:
-
Module
- Object
- Module
- Yast::SuSEFirewallServicesClass
- Includes:
- Logger
- Defined in:
- library/network/src/lib/network/susefirewallservices.rb
Overview
Global Definition of Firewall Services Manages services for SuSEFirewall2 and FirewallD
Direct Known Subclasses
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
-
#all_services ⇒ Object
private
Returns all known services loaded from disk on-the-fly.
-
#GetDescription(service) ⇒ String
Function returns description of a firewall service.
-
#GetFilenameFromServiceDefinedByPackage(service) ⇒ String
Creates a file name from service name defined by package.
-
#GetListOfServicesAddedByPackage ⇒ Array<String>
Returns list of service-ids defined by packages.
-
#GetMetadataAgent(filefullpath) ⇒ Yast::Term
private
Returns SCR Agent definition.
-
#GetModified ⇒ Boolean
Returns whether configuration was modified.
-
#GetNeededIPProtocols(service) ⇒ Array<String>
Function returns needed IP protocols for service.
-
#GetNeededPortsAndProtocols(service) ⇒ Hash{String => Array<String>}
Function returns needed ports and protocols for service.
-
#GetNeededRPCPorts(service) ⇒ Array<String>
Function returns needed RPC ports for service.
-
#GetNeededTCPPorts(service) ⇒ Array<String>
Function returns needed TCP ports for service.
-
#GetNeededUDPPorts(service) ⇒ Array<String>
Function returns needed UDP ports for service.
-
#GetSupportedServices ⇒ Hash{String => String}
Function returns the map of supported (known) services.
-
#initialize ⇒ SuSEFirewallServicesClass
constructor
A new instance of SuSEFirewallServicesClass.
-
#IsKnownService(service_id) ⇒ Boolean
Function returns if the service_id is a known (defined) service.
-
#ResetModified ⇒ Object
Sets that configuration was not modified.
-
#ServiceDefinedByPackage(service) ⇒ Boolean
Returns whether the service ID is defined by package.
Constructor Details
#initialize ⇒ SuSEFirewallServicesClass
Returns a new instance of SuSEFirewallServicesClass.
48 49 50 51 52 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 48 def initialize super textdomain "base" end |
Instance Method Details
#all_services ⇒ Object
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
152 153 154 155 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 152 def all_services ReadServicesDefinedByRPMPackages() if @services.nil? @services end |
#GetDescription(service) ⇒ String
Function returns description of a firewall service
126 127 128 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 126 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'.
193 194 195 196 197 198 199 200 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 193 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 |
#GetListOfServicesAddedByPackage ⇒ Array<String>
Returns list of service-ids defined by packages. (including the "service:" prefix)
86 87 88 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 86 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.
207 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 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 207 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 |
#GetModified ⇒ Boolean
Returns whether configuration was modified
167 168 169 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 167 def GetModified @sfws_modified end |
#GetNeededIPProtocols(service) ⇒ Array<String>
Function returns needed IP protocols for service
118 119 120 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 118 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).
146 147 148 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 146 def GetNeededPortsAndProtocols(service) DEFAULT_SERVICE.merge(service_details(service)) end |
#GetNeededRPCPorts(service) ⇒ Array<String>
Function returns needed RPC ports for service
110 111 112 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 110 def GetNeededRPCPorts(service) service_details(service)["rpc_ports"] || [] end |
#GetNeededTCPPorts(service) ⇒ Array<String>
Function returns needed TCP ports for service
94 95 96 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 94 def GetNeededTCPPorts(service) service_details(service)["tcp_ports"] || [] end |
#GetNeededUDPPorts(service) ⇒ Array<String>
Function returns needed UDP ports for service
102 103 104 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 102 def GetNeededUDPPorts(service) service_details(service)["udp_ports"] || [] end |
#GetSupportedServices ⇒ Hash{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",
}
65 66 67 68 69 70 71 72 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 65 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
78 79 80 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 78 def IsKnownService(service_id) !service_details(service_id, true).nil? end |
#ResetModified ⇒ Object
Sets that configuration was not modified
158 159 160 161 162 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 158 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.
180 181 182 |
# File 'library/network/src/lib/network/susefirewallservices.rb', line 180 def ServiceDefinedByPackage(service) service.start_with? DEFINED_BY_PKG_PREFIX end |