Module: Yast::NetworkServicesDnsInclude

Includes:
UI::TextHelpers
Defined in:
src/include/network/services/dns.rb

Constant Summary collapse

CUSTOM_RESOLV_POLICIES =

CWM wants id-value pairs

{
  "STATIC"          => "STATIC",
  "STATIC_FALLBACK" => "STATIC_FALLBACK"
}.freeze
NONE_LABEL =
"no".freeze
ANY_LABEL =
"any".freeze
NO_CHANGE_LABEL =
"no_change".freeze

Instance Method Summary collapse

Instance Method Details

#configObject



654
655
656
# File 'src/include/network/services/dns.rb', line 654

def config
  Yast::Lan.yast_config
end

#current_hostnameString

Convenience method to check the current static hostname

Returns:

  • (String)


307
308
309
# File 'src/include/network/services/dns.rb', line 307

def current_hostname
  config&.hostname&.static || ""
end

#dhcp?Boolean

Checks if any interface is configured to use DHCP

Returns:

  • (Boolean)

    true when an interface uses DHCP config



661
662
663
664
665
# File 'src/include/network/services/dns.rb', line 661

def dhcp?
  return false unless config&.connections

  config.connections.any?(&:dhcp?)
end

#DNSMainDialog(_standalone) ⇒ Object

Standalone dialog only - embedded one is handled separately via CWMTab



632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
# File 'src/include/network/services/dns.rb', line 632

def DNSMainDialog(_standalone)
  caption = _("Hostname and Name Server Configuration")

  functions = {
    "init"  => fun_ref(method(:InitHnWidget), "void (string)"),
    "store" => fun_ref(method(:StoreHnWidget), "void (string, map)"),
    :abort  => fun_ref(method(:ReallyAbort), "boolean ()")
  }

  Wizard.HideBackButton

  CWM.ShowAndRun(
    "widget_descr"       => @widget_descr_dns,
    "contents"           => @dns_contents,
    # dialog caption
    "caption"            => caption,
    "back_button"        => Label.BackButton,
    "next_button"        => Label.FinishButton,
    "fallback_functions" => functions
  )
end

#handleModifyResolvPolicy(key, _event) ⇒ Object



577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'src/include/network/services/dns.rb', line 577

def handleModifyResolvPolicy(key, _event)
  Builtins.y2milestone(
    "handleModifyResolvPolicy called: %1",
    UI.QueryWidget(Id("MODIFY_RESOLV"), :Value)
  )

  @resolver_modifiable = UI.QueryWidget(Id("MODIFY_RESOLV"), :Value) != :nomodify

  initPolicy(key)

  Builtins.y2milestone(
    "Exit: resolver_modifiable = %1",
    @resolver_modifiable
  )
  nil
end

#handlePolicy(_key, _event) ⇒ Object



539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'src/include/network/services/dns.rb', line 539

def handlePolicy(_key, _event)
  Builtins.y2milestone("handlePolicy")

  case UI.QueryWidget(Id("MODIFY_RESOLV"), :Value)
  when :custom
    SetHnItem("PLAIN_POLICY", UI.QueryWidget(Id("PLAIN_POLICY"), :Value))
  when :auto
    SetHnItem("PLAIN_POLICY", "auto")
  else
    SetHnItem("PLAIN_POLICY", "")
  end

  nil
end

#HandleResolverData(key, _event) ⇒ Object

Event handler for resolver data (nameservers, searchlist) enable or disable: is DHCP available?

Parameters:

  • key (String)

    the widget receiving the event

  • _event (Hash)

    the event being handled

Returns:

  • nil so that the dialog loops on



471
472
473
474
475
476
477
478
# File 'src/include/network/services/dns.rb', line 471

def HandleResolverData(key, _event)
  # if this one is disabled, it means NM is in charge (see also initModifyResolvPolicy())
  if Convert.to_boolean(UI.QueryWidget(Id("MODIFY_RESOLV"), :Enabled))
    # thus, we should not re-enable already disabled widgets
    UI.ChangeWidget(Id(key), :Enabled, @resolver_modifiable)
  end
  nil
end

