Class: Yast::HttpServerWidgetsClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/HttpServerWidgets.rb

Instance Method Summary (collapse)

Instance Method Details

- (Hash{String => String}) AskListen(network, port)

Show a popup for editing Listen statement.

Parameters:

  • network (String)

    string initial value for the network part of the statement If empty or _("All Addresses"), considered for all Listen for all interfaces.

  • port (String)

    string initial value for a port number

Returns:

  • (Hash{String => String})

    the new Listen statement or nil if Cancel was pressed



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
# File '../../src/modules/HttpServerWidgets.rb', line 2411

def AskListen(network, port)
  # translators: all network addresses Listen type
  adr_type = network == _("All Addresses") || network == ""
  port = "" if port == nil

  # translators: Listen type for all addresses;
  aa = _("All Addresses")

  ips = Builtins.union([aa], Builtins.maplist(HttpServer.ip2device) do |ip, dev|
    if IP.Check6(ip)
      next Builtins.sformat("[%1]", ip)
    else
      next ip
    end
  end)
  UI.OpenDialog(
    VBox(
      TextEntry(Id(:port), Label.Port, port),
      # translators: combo box label for list of configured IPs
      Left(
        ComboBox(Id("address"), Opt(:editable), _("Network &Address:"), ips)
      ),
      VSpacing(),
      ButtonBox(
        PushButton(Id(:ok), Label.OKButton),
        PushButton(Id(:cancel), Label.CancelButton)
      )
    )
  )

  UI.ChangeWidget(Id("address"), :Value, network) if !adr_type

  ret = nil
  res = {}
  begin
    ret = Convert.to_symbol(UI.UserInput)

    if ret == :ok
      Ops.set(
        res,
        "ADDRESS",
        Convert.to_string(UI.QueryWidget(Id("address"), :Value))
      )
      Ops.set(
        res,
        "PORT",
        Convert.to_string(UI.QueryWidget(Id(:port), :Value))
      )
      if Ops.get(res, "ADDRESS") == aa
        # on all addresses, cleanup the value
        Ops.set(res, "ADDRESS", "")
      else
        # validate
        if !validate_serverip("address", nil, nil)
          ret = nil
          next
        end
      end

      # validation
      if !Builtins.regexpmatch(
          Ops.get(res, "PORT", ""),
          "^[ \t]*[0-9]+[ \t]*$"
        )
        # translators: error message when validating Listen statement
        Popup.Error(_("Invalid port number."))
        ret = nil
        next
      end
    end
  end while ret != :ok && ret != :cancel

  res = nil if ret == :cancel

  UI.CloseDialog

  deep_copy(res)
end

- (Hash{String => String}) AskNewInfo(servername, ip)

Returns servername:ip

Parameters:

  • servername (String)

    string

  • ip (String)

    string

Returns:

  • (Hash{String => String})

    servername:ip



1152
1153
1154
1155
1156
1157
1158
1159
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
1207
1208
1209
1210
1211
1212
1213
1214
1215
# File '../../src/modules/HttpServerWidgets.rb', line 1152

def AskNewInfo(servername, ip)
  if Builtins.size(servername) == 0
    # suggest reasonable value
    servername = Hostname.MergeFQ(DNS.hostname, DNS.domain) 
    # maybe we should check, if there is such host already
  end

  ips = Builtins.maplist(HttpServer.ip2device) { |ip2, dev| ip2 }
  UI.OpenDialog(
    VBox(
      # translators: popup description on changing the default host
      # the old default host is changed to a virtual one, but it may
      # miss some needed information. the popup asks to set them.
      Label(
        _(
          "The current default host will be replaced by \n" +
            "the new host and will become a virtual host.\n" +
            "\n" +
            "However, the current default host does not have\n" +
            "the IP address or the server name specified.\n" +
            "Therefore, it is not possible to use it as \n" +
            "a virtual host. Verify the suggested values below \n" +
            "and click OK to continue with the default host\n" +
            "switch. Otherwise click Cancel not to change\n" +
            "the default host.\n"
        )
      ),
      # translators: textentry to set the host name
      TextEntry(Id(:servername), _("Server &Name:"), servername),
      # translators: textentry to set the host IP address
      Left(
        ComboBox(Id("ip"), Opt(:editable), _("Server &IP Address:"), ips)
      ),
      VSpacing(0.5),
      HBox(
        PushButton(Id(:ok), Opt(:default), Label.ContinueButton),
        PushButton(Id(:cancel), Label.CancelButton)
      )
    )
  )
  UI.SetFocus(:servername)
  UI.ChangeWidget(Id("ip"), :Value, ip)

  ret = nil
  begin
    ret = Convert.to_symbol(UI.UserInput)
    break if ret == :cancel

    servername = Punycode.EncodeDomainName(
      Convert.to_string(UI.QueryWidget(:servername, :Value))
    )
    # it must be `ok
    next if !validate_servername(servername)


    next if !validate_serverip("ip", nil, nil)
    ip = Convert.to_string(UI.QueryWidget(Id("ip"), :Value))

    break
  end while ret != nil

  UI.CloseDialog
  ret != :cancel ? { "name" => servername, "ip" => ip } : nil
end

- (Object) changeButtons(stat)



1226
1227
1228
1229
1230
1231
1232
# File '../../src/modules/HttpServerWidgets.rb', line 1226

def changeButtons(stat)
  UI.ChangeWidget(:set_default, :Enabled, stat)
  UI.ChangeWidget(:_tp_delete, :Enabled, stat)
  UI.ChangeWidget(:_tp_edit, :Enabled, stat)

  nil
end

- (Object) changeVHostPopup(value)



1693
1694
1695
1696
1697
1698
1699
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
1727
1728
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
# File '../../src/modules/HttpServerWidgets.rb', line 1693

def changeVHostPopup(value)
  vhost = ""
  items = Builtins.maplist(HttpServer.ip2device) do |ip, dev|
    if IP.Check6(ip)
      next Builtins.sformat("[%1]", ip)
    else
      next ip
    end
  end
  UI.OpenDialog(
    RadioButtonGroup(
      Id(:rb),
      VBox(
        Left(
          RadioButton(
            Id(:all_addr),
            Opt(:notify),
            _("All addresses (*)"),
            true
          )
        ),
        Left(RadioButton(Id(:multiselect), Opt(:notify), "")),
        MultiSelectionBox(Id(:ipaddress), _("IP Addresses"), items),
        Left(RadioButton(Id(:custom), Opt(:notify), "")),
        TextEntry(Id(:serv_name), _("ServerName")),
        VSpacing(),
        ButtonBox(
          PushButton(Id(:ok), Label.OKButton),
          PushButton(Id(:cancel), Label.CancelButton)
        )
      )
    )
  )
  if value == "*" || value == ""
    UI.ChangeWidget(:serv_name, :Value, value)
  else
    it = []
    Builtins.foreach(
      Convert.convert(items, :from => "list", :to => "list <string>")
    ) do |ip|
      it = Builtins.add(
        it,
        Item(
          Id(ip),
          ip,
          Builtins.contains(Builtins.splitstring(value, " "), ip)
        )
      )
    end
    unknown = false
    Builtins.foreach(Builtins.splitstring(value, " ")) do |ip|
      unknown = true if !Builtins.contains(items, ip)
    end
    if unknown
      UI.ChangeWidget(:serv_name, :Value, value)
      UI.ChangeWidget(:rb, :CurrentButton, :custom)
    else
      UI.ChangeWidget(:ipaddress, :Items, it)
      UI.ChangeWidget(:rb, :CurrentButton, :multiselect)
    end
  end

  ret = nil
  begin
    rb = Convert.to_symbol(UI.QueryWidget(Id(:rb), :CurrentButton))
    UI.ChangeWidget(Id(:ipaddress), :Enabled, rb == :multiselect)
    UI.ChangeWidget(Id(:serv_name), :Enabled, rb == :custom)
    ret = Convert.to_symbol(UI.UserInput)
  end while ret != :ok && ret != :cancel
  if ret == :ok
    case Convert.to_symbol(UI.QueryWidget(Id(:rb), :CurrentButton))
      when :all_addr
        vhost = "*"
      when :multiselect
        @selected = Convert.convert(
          UI.QueryWidget(Id(:ipaddress), :SelectedItems),
          :from => "any",
          :to   => "list <string>"
        )
        vhost = Builtins.mergestring(@selected, " ")
      when :custom
        vhost = Convert.to_string(UI.QueryWidget(Id(:serv_name), :Value))
      else
        vhost = ""
        Builtins.y2warning("unrecognized selection")
    end
  end
  UI.CloseDialog
  vhost
end

- (Boolean) CheckCommonServerCertificate

Validate certificate

Returns:

  • (Boolean)

    certificate valid



810
811
812
813
814
815
816
817
818
819
820
# File '../../src/modules/HttpServerWidgets.rb', line 810

def CheckCommonServerCertificate
  s = Convert.to_integer(
    SCR.Read(path(".target.size"), "/etc/ssl/servercerts/servercert.pem")
  )
  return false if Ops.less_or_equal(s, 0)
  s = Convert.to_integer(
    SCR.Read(path(".target.size"), "/etc/ssl/servercerts/serverkey.pem")
  )
  return false if Ops.less_or_equal(s, 0)
  true
end

- (Object) checkLoadedModuleFor(new)



2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
# File '../../src/modules/HttpServerWidgets.rb', line 2528

def checkLoadedModuleFor(new)
  loaded = YaST::HTTPDData.GetModuleList
  Builtins.foreach(YaST::HTTPDData.GetKnownModules) do |value|
    if Builtins.contains(Ops.get_list(value, "directives", []), new) &&
        !Builtins.contains(loaded, Ops.get_string(value, "name", ""))
      YaST::HTTPDData.ModifyModuleList(
        [Ops.get_string(value, "name", "")],
        true
      )
      Builtins.y2milestone(
        "loading module mod_%1 ...",
        Ops.get_string(value, "name", "")
      )
    end
  end

  nil
end

- (Object) DefaultHostPopupInit(option_id, option_type)

Fallback initialization function of a table entry / popup

Parameters:

  • option_id (Object)

    any unique option id

  • option_type (String)

    string the name of the key in the option list description



2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
# File '../../src/modules/HttpServerWidgets.rb', line 2885

def DefaultHostPopupInit(option_id, option_type)
  option_id = deep_copy(option_id)
  value = Ops.get_string(
    @host_options,
    [Convert.to_integer(option_id), "VALUE"],
    ""
  )

  if option_type == "VirtualByName"
    UI.ChangeWidget(Id(option_type), :CurrentButton, value)
  elsif option_type == "ServerName"
    UI.ChangeWidget(
      Id(option_type),
      :Value,
      Punycode.DecodeDomainName(Convert.to_string(value))
    )
  else
    UI.ChangeWidget(Id(option_type), :Value, value)
  end

  nil
end

- (Object) DefaultHostPopupStore(option_id, option_type)

Fallback store function of a table entry / popup

Parameters:

  • option_id (Object)

    any option id

  • option_type (String)

    string option key



2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
# File '../../src/modules/HttpServerWidgets.rb', line 2911

def DefaultHostPopupStore(option_id, option_type)
  option_id = deep_copy(option_id)
  property = option_type == "VirtualByName" ? :CurrentButton : :Value

  if option_id == nil
    # new option
    Ops.set(@host_options, @option_counter, { "KEY" => option_type })
    option_id = @option_counter
    @option_counter = Ops.add(@option_counter, 1)
  end
  value = Convert.to_string(UI.QueryWidget(Id(option_type), property))
  value = Punycode.EncodeDomainName(value) if option_type == "ServerName"
  Ops.set(@host_options, [Convert.to_integer(option_id), "VALUE"], value)
  HttpServer.modified = true

  nil
end

- (Object) DirInit(widget)

Initialize directory table

Parameters:

  • widget (String)

    string



1459
1460
1461
1462
1463
1464
# File '../../src/modules/HttpServerWidgets.rb', line 1459

def DirInit(widget)
  TablePopup.TableInit(@dirwidget, widget)
  UI.ChangeWidget(:dir_name, :Value, @dir_value)

  nil
end

- (Object) DirPopupInit(option_id, option_type)

Initialize directory popup

Parameters:

  • option_id (Object)

    any

  • option_type (String)

    string



1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
# File '../../src/modules/HttpServerWidgets.rb', line 1508

def DirPopupInit(option_id, option_type)
  option_id = deep_copy(option_id)
  value = Ops.get_string(
    @host_options,
    [Convert.to_integer(option_id), "VALUE"],
    ""
  )

  nil
end

- (Object) DirStore(key, event)

Store directory map

Parameters:

  • key (String)

    string

  • event (Hash)

    map



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
# File '../../src/modules/HttpServerWidgets.rb', line 1523

def DirStore(key, event)
  event = deep_copy(event)
  options = []
  new_dir = Convert.to_string(UI.QueryWidget(:dir_name, :Value))
  dir_before = false
  host = YaST::HTTPDData.GetHost(@currenthost)
  Builtins.foreach(host) do |option|
    if Ops.get_string(option, "KEY", "unknown") == "_SECTION" &&
        Ops.get_string(option, "SECTIONNAME", "unknown") == "Directory" &&
        Ops.get_string(option, "SECTIONPARAM", "unknown") == @dir_value
      dir_before = true
      newlist = []
      Builtins.foreach(@host_options) do |key2, value|
        newlist = Builtins.add(newlist, value)
      end
      Ops.set(option, "VALUE", newlist)
      Ops.set(option, "SECTIONPARAM", new_dir)
    end
    options = Builtins.add(options, option)
  end
  if !dir_before
    newlist = []
    Builtins.foreach(@host_options) do |key2, value|
      newlist = Builtins.add(newlist, value)
    end
    #		options = add(options, $["VALUE":newlist]);
    options = Builtins.add(
      host,
      {
        "KEY"          => "_SECTION",
        "SECTIONNAME"  => "Directory",
        "SECTIONPARAM" => new_dir,
        "VALUE"        => newlist
      }
    )
  end
  YaST::HTTPDData.ModifyHost(@currenthost, options)
  setHostOptions(nil)
  HttpServer.modified = true

  nil
end

- (Array) DirTableContents(descr)

Contents of host table

Parameters:

  • descr (Hash)

    map

Returns:

  • (Array)

    host contents



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
# File '../../src/modules/HttpServerWidgets.rb', line 2992

