Module: Yast::DhcpServerDnsServerDialogsInclude

Defined in:
../../src/include/dhcp-server/dns-server-dialogs.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) AddDNSRangeWorker(domain, hostname_domain, record_type, hostname_base, hostname_start, first_ip, last_ip)



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File '../../src/include/dhcp-server/dns-server-dialogs.rb', line 553

def AddDNSRangeWorker(domain, hostname_domain, record_type, hostname_base, hostname_start, first_ip, last_ip)
  if !Builtins.contains(["A", "PTR"], record_type)
    Builtins.y2error(
      "Record type %1 is not handled by this function",
      record_type
    )
    return false
  end

  if Builtins.regexpmatch(hostname_base, "%i")
    hostname_base = Builtins.regexpsub(
      hostname_base,
      "^(.*)%i(.*)",
      "\\1%1\\2"
    )
  else
    hostname_base = Ops.add(hostname_base, "%1")
  end
  Builtins.y2milestone("Hostname base: %1", hostname_base)

  hostname_start = 0 if hostname_start == nil

  first_ip_list = Builtins.maplist(Builtins.splitstring(first_ip, ".")) do |ip_part|
    Builtins.tointeger(ip_part)
  end
  last_ip_list = Builtins.maplist(Builtins.splitstring(last_ip, ".")) do |ip_part|
    Builtins.tointeger(ip_part)
  end
  Builtins.y2milestone("Creating range: %1 - %2", first_ip, last_ip)

  # list of hostnames for next punycode translation
  hostnames = []
  # list of IPs matching these hostnames (by index)
  ips = []

  hostname_counter = Ops.subtract(hostname_start, 1)
  index_counter = -1

  # for counting max numbers
  to_2 = nil
  to_3 = nil
  to_4 = nil

  # Generating hostnames and IPs
  while Ops.less_or_equal(
      Ops.get(first_ip_list, 0, 1),
      Ops.get(last_ip_list, 0, 0)
    )
    # Range (1).1.1.1 -> (2).1.1.1
    #           contains (1).254.254.254
    if Ops.less_than(
        Ops.get(first_ip_list, 0, 1),
        Ops.get(last_ip_list, 0, 0)
      )
      to_2 = 254
    else
      to_2 = Ops.get(last_ip_list, 1, 0)
    end
    while Ops.less_or_equal(Ops.get(first_ip_list, 1, 1), to_2)
      # Range 1.(1).1.1 -> 1.(2).1.1
      #           contains 1.(1).254.254
      if Ops.less_than(
          Ops.get(first_ip_list, 1, 1),
          Ops.get(last_ip_list, 1, 0)
        )
        to_3 = 254
      else
        to_3 = Ops.get(last_ip_list, 2, 0)
      end
      while Ops.less_or_equal(Ops.get(first_ip_list, 2, 1), to_3)
        # Range 1.1.(1).1 -> 1.1.(2).1
        #           contains 1.1.(1).254
        if Ops.less_than(
            Ops.get(first_ip_list, 2, 1),
            Ops.get(last_ip_list, 2, 0)
          )
          to_4 = 254
        else
          to_4 = Ops.get(last_ip_list, 3, 0)
        end
        while Ops.less_or_equal(Ops.get(first_ip_list, 3, 1), to_4)
          # 0 at the end of IP address means network
          # skip it!
          if Ops.get(first_ip_list, 3) == 0
            Builtins.y2milestone("Skipping %1", first_ip_list)
            Ops.set(
              first_ip_list,
              3,
              Ops.add(Ops.get(first_ip_list, 3, 0), 1)
            )
            next
          end

          hostname_counter = Ops.add(hostname_counter, 1)
          index_counter = Ops.add(index_counter, 1)

          Ops.set(
            hostnames,
            index_counter,
            Builtins.sformat(hostname_base, hostname_counter)
          )

          if record_type == "A"
            Ops.set(
              ips,
              index_counter,
              Builtins.sformat(
                "%1.%2.%3.%4",
                Ops.get(first_ip_list, 0, 0),
                Ops.get(first_ip_list, 1, 0),
                Ops.get(first_ip_list, 2, 0),
                Ops.get(first_ip_list, 3, 0)
              )
            )
          elsif record_type == "PTR"
            Ops.set(
              ips,
              index_counter,
              Builtins.sformat(
                "%1.%2.%3.%4.in-addr.arpa.",
                Ops.get(first_ip_list, 3, 0),
                Ops.get(first_ip_list, 2, 0),
                Ops.get(first_ip_list, 1, 0),
                Ops.get(first_ip_list, 0, 0)
              )
            )
          end
          Ops.set(
            first_ip_list,
            3,
            Ops.add(Ops.get(first_ip_list, 3, 0), 1)
          )
        end
        Ops.set(first_ip_list, 2, Ops.add(Ops.get(first_ip_list, 2, 0), 1))
        Ops.set(first_ip_list, 3, 0)
      end
      Ops.set(first_ip_list, 1, Ops.add(Ops.get(first_ip_list, 1, 0), 1))
      Ops.set(first_ip_list, 2, 0)
    end
    Ops.set(first_ip_list, 1, 0)
    Ops.set(first_ip_list, 0, Ops.add(Ops.get(first_ip_list, 0, 0), 1))
  end

  # Writing records into the DNS Server
  if Ops.greater_than(hostname_counter, 0)
    hostnames = Punycode.EncodePunycodes(hostnames)

    index_counter = -1
    Builtins.foreach(hostnames) do |one_hostname|
      index_counter = Ops.add(index_counter, 1)
      if record_type == "A"
        DnsServerAPI.AddZoneRR(
          domain,
          "A",
          one_hostname,
          Ops.get(ips, index_counter, "")
        )
      elsif record_type == "PTR"
        DnsServerAPI.AddZoneRR(
          domain,
          "PTR",
          Ops.get(ips, index_counter, ""),
          Ops.add(Ops.add(Ops.add(one_hostname, "."), hostname_domain), ".")
        )
      end
    end
  end

  true
