Module: Yast::DnsServerDialogMasterzoneInclude

Defined in:
../../src/include/dns-server/dialog-masterzone.rb

Defined Under Namespace

Modules: SOADefaults

Constant Summary

MAX_TEXT_RECORD_LENGTH =
255

Instance Method Summary (collapse)

Instance Method Details

- (Object) AdjustEditationWidgets(current_record, decoded_zone_name, zone_name)



1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1443

def AdjustEditationWidgets(current_record, decoded_zone_name, zone_name)
  current_record = deep_copy(current_record)
  current_type = Ops.get_string(current_record, "type", "A")

  current_key = Ops.get_string(current_record, "key", "")
  current_val = Ops.get_string(current_record, "value", "")

  current_service = ""
  current_protocol = ""

  current_prio = 0
  current_weight = 0
  current_port = 0

  case current_type
    when "SRV"
      if Builtins.regexpmatch(current_key, "^_[^_]+\\._[^_]+\\.?")
        current_service = Builtins.regexpsub(
          current_key,
          "^(_[^_]+)\\._[^_]+\\.?.*",
          "\\1"
        )
        current_protocol = Builtins.regexpsub(
          current_key,
          "^_[^_]+\\.(_[^\\.]+)\\.?.*",
          "\\1"
        )
        current_key = Builtins.regexpsub(
          current_key,
          "^_[^_]+\\._[^\\.]+\\.?(.*)$",
          "\\1"
        )

        # not to show an empty string
        current_key = Ops.add(zone_name.value, ".") if current_key == ""
      elsif current_key != "" && Builtins.regexpmatch(current_key, "[ \\t]")
        Builtins.y2error("Invalid record key: %1", current_key)
      end

      UI.ChangeWidget(Id("add_record_service"), :Value, current_service)
      UI.ChangeWidget(Id("add_record_protocol"), :Value, current_protocol)

      if Builtins.regexpmatch(
          current_val,
          "^[0-9]+[ \\t]+[0-9]+[ \\t]+[0-9]+.*"
        )
        current_prio = Builtins.tointeger(
          Builtins.regexpsub(
            current_val,
            "^([0-9]+)[ \\t]+[0-9]+[ \\t]+[0-9]+.*$",
            "\\1"
          )
        )
        current_weight = Builtins.tointeger(
          Builtins.regexpsub(
            current_val,
            "^[0-9]+[ \\t]+([0-9]+)[ \\t]+[0-9]+.*$",
            "\\1"
          )
        )
        current_port = Builtins.tointeger(
          Builtins.regexpsub(
            current_val,
            "^[0-9]+[ \\t]+[0-9]+[ \\t]+([0-9]+).*$",
            "\\1"
          )
        )
        current_val = Builtins.regexpsub(
          current_val,
          "^[0-9]+[ \\t]+[0-9]+[ \\t]+[0-9]+[ \\t]+(.*)$",
          "\\1"
        )
      elsif current_val != "" && Builtins.regexpmatch(current_val, "[ \\t]")
        Builtins.y2error("Invalid record val: %1", current_val)
      end

      UI.ChangeWidget(Id("add_record_prio"), :Value, current_prio)
      UI.ChangeWidget(Id("add_record_weight"), :Value, current_weight)
      UI.ChangeWidget(Id("add_record_port"), :Value, current_port)
    when "MX"
      if Builtins.regexpmatch(current_val, "[0-9]+[ \\t]+.*")
        current_prio = Builtins.tointeger(
          Builtins.regexpsub(current_val, "([0-9]+)[ \\t]+.*", "\\1")
        )
        current_val = Builtins.regexpsub(
          current_val,
          "[0-9]+[ \\t]+(.*)",
          "\\1"
        )
      elsif current_val != "" && Builtins.regexpmatch(current_val, "[ \\t]")
        Builtins.y2error("Invalid record val: %1", current_val)
      end

      UI.ChangeWidget(Id("add_record_prio"), :Value, current_prio)
    # "A", "AAAA", "CNAME", "NS", "PTR", "TXT", "SPF"
    else

  end

  # Applies to all
  UI.ChangeWidget(
    Id("add_record_name"),
    :Value,
    DnsServerHelperFunctions.RRToRelativeName(
      Punycode.DecodeDomainName(current_key),
      decoded_zone_name.value,
      current_type,
      "key"
    )
  )
  UI.ChangeWidget(Id("add_record_type"), :Value, current_type)
  UI.ChangeWidget(
    Id("add_record_val"),
    :Value,
    DnsServerHelperFunctions.RRToRelativeName(
      Punycode.DecodeDomainName(current_val),
      decoded_zone_name.value,
      current_type,
      "value"
    )
  )

  nil
end

- (Object) CheckAndModifyRecord(type, key, val)



2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2001

def CheckAndModifyRecord(type, key, val)
  # (SYNTAX) Checking the record by record-type (true or false)
  if CheckNewZoneRecordSyntax(
      { "key" => key.value, "type" => type.value, "val" => val.value }
    ) != true
    return false
  end
  # (LOGIC) Checking the record by record-type (true or false)
  if CheckNewZoneRecordLogic(
      { "key" => key.value, "type" => type.value, "val" => val.value }
    ) != true
    return false
  end

  tolower_type = Builtins.tolower(type.value)

  if tolower_type == nil || tolower_type == ""
    Builtins.y2error("tolover(%1) -> %2", type.value, tolower_type)
    return false
  end

  if tolower_type == "ptr"
    # no dot at the end
    if !Builtins.regexpmatch(val.value, "^.*\\.$")
      # add dot
      val.value = Ops.add(val.value, ".")
    end

    if Builtins.regexpmatch(key.value, "in-addr\\.arpa$") ||
        Builtins.regexpmatch(key.value, "ip6\\.arpa$")
      key.value = Ops.add(key.value, ".")
    end
  elsif Builtins.contains(["a", "cname", "ns", "mx"], tolower_type)
    if tolower_type == "mx"
      if !Builtins.regexpmatch(val.value, "^[ \t]*[0-9]+[ \t]+[^ \t].*$")
        val.value = Ops.add("0 ", val.value)
      else
        prio = Builtins.tointeger(
          Builtins.regexpsub(
            val.value,
            "^[ \t]*([0-9]+)[ \t]+[^ \t].*$",
            "\\1"
          )
        )
        if Ops.greater_than(prio, 65535)
          val.value = Ops.add(
            "65535 ",
            Builtins.regexpsub(
              val.value,
              "^[ \t]*[0-9]+[ \t]+([^ \t].*)$",
              "\\1"
            )
          )
          Builtins.y2milestone(
            "MX Priority decrased to maximal 65535 from %1",
            prio
          )
        end
      end
    end

    if tolower_type == "cname"
      key.value = TransformRecord(key.value)
      val.value = TransformRecord(val.value)
    elsif Builtins.contains(["ns", "mx"], tolower_type)
      val.value = TransformRecord(val.value)
    elsif tolower_type == "a"
      key.value = TransformRecord(key.value)
    end
  end

  true
end

- (Object) CheckNewZoneRecordLogic(record)

Checking new record by the “type”



1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1953

def CheckNewZoneRecordLogic(record)

  type = record['type']
  key  = record['key']
  val  = record['val']

  case type
    when "CNAME"
      # (hostname or FQ -> hostname or FQ)
      if key == val
        UI.SetFocus(Id("add_record_val"))
        # TRANSLATORS: a popup message, CNAME (link) points to itself
        Popup.Error(_("CNAME cannot point to itself."))
        return false
      end
      return true
    when *@supported_records
      # FIXME: A record should point to an IPv4 address
      # FIXME: AAAA record should point to IPv6 address
      # FIXME: NS should point to an A or AAAA record (if it is in the same domain)
      # FIXME: MX should point to an A or AAAA record (if it is in the same domain)
      # FIXME: SRV should point to an A or AAAA record (if it is in the same domain)
      return true
    else
      Builtins.y2error("unknown record type: #{type}")
      return false
  end
end

- (Object) CheckNewZoneRecordSyntax(record)

Checking new record by the “type”



1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1729