def DirTableContents(descr)
  descr = deep_copy(descr)
  if @host_options == nil
    # fill the data
    @option_counter = 0
    @host_options = {}
    @deleted_options = []
    res = []

    host = YaST::HTTPDData.GetHost(@currenthost)
    Builtins.foreach(host) do |option|
      key = Ops.get_string(option, "KEY", "unknown")
      if Ops.get_string(option, "KEY", "unknown") == "_SECTION" &&
          Ops.get_string(option, "SECTIONNAME", "unknown") == "Directory" &&
          Ops.get_string(option, "SECTIONPARAM", "unknown") == @dir_value
        Builtins.foreach(Ops.get_list(option, "VALUE", [])) do |value|
          if !(Ops.get_string(value, "KEY", "") == "_SECTION" &&
              Ops.get_string(value, "SECTIONPARAM", "") == "SSL")
            Ops.set(@host_options, @option_counter, value)
            res = Builtins.add(res, @option_counter)
            @option_counter = Ops.add(@option_counter, 1)
          end
        end
      else
        @option_counter = Ops.add(@option_counter, 1)
        next
      end
    end
    return deep_copy(res)
  else
    # just generate the list of ids
    return Builtins.maplist(@host_options) { |id, value| id }
  end
end

- (Object) get_host_value(keyword, host, defaultvalue)

Get host value

Parameters:

  • keyword (String)

    string

  • host (Array<Hash{String => Object>})

    list< map<string, any> >

  • defaultvalue (Object)

    any

Returns:

  • (Object)

    host value



827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
# File '../../src/modules/HttpServerWidgets.rb', line 827

def get_host_value(keyword, host, defaultvalue)
  host = deep_copy(host)
  defaultvalue = deep_copy(defaultvalue)
  res = deep_copy(defaultvalue)

  Builtins.foreach(host) do |option|
    if Ops.get(option, "KEY") == keyword
      res = Ops.get(option, "VALUE", defaultvalue)
      raise Break
    end
  end

  # drop quotes, if exist
  if Ops.is_string?(res)
    res = Builtins.regexpsub(
      Convert.to_string(res),
      "\"?([^\"]*)\"?",
      "\\1"
    )
  end

  deep_copy(res)
end

- (Hash) getDirOptions

Get directory options

Returns:

  • (Hash)

    directory options



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
# File '../../src/modules/HttpServerWidgets.rb', line 1468

def getDirOptions
  used = {}
  directives = []
  Builtins.foreach(YaST::HTTPDData.GetKnownModules) do |mod|
    Builtins.foreach(Ops.get_list(mod, "directives", [])) do |option|
      opt_list = []
      Builtins.foreach(Ops.get_list(option, "values", [])) do |value|
        opt_list = Builtins.add(opt_list, [value])
      end
      if Builtins.contains(Ops.get_list(option, "context", []), "Directory") &&
          !Builtins.contains(Ops.get_list(option, "context", []), "SSL")
        if opt_list != []
          Ops.set(
            used,
            Ops.get_string(option, "option", ""),
            { "popup" => { "widget" => :combobox, "items" => opt_list } }
          )
        else
          Ops.set(used, Ops.get_string(option, "option", ""), {})
        end
      end
    end
  end
  deep_copy(used)
end

- (Hash) getHostOptions(mainhost)

Get host options

Returns:

  • (Hash)

    host options



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
# File '../../src/modules/HttpServerWidgets.rb', line 1400

def getHostOptions(mainhost)
  used = {}
  directives = []
  Builtins.foreach(YaST::HTTPDData.GetKnownModules) do |mod|
    Builtins.foreach(Ops.get_list(mod, "directives", [])) do |option|
      opt_list = []
      Builtins.foreach(Ops.get_list(option, "values", [])) do |value|
        opt_list = Builtins.add(opt_list, [value])
      end
      if Builtins.contains(Ops.get_list(option, "context", []), "Server") &&
          !Builtins.contains(Ops.get_list(option, "context", []), "SSL")
        if opt_list != []
          Ops.set(
            used,
            Ops.get_string(option, "option", ""),
            { "popup" => { "widget" => :combobox, "items" => opt_list } }
          )
        else
          Ops.set(used, Ops.get_string(option, "option", ""), {})
        end
      end
    end
  end
  if mainhost
    used = Builtins.union(used, Builtins.filter(@popups) do |key, val|
      key != "SSL"
    end)
  else
    used = Builtins.union(used, @popups)
  end
  deep_copy(used)
end

- (Object) getServiceAutoStart



3568
3569
3570
3571
3572
3573
3574
# File '../../src/modules/HttpServerWidgets.rb', line 3568

def getServiceAutoStart
  if YaST::HTTPDData.GetService != nil && YaST::HTTPDData.GetService
    return true
  else
    return false
  end
end

- (Object) getSSLOptions



1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
# File '../../src/modules/HttpServerWidgets.rb', line 1432

def getSSLOptions
  used = {}
  directives = []
  Builtins.foreach(YaST::HTTPDData.GetKnownModules) do |mod|
    Builtins.foreach(Ops.get_list(mod, "directives", [])) do |option|
      opt_list = []
      Builtins.foreach(Ops.get_list(option, "values", [])) do |value|
        opt_list = Builtins.add(opt_list, [value])
      end
      if Builtins.contains(Ops.get_list(option, "context", []), "SSL")
        if opt_list != []
          Ops.set(
            used,
            Ops.get_string(option, "option", ""),
            { "popup" => { "widget" => :combobox, "items" => opt_list } }
          )
        else
          Ops.set(used, Ops.get_string(option, "option", ""), {})
        end
      end
    end
  end
  deep_copy(used)
end

- (Symbol) handleDirTable(key, event)

Handle directory table

Parameters:

  • key (String)

    string

  • event (Hash)

    map

Returns:

  • (Symbol)

    tablehandle



1498
1499
1500
1501
1502
1503
# File '../../src/modules/HttpServerWidgets.rb', line 1498

def handleDirTable(key, event)
  event = deep_copy(event)
  @host_options = nil if Ops.get(event, "ID") == :back

  TablePopup.TableHandle(@dirwidget, key, event)
end

- (Symbol) handleExpertConf(key, event)

Handler for expert configuration

Parameters:

  • key (String)

    string

  • event (Hash)

    map

