Module: Yast::FirewallUifunctionsInclude

Defined in:
../../src/include/firewall/uifunctions.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) AddAcceptBroadcastReplyRule



1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
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
# File '../../src/include/firewall/uifunctions.rb', line 1936

def AddAcceptBroadcastReplyRule
  zones = []
  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone_shortname|
    zones = Builtins.add(
      zones,
      Item(
        Id(zone_shortname),
        SuSEFirewall.GetZoneFullName(zone_shortname),
        # hard-coded default
        zone_shortname == "EXT"
      )
    )
  end

  UI.OpenDialog(
    VBox(
      Left(ComboBox(Id(:zone), _("&Zone"), zones)),
      Left(
        MinWidth(
          18,
          ComboBox(Id(:network), Opt(:editable), _("&Network"), ["0/0"])
        )
      ),
      Left(
        ComboBox(
          Id(:service),
          Opt(:notify),
          _("&Service"),
          [
            Item(Id("samba"), GetBcastServiceName("udp", "137")),
            Item(Id("slp"), GetBcastServiceName("udp", "427")),
            Item(Id("all-udp"), GetBcastServiceName("udp", "")),
            Item(Id("all-tcp"), GetBcastServiceName("tcp", "")),
            Item(Id("user-defined"), _("User-defined service"))
          ]
        )
      ),
      HSquash(
        HBox(
          HWeight(
            1,
            ComboBox(
              Id(:protocol),
              Opt(:disabled),
              _("&Protocol"),
              [
                Item(
                  Id("udp"),
                  SuSEFirewall.GetProtocolTranslatedName("udp"),
                  true
                ),
                Item(
                  Id("tcp"),
                  SuSEFirewall.GetProtocolTranslatedName("tcp")
                )
              ]
            )
          ),
          HWeight(1, InputField(Id(:port), Opt(:disabled), _("Po&rt"), ""))
        )
      ),
      VSpacing(1),
      ButtonBox(
        PushButton(
          Id(:ok),
          Opt(:okButton, :default, :key_F10),
          Label.AddButton
        ),
        PushButton(
          Id(:cancel),
          Opt(:cancelButton, :key_F9),
          Label.CancelButton
        )
      )
    )
  )

  dialog_ret = false
  while true
    ret = UI.UserInput

    if ret == :service
      custom_service = UI.QueryWidget(Id(:service), :Value) == "user-defined"
      UI.ChangeWidget(Id(:protocol), :Enabled, custom_service)
      UI.ChangeWidget(Id(:port), :Enabled, custom_service)
    elsif ret == :ok
      # read the current settings
      zone = Convert.to_string(UI.QueryWidget(Id(:zone), :Value))
      network = Convert.to_string(UI.QueryWidget(Id(:network), :Value))
      service = Convert.to_string(UI.QueryWidget(Id(:service), :Value))

      # use either pre-defined or user-defined
      protocol = service == "user-defined" ?
        Convert.to_string(UI.QueryWidget(Id(:protocol), :Value)) :
        GetBcastServiceProtocol(service)

      # use either pre-defined or user-defined
      port = service == "user-defined" ?
        Convert.to_string(UI.QueryWidget(Id(:port), :Value)) :
        GetBcastServicePort(service)

      if !ValidateBroadcastReplyRule(zone, network, service, protocol, port)
        next
      end

      # Add the rule if validation went fine
      items = SuSEFirewall.GetServicesAcceptRelated(zone)
      new_rule = Builtins.sformat("%1,%2", network, protocol)
      new_rule = Builtins.sformat("%1,%2", new_rule, port) if port != ""
      items = Builtins.add(items, new_rule)
      SuSEFirewall.SetServicesAcceptRelated(zone, items)

      # redraw table
      dialog_ret = true
      break
    else
      break
    end
  end

  UI.CloseDialog

  dialog_ret
end

- (Boolean) CheckAdditionalServicesDefinition(services_definition)

Checks the string (services definition) for syntax errors

Parameters:

  • services_definition (String)

Returns:

  • (Boolean)

    whether everything was ok or whether user wants is despite the error



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

def CheckAdditionalServicesDefinition(services_definition)
  if Builtins.regexpmatch(services_definition, ",")
    ports = Builtins.splitstring(services_definition, ",")
    return Popup.YesNoHeadline(
      # TRANSLATORS: popup headline
      _("Invalid Additional Service Definition"),
      # TRANSLATORS: popup message, %1 stands for the wrong settings (might be quite long)
      Builtins.sformat(
        _(
          "It appears that the additional service settings\n" +
            "%1\n" +
            "are wrong. Entries should be separated by spaces instead of commas,\n" +
            "which are not allowed.\n" +
            "Really use the current settings?"
        ),
        services_definition
      )
    )
  end

  true
end

- (Object) CheckIfTheyAreAllKnownPorts(ui_id, ports)

Function checks list of ports if they exist (are known).

Parameters:

  • ui_id (Object)

    for the setfocus

  • list (string)

    of ports to be checked



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
# File '../../src/include/firewall/uifunctions.rb', line 537

def CheckIfTheyAreAllKnownPorts(ui_id, ports)
  ui_id = deep_copy(ui_id)
  ports = deep_copy(ports)
  checked = true

  # begin of for~each
  Builtins.foreach(ports) do |port|
    # previos port was wrong, break the loop
    raise Break if !checked
    # just a waste-space
    next if port == ""
    # common numeric port
    if Builtins.regexpmatch(port, "^[0123456789]+$")
      port_nr = Builtins.tointeger(port)
      if CheckPortNumberDefinition(port_nr, port) && checked
        checked = true
      else
        checked = false
      end

      next
    end
    # common port range
    if Builtins.regexpmatch(port, "^[0123456789]+:[0123456789]+$")
      port1 = Builtins.regexpsub(
        port,
        "^([0123456789]+):[0123456789]+$",
        "\\1"
      )
      port2 = Builtins.regexpsub(
        port,
        "^[0123456789]+:([0123456789]+)$",
        "\\1"
      )

      port1i = Builtins.tointeger(port1)
      port2i = Builtins.tointeger(port2)

      checked = false if !CheckPortNumberDefinition(port1i, port)

      if !CheckPortNumberDefinition(port2i, port)
        checked = false
      # port range is defined as 'A:B' where A<B
      elsif port1i != nil && port2i != nil && Ops.less_than(port1i, port2i)
        next
      elsif !Popup.ContinueCancelHeadline(
          # TRANSLATORS: popup headline
          _("Invalid Port Range Definition"),
          # TRANSLATORS: popup message, %1 is a port-range defined by user
          Builtins.sformat(
            _(
              "Port range %1 is invalid.\n" +
                "It must be defined as the min_port_number:max_port_number and\n" +
                "max_port_number must be bigger than min_port_number."
            ),
            port
          )
        ) && checked
        checked = false
      end

      next
    end
    # port number
    if !PortAliases.IsKnownPortName(port)
      if !Popup.ContinueCancelHeadline(
          # TRANSLATORS: popup headline
          _("Unknown Port Name"),
          Builtins.sformat(
            # TRANSLATORS: popup message, %1 is a port-name
            _(
              "Port name %1 is unknown in your current system.\n" +
                "It probably would not work.\n" +
                "Really use this port?\n"
            ),
            port
          )
        )
        checked = false
      end

      next
    end # end of for~each
  end

  UI.SetFocus(Id(ui_id)) if !checked

  checked
end

- (Object) CheckPortNameDefinition(port_name)



524
525
526
527
528
529
530
531
# File '../../src/include/firewall/uifunctions.rb', line 524

def CheckPortNameDefinition(port_name)
  if PortAliases.IsAllowedPortName(port_name)
    return true
  else
    Report.Error(PortAliases.AllowedPortNameOrNumber)
    return false
  end
end

- (Object) CheckPortNameOrNumber(port)



1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
# File '../../src/include/firewall/uifunctions.rb', line 1647

def CheckPortNameOrNumber(port)
  # port number
  if Builtins.regexpmatch(port, "^[0123456789]+$")
    return CheckPortNumberDefinition(Builtins.tointeger(port), port) 
    # not a port range
  elsif !Builtins.regexpmatch(port, "^[0123456789]+:[0123456789]+$")
    return CheckPortNameDefinition(port)
  end

  nil
end

- (Object) CheckPortNumberDefinition(port_nr, port)



