Class: Yast::RemoteClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
../../src/modules/Remote.rb

Constant Summary

XDM_SERVICE_NAME =
"display-manager"
XINETD_SERVICE =
"xinetd"
PKG_CONTAINING_FW_SERVICES =
"xorg-x11-Xvnc"
GRAPHICAL_TARGET =
"graphical"

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) configure_display_manager

Updates the VNC and xdm configuration

Called from #Write. Ensures that required packages are installed, enables xinetd and xdm and writes the configuration files, reporting any error in the process.

Returns:

  • (Boolean)

    true if success, false otherwise



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File '../../src/modules/Remote.rb', line 331

def configure_display_manager

  if IsEnabled()
    # Install required packages
    if !Package.InstallAll(Packages.vnc_packages)
      log.error "Installing of required packages failed"
      return false
    end

    # Enable xinetd
    if !Service.Enable(XINETD_SERVICE)
      Report.Error(
        _("Enabling service %{service} has failed") % { :service => XINETD_SERVICE }
      )
      return false
    end

    # Enable XDM
    if !Service.Enable(XDM_SERVICE_NAME)
      Report.Error(
        _("Enabling service %{service} has failed") % { :service => XDM_SERVICE_NAME }
      )
      return false
    end
  end

  # Set DISPLAYMANAGER_REMOTE_ACCESS in sysconfig/displaymanager
  SCR.Write(
    path(".sysconfig.displaymanager.DISPLAYMANAGER_REMOTE_ACCESS"),
    IsEnabled() ? "yes" : "no"
  )
  SCR.Write(
    path(".sysconfig.displaymanager.DISPLAYMANAGER_ROOT_LOGIN_REMOTE"),
    IsEnabled() ? "yes" : "no"
  )
  SCR.Write(path(".sysconfig.displaymanager"), nil)

  #Do this only if package xinetd is installed (#256385)
  return false if Package.Installed("xinetd") && !WriteXinetd()

  true
end

- (Object) Disable

Disables remote administration.



103
104
105
106
107
# File '../../src/modules/Remote.rb', line 103

def Disable
  @allow_administration = false

  nil
end

- (Object) Enable

Enables remote administration.



96
97
98
99
100
# File '../../src/modules/Remote.rb', line 96

def Enable
  @allow_administration = true

  nil
end

- (Object) IsDisabled

Checks if remote administration is currently disallowed



91
92
93
# File '../../src/modules/Remote.rb', line 91

def IsDisabled
  !IsEnabled()
end

- (Object) IsEnabled

Checks if remote administration is currently allowed



86
87
88
# File '../../src/modules/Remote.rb', line 86

def IsEnabled
  @allow_administration
end

- (Object) main



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File '../../src/modules/Remote.rb', line 44

def main
  Yast.import "UI"
  textdomain "network"

  Yast.import "Label"
  Yast.import "Mode"
  Yast.import "Package"
  Yast.import "Packages"
  Yast.import "Service"
  Yast.import "SuSEFirewall"
  Yast.import "Progress"
  Yast.import "Linuxrc"
  Yast.import "String"
  Yast.import "FileUtils"
  Yast.import "Message"
  Yast.import "SystemdTarget"

  Yast.include self, "network/routines.rb"

  # security types supported by Xvnc
  @SEC_NONE = "none"
  @SEC_VNCAUTH = "vncauth"

  @SEC_TYPES = [@SEC_NONE, @SEC_VNCAUTH]

  @SEC_OPT_SECURITYTYPE = "securitytypes"

  # Currently, all attributes (enablement of remote access)
  # are applied on vnc1 even vnchttpd1 configuration

  # Allow remote administration
  @allow_administration = false

  # Default display manager
  @default_dm = "xdm"

  # Remote administration has been already proposed
  # Only force-reset can change it
  @already_proposed = false
end

- (Object) Propose

Function proposes a configuration But only if it hasn't been proposed already



126
127
128
129
130
# File '../../src/modules/Remote.rb', line 126

def Propose
  Reset() if !@already_proposed

  nil
end

- (Object) Read

Read the current status

Returns:

  • true on success



206
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
239
240
241
242
243
244
245
246
247
248
249
250
# File '../../src/modules/Remote.rb', line 206