Returns:

  • (Symbol)

    (nil, `expert)



3559
3560
3561
3562
3563
3564
3565
3566
3567
# File '../../src/modules/HttpServerWidgets.rb', line 3559

def handleExpertConf(key, event)
  event = deep_copy(event)
  if Ops.get(event, "ID") == "expert_conf"
    @init_tab = "listen"
    return :expert
  else
    return nil
  end
end

- (Object) handleHostTable(key, event)

Handler for editing default host. Handles additional buttons, like logs and modules. Rest is passed to TablePopup::TableHandle.

@param [String] key the key modified @param [Hash] event event description @return [Symbol] the result of the handling



2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
# File '../../src/modules/HttpServerWidgets.rb', line 2850

def handleHostTable(key, event)
  event = deep_copy(event)
  if Ops.get_string(event, "EventType", "") == "WidgetEvent" &&
      Ops.get(event, "WidgetID") == :_tp_add
    @dir_value = ""
  else
    @dir_value = Ops.get_string(
      @host_options,
      [
        Convert.to_integer(UI.QueryWidget(:_tp_table, :CurrentItem)),
        "VALUE"
      ],
      ""
    )
  end

  # handle menu button entries
  # 	if( event["ID"]:nil == `show_access_log ) {
  # 	    return showAccessLogPopup( key, event );
  # 	}
  # 	else if( event["ID"]:nil == `show_error_log ) {
  # 	    return showErrorLogPopup( key, event );
  # 	}
  res = TablePopup.TableHandleWrapper(key, event)
  # 	if (update_contents)
  # 	{
  # 	    update_contents = false;
  # 	    TablePopup::TableInit( hostwidget, key);
  # 	}
  res
end

- (Symbol) handleListenSettings(key, event)

Handle function of a widget

Parameters:

  • key (String)

    any widget key of widget that is processed

  • event (Hash)

    map event that occured

Returns:

  • (Symbol)

    symbol for WS or nil



3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
# File '../../src/modules/HttpServerWidgets.rb', line 3288

def handleListenSettings(key, event)
  event = deep_copy(event)
  UI.SetFocus(Id(:listen))
  current = Convert.to_integer(UI.QueryWidget(Id(:listen), :CurrentItem))
  currentitem = current != nil ?
    Convert.to_term(UI.QueryWidget(Id(:listen), term(:Item, current))) :
    Item(-1, "", "")
  network = Ops.get_string(currentitem, 1)
  # translators: all network addresses Listen type
  network = "" if network == _("All Addresses")
  port = Ops.get_string(currentitem, 2, "")

  if Ops.get(event, "ID") == :add
    # translators: all network addresses Listen type
    res = AskListen(_("All Addresses"), "")
    if res != nil
      if false # FIXME: CreateListen error reporting
        # translators: error message for adding a new Listen statement
        Popup.Error(
          Builtins.sformat(_("The entry '%1' already exists."), res)
        )
      else
        #		  if (IP::Check6(res["ADDRESS"]:"")) res["ADDRESS"]=sformat("[%1]", res["ADDRESS"]:"");
        YaST::HTTPDData.CreateListen(
          Builtins.tointeger(Ops.get(res, "PORT", "80")),
          Builtins.tointeger(Ops.get(res, "PORT", "80")),
          Ops.get(res, "ADDRESS", "")
        )
        Builtins.y2internal("get %1", YaST::HTTPDData.GetCurrentListen)
        HttpServer.modified = true
      end
    end
  elsif Ops.get(event, "ID") == :delete
    validate = Builtins.size(YaST::HTTPDData.GetCurrentListen) != 0

    Builtins.y2debug("Validation result: %1", validate)

    if !validate
      # translators: error message
      Popup.Error(
        _(
          "The list of the ports to which the server should\nlisten cannot be empty."
        )
      )
      return nil
    end
    # remove the entry
    YaST::HTTPDData.DeleteListen(
      Builtins.tointeger(port),
      Builtins.tointeger(port),
      network
    )
    HttpServer.modified = true
  elsif Ops.get(event, "ID") == :edit
    res = AskListen(network, port)
    if res != nil
      # remove the old one
      YaST::HTTPDData.DeleteListen(
        Builtins.tointeger(port),
        Builtins.tointeger(port),
        network
      )
      # create the new one
      YaST::HTTPDData.CreateListen(
        Builtins.tointeger(Ops.get(res, "PORT", "80")),
        Builtins.tointeger(Ops.get(res, "PORT", "80")),
        Ops.get(res, "ADDRESS", "")
      )
      HttpServer.modified = true
    end
  end

  initListenSettings(nil)

  nil
end

- (Symbol) handleModules(key, event)

Handle function of a widget

Parameters:

  • key (String)

    any widget key of widget that is processed

  • event (Hash)

    any event that occured

Returns:

  • (Symbol)

    symbol for WS or nil



3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
# File '../../src/modules/HttpServerWidgets.rb', line 3128

def handleModules(key, event)
  event = deep_copy(event)
  UI.SetFocus(Id(:modules))
  if Ops.get(event, "ID") == :toggle
    ci = Convert.to_integer(UI.QueryWidget(Id(:modules), :CurrentItem))

    #	    string status = (string) select( (term) UI::QueryWidget( `id(`modules), `Item(ci) ), 2, _("Enabled") );
    status = Ops.get_locale(
      Convert.to_term(UI.QueryWidget(Id(:modules), term(:Item, ci))),
      2,
      _("Enabled")
    )
    #	    string name = (string) select( (term) UI::QueryWidget( `id(`modules), `Item(ci) ), 1, nil );
    name = Ops.get_string(
      Convert.to_term(UI.QueryWidget(Id(:modules), term(:Item, ci))),
      1,
      ""
    )
    Builtins.y2debug("Status of module: %1", status)
    if status == _("Enabled")
      status = _("Disabled")
    else
      status = _("Enabled")
    end
    UI.ChangeWidget(Id(:modules), term(:Item, ci, 1), status)
    Builtins.foreach(YaST::HTTPDData.GetKnownModules) do |mods|
      if name == Ops.get_string(mods, "name", "") && status == _("Enabled") &&
          Ops.get(mods, "exclude") != nil
        Builtins.foreach(Ops.get_list(mods, "exclude", [])) do |exclude|
          YaST::HTTPDData.ModifyModuleList([exclude], false)
          Builtins.foreach(
            Convert.to_list(UI.QueryWidget(Id(:modules), :Items))
          ) do |excl_row|
            if exclude == Ops.get_string(Convert.to_term(excl_row), 1, "")
              row = Ops.get_integer(
                Ops.get_term(Convert.to_term(excl_row), 0),
                0
              )
              if row != nil
                UI.ChangeWidget(
                  Id(:modules),
                  term(:Item, row, 1),
                  _("Disabled")
                )
              end
            end
          end
          Builtins.y2milestone(
            "Disabling module %1 excluded by %2",
            exclude,
            name
          )
        end
      end
    end
    YaST::HTTPDData.ModifyModuleList([name], status == _("Enabled"))
    HttpServer.modified = true
  elsif Ops.get(event, "ID") == :add_user
    module_dirs = Builtins.sformat(
      "/usr/lib*/apache2/ /usr/lib*/apache2-%1/",
      PackageSystem.Installed("apache2-prefork") ? "prefork" : "worker"
    )
    # list of all installed modules
    all_modules = Builtins.splitstring(
      Ops.get_string(
        Convert.convert(
          SCR.Execute(
            path(".target.bash_output"),
            Builtins.sformat(
              "ls %1|grep \".so$\"|cut -d. -f1|cut -d_ -f2-",
              module_dirs
            )
          ),
          :from => "any",
          :to   => "map <string, any>"
        ),
        "stdout",
        ""
      ),
      "\n"
    )
    existing = Builtins.maplist(YaST::HTTPDData.GetKnownModules) do |mod|
      Ops.get_locale(mod, "name", _("unknown"))
    end
    # extract unknown modules from all installed
    unknown_modules = []
    Builtins.foreach(all_modules) do |single_module|
      if !Builtins.contains(existing, single_module) && single_module != ""
        unknown_modules = Builtins.add(unknown_modules, single_module)
      end
    end
    Builtins.y2milestone("List of new modules %1", unknown_modules)
    UI.OpenDialog(
      VBox(
        # translators: combo box for selsect module from installed unknown modules
        ComboBox(Id(:mod), _("New Module &Name:"), unknown_modules),
        ButtonBox(
          PushButton(Id(:ok), Opt(:default), Label.OKButton),
          PushButton(Id(:cancel), Label.CancelButton)
        )
      )
    )

    UI.SetFocus(Id(:mod))

    ret = Convert.to_symbol(UI.UserInput)

    if ret == :ok
      mod = String.CutBlanks(
        Convert.to_string(UI.QueryWidget(Id(:mod), :Value))
      )
      if mod == ""
        # translators: error message
        Report.Error(_("A name for the module to add is required."))
      elsif Builtins.contains(existing, mod)
        # translators: error message
        Report.Error(_("The module is already in the list."))
      else
        YaST::HTTPDData.ModifyModuleList([mod], true)
        HttpServer.modified = true
      end
    end
    UI.CloseDialog
    initModules(nil)
  end

  nil
end

- (Symbol) handleOpenPort(key, event)

Handling open port

Parameters:

  • key (String)

    string

  • event (Hash)

    map

Returns:

  • (Symbol)

    nil



3429
3430
3431
3432
# File '../../src/modules/HttpServerWidgets.rb', line 3429

def handleOpenPort(key, event)
  event = deep_copy(event)
  nil
end

- (Symbol) handleServiceStatus(key, event)

Handling service status

Parameters:

  • key (String)

    string

  • event (Hash)

    map

Returns:

  • (Symbol)

    (overview_table,edit. `menu)



3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
# File '../../src/modules/HttpServerWidgets.rb', line 3396

def handleServiceStatus(key, event)
  event = deep_copy(event)
  # enable/disable overview widget
  enable = Convert.to_boolean(UI.QueryWidget(Id("enabled"), :Value))

  UI.ChangeWidget(:overview_table, :Enabled, enable)
  UI.ChangeWidget(:edit, :Enabled, enable)
  UI.ChangeWidget(:menu, :Enabled, enable)

  nil
end

- (Symbol) handleSSLTable(key, event)

Handle SSL widget table

Parameters:

  • key (String)

    string

  • event (Hash)

    map

Returns:

  • (Symbol)

    sslhandle



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
# File '../../src/modules/HttpServerWidgets.rb', line 2190

def handleSSLTable(key, event)
  event = deep_copy(event)
  if Ops.get(event, "ID") == :import_certificate
    #translators: dialog to set *.pem file with certificate
    pem = UI.AskForExistingFile("/", "*.pem", _("Select Certificate"))
    if pem == nil
      # cancel
      return nil
    end

    cert = Convert.to_string(SCR.Read(path(".target.string"), pem))
    if cert != nil
      # pass the data to the backend
      YaST::HTTPDData.SetCert(@currenthost, "CERT", cert)

      # get the correct host name
      host = YaST::HTTPDData.GetHost(@currenthost)
      host = set_host_value(
        "SSLCertificateFile",
        host,
        Ops.add(
          Ops.add(
            "/etc/apache2/ssl.crt/",
            Convert.to_string(get_host_value("ServerName", host, "default"))
          ),
          "-cert.pem"
        )
      )
      YaST::HTTPDData.ModifyHost(@currenthost, host)
      TablePopup.TableInitWrapper(key)
      return nil
    end

    # translators: error message un failed certificate import
    Report.Error(Builtins.sformat(_("Cannot import certificate\n%1"), pem))
  elsif Ops.get(event, "ID") == :common_certificate
    pem = "/etc/ssl/servercerts/servercert.pem"
    if !CheckCommonServerCertificate()
      #translators: dialog to set *.pem file with certificate
      pem = UI.AskForExistingFile(
        "/etc/ssl/servercerts",
        "*.pem",
        _("Select Certificate")
      )
      if pem == nil
        # cancelled
        return nil
      end
    else
      host = YaST::HTTPDData.GetHost(@currenthost)
      host = set_host_value(
        "SSLCertificateFile",
        host,
        "/etc/ssl/servercerts/servercert.pem"
      )
      host = set_host_value(
        "SSLCertificateKeyFile",
        host,
        "/etc/ssl/servercerts/serverkey.pem"
      )
      YaST::HTTPDData.ModifyHost(@currenthost, host)
    end

    TablePopup.TableInitWrapper(key)
    return nil
  elsif Ops.get(event, "ID") == :back
    @host_options = nil
  end

  TablePopup.TableHandle(@sslwidget, key, event)
end

- (Object) handleVhostDetails(key, event)



1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
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
# File '../../src/modules/HttpServerWidgets.rb', line 1957

def handleVhostDetails(key, event)
  event = deep_copy(event)
  documentroot = Builtins.find(@vhost_descr) do |row|
    Ops.get_string(row, "KEY", "") == "DocumentRoot"
  end
  ip = Builtins.find(@vhost_descr) do |row|
    Ops.get_string(row, "KEY", "") == "HostIP"
  end
  servername = Builtins.find(@vhost_descr) do |row|
    Ops.get_string(row, "KEY", "") == "ServerName"
  end

  if Convert.to_boolean(UI.QueryWidget(:cgi_support, :Value))
    UI.ChangeWidget(:cgi_dir, :Enabled, true)
    UI.ChangeWidget(:browse_cgi_dir, :Enabled, true)
  else
    UI.ChangeWidget(:cgi_dir, :Enabled, false)
    UI.ChangeWidget(:browse_cgi_dir, :Enabled, false)
  end
  if Convert.to_boolean(UI.QueryWidget(:ssl_support, :Value))
    UI.ChangeWidget(:certfile, :Enabled, true)
    UI.ChangeWidget(:browse_cert, :Enabled, true)
    UI.ChangeWidget(:keyfile, :Enabled, true)
    UI.ChangeWidget(:browse_key, :Enabled, true)
  else
    UI.ChangeWidget(:certfile, :Enabled, false)
    UI.ChangeWidget(:browse_cert, :Enabled, false)
    UI.ChangeWidget(:keyfile, :Enabled, false)
    UI.ChangeWidget(:browse_key, :Enabled, false)
  end


  if Ops.get(event, "WidgetClass") == :PushButton
    case Ops.get_symbol(event, "ID")
      when :dns_add_rec
        Builtins.y2milestone(
          "Add record %1 to zone %2",
          Ops.get_string(servername, "VALUE", ""),
          @dns_zone
        )
        UI.ChangeWidget(:dns_add_rec, :Enabled, false)
        DnsServerAPI.AddZoneRR(
          @dns_zone,
          "A",
          Ops.add(Ops.get_string(servername, "VALUE", ""), "."),
          Ops.get_string(ip, "VALUE", "")
        )
      when :dns_create_zone
        Builtins.y2milestone(
          "Create new zone ... %1",
          UI.QueryWidget(:new_zone, :Value)
        )
        UI.ChangeWidget(:dns_create_zone, :Enabled, false)
        UI.ChangeWidget(:new_zone, :Enabled, false)
        @dns_zone = Convert.to_string(UI.QueryWidget(:new_zone, :Value))
        DnsServerAPI.AddZone(@dns_zone, "master", {})
        DnsServerAPI.AddZoneRR(
          @dns_zone,
          "A",
          Ops.add(Ops.get_string(servername, "VALUE", ""), "."),
          Ops.get_string(ip, "VALUE", "")
        )
      when :browse_cgi_dir
        cgi_dir = UI.AskForExistingDirectory(
          "/srv/www/cgi-bin",
          _("CGI Directory")
        )
        UI.ChangeWidget(:cgi_dir, :Value, cgi_dir) if cgi_dir != nil
      when :browse_cert
        cert_file = UI.AskForExistingFile(
          "/etc/apache2/ssl.crt",
          "*.crt *.pem",
          _("Choose Certificate File")
        )
        if cert_file != nil &&
            SCR.Execute(
              path(".target.bash"),
              Builtins.sformat("openssl x509 -in %1", cert_file)
            ) == 0
          UI.ChangeWidget(:certfile, :Value, cert_file)
        else
          UI.ChangeWidget(:certfile, :Value, "")
          # translators: error popup
          Popup.Error(_("Enter the certificate file."))
        end
      when :browse_key
        key_file = UI.AskForExistingFile(
          "/etc/apache2/ssl.key",
          "*.key *.pem",
          _("Choose Certificate Key File")
        )
        #   boolean keyfile = (SCR::Execute(.target.bash, sformat("openssl rsa -in %1", cert_file))==0)?true:false;
        if key_file != nil &&
            SCR.Execute(
              path(".target.bash"),
              Builtins.sformat("openssl rsa -in %1", key_file)
            ) == 0
          UI.ChangeWidget(:keyfile, :Value, key_file)
        else
          UI.ChangeWidget(:keyfile, :Value, "")
          # translators: error popup
          Popup.Error(_("Enter the key file."))
        end
    end
  end

  nil
end

- (Object) handleVhostId(key, event)



1635
1636
1637
1638
1639
1640
1641
1642
1643
# File '../../src/modules/HttpServerWidgets.rb', line 1635

def handleVhostId(key, event)
  event = deep_copy(event)
  if Ops.get_string(event, "EventType", "") == "WidgetEvent" &&
      Ops.get(event, "WidgetID") == :browse
    dir = UI.AskForExistingDirectory("/srv", _("Choose Document Root"))
    UI.ChangeWidget(:documentroot, :Value, dir) if dir != nil
  end
  nil
end

- (Object) handleVhostRest(key, event)



1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
# File '../../src/modules/HttpServerWidgets.rb', line 1785

def handleVhostRest(key, event)
  event = deep_copy(event)
  if Ops.get_string(event, "EventReason", "") == "Activated" &&
      Ops.get(event, "ID") == :change_vhost
    vhost = changeVHostPopup(
      Convert.to_string(UI.QueryWidget(:virtual_host, :Value))
    )
    if Ops.greater_than(Builtins.size(vhost), 0)
      UI.ChangeWidget(Id(:virtual_host), :Value, vhost)
    end
  end
  nil
end

- (String) HostDocumentRootSummary(key, id)

Get document root for host

Parameters:

  • key (Object)

    any

  • id (String)

    string

Returns:

  • (String)

    document root



1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
# File '../../src/modules/HttpServerWidgets.rb', line 1281

def HostDocumentRootSummary(key, id)
  key = deep_copy(key)
  Convert.to_string(
    get_host_value(
      "DocumentRoot",
      YaST::HTTPDData.GetHost(Convert.to_string(key)),
      ""
    )
  )
end

- (String) HostId2Key(desc, option_id)

Get value from id

Parameters:

  • desc (Hash)

    map

  • option_id (Object)

    any

Returns:

  • (String)

    value



2523
2524
2525
2526
2527
# File '../../src/modules/HttpServerWidgets.rb', line 2523

def HostId2Key(desc, option_id)
  desc = deep_copy(desc)
  option_id = deep_copy(option_id)
  Ops.get_string(@host_options, [Convert.to_integer(option_id), "KEY"], "")
end

- (Object) HostInit(key)

Initialize host widget

Parameters:

  • key (String)

    string



1388
1389
1390
1391
1392
1393
1394
1395
1396
# File '../../src/modules/HttpServerWidgets.rb', line 1388

def HostInit(key)
  if key == "MAIN_HOST"
    @init_tab = "main_host"
    @currenthost = "main"
  end
  TablePopup.TableInit(@hostwidget, key)

  nil
end

- (Boolean) HostIsDefault(widget, key)

Is that host default?

Parameters:

  • widget (Object)

    any

  • key (String)

    string

Returns:

  • (Boolean)

    is_default?



1296
1297
1298
1299
# File '../../src/modules/HttpServerWidgets.rb', line 1296

def HostIsDefault(widget, key)
  widget = deep_copy(widget)
  key == "default"
end

- (String) HostName(key, id)

Get server name for host

Parameters:

  • key (Object)

    any

  • id (String)

    string

Returns:

  • (String)

    server name



1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
# File '../../src/modules/HttpServerWidgets.rb', line 1262

def HostName(key, id)
  key = deep_copy(key)
  res = Convert.to_string(
    get_host_value(
      "ServerName",
      YaST::HTTPDData.GetHost(Convert.to_string(key)),
      Convert.to_string(key)
    )
  )
  res = Punycode.DecodeDomainName(res)
  # translators: human-readable "default host"
  res = _("Default Host") if key == "default" && res == "default"
  res
end

- (Array) HostsContents(descr)

Hosts contents

Parameters:

  • descr (Hash)

    map

Returns:

  • (Array)

    host list



1221
1222
1223
1224
# File '../../src/modules/HttpServerWidgets.rb', line 1221

def HostsContents(descr)
  descr = deep_copy(descr)
  Builtins.filter(YaST::HTTPDData.GetHostsList) { |row| row != "main" }
end

- (Boolean) HostsDelete(opt_id, opt_key)

Widget for delete host

Parameters:

  • opt_id (Object)

    any

  • opt_key (String)

    string

Returns:

  • (Boolean)

    delete success



1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
# File '../../src/modules/HttpServerWidgets.rb', line 1238

def HostsDelete(opt_id, opt_key)
  opt_id = deep_copy(opt_id)
  if opt_id == "default"
    # translators: popup error message - default host cannot be deleted
    Popup.Error(_("Cannot delete the default host."))
    return false
  end
  # message popup
  return false if !Popup.YesNo(_("Delete selected host?"))

  HttpServer.modified = true
  ret = YaST::HTTPDData.DeleteHost(Convert.to_string(opt_id))
  if Builtins.size(HostsContents({})) == 0
    changeButtons(false)
  else
    changeButtons(true)
  end
  ret
end

- (Symbol) HostsHandle(table, event)

Handle host widget

Parameters:

  • table (String)

    string

  • event (Hash)

    map

Returns:

  • (Symbol)

    (add,edit)



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
1330
1331
1332
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
# File '../../src/modules/HttpServerWidgets.rb', line 1305

def HostsHandle(table, event)
  event = deep_copy(event)
  if Builtins.size(Convert.to_list(UI.QueryWidget(:_tp_table, :Items))) == 0
    changeButtons(false)
  else
    changeButtons(true)
  end

  if Ops.get(event, "ID") == :_tp_add
    return :add
  elsif Ops.get(event, "ID") == :_tp_edit
    @currenthost = Convert.to_string(
      UI.QueryWidget(:_tp_table, :CurrentItem)
    )
    return :edit
  elsif Ops.get(event, "ID") == :set_default
    host = Convert.to_string(UI.QueryWidget(:_tp_table, :CurrentItem))
    if host == "default"
      # popup - it is already the default host
      Popup.Message(_("The host is already default."))
      return nil
    end

    Builtins.y2milestone("Changing default host to '%1'", host)

    defhost_options = YaST::HTTPDData.GetHost("main")
    servername = Convert.to_string(
      get_host_value("ServerName", defhost_options, "")
    )
    ip = Convert.to_string(get_host_value("HostIP", defhost_options, ""))
    if ip == "" || servername != ""
      # we must set a new server name and ip for the old default host
      res = AskNewInfo(servername, ip)
      if res == nil
        # cancel the change
        return nil
      end

      ip = Ops.get_string(res, "ip", ip)
      servername = Ops.get_string(res, "name", ip)
      defhost_options = set_host_value("HostIP", defhost_options, ip)
      defhost_options = set_host_value(
        "ServerName",
        defhost_options,
        servername
      )
    end
    # move the old default host elsewhere
    YaST::HTTPDData.CreateHost(
      Ops.add(Ops.add(ip, "/"), servername),
      defhost_options
    )
    # replace the values of the default host by the new one
    YaST::HTTPDData.ModifyHost("main", YaST::HTTPDData.GetHost(host))
    # remove the old non-default host
    YaST::HTTPDData.DeleteHost(host)

    HttpServer.modified = true

    TablePopup.TableInit(@hosts_widget, table)
  else
    return TablePopup.TableHandle(@hosts_widget, table, event)
  end
  nil
end

- (Object) HostsInit(widget)

Initialize hosts table widget

Parameters:

  • widget (String)

    string



1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
# File '../../src/modules/HttpServerWidgets.rb', line 1373

def HostsInit(widget)
  @init_tab = "hosts"
  TablePopup.TableInit(@hosts_widget, widget)
  @vhost_descr = []
  # menu button label
  UI.ReplaceWidget(
    Id(:_tp_table_repl),
    PushButton(Id(:set_default), _("Set as De&fault"))
  )

  nil
end

- (Object) HostStore(key, event)

Store host settings

Parameters:

  • key (String)

    string

  • event (Hash)

    map



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
# File '../../src/modules/HttpServerWidgets.rb', line 2550

def HostStore(key, event)
  event = deep_copy(event)
  options = []
  Builtins.foreach(@host_options) do |key2, values|
    if Builtins.haskey(values, "DATA")
      #In main host SSL can't be used
      if Ops.get_string(values, "KEY", "") == "SSL"
        options = Builtins.add(
          options,
          {
            "KEY"          => "_SECTION",
            "SECTIONNAME"  => "IfDefine",
            "SECTIONPARAM" => "SSL",
            "VALUE"        => Ops.get_list(values, "DATA", []),
            "OVERHEAD"     => Ops.get_string(values, "OVERHEAD", "")
          }
        )
        Builtins.y2milestone("SSL section - %1", options)
      end

      if Ops.get_string(values, "KEY", "") == "Directory"
        options = Builtins.add(
          options,
          {
            "KEY"          => "_SECTION",
            "SECTIONNAME"  => "Directory",
            "SECTIONPARAM" => Ops.get_string(values, "VALUE", ""),
            "VALUE"        => Ops.get_list(values, "DATA", []),
            "OVERHEAD"     => Ops.get_string(values, "OVERHEAD", "")
          }
        )
        Builtins.y2milestone("Directory section - %1", values)
      end

      if Ops.get_string(values, "KEY", "") == "mod_userdir.c"
        options = Builtins.add(
          options,
          {
            "KEY"          => "_SECTION",
            "SECTIONNAME"  => "IfModule",
            "SECTIONPARAM" => "mod_userdir.c",
            "VALUE"        => Ops.get_list(values, "DATA", []),
            "OVERHEAD"     => Ops.get_string(values, "OVERHEAD", "")
          }
        )
        Builtins.y2milestone("Directory section - %1", values)
      end
    else
      options = Builtins.add(options, values)
      Builtins.y2milestone("Global section - %1", values)
    end
  end

  options = Builtins.filter(options) { |option| option != nil }

  # for all host options check whether module from directive is loaded
  Builtins.foreach(options) do |values|
    checkLoadedModuleFor(Ops.get_string(values, "KEY", ""))
  end

  if @currenthost != "main"
    options = Builtins.add(
      options,
      {
        "KEY"   => "HostIP",
        "VALUE" => Convert.to_string(
          UI.QueryWidget(Id(:virtual_host), :Value)
        )
      }
    )
    options = Builtins.add(
      options,
      {
        "KEY"   => "VirtualByName",
        "VALUE" => UI.QueryWidget(Id(:resolution), :Value) == :name_based ? "1" : "0"
      }
    )
  end
  YaST::HTTPDData.ModifyHost(@currenthost, options)

  setHostOptions(nil)

  nil
end

- (Array) HostTableContents(descr)

Function for getting contents of the default host table

Parameters:

  • descr (Hash)

    map description map of the table

Returns:

  • (Array)

    of items for the table



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
2678
2679
2680
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
# File '../../src/modules/HttpServerWidgets.rb', line 2647

def HostTableContents(descr)
  descr = deep_copy(descr)
  if @host_options == nil
    # fill the data
    @option_counter = 0
    @host_options = {}
    @deleted_options = []
    res = []

    # flags, whether the required entries are present
    servername = false
    serveradmin = false
    documentroot = false

    host = YaST::HTTPDData.GetHost(@currenthost)
    Builtins.foreach(host) do |option|
      key = Ops.get_string(option, "KEY", "unknown")
      servername = true if key == "ServerName"
      serveradmin = true if key == "ServerAdmin"
      documentroot = true if key == "DocumentRoot"
      if key == "_SECTION" &&
          Ops.get_string(option, "SECTIONNAME", "") == "Directory"
        Ops.set(
          @host_options,
          @option_counter,
          {
            "KEY"      => "Directory",
            "VALUE"    => Ops.get_string(option, "SECTIONPARAM", ""),
            "DATA"     => Ops.get_list(option, "VALUE", []),
            "OVERHEAD" => Ops.get_string(option, "OVERHEAD", "")
          }
        )
        res = Builtins.add(res, @option_counter)
        @option_counter = Ops.add(@option_counter, 1)
      end
      if key == "_SECTION" &&
          Ops.get_string(option, "SECTIONPARAM", "") == "SSL"
        Ops.set(
          @host_options,
          @option_counter,
          {
            "KEY"      => "SSL",
            "VALUE"    => "",
            "DATA"     => Ops.get_list(option, "VALUE", []),
            "OVERHEAD" => Ops.get_string(option, "OVERHEAD", "")
          }
        )
        res = Builtins.add(res, @option_counter)
        @option_counter = Ops.add(@option_counter, 1)
      end
      # skip SECTIONS
      if key == "_SECTION"
        if Ops.get_string(option, "SECTIONNAME", "") == "IfModule"
          Ops.set(
            @host_options,
            @option_counter,
            {
              "KEY"      => Ops.get_string(option, "SECTIONPARAM", ""),
              "VALUE"    => "",
              "DATA"     => Ops.get_list(option, "VALUE", []),
              "OVERHEAD" => Ops.get_string(option, "OVERHEAD", "")
            }
          )
          res = Builtins.add(res, @option_counter)
          @option_counter = Ops.add(@option_counter, 1)
        else
          @option_counter = Ops.add(@option_counter, 1)
          next
        end
      # skip HostIP for default host
      elsif @currenthost == "main" && key == "HostIP"
        Ops.set(@host_options, @option_counter, option)
        @option_counter = Ops.add(@option_counter, 1)
        next
      else
        Ops.set(@host_options, @option_counter, option)
        res = Builtins.add(res, @option_counter)
        @option_counter = Ops.add(@option_counter, 1)
      end
    end


    # required entries
    if !servername
      Builtins.y2milestone("Adding missing ServerName")
      Ops.set(
        @host_options,
        @option_counter,
        { "KEY" => "ServerName", "VALUE" => "" }
      )
      res = Builtins.add(res, @option_counter)
      @option_counter = Ops.add(@option_counter, 1)
    end

    if !serveradmin
      Builtins.y2milestone("Adding missing ServerAdmin")
      Ops.set(
        @host_options,
        @option_counter,
        { "KEY" => "ServerAdmin", "VALUE" => "" }
      )
      res = Builtins.add(res, @option_counter)
      @option_counter = Ops.add(@option_counter, 1)
    end

    if !documentroot
      Builtins.y2milestone("Adding missing DocumentRoot")
      Ops.set(
        @host_options,
        @option_counter,
        { "KEY" => "DocumentRoot", "VALUE" => "" }
      )
      res = Builtins.add(res, @option_counter)
      @option_counter = Ops.add(@option_counter, 1)
    end
    return deep_copy(res)
  else
    # just generate the list of ids
    return Builtins.maplist(@host_options) { |id, value| id }
  end
end

- (Boolean) HostTableEntryDelete(opt_id, opt_key)

Delete function of the global table

Parameters:

  • opt_id (Object)

    any option id of selected option

  • opt_key (String)

    any option key of selected option

Returns:

  • (Boolean)

    true if was really deleted



2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
# File '../../src/modules/HttpServerWidgets.rb', line 2827

def HostTableEntryDelete(opt_id, opt_key)
  opt_id = deep_copy(opt_id)
  return false if !Confirm.DeleteSelected

  @host_options = Builtins.filter(@host_options) do |opt, value|
    opt != opt_id
  end

  @deleted_options = Builtins.add(
    @deleted_options,
    Convert.to_integer(opt_id)
  )

  HttpServer.modified = true
  true
end

- (String) HostTableEntrySummary(option_id, option_type)

Fallback summary function of a table entry / popup

Parameters:

  • option_id (Object)

    any option unique id

  • option_type (String)

    string option type

Returns:

  • (String)

    table entry summary



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
# File '../../src/modules/HttpServerWidgets.rb', line 2933

def HostTableEntrySummary(option_id, option_type)
  option_id = deep_copy(option_id)
  if option_type == "VirtualByName"
    if Ops.get_string(
        @host_options,
        [Convert.to_integer(option_id), "VALUE"],
        ""
      ) == "1"
      # translators: table entry text for name-based vhosts
      return _("Resolution via HTTP Headers")
    else
      # translators: table entry text for IP-based vhosts
      return _("Resolution via IP Address Used")
    end
  elsif option_type == "Directory"
    return Ops.add(
      Ops.get_string(
        @host_options,
        [Convert.to_integer(option_id), "VALUE"],
        ""
      ),
      "..."
    )
  elsif option_type == "ServerName"
    return Punycode.DecodeDomainName(
      Ops.get_string(
        @host_options,
        [Convert.to_integer(option_id), "VALUE"],
        ""
      )
    )
  else
    return Ops.get_string(
      @host_options,
      [Convert.to_integer(option_id), "VALUE"],
      ""
    )
  end
end

- (Object) initListenInterfaces(key)

Initialize listen interfaces

Parameters:

  • key (String)

    string



3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
# File '../../src/modules/HttpServerWidgets.rb', line 3455

def initListenInterfaces(key)
  Builtins.y2milestone("Initializing Listen Interfaces ... %1", key)
  all = false
  Builtins.foreach(YaST::HTTPDData.GetCurrentListen) do |listens|
    all = true if Ops.get_string(listens, "ADDRESS", "") == ""
  end

  ips = Builtins.maplist(HttpServer.ip2device) do |ip, dev|
    if all
      next Item(ip, true)
    else
      checked = false
      Builtins.foreach(YaST::HTTPDData.GetCurrentListen) do |listens|
        checked = true if Ops.get_string(listens, "ADDRESS", "") == ip
      end
      next Item(ip, checked)
    end
  end
  #translators: multi selection box
  UI.ReplaceWidget(
    Id(@mode_replace_point_key),
    MultiSelectionBox(Id("multi_sel_box"), _("&Listen on Interfaces"), ips)
  )

  nil
end

- (Object) initListenSettings(key)

Initialize function of a widget

Parameters:

  • key (String)

    any widget key of widget that is processed



3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
# File '../../src/modules/HttpServerWidgets.rb', line 3261

def initListenSettings(key)
  id = -1
  listen = YaST::HTTPDData.GetCurrentListen
  Builtins.y2milestone("Listen: %1", listen)
  items = Builtins.maplist(listen) do |litem|
    id = Ops.add(id, 1)
    listen2item(litem, id)
  end
  UI.ChangeWidget(Id(:listen), :Items, items)

  # enable/disable buttons - at least single Listen must be present
  UI.ChangeWidget(
    Id(:delete),
    :Enabled,
    Ops.greater_than(Builtins.size(listen), 1)
  )

  # set focus
  UI.SetFocus(Id(:listen))

  nil
end

- (Object) initModules(key)

Initialize function of a widget

Parameters:

  • key (String)

    any widget key of widget that is processed



3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
# File '../../src/modules/HttpServerWidgets.rb', line 3031

def initModules(key)
  known = YaST::HTTPDData.GetKnownModules
  modules = YaST::HTTPDData.GetModuleList
  index = -1
  # create temporary list of maps from modules
  listmodules = Builtins.maplist(modules) do |name|
    Builtins.mapmap(
      {
        "default"  => "1",
        "name"     => name,
        "summary"  => _("unknown"),
        "requires" => ""
      }
    ) { |k, v| { k => v } }
  end
  # add to known modules list modules from temporary list
  Builtins.foreach(listmodules) do |mapmodules|
    finded = false
    Builtins.foreach(known) do |mapknownmodules|
      #translators: list of known and unknown modules
      if Ops.get_locale(mapknownmodules, "name", _("unknown")) ==
          Ops.get_locale(mapmodules, "name", _("unknown"))
        finded = true
      end
    end
    known = Builtins.add(known, mapmodules) if !finded
  end
  items = Builtins.maplist(known) do |mod|
    index = Ops.add(index, 1)
    # translators: server module status unknown
    name = Ops.get_locale(mod, "name", _("unknown"))
    #	if ((mod["default"]:"0" == "1") && (!contains(modules, name))) YaST::HTTPDData::ModifyModuleList ([name], true);
    # translators: server module status
    Item(
      Id(index),
      name,
      Builtins.contains(modules, name) ?
        _("Enabled") :
        # translators: server module status
        _("Disabled"),
      Ops.get_string(mod, "summary", "")
    )
  end
  UI.ChangeWidget(Id(:modules), :Items, items)
  UI.SetFocus(Id(:modules))

  nil
end

- (Object) initOpenPort(key)

Initialize open port

Parameters:

  • key (String)

    string



3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
# File '../../src/modules/HttpServerWidgets.rb', line 3412

def initOpenPort(key)
  port = nil

  Builtins.foreach(YaST::HTTPDData.GetCurrentListen) do |listens|
    port = Ops.get_string(listens, "PORT", "80") if port != "80"
  end
  port = "80" if port == nil
  Builtins.y2milestone("Port finally :  %1", port)
  UI.ChangeWidget(Id(key), :Value, port)

  nil
end

- (Object) initScriptModules(key)



3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
# File '../../src/modules/HttpServerWidgets.rb', line 3502

def initScriptModules(key)
  enable_php5 = false
  enable_perl = false
  enable_python = false
  #	boolean enable_ruby=false;
  modules = YaST::HTTPDData.GetModuleList
  enable_php5 = true if Builtins.contains(modules, "php5")
  enable_perl = true if Builtins.contains(modules, "perl")
  enable_python = true if Builtins.contains(modules, "python")
  #	if (contains(modules, "ruby")) enable_ruby = true;

  UI.ReplaceWidget(
    Id(:scr_mod_replace),
    HBox(
      HSpacing(6),
      VBox(
        VSpacing(3), #translators: checkbox - support for php script language
        Left(
          CheckBox(
            Id(:scr_mod_php5),
            _("Enable &PHP5 Scripting"),
            enable_php5
          )
        ),
        VSpacing(1), #translators: checkbox - support for perl script language
        Left(
          CheckBox(
            Id(:scr_mod_perl),
            _("Enable P&erl Scripting"),
            enable_perl
          )
        ),
        VSpacing(1), #translators: checkbox - support for python script language
        Left(
          CheckBox(
            Id(:scr_mod_python),
            _("Enable P&ython Scripting"),
            enable_python
          )
        ),
        #                        `VSpacing(1),   //translators: checkbox - support for ruby script language
        #                      `Left(`CheckBox(`id(`scr_mod_ruby), _("Enable &Ruby Scripting"), enable_ruby)),
        VSpacing(2)
      )
    )
  )
  Builtins.y2milestone("initializing script modules")

  nil