515
516
517
518
519
520
521
522
# File '../../src/include/firewall/uifunctions.rb', line 515

def CheckPortNumberDefinition(port_nr, port)
  if Ops.less_than(port_nr, 1) ||
      Ops.greater_than(port_nr, SuSEFirewall.max_port_number)
    return ReportWrongPortDefinition(Builtins.tostring(port_nr), port)
  else
    return true
  end
end

- (Object) DeleteSelectedCustomRule(selected_zone, current_item)



1638
1639
1640
1641
1642
1643
1644
1645
# File '../../src/include/firewall/uifunctions.rb', line 1638

def DeleteSelectedCustomRule(selected_zone, current_item)
  if SuSEFirewallExpertRules.DeleteRuleID(selected_zone, current_item)
    RedrawCustomRules(selected_zone)
    UI.ChangeWidget(Id("custom_rules_table"), :SelectedItem, 0)
  end

  nil
end

- (Object) DisableBackButton(key)

Function disables the back button. Fake function for CWM Tree Widget.



114
115
116
117
118
119
# File '../../src/include/firewall/uifunctions.rb', line 114

def DisableBackButton(key)
  SetFirewallIcon()
  UI.ChangeWidget(Id(:back), :Enabled, false)

  nil
end

- (Object) GetBcastNetworkName(network)



1843
1844
1845
1846
1847
1848
1849
# File '../../src/include/firewall/uifunctions.rb', line 1843

def GetBcastNetworkName(network)
  if network == "0/0"
    return _("All networks")
  else
    return Builtins.sformat(_("Subnet: %1"), network)
  end
end

- (Object) GetBcastServiceName(protocol, sport)



1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
# File '../../src/include/firewall/uifunctions.rb', line 1825

def GetBcastServiceName(protocol, sport)
  if protocol == "udp" && sport == ""
    return _("All services using UDP")
  elsif protocol == "tcp" && sport == ""
    return _("All services using TCP")
  elsif protocol == "udp" && PortAliases.GetPortNumber(sport) == 137
    return _("Samba browsing")
  elsif protocol == "udp" && PortAliases.GetPortNumber(sport) == 427
    return _("SLP browsing")
  else
    return Builtins.sformat(
      "%1/%2",
      SuSEFirewall.GetProtocolTranslatedName(protocol),
      sport
    )
  end
end

- (Object) GetBcastServicePort(service)



1898
1899
1900
# File '../../src/include/firewall/uifunctions.rb', line 1898

def GetBcastServicePort(service)
  Ops.get(@service_to_port, service, "")
end

- (Object) GetBcastServiceProtocol(service)



1894
1895
1896
# File '../../src/include/firewall/uifunctions.rb', line 1894

def GetBcastServiceProtocol(service)
  Ops.get(@service_to_protocol, service, "")
end

- (Fixnum) GetPortNumber(ui_id)

Function checks port number got as parameter. If check fails SetFocus is called and an empty string is returned.

Parameters:

  • any

    UI id

Returns:

  • (Fixnum)

    port number (or nil)



1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
# File '../../src/include/firewall/uifunctions.rb', line 1098

def GetPortNumber(ui_id)
  ui_id = deep_copy(ui_id)
  port_to_be_checked = Convert.to_string(UI.QueryWidget(Id(ui_id), :Value))
  port_number = PortAliases.GetPortNumber(port_to_be_checked)

  # if port name wasn't found
  if port_number == nil
    Popup.Error(
      # TRANSLATORS: popup error message
      _(
        "Wrong port definition.\n" +
          "No port number found for this port name.\n" +
          "Use the port number instead of the port name.\n"
      )
    )

    # setfocus for GUI
    UI.SetFocus(Id(ui_id)) if ui_id != "" && ui_id != nil
  end

  port_number
end

- (Object) HandleAllowedServices(key, event)



911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
# File '../../src/include/firewall/uifunctions.rb', line 911

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

  current_zone = Convert.to_string(
    UI.QueryWidget(Id("allowed_services_zone"), :Value)
  )

  # changing zone
  if ret == "allowed_services_zone"
    RedrawAllowedServices(current_zone)
  elsif ret == "protect_from_internal"
    protect_from_internal = Convert.to_boolean(
      UI.QueryWidget(Id("protect_from_internal"), :Value)
    )
    SuSEFirewall.SetProtectFromInternalZone(protect_from_internal)
    RedrawAllowedServices(current_zone)
  elsif ret == "add_allowed_service"
    add_service = Convert.to_string(
      UI.QueryWidget(Id("allow_service_names"), :Value)
    )
    SuSEFirewall.SetServicesForZones([add_service], [current_zone], true)
    RedrawAllowedServices(current_zone)
  elsif ret == "remove_allowed_service"
    if Confirm.DeleteSelected
      remove_service = Convert.to_string(
        UI.QueryWidget(Id("table_allowed_services"), :CurrentItem)
      )
      SuSEFirewall.SetServicesForZones(
        [remove_service],
        [current_zone],
        false
      )
      RedrawAllowedServices(current_zone)
    end
  elsif ret == "advanced_allowed_service"
    # redraw when "OK" button pressed
    if HandlePopupAdditionalServices(current_zone)
      RedrawAllowedServices(current_zone)
    end
  end

  nil
end

- (Object) HandleBroadcastReply(key, event)



2061
2062
2063
2064
2065
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
# File '../../src/include/firewall/uifunctions.rb', line 2061

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

  if ret == :add_br
    RedrawBroadcastReplyTable() if AddAcceptBroadcastReplyRule()
  elsif ret == :delete_br
    current_id = Convert.to_string(
      UI.QueryWidget(Id("table_broadcastreply"), :Value)
    )
    if current_id != nil && current_id != ""
      if Confirm.DeleteSelected
        item_to_delete = Builtins.splitstring(current_id, " ")
        items = SuSEFirewall.GetServicesAcceptRelated(
          Ops.get_string(item_to_delete, 0, "")
        )
        item_in_list = Builtins.tointeger(
          Ops.get_string(item_to_delete, 1, "-1")
        )
        Ops.set(items, item_in_list, nil)
        items = Builtins.filter(items) { |one_rule| one_rule != nil }
        SuSEFirewall.SetServicesAcceptRelated(
          Ops.get_string(item_to_delete, 0, ""),
          items
        )
        RedrawBroadcastReplyTable()
      end
    else
      Report.Error(_("Select an item to delete."))
    end
  end

  nil
end

- (Object) HandleCustomRules(key, event)



1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
# File '../../src/include/firewall/uifunctions.rb', line 1797

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

  selected_zone = Convert.to_string(
    UI.QueryWidget(Id("custom_rules_firewall_zone"), :Value)
  )

  if ret == "custom_rules_firewall_zone"
    @customrules_current_zone = selected_zone
    RedrawCustomRules(selected_zone)
  elsif ret == "add_custom_rule"
    if HandlePopupAddCustomRule(selected_zone)
      RedrawCustomRules(selected_zone)
    end
  elsif ret == "remove_custom_rule"
    current_item = Convert.to_integer(
      UI.QueryWidget(Id("custom_rules_table"), :CurrentItem)
    )

    if current_item != nil && Confirm.DeleteSelected
      DeleteSelectedCustomRule(selected_zone, current_item)
    end
  end

  nil
end

- (Object) HandleFirewallInterfaces(key, event)

Function handles whole firewall-interfaces dialg



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
# File '../../src/include/firewall/uifunctions.rb', line 419

def HandleFirewallInterfaces(key, event)
  event = deep_copy(event)
  ret = Ops.get(event, "ID")
  # "Activated" (double-click) or "SelectionChanged" (any other)
  event_reason = Ops.get_string(event, "EventReason", "SelectionChanged")

  current_item = Convert.to_string(
    UI.QueryWidget(Id("table_firewall_interfaces"), :CurrentItem)
  )

  # double click on the table item
  if ret == "table_firewall_interfaces" && event_reason == "Activated"
    # known iterface means -> as it was pressed [Change] button
    if Builtins.regexpmatch(current_item, "^known-")
      ret = "change_firewall_interface" 
      # known iterface means -> as it was pressed [Custom] button
    elsif Builtins.regexpmatch(current_item, "^special-")
      ret = "user_defined_firewall_interface"
    end
  end

  # Double click on the item or some modification button has been pressed
  if ret == "change_firewall_interface" ||
      ret == "user_defined_firewall_interface"
    # "change" can handle both interfaces and special strings
    if ret == "change_firewall_interface"
      # handling interfaces
      if Builtins.regexpmatch(current_item, "^known-")
        HandlePopupSetFirewallInterfaceIntoZone(
          Builtins.regexpsub(current_item, "^known-(.*)", "\\1")
        ) 
        # handling special strings
      elsif Builtins.regexpmatch(current_item, "^special-")
        HandlePopupAdditionalSettingsForZones()
      else
        Builtins.y2error("Uknown interfaces_item '%1'", current_item)
      end 
      # "user-defined" can only handle special strings
    elsif ret == "user_defined_firewall_interface"
      HandlePopupAdditionalSettingsForZones()
    end 
    # single click (changed current item)
  elsif ret == "table_firewall_interfaces" &&
      event_reason == "SelectionChanged"
    SetFirewallInterfacesCustomAndChangeButtons(current_item)
  end

  nil