def Read
  xdm = Service.Enabled(XDM_SERVICE_NAME)
  dm_ra = Convert.to_string(
    SCR.Read(path(".sysconfig.displaymanager.DISPLAYMANAGER_REMOTE_ACCESS"))
  ) == "yes"
  @default_dm = Convert.to_string(
    SCR.Read(path(".sysconfig.displaymanager.DISPLAYMANAGER"))
  )

  xinetd = Service.Enabled(XINETD_SERVICE)
  # are the proper services enabled in xinetd?
  xinetd_conf = Convert.convert(
    SCR.Read(path(".etc.xinetd_conf.services")),
    :from => "any",
    :to   => "list <map>"
  )
  vnc_conf = Builtins.filter(xinetd_conf) do |m|
    s = Ops.get_string(m, "service", "")
    s == "vnc1" || s == "vnchttpd1"
  end
  vnc = Builtins.size(vnc_conf) == 2 &&
    Ops.get_boolean(vnc_conf, [0, "enabled"], false) &&
    Ops.get_boolean(vnc_conf, [1, "enabled"], false)

  log.info "#{XDM_SERVICE_NAME}: #{xdm}, DM_R_A: #{dm_ra}"
  log.info "xinetd: #{xinetd}, VNC: #{vnc}"

  @allow_administration = xdm && dm_ra && xinetd && vnc

  # Package containing SuSEfirewall2 services has to be installed before
  # reading SuSEFirewall, otherwise exception is thrown by firewall
  if Package.Install(PKG_CONTAINING_FW_SERVICES)
    current_progress = Progress.set(false)
    SuSEFirewall.Read
    Progress.set(current_progress)
  else
    Report.Error(
      _("Package %{package} is not installed\nfirewall settings will be disabled.") % {
        :package => PKG_CONTAINING_FW_SERVICES
      }
    )
  end

  true
end

- (Object) Reset

Reset all module data.



110
111
112
113
114
115
116
117
118
119
120
121
122
# File '../../src/modules/Remote.rb', line 110

def Reset
  @already_proposed = true

  # Bugzilla #135605 - enabling Remote Administration when installing using VNC
  @allow_administration = Linuxrc.vnc

  Builtins.y2milestone(
    "Remote Administration was proposed as: %1",
    @allow_administration ? "enabled" : "disabled"
  )

  nil
end

- (Object) restart_display_manager



374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File '../../src/modules/Remote.rb', line 374

def restart_display_manager
  if Service.active?(XDM_SERVICE_NAME)
    Report.Error(Message.CannotRestartService(XDM_SERVICE_NAME)) unless Service.Reload(XDM_SERVICE_NAME)
    Report.Warning(
      _(
        "Your display manager must be restarted.\n" +
        "To take the changes in remote administration into account, \n" +
        "please restart it manually or log out and log in again."
      )
    )
  else
    Report.Error(Message.CannotRestartService(XDM_SERVICE_NAME)) unless Service.Restart(XDM_SERVICE_NAME)
  end
end

- (Object) restart_services

Restarts xinetd and xdm, reporting errors to the user



390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File '../../src/modules/Remote.rb', line 390

def restart_services
  if IsEnabled()
    SystemdTarget.set_default(GRAPHICAL_TARGET)

    Report.Error(Message.CannotRestartService(XINETD_SERVICE)) unless Service.Restart(XINETD_SERVICE)

    restart_display_manager
  else
    # xinetd may be needed for other services so we never turn it
    # off. It will exit anyway if no services are configured.
    # If it is running, restart it.
    Service.Reload(XINETD_SERVICE) if Service.active?(XINETD_SERVICE)
  end
end

- (Object) ServerArgsRemoveOpt(server_args, option, has_value)

Removes all options <option> (and its value) from <server_args>

Note: server_args has to be valid. In case of incorrect input (e.g. -opt1= -opt2) is result undefined.

Parameters:

  • server_args (String)

    list of options as provided by server_args attribute in /etc/xinet.d/vnc

  • option (String)

    option name. Typically alphanumeric string. If a regexp special characters are used behavior is undefined.

  • has_value (Boolean)

    if true then option is expected to be followed by a value

Returns:

  • modified server_args string in case of success unchanged server_args otherwise



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File '../../src/modules/Remote.rb', line 145