def CheckNewZoneRecordSyntax(record)
  record = deep_copy(record)
  # $[ "key" : key, "type" : type, "val" : val ]

  type = Ops.get(record, "type", "")
  key = Ops.get(record, "key", "")
  val = Ops.get(record, "val", "")

  if Builtins.regexpmatch(key, "^.*\\.$")
    key = Builtins.regexpsub(key, "^(.*)\\.$", "\\1")
  end
  if Builtins.regexpmatch(val, "^.*\\.$")
    val = Builtins.regexpsub(val, "^(.*)\\.$", "\\1")
  end

  # -- A -- \\
  if type == "A"
    # (hostname or FQ -> IPv4)
    # BNC #646895: Wildcard '*' not supported as valid hostname
    if Hostname.Check(key) != true && Hostname.CheckFQ(key) != true &&
        key != "*"
      UI.SetFocus(Id("add_record_name"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end
    if IP.Check4(val) != true
      UI.SetFocus(Id("add_record_val"))
      Popup.Error(IP.Valid4)
      return false
    end
    return true 

    # -- CNAME -- \\
  elsif type == "CNAME"
    # (hostname or FQ -> hostname or FQ)
    if Hostname.Check(key) != true && Hostname.CheckFQ(key) != true &&
        key != "*"
      UI.SetFocus(Id("add_record_name"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end
    if Hostname.Check(val) != true && Hostname.CheckFQ(val) != true
      UI.SetFocus(Id("add_record_val"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end
    return true 

    # -- NS -- \\
  elsif type == "NS"
    # (hostname or domain or FQ -> hostname or FQ)
    if Hostname.Check(key) != true && Hostname.CheckDomain(key) != true &&
        Hostname.CheckFQ(key) != true &&
        key != "*"
      UI.SetFocus(Id("add_record_name"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end
    if Hostname.Check(val) != true && Hostname.CheckFQ(val) != true
      UI.SetFocus(Id("add_record_val"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end
    return true 

    # -- MX -- \\
  elsif type == "MX"
    if Builtins.regexpmatch(val, "^[ \t]*[0-9]+[ \t]+[^ \t].*$")
      val = Builtins.regexpsub(val, "^[ \t]*[0-9]+[ \t]+([^ \t].*)$", "\\1") 
      # FIXME: check also priority
    end
    # (hostname or domain or FQ -> hostname or FQ)
    if Hostname.Check(key) != true && Hostname.CheckDomain(key) != true &&
        Hostname.CheckFQ(key) != true &&
        key != "*"
      UI.SetFocus(Id("add_record_name"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end
    if Hostname.Check(val) != true && Hostname.CheckFQ(val) != true
      UI.SetFocus(Id("add_record_val"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end
    return true 

    # -- PTR -- \\
  elsif type == "PTR"
    val = Ops.get(record, "val", "")

    # (hostname or domain or FQ)
    if Hostname.CheckFQ(val) != true || !Builtins.regexpmatch(val, "\\.*$")
      UI.SetFocus(Id("add_record_val"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end

    zone_name = Ops.add(Ops.get_string(@current_zone, "zone", ""), ".")

    # IPv6 reverse zone
    if Builtins.regexpmatch(zone_name, ".*\\.ip6\\.arpa\\.?$")
      key = Ops.get(record, "key", "")

      # relative reverse IPv6
      if !Builtins.regexpmatch(key, "\\.[ \\t]*$")
        key = Ops.add(Ops.add(key, "."), zone_name)
      end
      if !Builtins.regexpmatch(
          key,
          "^[ \\t]*([0-9a-fA-F]\\.){32}ip6\\.arpa\\.[ \\t]*$"
        )
        Builtins.y2error("Wrong reverse IPv6: '%1'", key)
        UI.SetFocus(Id("add_record_name"))
        # Pop-up error message, %1 is replaced with an example
        Popup.Error(
          Builtins.sformat(
            _(
              "Invalid IPv6 reverse IP.\n" +
                "\n" +
                "IPv6 reverse records are supported either in the full form (%1)\n" +
                "or in the relative form to the current zone."
            ),
            "*.ip6.arpa."
          )
        )
        return false
      end 
      # IPv4 reverse zone
    else
      num = "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"
      ipv4_incompl = Ops.add(
        Ops.add(Ops.add(Ops.add(Ops.add("^", num), "(\\."), num), "){0,3}"),
        "(\\.in-addr\\.arpa)*\\.*$"
      )
      if !Builtins.regexpmatch(key, ipv4_incompl)
        UI.SetFocus(Id("add_record_name"))
        Popup.Error(Hostname.ValidFQ)
        return false
      end
    end

    return true 

    # -- AAAA -- \\
  elsif type == "AAAA"
    # (hostname or FQ)
    if Hostname.Check(key) != true && Hostname.CheckFQ(key) != true &&
        key != "*"
      UI.SetFocus(Id("add_record_name"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end
    if IP.Check6(val) != true
      UI.SetFocus(Id("add_record_val"))
      Popup.Error(_("Invalid IPv6 address."))
      return false
    end
    return true 

    # -- SRV -- \\
  elsif type == "SRV"
    # int int int hostname
    if Builtins.regexpmatch(
        val,
        "^[ \t]*[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[^ \t].*$"
      )
      val = Builtins.regexpsub(
        val,
        "^[ \t]*[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+([^ \t].*)$",
        "\\1"
      ) 
      # FIXME: check also other values (ints)
    end
    if Hostname.Check(val) != true && Hostname.CheckFQ(val) != true
      UI.SetFocus(Id("add_record_val"))
      Popup.Error(Hostname.ValidFQ)
      return false
    end
    return true 

  # TXT or SPF
  elsif type == "TXT" or type == "SPF"
    if !ValidTextRecordName(key)
      UI.SetFocus(Id("add_record_name"))
      # TRANSLATORS: Error message
      # %{type} replaced with record type (TXT or SPF)
      Popup.Error(
        _(
          "Invalid %{type} record key. It should consist of printable US-ASCII characters excluding '='\nand must be at least one character long."
        ) % {:type => type}
      )
      return false
    end

    # Too long records need to be split into more smaller parts
    # Although splitting is done while writing it to the config file,
    # checking, whether it's possible, is done here in advance.
    max_val_size = val.split.map{|s| s.size}.max
    if max_val_size > MAX_TEXT_RECORD_LENGTH
      UI.SetFocus(Id("add_record_val"))
      # TRANSLATORS: Error message
      # %{type}    - replaced with record type (TXT or SPF)
      # %{max}     - replaced with the maximal length
      # %{current} - replaced with the current length of a new TXT record.
      Popup.Error(
        _(
          "Maximal length of a %{type} record is %{max} characters.\n" +
          "This message is %{current} characters long."
        ) % {
          :type => type,
          :max => MAX_TEXT_RECORD_LENGTH,
          :current => max_val_size
        }
      )
      return false
    end
    return true
  end

  Builtins.y2error("unknown record type: %1", Ops.get(record, "type", ""))
  false
end

- (Object) ForwardZone_AddZoneForwarder



2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2864

def ForwardZone_AddZoneForwarder
  new_forwarder = Convert.to_string(
    UI.QueryWidget(Id("new_forwarder"), :Value)
  )
  if !IP.Check4(new_forwarder)
    UI.SetFocus(Id("new_forwarder"))
    Report.Error(IP.Valid4)
  else
    @current_zone_forwarders = Builtins.toset(
      Builtins.add(@current_zone_forwarders, new_forwarder)
    )
    InitTableOfZOneForwarders()
  end

  nil
end

- (Object) ForwardZone_DeleteZoneForwarder



2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2881

def ForwardZone_DeleteZoneForwarder
  delete_forwarder = Convert.to_string(
    UI.QueryWidget(Id("zone_forwarders_list"), :CurrentItem)
  )
  if delete_forwarder != nil && delete_forwarder != ""
    @current_zone_forwarders = Builtins.filter(@current_zone_forwarders) do |one_forwarder|
      one_forwarder != delete_forwarder
    end
    InitTableOfZOneForwarders()
  end

  nil
end

- (Object) GetEditationWidgets(rec_type)



1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1208

def GetEditationWidgets(rec_type)
  ret = nil

  case rec_type
    when "MX"
      ret = HBox(
        # Textentry - zone settings - Record Name
        Top(
          InputField(
            Id("add_record_name"),
            Opt(:hstretch),
            _("&Record Key")
          )
        ),
        # Combobox - zone settings - Record Type
        Top(
          ComboBox(
            Id("add_record_type"),
            Opt(:notify),
            _("T&ype"),
            @supported_records_ui
          )
        ),
        # IntField - zone settings - Record Value
        Top(
          HSquash(
            IntField(
              Id("add_record_prio"),
              Opt(:hstretch),
              _("&Priority"),
              0,
              65535,
              0
            )
          )
        ),
        # Textentry - zone settings - Record Value
        Top(InputField(Id("add_record_val"), Opt(:hstretch), _("Val&ue")))
      )
    when "SRV"
      ret = HBox(
        VBox(
          # Textentry - zone settings - Record Name
          InputField(
            Id("add_record_name"),
            Opt(:hstretch),
            _("&Record Key")
          ),
          HBox(
            # Textentry - zone settings - Record Name
            ComboBox(
              Id("add_record_service"),
              Opt(:editable, :hstretch),
              _("&Service"),
              [
                Item("_http"),
                Item("_ftp"),
                Item("_imap"),
                Item("_ldap"),
                Item("_PK"),
                Item("_XREP")
              ]
            ),
            # Textentry - zone settings - Record Name
            ComboBox(
              Id("add_record_protocol"),
              Opt(:editable, :hstretch),
              _("&Protocol"),
              [Item("_tcp"), Item("_udp")]
            ),
            HStretch()
          )
        ),
        Top(
          # Combobox - zone settings - Record Type
          ComboBox(
            Id("add_record_type"),
            Opt(:notify),
            _("T&ype"),
            @supported_records_ui
          )
        ),
        VBox(
          # IntField - zone settings - Record Value
          InputField(Id("add_record_val"), Opt(:hstretch), _("Val&ue")),
          HBox(
            # IntField - zone settings - Record Value
            IntField(Id("add_record_prio"), _("&Priority"), 0, 65535, 0),
            # IntField - zone settings - Record Value
            IntField(Id("add_record_weight"), _("&Weight"), 0, 65535, 0),
            # IntField - zone settings - Record Value
            IntField(Id("add_record_port"), _("&Port"), 0, 65535, 0)
          )
        )
      )
    # "A", "AAAA", "CNAME", "NS", "PTR", "TXT", "SPF"
    else
      ret = HBox(
        # Textentry - zone settings - Record Name
        Top(
          InputField(
            Id("add_record_name"),
            Opt(:hstretch),
            _("&Record Key")
          )
        ),
        # Combobox - zone settings - Record Type
        Top(
          ComboBox(
            Id("add_record_type"),
            Opt(:notify),
            _("T&ype"),
            @supported_records_ui
          )
        ),
        # Textentry - zone settings - Record Value
        Top(InputField(Id("add_record_val"), Opt(:hstretch), _("Val&ue")))
      )
  end

  deep_copy(ret)
end

- (Yast::Term) GetMasterZoneEditorTab(tab_id)

Dialog Zone Editor - Tab

Parameters:

  • tab_id (String)

Returns:

  • (Yast::Term)

    dialog for ZoneEditorDialog()



2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2325

def GetMasterZoneEditorTab(tab_id)
  if tab_id == "basics"
    return GetMasterZoneEditorTabBasics()
  elsif tab_id == "name_servers"
    return GetMasterZoneEditorTabNameServers()
  elsif tab_id == "mail_servers"
    return GetMasterZoneEditorTabMailServers()
  elsif tab_id == "soa_settings"
    return GetMasterZoneEditorTabSOASettings()
  elsif tab_id == "records"
    return GetMasterZoneEditorTabRecords()
  end

  # This should never happen, but ...
  Builtins.y2error("unknown tab_id: %1", tab_id)
  # When no dialog defined for this tab (software error)
  Label(_("An internal error has occurred."))
end

- (Yast::Term) GetMasterZoneEditorTabBasics

Dialog Tab - Zone Editor - Basics

Returns:

  • (Yast::Term)

    for Get_ZoneEditorTab()



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
# File '../../src/include/dns-server/dialog-masterzone.rb', line 63

def GetMasterZoneEditorTabBasics
  updater_keys_m = DnsTsigKeys.ListTSIGKeys
  updater_keys = Builtins.maplist(updater_keys_m) do |m|
    Ops.get_string(m, "key", "")
  end
  acl = DnsServer.GetAcl
  acl = Builtins.maplist(acl) do |a|
    while Builtins.substring(a, 0, 1) == " " ||
        Builtins.substring(a, 0, 1) == "\t"
      a = Builtins.substring(a, 1)
    end
    s = Builtins.splitstring(a, " \t")
    type = Ops.get(s, 0, "")
    type
  end
  acl = Builtins.filter(acl) { |a| a != "" }
  acl = Convert.convert(
    Builtins.sort(
      Builtins.merge(acl, ["any", "none", "localhost", "localnets"])
    ),
    :from => "list",
    :to   => "list <string>"
  )

  expert_settings = Empty()
  if DnsServer.ExpertUI
    expert_settings = VBox(
      Left(
        CheckBoxFrame(
          Id("allow_ddns"),
          Opt(:notify),
          # check box
          _("A&llow Dynamic Updates"),
          true,
          Left(
            ReplacePoint(
              Id(:ddns_key_rp),
              # combo box
              HSquash(
                ComboBox(
                  Id("ddns_key"),
                  Opt(:hstretch),
                  _("TSIG &Key"),
                  updater_keys
                )
              )
            )
          )
        )
      ),
      VSpacing(1)
    )
  end

  # bug #203910
  # hide "none" from listed ACLs
  # "none" means, not allowed and thus multiselectbox of ACLs is disabled
  acl = Builtins.filter(acl) { |one_acl| one_acl != "none" }

  @available_zones_to_connect = []
  zone_name = ""
  zones_to_connect = Builtins.maplist(@zones) do |z|
    zone_name = Ops.get_string(z, "zone", "")
    # zone must be: reverse, not-internal, master
    if DnsServerHelperFunctions.IsReverseZone(zone_name) ||
        DnsServerHelperFunctions.IsInternalZone(zone_name) ||
        Ops.get_string(z, "type", "") != "master"
      next nil
    end
    @available_zones_to_connect = Builtins.add(
      @available_zones_to_connect,
      zone_name
    )
    Item(Id(zone_name), Punycode.DecodeDomainName(zone_name))
  end
  zones_to_connect = Builtins.sort(Builtins.filter(zones_to_connect) do |one_zone|
    one_zone != nil
  end)

  zones_connected = DnsServer.GetWhichZonesAreConnectedWith(
    Ops.get_string(@current_zone, "zone", "")
  )
  Builtins.y2milestone(
    "Connected with zone %1: %2",
    Ops.get_string(@current_zone, "zone", ""),
    zones_connected
  )

  contents = VBox(
    expert_settings,
    Left(
      CheckBoxFrame(
        Id("enable_zone_transport"),
        Opt(:notify),
        # check box
        _("Enable &Zone Transport"),
        true,
        # multi selection box
        VSquash(
          HSquash(
            MinWidth(30, MultiSelectionBox(Id("acls_list"), _("ACLs"), acl))
          )
        )
      )
    ),
    VSpacing(1),
    # Reverse zones can be automatically generated
    DnsServerHelperFunctions.IsReverseZone(
      Ops.get_string(@current_zone, "zone", "")
    ) == true ?
      Left(
        CheckBoxFrame(
          Id("generate_from_forward_zone"),
          Opt(:notify),
          # check box
          _("A&utomatically Generate Records From"),
          true,
          # multi selection box
          VSquash(
            HSquash(
              MinWidth(
                30,
                ComboBox(
                  Id("generate_from_forward_zone_sel"),
                  _("Zon&e"),
                  zones_to_connect
                )
              )
            )
          )
        )
      ) :
      Ops.greater_than(Builtins.size(zones_connected), 0) ?
        Left(
          Frame(
            # frame label
            _("Connected Reverse Zones"),
            VBox(Label(Builtins.mergestring(zones_connected, "\n")))
          )
        ) :
        Empty(),
    VStretch()
  )

  deep_copy(contents)
end

- (Yast::Term) GetMasterZoneEditorTabMailServers

Dialog Tab - Zone Editor - Mail Servers

Returns:

  • (Yast::Term)

    for Get_ZoneEditorTab()



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
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
# File '../../src/include/dns-server/dialog-masterzone.rb', line 694

def GetMasterZoneEditorTabMailServers
  contents = VBox(
    VSquash(
      Frame(
        # Frame label - adding mail server
        _("Mail Server to Add"),
        VBox(
          HBox(
            HWeight(
              7,
              HBox(
                # Textentry - addind mail server - Name
                InputField(
                  Id("add_mail_server"),
                  Opt(:hstretch),
                  _("&Address")
                ),
                # IntField - adding mail server - Priority
                IntField(Id("add_priority"), _("&Priority"), 0, 65535, 0)
              )
            ),
            HWeight(
              2,
              VBox(
                VStretch(),
                VSquash(
                  PushButton(Id("add_mx"), Opt(:hstretch), Label.AddButton)
                )
              )
            )
          ),
          VSpacing(0.5)
        )
      )
    ),
    HBox(
      HWeight(
        7,
        VBox(
          # Table label - listing mail servers
          Left(Label(_("Mail Relay List"))),
          Table(
            Id("mail_server_list"),
            Header(
              # Table header item - listing mail servers
              _("Mail Server"),
              # Table header item - listing mail servers
              _("Priority")
            ),
            []
          )
        )
      ),
      HWeight(
        2,
        VBox(
          VSquash(VSpacing(1)),
          VSquash(
            PushButton(Id("delete_mx"), Opt(:hstretch), Label.DeleteButton)
          ),
          VStretch()
        )
      )
    )
  )
  deep_copy(contents)
end

- (Yast::Term) GetMasterZoneEditorTabNameServers

Dialog Tab - Zone Editor - Name Servers

Returns:

  • (Yast::Term)

    for Get_ZoneEditorTab()



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
544
545
546
547
# File '../../src/include/dns-server/dialog-masterzone.rb', line 496

def GetMasterZoneEditorTabNameServers
  contents = VBox(
    VSquash(
      HBox(
        HWeight(
          7,
          # Textentry - adding nameserver
          InputField(
            Id("add_name_server"),
            Opt(:hstretch),
            _("&Name Server to Add")
          )
        ),
        HWeight(
          2,
          VBox(
            VStretch(),
            VSquash(
              PushButton(Id("add_ns"), Opt(:hstretch), Label.AddButton)
            )
          )
        )
      )
    ),
    HBox(
      HWeight(
        7,
        ReplacePoint(
          Id("name_server_list_rp"),
          # Selectionbox - listing current nameservers
          SelectionBox(
            Id("name_server_list"),
            Opt(:hstretch),
            _("Na&me Server List"),
            []
          )
        )
      ),
      HWeight(
        2,
        VBox(
          VSquash(VSpacing(1)),
          VSquash(
            PushButton(Id("delete_ns"), Opt(:hstretch), Label.DeleteButton)
          ),
          VStretch()
        )
      )
    )
  )
  deep_copy(contents)
end

- (Yast::Term) GetMasterZoneEditorTabRecords

Dialog Tab - Zone Editor - Records

Returns:

  • (Yast::Term)

    for Get_ZoneEditorTab()



1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1333

def GetMasterZoneEditorTabRecords
  # reverse zone
  if DnsServerHelperFunctions.IsReverseZone(
      Ops.get_string(@current_zone, "zone", "")
    )
    @supported_records = ["PTR", "NS"]
  else
    @supported_records = ["A", "AAAA", "CNAME", "NS", "MX", "SRV", "TXT", "SPF"]
  end

  record_type_descriptions = {
    "A"     => _("A: IPv4 Domain Name Translation"),
    "AAAA"  => _("AAAA: IPv6 Domain Name Translation"),
    "CNAME" => _("CNAME: Alias for Domain Name"),
    "NS"    => _("NS: Name Server"),
    "MX"    => _("MX: Mail Relay"),
    "PTR"   => _("PTR: Reverse Translation"),
    "SRV"   => _("SRV: Services Record"),
    "TXT"   => _("TXT: Text Record"),
    "SPF"   => _("SPF: Sender Policy Framework"),
  }

  @supported_records_ui = Builtins.maplist(@supported_records) do |one_rec_type|
    Item(
      Id(one_rec_type),
      Ops.get(record_type_descriptions, one_rec_type, one_rec_type)
    )
  end

  @current_rr_rp = GetEditationWidgets(nil)

  contents = VBox(
    HStretch(),
    VSquash(
      # Frame label - Adding/Changing IP/CNAME/Type... zone settings
      Frame(
        _("Record Settings"),
        VBox(
          HBox(
            HWeight(
              11,
              # Will be replaced with another box of widgets
              # after selecting another RR type
              ReplacePoint(Id("rr_rp"), @current_rr_rp)
            ),
            HWeight(
              2,
              VBox(
                VSpacing(2),
                # Pushbutton - Change Record
                VSquash(
                  PushButton(
                    Id("change_record"),
                    Opt(:hstretch),
                    _("C&hange")
                  )
                ),
                VSquash(
                  PushButton(
                    Id("add_record"),
                    Opt(:hstretch),
                    Label.AddButton
                  )
                )
              )
            )
          )
        )
      )
    ),
    VSpacing(0.5),
    # Table label - Records listing
    Left(Label(_("Configured Resource Records"))),
    HBox(
      HWeight(
        11,
        VBox(
          Table(
            Id("records_list"),
            Opt(:notify, :immediate),
            Header(
              # Table menu item - Records listing
              _("Record Key"),
              # Table menu item - Records listing
              _("Type"),
              # Table menu item - Records listing
              _("Value")
            ),
            []
          )
        )
      ),
      HWeight(
        2,
        VBox(
          VSquash(
            PushButton(
              Id("delete_record"),
              Opt(:hstretch),
              Label.DeleteButton
            )
          ),
          VStretch()
        )
      )
    )
  )
  deep_copy(contents)
end

- (Yast::Term) GetMasterZoneEditorTabSOASettings

Dialog Tab - Zone Editor - Zone Settings

Returns:

  • (Yast::Term)

    for Get_ZoneEditorTab()



937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
# File '../../src/include/dns-server/dialog-masterzone.rb', line 937

def GetMasterZoneEditorTabSOASettings
  dns_units = [
    # DNS Settings time units (combobox item)
    Item(Id(""), _("Seconds")),
    # DNS Settings time units (combobox item)
    Item(Id("m"), _("Minutes")),
    # DNS Settings time units (combobox item)
    Item(Id("h"), _("Hours")),
    # DNS Settings time units (combobox item)
    Item(Id("d"), _("Days")),
    # DNS Settings time units (combobox item)
    Item(Id("w"), _("Weeks"))
  ]

  contents = VBox(
    HBox(
      HWeight(
        50,
        VBox(
          # Textentry - setting Serial for zone
          InputField(
            Id("zone_settings_serial"),
            Opt(:hstretch),
            _("Seri&al"),
            ""
          ),
          VSpacing(1),
          HBox(
            # Textentry - setting TTL for zone
            IntField(
              Id("zone_settings_ttl_value"),
              Opt(:hstretch),
              _("TT&L"),
              0,
              9999999,
              0
            ),
            ComboBox(Id("zone_settings_ttl_units"), _("&Unit"), dns_units)
          ),
          VStretch()
        )
      ),
      HSpacing(2),
      HWeight(
        50,
        VBox(
          HBox(
            Opt(:hstretch),
            # IntField - Setting DNS Refresh - Value
            IntField(
              Id("zone_settings_refresh_value"),
              _("Re&fresh"),
              0,
              9999999,
              0
            ),
            # Combobox - Setting DNS Refresh - Unit
            ComboBox(
              Id("zone_settings_refresh_units"),
              _("Un&it"),
              dns_units
            )
          ),
          HBox(
            Opt(:hstretch),
            # IntField - Setting DNS Retry - Value
            IntField(
              Id("zone_settings_retry_value"),
              _("Retr&y"),
              0,
              9999999,
              0
            ),
            # Combobox - Setting DNS Retry - Unit
            ComboBox(Id("zone_settings_retry_units"), _("&Unit"), dns_units)
          ),
          HBox(
            Opt(:hstretch),
            # IntField - Setting DNS Expiry - Value
            IntField(
              Id("zone_settings_expiry_value"),
              _("Ex&piration"),
              0,
              9999999,
              0
            ),
            # Combobox - Setting DNS Expiry - Unit
            ComboBox(
              Id("zone_settings_expiry_units"),
              _("U&nit"),
              dns_units
            )
          ),
          HBox(
            Opt(:hstretch),
            # IntField - Setting DNS Minimum - Value
            IntField(
              Id("zone_settings_minimum_value"),
              _("&Minimum"),
              0,
              9999999,
              0
            ),
            # Combobox - Setting DNS Minimum - Unit
            ComboBox(
              Id("zone_settings_minimum_units"),
              _("Uni&t"),
              dns_units
            )
          ),
          VStretch()
        )
      )
    )
  )
  deep_copy(contents)
end

- (Object) HandleMasterZoneTab(dialog, event)



2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2376

def HandleMasterZoneTab(dialog, event)
  event = deep_copy(event)
  ret = nil
  if dialog == "basics"
    HandleZoneBasicsTab(event)
  elsif dialog == "name_servers"
    ret = HandleNsListTab(event)
  elsif dialog == "mail_servers"
    ret = HandleMxListTab(event)
  elsif dialog == "soa_settings"
    ret = HandleSoaTab(event)
  elsif dialog == "records"
    HandleZoneRecordsTab(event)
  end
  ret
end

- (Object) HandleMxListTab(event)

Handle events in a tab of a dialog



841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
# File '../../src/include/dns-server/dialog-masterzone.rb', line 841

def HandleMxListTab(event)
  event = deep_copy(event)
  ret = Ops.get(event, "ID")

  if ret == "add_mx"
    new_mx_decoded = Convert.to_string(
      UI.QueryWidget(Id("add_mail_server"), :Value)
    )
    new_mx = Punycode.EncodeDomainName(new_mx_decoded)

    prio = Convert.to_integer(UI.QueryWidget(Id("add_priority"), :Value))
    # maximal priority is 65535
    if Ops.greater_than(prio, 65535)
      prio = 65535
      UI.ChangeWidget(Id("add_priority"), :Value, 65535)
    end

    zn = Ops.add(Ops.get_string(@current_zone, "zone", ""), ".")

    check_mx = new_mx
    if Builtins.regexpmatch(check_mx, "^.*\\.$")
      check_mx = Builtins.regexpsub(check_mx, "^(.*)\\.$", "\\1")
    end

    # validating mail server
    if Hostname.Check(check_mx) != true &&
        Hostname.CheckFQ(check_mx) != true
      UI.SetFocus(Id("add_mail_server"))
      # A popup error message
      Popup.Error(
        _("The specified value is not a valid hostname or IP address.")
      )
      return nil
    end

    # absolute hostname
    if Builtins.regexpmatch(new_mx, "\\..*[^.]$")
      new_mx = Ops.add(new_mx, ".")
    # relative hostname
    elsif Builtins.regexpmatch(new_mx, "^[^.]*$")
      new_mx = Builtins.sformat("%1.%2", new_mx, zn)
    end

    mx_list_check = Builtins.filter(@current_zone_mx) do |mx|
      split = Builtins.splitstring(mx, " \t")
      split = Builtins.filter(split) { |s| s != "" }
      address = Ops.get(split, 1, "")
      address == new_mx
    end
    if Ops.greater_than(Builtins.size(mx_list_check), 0)
      UI.SetFocus(Id("add_name_server"))
      # error message
      Popup.Error(_("The specified mail server already exists."))
      return nil
    end

    new_mx = Builtins.sformat("%1 %2", prio, new_mx)
    Builtins.y2milestone("New MX: %1", new_mx)

    current_zone_ref = arg_ref(@current_zone)
    DnsServerHelperFunctions.HandleNsupdate(
      { "type" => "MX", "key" => zn, "value" => new_mx },
      "add",
      current_zone_ref
    )
    @current_zone = current_zone_ref.value

    @current_zone_mx = Builtins.add(@current_zone_mx, new_mx)
    RedrawMxListWidget()
  elsif ret == "delete_mx"
    selected = Convert.to_integer(
      UI.QueryWidget(Id("mail_server_list"), :CurrentItem)
    )
    selected_value = Ops.get(@current_zone_mx, selected, "")
    Ops.set(@current_zone_mx, selected, nil)
    @current_zone_mx = Builtins.filter(@current_zone_mx) { |mx| mx != nil }
    RedrawMxListWidget()

    zn = Ops.add(Ops.get_string(@current_zone, "zone", ""), ".")
    current_zone_ref = arg_ref(@current_zone)
    DnsServerHelperFunctions.HandleNsupdate(
      { "type" => "MX", "key" => zn, "value" => selected_value },
      "delete",
      current_zone_ref
    )
    @current_zone = current_zone_ref.value
  end
  nil
end

- (Object) HandleNsListTab(event)

Handle events in a tab of a dialog



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
# File '../../src/include/dns-server/dialog-masterzone.rb', line 617

def HandleNsListTab(event)
  event = deep_copy(event)
  ret = Ops.get(event, "ID")

  if ret == "add_ns"
    zn = Ops.add(Ops.get_string(@current_zone, "zone", ""), ".")

    # NS is converted to the Punycode first
    new_ns_entered = Convert.to_string(
      UI.QueryWidget(Id("add_name_server"), :Value)
    )
    new_ns = Punycode.EncodeDomainName(new_ns_entered)
    Builtins.y2milestone("New NS: %1", new_ns)

    check_ns = new_ns
    if Builtins.regexpmatch(check_ns, "^.*\\.$")
      check_ns = Builtins.regexpsub(check_ns, "^(.*)\\.$", "\\1")
    end

    # validating name server
    if Hostname.Check(check_ns) != true &&
        Hostname.CheckFQ(check_ns) != true
      UI.SetFocus(Id("add_name_server"))
      # A popup error message
      Popup.Error(Hostname.ValidDomain)
      return nil
    end
    # absolute hostname
    if Builtins.regexpmatch(new_ns, "\\..*[^.]$")
      new_ns = Ops.add(new_ns, ".")
    elsif Builtins.regexpmatch(new_ns, "^[^.]*$")
      new_ns = Builtins.sformat("%1.%2", new_ns, zn)
    end
    if Builtins.contains(@current_zone_ns, new_ns)
      UI.SetFocus(Id("add_name_server"))
      # error message
      Popup.Error(_("The specified name server already exists."))
      return nil
    end

    current_zone_ref = arg_ref(@current_zone)
    DnsServerHelperFunctions.HandleNsupdate(
      { "type" => "NS", "key" => zn, "value" => new_ns },
      "add",
      current_zone_ref
    )
    @current_zone = current_zone_ref.value

    @current_zone_ns = Builtins.add(@current_zone_ns, new_ns)
    RedrawNsListWidget()
  elsif ret == "delete_ns"
    selected = Convert.to_string(
      UI.QueryWidget(Id("name_server_list"), :CurrentItem)
    )
    @current_zone_ns = Builtins.filter(@current_zone_ns) do |ns|
      ns != selected
    end
    RedrawNsListWidget()

    zn = Ops.add(Ops.get_string(@current_zone, "zone", ""), ".")
    current_zone_ref = arg_ref(@current_zone)
    DnsServerHelperFunctions.HandleNsupdate(
      { "type" => "NS", "key" => zn, "value" => selected },
      "delete",
      current_zone_ref
    )
    @current_zone = current_zone_ref.value
  end
  nil
end

- (Object) HandleSoaTab(event)

Handle events in a tab of a dialog



1156
1157
1158
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1156

def HandleSoaTab(event)
  nil
end

- (Object) HandleZoneBasicsTab(event)

Handle events in a tab of a dialog



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
# File '../../src/include/dns-server/dialog-masterzone.rb', line 457

def HandleZoneBasicsTab(event)
  event = deep_copy(event)
  ret = Ops.get(event, "ID")

  if DnsServer.ExpertUI
    if ret == "allow_ddns" && Mode.config
      # popup message
      Popup.Message(
        _(
          "This function is not available during\npreparation for autoinstallation.\n"
        )
      )
      UI.ChangeWidget(Id("allow_ddns"), :Value, false)
      return nil
    end
    if ret == "allow_ddns" &&
        Convert.to_boolean(UI.QueryWidget(Id("allow_ddns"), :Value)) &&
        Builtins.size(DnsTsigKeys.ListTSIGKeys) == 0
      # error report
      Report.Error(_("No TSIG key is defined."))
      UI.ChangeWidget(Id("allow_ddns"), :Value, false)
    end
    UI.ChangeWidget(
      Id("ddns_key"),
      :Enabled,
      Convert.to_boolean(UI.QueryWidget(Id("allow_ddns"), :Value))
    )
  end

  ZoneAclHandle(event)
  nil
end

- (Object) HandleZoneRecordsTab(event)

Handle events in a tab of a dialog



2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2107

def HandleZoneRecordsTab(event)
  event = deep_copy(event)
  ret = Ops.get(event, "ID")
  zone_fqdn = Ops.add(Ops.get_string(@current_zone, "zone", ""), ".")

  r = Convert.to_integer(UI.QueryWidget(Id("records_list"), :CurrentItem))
  # Currently selected type
  type = Convert.to_string(UI.QueryWidget(Id("add_record_type"), :Value))

  # translating new record key
  key = Convert.to_string(UI.QueryWidget(Id("add_record_name"), :Value))
  if key == "@"
    key = zone_fqdn
    Builtins.y2warning("Transforming key @ into %1", key)
  end
  key = Punycode.EncodeDomainName(key)

  # translating new record val
  val = Punycode.EncodeDomainName(
    Convert.to_string(UI.QueryWidget(Id("add_record_val"), :Value))
  )

  record_service = ""
  record_protocol = ""

  record_prio = 0
  record_weigh = 0
  record_port = 0

  zone = Ops.get_string(@current_zone, "zone", "")
  decoded_zone = Punycode.DecodeDomainName(zone)

  # Switch to new type of Editation dialog
  if ret == "add_record_type"
    if type != @last_add_record_type
      type_ref = arg_ref(type)
      decoded_zone_ref = arg_ref(decoded_zone)
      zone_ref = arg_ref(zone)
      SwitchAndAdjustEditationWidgets(
        type_ref,
        { "type" => type },
        decoded_zone_ref,
        zone_ref
      )
      type = type_ref.value
      decoded_zone = decoded_zone_ref.value
      zone = zone_ref.value
    end
    return nil
  end

  case type
    when "SRV"
      record_service = Convert.to_string(
        UI.QueryWidget(Id("add_record_service"), :Value)
      )
      record_protocol = Convert.to_string(
        UI.QueryWidget(Id("add_record_protocol"), :Value)
      )

      # empty key or FQDN
      if key == "" || key == zone_fqdn
        key = Builtins.sformat("%1.%2", record_service, record_protocol) 
        # non empty key & not matching zone FQDN
      else
        key = Builtins.sformat(
          "%1.%2.%3",
          record_service,
          record_protocol,
          key
        )
      end

      record_prio = Convert.to_integer(
        UI.QueryWidget(Id("add_record_prio"), :Value)
      )
      record_weigh = Convert.to_integer(
        UI.QueryWidget(Id("add_record_weight"), :Value)
      )
      record_port = Convert.to_integer(
        UI.QueryWidget(Id("add_record_port"), :Value)
      )

      val = Builtins.sformat(
        "%1 %2 %3 %4",
        record_prio,
        record_weigh,
        record_port,
        val
      )
    when "MX"
      record_prio = Convert.to_integer(
        UI.QueryWidget(Id("add_record_prio"), :Value)
      )

      val = Builtins.sformat("%1 %2", record_prio, val)
    # "A", "AAAA", "CNAME", "NS", "PTR", "TXT", "SPF"
    else

  end

  # Switching selected record
  if ret == "records_list"
    # type might have changed
    type = Ops.get_string(@current_zone, ["records", r, "type"], "")
    type_ref = arg_ref(type)
    decoded_zone_ref = arg_ref(decoded_zone)
    zone_ref = arg_ref(zone)
    SwitchAndAdjustEditationWidgets(
      type_ref,
      Ops.get_map(@current_zone, ["records", r], {}),
      decoded_zone_ref,
      zone_ref
    )
    type = type_ref.value
    decoded_zone = decoded_zone_ref.value
    zone = zone_ref.value
  # Changing selected record
  elsif ret == "change_record"
    if (
        type_ref = arg_ref(type);
        key_ref = arg_ref(key);
        val_ref = arg_ref(val);
        _CheckAndModifyRecord_result = CheckAndModifyRecord(
          type_ref,
          key_ref,
          val_ref
        );
        type = type_ref.value;
        key = key_ref.value;
        val = val_ref.value;
        _CheckAndModifyRecord_result
      ) != true
      return nil
    end

    current_zone_ref = arg_ref(@current_zone)
    DnsServerHelperFunctions.HandleNsupdate(
      Ops.get_map(@current_zone, ["records", r], {}),
      "delete",
      current_zone_ref
    )
    @current_zone = current_zone_ref.value

    Ops.set(@current_zone, ["records", r, "key"], key)
    Ops.set(@current_zone, ["records", r, "type"], type)
    Ops.set(@current_zone, ["records", r, "value"], val)
    RedrawZonesTable()

    current_zone_ref = arg_ref(@current_zone)
    DnsServerHelperFunctions.HandleNsupdate(
      Ops.get_map(@current_zone, ["records", r], {}),
      "add",
      current_zone_ref
    )
    @current_zone = current_zone_ref.value
  # Adding new record
  elsif ret == "add_record"
    if (
        type_ref = arg_ref(type);
        key_ref = arg_ref(key);
        val_ref = arg_ref(val);
        _CheckAndModifyRecord_result = CheckAndModifyRecord(
          type_ref,
          key_ref,
          val_ref
        );
        type = type_ref.value;
        key = key_ref.value;
        val = val_ref.value;
        _CheckAndModifyRecord_result
      ) != true
      return nil
    end

    rec = { "key" => key, "type" => type, "value" => val }
    Ops.set(
      @current_zone,
      "records",
      Builtins.add(Ops.get_list(@current_zone, "records", []), rec)
    )
    RedrawZonesTable()

    current_zone_ref = arg_ref(@current_zone)
    DnsServerHelperFunctions.HandleNsupdate(rec, "add", current_zone_ref)
    @current_zone = current_zone_ref.value
  # Removing selected record
  elsif ret == "delete_record"
    return nil if !Confirm.DeleteSelected

    current_zone_ref = arg_ref(@current_zone)
    DnsServerHelperFunctions.HandleNsupdate(
      Ops.get_map(@current_zone, ["records", r], {}),
      "delete",
      current_zone_ref
    )
    @current_zone = current_zone_ref.value

    Ops.set(@current_zone, ["records", r], nil)
    Ops.set(
      @current_zone,
      "records",
      Builtins.filter(Ops.get_list(@current_zone, "records", [])) do |r2|
        r2 != nil
      end
    )
    RedrawZonesTable() 

    # And the rest...
  else
    Builtins.y2error("Uknown ret: %1", ret)
  end

  nil
end

- (Object) initialize_dns_server_dialog_masterzone(include_target)



26
27
28
29
30
31
32
33
34
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
# File '../../src/include/dns-server/dialog-masterzone.rb', line 26

def initialize_dns_server_dialog_masterzone(include_target)
  textdomain "dns-server"

  Yast.import "Label"
  Yast.import "Wizard"
  Yast.import "DnsServer"
  Yast.import "DnsFakeTabs"
  Yast.import "DnsRoutines"
  Yast.import "DnsServerAPI"
  Yast.import "Confirm"
  Yast.import "Hostname"
  Yast.import "IP"
  Yast.import "Popup"
  Yast.import "DnsTsigKeys"
  Yast.import "Mode"
  Yast.import "Report"
  Yast.import "Punycode"
  Yast.import "DnsServerHelperFunctions"

  Yast.include include_target, "dns-server/misc.rb"

  @available_zones_to_connect = []

  @supported_records    = []
  @supported_records_ui = []

  @last_add_record_type = nil

  # current RR type used in `ReplacePoint (`id ("rr_rp"))
  @current_rr_rp = nil

  # All current forwarders are stored here
  @current_zone_forwarders = []
end

- (Object) InitMasterZoneTab(dialog)



2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2344

def InitMasterZoneTab(dialog)
  if dialog == "basics"
    InitZoneBasicsTab()
  elsif dialog == "name_servers"
    InitNsListTab()
  elsif dialog == "mail_servers"
    InitMxListTab()
  elsif dialog == "soa_settings"
    InitSoaTab()
  elsif dialog == "records"
    InitZoneRecordsTab()
  end

  nil
end

- (Object) InitMxListTab

Initialize the tab of the dialog



802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
# File '../../src/include/dns-server/dialog-masterzone.rb', line 802

def InitMxListTab
  zone_name = Ops.get_string(@current_zone, "zone", "")
  records = Builtins.filter(Ops.get_list(@current_zone, "records", [])) do |r|
    Ops.get_string(r, "type", "") == "MX" &&
      (Ops.get_string(r, "key", "") == Builtins.sformat("%1.", zone_name) ||
        Ops.get_string(r, "key", "") == "@")
  end
  @current_zone_mx = Builtins.maplist(records) do |r|
    Ops.get_string(r, "value", "")
  end
  @current_zone_mx = Builtins.filter(@current_zone_mx) { |z| z != "" }

  RedrawMxListWidget()

  nil
end

- (Object) InitNsListTab

Initialize the tab of the dialog



587
588
589
590
591
592
593
# File '../../src/include/dns-server/dialog-masterzone.rb', line 587

def InitNsListTab
  RegenerateCurrentZoneNS()
  RedrawNsListWidget() 
  #ValidCharsNsListWidget ();

  nil
end

- (Object) InitSoaTab

Initialize the tab of the dialog



1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1064

def InitSoaTab
  UI.ChangeWidget(
    Id("zone_settings_serial"),
    :Value,
    Ops.get_string(@current_zone, ["soa", "serial"], "")
  )

  map_ids_to_values = {
    "zone_settings_ttl"     => "ttl",
    "zone_settings_refresh" => "refresh",
    "zone_settings_retry"   => "retry",
    "zone_settings_expiry"  => "expiry",
    "zone_settings_minimum" => "minimum"
  }

  Builtins.foreach(map_ids_to_values) do |id, value|
    time_int = 0
    if id == "zone_settings_ttl"
      time_int = DnsServerAPI.TimeToSeconds(
        Ops.get_string(@current_zone, value, "0S")
      )
    else
      time_int = DnsServerAPI.TimeToSeconds(
        Ops.get_string(@current_zone, ["soa", value], "0S")
      )
    end
    time_str = DnsServerAPI.SecondsToHighestTimeUnit(time_int)
    UI.ChangeWidget(
      Id(Ops.add(id, "_value")),
      :Value,
      Builtins.tointeger(Builtins.filterchars(time_str, "0123456789"))
    )
    UI.ChangeWidget(
      Id(Ops.add(id, "_units")),
      :Value,
      Builtins.tolower(Builtins.filterchars(time_str, "WwDdHhMmSs"))
    )
  end

  UI.ChangeWidget(Id("zone_settings_serial"), :ValidChars, "0123456789")

  nil
end

- (Object) InitTableOfZOneForwarders



2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2849

def InitTableOfZOneForwarders
  if @current_zone_forwarders != nil && @current_zone_forwarders != []
    forwarders_items = []
    Builtins.foreach(@current_zone_forwarders) do |one_forwarder|
      forwarders_items = Builtins.add(
        forwarders_items,
        Item(Id(one_forwarder), one_forwarder)
      )
    end
    UI.ChangeWidget(Id("zone_forwarders_list"), :Items, forwarders_items)
  end

  nil
end

- (Object) InitZoneBasicsTab

Initialize the tab of the dialog



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File '../../src/include/dns-server/dialog-masterzone.rb', line 381

def InitZoneBasicsTab
  SetDNSSErverIcon()

  allowed = false
  key = nil
  Builtins.foreach(Ops.get_list(@current_zone, "options", [])) do |m|
    if Ops.get_string(m, "key", "") == "allow-update" && !allowed
      key = Builtins.regexpsub(
        Ops.get_string(m, "value", ""),
        "^.*key[ \t]+([^ \t;]+)[ \t;]+.*$",
        "\\1"
      )
      allowed = true if key != nil
    end
  end
  if DnsServer.ExpertUI
    UI.ChangeWidget(Id("allow_ddns"), :Value, allowed)
    UI.ChangeWidget(Id("ddns_key"), :Enabled, allowed)

    UI.ChangeWidget(Id("ddns_key"), :Value, key) if allowed
  end

  ZoneAclInit()
  ZoneConnectedWithInit()

  nil
end

- (Object) InitZoneRecordsTab

Initialize the tab of the dialog



1688
1689
1690
1691
1692
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1688

def InitZoneRecordsTab
  RedrawZonesTable()

  nil
end

- (Object) num2unit(num)



1055
1056
1057
1058
1059
1060
1061
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1055

def num2unit(num)
  unit = Builtins.filterchars(Builtins.tolower(num), "smhdw")
  return "" if Builtins.size(unit) == 0
  unit = Builtins.substring(unit, 0, 1)
  unit = "" if unit == "s"
  unit
end

- (Object) RedrawMxListWidget



762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File '../../src/include/dns-server/dialog-masterzone.rb', line 762

def RedrawMxListWidget
  zone_mx_decoded = Punycode.DocodeDomainNames(@current_zone_mx)

  index = -1
  # create term items using already translated strings
  items = Builtins.maplist(zone_mx_decoded) do |one_mx|
    one_address_name = one_mx
    one_address_name = Builtins.regexpsub(
      one_address_name,
      "^[0123456789]+[ \t]+(.*)$",
      "\\1"
    )
    one_priority = one_mx
    one_priority = Builtins.regexpsub(
      one_priority,
      "^([0123456789]+)[ \t]+.*$",
      "\\1"
    )
    index = Ops.add(index, 1)
    Item(Id(index), one_address_name, one_priority)
  end

  items = Builtins.sort(items) do |x, y|
    Ops.less_than(Ops.get_string(x, 1, ""), Ops.get_string(y, 2, ""))
  end

  # initialize the widget content
  UI.ChangeWidget(Id("mail_server_list"), :Items, items)

  nil
end

- (Object) RedrawNsListWidget



549
550
551
552
553
554
555
556
557
558
559
560
561
# File '../../src/include/dns-server/dialog-masterzone.rb', line 549

def RedrawNsListWidget
  UI.ReplaceWidget(
    Id("name_server_list_rp"),
    SelectionBox(
      Id("name_server_list"),
      # selection box label
      _("Na&me Server List"),
      Punycode.DocodeDomainNames(@current_zone_ns)
    )
  )

  nil
end

- (Object) RedrawZonesTable



1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1568

def RedrawZonesTable
  index = -1
  zone_name = Ops.get_string(@current_zone, "zone", "")
  decoded_zone_name = Punycode.DecodeDomainName(zone_name)

  ret = Builtins.maplist(Ops.get_list(@current_zone, "records", [])) do |m|
    index = Ops.add(index, 1)
    if Ops.get_string(m, "type", "") == "TTL" ||
        Ops.get_string(m, "type", "") == "ORIGIN"
      next -1
    end
    if (Ops.get_string(m, "type", "") == "NS" ||
        Ops.get_string(m, "type", "") == "MX") &&
        (Ops.get_string(m, "key", "") == Builtins.sformat("%1.", zone_name) ||
          Ops.get_string(m, "key", "") == "@")
      next -1
    end
    next -1 if Ops.get_string(m, "type", "") == "comment"
    index
  end
  ret = Builtins.filter(ret) { |r2| r2 != nil && r2 != -1 }

  # keys
  decoded_names = Builtins.maplist(ret) do |r2|
    Ops.get_string(@current_zone, ["records", r2, "key"], "")
  end

  const_plus = Builtins.size(decoded_names)

  # values
  Builtins.foreach(Builtins.maplist(ret) do |r2|
    Ops.get_string(@current_zone, ["records", r2, "value"], "")
  end) { |record| decoded_names = Builtins.add(decoded_names, record) }
  decoded_names = Punycode.DecodePunycodes(decoded_names)

  counter = -1
  items = Builtins.maplist(ret) do |r2|
    counter = Ops.add(counter, 1)
    record_type = Ops.get_string(@current_zone, ["records", r2, "type"], "")
    Item(
      Id(r2),
      DnsServerHelperFunctions.RRToRelativeName(
        Ops.get(
          decoded_names,
          counter,
          Ops.get_string(@current_zone, ["records", r2, "key"], "")
        ),
        decoded_zone_name,
        record_type,
        "key"
      ),
      record_type,
      DnsServerHelperFunctions.RRToRelativeName(
        Ops.get(
          decoded_names,
          Ops.add(counter, const_plus),
          Ops.get_string(@current_zone, ["records", r2, "value"], "")
        ),
        decoded_zone_name,
        record_type,
        "value"
      )
    )
  end

  # remember the last selected item
  r = Convert.to_integer(UI.QueryWidget(Id("records_list"), :CurrentItem))
  r = Ops.get_integer(items, [0, 0, 0], 0) if r == nil

  # Redraw
  UI.ChangeWidget(Id("records_list"), :Items, items)

  # Set CurrentItem again
  if Ops.greater_than(Builtins.size(items), 0)
    UI.ChangeWidget(Id("records_list"), :CurrentItem, r)
  end

  UI.ChangeWidget(
    Id("delete_record"),
    :Enabled,
    Ops.greater_than(Builtins.size(items), 0)
  )
  UI.ChangeWidget(
    Id("change_record"),
    :Enabled,
    Ops.greater_than(Builtins.size(items), 0)
  )

  if Ops.greater_than(Builtins.size(items), 0)
    r = Convert.to_integer(UI.QueryWidget(Id("records_list"), :CurrentItem))

    current_record = Ops.get_map(@current_zone, ["records", r], {})
    current_type = Ops.get_string(current_record, "type", "A")

    current_type_ref = arg_ref(current_type)
    decoded_zone_name_ref = arg_ref(decoded_zone_name)
    zone_name_ref = arg_ref(zone_name)
    SwitchAndAdjustEditationWidgets(
      current_type_ref,
      current_record,
      decoded_zone_name_ref,
      zone_name_ref
    )
    current_type = current_type_ref.value
    decoded_zone_name = decoded_zone_name_ref.value
    zone_name = zone_name_ref.value
  end

  nil
end

- (Object) RegenerateCurrentZoneNS

/** * Setting ValidChars for dialog */ void ValidCharsNsListWidget () { UI::ChangeWidget( id ("add_name_server"),ValidChars, Hostname::ValidCharsFQ); }



570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File '../../src/include/dns-server/dialog-masterzone.rb', line 570

def RegenerateCurrentZoneNS
  zone_name = Ops.get_string(@current_zone, "zone", "")
  records = Builtins.filter(Ops.get_list(@current_zone, "records", [])) do |r|
    Ops.get_string(r, "type", "") == "NS" &&
      (Ops.get_string(r, "key", "") == Builtins.sformat("%1.", zone_name) ||
        Ops.get_string(r, "key", "") == "@")
  end
  @current_zone_ns = Builtins.maplist(records) do |r|
    Ops.get_string(r, "value", "")
  end
  @current_zone_ns = Builtins.filter(@current_zone_ns) { |z| z != "" }
  Builtins.y2milestone("NSs: %1", @current_zone_ns)

  nil
end

- (Object) runForwardZoneTabDialog

Dialog Zone Editor - Forward

Returns:

  • (Object)

    dialog result for wizard



2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2897

def runForwardZoneTabDialog
  zone_name = Ops.get_string(@current_zone, "zone", "")
  @current_zone_forwarders = DnsServerAPI.GetZoneForwarders(
    Ops.get_string(@current_zone, "zone", "")
  )

  contents = VBox(
    HBox(
      # Label - connected with Textentry which shows current edited zone
      HSquash(Label(_("Settings for Zone"))),
      HSquash(
        InputField(
          Id("current_zone"),
          Opt(:disabled, :hstretch),
          "",
          Punycode.DecodeDomainName(zone_name)
        )
      ),
      HStretch()
    ),
    VSpacing(1),
    VSquash(
      HBox(
        HWeight(
          7,
          # Textentry - adding forwarder
          InputField(
            Id("new_forwarder"),
            Opt(:hstretch),
            _("New &Forwarder IP Address")
          )
        ),
        HWeight(
          2,
          VBox(
            VStretch(),
            VSquash(
              PushButton(
                Id("add_forwarder"),
                Opt(:hstretch),
                Label.AddButton
              )
            )
          )
        )
      )
    ),
    HBox(
      HWeight(
        7,
        # Selectionbox - listing current forwarders
        SelectionBox(
          Id("zone_forwarders_list"),
          Opt(:hstretch),
          _("Current &Zone Forwarders"),
          []
        )
      ),
      HWeight(
        2,
        VBox(
          VSquash(VSpacing(1)),
          VSquash(
            PushButton(
              Id("delete_forwarder"),
              Opt(:hstretch),
              Label.DeleteButton
            )
          ),
          VStretch()
        )
      )
    )
  )

  # dialog caption
  caption = _("Forward Zone Editor")

  Wizard.SetContentsButtons(
    caption,
    contents,
    Ops.get_string(@HELPS, "forward_zone", ""),
    Label.CancelButton,
    Label.OKButton
  )
  UI.ChangeWidget(Id("new_forwarder"), :ValidChars, IP.ValidChars4)

  InitTableOfZOneForwarders()

  ret = nil

  while true
    ret = UI.UserInput

    if ret == :abort || ret == :cancel
      if ReallyAbort()
        return :abort
      else
        next
      end
    elsif ret == :back
      break
    elsif ret == "add_forwarder"
      ForwardZone_AddZoneForwarder()
      next
    elsif ret == "delete_forwarder"
      ForwardZone_DeleteZoneForwarder()
      next
    elsif ret == :next
      if Builtins.size(@current_zone_forwarders) == 0
        # TRANSLATORS: popup question
        if !Popup.YesNo(
            _(
              "This forward zone has no forwarders defined, which means\n" +
                "that all DNS queries for this zone are denied.\n" +
                "Really deny these queries?"
            )
          )
          next
        end
      end

      Builtins.y2milestone(
        "Zone %1 (%2), Forwarders: %3",
        Ops.get_string(@current_zone, "zone", ""),
        Punycode.DecodeDomainName(Ops.get_string(@current_zone, "zone", "")),
        @current_zone_forwarders
      )
      Ops.set(@current_zone, "modified", true)
      if Ops.greater_than(Builtins.size(@current_zone_forwarders), 0)
        Ops.set(
          @current_zone,
          "forwarders",
          Builtins.sformat(
            "{ %1; }",
            Builtins.mergestring(@current_zone_forwarders, "; ")
          )
        )
      else
        Ops.set(@current_zone, "forwarders", "{}")
      end
      DnsServer.StoreCurrentZone(@current_zone)
      DnsServer.StoreZone
      DnsServer.SetModified
      break
    else
      Builtins.y2error("Unexpected return %1", ret)
    end
  end

  Ops.set(@current_zone, "modified", true) if ret == :next
  # empty the list
  @current_zone_forwarders = []
  @was_editing_zone = true

  Convert.to_symbol(ret)
end

- (Object) runMasterZoneTabDialog

Dialog Zone Editor - Main

Returns:

  • (Object)

    dialog result for wizard



2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2411

def runMasterZoneTabDialog
  # Dialog Caption - Expert Settings - Zone Editor
  caption = _("Zone Editor")

  # Helps ale linked like this Tab_ID -> HELPS[ Help_ID ]
  help_identificators = {
    "basics"       => "zone_editor_basics",
    "name_servers" => "zone_editor_nameservers",
    "mail_servers" => "zone_editor_mailservers",
    "soa_settings" => "zone_editor_soa",
    "records"      => "zone_editor_records"
  }

  zone_name = Ops.get_string(@current_zone, "zone", "")
  zone_name_dec = Punycode.DecodeDomainName(zone_name)
  current_tab = "basics"

  tab_terms = []

  # Different list of tabs for reverse zone
  if DnsServerHelperFunctions.IsReverseZone(zone_name)
    tab_terms = [
      # Menu Item - Zone Editor - Tab
      Item(Id("basics"), _("&Basics")),
      # Menu Item - Zone Editor - Tab
      Item(Id("name_servers"), _("NS Recor&ds")),
      # Menu Item - Zone Editor - Tab
      Item(Id("soa_settings"), _("&SOA")),
      # Menu Item - Zone Editor - Tab
      Item(Id("records"), _("R&ecords"))
    ] 
    # Not a reverse zone
  else
    tab_terms = [
      # Menu Item - Zone Editor - Tab
      Item(Id("basics"), _("&Basics")),
      # Menu Item - Zone Editor - Tab
      Item(Id("name_servers"), _("NS Recor&ds")),
      # Menu Item - Zone Editor - Tab
      Item(Id("mail_servers"), _("M&X Records")),
      # Menu Item - Zone Editor - Tab
      Item(Id("soa_settings"), _("&SOA")),
      # Menu Item - Zone Editor - Tab
      Item(Id("records"), _("R&ecords"))
    ]
  end



  contents =
    #`Top (
    VBox(
      Opt(:hvstretch),
      HBox(
        # Label - connected with Textentry which shows current edited zone
        HSquash(Label(_("Settings for Zone"))),
        HSquash(
          MinWidth(
            Ops.add(Builtins.size(zone_name_dec), 3),
            InputField(
              Id("current_zone"),
              Opt(:disabled, :hstretch),
              "",
              zone_name_dec
            )
          )
        ),
        HStretch()
      ),
      VSpacing(1),
      # Here start Tabs
      # FIXME: after `Tab implementation
      UI.HasSpecialWidget(:DumbTab) ?
        DumbTab(
          Id(:dumbtab),
          tab_terms,
          ReplacePoint(
            Id(:tabContents),
            GetMasterZoneEditorTab(current_tab)
          )
        ) :
        DnsFakeTabs.DumbTabs(
          tab_terms,
          ReplacePoint(
            Id(:tabContents),
            GetMasterZoneEditorTab(current_tab)
          )
        )
    )
  #);
  # Menu Item - Zone Editor - Tab
  qwerty = _("Ad&vanced")
  # error report
  #qwerty = _("The input value is invalid.");
  # error report
  #qwerty = _("At least one name server must be defined.");

  # FIXME: Only one help is used for all tabs. Maybe would be better to change the help for every single tab.
  Wizard.SetContentsButtons(
    caption,
    contents,
    Ops.get_string(
      @HELPS,
      Ops.get(help_identificators, current_tab, ""),
      ""
    ),
    Label.BackButton,
    Label.OKButton
  )
  Wizard.DisableBackButton
  Wizard.SetAbortButton(:go_back, Label.CancelButton)
  InitMasterZoneTab(current_tab)

  event = nil
  ret = nil
  while true
    event = UI.WaitForEvent
    ret = Ops.get(event, "ID")

    if ret == :next
      # The new ones are alerady stored there
      if current_tab != "name_servers"
        # BNC #436456
        StoreZoneBasicsTab() if current_tab == "basics"

        RegenerateCurrentZoneNS()
      end

      # at least one NS server must be set
      if Builtins.size(@current_zone_ns) == 0
        Builtins.y2warning("At least one NS server must be set")
        current_tab = "name_servers"
        UI.ReplaceWidget(
          :tabContents,
          GetMasterZoneEditorTab("name_servers")
        )
        if UI.HasSpecialWidget(:DumbTab)
          UI.ChangeWidget(Id(:dumbtab), :CurrentItem, current_tab)
        end
        Report.Error(_("At least one NS server must be set."))
        next
      end

      if ValidateMasterZoneTab(current_tab, event)
        break
      else
        next
      end
    end
    if ret == :go_back
      ret = :back
      break
    # close the whole dialog
    elsif ret == :cancel
      if ReallyAbort()
        return :abort
      else
        next
      end
    # TAB fake
    elsif ret == "basics" || ret == "name_servers" || ret == "mail_servers" ||
        ret == "soa_settings" ||
        ret == "records"
      if ValidateMasterZoneTab(current_tab, event)
        StoreMasterZoneTab(current_tab)
        current_tab = Convert.to_string(ret)

        show_warning = ""

        autogenerated_reverse_zone_allows = [
          "basics",
          "soa_settings",
          "name_servers"
        ]

        # Fake current tab if selected tab not allowed
        if Ops.get_string(
            # connected_with i set
            @current_zone,
            "connected_with",
            ""
          ) != "" &&
            Ops.get(@current_zone, "connected_with") != nil &&
            !# switching to forbidden tab
            Builtins.contains(
              autogenerated_reverse_zone_allows,
              Builtins.tostring(ret)
            )
          current_tab = "basics"
          if UI.HasSpecialWidget(:DumbTab)
            UI.ChangeWidget(Id(:dumbtab), :CurrentItem, current_tab)
          end
          Builtins.y2warning(
            "connected_with has been set, setting '%1' is not allowed",
            ret
          )
          # warning message, %1 is replaced with a zone name
          #
          # Automatically Generate Records From is a feature that makes YaST to generate
          # DNS records manually from selected zone
          show_warning = Builtins.sformat(
            _(
              "Current zone records are automatically generated from %1 zone.\nTo change records manually disable the Automatically Generate Records From feature."
            ),
            Ops.get_string(@current_zone, "connected_with", "")
          )
        end

        # Switch contents
        UI.ReplaceWidget(:tabContents, GetMasterZoneEditorTab(current_tab))

        if current_tab == "records"
          help_part2 = "zone_editor_records_forward"
          if DnsServerHelperFunctions.IsReverseZone(
              Ops.get_string(@current_zone, "zone", "")
            )
            help_part2 = "zone_editor_records_reverse"
          end

          Wizard.RestoreHelp(
            Ops.add(
              Ops.get_string(
                @HELPS,
                Ops.get(help_identificators, current_tab, ""),
                ""
              ),
              Ops.get_string(@HELPS, help_part2, "")
            )
          )
        else
          Wizard.RestoreHelp(
            Ops.get_string(
              @HELPS,
              Ops.get(help_identificators, current_tab, ""),
              ""
            )
          )
        end

        # Initialize values
        InitMasterZoneTab(current_tab)

        # Show warning if anything to show
        Report.Warning(show_warning) if show_warning != ""
      else
        # ensure the same tab selected
        if UI.HasSpecialWidget(:DumbTab)
          UI.ChangeWidget(Id(:dumbtab), :CurrentItem, current_tab)
        end
      end
    else
      ret = HandleMasterZoneTab(current_tab, event)
      break if ret != nil
    end
  end

  if ret == :next
    StoreMasterZoneTab(current_tab)
    Ops.set(@current_zone, "modified", true)
    DnsServer.StoreCurrentZone(@current_zone)
    DnsServer.StoreZone
    DnsServer.SetModified
  end

  @was_editing_zone = true
  Convert.to_symbol(ret)
end

- (Object) runSlaveZoneTabDialog

Dialog Zone Editor - Slave

Returns:

  • (Object)

    dialog result for wizard



2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2681

def runSlaveZoneTabDialog
  acl = Builtins.maplist(DnsServer.GetAcl) do |acl_record|
    acl_splitted = Builtins.splitstring(acl_record, " \t")
    Ops.get(acl_splitted, 0, "")
  end
  acl = Convert.convert(
    Builtins.sort(
      Builtins.merge(acl, ["any", "none", "localhost", "localnets"])
    ),
    :from => "list",
    :to   => "list <string>"
  )

  # bug #203910
  # hide "none" from listed ACLs
  # "none" means, not allowed and thus multiselectbox of ACLs is disabled
  acl = Builtins.filter(acl) { |one_acl| one_acl != "none" }

  zone_name = Ops.get_string(@current_zone, "zone", "")
  contents = VBox(
    HBox(
      # Label - connected with Textentry which shows current edited zone
      HSquash(Label(_("Settings for Zone"))),
      HSquash(
        InputField(
          Id("current_zone"),
          Opt(:disabled, :hstretch),
          "",
          Punycode.DecodeDomainName(zone_name)
        )
      ),
      HStretch()
    ),
    VSpacing(1),
    # TRANSLATORS: Text entry
    Left(
      InputField(Id("master"), Opt(:hstretch), _("&Master DNS Server IP"))
    ),
    VSpacing(2),
    Left(
      CheckBox(
        Id("enable_zone_transport"),
        Opt(:notify),
        # check box
        _("Enable &Zone Transport")
      )
    ),
    # multi selection box
    VSquash(MultiSelectionBox(Id("acls_list"), _("ACLs"), acl)),
    VStretch()
  )

  # dialog caption
  caption = _("Zone Editor")

  Wizard.SetContentsButtons(
    caption,
    contents,
    Ops.get_string(@HELPS, "slave_zone", ""),
    Label.CancelButton,
    Label.OKButton
  )

  event = {}
  ret = nil
  ZoneAclInit()
  zm = Ops.get_string(@current_zone, "masters", "")
  i = Builtins.findfirstof(zm, "{")
  zm = Builtins.substring(zm, Ops.add(i, 1)) if i != nil
  i = Builtins.findfirstof(zm, "}")
  zm = Builtins.substring(zm, 0, i) if i != nil
  @current_zone_masters = Builtins.splitstring(zm, ";")
  @current_zone_masters = Builtins.maplist(@current_zone_masters) do |m|
    Builtins.mergestring(Builtins.splitstring(m, " "), "")
  end
  @current_zone_masters = Builtins.filter(@current_zone_masters) do |m|
    m != ""
  end
  UI.ChangeWidget(
    Id("master"),
    :Value,
    Ops.get(@current_zone_masters, 0, "")
  )
  UI.ChangeWidget(Id("master"), :ValidChars, "0123456789.")
  while true
    event = UI.WaitForEvent
    ret = Ops.get(event, "ID")
    ZoneAclHandle(event)
    if ret == :abort
      if ReallyAbort()
        return :abort
      else
        next
      end
    end
    if ret == :back
      # fixing bug #45950, slave zone _MUST_ have master server
      if Builtins.size(@current_zone_masters) == 0
        if Popup.ContinueCancelHeadline(
            # TRANSLATORS: Popup error headline
            _("Missing Master Server"),
            # TRANSLATORS: Popup error text
            _(
              "Every slave zone must have its master server IP defined.\n" +
                "Configuration of a DNS server without a master server would fail.\n" +
                "If you continue, the current zone will be removed."
            )
          )
          # removing current zone - zone needs master server
          @zones = Builtins.filter(@zones) { |z| z != @current_zone }
          DnsServer.StoreZones(@zones)
          break
        else
          next
        end
      end

      break
    end
    if ret == :next
      if false
        # TRANSLATORS: A popup error message
        Report.Error(_("No master DNS server defined."))
        next
      else
        # controlling sever name, IP
        master_server = Convert.to_string(
          UI.QueryWidget(Id("master"), :Value)
        )
        # Master server must be only IP
        if IP.Check4(master_server) != true
          UI.SetFocus(Id("master"))
          # A popup error message
          Popup.Error(
            _("The specified master name server is not a valid IP address.")
          )
          next
        end
        break
      end
    end
  end
  if ret == :next
    Ops.set(
      @current_zone,
      "masters",
      Builtins.sformat(
        "{ %1; }",
        Convert.to_string(UI.QueryWidget(Id("master"), :Value))
      )
    )
    ZoneAclStore()
    Ops.set(@current_zone, "modified", true)
    DnsServer.StoreCurrentZone(@current_zone)
    DnsServer.StoreZone
    DnsServer.SetModified
  end
  @was_editing_zone = true
  Convert.to_symbol(ret)
end

- (Object) runStubZoneTabDialog

Dialog Zone Editor - Stub

Returns:

  • (Object)

    dialog result for wizard



2844
2845
2846
2847
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2844

def runStubZoneTabDialog
  @was_editing_zone = true
  runSlaveZoneTabDialog
end

- (Object) StoreMasterZoneTab(dialog)



2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2360

def StoreMasterZoneTab(dialog)
  if dialog == "basics"
    StoreZoneBasicsTab()
  elsif dialog == "name_servers"
    StoreNsListTab()
  elsif dialog == "mail_servers"
    StoreMxListTab()
  elsif dialog == "soa_settings"
    StoreSoaTab()
  elsif dialog == "records"
    StoreZoneRecordsTab()
  end

  nil
end

- (Object) StoreMxListTab

Store settings of a tab of a dialog



820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
# File '../../src/include/dns-server/dialog-masterzone.rb', line 820

def StoreMxListTab
  zone_name = Ops.get_string(@current_zone, "zone", "")
  records = Builtins.filter(Ops.get_list(@current_zone, "records", [])) do |r|
    !(Ops.get_string(r, "type", "") == "MX" &&
      (Ops.get_string(r, "key", "") == Builtins.sformat("%1.", zone_name) ||
        Ops.get_string(r, "key", "") == zone_name ||
        Ops.get_string(r, "key", "") == "@"))
  end
  new_rec = Builtins.maplist(@current_zone_mx) do |a|
    {
      "key"   => Builtins.sformat("%1.", zone_name),
      "type"  => "MX",
      "value" => a
    }
  end
  Ops.set(@current_zone, "records", Builtins.merge(new_rec, records))

  nil
end

- (Object) StoreNsListTab

Store settings of a tab of a dialog



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

def StoreNsListTab
  zone_name = Ops.get_string(@current_zone, "zone", "")
  records = Builtins.filter(Ops.get_list(@current_zone, "records", [])) do |r|
    !(Ops.get_string(r, "type", "") == "NS" &&
      (Ops.get_string(r, "key", "") == Builtins.sformat("%1.", zone_name) ||
        Ops.get_string(r, "key", "") == zone_name ||
        Ops.get_string(r, "key", "") == "@"))
  end
  new_rec = Builtins.maplist(@current_zone_ns) do |a|
    {
      "key"   => Builtins.sformat("%1.", zone_name),
      "type"  => "NS",
      "value" => a
    }
  end
  Ops.set(@current_zone, "records", Builtins.merge(new_rec, records))

  nil
end

- (Object) StoreSoaTab

Store SOA dialog settings



1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1109

def StoreSoaTab
  @current_zone['ttl'] = "%{ttl_value}%{ttl_units}" % {
    :ttl_value => UI.QueryWidget(Id('zone_settings_ttl_value'), :Value),
    :ttl_units => UI.QueryWidget(Id('zone_settings_ttl_units'), :Value)
  }

  soa_update = {
    'serial' => UI.QueryWidget(Id('zone_settings_serial'), :Value),
    'refresh' => "%{refresh_value}%{refresh_units}" % {
      :refresh_value => UI.QueryWidget(Id('zone_settings_refresh_value'), :Value),
      :refresh_units => UI.QueryWidget(Id('zone_settings_refresh_units'), :Value)
    },
    'retry' => "%{retry_value}%{retry_units}" % {
      :retry_value => UI.QueryWidget(Id('zone_settings_retry_value'), :Value),
      :retry_units => UI.QueryWidget(Id('zone_settings_retry_units'), :Value)
    },
    'expiry' => "%{expiry_value}%{expiry_units}" % {
      :expiry_value => UI.QueryWidget(Id('zone_settings_expiry_value'), :Value),
      :expiry_units => UI.QueryWidget(Id('zone_settings_expiry_units'), :Value)
    },
    'minimum' => "%{minimum_value}%{minimum_units}" % {
      :minimum_value => UI.QueryWidget(Id('zone_settings_minimum_value'), :Value),
      :minimum_units => UI.QueryWidget(Id('zone_settings_minimum_units'), :Value)
    }
  }

  @current_zone['soa'] ||= {}
  @current_zone['soa'].merge!(soa_update)

  @current_zone['update_actions'] ||= []
  @current_zone['update_actions'] << {
    'operation' => 'add',
    'type'      => 'SOA',
    'key'       => @current_zone['zone'] + '.',
    'value'     => [
                     @current_zone['soa'].fetch('server',  SOADefaults::DNS_SERVER),
                     @current_zone['soa'].fetch('mail',    SOADefaults::EMAIL_ADDRESS),
                     @current_zone['soa'].fetch('serial',  SOADefaults::SERIAL),
                     @current_zone['soa'].fetch('refresh', SOADefaults::REFRESH),
                     @current_zone['soa'].fetch('retry',   SOADefaults::RETRY),
                     @current_zone['soa'].fetch('expiry',  SOADefaults::EXPIRY),
                     @current_zone['soa'].fetch('minimum', SOADefaults::MINIMUM)
                   ].join(' ')
  }
end

- (Object) StoreZoneBasicsTab

Store settings of a tab of a dialog



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
# File '../../src/include/dns-server/dialog-masterzone.rb', line 410

def StoreZoneBasicsTab
  Ops.set(
    @current_zone,
    "options",
    Builtins.maplist(Ops.get_list(@current_zone, "options", [])) do |m|
      if Ops.get_string(m, "key", "") == "allow-update" &&
          Builtins.regexpmatch(
            Ops.get_string(m, "value", ""),
            "^.*key[ \t]+[^ \t;]+[ \t;]+.*$"
          )
        next {}
      end
      deep_copy(m)
    end
  )
  Ops.set(
    @current_zone,
    "options",
    Builtins.filter(Ops.get_list(@current_zone, "options", [])) do |m|
      m != {}
    end
  )

  if DnsServer.ExpertUI
    key = Convert.to_string(UI.QueryWidget(Id("ddns_key"), :Value))
    allowed = Convert.to_boolean(UI.QueryWidget(Id("allow_ddns"), :Value))
    if allowed
      Ops.set(
        @current_zone,
        "options",
        Builtins.add(
          Ops.get_list(@current_zone, "options", []),
          {
            "key"   => "allow-update",
            "value" => Builtins.sformat("{ key %1; }", key)
          }
        )
      )
    end
  end
  ZoneAclStore()
  ZoneConnectedWithStore()

  nil
end

- (Object) StoreZoneRecordsTab

Store settings of a tab of a dialog



1695
1696
1697
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1695

def StoreZoneRecordsTab
  nil
end

- (Object) SwitchAndAdjustEditationWidgets(type, current_record, decoded_zone, zone)



2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2074

def SwitchAndAdjustEditationWidgets(type, current_record, decoded_zone, zone)
  current_record = deep_copy(current_record)
  new_rr_rp = GetEditationWidgets(type.value)

  key = Convert.to_string(UI.QueryWidget(Id("add_record_name"), :Value))
  val = Convert.to_string(UI.QueryWidget(Id("add_record_val"), :Value))

  if !Builtins.haskey(current_record, "key")
    Ops.set(current_record, "key", key)
  end
  if !Builtins.haskey(current_record, "value")
    Ops.set(current_record, "value", val)
  end

  # Replacing the editation widgets
  if new_rr_rp != @current_rr_rp
    @current_rr_rp = deep_copy(new_rr_rp)
    UI.ReplaceWidget(Id("rr_rp"), @current_rr_rp)
    @last_add_record_type = type.value
    UI.ChangeWidget(Id("add_record_type"), :Value, type.value)
    UI.SetFocus(Id("add_record_type"))
  end

  decoded_zone_ref = arg_ref(decoded_zone.value)
  zone_ref = arg_ref(zone.value)
  AdjustEditationWidgets(current_record, decoded_zone_ref, zone_ref)
  decoded_zone.value = decoded_zone_ref.value
  zone.value = zone_ref.value

  nil
end

- (Object) TransformRecord(record)

Transform a given key/value by adding the ending dot if it ends with the current zone name



1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1984

def TransformRecord(record)
  zone_regexp = Builtins.mergestring(
    Builtins.splitstring(Ops.get_string(@current_zone, "zone", ""), "."),
    "\\."
  )

  # key terminated with zone name without dot
  if Builtins.regexpmatch(
      record,
      Ops.add(Ops.add(".*\\.", zone_regexp), "$")
    )
    record = Ops.add(record, ".")
  end

  record
end

- (Object) ValidateMasterZoneTab(dialog, event)



2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
# File '../../src/include/dns-server/dialog-masterzone.rb', line 2393

def ValidateMasterZoneTab(dialog, event)
  event = deep_copy(event)
  ret = true
  if dialog == "basics"
    ret = true
  elsif dialog == "name_servers"
    ret = true
  elsif dialog == "mail_servers"
    ret = true
  elsif dialog == "soa_settings"
    ret = ValidateSoaTab(event)
  elsif dialog == "records"
    ret = true
  end
  ret
end

- (Object) ValidateSoaTab(event)



1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1160

def ValidateSoaTab(event)
  serial = Convert.to_string(
    UI.QueryWidget(Id("zone_settings_serial"), :Value)
  )
  if serial == ""
    UI.SetFocus(Id("zone_settings_serial"))
    Popup.Error(_("The serial number of the zone must be specified."))
    return false
  end
  if Ops.greater_than(Builtins.size(serial), 10)
    UI.SetFocus(Id("zone_settings_serial"))
    Popup.Error(
      Builtins.sformat(
        # error report, %1 is an integer
        _("The serial number must be no more than %1 digits long."),
        10
      )
    )
    return false
  end
  refresh_str = Builtins.sformat(
    "%1%2",
    UI.QueryWidget(Id("zone_settings_refresh_value"), :Value),
    UI.QueryWidget(Id("zone_settings_refresh_units"), :Value)
  )
  expiry_str = Builtins.sformat(
    "%1%2",
    UI.QueryWidget(Id("zone_settings_expiry_value"), :Value),
    UI.QueryWidget(Id("zone_settings_expiry_units"), :Value)
  )
  refresh = Builtins.tointeger(DnsRoutines.NormalizeTime(refresh_str))
  expiry = Builtins.tointeger(DnsRoutines.NormalizeTime(expiry_str))
  if Ops.less_than(expiry, refresh)
    # TRANSLATORS: A popup with question, current setting could produce errors
    if !Popup.YesNo(
        _(
          "The expiration time-out is higher than the time period\n" +
            "of zone refreshes. The zone will not be reachable\n" +
            "from slave name servers all the time.\n" +
            "Continue?"
        )
      )
      return false
    end
  end
  true
end

- (Object) ValidTextRecordName(name)

Checks whether a given string is a valid TXT record key (name)



1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
# File '../../src/include/dns-server/dialog-masterzone.rb', line 1700

def ValidTextRecordName(name)
  # Checking the length
  if name == nil || name == ""
    Builtins.y2warning("TXT record key must not be empty")
    return false
  end

  # Checking for forbidden '='
  if Builtins.regexpmatch(name, "=")
    Builtins.y2warning(
      "TXT record key %1 must not contain a '=' character.",
      name
    )
    return false
  end

  # only US-ASCII characters are allowed
  if Builtins.size(name) != Builtins.size(Builtins.toascii(name))
    Builtins.y2warning(
      "TXT record key %1 contains some non US-ASCII characters",
      name
    )
    return false
  end

  true
end

- (Object) ZoneAclHandle(event)



364
365
366
367
368
369
370
371
372
373
374
# File '../../src/include/dns-server/dialog-masterzone.rb', line 364

def ZoneAclHandle(event)
  event = deep_copy(event)
  ret = Ops.get(event, "ID")
  UI.ChangeWidget(
    Id("acls_list"),
    :Enabled,
    Convert.to_boolean(UI.QueryWidget(Id("enable_zone_transport"), :Value))
  )

  nil
end

- (Object) ZoneAclInit



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
# File '../../src/include/dns-server/dialog-masterzone.rb', line 210

def ZoneAclInit
  allowed = false
  keys = []
  Builtins.foreach(Ops.get_list(@current_zone, "options", [])) do |m|
    if Ops.get_string(m, "key", "") == "allow-transfer" && !allowed
      key = Builtins.regexpsub(
        Ops.get_string(m, "value", ""),
        "^.*\\{[ \t]*(.*)[ \t]*\\}.*$",
        "\\1"
      )
      if key != nil
        keys = Builtins.splitstring(key, " ;")
        keys = Builtins.filter(keys) { |k| k != "" }
        allowed = true
      end
    end
  end

  # bug #203910
  # no keys in allow-transfer means that transfer is allowed for all
  # explicitly say that
  if Builtins.size(keys) == 0
    allowed = true
    keys = ["any"] 
    # the only way how to disable the transfer is to set "allow-transfer { none; };"
    # "none" must be alone, remove it from the list, it is not present in the multi-sel box
  elsif Builtins.size(keys) == 1 && keys == ["none"]
    allowed = false
    keys = []
  end

  UI.ChangeWidget(Id("enable_zone_transport"), :Value, allowed)
  UI.ChangeWidget(Id("acls_list"), :Enabled, allowed)
  UI.ChangeWidget(Id("acls_list"), :SelectedItems, keys) if allowed

  nil
end

- (Object) ZoneAclStore



271
272
273
274
275
276
277
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
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
# File '../../src/include/dns-server/dialog-masterzone.rb', line 271

def ZoneAclStore
  Ops.set(
    @current_zone,
    "options",
    Builtins.maplist(Ops.get_list(@current_zone, "options", [])) do |m|
      if Ops.get_string(m, "key", "") == "allow-transfer" &&
          Builtins.regexpmatch(
            Ops.get_string(m, "value", ""),
            "^.*\\{[ \t]*(.*)[ \t]*\\}.*$"
          )
        next {}
      end
      deep_copy(m)
    end
  )
  Ops.set(
    @current_zone,
    "options",
    Builtins.filter(Ops.get_list(@current_zone, "options", [])) do |m|
      m != {}
    end
  )
  keys = Convert.convert(
    UI.QueryWidget(Id("acls_list"), :SelectedItems),
    :from => "any",
    :to   => "list <string>"
  )
  allowed = Convert.to_boolean(
    UI.QueryWidget(Id("enable_zone_transport"), :Value)
  )


  # bug #203910
  # always store the allow-transfer option explicitly
  # if zone transfer is not allowed, set allow-transfer to { none; };
  if !allowed
    keys = ["none"]
    Builtins.y2milestone("ZoneTransfer not allowed, keys: %1", keys) 
    # otherwise set selected keys
  else
    Builtins.y2milestone("Zone transfer is allowed, keys: %1", keys)
    # no ACL selected means "any" is selected by default
    keys = ["any"] if Builtins.size(keys) == 0
  end

  # store either "none" (transfer disabled) or "all" (transfer enabled)
  # or selected ACLs (transfer enabled for selected ACLs)
  Ops.set(
    @current_zone,
    "options",
    Builtins.add(
      Ops.get_list(@current_zone, "options", []),
      {
        "key"   => "allow-transfer",
        "value" => Builtins.sformat(
          "{ %1; }",
          Builtins.mergestring(keys, "; ")
        )
      }
    )
  )

  nil
end

- (Object) ZoneConnectedWithInit



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File '../../src/include/dns-server/dialog-masterzone.rb', line 248

def ZoneConnectedWithInit
  if DnsServerHelperFunctions.IsReverseZone(
      Ops.get_string(@current_zone, "zone", "")
    ) == true
    if Ops.get_string(@current_zone, "connected_with", "") != "" &&
        Builtins.contains(
          @available_zones_to_connect,
          Ops.get_string(@current_zone, "connected_with", "")
        )
      UI.ChangeWidget(
        Id("generate_from_forward_zone_sel"),
        :Value,
        Ops.get_string(@current_zone, "connected_with", "")
      )
      UI.ChangeWidget(Id("generate_from_forward_zone"), :Value, true)
    else
      UI.ChangeWidget(Id("generate_from_forward_zone"), :Value, false)
    end
  end

  nil
end

- (Object) ZoneConnectedWithStore



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
# File '../../src/include/dns-server/dialog-masterzone.rb', line 336

def ZoneConnectedWithStore
  if DnsServerHelperFunctions.IsReverseZone(
      Ops.get_string(@current_zone, "zone", "")
    )
    if Convert.to_boolean(
        UI.QueryWidget(Id("generate_from_forward_zone"), :Value)
      ) == true
      Ops.set(
        @current_zone,
        "connected_with",
        Convert.to_string(
          UI.QueryWidget(Id("generate_from_forward_zone_sel"), :Value)
        )
      )
    else
      Ops.set(@current_zone, "connected_with", "")
    end

    Builtins.y2milestone(
      "Zone '%1' connected with '%2'",
      Ops.get_string(@current_zone, "zone", ""),
      Ops.get_string(@current_zone, "connected_with", "")
    )
  end

  nil
end