end

- (Object) CheckDNSRange(first_ip, last_ip, current_d_settings)



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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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/include/dhcp-server/dns-server-dialogs.rb', line 144

def CheckDNSRange(first_ip, last_ip, current_d_settings)
  # range in binary form
  first_ip_bin = IP.IPv4ToBits(first_ip)
  last_ip_bin = IP.IPv4ToBits(last_ip)

  # they have to be defined
  if first_ip_bin == nil || last_ip_bin == nil
    Report.Error(
      Builtins.sformat(
        # TRANSLATORS: popup error, %1 is the first IP of the range, %2 is the last one
        _("Internal error.\nCannot create IP range from %1 and %2."),
        first_ip,
        last_ip
      )
    )
    return false
  end

  # network mask in binary form
  bits = Builtins.tointeger(
    Ops.get(current_d_settings.value, "netmask_bits")
  )
  network_bits = Ops.get(current_d_settings.value, "network_binary")
  # first x bits from network in binary form
  network_bits = Builtins.substring(network_bits, 0, bits)
  Builtins.y2milestone("Network Mask: %1", network_bits)

  # doest the first IP match the current network?
  first_ip_mask = Builtins.substring(first_ip_bin, 0, bits)
  # network bits must be the same in both IP and Network
  if first_ip_mask != network_bits
    Report.Error(
      # TRANSLATORS: popup error, %1 is an IP address
      # %2 is a network, %3 is a netmask
      Builtins.sformat(
        _("IP address %1 does not match\nthe current network %2/%3.\n"),
        first_ip,
        Ops.get(current_d_settings.value, "network", ""),
        Ops.get(current_d_settings.value, "netmask", "")
      )
    )
    UI.SetFocus(Id("first_ip"))
    return false
  end

  # does the second IP match the current network?
  last_ip_mask = Builtins.substring(last_ip_bin, 0, bits)
  # network bits must be the same in both IP and Network
  if last_ip_mask != network_bits
    Report.Error(
      Builtins.sformat(
        _("IP address %1 does not match\nthe current network %2/%3.\n"),
        last_ip,
        Ops.get(current_d_settings.value, "network", ""),
        Ops.get(current_d_settings.value, "netmask", "")
      )
    )
    UI.SetFocus(Id("last_ip"))
    return false
  end

  # the Address part of IPs
  first_ip_bin = Builtins.substring(first_ip_bin, bits)
  last_ip_bin = Builtins.substring(last_ip_bin, bits)
  Builtins.y2milestone("First IP: %1", first_ip_bin)
  Builtins.y2milestone("Last IP:  %1", last_ip_bin)

  # the Address part of the DHCP range
  fist_ip_dhcp = IP.IPv4ToBits(
    Ops.get(current_d_settings.value, "from_ip", "")
  )
  last_ip_dhcp = IP.IPv4ToBits(
    Ops.get(current_d_settings.value, "to_ip", "")
  )
  fist_ip_dhcp = Builtins.substring(fist_ip_dhcp, bits)
  last_ip_dhcp = Builtins.substring(last_ip_dhcp, bits)

  # isn't the first IP bigger than the last one?
  if Ops.greater_than(
      Builtins.tointeger(first_ip_bin),
      Builtins.tointeger(last_ip_bin)
    )
    # TRANSLATORS: popup error
    Report.Error(
      _("The last IP address must be higher than the first one.")
    )
    return false
  end

  # isn't the first IP out of the current DHCP range?
  if Ops.less_than(
      Builtins.tointeger(first_ip_bin),
      Builtins.tointeger(fist_ip_dhcp)
    ) ||
      Ops.greater_than(
        Builtins.tointeger(fist_ip_dhcp),
        Builtins.tointeger(last_ip_dhcp)
      )
    Report.Error(
      Builtins.sformat(
        # TRANSLATORS: popup error, %1 an IP address
        # %2 is the first IP address of the range, %3 is the last one
        _(
          "The IP address %1 is\n" +
            "outside the current\n" +
            "dynamic DHCP range %2-%3.\n"
        ),
        first_ip,
        Ops.get(current_d_settings.value, "from_ip", ""),
        Ops.get(current_d_settings.value, "to_ip", "")
      )
    )
    return false
  end

  # isn't the last IP out of the current DHCP range?
  if Ops.less_than(
      Builtins.tointeger(last_ip_bin),
      Builtins.tointeger(fist_ip_dhcp)
    ) ||
      Ops.greater_than(
        Builtins.tointeger(last_ip_dhcp),
        Builtins.tointeger(last_ip_dhcp)
      )
    Report.Error(
      Builtins.sformat(
        # TRANSLATORS: popup error, %1 an IP address
        # %2 is the first IP address of the range, %3 is the last one
        _(
          "The IP address %1 is\n" +
            "outside the current\n" +
            "dynamic DHCP range %2-%3.\n"
        ),
        last_ip,
        Ops.get(current_d_settings.value, "from_ip", ""),
        Ops.get(current_d_settings.value, "to_ip", "")
      )
    )
    return false
  end

  true