end

- (Object) HandleIPsecSupport(key, event)



1380
1381
1382
1383
1384
1385
1386
1387
# File '../../src/include/firewall/uifunctions.rb', line 1380

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

  HandlePopupIPsecTrustAsZone() if ret == "ipsec_details"

  nil
end

- (Object) HandleMasquerading(key, event)



1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
# File '../../src/include/firewall/uifunctions.rb', line 1297

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

  if ret == "masquerade_networks"
    masquerade = Convert.to_boolean(
      UI.QueryWidget(Id("masquerade_networks"), :Value)
    )
    SuSEFirewall.SetMasquerade(masquerade)
    # enabling or disabling masquerade redirect table when masquerade enabled
    #if (!IsThisExpertConfiguration()) {
    SetMasqueradeTableUsable(masquerade) 
    #}
  end

  nil
end

- (Object) HandlePopupAddCustomRule(selected_zone)



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
1687
1688
1689
1690
1691
1692
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
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
# File '../../src/include/firewall/uifunctions.rb', line 1659

def HandlePopupAddCustomRule(selected_zone)
  UI.OpenDialog(
    @all_popup_definition,
    HBox(
      MinWidth(30, RichText(HelpForDialog("custom-rules-popup"))),
      AddCustomFirewallRule()
    )
  )
  UI.SetFocus(Id("add_source_network"))

  ret_value = false

  while true
    ret = UI.UserInput

    if ret == "cancel" || ret == :cancel
      break
    elsif ret == "ok"
      next if !ValidateExistency("add_source_network")
      next if !ValidateExistency("add_protocol")

      add_source_network = Convert.to_string(
        UI.QueryWidget(Id("add_source_network"), :Value)
      )
      add_protocol = Convert.to_string(
        UI.QueryWidget(Id("add_protocol"), :Value)
      )
      add_destination_port = Convert.to_string(
        UI.QueryWidget(Id("add_destination_port"), :Value)
      )
      add_source_port = Convert.to_string(
        UI.QueryWidget(Id("add_source_port"), :Value)
      )
      add_options = Convert.to_string(
        UI.QueryWidget(Id("add_options"), :Value)
      )

      # network is mandatory
      if add_source_network == "" || !IP.CheckNetwork(add_source_network)
        UI.SetFocus(Id("add_source_network"))
        Report.Error(
          Ops.add(
            Ops.add(
              Builtins.sformat(
                _("Invalid network definition '%1'"),
                add_source_network
              ),
              "\n"
            ),
            IP.ValidNetwork
          )
        )
        next
      end

      # destination port is optional
      if add_destination_port != ""
        if PortRanges.IsPortRange(add_destination_port)
          if !PortRanges.IsValidPortRange(add_destination_port)
            UI.SetFocus(Id("add_destination_port"))
            Report.Error(
              Builtins.sformat(
                _("Invalid port range '%1'"),
                add_destination_port
              )
            )
            next
          end
        elsif !CheckPortNameOrNumber(add_destination_port)
          UI.SetFocus(Id("add_destination_port"))
          Report.Error(
            Ops.add(
              Ops.add(
                Builtins.sformat(
                  _("Invalid port name or number '%1'"),
                  add_destination_port
                ),
                "\n"
              ),
              PortAliases.AllowedPortNameOrNumber
            )
          )
          next
        end
      end

      # source port is optional
      if add_source_port != ""
        if PortRanges.IsPortRange(add_source_port)
          if !PortRanges.IsValidPortRange(add_source_port)
            UI.SetFocus(Id("add_source_port"))
            Report.Error(
              Builtins.sformat(
                _("Invalid port range '%1'"),
                add_source_port
              )
            )
            next
          end
        elsif !CheckPortNameOrNumber(add_source_port)
          UI.SetFocus(Id("add_source_port"))
          Report.Error(
            Ops.add(
              Ops.add(
                Builtins.sformat(
                  _("Invalid port name or number '%1'"),
                  add_source_port
                ),
                "\n"
              ),
              PortAliases.AllowedPortNameOrNumber
            )
          )
          next
        end
      end

      SuSEFirewallExpertRules.AddNewAcceptRule(
        selected_zone,
        {
          "network"  => add_source_network,
          "protocol" => add_protocol,
          "dport"    => add_destination_port,
          "sport"    => add_source_port,
          "options"  => add_options
        }
      )

      ret_value = true
      break
    end
  end

  UI.CloseDialog

  ret_value
end

- (Object) HandlePopupAdditionalServices(zone)



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
# File '../../src/include/firewall/uifunctions.rb', line 654

def HandlePopupAdditionalServices(zone)
  zone_name = SuSEFirewall.GetZoneFullName(zone)

  UI.OpenDialog(@all_popup_definition, AdditionalServices(zone_name))

  # getting additional services
  additional_tcp = Builtins.toset(
    SuSEFirewall.GetAdditionalServices("TCP", zone)
  )
  additional_udp = Builtins.toset(
    SuSEFirewall.GetAdditionalServices("UDP", zone)
  )
  additional_rpc = Builtins.toset(
    SuSEFirewall.GetAdditionalServices("RPC", zone)
  )
  additional_ip = Builtins.toset(
    SuSEFirewall.GetAdditionalServices("IP", zone)
  )

  # filling up popup dialog
  UI.ChangeWidget(
    Id("additional_tcp"),
    :Value,
    Builtins.mergestring(additional_tcp, " ")
  )
  UI.ChangeWidget(
    Id("additional_udp"),
    :Value,
    Builtins.mergestring(additional_udp, " ")
  )
  UI.ChangeWidget(
    Id("additional_rpc"),
    :Value,
    Builtins.mergestring(additional_rpc, " ")
  )
  UI.ChangeWidget(
    Id("additional_ip"),
    :Value,
    Builtins.mergestring(additional_ip, " ")
  )

  # Filling up help
  UI.ChangeWidget(:help_text, :Value, HelpForDialog("additional-services"))

  ret = nil
  ret_value = false
  while true
    ret = UI.UserInput

    if ret == "ok"
      s_additional_tcp = Convert.to_string(
        UI.QueryWidget(Id("additional_tcp"), :Value)
      )
      new_additional_tcp = Builtins.toset(
        Builtins.splitstring(s_additional_tcp, " ")
      )

      s_additional_udp = Convert.to_string(
        UI.QueryWidget(Id("additional_udp"), :Value)
      )
      new_additional_udp = Builtins.toset(
        Builtins.splitstring(s_additional_udp, " ")
      )

      s_additional_rpc = Convert.to_string(
        UI.QueryWidget(Id("additional_rpc"), :Value)
      )
      new_additional_rpc = Builtins.toset(
        Builtins.splitstring(s_additional_rpc, " ")
      )

      s_additional_ip = Convert.to_string(
        UI.QueryWidget(Id("additional_ip"), :Value)
      )
      new_additional_ip = Builtins.toset(
        Builtins.splitstring(s_additional_ip, " ")
      )

      # Check the format
      next if !CheckAdditionalServicesDefinition(s_additional_tcp)
      next if !CheckAdditionalServicesDefinition(s_additional_udp)
      next if !CheckAdditionalServicesDefinition(s_additional_rpc)
      next if !CheckAdditionalServicesDefinition(s_additional_ip)

      # checking for known TCP and UDP port names
      if !CheckIfTheyAreAllKnownPorts("additional_tcp", new_additional_tcp)
        next
      end
      if !CheckIfTheyAreAllKnownPorts("additional_udp", new_additional_udp)
        next
      end

      SuSEFirewall.SetAdditionalServices("TCP", zone, new_additional_tcp)
      SuSEFirewall.SetAdditionalServices("UDP", zone, new_additional_udp)
      SuSEFirewall.SetAdditionalServices("RPC", zone, new_additional_rpc)
      SuSEFirewall.SetAdditionalServices("IP", zone, new_additional_ip)

      ret_value = true
      break
    elsif ret == "cancel" || ret == :cancel
      ret_value = false
      break
    end
  end

  UI.CloseDialog
  ret_value