end

- (Object) initServiceStatus(key)

Initialize function of a widget

Parameters:

  • key (String)

    any widget key of widget that is processed



3370
3371
3372
3373
3374
3375
3376
3377
3378
# File '../../src/modules/HttpServerWidgets.rb', line 3370

def initServiceStatus(key)
  if YaST::HTTPDData.GetService != nil && YaST::HTTPDData.GetService
    UI.ChangeWidget(Id("enabled"), :Value, true)
  else
    UI.ChangeWidget(Id("disabled"), :Value, true)
  end

  nil
end

- (Object) initSummaryText(key)



3580
3581
3582
3583
3584
3585
3586
3587
# File '../../src/modules/HttpServerWidgets.rb', line 3580

def initSummaryText(key)
  UI.ReplaceWidget(
    Id(:summary_text_rp),
    RichText(Ops.get_string(HttpServer.Summary, 0, "error"))
  )

  nil
end

- (Object) initVhostDetails(key)



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
1951
1952
1953
1954
1955
# File '../../src/modules/HttpServerWidgets.rb', line 1831

def initVhostDetails(key)
  servername = Builtins.find(@vhost_descr) do |row|
    Ops.get_string(row, "KEY", "") == "ServerName"
  end
  ip = Builtins.find(@vhost_descr) do |row|
    Ops.get_string(row, "KEY", "") == "HostIP"
  end

  @dns_zone = ""

  if HttpServer.configured_dns
    if IP.Check4(Ops.get_string(ip, "VALUE", ""))
      Builtins.foreach(DnsServerAPI.GetZones) do |key2, value|
        if Ops.get_string(value, "type", "") == "master"
          if Builtins.regexpmatch(
              Ops.get_string(servername, "VALUE", ""),
              Ops.add(Ops.add("\\.", key2), "$")
            ) &&
              Ops.greater_than(
                Builtins.size(key2),
                Builtins.size(@dns_zone)
              )
            @dns_zone = key2
          end
          Builtins.y2milestone(_("Master Zone %1"), key2)
        else
          Builtins.y2warning("Zone %1 is not type master", key2)
        end
      end
      if Ops.greater_than(Builtins.size(@dns_zone), 0)
        Builtins.y2milestone("Matching zone %1", @dns_zone)
        exists = false
        Builtins.foreach(DnsServerAPI.GetZoneRRs(@dns_zone)) do |records|
          if Ops.get_string(records, "key", "") ==
              Ops.get_string(servername, "VALUE", "") ||
              Ops.get_string(records, "key", "") ==
                Ops.add(Ops.get_string(servername, "VALUE", ""), ".")
            exists = true
          end
        end
        if exists == true
          Builtins.y2milestone(
            _("Record %1 already exists in zone %2."),
            Ops.get_string(servername, "VALUE", ""),
            @dns_zone
          )
        else
          UI.ReplaceWidget(
            :replace,
            Frame(
              _("DNS Settings"),
              Left(
                HBox(
                  Label(Ops.get_string(servername, "VALUE", "")),
                  PushButton(Id(:dns_add_rec), _("Add to Zone"))
                )
              )
            )
          )
        end
      else
        opts = Builtins.splitstring(
          Ops.get_string(servername, "VALUE", ""),
          "."
        )
        Ops.set(opts, 0, nil)
        newList = []
        Builtins.foreach(opts) do |it|
          if it != nil
            tmpList = []
            Builtins.foreach(newList) do |itzone|
              if !Builtins.contains(
                  Map.Keys(DnsServerAPI.GetZones),
                  Ops.add(Ops.add(itzone, "."), it)
                )
                tmpList = Builtins.add(
                  tmpList,
                  Ops.add(Ops.add(itzone, "."), it)
                )
              else
                Builtins.y2warning(
                  "%1 is already configured zone",
                  Ops.add(Ops.add(itzone, "."), it)
                )
              end
            end
            newList = deep_copy(tmpList)
            newList = Builtins.add(newList, it)
          end
        end

        if Ops.greater_than(Builtins.size(opts), 0)
          UI.ReplaceWidget(
            :replace,
            Frame(
              _("DNS Settings"),
              Left(
                HBox(
                  Label(Ops.get_string(servername, "VALUE", "")),
                  ComboBox(Id(:new_zone), _("Zone Name"), newList),
                  PushButton(Id(:dns_create_zone), _("Create New Zone"))
                )
              )
            )
          )
        end
      end
    else
      Builtins.y2warning(
        "%1 is not valid IP4 address",
        Ops.get_string(ip, "VALUE", "")
      )
    end
  end

  # disable using SSL for name-based virtual host
  Builtins.foreach(@vhost_descr) do |row|
    if Ops.get_string(row, "KEY", "") == "VirtualByName" &&
        Ops.get_string(row, "VALUE", "0") == "1"
      UI.ChangeWidget(:ssl_support, :Enabled, false)
    end
  end

  nil