#InitDhcpHostname(_key) ⇒ Object

Init handler for DHCP_HOSTNAME



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'src/include/network/services/dns.rb', line 426

def InitDhcpHostname(_key)
  UI.ChangeWidget(Id("DHCP_HOSTNAME"), :Enabled, dhcp? && config&.backend?(:wicked))
  dhcp_hostname = DNS.dhcp_hostname

  items = [
    # translators: no device selected placeholder
    Item(Id(:none), _("no"), dhcp_hostname == :none),
    # translators: placeholder for "set hostname via any DHCP aware device"
    Item(Id(:any), _("yes: any"), dhcp_hostname == :any)
  ]

  iface_names = config.connections.to_a.select(&:dhcp?).map(&:interface)
  items += iface_names.map do |iface|
    # translators: label is in form yes: <device name>
    Item(Id(iface), format(_("yes: %s"), iface), dhcp_hostname == iface)
  end

  UI.ReplaceWidget(
    Id("dhcp_hostname_method"),
    ComboBox(
      Id("DHCP_HOSTNAME"),
      "",
      items
    )
  )

  log.info("InitDhcpHostname: preselected item = #{dhcp_hostname}")

  nil
end

#InitHnSettingsObject

Initialize internal state according current system configuration.



343
344
345
346
347
# File 'src/include/network/services/dns.rb', line 343

def InitHnSettings
  @hn_settings = InitSettings()

  nil
end

#InitHnWidget(key) ⇒ Object

Default function to init the value of a widget. Used for push buttons.

Parameters:

  • key (String)

    id of the widget



399
400
401
402
403
404
# File 'src/include/network/services/dns.rb', line 399

def InitHnWidget(key)
  value = Ops.get(@hn_settings, key)
  UI.ChangeWidget(Id(key), :Value, value)

  nil
end

#initHostnameGlobal(_key) ⇒ Object

Used in GUI mode - initializes widgets according hn_settings

Parameters:

  • _key (String)

    ignored



596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'src/include/network/services/dns.rb', line 596

def initHostnameGlobal(_key)
  InitHnSettings()

  Builtins.foreach(
    Convert.convert(
      Map.Keys(@hn_settings),
      from: "list",
      to:   "list <string>"
    )
  ) { |key2| InitHnWidget(key2) }
  # disable those if NM is in charge
  disable_unconfigureable_items(
    ["NAMESERVER_1", "NAMESERVER_2", "NAMESERVER_3", "SEARCHLIST_S"],
    false
  )

  nil
end

#initialize_network_services_dns(include_target) ⇒ Object



35
36
37
38
39
40
41
42
43
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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
# File 'src/include/network/services/dns.rb', line 35