end

- (Object) HandlePopupAdditionalSettingsForZones

Function handles popup with additional settings in zones



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
# File '../../src/include/firewall/uifunctions.rb', line 333

def HandlePopupAdditionalSettingsForZones
  starting_additionals = {}
  zones_additons = {}

  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone_shortname|
    specials = SuSEFirewall.GetSpecialInterfacesInZone(zone_shortname)
    Ops.set(starting_additionals, zone_shortname, specials)
    Ops.set(
      zones_additons,
      zone_shortname,
      {
        "name"  => SuSEFirewall.GetZoneFullName(zone_shortname),
        "items" => Builtins.mergestring(specials, " ")
      }
    )
  end

  UI.OpenDialog(
    @all_popup_definition,
    AdditionalSettingsForZones(zones_additons)
  )

  ret = Convert.to_string(UI.UserInput)

  changed = false
  if ret == "ok"
    events_remove = []
    events_add = []
    Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone_shortname|
      new_additions = Builtins.splitstring(
        Convert.to_string(
          UI.QueryWidget(
            Id(Ops.add("zone_additions_", zone_shortname)),
            :Value
          )
        ),
        " "
      )
      # checking for new additions
      Builtins.foreach(new_additions) do |new_addition_item|
        if new_addition_item != "" &&
            !Builtins.contains(
              Ops.get(starting_additionals, zone_shortname, []),
              new_addition_item
            )
          changed = true
          events_add = Builtins.add(
            events_add,
            [new_addition_item, zone_shortname]
          )
        end
      end
      # checking for removed additions
      Builtins.foreach(Ops.get(starting_additionals, zone_shortname, [])) do |old_addition_item|
        if old_addition_item != "" &&
            !Builtins.contains(new_additions, old_addition_item)
          changed = true
          events_remove = Builtins.add(
            events_remove,
            [old_addition_item, zone_shortname]
          )
        end
      end
    end
    Builtins.foreach(events_add) do |adding|
      SuSEFirewall.AddSpecialInterfaceIntoZone(
        Ops.get(adding, 0, ""),
        Ops.get(adding, 1, "")
      )
    end
    Builtins.foreach(events_remove) do |removing|
      SuSEFirewall.RemoveSpecialInterfaceFromZone(
        Ops.get(removing, 0, ""),
        Ops.get(removing, 1, "")
      )
    end
  end

  UI.CloseDialog

  RedrawFirewallInterfaces() if changed

  nil
end

- (Object) HandlePopupAddRedirectToMasqueradedIPRule



1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
# File '../../src/include/firewall/uifunctions.rb', line 1217

def HandlePopupAddRedirectToMasqueradedIPRule
  UI.OpenDialog(@all_popup_definition, AddRedirectToMasqueradedIPRule())
  UI.SetFocus(Id("add_source_network"))

  ret_value = false

  while true
    ret = UI.UserInput

    if ret == "cancel" || ret == :cancel
      break
    elsif ret == "ok"
      next if !ValidateExistency("add_requested_port")
      next if !ValidateExistency("add_source_network")
      next if !ValidateExistency("add_redirectto_ip")

      next if !ValidatePortEntry("add_requested_port")
      next if !ValidatePortEntry("add_redirectto_port")
      next if !ValidateIPEntry("add_redirectto_ip")

      # FIXME: checking for spaces in sttrings
      #        removing space from start or end of the string

      add_source_network = Convert.to_string(
        UI.QueryWidget(Id("add_source_network"), :Value)
      )
      add_requested_ip = Convert.to_string(
        UI.QueryWidget(Id("add_requested_ip"), :Value)
      )
      add_protocol = Convert.to_string(
        UI.QueryWidget(Id("add_protocol"), :Value)
      )
      add_requested_port = Convert.to_string(
        UI.QueryWidget(Id("add_requested_port"), :Value)
      )
      add_redirectto_ip = Convert.to_string(
        UI.QueryWidget(Id("add_redirectto_ip"), :Value)
      )
      add_redirectto_port = Convert.to_string(
        UI.QueryWidget(Id("add_redirectto_port"), :Value)
      )

      # Ports must be port numbers, getting port numbers from port names
      if add_requested_port != "" && add_requested_port != nil
        add_requested_port = Builtins.tostring(
          GetPortNumber("add_requested_port")
        )
        next if add_requested_port == nil
      end
      if add_redirectto_port != "" && add_redirectto_port != nil
        add_redirectto_port = Builtins.tostring(
          GetPortNumber("add_redirectto_port")
        )
        next if add_redirectto_port == nil
      end

      # Requested IP is optional
      next if add_requested_ip != "" && !ValidateIPEntry("add_requested_ip")

      SuSEFirewall.AddForwardIntoMasqueradeRule(
        add_source_network,
        add_redirectto_ip,
        add_protocol,
        add_requested_port,
        add_redirectto_port,
        add_requested_ip
      )

      ret_value = true
      break
    end
  end

  UI.CloseDialog

  RedrawRedirectToMasqueradedIPTable() if ret_value

  nil
end

- (Object) HandlePopupIPsecTrustAsZone



1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
# File '../../src/include/firewall/uifunctions.rb', line 1342

def HandlePopupIPsecTrustAsZone
  UI.OpenDialog(@all_popup_definition, IPsecTrustAsZone())

  default_value = SuSEFirewall.GetTrustIPsecAs
  UI.ChangeWidget(Id("trust_ipsec_as"), :Value, default_value)

  ret = UI.UserInput

  if ret == "ok"
    new_value = Convert.to_string(
      UI.QueryWidget(Id("trust_ipsec_as"), :Value)
    )
    SuSEFirewall.SetTrustIPsecAs(new_value)
  end

  UI.CloseDialog

  nil
end

- (Object) HandlePopupSetFirewallInterfaceIntoZone(interface)

Function handles popup dialog witch setting Interface into Zone



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
# File '../../src/include/firewall/uifunctions.rb', line 285

def HandlePopupSetFirewallInterfaceIntoZone(interface)
  # interface could be unassigned
  # TRANSLATORAS: selection box item, connected with firewall zone of interface
  zones = [Item(Id(""), _("No Zone Assigned"))]
  # current zone of interface
  current_zone = SuSEFirewall.GetZoneOfInterface(interface)
  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone_shortname|
    zones = Builtins.add(
      zones,
      Item(
        Id(zone_shortname),
        SuSEFirewall.GetZoneFullName(zone_shortname),
        zone_shortname == current_zone ? true : false
      )
    )
  end

  # opening popup
  UI.OpenDialog(
    @all_popup_definition,
    SetFirewallInterfaceIntoZone(
      Ops.get(@known_device_names, interface, ""),
      interface,
      zones
    )
  )

  ret = Convert.to_string(UI.UserInput)

  changed = false
  if ret == "ok"
    new_zone = Convert.to_string(
      UI.QueryWidget(Id("zone_for_interface"), :Value)
    )
    if new_zone != current_zone
      changed = true
      SuSEFirewall.AddInterfaceIntoZone(interface, new_zone)
    end
  end

  UI.CloseDialog

  RedrawFirewallInterfaces() if changed

  nil
end

- (Object) HandleRedirectToMasqueradedIP(key, event)



1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
# File '../../src/include/firewall/uifunctions.rb', line 1315

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

  if ret == "add_redirect_to_masquerade"
    HandlePopupAddRedirectToMasqueradedIPRule()
  elsif ret == "remove_redirect_to_masquerade"
    current_item = Convert.to_integer(
      UI.QueryWidget(Id("table_redirect_masq"), :CurrentItem)
    )
    if Confirm.DeleteSelected
      SuSEFirewall.RemoveForwardIntoMasqueradeRule(current_item)
      RedrawRedirectToMasqueradedIPTable()
    end
  end

  nil
end

- (Object) InitAllowedServices(key)