end

- (Object) initVhostId(key)



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
# File '../../src/modules/HttpServerWidgets.rb', line 1595

def initVhostId(key)
  if @vhost_descr != []
    servername = ""
    Builtins.foreach(@vhost_descr) do |row|
      if Ops.get_string(row, "KEY", "") == "ServerName"
        servername = Ops.get_string(row, "VALUE", "")
      end
    end
    documentroot = ""
    Builtins.foreach(@vhost_descr) do |row|
      if Ops.get_string(row, "KEY", "") == "DocumentRoot"
        documentroot = Ops.get_string(row, "VALUE", "")
      end
    end
    admin = ""
    Builtins.foreach(@vhost_descr) do |row|
      if Ops.get_string(row, "KEY", "") == "ServerAdmin"
        admin = Ops.get_string(row, "VALUE", "")
      end
    end
    if Ops.greater_than(Builtins.size(servername), 0)
      UI.ChangeWidget(
        :servername,
        :Value,
        Punycode.DecodeDomainName(servername)
      )
    end
    if Ops.greater_than(Builtins.size(documentroot), 0)
      UI.ChangeWidget(:documentroot, :Value, documentroot)
    end
    if Ops.greater_than(Builtins.size(admin), 0)
      UI.ChangeWidget(:admin, :Value, admin)
    end
  end

  UI.SetFocus(:servername)

  nil
end

- (Object) initVhostRes(key)



1566
1567
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
# File '../../src/modules/HttpServerWidgets.rb', line 1566

def initVhostRes(key)
  vhost = YaST::HTTPDData.GetVhostType(@currenthost)
  if @vhost_descr != []
    vhost = {}
    Builtins.foreach(@vhost_descr) do |row|
      if Ops.get_string(row, "KEY", "") == "HostIP"
        Ops.set(vhost, "id", Ops.get_string(row, "VALUE", ""))
      end
      if Ops.get_string(row, "KEY", "") == "VirtualByName"
        Ops.set(
          vhost,
          "type",
          Ops.get_string(row, "VALUE", "0") == "0" ? "ip-based" : "name-based"
        )
      end
    end
  end

  if Ops.get_string(vhost, "type", "") == "ip-based"
    UI.ChangeWidget(:resolution, :CurrentButton, :ip_based)
  else
    UI.ChangeWidget(:resolution, :CurrentButton, :name_based)
  end
  UI.ChangeWidget(:virtual_host, :Value, Ops.get_string(vhost, "id", ""))
  UI.ChangeWidget(:virtual_host, :Enabled, false)

  nil
end

- (Yast::Term) listen2item(arg, id)

Convert a Listen string to an item for table. Splits by the colon.

Parameters:

  • arg (Hash{String => Object})

    the Listen map

  • id (Fixnum)

    the id of this item

Returns:

  • (Yast::Term)

    term for the table



2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
# File '../../src/modules/HttpServerWidgets.rb', line 2394

def listen2item(arg, id)
  arg = deep_copy(arg)
  #translators: all network addresses Listen type
  address = Ops.get_locale(arg, "ADDRESS", _("All Addresses"))
  #translators: all network addresses Listen type
  address = _("All Addresses") if address == ""
  port = Ops.get_string(arg, "PORT", "80")

  Item(Id(id), address, port)
end

- (Object) main



15
16
17
18
19
20
21
22
23
24
25
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
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
761
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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
# File '../../src/modules/HttpServerWidgets.rb', line 15