def initialize_network_services_dns(include_target)
  textdomain "network"

  Yast.import "CWM"
  Yast.import "DNS"
  Yast.import "Hostname"
  Yast.import "IP"
  Yast.import "Label"
  Yast.import "Popup"
  Yast.import "Map"

  Yast.include include_target, "network/routines.rb"
  Yast.include include_target, "network/widgets.rb"
  Yast.include include_target, "network/lan/help.rb"

  # If there's a process modifying resolv.conf, we warn the user before
  # letting him change things that will be overwritten anyway.
  # See also #61000.
  @resolver_modifiable = false

  # original setup, used to determine whether data have been modified
  @settings_orig = {}

  # CWM buffer for both dialogs.  Note that NAMESERVERS and SEARCHLIST
  # are lists and their widgets are suffixed.
  @hn_settings = {}

  # TODO: It would be nice to display also transient hostname here - e.g. that
  # one received from dhcp
  @widget_descr_dns = {
    "HOSTNAME"        => {
      "widget"            => :textentry,
      "label"             => _("Static H&ostname"),
      "opt"               => [],
      "help"              => Ops.get_string(@help, "hostname_global", ""),
      "valid_chars"       => Yast::Hostname.ValidCharsDomain,
      "validate_type"     => :function_no_popup,
      "validate_function" => fun_ref(
        method(:ValidateHostname),
        "boolean (string, map)"
      ),
      # validation error popup
      "validate_help"     => Ops.add(
        _("The hostname is invalid.") + "\n",
        Hostname.ValidHost
      )
    },
    "HOSTNAME_GLOBAL" => {
      "widget" => :empty,
      "init"   => fun_ref(
        method(:initHostnameGlobal),
        "void (string)"
      ),
      "store"  => fun_ref(
        method(:storeHostnameGlobal),
        "void (string, map)"
      )
    },
    "DHCP_HOSTNAME"   => {
      "widget"        => :custom,
      "custom_widget" => HBox(
        Label(_("Set Hostname via DHCP")),
        HSpacing(2),
        ReplacePoint(Id("dhcp_hostname_method"), Empty()),
        ReplacePoint(Id("dh_host_text"), Empty())
      ),
      "init"          => fun_ref(method(:InitDhcpHostname), "void (string)"),
      "store"         => fun_ref(method(:StoreDhcpHostname), "void (string, map)")
    },
    "MODIFY_RESOLV"   => {
      "widget" => :combobox,
      "label"  => _("&Modify DNS Configuration"),
      "opt"    => [:notify],
      "items"  => [
        [:nomodify, _("Only Manually")],
        [:auto, _("Use Default Policy")],
        [:custom, _("Use Custom Policy")]
      ],
      "init"   => fun_ref(method(:initModifyResolvPolicy), "void (string)"),
      "handle" => fun_ref(
        method(:handleModifyResolvPolicy),
        "symbol (string, map)"
      ),
      "help"   => Ops.get_string(@help, "dns_config_policy", "")
    },
    "PLAIN_POLICY"    => {
      "widget" => :combobox,
      "label"  => _("&Custom Policy Rule"),
      "opt"    => [:editable],
      "items"  => CUSTOM_RESOLV_POLICIES.to_a,
      "init"   => fun_ref(method(:initPolicy), "void (string)"),
      "handle" => fun_ref(method(:handlePolicy), "symbol (string, map)"),
      "help"   => ""
    },
    "NAMESERVER_1"    => {
      "widget"            => :textentry,
      "label"             => _("Name Server &1"),
      "opt"               => [],
      "help"              => "",
      # at "SEARCHLIST_S"
      "handle"            => fun_ref(
        method(:HandleResolverData),
        "symbol (string, map)"
      ),
      "valid_chars"       => IP.ValidChars,
      "validate_type"     => :function_no_popup,
      "validate_function" => fun_ref(
        method(:ValidateIP),
        "boolean (string, map)"
      ),
      # validation error popup
      "validate_help"     => _("The IP address of the name server is invalid.") + "\n\n" +
        IP.Valid4 + "\n\n" + IP.Valid6
    },
    # NAMESERVER_2 and NAMESERVER_3 are cloned in the dialog function
    "SEARCHLIST_S"    => {
      "widget"            => :multi_line_edit,
      "label"             => _("Do&main Search"),
      "opt"               => [],
      "help"              => Ops.get_string(@help, "searchlist_s", ""),
      "handle"            => fun_ref(
        method(:HandleResolverData),
        "symbol (string, map)"
      ),
      "validate_type"     => :function,
      "validate_function" => fun_ref(
        method(:ValidateSearchList),
        "boolean (string, map)"
      )
    }
  }

  Ops.set(
    @widget_descr_dns,
    "NAMESERVER_2",
    Ops.get(@widget_descr_dns, "NAMESERVER_1", {})
  )
  Ops.set(
    @widget_descr_dns,
    "NAMESERVER_3",
    Ops.get(@widget_descr_dns, "NAMESERVER_1", {})
  )
  Ops.set(@widget_descr_dns, ["NAMESERVER_2", "label"], _("Name Server &2"))
  Ops.set(@widget_descr_dns, ["NAMESERVER_3", "label"], _("Name Server &3"))

  @dns_contents = VBox(
    VBox(
      HBox(
        "HOSTNAME",
        "HOSTNAME_GLOBAL" # global help, init, store for all dialog
      ),
      VSpacing(0.49),
      VBox(
        Left("DHCP_HOSTNAME")
      )
    ),
    VSpacing(1),
    Left(HBox("MODIFY_RESOLV", HSpacing(1), "PLAIN_POLICY")),
    MarginBox(
      0.49,
      0.49,
      Frame(
        _("Name Servers and Domain Search List"),
        VBox(
          VSquash(
            HBox(
              HWeight(1, VBox("NAMESERVER_1", "NAMESERVER_2", "NAMESERVER_3")),
              HSpacing(1),
              HWeight(1, "SEARCHLIST_S")
            )
          )
        )
      )
    ),
    VStretch()
  )

  @dns_td = {
    "resolv" => {
      "header"       => _("Hostname/DNS"),
      "contents"     => @dns_contents,
      "widget_names" => [
        "HOSTNAME",
        "HOSTNAME_GLOBAL",
        "DOMAIN",
        "DHCP_HOSTNAME",
        "MODIFY_RESOLV",
        "PLAIN_POLICY",
        "NAMESERVER_1",
        "NAMESERVER_2",
        "NAMESERVER_3",
        "SEARCHLIST_S"
      ]
    }
  }