def ServerArgsRemoveOpt(server_args, option, has_value)
  return server_args if IsEmpty(server_args) || IsEmpty(option)

  # Note: value (e.g. filename in -passwdfile) cannot be quoted (a bug in Xvnc ?).
  # valid forms are:
  # e.g. -file=path_to_file or
  # e.g. -file path_to_file
  value_pattern_nquote = "[=[:space:]][^[:space:]]+"
  pattern = Builtins.sformat(
    "[[:space:]]*[-]{0,2}%1%2",
    option,
    has_value ? value_pattern_nquote : ""
  )

  # Xvnc:
  # - is case insensitive to option names.
  # - option can be prefixed by 0 or up to 2 dashes
  # - option and value can be separated by space or =
  new_server_args = server_args.downcase

  new_server_args = String.CutRegexMatch(new_server_args, pattern, true)

  new_server_args
end

- (Object) SetSecurityType(server_args, sec_type)

Appends option for particular security type.

Parameters:

  • server_args (String)

    string with server options as written in xinetd cfg file

  • sec_type (String)

    a security type supported by Xvnc (see man xvnc)

Returns:

  • server_args with appended option for particular sec_type if sec_type is valid. Unchanged server_args otherwise.



197
198
199
200
201
202
# File '../../src/modules/Remote.rb', line 197

def SetSecurityType(server_args, sec_type)
  # validate sec_type
  return server_args if !@SEC_TYPES.include?(sec_type)

  SetServerArgsOpt(server_args, @SEC_OPT_SECURITYTYPE, sec_type)
end

- (Object) SetServerArgsOpt(server_args, option, value)

Add given option and its value to server_args.

If option is present already then all occurences of option are removed. New option value pair is added subsequently.



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File '../../src/modules/Remote.rb', line 174

def SetServerArgsOpt(server_args, option, value)
  new_server_args = ServerArgsRemoveOpt(
    server_args,
    option,
    IsNotEmpty(value)
  )
  new_server_args = Builtins.sformat(
    "%1 -%2 %3",
    new_server_args,
    option,
    value
  )

  String.CutBlanks(new_server_args)
end

- (Object) Summary

Create summary

Returns:

  • summary text



407
408
409
410
# File '../../src/modules/Remote.rb', line 407

def Summary
  # description in proposal
  IsEnabled() ? _("Remote administration is enabled.") : _("Remote administration is disabled.")
end

- (Object) Write

Update the SCR according to network settings

Returns:

  • true on success



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File '../../src/modules/Remote.rb', line 290

def Write
  steps = [
    # Progress stage 1
    _("Write firewall settings"),
    # Progress stage 2
    _("Configure display manager")
  ]

  if Mode.normal
    # Progress stage 3
    steps << _("Restart the services")
  end

  caption = _("Saving Remote Administration Configuration")

  Progress.New(caption, " ", Builtins.size(steps), steps, [], "")

  ProgressNextStage(_("Writing firewall settings..."))
  current_progress = Progress.set(false)
  SuSEFirewall.Write
  Progress.set(current_progress)

  ProgressNextStage(_("Configuring display manager..."))
  return false unless configure_display_manager

  if Mode.normal
    ProgressNextStage(_("Restarting the service..."))
    restart_services
    Progress.NextStage
  end

  true
end

- (Object) WriteXinetd



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File '../../src/modules/Remote.rb', line 252

def WriteXinetd
  # Enable/disable vnc1 and vnchttpd1 in xinetd.d/vnc
  # If the port is changed, change also the help in remote/dialogs.ycp
  # The agent is in yast2-inetd.rpm
  xinetd = Convert.convert(
    SCR.Read(path(".etc.xinetd_conf.services")),
    :from => "any",
    :to   => "list <map>"
  )

  xinetd = Builtins.maplist(xinetd) do |m|
    s = Ops.get_string(m, "service", "")
    next deep_copy(m) if !(s == "vnc1" || s == "vnchttpd1")
    Ops.set(m, "changed", true)
    Ops.set(m, "enabled", @allow_administration)
    server_args = Ops.get_string(m, "server_args", "")
    if IsEnabled()
      # use none authentication, xdm will take care of it
      Ops.set(m, "server_args", SetSecurityType(server_args, @SEC_NONE))
    else
      # switch back to default when remote administration is disallowed.
      Ops.set(
        m,
        "server_args",
        ServerArgsRemoveOpt(server_args, @SEC_OPT_SECURITYTYPE, true)
      )
    end
    log.info "Updated xinet cfg: #{m}"
    deep_copy(m)
  end

  SCR.Write(path(".etc.xinetd_conf.services"), xinetd)

  true
end