def main
  Yast.import "UI"

  textdomain "http-server"

  Yast.import "Directory"
  Yast.import "Mode"
  Yast.import "IP"
  Yast.import "Label"
  Yast.import "Popup"
  Yast.import "Report"
  Yast.import "Service"
  Yast.import "String"
  Yast.import "LogView"
  Yast.import "TablePopup"
  Yast.import "HttpServer"
  Yast.import "YaST::HTTPDData"
  Yast.import "Confirm"
  Yast.import "SuSEFirewall"
  Yast.import "CWMServiceStart"
  Yast.import "CWMFirewallInterfaces"
  Yast.import "Punycode"
  Yast.import "Package"
  Yast.import "DnsServerAPI"
  Yast.import "FileUtils"
  Yast.import "Hostname"
  Yast.import "DNS"
  Yast.import "Arch"
  Yast.import "PackageSystem"
  Yast.import "Map"

  Yast.include self, "http-server/helps.rb"

  @currenthost = "main"
  @dir_value = ""
  @init_tab = "listen"

  @update_contents = false
  @vhost_descr = []

  @overview_widget = {
    "widget"        => :custom,
    "custom_widget" => VBox(
      Mode.config ?
        VSpacing(0) :
        # menu button label
        MenuButton(
          Id(:menu),
          _("&Log Files"),
          # menu button item
          [
            Item(Id(:show_access_log), _("Show &Access Log")),
            # menu button item
            Item(Id(:show_error_log), _("Show &Error Log"))
          ]
        )
    ),
    #    "init"		:  OverviewInit,
    "handle"        => fun_ref(
      method(:OverviewHandle),
      "symbol (string, map)"
    ),
    "help"          => Ops.get_string(@HELPS, "overview_widget", "")
  }

  @hosts_widget = TablePopup.CreateTableDescr(
    {
      "add_delete_buttons" => true,
      "up_down_buttons"    => false,
      "unique_keys"        => true,
      "changed_column"     => true
    },
    {
      "init"          => fun_ref(method(:HostsInit), "void (string)"),
      "handle"        => fun_ref(
        method(:HostsHandle),
        "symbol (string, map)"
      ),
      "ids"           => fun_ref(method(:HostsContents), "list (map)"),
      "option_delete" => fun_ref(
        method(:HostsDelete),
        "boolean (any, string)"
      ),
      "help"          => Ops.get_string(@HELPS, "hosts", ""),
      "fallback"      => {
        "summary"    => fun_ref(
          method(:HostDocumentRootSummary),
          "string (any, string)"
        ),
        "changed"    => fun_ref(
          method(:HostIsDefault),
          "boolean (any, string)"
        ),
        "label_func" => fun_ref(method(:HostName), "string (any, string)")
      }
    }
  )


  @mode_replace_point_key = "replace_point"

  # Map of popups for CWM
  @popups = {
    "ServerName"    => {
      "table" => {
        # table cell description
        "label"    => _("Server Name"),
        "optional" => false,
        "unique"   => true
      },
      "popup" => {
        # table cell description
        "label"  => _("Server Name"),
        "widget" => :textentry
      }
    },
    "DocumentRoot"  => {
      "table" => {
        # table cell description
        "label"    => _("Document Root"),
        "optional" => false,
        "unique"   => true
      },
      "popup" => { "widget" => :textentry }
    },
    "ServerAdmin"   => {
      "table" => {
        # table cell description
        "label"    => _(
          "Server Administrator E-Mail"
        ),
        "optional" => false,
        "unique"   => true
      },
      "popup" => { "widget" => :textentry }
    },
    "VirtualByName" => {
      "table" => {
        # table cell description
        "label"    => _("Server Resolution"),
        "optional" => false,
        "unique"   => true
      },
      "popup" => {
        "widget" => :radio_buttons,
        "items"  => [
          # translators: radio button for name-based virtual hosts
          ["1", _("Determine Request Server by HTTP &Headers")],
          # translators: radio button for IP-based virtual hosts
          ["0", _("Determine Request Server by Server IP &Address")]
        ]
      }
    },
    "HostIP"        => {
      "table" => {
        # table cell description
        "label"    => _("IP Address"),
        "optional" => false,
        "unique"   => true
      }
    },
    "SSL"           => {
      "table" => { "handle" => :ssl, "optional" => false, "unique" => true }
    },
    "Directory"     => {
      "table" => { "handle" => :dir, "optional" => true, "unique" => true }
    }
  }

  @hostwidget = TablePopup.CreateTableDescr(
    {
      "add_delete_buttons" => true,
      "up_down_buttons"    => false,
      "unique_keys"        => false
    },
    {
      "init"              => fun_ref(method(:HostInit), "void (string)"),
      "handle"            => fun_ref(
        method(:handleHostTable),
        "symbol (string, map)"
      ),
      "store"             => fun_ref(
        method(:HostStore),
        "void (string, map)"
      ),
      "validate_type"     => :function,
      "validate_function" => fun_ref(
        method(:validate_server_fnc),
        "boolean (string, map)"
      ),
      "options"           => getHostOptions(false),
      "ids"               => fun_ref(
        method(:HostTableContents),
        "list (map)"
      ),
      "id2key"            => fun_ref(
        method(:HostId2Key),
        "string (map, any)"
      ),
      "fallback"          => {
        "init"    => fun_ref(
          method(:DefaultHostPopupInit),
          "void (any, string)"
        ),
        "store"   => fun_ref(
          method(:DefaultHostPopupStore),
          "void (any, string)"
        ),
        "summary" => fun_ref(
          method(:HostTableEntrySummary),
          "string (any, string)"
        )
      },
      "option_delete"     => fun_ref(
        method(:HostTableEntryDelete),
        "boolean (any, string)"
      ),
      "add_items"         => Builtins.maplist(
        Convert.convert(
          getHostOptions(false),
          :from => "map",
          :to   => "map <string, any>"
        )
      ) { |key, value| key },
      "help"              => Ops.get_string(@HELPS, "global_table", "")
    }
  )

  @host_options = nil

  @sslwidget = TablePopup.CreateTableDescr(
    {
      "add_delete_buttons" => true,
      "up_down_buttons"    => false,
      "unique_keys"        => true
    },
    {
      "init"          => fun_ref(method(:SSLInit), "void (string)"),
      "handle"        => fun_ref(
        method(:handleSSLTable),
        "symbol (string, map)"
      ),
      "store"         => fun_ref(method(:SSLStore), "void (string, map)"),
      "options"       => Convert.convert(
        getSSLOptions,
        :from => "map",
        :to   => "map <string, any>"
      ),
      "ids"           => fun_ref(method(:SSLTableContents), "list (map)"),
      "id2key"        => fun_ref(method(:HostId2Key), "string (map, any)"),
      "fallback"      => {
        "init"    => fun_ref(
          method(:DefaultHostPopupInit),
          "void (any, string)"
        ),
        "store"   => fun_ref(
          method(:DefaultHostPopupStore),
          "void (any, string)"
        ),
        "summary" => fun_ref(
          method(:HostTableEntrySummary),
          "string (any, string)"
        )
      },
      "option_delete" => fun_ref(
        method(:HostTableEntryDelete),
        "boolean (any, string)"
      ),
      "add_items"     => Builtins.maplist(
        Convert.convert(
          getSSLOptions,
          :from => "map",
          :to   => "map <string, any>"
        )
      ) { |key, value| key },
      "help"          => Ops.get_string(@HELPS, "ssl", "")
    }
  )


  @dirwidget = TablePopup.CreateTableDescr(
    {
      "add_delete_buttons" => true,
      "up_down_buttons"    => false,
      "unique_keys"        => true
    },
    {
      "init"          => fun_ref(method(:DirInit), "void (string)"),
      "handle"        => fun_ref(
        method(:handleDirTable),
        "symbol (string, map)"
      ),
      "store"         => fun_ref(method(:DirStore), "void (string, map)"),
      "options"       => Convert.convert(
        getDirOptions,
        :from => "map",
        :to   => "map <string, any>"
      ),
      "ids"           => fun_ref(method(:DirTableContents), "list (map)"),
      "id2key"        => fun_ref(method(:HostId2Key), "string (map, any)"),
      "fallback"      => {
        "init"    => fun_ref(method(:DirPopupInit), "void (any, string)"),
        "store"   => fun_ref(
          method(:DefaultHostPopupStore),
          "void (any, string)"
        ),
        "summary" => fun_ref(
          method(:HostTableEntrySummary),
          "string (any, string)"
        )
      },
      "option_delete" => fun_ref(
        method(:HostTableEntryDelete),
        "boolean (any, string)"
      ),
      "add_items"     => Builtins.maplist(
        Convert.convert(
          getDirOptions,
          :from => "map",
          :to   => "map <string, any>"
        )
      ) { |key, value| key },
      "help"          => Ops.get_string(@HELPS, "dir", "")
    }
  )

  @dns_zone = ""



  # Map of widgets for CWM
  @widgets = {
    "server_enable"     => {
      "widget"        => :radio_buttons,
      # translator: server enable/disable radio button group
      "label"         => _(
        "HTTP &Service"
      ),
      "items"         => [
        # translators: service status radio button label
        ["disabled", _("Disabled")],
        # translators: service status radio button label
        ["enabled", _("Enabled")]
      ],
      "init"          => fun_ref(
        method(:initServiceStatus),
        "void (string)"
      ),
      "handle"        => fun_ref(
        method(:handleServiceStatus),
        "symbol (string, map)"
      ),
      "store"         => fun_ref(
        method(:storeServiceStatus),
        "void (string, map)"
      ),
      "handle_events" => ["enabled", "disabled"],
      "opt"           => [:notify],
      "help"          => Ops.get_string(@HELPS, "server_enable", "")
    },
    "firewall_adapt"    => CWMFirewallInterfaces.CreateOpenFirewallWidget(
      {
        "services"        => ["service:apache2", "service:apache2-ssl"],
        "help"            => Ops.get_string(@HELPS, "firewall_adapt", ""),
        "display_details" => true
      }
    ),
    "host"              => @hostwidget,
    "LISTEN"            => {
      "widget"        => :custom,
      "custom_widget" => VBox(
        # translators: radio button group label
        Left(Label(_("Listen on Ports:"))),
        Table(
          Id(:listen),
          Header(
            # table header
            _("Network Address"),
            # table header
            _("Port")
          ),
          []
        ),
        HBox(
          PushButton(Id(:add), Opt(:key_F3), Label.AddButton),
          PushButton(Id(:edit), Opt(:key_F4), Label.EditButton),
          PushButton(Id(:delete), Opt(:key_F5), Label.DeleteButton),
          HStretch()
        )
      ),
      "init"          => fun_ref(
        method(:initListenSettings),
        "void (string)"
      ),
      "handle"        => fun_ref(
        method(:handleListenSettings),
        "symbol (string, map)"
      ),
      "help"          => Ops.get_string(@HELPS, "listen", "")
    },
    "MODULES"           => {
      "widget"            => :custom,
      "custom_widget"     => VBox(
        Table(
          Id(:modules),
          Header(
            # table header: module name
            _("Name"),
            # table header: module status
            _("Status") + "    ",
            # table header: module description
            _("Description")
          ),
          []
        ),
        HBox(
          PushButton(
            Id(:toggle),
            # translators: toggle button label
            _("&Toggle Status")
          ),
          HStretch(),
          PushButton(
            Id(:add_user),
            # translators: add user-defined module button label
            _("&Add Module")
          )
        )
      ),
      "init"              => fun_ref(method(:initModules), "void (string)"),
      "handle"            => fun_ref(
        method(:handleModules),
        "symbol (string, map)"
      ),
      "validate_type"     => :function,
      "validate_function" => fun_ref(
        method(:validateModules),
        "boolean (string, map)"
      ),
      "help"              => Ops.get_string(@HELPS, "modules", "")
    },
    "MAIN_HOST"         => TablePopup.CreateTableDescr(
      {
        "add_delete_buttons" => true,
        "up_down_buttons"    => false,
        "unique_keys"        => false
      },
      {
        "init"              => fun_ref(method(:HostInit), "void (string)"),
        "handle"            => fun_ref(
          method(:handleHostTable),
          "symbol (string, map)"
        ),
        "store"             => fun_ref(
          method(:HostStore),
          "void (string, map)"
        ),
        "validate_type"     => :function,
        "validate_function" => fun_ref(
          method(:validate_server_fnc),
          "boolean (string, map)"
        ),
        "options"           => getHostOptions(true),
        "ids"               => fun_ref(
          method(:HostTableContents),
          "list (map)"
        ),
        "id2key"            => fun_ref(
          method(:HostId2Key),
          "string (map, any)"
        ),
        "fallback"          => {
          "init"    => fun_ref(
            method(:DefaultHostPopupInit),
            "void (any, string)"
          ),
          "store"   => fun_ref(
            method(:DefaultHostPopupStore),
            "void (any, string)"
          ),
          "summary" => fun_ref(
            method(:HostTableEntrySummary),
            "string (any, string)"
          )
        },
        "option_delete"     => fun_ref(
          method(:HostTableEntryDelete),
          "boolean (any, string)"
        ),
        "add_items"         => Builtins.maplist(
          Convert.convert(
            getHostOptions(true),
            :from => "map",
            :to   => "map <string, any>"
          )
        ) { |key, value| key },
        "help"              => Ops.get_string(@HELPS, "global_table", "")
      }
    ),
    "HOSTS"             => TablePopup.CreateTableDescr(
      {
        "add_delete_buttons" => true,
        "up_down_buttons"    => false,
        "unique_keys"        => true,
        "changed_column"     => true
      },
      {
        "init"          => fun_ref(method(:HostsInit), "void (string)"),
        "handle"        => fun_ref(
          method(:HostsHandle),
          "symbol (string, map)"
        ),
        "ids"           => fun_ref(method(:HostsContents), "list (map)"),
        "option_delete" => fun_ref(
          method(:HostsDelete),
          "boolean (any, string)"
        ),
        "help"          => Ops.get_string(@HELPS, "hosts", ""),
        "fallback"      => {
          "summary"    => fun_ref(
            method(:HostDocumentRootSummary),
            "string (any, string)"
          ),
          "changed"    => fun_ref(
            method(:HostIsDefault),
            "boolean (any, string)"
          ),
          "label_func" => fun_ref(method(:HostName), "string (any, string)")
        }
      }
    ),
    "logs"              => @overview_widget,
    "hosts"             => @hosts_widget,
    "ssl"               => @sslwidget,
    "dir"               => @dirwidget,
    "dir_name"          => {
      "widget"        => :custom,
      "custom_widget" => VBox(TextEntry(Id(:dir_name), _("Directory")))
    },
    # wizard widgets
    "open_port"         => {
      "widget"            => :textentry,
      # translators: text entry
      "label"             => _("&Port:"),
      "init"              => fun_ref(method(:initOpenPort), "void (string)"),
      "validate_type"     => :function,
      "validate_function" => fun_ref(
        method(:validateOpenPort),
        "boolean (string, map)"
      ),
      "help"              => Ops.get_string(@HELPS, "open_port", "")
    },
    "listen_interfaces" => {
      "widget"            => :custom,
      # translators: multi selection box
      "custom_widget"     => ReplacePoint(
        Id(@mode_replace_point_key),
        MultiSelectionBox(_("&Listen on Interfaces"), [])
      ),
      "init"              => fun_ref(
        method(:initListenInterfaces),
        "void (string)"
      ),
      "validate_type"     => :function,
      "validate_function" => fun_ref(
        method(:validateListenInterfaces),
        "boolean (string, map)"
      ),
      "help"              => Ops.get_string(@HELPS, "listen_interfaces", "")
    },
    "booting"           => CWMServiceStart.CreateAutoStartWidget(
      {
        "get_service_auto_start" => fun_ref(
          method(:getServiceAutoStart),
          "boolean ()"
        ),
        "set_service_auto_start" => fun_ref(
          method(:setServiceAutoStart),
          "void (boolean)"
        ),
        #translators: radiobutton - to start Apache2 service automatically
        "start_auto_button"      => _(
          "Start Apache2 Server When Booting"
        ),
        #translators: radiobutton - to don't start Apache2 service
        "start_manual_button"    => _(
          "Start Apache2 Server Manually"
        )
      }
    ),
    "expert_conf"       => {
      "widget" => :push_button,
      #translators: button to enter expert configuration
      "label"  => _(
        "&HTTP Server Expert Configuration..."
      ),
      #		"init"	 : initExpertConf,
      "handle" => fun_ref(
        method(:handleExpertConf),
        "symbol (string, map)"
      ),
      "help"   => Ops.get_string(@HELPS, "expert_conf", "")
    },
    "script_modules"    => {
      "widget"        => :custom,
      "custom_widget" => ReplacePoint(Id(:scr_mod_replace), Label("")),
      "init"          => fun_ref(
        method(:initScriptModules),
        "void (string)"
      ),
      "help"          => Ops.get_string(@HELPS, "script_modules", "")
    },
    "vhost_id"          => {
      "widget"            => :custom,
      "custom_widget"     => Frame(
        # translators: frame title for new hsot identification details
        _("Server Identification"),
        VBox(
          # translators: textentry, new host server name
          TextEntry(Id(:servername), _("Server &Name:")),
          HBox(
            # translators: textentry, document root for the new host
            TextEntry(Id(:documentroot), _("Server &Contents Root:")),
            VBox(Label(""), PushButton(Id(:browse), Label.BrowseButton))
          ),
          # translators: textentry, administrator's e-mail for the new host
          TextEntry(Id(:admin), _("&Administrator E-Mail:"))
        )
      ),
      "help"              => Ops.get_string(@HELPS, "vhost_id", ""),
      "init"              => fun_ref(method(:initVhostId), "void (string)"),
      "handle"            => fun_ref(
        method(:handleVhostId),
        "symbol (string, map)"
      ),
      "validate_type"     => :function,
      "validate_function" => fun_ref(
        method(:validateVhostId),
        "boolean (string, map)"
      ),
      "store"             => fun_ref(
        method(:storeVhostId),
        "void (string, map)"
      )
    },
    "vhost_res"         => {
      "widget"            => :custom,
      "custom_widget"     => Frame(
        # translators: frame title for method of incoming request resolution
        _("Server Resolution"),
        HBox(
          VBox(
            # translators: IP address for the new host
            Left(TextEntry(Id(:virtual_host), _("VirtualHost"))),
            Left(PushButton(Id(:change_vhost), _("Change VirtualHost ID")))
          ),
          RadioButtonGroup(
            Id(:resolution),
            VBox(
              # translators: radio button for name-based virtual hosts
              Left(
                RadioButton(
                  Id(:name_based),
                  Opt(:notify),
                  _("Determine Request Server by HTTP &Headers"),
                  true
                )
              ),
              # translators: radio button for IP-based virtual hosts
              Left(
                RadioButton(
                  Id(:ip_based),
                  Opt(:notify),
                  _("Determine Request Server by Server IP &Address")
                )
              )
            )
          )
        )
      ),
      "init"              => fun_ref(method(:initVhostRes), "void (string)"),
      "handle"            => fun_ref(
        method(:handleVhostRest),
        "symbol (string, map)"
      ),
      "validate_type"     => :function,
      "validate_function" => fun_ref(
        method(:validateVhostRes),
        "boolean (string, map)"
      ),
      "help"              => Ops.get_string(@HELPS, "vhost_res", "")
    },
    "vhost_details"     => {
      "widget"        => :custom,
      "custom_widget" => HBox(
        HSpacing(0.5),
        VBox(
          ReplacePoint(Id(:replace), Empty()),
          VSpacing(1),
          Frame(
            # translators: frame title for virtual host identification details
            _("CGI Options"),
            VBox(
              Left(
                CheckBox(
                  Id(:cgi_support),
                  Opt(:notify),
                  _("Enable &CGI for This Virtual Host")
                )
              ),
              HBox(
                # translators: textentry, certificate file path
                TextEntry(Id(:cgi_dir), _("CGI &Directory Path")),
                VBox(
                  Label(""),
                  PushButton(Id(:browse_cgi_dir), Label.BrowseButton)
                )
              )
            )
          ),
          VSpacing(1),
          Frame(
            _("SSL Support"),
            VBox(
              Left(
                CheckBox(
                  Id(:ssl_support),
                  Opt(:notify),
                  _("Enable &SSL Support for This Virtual Host")
                )
              ),
              VBox(
                # translators: textentry, certificate file path
                HBox(
                  Label(""),
                  TextEntry(Id(:certfile), _("&Certificate File Path")),
                  PushButton(Id(:browse_cert), Label.BrowseButton)
                ),
                HBox(
                  Label(""),
                  TextEntry(Id(:keyfile), _("&Certificate Key File Path")),
                  PushButton(Id(:browse_key), Label.BrowseButton)
                )
              )
            )
          ),
          VSpacing(1),
          Frame(
            _("Directory Options"),
            Left(TextEntry(Id(:dir_index), _("&Directory Index")))
          ),
          VSpacing(1),
          Frame(
            _("Public HTML"),
            Left(CheckBox(Id(:pub_html), _("Enable &Public HTML")))
          )
        )
      ),
      "init"          => fun_ref(method(:initVhostDetails), "void (string)"),
      "handle"        => fun_ref(
        method(:handleVhostDetails),
        "symbol (string, map)"
      ),
      "store"         => fun_ref(
        method(:storeVhostDetails),
        "void (string, map)"
      ),
      "help"          => Ops.get_string(@HELPS, "vhost_details", "")
    },
    "summary_text"      => {
      "widget"        => :custom,
      "custom_widget" => ReplacePoint(Id(:summary_text_rp), RichText("")),
      "init"          => fun_ref(method(:initSummaryText), "void (string)"),
      "help"          => Ops.get_string(@HELPS, "summary_text", "")
    }
  }

  # *************************************** log popups **************************


  # ************************************ default host table ********************

  @option_counter = 0
  @deleted_options = []

  # these are for future use:

  # error message - the entered ip address is not found
  @__nonconfigured_ipaddress = _(
    "The IP address is not configured\non this machine."
  )