end

#initModifyResolvPolicy(_key) ⇒ Object



564
565
566
567
568
569
570
571
572
573
574
575
# File 'src/include/network/services/dns.rb', line 564

def initModifyResolvPolicy(_key)
  Builtins.y2milestone("initModifyResolvPolicy")

  # first initialize correctly
  default = modify_resolv_default

  UI.ChangeWidget(Id("MODIFY_RESOLV"), :Value, default)
  # then disable if needed
  disable_unconfigureable_items(["MODIFY_RESOLV"], false)

  nil
end

#initPolicy(_key) ⇒ Object



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'src/include/network/services/dns.rb', line 518

def initPolicy(_key)
  # first initialize correctly
  Builtins.y2milestone(
    "initPolicy: %1",
    UI.QueryWidget(Id("MODIFY_RESOLV"), :Value)
  )
  if UI.QueryWidget(Id("MODIFY_RESOLV"), :Value) == :custom
    UI.ChangeWidget(Id("PLAIN_POLICY"), :Enabled, true)
    if UI.QueryWidget(Id("PLAIN_POLICY"), :Value) == ""
      UI.ChangeWidget(Id("PLAIN_POLICY"), :Value, DNS.resolv_conf_policy)
    end
  else
    UI.ChangeWidget(Id("PLAIN_POLICY"), :Value, "")
    UI.ChangeWidget(Id("PLAIN_POLICY"), :Enabled, false)
  end
  # then disable if needed
  disable_unconfigureable_items(["PLAIN_POLICY"], false)

  nil
end

#InitSettingsObject

Returns initial settings for this dialog in one map, from DNS::.

Returns:

  • initial settings for this dialog in one map, from DNS::



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'src/include/network/services/dns.rb', line 240

def InitSettings
  settings = {
    "HOSTNAME"     => DNS.hostname,
    "PLAIN_POLICY" => DNS.resolv_conf_policy
  }
  # the rest is not so straightforward,
  # because we have list variables but non-list widgets

  # domain search
  searchstring = Builtins.mergestring(DNS.searchlist, "\n")
  # #49094: populate the search list
  # #437759: discard 'site', nobody really wants that pre-set
  if searchstring == "" && Ops.get_string(settings, "DOMAIN", "") != "site"
    searchstring = Ops.get_string(settings, "DOMAIN", "")
  end
  Ops.set(settings, "SEARCHLIST_S", searchstring)
  Ops.set(settings, "NAMESERVER_1", DNS.nameservers[0].to_s)
  Ops.set(settings, "NAMESERVER_2", DNS.nameservers[1].to_s)
  Ops.set(settings, "NAMESERVER_3", DNS.nameservers[2].to_s)

  @settings_orig = deep_copy(settings)

  deep_copy(settings)
end

#modify_resolv_defaultObject



554
555
556
557
558
559
560
561
562
# File 'src/include/network/services/dns.rb', line 554