880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
# File '../../src/include/firewall/uifunctions.rb', line 880

def InitAllowedServices(key)
  SetFirewallIcon()

  if SuSEFirewall.GetProtectFromInternalZone
    UI.ChangeWidget(Id("protect_from_internal"), :Value, true)
  else
    UI.ChangeWidget(Id("protect_from_internal"), :Value, false)
  end

  # The default zone
  init_zone = "EXT"

  # All zones
  all_currently_known_zones = SuSEFirewall.GetKnownFirewallZones

  # The default zone must exist in configuration
  if !Builtins.contains(all_currently_known_zones, init_zone)
    init_zone = Ops.get(all_currently_known_zones, 0)
  end
  # Checking
  if init_zone == nil
    Builtins.y2error("There are no zones defined!")
    return
  end

  RedrawAllowedServices(init_zone)
  UI.ChangeWidget(Id("allowed_services_zone"), :Value, init_zone)

  nil
end

- (Object) InitBroadcastConfigurationSimple(key)



1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
# File '../../src/include/firewall/uifunctions.rb', line 1430

def InitBroadcastConfigurationSimple(key)
  SetFirewallIcon()

  replace_dialog = VBox()

  allowed_bcast_ports = SuSEFirewall.GetBroadcastAllowedPorts

  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
    zone_name = SuSEFirewall.GetZoneFullName(zone)
    ports_for_zone = Builtins.mergestring(
      Ops.get(allowed_bcast_ports, zone, []),
      " "
    )
    log_packets = SuSEFirewall.GetIgnoreLoggingBroadcast(zone) == "no"
    replace_dialog = Builtins.add(
      replace_dialog,
      HBox(
        HWeight(
          40,
          InputField(
            Id(Ops.add("bcast_ports_", zone)),
            Opt(:hstretch),
            zone_name,
            ports_for_zone
          )
        ),
        HWeight(
          60,
          VBox(
            Label(""),
            # TRANSLATORS: check box
            CheckBox(
              Id(Ops.add("bcast_log_", zone)),
              _("&Log Not Accepted Broadcast Packets"),
              log_packets
            )
          )
        )
      )
    )
  end

  UI.ReplaceWidget(Id("replace_point_bcast"), replace_dialog)

  nil
end

- (Object) InitBroadcastReply(key)



1888
1889
1890
1891
1892
# File '../../src/include/firewall/uifunctions.rb', line 1888

def InitBroadcastReply(key)
  RedrawBroadcastReplyTable()

  nil
end

- (Object) InitCustomRules(key)



1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
# File '../../src/include/firewall/uifunctions.rb', line 1601

def InitCustomRules(key)
  SetFirewallIcon()

  # set the default once, EXT is the first one
  if @customrules_current_zone == nil
    Builtins.foreach(
      Convert.convert(
        Builtins.union(SuSEFirewall.GetKnownFirewallZones, ["EXT"]),
        :from => "list",
        :to   => "list <string>"
      )
    ) do |one_zone|
      # at least one interface in the zone
      if Ops.greater_than(
          Builtins.size(
            SuSEFirewall.GetInterfacesInZoneSupportingAnyFeature(one_zone)
          ),
          0
        )
        @customrules_current_zone = one_zone
      end
    end
    # nothing found, set the default manually
    @customrules_current_zone = "EXT" if @customrules_current_zone == nil
  end

  UI.ChangeWidget(
    Id("custom_rules_firewall_zone"),
    :Value,
    @customrules_current_zone
  )

  RedrawCustomRules(@customrules_current_zone)

  nil
end

- (Object) InitFirewallInterfaces(key)

Function initializes Interfaces table and known_device_names



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
# File '../../src/include/firewall/uifunctions.rb', line 245

def InitFirewallInterfaces(key)
  SetFirewallIcon()

  # initializing names of interfaces
  @known_device_names = {}
  Builtins.foreach(SuSEFirewall.GetAllKnownInterfaces) do |known_interface|
    # shortening the network card name
    if Ops.greater_than(
        Builtins.size(Ops.get(known_interface, "name", "")),
        @max_length_intname
      )
      Ops.set(
        known_interface,
        "name",
        Ops.add(
          Builtins.substring(
            Ops.get(known_interface, "name", ""),
            0,
            Ops.subtract(@max_length_intname, 3)
          ),
          "..."
        )
      )
    end
    Ops.set(
      @known_device_names,
      Ops.get(known_interface, "id", ""),
      Ops.get(known_interface, "name", "")
    )
  end

  # known interfaces/string have ID: "known-" + interface
  # uknown strings have          ID: "special-" + string

  RedrawFirewallInterfaces()

  nil
end

- (Object) initialize_firewall_uifunctions(include_target)



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
# File '../../src/include/firewall/uifunctions.rb', line 35

def initialize_firewall_uifunctions(include_target)
  Yast.import "UI"
  textdomain "firewall"

  Yast.import "Confirm"
  Yast.import "SuSEFirewall"
  Yast.import "SuSEFirewallServices"
  Yast.import "SuSEFirewallExpertRules"
  Yast.import "PortAliases"
  Yast.import "Popup"
  Yast.import "Wizard"
  Yast.import "Report"
  Yast.import "Label"
  Yast.import "Mode"
  Yast.import "IP"
  Yast.import "Netmask"
  Yast.import "PortRanges"

  Yast.include include_target, "firewall/generalfunctions.rb"
  Yast.include include_target, "firewall/helps.rb"
  Yast.include include_target, "firewall/subdialogs.rb"

  # GLOBAL UI CONFIGURATION
  @all_popup_definition = Opt(:decorated, :centered)

  # maximum length of the string "Interface Name" (min. 3)
  @max_length_intname = 35

  # map of device names
  @known_device_names = {}

  @firewall_enabled_st = nil
  @firewall_started_st = nil

  @customrules_current_zone = nil

  @service_to_protocol = {
    "samba"   => "udp",
    "slp"     => "udp",
    "all-udp" => "udp",
    "all-ycp" => "udp"
  }

  @service_to_port = {
    "samba"   => "137",
    "slp"     => "427",
    "all-udp" => "",
    "all-tcp" => ""
  }
end

- (Object) InitIPsecSupport(key)

IPsec support opens IPsec traffic from external zone



1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
# File '../../src/include/firewall/uifunctions.rb', line 1363

def InitIPsecSupport(key)
  SetFirewallIcon()

  # FIXME: check whether such service exists
  supported = SuSEFirewall.IsServiceSupportedInZone("service:ipsec", "EXT")

  if supported == nil
    Builtins.y2error("No such service 'service:ipsec'")
    UI.ChangeWidget(Id("ispsec_support"), :Enabled, false)
  else
    UI.ChangeWidget(Id("ispsec_support"), :Enabled, true)
    UI.ChangeWidget(Id("ispsec_support"), :Value, supported)
  end

  nil
end

- (Object) InitLoggingLevel(key)



1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
# File '../../src/include/firewall/uifunctions.rb', line 1399

def InitLoggingLevel(key)
  SetFirewallIcon()

  UI.ChangeWidget(
    Id("logging_ACCEPT"),
    :Value,
    SuSEFirewall.GetLoggingSettings("ACCEPT")
  )
  UI.ChangeWidget(
    Id("logging_DROP"),
    :Value,
    SuSEFirewall.GetLoggingSettings("DROP")
  )

  nil
end

- (Object) InitMasquerading(key)



1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
# File '../../src/include/firewall/uifunctions.rb', line 1007

def InitMasquerading(key)
  SetFirewallIcon()

  masquerade = SuSEFirewall.GetMasquerade
  masquerade_possible = IsMasqueradingPossible()

  # setting checkbox
  UI.ChangeWidget(Id("masquerade_networks"), :Value, masquerade)

  # enabling or disabling masquerade redirect table when masquerading is enabled
  # and also possible
  #if (!IsThisExpertConfiguration()) {
  SetMasqueradeTableUsable(masquerade && masquerade_possible)
  #}

  # impossible masquerading, user gets information why
  if !masquerade_possible
    # disabling checkbox
    UI.ChangeWidget(Id("masquerade_networks"), :Enabled, false)

    UI.ReplaceWidget(
      Id("replacepoint_masquerade_information"), #:
      #`Left(`Label("FIXME: missing functionality for expert configuration"))
      #)
      #(!IsThisExpertConfiguration() ?
      # TRANSLATORS: informative label
      Left(
        Label(
          _(
            "Masquerading needs at least one external interface and one other interface."
          )
        )
      )
    )
  end

  nil