end

- (Object) CreateUI_DNSRangeDialog(range_min, range_max, old_range)



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
# File '../../src/include/dhcp-server/dns-server-dialogs.rb', line 55

def CreateUI_DNSRangeDialog(range_min, range_max, old_range)
  old_range = deep_copy(old_range)
  # old_range: $[
  #     "base"  : "dhcp-%",
  #     "start" : 0,
  #     "from"  : "192.168.10.1",
  #     "to"    : "192.168.10.100"
  # ]

  # TRANSLATORS: dialog caption
  dialog_caption = _("Add New DNS Record Range")
  if old_range != {} && old_range != nil
    # TRANSLATORS: dialog caption
    dialog_caption = _("Edit DNS Record Range")
  end

  UI.OpenDialog(
    VBox(
      MarginBox(
        1,
        1,
        Frame(
          dialog_caption,
          VBox(
            HBox(
              # TRANSLATORS: text entry
              TextEntry(Id("current_range_min"), _("Min&imum IP Address")),
              # TRANSLATORS: text entry
              TextEntry(Id("current_range_max"), _("Ma&ximum IP Address"))
            ),
            HBox(
              # TRANSLATORS: text entry
              TextEntry(Id("hostname_base"), _("&Hostname Base")),
              # TRANSLATORS: text entry
              TextEntry(Id("hostname_start"), _("&Start"))
            ),
            HBox(
              # TRANSLATORS: text entry
              TextEntry(Id("first_ip"), _("&First IP Address")),
              # TRANSLATORS: text entry
              TextEntry(Id("last_ip"), _("&Last IP Address"))
            )
          )
        )
      ),
      ButtonBox(
        PushButton(Id(:ok), Label.OKButton),
        PushButton(Id(:cancel), Label.CancelButton)
      )
    )
  )

  UI.ChangeWidget(Id("current_range_min"), :Value, range_min)
  UI.ChangeWidget(Id("current_range_max"), :Value, range_max)

  # FIXME: default
  UI.ChangeWidget(
    Id("hostname_base"),
    :Value,
    Ops.get_string(old_range, "base", "dhcp-%i")
  )
  UI.ChangeWidget(
    Id("hostname_start"),
    :Value,
    Builtins.tostring(Ops.get_integer(old_range, "start", 1))
  )

  UI.ChangeWidget(Id("current_range_min"), :Enabled, false)
  UI.ChangeWidget(Id("current_range_max"), :Enabled, false)

  UI.ChangeWidget(Id("first_ip"), :ValidChars, IP.ValidChars4)
  UI.ChangeWidget(Id("last_ip"), :ValidChars, IP.ValidChars4)
  UI.ChangeWidget(Id("hostname_start"), :ValidChars, "0123456789")

  # Predefining possible values
  UI.ChangeWidget(
    Id("first_ip"),
    :Value,
    Ops.get_string(old_range, "from", range_min)
  )
  UI.ChangeWidget(
    Id("last_ip"),
    :Value,
    Ops.get_string(old_range, "to", range_max)
  )

  nil