end

- (Symbol) OverviewHandle(table, event)

Handle overview (listen) widget

Parameters:

  • table (String)

    string

  • event (Hash)

    map

Returns:

  • (Symbol)

    (access/error popup)



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File '../../src/modules/HttpServerWidgets.rb', line 1136

def OverviewHandle(table, event)
  event = deep_copy(event)
  # handle menu button entries
  if Ops.get(event, "ID") == :show_access_log
    return showAccessLogPopup(table, event)
  elsif Ops.get(event, "ID") == :show_error_log
    return showErrorLogPopup(table, event)
  end
  nil
end

- (Object) ReloadServer

Reload server



1039
1040
1041
1042
1043
# File '../../src/modules/HttpServerWidgets.rb', line 1039

def ReloadServer
  SCR.Execute(path(".target.bash"), "rcapache2 reload")

  nil
end

- (Array< Hash{String => Object>}) set_host_value(keyword, host, value)

Set host value

Parameters:

  • keyword (String)

    string

  • host (Array<Hash{String => Object>})

    list< map<string, any> >

  • value (Object)

    any

Returns:

  • (Array< Hash{String => Object>})

    host map



856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
# File '../../src/modules/HttpServerWidgets.rb', line 856

def set_host_value(keyword, host, value)
  host = deep_copy(host)
  value = deep_copy(value)
  index = 0
  Builtins.foreach(host) do |option|
    raise Break if Ops.get(option, "KEY") == keyword
    index = Ops.add(index, 1)
  end

  # adding a new option
  if Ops.greater_or_equal(index, Builtins.size(host))
    Ops.set(host, index, { "KEY" => keyword, "VALUE" => value })
  else
    Ops.set(host, [index, "VALUE"], value)
  end

  deep_copy(host)
end

- (Object) setHostOptions(new_options)

Set host options

Parameters:

  • new_options (Hash <Fixnum, Hash{String => Object>})

    map < integer, map < string,any > >



2637
2638
2639
2640
2641
2642
# File '../../src/modules/HttpServerWidgets.rb', line 2637

def setHostOptions(new_options)
  new_options = deep_copy(new_options)
  @host_options = deep_copy(new_options)

  nil
end

- (Object) setServiceAutoStart(status)



3575
3576
3577
3578
3579
# File '../../src/modules/HttpServerWidgets.rb', line 3575

def setServiceAutoStart(status)
  YaST::HTTPDData.ModifyService(status)

  nil
end

- (Object) showAccessLogPopup(key, event)

Handle function of the access log button (the first defined access log file)

Parameters:

  • key (Object)

    any key of the widget

  • event (Hash)

    map event that occured

Returns:

  • value for wizard sequencer, always nil



1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
# File '../../src/modules/HttpServerWidgets.rb', line 1048

def showAccessLogPopup(key, event)
  key = deep_copy(key)
  event = deep_copy(event)
  # FIXME: log files needs to be done via HTTPDData
  # string log = (string) select( YaST::HTTPDData::GetAccessLogFiles( [currenthost] ), 0, "/var/log/apache2/access_log" );

  # strip the log format, if present
  log = ""
  #	log = select( splitstring( log, " " ), 0, "/var/log/apache2/access_log" );
  log = Ops.get(
    Builtins.splitstring(log, " "),
    0,
    "/var/log/apache2/access_log"
  )

  LogView.Display(
    {
      "command" => Builtins.sformat(
        "tail -f %1 -n 100 | /usr/sbin/logresolve2",
        log
      ),
      "save"    => true,
      "actions" => [
        # menubutton entry, try to keep short
        [
          _("&Reload HTTP Server"),
          fun_ref(method(:ReloadServer), "void ()")
        ],
        # menubutton entry, try to keep short
        [
          _("Save Settings and Re&start HTTP Server"),
          fun_ref(HttpServer.method(:Write), "boolean ()"),
          true
        ]
      ]
    }
  )
  nil
end

- (Object) showErrorLogPopup(key, event)

Handle function of the error log button

Parameters:

  • key (Object)

    any key of the widget

  • event (Hash)

    map event that occured

Returns:

  • value for wizard sequencer, always nil



1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
# File '../../src/modules/HttpServerWidgets.rb', line 1092

def showErrorLogPopup(key, event)
  key = deep_copy(key)
  event = deep_copy(event)
  # FIXME: log files needs to be done via HTTPDData
  # string log = (string) select( YaST::HTTPDData::GetErrorLogFiles( [currenthost] ), 0, "/var/log/apache2/error_log" );

  # strip the log format, if present
  log = ""
  #	log = select( splitstring( log, " " ), 0, "/var/log/apache2/error_log" );
  log = Ops.get(
    Builtins.splitstring(log, " "),
    0,
    "/var/log/apache2/error_log"
  )

  LogView.Display(
    {
      "command" => Builtins.sformat(
        "tail -f %1 -n 100 | /usr/sbin/logresolve2",
        log
      ),
      "save"    => true,
      "actions" => [
        # menubutton entry, try to keep short
        [
          _("&Reload HTTP Server"),
          fun_ref(method(:ReloadServer), "void ()")
        ],
        # menubutton entry, try to keep short
        [
          _("Save Settings and Re&start HTTP Server"),
          fun_ref(HttpServer.method(:Write), "boolean ()"),
          true
        ]
      ]
    }
  )
  nil
end

- (Object) SSLInit(widget)

Initialize SSL widget

Parameters:

  • widget (String)

    string



2264
2265
2266
2267
2268
# File '../../src/modules/HttpServerWidgets.rb', line 2264

def SSLInit(widget)
  TablePopup.TableInit(@sslwidget, widget)

  nil
end

- (Object) SSLStore(key, event)

Store SSL setting

Parameters:

  • key (String)

    string

  • event (Hash)

    map



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
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
# File '../../src/modules/HttpServerWidgets.rb', line 2273

def SSLStore(key, event)
  event = deep_copy(event)
  found = false
  forssl = []
  fordir = []


  Builtins.foreach(@host_options) do |key2, value|
    Builtins.foreach(YaST::HTTPDData.GetKnownModules) do |val|
      if Ops.get_string(val, "name", "") == "ssl"
        Builtins.foreach(Ops.get_list(val, "directives", [])) do |pom|
          if Ops.get_string(pom, "option", "") ==
              Ops.get_string(value, "KEY", "")
            if Builtins.contains(
                Ops.get_list(pom, "context", []),
                "Directory"
              )
              fordir = Builtins.add(fordir, value)
            end
            if Builtins.contains(Ops.get_list(pom, "context", []), "Server")
              forssl = Builtins.add(forssl, value)
            end
          end
        end
      end
    end
  end


  options = []

  vhost = YaST::HTTPDData.GetVhostType(@currenthost)
  if Ops.get_string(vhost, "type", "") == "ip-based"
    options = Builtins.add(
      options,
      { "KEY" => "VirtualByName", "VALUE" => "0" }
    )
  else
    options = Builtins.add(
      options,
      { "KEY" => "VirtualByName", "VALUE" => "1" }
    )
  end
  options = Builtins.add(
    options,
    { "KEY" => "HostIP", "VALUE" => Ops.get_string(vhost, "id", "") }
  )

  Builtins.foreach(YaST::HTTPDData.GetHost(@currenthost)) do |option|
    if Ops.get_string(option, "KEY", "unknown") == "_SECTION" &&
        Ops.get_string(option, "SECTIONPARAM", "unknown") == "SSL"
      found = true
      Ops.set(option, "VALUE", forssl)
      if Ops.greater_than(Builtins.size(forssl), 0)
        options = Builtins.add(options, option)
      end
    elsif Ops.get_string(option, "KEY", "unknown") == "_SECTION" &&
        Ops.get_string(option, "SECTIONNAME", "unknown") == "Directory"
      temp_dir = []
      Builtins.foreach(Ops.get_list(option, "VALUE", [])) do |value|
        if !(Ops.get_string(value, "KEY", "unknown") == "_SECTION" &&
            Ops.get_string(value, "SECTIONPARAM", "unknown") == "SSL")
          temp_dir = Builtins.add(temp_dir, value)
        end
      end
      if fordir != []
        Ops.set(
          option,
          "VALUE",
          Builtins.add(
            temp_dir,
            {
              "KEY"          => "_SECTION",
              "SECTIONNAME"  => "IfDefine",
              "SECTIONPARAM" => "SSL",
              "VALUE"        => fordir
            }
          )
        )
      else
        dir_newlist = []
        Builtins.foreach(Ops.get_list(option, "VALUE", [])) do |dir_item|
          if !(Ops.get_string(dir_item, "KEY", "") == "_SECTION" &&
              Ops.get_string(dir_item, "SECTIONPARAM", "") == "SSL")
            dir_newlist = Builtins.add(dir_newlist, dir_item)
          end
        end
        Ops.set(option, "VALUE", dir_newlist)
      end

      options = Builtins.add(options, option)
    else
      options = Builtins.add(options, option)
    end
  end
  if !found
    options = Builtins.add(
      options,
      {
        "KEY"          => "_SECTION",
        "SECTIONNAME"  => "IfDefine",
        "SECTIONPARAM" => "SSL",
        "VALUE"        => forssl
      }
    )
  end
  #TODO::SSLWrite()
  YaST::HTTPDData.ModifyHost(@currenthost, options)
  setHostOptions(nil)
  HttpServer.modified = true

  nil
end

- (Array) SSLTableContents(descr)

Function for getting contents of the default host table

Parameters:

  • descr (Hash)

    map description map of the table

Returns:

  • (Array)

    of items for the table



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
# File '../../src/modules/HttpServerWidgets.rb', line 2772

def SSLTableContents(descr)
  descr = deep_copy(descr)
  if @host_options == nil
    # fill the data
    @option_counter = 0
    @host_options = {}
    @deleted_options = []
    res = []

    host = YaST::HTTPDData.GetHost(@currenthost)
    Builtins.foreach(host) do |option|
      key = Ops.get_string(option, "KEY", "unknown")
      # skip non-SSL options
      if Ops.get_string(option, "KEY", "unknown") == "_SECTION" &&
          Ops.get_string(option, "SECTIONPARAM", "unknown") == "SSL"
        Builtins.foreach(Ops.get_list(option, "VALUE", [])) do |value|
          Ops.set(@host_options, @option_counter, value)
          res = Builtins.add(res, @option_counter)
          @option_counter = Ops.add(@option_counter, 1)
        end
      else
        if Ops.get_string(option, "KEY", "unknown") == "_SECTION" &&
            Ops.get_string(option, "SECTIONNAME", "unknown") == "Directory"
          Builtins.foreach(Ops.get_list(option, "VALUE", [])) do |value|
            if Ops.get_string(value, "KEY", "unknown") == "_SECTION" &&
                Ops.get_string(value, "SECTIONPARAM", "unknown") == "SSL" &&
                Ops.get_list(value, "VALUE", []) != []
              Builtins.foreach(Ops.get_list(value, "VALUE", [])) do |directive|
                found = false
                Builtins.foreach(@host_options) do |key2, val|
                  found = true if val == directive
                end
                if found == false
                  Ops.set(@host_options, @option_counter, directive)
                  res = Builtins.add(res, @option_counter)
                  @option_counter = Ops.add(@option_counter, 1)
                end
              end
            end
          end
        end
        @option_counter = Ops.add(@option_counter, 1)
        next
      end
    end
    return deep_copy(res)
  else
    # just generate the list of ids
    return Builtins.maplist(@host_options) { |id, value| id }
  end
end

- (Object) SSLTypeStore(option_id, option_type)

Store SSL type

Parameters:

  • option_id (Object)

    any

  • option_type (String)

    string



2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
# File '../../src/modules/HttpServerWidgets.rb', line 2976

def SSLTypeStore(option_id, option_type)
  option_id = deep_copy(option_id)
  # it is a radio button group
  Ops.set(
    @host_options,
    [Convert.to_integer(option_id), "VALUE"],
    UI.QueryWidget(Id(option_type), :CurrentButton)
  )
  HttpServer.modified = true

  nil
end

- (Object) storeServiceStatus(key, event)

Store function of a widget

Parameters:

  • key (String)

    any widget key of widget that is processed

  • event (Hash)

    map event that occured



3383
3384
3385
3386
3387
3388
3389
3390
3391
# File '../../src/modules/HttpServerWidgets.rb', line 3383

def storeServiceStatus(key, event)
  event = deep_copy(event)
  YaST::HTTPDData.ModifyService(
    Convert.to_boolean(UI.QueryWidget(Id("enabled"), :Value))
  )
  HttpServer.modified = true

  nil
end

- (Object) storeVhostDetails(key, events)



2066
2067
2068
2069
2070
2071
2072
2073
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
2105
2106
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
# File '../../src/modules/HttpServerWidgets.rb', line 2066