end

- (Object) InitRedirectToMasqueradedIP(key)



1334
1335
1336
1337
1338
1339
1340
# File '../../src/include/firewall/uifunctions.rb', line 1334

def InitRedirectToMasqueradedIP(key)
  SetFirewallIcon()

  RedrawRedirectToMasqueradedIPTable()

  nil
end

- (Object) InitServiceStartVsStartedStopped(key)



1501
1502
1503
1504
1505
1506
# File '../../src/include/firewall/uifunctions.rb', line 1501

def InitServiceStartVsStartedStopped(key)
  @firewall_enabled_st = SuSEFirewall.GetEnableService
  @firewall_started_st = SuSEFirewall.IsStarted

  nil
end

- (Boolean) IsMasqueradingPossible

Function returns if masquerading is possible. Masquerading needs at least two interfaces in two different firewall zones. One of them has to be External.

Returns:

  • (Boolean)

    if possible.



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
# File '../../src/include/firewall/uifunctions.rb', line 972

def IsMasqueradingPossible
  # FIXME: for Expert configuration, there is possible to set the masqueraded zone
  #        it is EXT for Simple configuration as default
  possible = false

  # if (!IsThisExpertConfiguration()) {
  # needs to have any external and any other interface
  has_external = false
  has_other = false

  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
    # no interfaces in zone
    if Builtins.size(
        Builtins.union(
          SuSEFirewall.GetInterfacesInZone(zone),
          SuSEFirewall.GetSpecialInterfacesInZone(zone)
        )
      ) == 0
      next
    end
    if zone == "EXT"
      has_external = true
    else
      has_other = true
    end
  end

  possible = has_external && has_other
  # } else {
  #    y2error("FIXME: missing functionality for expert configuration");
  #}

  possible
end

- (Object) RedrawAllowedServices(current_zone)



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
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
# File '../../src/include/firewall/uifunctions.rb', line 782

def RedrawAllowedServices(current_zone)
  if !Builtins.contains(SuSEFirewall.GetKnownFirewallZones, current_zone)
    Builtins.y2error("Unknown zone '%1'", current_zone)
    return nil
  end

  # FIXME: protect from internal, disabling table, etc...

  allowed_services = []
  # sorted by translated service_name
  translations_to_service_ids = {}

  Builtins.foreach(SuSEFirewallServices.GetSupportedServices) do |service_id, service_name|
    # a service with the very same name (translation) already defined
    if Ops.get(translations_to_service_ids, service_name) != nil
      # service:apache2 -> apache2
      if SuSEFirewallServices.ServiceDefinedByPackage(service_id)
        service_name = Builtins.sformat(
          "%1 (%2)",
          service_name,
          SuSEFirewallServices.GetFilenameFromServiceDefinedByPackage(
            service_id
          )
        )
      else
        service_name = Builtins.sformat("%1 (%2)", service_name, service_id)
      end
    end
    Ops.set(translations_to_service_ids, service_name, service_id)
  end

  all_known_services = GetDefinedServicesListedItems()
  not_allowed_services = []

  # not protected, all services are allowed
  if current_zone == "INT" && !SuSEFirewall.GetProtectFromInternalZone
    Builtins.foreach(translations_to_service_ids) do |service_name, service_id|
      allowed_services = Builtins.add(
        allowed_services,
        Item(Id(service_id), service_name)
      )
    end 
    # protected, only allowed services
  else
    Builtins.foreach(translations_to_service_ids) do |service_name, service_id|
      if SuSEFirewall.IsServiceSupportedInZone(service_id, current_zone)
        allowed_services = Builtins.add(
          allowed_services,
          Item(
            Id(service_id),
            service_name,
            SuSEFirewallServices.GetDescription(service_id)
          )
        )
      else
        not_allowed_services = Builtins.add(
          not_allowed_services,
          Item(Id(service_id), service_name)
        )
      end
    end
  end

  # BNC #461790: A better sorting
  allowed_services = Builtins.sort(allowed_services) do |x, y|
    Ops.less_or_equal(
      Builtins.tolower(Ops.get_string(x, 1, "a")),
      Builtins.tolower(Ops.get_string(y, 1, "b"))
    )
  end
  not_allowed_services = Builtins.sort(not_allowed_services) do |x, y|
    Ops.less_or_equal(
      Builtins.tolower(Ops.get_string(x, 1, "a")),
      Builtins.tolower(Ops.get_string(y, 1, "b"))
    )
  end

  UI.ChangeWidget(Id("table_allowed_services"), :Items, allowed_services)
  UI.ReplaceWidget(
    Id("allow_service_names_replacepoint"),
    # TRANSLATORS: select box
    ComboBox(
      Id("allow_service_names"),
      _("&Service to Allow"),
      not_allowed_services
    )
  )

  # disable or enable buttons, selectboxes, table
  RedrawAllowedServicesDialog(current_zone)

  if Builtins.size(allowed_services) == 0
    UI.ChangeWidget(Id("remove_allowed_service"), :Enabled, false)
  end

  nil
end

- (Object) RedrawAllowedServicesDialog(current_zone)



763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
# File '../../src/include/firewall/uifunctions.rb', line 763

def RedrawAllowedServicesDialog(current_zone)
  if SuSEFirewall.GetProtectFromInternalZone == false &&
      current_zone == "INT"
    UI.ChangeWidget(Id("allow_service_names"), :Enabled, false)
    UI.ChangeWidget(Id("add_allowed_service"), :Enabled, false)
    UI.ChangeWidget(Id("table_allowed_services"), :Enabled, false)
    UI.ChangeWidget(Id("remove_allowed_service"), :Enabled, false)
    UI.ChangeWidget(Id("advanced_allowed_service"), :Enabled, false)
  else
    UI.ChangeWidget(Id("allow_service_names"), :Enabled, true)
    UI.ChangeWidget(Id("add_allowed_service"), :Enabled, true)
    UI.ChangeWidget(Id("table_allowed_services"), :Enabled, true)
    UI.ChangeWidget(Id("remove_allowed_service"), :Enabled, true)
    UI.ChangeWidget(Id("advanced_allowed_service"), :Enabled, true)
  end

  nil
end

- (Object) RedrawBroadcastReplyTable



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
# File '../../src/include/firewall/uifunctions.rb', line 1851

def RedrawBroadcastReplyTable
  items = []

  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
    ruleset = SuSEFirewall.GetServicesAcceptRelated(zone)
    rule_in_ruleset = -1
    Builtins.foreach(ruleset) do |one_rule|
      rule_in_ruleset = Ops.add(rule_in_ruleset, 1)
      rulelist = Builtins.splitstring(one_rule, ",")
      items = Builtins.add(
        items,
        Item(
          Id(Builtins.sformat("%1 %2", zone, rule_in_ruleset)),
          SuSEFirewall.GetZoneFullName(zone),
          Builtins.sformat(
            GetBcastServiceName(
              Ops.get(rulelist, 1, ""),
              Ops.get(rulelist, 2, "")
            )
          ),
          GetBcastNetworkName(Ops.get(rulelist, 0, "0/0"))
        )
      )
    end
  end

  if UI.WidgetExists(Id("table_broadcastreply"))
    UI.ChangeWidget(Id("table_broadcastreply"), :Items, items)
  end

  if UI.WidgetExists(Id(:delete_br))
    UI.ChangeWidget(Id(:delete_br), :Enabled, Builtins.size(items) != 0)
  end

  nil
end

- (Object) RedrawCustomRules(current_zone)



1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
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
1594
1595
1596
1597
1598
1599
# File '../../src/include/firewall/uifunctions.rb', line 1556