end

- (Object) initialize_dhcp_server_dns_server_dialogs(include_target)



11
12
13
14
15
16
17
18
19
20
21
22
# File '../../src/include/dhcp-server/dns-server-dialogs.rb', line 11

def initialize_dhcp_server_dns_server_dialogs(include_target)
  Yast.import "UI"

  textdomain "dhcp-server"

  Yast.import "IP"
  Yast.import "Label"
  Yast.import "Report"
  Yast.import "Punycode"
  Yast.import "Hostname"
  Yast.import "DnsServerAPI"
end

- (Object) IPisInRangeOfIPs(ipv4, first_ip, last_ip)



288
289
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
323
324
325
326
327
328
329
330
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File '../../src/include/dhcp-server/dns-server-dialogs.rb', line 288

def IPisInRangeOfIPs(ipv4, first_ip, last_ip)
  # Checking delta between first_ip and last_ip
  ipv4_list = Builtins.maplist(Builtins.splitstring(ipv4, ".")) do |ip_part|
    Builtins.tointeger(ip_part)
  end
  first_ip_list = Builtins.maplist(Builtins.splitstring(first_ip, ".")) do |ip_part|
    Builtins.tointeger(ip_part)
  end
  last_ip_list = Builtins.maplist(Builtins.splitstring(last_ip, ".")) do |ip_part|
    Builtins.tointeger(ip_part)
  end

  # Computing deltas
  # 195(.168.0.1) - 192(.11.0.58) => 3
  address_1_1 = Ops.subtract(
    Ops.get(ipv4_list, 0, 0),
    Ops.get(first_ip_list, 0, 0)
  )
  address_1_2 = Ops.subtract(
    Ops.get(ipv4_list, 1, 0),
    Ops.get(first_ip_list, 1, 0)
  )
  address_1_3 = Ops.subtract(
    Ops.get(ipv4_list, 2, 0),
    Ops.get(first_ip_list, 2, 0)
  )
  address_1_4 = Ops.subtract(
    Ops.get(ipv4_list, 3, 0),
    Ops.get(first_ip_list, 3, 0)
  )

  address_2_1 = Ops.subtract(
    Ops.get(last_ip_list, 0, 0),
    Ops.get(ipv4_list, 0, 0)
  )
  address_2_2 = Ops.subtract(
    Ops.get(last_ip_list, 1, 0),
    Ops.get(ipv4_list, 1, 0)
  )
  address_2_3 = Ops.subtract(
    Ops.get(last_ip_list, 2, 0),
    Ops.get(ipv4_list, 2, 0)
  )
  address_2_4 = Ops.subtract(
    Ops.get(last_ip_list, 3, 0),
    Ops.get(ipv4_list, 3, 0)
  )

  range_status = nil

  # Firstly, checking the IPv4 and the first address in the range
  # IPv4 must be bigger or equal to it
  if ipv4 == first_ip
    range_status = true 

    # first chunk is either smaller or bigger than zero
  elsif Ops.less_than(address_1_1, 0) || Ops.greater_than(address_1_1, 0)
    # bigger means that the IP range is correct
    range_status = Ops.greater_than(address_1_1, 0) 

    # if they are equal, check the very next chunk...
  elsif Ops.less_than(address_1_2, 0) || Ops.greater_than(address_1_2, 0)
    range_status = Ops.greater_than(address_1_2, 0)
  elsif Ops.less_than(address_1_3, 0) || Ops.greater_than(address_1_3, 0)
    range_status = Ops.greater_than(address_1_3, 0)
  elsif Ops.less_than(address_1_4, 0) || Ops.greater_than(address_1_4, 0)
    range_status = Ops.greater_than(address_1_4, 0) 

    # what else?
  else
    Builtins.y2error(
      "Unknown match IP: %1 First: %2",
      ipv4_list,
      first_ip_list
    )
    range_status = false
  end

  # First checking didn't match
  return false if !range_status

  # Secondly, checking the IPv4 and the last address in the range
  # IPv4 must be smaller or equal to it
  if ipv4 == last_ip
    range_status = true 

    # first chunk is either smaller or bigger than zero
  elsif Ops.less_than(address_2_1, 0) || Ops.greater_than(address_2_1, 0)
    # bigger means that the IP range is correct
    range_status = Ops.greater_than(address_2_1, 0) 

    # if they are equal, check the very next chunk...
  elsif Ops.less_than(address_2_2, 0) || Ops.greater_than(address_2_2, 0)
    range_status = Ops.greater_than(address_2_2, 0)
  elsif Ops.less_than(address_2_3, 0) || Ops.greater_than(address_2_3, 0)
    range_status = Ops.greater_than(address_2_3, 0)
  elsif Ops.less_than(address_2_4, 0) || Ops.greater_than(address_2_4, 0)
    range_status = Ops.greater_than(address_2_4, 0) 

    # what else?
  else
    Builtins.y2error(
      "Unknown match IP: %1 Last: %2",
      ipv4_list,
      last_ip_list
    )
    range_status = false
  end

  range_status