def modify_resolv_default
  if DNS.resolv_conf_policy.nil? || DNS.resolv_conf_policy == ""
    Id(:nomodify)
  elsif DNS.resolv_conf_policy == "auto" || DNS.resolv_conf_policy == "STATIC *"
    Id(:auto)
  else
    Id(:custom)
  end
end

#NonEmpty(l) ⇒ Object

Returns only non-empty items.

Parameters:

  • l (Array<String>)

    list of strings

Returns:

  • only non-empty items



234
235
236
237
# File 'src/include/network/services/dns.rb', line 234

def NonEmpty(l)
  l = deep_copy(l)
  Builtins.filter(l) { |s| s != "" }
end

#SetHnItem(key, value) ⇒ Object

Function for updating actual hostname settings.

Parameters:

  • key (String)

    for known keys see hn_settings

  • value (Object)

    value for particular hn_settings key



352
353
354
355
356
357
358
359
360
361
362
# File 'src/include/network/services/dns.rb', line 352

def SetHnItem(key, value)
  Builtins.y2milestone(
    "hn_settings[ \"%1\"] changes '%2' -> '%3'",
    key,
    @hn_settings[key].to_s,
    value
  )
  @hn_settings[key] = value

  nil
end

#SetHostname(value) ⇒ Object

Function for updating actual hostname.



365
366
367
368
369
370
# File 'src/include/network/services/dns.rb', line 365

def SetHostname(value)
  value = deep_copy(value)
  SetHnItem("HOSTNAME", value)

  nil
end

#SetNameserver1(value) ⇒ Object

Function for updating ip address of first nameserver.



373
374
375
376
377
378
# File 'src/include/network/services/dns.rb', line 373

def SetNameserver1(value)
  value = deep_copy(value)
  SetHnItem("NAMESERVER_1", value)

  nil
end

#SetNameserver2(value) ⇒ Object

Function for updating ip address of second nameserver.



381
382
383
384
385
386
# File 'src/include/network/services/dns.rb', line 381

def SetNameserver2(value)
  value = deep_copy(value)
  SetHnItem("NAMESERVER_2", value)

  nil
end

#SetNameserver3(value) ⇒ Object

Function for updating ip address of third nameserver.



389
390
391
392
393
394
# File 'src/include/network/services/dns.rb', line 389

def SetNameserver3(value)
  value = deep_copy(value)
  SetHnItem("NAMESERVER_3", value)

  nil
end

#store_hostname(value) ⇒ String

Stores user's input from hostname field

Parameters:

  • value (String)

Returns:

  • (String)

    stored hostname



269
270
271
272
273
274
275
# File 'src/include/network/services/dns.rb', line 269

def store_hostname(value)
  hostname = config.hostname
  hostname.static = value
  hostname.installer = value if Stage.initial

  value
end

#StoreDhcpHostname(_key, _event) ⇒ Object

Store handler for DHCP_HOSTNAME



458
459
460
461
462
463
464
# File 'src/include/network/services/dns.rb', line 458

def StoreDhcpHostname(_key, _event)
  return if !UI.QueryWidget(Id("DHCP_HOSTNAME"), :Enabled)

  DNS.dhcp_hostname = UI.QueryWidget(Id("DHCP_HOSTNAME"), :Value)

  nil
end

#StoreHnSettingsObject

Stores actual hostname settings.



336
337
338
339
340
# File 'src/include/network/services/dns.rb', line 336

def StoreHnSettings
  StoreSettings(@hn_settings)

  nil
end

#StoreHnWidget(key, _event) ⇒ Object

Default function to store the value of a widget.

Parameters:

  • key (String)

    id of the widget

  • _event (Hash)

    the event being handled



409
410
411
412
413
414
# File 'src/include/network/services/dns.rb', line 409

def StoreHnWidget(key, _event)
  value = UI.QueryWidget(Id(key), :Value)
  SetHnItem(key, value)

  nil
end

#storeHostnameGlobal(_key, event) ⇒ Object

Used in GUI mode - updates and stores actuall hostname settings according dialog widgets content. It calls store handler for every widget from hn_settings with event as an option.

Parameters:

  • _key (String)

    ignored

  • event (Hash)

    user generated event