def RedrawCustomRules(current_zone)
  if current_zone == nil ||
      !Builtins.contains(SuSEFirewall.GetKnownFirewallZones, current_zone)
    Builtins.y2error("Unknown zone '%1'", current_zone)
    return nil
  end

  rules = SuSEFirewallExpertRules.GetListOfAcceptRules(current_zone)

  # some rules are already defined
  if Ops.greater_than(Builtins.size(rules), 0)
    counter = -1
    items = Builtins.maplist(rules) do |one_rule|
      counter = Ops.add(counter, 1)
      Item(
        Id(counter),
        Ops.get(one_rule, "network", ""),
        SuSEFirewall.GetProtocolTranslatedName(
          Ops.get(one_rule, "protocol", "")
        ),
        UserReadablePortName(
          Ops.get(one_rule, "dport", ""),
          Ops.get(one_rule, "protocol", "")
        ),
        UserReadablePortName(Ops.get(one_rule, "sport", ""), ""),
        Ops.get(one_rule, "options", "")
      )
    end

    items = Builtins.sort(items) do |aa, bb|
      Ops.less_than(Ops.get_string(aa, 1, ""), Ops.get_string(bb, 1, ""))
    end

    UI.ChangeWidget(Id("custom_rules_table"), :Items, items)
    UI.ChangeWidget(Id("remove_custom_rule"), :Enabled, true) 

    # no rules defined
  else
    UI.ChangeWidget(Id("custom_rules_table"), :Items, [])
    UI.ChangeWidget(Id("remove_custom_rule"), :Enabled, false)
  end

  nil
end

- (Object) RedrawFirewallInterfaces

Function redraws Interfaces Table



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
# File '../../src/include/firewall/uifunctions.rb', line 178

def RedrawFirewallInterfaces
  table_items = []

  # firstly listing all known interfaces
  Builtins.foreach(SuSEFirewall.GetAllKnownInterfaces) do |interface|
    # TRANSLATORS: table item, connected with firewall zone of interface
    zone_name = _("No zone assigned")
    if Ops.get(interface, "zone") != nil
      zone_name = SuSEFirewall.GetZoneFullName(Ops.get(interface, "zone"))
    end
    # shortening the network card name
    if Ops.get(interface, "name") != nil &&
        Ops.greater_than(
          Builtins.size(Ops.get(interface, "name", "")),
          @max_length_intname
        )
      Ops.set(
        interface,
        "name",
        Ops.add(
          Builtins.substring(
            Ops.get(interface, "name", ""),
            0,
            Ops.subtract(@max_length_intname, 3)
          ),
          "..."
        )
      )
    end
    table_items = Builtins.add(
      table_items,
      Item(
        Id(Ops.add("known-", Ops.get(interface, "id"))),
        Ops.get(interface, "name"),
        Ops.get(interface, "id"),
        zone_name
      )
    )
  end

  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
    specials = SuSEFirewall.GetSpecialInterfacesInZone(zone)
    zone_name = SuSEFirewall.GetZoneFullName(zone)
    custom_string_text = ""
    Builtins.foreach(specials) do |special|
      # TRANSLATORS: table item, "User defined string" instead of Device_name
      custom_string_text = _("Custom string")
      table_items = Builtins.add(
        table_items,
        Item(
          Id(Ops.add("special-", special)),
          custom_string_text,
          special,
          zone_name
        )
      )
    end
  end

  UI.ChangeWidget(Id("table_firewall_interfaces"), :Items, table_items)

  SetFirewallInterfacesCustomAndChangeButtons(nil)

  nil
end

- (Object) RedrawRedirectToMasqueradedIPTable



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
# File '../../src/include/firewall/uifunctions.rb', line 1175

def RedrawRedirectToMasqueradedIPTable
  items = []

  row_id = 0
  Builtins.foreach(SuSEFirewall.GetListOfForwardsIntoMasquerade) do |rule|
    # redirect_to_port is the same as requested_port if not defined
    if Ops.get(rule, "to_port", "") == ""
      Ops.set(rule, "to_port", Ops.get(rule, "req_port", ""))
    end
    # printing port names rather then port numbers
    Builtins.foreach(["req_port", "to_port"]) do |key|
      Ops.set(
        rule,
        key,
        UserReadablePortName(
          Ops.get(rule, key, ""),
          Ops.get(rule, "protocol", "")
        )
      )
    end
    items = Builtins.add(
      items,
      Item(
        Id(row_id),
        Ops.get(rule, "source_net", ""),
        Ops.get(rule, "protocol", ""),
        Ops.get(rule, "req_ip", ""),
        Ops.get(rule, "req_port", ""),
        UI.Glyph(:BulletArrowRight),
        Ops.get(rule, "forward_to", ""),
        Ops.get(rule, "to_port", "")
      )
    )
    row_id = Ops.add(row_id, 1)
  end

  UI.ChangeWidget(Id("table_redirect_masq"), :Items, items)

  nil
end

- (Boolean) ReportWrongPortDefinition(port_nr, port_definition)

Reports that the port definition is wrong. Either a single port or a port range. Returns whether user accepts the wrong port definition despite this warning.

// maximum port number is 65535, port range boolean accepted = ReportWrongPortDefinition(99999, “5:99999”); // dtto., single port boolean whattodo = ReportWrongPortDefinition(78910, “78910”);

Parameters:

  • port_nr (String)
  • port_definition (String)

    might be a single port or a port-range definition

Returns:

  • (Boolean)

    whether user accepts the port definition despite the warning.



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
# File '../../src/include/firewall/uifunctions.rb', line 482

def ReportWrongPortDefinition(port_nr, port_definition)
  port_err = ""

  if port_nr == port_definition
    # TRANSLATORS: error message, %1 stands for the port number
    port_err = Builtins.sformat(_("Port number %1 is invalid."), port_nr)
  else
    # TRANSLATORS: error message, %1 stands for the port number,
    # %2 stands for, e.g., port range, where the wrong port definition %1 was found
    port_err = Builtins.sformat(
      _("Port number %1 in definition %2 is invalid."),
      port_nr,
      port_definition
    )
  end

  Popup.ContinueCancelHeadline(
    # TRANSLATORS: popup headline
    _("Invalid Port Definition"),
    Ops.add(
      Ops.add(port_err, "\n\n"),
      # TRANSLATORS: popup message, %1 stands for the maximal port number
      # that is possible to use in port-range
      Builtins.sformat(
        _(
          "The port number must be in the interval from 1 to %1 (inclusive)."
        ),
        SuSEFirewall.max_port_number
      )
    )
  )
end

- (Object) SaveAndRestart

Function saves configuration and restarts firewall



122
123
124
125
126
127
128
129
130
131
# File '../../src/include/firewall/uifunctions.rb', line 122

def SaveAndRestart
  Wizard.CreateDialog
  Wizard.RestoreHelp(HelpForDialog("saving_configuration"))
  success = SuSEFirewall.SaveAndRestartService
  SuSEFirewall.SetStartService(true) if success
  Builtins.sleep(500)
  UI.CloseDialog

  success
end

- (Object) SetEnableFirewall(new_state)



1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
# File '../../src/include/firewall/uifunctions.rb', line 1508

def SetEnableFirewall(new_state)
  if @firewall_enabled_st == new_state
    Builtins.y2milestone(
      "Enable firewall status preserved (enable=%1)",
      @firewall_enabled_st
    )
    return
  end

  curr_running = SuSEFirewall.IsStarted
  new_running = new_state

  # disabling firewall
  if new_state == false && curr_running == true
    # TRANSLATORS: popup question
    if Popup.YesNo(
        _(
          "Firewall automatic starting has been disabled\n" +
            "but firewall is currently running.\n" +
            "\n" +
            "Stop the firewall after the new configuration has been written?\n"
        )
      )
      Builtins.y2milestone(
        "User decided to stop the firewall after it is disabled"
      )
      new_running = false
    else
      Builtins.y2milestone(
        "User decided not to stop the firewall after it is disabled"
      )
      new_running = true
    end
  end

  # Changes the default values - Enable and Start at once
  SuSEFirewall.SetEnableService(new_state)
  SuSEFirewall.SetStartService(new_running)

  Builtins.y2milestone(
    "New Settings - Firewall Enabled: %1, Firewall Started: %2 (after Write())",
    SuSEFirewall.GetEnableService,
    SuSEFirewall.GetStartService
  )

  nil
end

- (Object) SetFirewallIcon

Sets the dialog icon.



106
107
108
109
110
# File '../../src/include/firewall/uifunctions.rb', line 106

def SetFirewallIcon
  Wizard.SetTitleIcon("yast-firewall")

  nil
end

- (Object) SetFirewallInterfacesCustomAndChangeButtons(current_item)

Function sets appropriate states for [Change] and [Custom] buttons



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File '../../src/include/firewall/uifunctions.rb', line 156