end

- (Object) IsDNSZoneMaintained(zone_name)



24
25
26
27
28
29
30
31
32
33
34
# File '../../src/include/dhcp-server/dns-server-dialogs.rb', line 24

def IsDNSZoneMaintained(zone_name)
  if zone_name == nil
    Builtins.y2error("Undefined zone name")
    return nil
  end

  all_zones = DnsServerAPI.GetZones

  # found or not?
  Ops.get(all_zones, zone_name) == nil
end

- (Object) IsDNSZoneMaster(zone_name)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File '../../src/include/dhcp-server/dns-server-dialogs.rb', line 36

def IsDNSZoneMaster(zone_name)
  if zone_name == nil
    Builtins.y2error("Undefined zone name")
    return nil
  end

  all_zones = DnsServerAPI.GetZones

  # if zone not found
  ret = nil

  # is master or not?
  if Ops.get(all_zones, zone_name) != nil
    ret = Ops.get(all_zones, [zone_name, "type"]) == "master"
  end

  ret
end

- (Object) ValidateAddDNSRangeDialog(current_d_settings)



400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File '../../src/include/dhcp-server/dns-server-dialogs.rb', line 400

def ValidateAddDNSRangeDialog(current_d_settings)
  ret = nil

  hostname_base = Convert.to_string(
    UI.QueryWidget(Id("hostname_base"), :Value)
  )
  Builtins.y2milestone("Entered hostname base: %1", hostname_base)

  # checking number of '%i' in the hostname base
  nr_hostname_base = hostname_base
  i_count = 0
  while Builtins.regexpmatch(nr_hostname_base, "%i")
    i_count = Ops.add(i_count, 1)
    nr_hostname_base = Builtins.regexpsub(
      nr_hostname_base,
      "(.*)%i(.*)",
      "\\1--\\2"
    )
  end
  if Ops.greater_than(i_count, 1)
    Report.Error(
      # TRANSLATORS: popup error '%i' is a special string, do not translate it, please
      _("There can be only one '%i' in the hostname base string.")
    )
    return nil
  end
  nr_hostname_base = nil

  hostname_base_check = hostname_base
  if hostname_base_check != "" && hostname_base_check != nil
    # integer listed
    if Builtins.regexpmatch(hostname_base_check, "%i")
      hostname_base_check = Builtins.regexpsub(
        hostname_base_check,
        "^(.*)%i(.*)",
        "\\10\\2"
      ) 
      # add something
    else
      hostname_base_check = Ops.add(hostname_base_check, "0")
    end

    hostname_base_check = Punycode.EncodeDomainName(hostname_base_check)
  end

  Builtins.y2milestone("Checking hostname base: %1", hostname_base_check)

  # Checking the hostname base
  if hostname_base_check == "" || hostname_base_check == nil ||
      !Hostname.Check(hostname_base_check)
    UI.SetFocus(Id("hostname_base"))
    # TRANSLATORS: popup error, followed by a newline and a valid hostname description
    Report.Error(
      Ops.add(_("Invalid hostname.") + "\n\n", Hostname.ValidHost)
    )
    return nil
  end

  first_ip = Convert.to_string(UI.QueryWidget(Id("first_ip"), :Value))
  if !IP.Check4(first_ip)
    UI.SetFocus(Id("first_ip"))
    # TRANSLATORS: popup error, followed by a newline and a valid IPv4 description
    Report.Error(Ops.add(_("Invalid IP address.") + "\n\n", IP.Valid4))
    return nil
  end

  if !IPisInRangeOfIPs(
      first_ip,
      Ops.get(current_d_settings.value, "ipv4_min", ""),
      Ops.get(current_d_settings.value, "ipv4_max", "")
    )
    Report.Error(
      Builtins.sformat(
        # TRANSLATORS: popup error, %1 is an IP address
        # %2 is the first IP address of the range, %3 is the last one
        _(
          "IP address %1 is not in the range of allowed\nIP addresses (%2-%3) defined in the DHCP server.\n"
        ),
        first_ip,
        Ops.get(current_d_settings.value, "ipv4_min", ""),
        Ops.get(current_d_settings.value, "ipv4_max", "")
      )
    )
    return nil
  end

  last_ip = Convert.to_string(UI.QueryWidget(Id("last_ip"), :Value))
  if !IP.Check4(last_ip)
    UI.SetFocus(Id("last_ip"))
    # TRANSLATORS: popup error, followed by a newline and a valid IPv4 description
    Report.Error(Ops.add(_("Invalid IP address.") + "\n\n", IP.Valid4))
    return nil
  end

  if !IPisInRangeOfIPs(
      last_ip,
      Ops.get(current_d_settings.value, "ipv4_min", ""),
      Ops.get(current_d_settings.value, "ipv4_max", "")
    )
    Report.Error(
      Builtins.sformat(
        # TRANSLATORS: popup error, %1 is an IP address
        # %2 is the first IP address of the range, %3 is the last one
        _(
          "IP address %1 is not in the range of allowed\nIP addresses (%2-%3) defined in the DHCP server.\n"
        ),
        first_ip,
        Ops.get(current_d_settings.value, "ipv4_min", ""),
        Ops.get(current_d_settings.value, "ipv4_max", "")
      )
    )
    return nil
  end

  hostname_start_s = Convert.to_string(
    UI.QueryWidget(Id("hostname_start"), :Value)
  )
  hostname_start = 0
  if Builtins.regexpmatch(hostname_start_s, "^[0123456789]+$")
    hostname_start = Builtins.tointeger(hostname_start_s)
  end

  if !(
      current_d_settings_ref = arg_ref(current_d_settings.value);
      _CheckDNSRange_result = CheckDNSRange(
        first_ip,
        last_ip,
        current_d_settings_ref
      );
      current_d_settings.value = current_d_settings_ref.value;
      _CheckDNSRange_result
    )
    return nil
  end

  ret = {
    "hostname_base"  => hostname_base,
    "hostname_start" => hostname_start,
    "first_ip"       => first_ip,
    "last_ip"        => last_ip
  }

  deep_copy(ret)
end