620
621
622
623
624
625
626
627
628
# File 'src/include/network/services/dns.rb', line 620

def storeHostnameGlobal(_key, event)
  @hn_settings.each_key do |key2|
    StoreHnWidget(key2, event) if UI.QueryWidget(Id(key2), :Enabled)
  end

  StoreHnSettings()

  nil
end

#StoreSettings(settings) ⇒ Object

Parameters:

  • settings (Hash)

    map of settings to be stored to DNS::



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'src/include/network/services/dns.rb', line 278

def StoreSettings(settings)
  settings = deep_copy(settings)
  nameservers = [
    Ops.get_string(settings, "NAMESERVER_1", ""),
    Ops.get_string(settings, "NAMESERVER_2", ""),
    Ops.get_string(settings, "NAMESERVER_3", "")
  ]
  searchlist = Builtins.splitstring(
    Ops.get_string(settings, "SEARCHLIST_S", ""),
    " ,\n\t"
  )

  hostname = settings["HOSTNAME"] || ""
  update_hostname_hosts(hostname)
  store_hostname(hostname)

  valid_nameservers = NonEmpty(nameservers).each_with_object([]) do |ip_str, all|
    all << IPAddr.new(ip_str) if IP.Check(ip_str)
  end
  DNS.nameservers = valid_nameservers
  DNS.searchlist = NonEmpty(searchlist)
  DNS.resolv_conf_policy = settings["PLAIN_POLICY"]

  nil
end

#update_hostname_hosts(hostname) ⇒ Object

Allow to update a connection hostname using the new hostname when the connection hostname was the modified hostname

Parameters:

  • hostname (String)

    New static hostname



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'src/include/network/services/dns.rb', line 315

def update_hostname_hosts(hostname)
  return false if hostname == current_hostname
  return false if current_hostname.empty?

  conn = config.connections.find { |c| c.hostnames&.include?(current_hostname) }
  return false if !conn

  proposed_hostname = propose_hostname_for(conn, hostname)

  return false if !Popup.YesNo(
    wrap_text(
      format(_("The interface '%s' static IP address is mapped to the hostname '%s'.\n\n" \
               "Would you like to adapt it to '%s'?"),
        conn.name, current_hostname, proposed_hostname)
    )
  )

  conn.hostname = proposed_hostname
end

#use_dhcp_hostname?Boolean

Checks whether setting hostname via DHCP is allowed

Returns:

  • (Boolean)


421
422
423
# File 'src/include/network/services/dns.rb', line 421

def use_dhcp_hostname?
  UI.QueryWidget(Id("DHCP_HOSTNAME"), :Value) != NONE_LABEL
end

#ValidateHostname(key, _event) ⇒ Boolean

Validator for hostname, no_popup

Parameters:

  • key (String)

    the widget being validated

  • _event (Hash)

    the event being handled

Returns:

  • (Boolean)

    whether the current static hostname is valid or not



484
485
486
487
488
489
490
# File 'src/include/network/services/dns.rb', line 484

def ValidateHostname(key, _event)
  value = UI.QueryWidget(Id(key), :Value).to_s

  # 1) empty hostname is allowed - /etc/hostname gets cleared in such case
  # 2) FQDN is allowed
  value.empty? || Hostname.Check(value.tr(".", ""))
end

#ValidateSearchList(key, _event) ⇒ Object

Validator for the search list

Parameters:

  • key (String)

    the widget being validated

  • _event (Hash)

    the event being handled

Returns:

  • whether valid



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'src/include/network/services/dns.rb', line 496

def ValidateSearchList(key, _event)
  value = Convert.to_string(UI.QueryWidget(Id(key), :Value))
  sl = NonEmpty(Builtins.splitstring(value, " ,\n\t"))
  error = ""

  sl.each do |s|
    next if Hostname.CheckDomain(s)

    # TRANSLATORS: Popup::Error text
    error = Builtins.sformat(_("The search domain '%1' is invalid."), s) +
      "\n" + Hostname.ValidDomain
    break
  end

  if error != ""
    UI.SetFocus(Id(key))
    Popup.Error(error)
    return false
  end
  true
end