def storeVhostDetails(key, events)
  events = deep_copy(events)
  ip = Builtins.find(@vhost_descr) do |row|
    Ops.get_string(row, "KEY", "") == "HostIP"
  end
  servername = Builtins.find(@vhost_descr) do |row|
    Ops.get_string(row, "KEY", "") == "ServerName"
  end
  documentroot = Builtins.find(@vhost_descr) do |row|
    Ops.get_string(row, "KEY", "") == "DocumentRoot"
  end

  if UI.QueryWidget(:cgi_support, :Value) == true
    _alias = Ops.add(
      "/cgi-bin/ ",
      Convert.to_string(UI.QueryWidget(:cgi_dir, :Value))
    )
    @vhost_descr = Builtins.add(
      @vhost_descr,
      { "KEY" => "ScriptAlias", "VALUE" => _alias }
    )
    @vhost_descr = Builtins.add(
      @vhost_descr,
      {
        "KEY"          => "_SECTION",
        "SECTIONNAME"  => "Directory",
        "SECTIONPARAM" => UI.QueryWidget(:cgi_dir, :Value),
        "VALUE"        => [
          { "KEY" => "AllowOverride", "VALUE" => "None" },
          { "KEY" => "Options", "VALUE" => "+ExecCGI -Includes" },
          { "KEY" => "Order", "VALUE" => "allow,deny" },
          { "KEY" => "Allow", "VALUE" => "from all" }
        ],
        "OVERHEAD"     => ""
      }
    )
    Builtins.y2milestone("CGI support for virtual host added")
  end

  ssl_values = {}
  if UI.QueryWidget(:ssl_support, :Value) == true
    cert_file = Builtins.tostring(UI.QueryWidget(:certfile, :Value))
    key_file = Builtins.tostring(UI.QueryWidget(:keyfile, :Value))

    if Ops.greater_than(Builtins.size(cert_file), 0) &&
        Ops.greater_than(Builtins.size(key_file), 0)
      YaST::HTTPDData.ModifyModuleList(["ssl"], true)
      ssl_values = {
        "KEY"          => "_SECTION",
        "SECTIONNAME"  => "IfDefine",
        "SECTIONPARAM" => "SSL",
        "VALUE"        => [
          { "KEY" => "SSLCertificateFile", "VALUE" => cert_file },
          { "KEY" => "SSLCertificateKeyFile", "VALUE" => key_file },
          { "KEY" => "SSLEngine", "VALUE" => "on" }
        ]
      }
    else
      Builtins.y2error("%1 is not valid Certificate File!", cert_file)
    end
  end

  if Ops.greater_than(Builtins.size(ssl_values), 0)
    @vhost_descr = Builtins.add(@vhost_descr, ssl_values)
  end


  #		  vhost_descr = YaST::HTTPDData::GetHost(ip["VALUE"]:""+"/"+servername["VALUE"]:"");
  directory_index = Convert.to_string(UI.QueryWidget(:dir_index, :Value))

  if Ops.greater_than(Builtins.size(directory_index), 0)
    tmp_descr = []

    Builtins.foreach(@vhost_descr) do |value|
      if Ops.get_string(value, "KEY", "") == "_SECTION" &&
          Ops.get_string(value, "SECTIONNAME", "") == "Directory" &&
          Builtins.search(
            Ops.get_string(value, "SECTIONPARAM", ""),
            Ops.get_string(documentroot, "VALUE", "")
          ) != nil
        #				  if (size(directory_index)>0)
        Ops.set(
          value,
          "VALUE",
          Builtins.add(
            Ops.get_list(value, "VALUE", []),
            { "KEY" => "DirectoryIndex", "VALUE" => directory_index }
          )
        )
      end
      tmp_descr = Builtins.add(tmp_descr, value) #			vhost_descr = add(vhost_descr, value);
    end
    @vhost_descr = deep_copy(tmp_descr)
  end
  #		 }
  if UI.QueryWidget(:pub_html, :Value) == true
    @vhost_descr = Builtins.add(
      @vhost_descr,
      { "KEY" => "UserDir", "VALUE" => "public_html" }
    )
  end
  if YaST::HTTPDData.CreateHost(
      Ops.add(
        Ops.add(Ops.get_string(ip, "VALUE", ""), "/"),
        Ops.get_string(servername, "VALUE", "")
      ),
      @vhost_descr
    ) == nil
    error = YaST::HTTPDData.Error
    Popup.Error(Ops.get(error, "summary", ""))
  end
  HttpServer.modified = true
  @vhost_descr = []

  nil
end

- (Object) storeVhostId(opt_id, event)



1688
1689
1690
1691
# File '../../src/modules/HttpServerWidgets.rb', line 1688

def storeVhostId(opt_id, event)
  event = deep_copy(event)
  nil
end

- (Boolean) validate_server(hostid, server)

Function for validate server entries

Parameters:

  • hostid (String)

    string

  • server (Array<Hash{String => Object>})

    list < map<string,any> >

Returns:

  • (Boolean)

    valid server



934
935
936
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
# File '../../src/modules/HttpServerWidgets.rb', line 934

def validate_server(hostid, server)
  server = deep_copy(server)
  #TODO: don't allow user to use this directive !!!
  #main server can't use SSL
  valid = true
  Builtins.foreach(server) do |value|
    if Ops.get_string(value, "KEY", "") == "SSL"
      #translators: popup error message when validate server
      Report.Error(
        _("The default host cannot be configured with SSL support.")
      )
      valid = false
      next false
    end
  end if hostid == "main"
  return false if !valid

  hosts = YaST::HTTPDData.GetHostsList

  servername = Convert.to_string(get_host_value("ServerName", server, nil))
  ip = Convert.to_string(get_host_value("HostIP", server, nil))
  namebased = Convert.to_string(
    get_host_value("VirtualByName", server, nil)
  ) == "1"
  documentroot = Convert.to_string(
    get_host_value("DocumentRoot", server, "")
  )

  # for apache2.2 ServerName is not forced (if not - hostname will be used)
  if Builtins.size(servername) == 0
    if hostid == "main"
      Report.Warning(
        _("When no Server name is defined, hostname will be used instead.")
      )
      return true
    else
      #translators: popup error message when validate server
      Report.Error(_("Server name cannot be empty."))
      return false
    end
  end

  return false if !FileUtils.CheckAndCreatePath(documentroot)
  res = true

  Builtins.foreach(hosts) do |host|
    # skip ourself also when this is main server
    next if host == hostid || hostid == "main"
    next if host == "main"
    # find out the server name
    value = Convert.to_string(
      get_host_value("ServerName", YaST::HTTPDData.GetHost(host), nil)
    )
    if value == servername
      # error message - the entered server name is already configured
      # in another virtual host
      Report.Error(
        _(
          "The server name entered is already configured on another virtual host."
        )
      )
      res = false
      raise Break
    end
    vhost = YaST::HTTPDData.GetVhostType(host)
    if !FileUtils.CheckAndCreatePath(documentroot)
      res = false
      raise Break
    end
    if Ops.get_string(vhost, "id", "") == ip
      # this is valid only if both of them are name-based, not ip-based (bnc#486476)
      if !(Ops.get_string(YaST::HTTPDData.GetVhostType(host), "type", "") == "name-based" && namebased)
        # error message - the entered ip address is already
        # configured for another virtual host
        error_msg = Builtins.sformat(
          "%1 : %2",
          _("The IP address is already configured on another virtual host"),
          host
        )
        Report.Error(error_msg)
        res = false
        raise Break
      end
    end
  end

  # validate server admin
  serveradmin = Convert.to_string(
    get_host_value("ServerAdmin", server, nil)
  )
  if !Builtins.regexpmatch(serveradmin, ".+@.+")
    #translators: popup error message when validate ServerAdmin
    Report.Error(_("Administrator E-Mail is invalid."))
    res = false
  end

  res
end

- (Boolean) validate_server_fnc(id, key)

Validate server function

Parameters:

  • id (String)

    string

  • key (Hash)

    map

Returns:

  • (Boolean)

    validate



2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
# File '../../src/modules/HttpServerWidgets.rb', line 2494

def validate_server_fnc(id, key)
  key = deep_copy(key)
  # convert the map to list
  val = Builtins.maplist(@host_options) { |index, data| data }
  if @currenthost != "main"
    val = Builtins.add(
      val,
      {
        "KEY"   => "HostIP",
        "VALUE" => Convert.to_string(
          UI.QueryWidget(Id(:virtual_host), :Value)
        )
      }
    )
    val = Builtins.add(
      val,
      {
        "KEY"   => "VirtualByName",
        "VALUE" => UI.QueryWidget(Id(:resolution), :Value) == :ip_based ? "0" : "1"
      }
    )
  end
  validate_server(@currenthost, val)
end

- (Boolean) validate_serverip(id, key, event)

Validate IP for host

Parameters:

  • id (Object)

    any

  • key (Object)

    any

  • event (Hash)

    map

Returns:

  • (Boolean)

    is IP valid



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
# File '../../src/modules/HttpServerWidgets.rb', line 898

def validate_serverip(id, key, event)
  id = deep_copy(id)
  key = deep_copy(key)
  event = deep_copy(event)
  Yast.import "IP"
  value = Convert.to_string(UI.QueryWidget(Id(id), :Value))

  # check, if there is also a port, if yes, skip it
  #    integer pos = search (value, ":");
  #    if (pos != nil) value = substring (value, 0, pos);

  # validate wildcard
  return true if value == "*"
  # remove brackets before validation (because of IPv6 [::])
  if Builtins.substring(value, 0, 1) == "[" &&
      Builtins.substring(value, Ops.subtract(Builtins.size(value), 1), 1) == "]"
    value = Builtins.substring(
      value,
      1,
      Ops.subtract(Builtins.size(value), 2)
    )
  end

  if !IP.Check(value)
    #translators: popup error message when validate server ip
    Popup.Error(_("Invalid IP address."))
    return false
  else
    return true
  end
end

- (Boolean) validate_servername(value)

Validate server name

Parameters:

  • key

    any

  • id

    any

  • event

    map

Returns:

  • (Boolean)

    valid servername



880
881
882
883
884
885
886
887
888
889
890
891
# File '../../src/modules/HttpServerWidgets.rb', line 880

def validate_servername(value)
  #    string value = Punycode::EncodeDomainName( (string)UI::QueryWidget (`id(key), `Value) );
  if !Hostname.CheckFQ(value)
    #translators: popup error message when validate servername
    Popup.Error(
      Ops.add(_("Invalid server name.") + "\n\n", Hostname.ValidFQ)
    )
    return false
  else
    return true
  end
end

- (Boolean) validateListenInterfaces(key, event)

Returns validate interfaces

Parameters:

  • key (String)

    string

  • event (Hash)

    map

Returns:

  • (Boolean)

    validate interfaces



3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
# File '../../src/modules/HttpServerWidgets.rb', line 3486

def validateListenInterfaces(key, event)
  event = deep_copy(event)
  if Ops.less_than(
      Builtins.size(
        Convert.to_list(UI.QueryWidget(Id("multi_sel_box"), :SelectedItems))
      ),
      1
    )
    #translators: popup error - multi selection box with server network adresses
    Popup.Error(_("At least one interface must be selected."))
    UI.SetFocus(Id(key))
    return false
  else
    return true
  end
end

- (Object) validateModules(id, key)



3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
# File '../../src/modules/HttpServerWidgets.rb', line 3080

def validateModules(id, key)
  key = deep_copy(key)
  valid = true
  selected = []
  Builtins.foreach(
    Convert.convert(
      UI.QueryWidget(:modules, :Items),
      :from => "any",
      :to   => "list <term>"
    )
  ) do |i|
    if Ops.get_string(i, 2, "") == _("Enabled")
      selected = Builtins.add(selected, Ops.get_string(i, 1, ""))
    end
  end
  all_modules = {}
  Builtins.foreach(YaST::HTTPDData.GetKnownModules) do |row|
    Ops.set(
      all_modules,
      Ops.get_string(row, "name", ""),
      Builtins.remove(row, "name")
    )
  end
  Builtins.foreach(selected) do |mod|
    require = Ops.get_string(all_modules, [mod, "requires"], "")
    if Ops.greater_than(Builtins.size(require), 0)
      if !Builtins.contains(selected, require)
        message = Builtins.sformat(
          "%1:\n %2 %3 %4\n%5",
          _("Modules dependency problem"),
          mod,
          _("requires"),
          require,
          _("Enable required module or disable first one.")
        )
        Popup.Error(message)
        Builtins.y2warning("Error message: %1", message)
        valid = false
      end
    end
  end
  valid
end

- (Boolean) validateOpenPort(key, event)

Validation open port

Parameters:

  • key (String)

    string

  • event (Hash)

    string

Returns:

  • (Boolean)

    validate open port



3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
# File '../../src/modules/HttpServerWidgets.rb', line 3438

def validateOpenPort(key, event)
  event = deep_copy(event)
  value = Convert.to_string(UI.QueryWidget(Id(key), :Value))
  Builtins.y2milestone("validate open port ... %1", value)
  if !Builtins.regexpmatch(value, "^[ \t]*[0-9]+[ \t]*$")
    #translators: popup error
    Popup.Error(_("Invalid port number."))
    UI.SetFocus(Id(key))
    return false
  else
    return true
  end
end

- (Object) validateVhostId(key, event)



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
1678
1679
1680
1681
1682
1683
1684
1685
1686
# File '../../src/modules/HttpServerWidgets.rb', line 1645

def validateVhostId(key, event)
  event = deep_copy(event)
  # FIXME: Do checks about the IP address availability
  ip = Convert.to_string(UI.QueryWidget(:virtual_host, :Value))
  servername = Punycode.EncodeDomainName(
    Convert.to_string(UI.QueryWidget(:servername, :Value))
  )
  documentroot = Convert.to_string(UI.QueryWidget(:documentroot, :Value))
  admin = Convert.to_string(UI.QueryWidget(:admin, :Value))
  virtualbyname = Convert.to_boolean(UI.QueryWidget(:name_based, :Value))

  return false if !validate_servername(servername)

  #     if (! validate_serverip("", "ipaddress", nil)) return false;

  if Builtins.size(admin) == 0
    # translators: error popup
    Popup.Error(_("Administrator E-Mail cannot be empty."))
    return nil
  end

  @vhost_descr = [
    { "KEY" => "DocumentRoot", "VALUE" => documentroot },
    { "KEY" => "ServerName", "VALUE" => servername },
    { "KEY" => "ServerAdmin", "VALUE" => admin },
    { "KEY" => "VirtualByName", "VALUE" => virtualbyname ? "1" : "0" },
    { "KEY" => "HostIP", "VALUE" => ip },
    {
      "KEY"          => "_SECTION",
      "SECTIONNAME"  => "Directory",
      "SECTIONPARAM" => documentroot,
      "VALUE"        => [
        { "KEY" => "AllowOverride", "VALUE" => "None" },
        { "KEY" => "Order", "VALUE" => "allow,deny" },
        { "KEY" => "Allow", "VALUE" => "from all" }
      ],
      "OVERHEAD"     => ""
    }
  ]
  return false if !validate_server(nil, @vhost_descr)
  true
end

- (Object) validateVhostRes(key, event)



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
# File '../../src/modules/HttpServerWidgets.rb', line 1800

def validateVhostRes(key, event)
  event = deep_copy(event)
  vhost = Convert.to_string(UI.QueryWidget(Id(:virtual_host), :Value))
  if Builtins.size(vhost) == 0
    Popup.Error(_("Name for VirtualHost ID cannot be empty."))
    return false
  end

  # for name-based vhost only IP address is allowed
  # or regexp (* or *:port) or list of IP addresses
  if UI.QueryWidget(:resolution, :Value) == :name_based
    # regexp matches '*' and '*:80'
    return true if Builtins.regexpmatch(vhost, "^\\*$|^\\*:[[:digit:]]+$")
    ok = true
    Builtins.foreach(Builtins.splitstring(vhost, " ")) do |ip|
      ok = false if !IP.Check4(ip)
    end
    if !ok
      Popup.Warning(
        _(
          "To use name-based virtual hosting,\n" +
            "you must designate the IP address on the server\n" +
            "that will be accepting requests for the hosts.\n" +
            "Also * for all addresses and *:port are acceptable."
        )
      )
    end
    return ok
  end
  true
end