def SetFirewallInterfacesCustomAndChangeButtons(current_item)
  # if called from Init() function
  if current_item == nil
    current_item = Convert.to_string(
      UI.QueryWidget(Id("table_firewall_interfaces"), :CurrentItem)
    )
  end

  # string is one of known network interfaces
  if Builtins.regexpmatch(current_item, "^known-.*")
    UI.ChangeWidget(Id("change_firewall_interface"), :Enabled, true)
    UI.ChangeWidget(Id("user_defined_firewall_interface"), :Enabled, true) 
    # string is a custom string
  else
    UI.ChangeWidget(Id("change_firewall_interface"), :Enabled, false)
    UI.ChangeWidget(Id("user_defined_firewall_interface"), :Enabled, true)
  end

  nil
end

- (Object) SetMasqueradeTableUsable(usable)

Function sets UI for Masquerade Table (and buttons) enabled or disabled

Parameters:

  • boolean

    enable



959
960
961
962
963
964
965
# File '../../src/include/firewall/uifunctions.rb', line 959

def SetMasqueradeTableUsable(usable)
  UI.ChangeWidget(Id("table_redirect_masq"), :Enabled, usable)
  UI.ChangeWidget(Id("add_redirect_to_masquerade"), :Enabled, usable)
  UI.ChangeWidget(Id("remove_redirect_to_masquerade"), :Enabled, usable)

  nil
end

- (Object) StartNow

Function starts Firewall services and sets firewall to be started after exiting YaST



135
136
137
138
139
140
141
142
# File '../../src/include/firewall/uifunctions.rb', line 135

def StartNow
  UI.OpenDialog(Label(_("Starting firewall...")))
  SuSEFirewall.SetStartService(true)
  ret = SuSEFirewall.StartServices
  UI.CloseDialog

  ret
end

- (Object) StopNow

Function stops Firewall services and sets firewall to be stopped after exiting YaST



146
147
148
149
150
151
152
153
# File '../../src/include/firewall/uifunctions.rb', line 146

def StopNow
  UI.OpenDialog(Label(_("Stopping firewall...")))
  SuSEFirewall.SetStartService(false)
  ret = SuSEFirewall.StopServices
  UI.CloseDialog

  ret
end

- (Object) StoreBroadcastConfigurationSimple(key, event)

FIXME: should check for PortAliases::IsKnownPortName() in future



1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
# File '../../src/include/firewall/uifunctions.rb', line 1478

def StoreBroadcastConfigurationSimple(key, event)
  event = deep_copy(event)
  allowed_bcast_ports = {}

  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
    allowed_ports = Builtins.splitstring(
      Convert.to_string(
        UI.QueryWidget(Id(Ops.add("bcast_ports_", zone)), :Value)
      ),
      " "
    )
    log_packets = Convert.to_boolean(
      UI.QueryWidget(Id(Ops.add("bcast_log_", zone)), :Value)
    )
    Ops.set(allowed_bcast_ports, zone, allowed_ports)
    SuSEFirewall.SetIgnoreLoggingBroadcast(zone, log_packets ? "no" : "yes")
  end

  SuSEFirewall.SetBroadcastAllowedPorts(allowed_bcast_ports)

  nil
end

- (Object) StoreIPsecSupport(key, event)



1389
1390
1391
1392
1393
1394
1395
1396
1397
# File '../../src/include/firewall/uifunctions.rb', line 1389

def StoreIPsecSupport(key, event)
  event = deep_copy(event)
  to_support = Convert.to_boolean(
    UI.QueryWidget(Id("ispsec_support"), :Value)
  )
  SuSEFirewall.SetServicesForZones(["ipsec"], ["EXT"], to_support)

  nil
end

- (Object) StoreLoggingLevel(key, event)



1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
# File '../../src/include/firewall/uifunctions.rb', line 1416

def StoreLoggingLevel(key, event)
  event = deep_copy(event)
  SuSEFirewall.SetLoggingSettings(
    "ACCEPT",
    Convert.to_string(UI.QueryWidget(Id("logging_ACCEPT"), :Value))
  )
  SuSEFirewall.SetLoggingSettings(
    "DROP",
    Convert.to_string(UI.QueryWidget(Id("logging_DROP"), :Value))
  )

  nil
end

- (Object) UserReadablePortName(port, protocol)



1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
# File '../../src/include/firewall/uifunctions.rb', line 1149

def UserReadablePortName(port, protocol)
  return "" if port == ""
  return nil if port == nil

  protocol = Builtins.tolower(protocol)
  # Do not seek port number for RPC services
  return port if protocol == "rpc" || protocol == "_rpc_"

  # number
  if Builtins.regexpmatch(port, "^[0123456789]+$")
    port_name = GetPortName(port)
    # port name must be known and not the same as defined yet
    if port_name != nil && port_name != port
      port = Builtins.sformat("%1 (%2)", port_name, port)
    end 
    # not a port range
  elsif !Builtins.regexpmatch(port, "^[0123456789]+:[0123456789]+$")
    port_number = PortAliases.GetPortNumber(port)
    if port_number != nil && Builtins.tostring(port_number) != port
      port = Builtins.sformat("%1 (%2)", port, port_number)
    end
  end

  port
end

- (Object) ValidateBroadcastReplyRule(zone, network, service, protocol, port)



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
# File '../../src/include/firewall/uifunctions.rb', line 1902

def ValidateBroadcastReplyRule(zone, network, service, protocol, port)
  return true if service != "user-defined"

  if !IP.CheckNetwork(network)
    UI.SetFocus(Id(:network))
    Report.Error(
      Ops.add(
        Ops.add(
          Builtins.sformat(_("Invalid network definition '%1'"), network),
          "\n"
        ),
        IP.ValidNetwork
      )
    )
    return false
  end

  if !PortAliases.IsAllowedPortName(port)
    UI.SetFocus(Id(:port))
    Report.Error(
      Ops.add(
        Ops.add(
          Builtins.sformat(_("Invalid port name or number '%1'"), port),
          "\n"
        ),
        PortAliases.AllowedPortNameOrNumber
      )
    )
    return false
  end

  true
end

- (Object) ValidateExistency(ui_id)

Validates existency of a value in a referenced UI entry and reports error otherwise

Parameters:

  • any

    UI id



1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
# File '../../src/include/firewall/uifunctions.rb', line 1051

def ValidateExistency(ui_id)
  ui_id = deep_copy(ui_id)
  if UI.QueryWidget(Id(ui_id), :Value) == ""
    UI.SetFocus(Id(ui_id))
    # TRANSLATORS: popup message
    Popup.Error(_("This entry must be completed."))
    return false
  end
  true
end

- (Boolean) ValidateIPEntry(ui_id)

Checks whether the referenced UI entry contains a valid IPv4 or v6 and reports error otherwise.

Parameters:

  • any

    UI id

Returns:

  • (Boolean)

    whether it's valid IP



1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
# File '../../src/include/firewall/uifunctions.rb', line 1126

def ValidateIPEntry(ui_id)
  ui_id = deep_copy(ui_id)
  ip = Convert.to_string(UI.QueryWidget(Id(ui_id), :Value))
  if !IP.Check(ip)
    UI.SetFocus(Id(ui_id))
    Popup.Error(
      Ops.add(
        Ops.add(
          Ops.add(
            # TRANSLATORS: popup message, right definition is two lines below this message
            _("Invalid IP definition.") + "\n\n",
            IP.Valid4
          ),
          "\n"
        ),
        IP.Valid6
      )
    )
    return false
  end
  true
end

- (Boolean) ValidatePortEntry(ui_id)

Checks whether the referenced UI entry contains a valid port definition and reports an error otherwise

Parameters:

  • any

    UI id

Returns:

  • (Boolean)

    if entry is valid



1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
# File '../../src/include/firewall/uifunctions.rb', line 1067

def ValidatePortEntry(ui_id)
  ui_id = deep_copy(ui_id)
  port = Convert.to_string(UI.QueryWidget(Id(ui_id), :Value))

  # no port can be allowed
  return true if port == ""

  # checking for port-name rightness
  if !PortAliases.IsAllowedPortName(port)
    UI.SetFocus(Id(ui_id))
    Popup.Error(
      Ops.add(
        # TRANSLATORS: popup message, right port definition is two lines below this message
        _("Wrong port definition.") + "\n\n",
        PortAliases.AllowedPortNameOrNumber
      )
    )
    return false
  end

  # checking for known TCP and UDP port names
  return false if !CheckIfTheyAreAllKnownPorts(ui_id, [port])

  true
end