Class: Yast::CWMFirewallInterfacesClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) CheckPossbilityToChangeFirewall(new_status)

Checks whether it is possible to change the firewall status



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

def CheckPossbilityToChangeFirewall(new_status)
  # Reset buggy ifaces
  @buggy_ifaces = []

  # User want's to disable the service in firewall
  # that works always
  return true if new_status == false

  # 'any' in 'EXT'
  # interfaces are mentioned in some zone or they are covered by the special string
  # enable-on-all or disable-on-all will work
  return true if SuSEFirewall.IsAnyNetworkInterfaceSupported

  # every network interface must have its zone assigned
  all_ok = true
  all_ifaces = SuSEFirewall.GetAllKnownInterfaces
  Builtins.foreach(SuSEFirewall.GetAllKnownInterfaces) do |one_interface|
    if Ops.get(one_interface, "zone").nil? ||
        Ops.get(one_interface, "zone", "") == ""
      Builtins.y2warning(
        "Cannot enable service because interface %1 is not mentioned anywhere...",
        Ops.get(one_interface, "id", "ID")
      )
      @buggy_ifaces = Builtins.add(
        @buggy_ifaces,
        Ops.get(one_interface, "id", "interface")
      )
      all_ok = false
    end
  end
  if all_ok
    return true
  else
    ifaces_list = Builtins.mergestring(@buggy_ifaces, "\n")
    # yes-no popup
    if Popup.YesNo(
        Builtins.sformat(
          _(
            "Because of SuSE Firewall settings, the port\n" \
              "on the following interfaces cannot be opened:\n" \
              "%1\n" \
              "\n" \
              "Continue?"
          ),
          ifaces_list
        )
      )
      # all known ifaces are buggy
      if Builtins.size(@buggy_ifaces) == Builtins.size(all_ifaces)
        return false
      else
        # at least one iface isn't buggy
        return true
      end
    else
      # cancel
      @buggy_ifaces = deep_copy(@all_interfaces)
      return false
    end
  end

  false
end

- (Hash) CreateInterfacesWidget(settings)

Get the widget description map <pre>

Behavior manipulating functions (mandatory) - “get_allowed_interfaces” : list<string>() – function that returns the list of allowed network interfaces - “set_allowed_interfaces” : void (list<string>) – function that sets the list of allowed interfaces

Additional settings: - “help” : string – help to the whole widget. If not specified, generic help is used (button labels are patched correctly) </pre>

Parameters:

  • settings (Hash{String => Object})

    a map of all parameters needed to create the widget properly

Returns:

  • (Hash)

    the widget description map



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

def CreateInterfacesWidget(settings)
  settings = deep_copy(settings)
  widget = HBox(
    HSpacing(1),
    VBox(
      HSpacing(48),
      VSpacing(1),
      ReplacePoint(
        Id("_cwm_interface_list_rp"),
        MultiSelectionBox(
          Id("_cwm_interface_list"),
          # translators: selection box title
          _("Network &Interfaces with Open Port in Firewall"),
          []
        )
      ),
      VSpacing(1),
      HBox(
        HStretch(),
        HWeight(
          1,
          PushButton(
            Id("_cwm_interface_select_all"),
            # push button to select all network intefaces for firewall
            _("Select &All")
          )
        ),
        HWeight(
          1,
          PushButton(
            Id("_cwm_interface_select_none"),
            # push button to deselect all network intefaces for firewall
            _("Select &None")
          )
        ),
        HStretch()
      ),
      VSpacing(1)
    ),
    HSpacing(1)
  )

  help = "" # TODO

  if Builtins.haskey(settings, "help")
    help = Ops.get_string(settings, "help", "")
  end

  ret = Convert.convert(
    Builtins.union(
      settings,

      "widget"            => :custom,
      "custom_widget"     => widget,
      "help"              => help,
      "init"              => fun_ref(
        method(:InterfacesInitWrapper),
        "void (string)"
      ),
      "store"             => fun_ref(
        method(:InterfacesStoreWrapper),
        "void (string, map)"
      ),
      "handle"            => fun_ref(
        method(:InterfacesHandleWrapper),
        "symbol (string, map)"
      ),
      "validate_type"     => :function,
      "validate_function" => fun_ref(
        method(:InterfacesValidateWrapper),
        "boolean (string, map)"
      )

    ),
    from: "map",
    to:   "map <string, any>"
  )

  deep_copy(ret)
end

- (Hash) CreateOpenFirewallWidget(settings)

Get the widget description map of the firewall enablement widget <pre>

  • “services” : list<string> – services identifications for the Firewall.ycp module

  • “display_details” : boolean – true if the details button should be displayed

  • “firewall_details_handler” : symbol () – function to handle the firewall details button. If returns something else than nil, dialog is exited with the returned symbol as value for wizard sequencer. If not specified, but “display_details” is true, common popup is used.

  • “open_firewall_checkbox” : string – label of the check box

  • “firewall_details_button” : string – label of the push button for changing firewall details

  • “help” : string – help to the widget. If not specified, generic help is used </pre>

Parameters:

  • settings (Hash{String => Object})

    a map of all parameters needed to create the widget properly

Returns:

  • (Hash)

    the widget description map



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
1087
1088
1089
1090
1091
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
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File '../../src/modules/CWMFirewallInterfaces.rb', line 1055

def CreateOpenFirewallWidget(settings)
  settings = deep_copy(settings)
  help = ""
  # check box

  open_firewall_checkbox = Ops.get_locale(
    settings,
    "open_firewall_checkbox",
    _("Open Port in &Firewall")
  )
  # push button

  firewall_details_button = Ops.get_locale(
    settings,
    "firewall_details_button",
    _("Firewall &Details...")
  )

  display_firewall_details = Builtins.haskey(
    settings,
    "firewall_details_handler"
  ) ||
    Ops.get_boolean(settings, "display_details", false)
  if Builtins.haskey(settings, "help")
    help = Ops.get_string(settings, "help", "")
  else
    help = OpenFirewallHelp(display_firewall_details)
  end

  firewall_settings = CheckBox(
    Id("_cwm_open_firewall"),
    Opt(:notify),
    open_firewall_checkbox
  )
  if display_firewall_details
    firewall_settings = HBox(
      firewall_settings,
      HSpacing(2),
      PushButton(Id("_cwm_firewall_details"), firewall_details_button)
    )
  end
  firewall_settings = VBox(
    Frame(
      _("Firewall Settings"),
      VBox(
        Left(firewall_settings),
        Left(
          ReplacePoint(
            Id(:_cwm_firewall_status_rp),
            # label text
            Label(_("Firewall is open"))
          )
        )
      )
    )
  )

  if !Builtins.haskey(settings, "services")
    firewall_settings = VBox()
    help = ""
    Builtins.y2error("Firewall services not specified")
  end

  ret = Convert.convert(
    Builtins.union(
      {
        "widget"        => :custom,
        "custom_widget" => firewall_settings,
        "help"          => help,
        "init"          => fun_ref(
          method(:OpenFirewallInitWrapper),
          "void (string)"
        ),
        "store"         => fun_ref(
          method(:OpenFirewallStoreWrapper),
          "void (string, map)"
        ),
        "handle"        => fun_ref(
          method(:OpenFirewallHandleWrapper),
          "symbol (string, map)"
        ),
        "handle_events" => ["_cwm_firewall_details", "_cwm_open_firewall"]
      },
      settings
    ),
    from: "map",
    to:   "map <string, any>"
  )

  deep_copy(ret)
end

- (Object) DisableOpenFirewallWidget

Disable the whole firewal widget

Parameters:

  • key

    strnig the widget key



976
977
978
979
980
981
982
983
# File '../../src/modules/CWMFirewallInterfaces.rb', line 976

def DisableOpenFirewallWidget
  return if !UI.WidgetExists(Id("_cwm_open_firewall"))
  return if !UI.WidgetExists(Id("_cwm_firewall_details"))
  UI.ChangeWidget(Id("_cwm_open_firewall"), :Enabled, false)
  UI.ChangeWidget(Id("_cwm_firewall_details"), :Enabled, false)

  nil
end

- (Symbol) DisplayDetailsPopup(settings)

Display the firewall interfaces selection as a popup

Returns:

  • (Symbol)

    return value of the dialog



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

def DisplayDetailsPopup(settings)
  settings = deep_copy(settings)
  # FIXME: breaks help if run in dialog with Tab!!!!!!
  # settings stack must be created in CWM::Run
  w = CWM.CreateWidgets(
    ["firewall_ifaces"],
    "firewall_ifaces" => CreateInterfacesWidget(settings)
  )
  contents = VBox(
    "firewall_ifaces",
    ButtonBox(
      PushButton(Id(:ok), Opt(:okButton, :key_F10), Label.OKButton),
      PushButton(
        Id(:cancel),
        Opt(:cancelButton, :key_F9),
        Label.CancelButton
      )
    )
  )
  contents = CWM.PrepareDialog(contents, w)
  UI.OpenDialog(contents)
  ret = CWM.Run(w, {})
  UI.CloseDialog
  ret
end

- (Object) DisplayFirewallDetailsPopupHandler(widget)

Display popup with firewall settings details



271
272
273
274
275
276
277
278
279
280
281
# File '../../src/modules/CWMFirewallInterfaces.rb', line 271

def DisplayFirewallDetailsPopupHandler(widget)
  widget = deep_copy(widget)
  common_details_handler = Convert.convert(
    Ops.get(widget, "common_details_handler"),
    from: "any",
    to:   "void (map <string, any>)"
  )
  common_details_handler.call(widget) if !common_details_handler.nil?

  nil
end

- (Object) EnableOpenFirewallWidget

Enable the whole firewal widget

Parameters:

  • key

    strnig the widget key



965
966
967
968
969
970
971
972
# File '../../src/modules/CWMFirewallInterfaces.rb', line 965

def EnableOpenFirewallWidget
  return if !UI.WidgetExists(Id("_cwm_open_firewall"))
  return if !UI.WidgetExists(Id("_cwm_firewall_details"))
  UI.ChangeWidget(Id("_cwm_open_firewall"), :Enabled, true)
  EnableOrDisableFirewallDetails()

  nil
end

- (Object) EnableOrDisableFirewallDetails

Enable or disable the firewall details widget according to the status of “open firewall” checkbox



87
88
89
90
91
92
93
94
95
96
97
98
99
# File '../../src/modules/CWMFirewallInterfaces.rb', line 87

def EnableOrDisableFirewallDetails
  return if !UI.WidgetExists(Id("_cwm_open_firewall"))
  return if !UI.WidgetExists(Id("_cwm_firewall_details"))
  enabled = Convert.to_boolean(
    UI.QueryWidget(Id("_cwm_open_firewall"), :Value)
  )
  enabled = false if enabled.nil?
  enabled = false if Builtins.size(@all_interfaces) == 0

  UI.ChangeWidget(Id("_cwm_firewall_details"), :Enabled, enabled)

  nil
end

- (Object) InitAllInterfacesList

Initialize the list of all known interfaces



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

def InitAllInterfacesList
  # Do not read NetworkInterfaces when they are already read
  if !Mode.config && !Mode.installation && !Mode.update
    Builtins.y2milestone("Reading NetworkInterfaces...")
    NetworkInterfaces.Read
  end
  @all_interfaces = String.NonEmpty(NetworkInterfaces.List(""))
  @all_interfaces = Builtins.filter(@all_interfaces) { |i| i != "lo" }
  if !Mode.config
    @interface_items = Builtins.maplist(@all_interfaces) do |i|
      label = NetworkInterfaces.GetValue(i, "BOOTPROTO")
      ipaddr = NetworkInterfaces.GetValue(i, "IPADDR")
      # BNC #483455: Interface zone name
      zone = SuSEFirewall.GetZoneOfInterface(i)
      if !zone.nil? && zone != ""
        zone = SuSEFirewall.GetZoneFullName(zone)
      else
        zone = _("Interface is not assigned to any zone")
      end
      if label == "static" || label == "" || label.nil?
        label = ipaddr
      else
        label = Builtins.toupper(label)
        if !ipaddr.nil? && ipaddr != ""
          label = Builtins.sformat("%1/%2", label, ipaddr)
        end
      end
      if label.nil? || label == ""
        label = i
      else
        label = Builtins.sformat("%1 (%2 / %3)", i, label, zone)
      end
      Item(Id(i), label)
    end
  else
    @interface_items = Builtins.maplist(@all_interfaces) do |i|
      Item(Id(i), i)
    end
  end

  @any_iface_supported = SuSEFirewall.IsAnyNetworkInterfaceSupported

  nil
end

- (Object) InitAllowedInterfaces(services)

Initialize the list of allowed interfaces Changes the internal variables

Parameters:

  • services (Array<String>)

    a list of services



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

def InitAllowedInterfaces(services)
  services = deep_copy(services)
  service_status = {}

  ifaces_info = SuSEFirewall.GetServicesInZones(services)
  Builtins.foreach(ifaces_info) do |_s, status|
    Builtins.foreach(status) do |iface, en|
      Ops.set(
        service_status,
        iface,
        Ops.get(service_status, iface, true) && en
      )
    end
  end
  service_status = Builtins.filter(service_status) { |_iface, en| en == true }
  Builtins.y2milestone("Status: %1", service_status)
  @allowed_interfaces = Builtins.maplist(service_status) do |iface, _en|
    iface
  end

  # Checking whether the string 'any' is in the 'EXT' zone
  # If it is, checking the status of services for this zone
  # If it is enabled, adding it these interfaces into the list of allowed interfaces
  #                   and setting this zone to enabled
  if SuSEFirewall.IsAnyNetworkInterfaceSupported
    interfaces_supported_by_any = SuSEFirewall.InterfacesSupportedByAnyFeature(
      SuSEFirewall.special_all_interface_zone
    )
    if Ops.greater_than(Builtins.size(interfaces_supported_by_any), 0)
      Builtins.foreach(services) do |service|
        Ops.set(
          service_status,
          SuSEFirewall.special_all_interface_zone,
          SuSEFirewall.IsServiceSupportedInZone(
            service,
            SuSEFirewall.special_all_interface_zone
          ) &&
            Ops.get(
              service_status,
              SuSEFirewall.special_all_interface_zone,
              true
            )
        )
      end
      if Ops.get(
        service_status,
        SuSEFirewall.special_all_interface_zone,
        false
        )
        @allowed_interfaces = Convert.convert(
          Builtins.union(@allowed_interfaces, interfaces_supported_by_any),
          from: "list",
          to:   "list <string>"
        )
      end
    end
  end

  # Check the INT zone, it's not protected by default
  # See bnc #382686
  internal_interfaces = SuSEFirewall.GetInterfacesInZone("INT")
  if Ops.greater_than(Builtins.size(internal_interfaces), 0) &&
      SuSEFirewall.GetProtectFromInternalZone == false
    Builtins.y2milestone(
      "Unprotected internal interfaces: %1",
      internal_interfaces
    )
    @allowed_interfaces = Convert.convert(
      Builtins.union(@allowed_interfaces, internal_interfaces),
      from: "list",
      to:   "list <string>"
    )
  else
    Builtins.y2milestone(
      "Internal zone is protected or there are no interfaces in it"
    )
  end

  @configuration_changed = false

  nil
end

- (Symbol) InterfacesHandle(_widget, _key, event)

Handle function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map event to be handled

Returns:

  • (Symbol)

    for wizard sequencer or nil



431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File '../../src/modules/CWMFirewallInterfaces.rb', line 431

def InterfacesHandle(_widget, _key, event)
  event_id = Ops.get(event, "ID")
  if event_id == "_cwm_interface_select_all"
    UI.ChangeWidget(
      Id("_cwm_interface_list"),
      :SelectedItems,
      @all_interfaces
    )
    return nil
  end
  if event_id == "_cwm_interface_select_none"
    UI.ChangeWidget(Id("_cwm_interface_list"), :SelectedItems, [])
    return nil
  end
  nil
end

- (Symbol) InterfacesHandleWrapper(key, event)

Handle function of the widget

Parameters:

  • key (String)

    strnig the widget key

  • event (Hash)

    map event to be handled

Returns:

  • (Symbol)

    for wizard sequencer or nil



662
663
664
665
# File '../../src/modules/CWMFirewallInterfaces.rb', line 662

def InterfacesHandleWrapper(key, event)
  event = deep_copy(event)
  InterfacesHandle(CWM.GetProcessedWidget, key, event)
end

- (Object) InterfacesInit(_widget, _key)

Init function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File '../../src/modules/CWMFirewallInterfaces.rb', line 404

def InterfacesInit(_widget, _key)
  # set the list of ifaces
  InitAllInterfacesList() if @all_interfaces.nil?
  UI.ReplaceWidget(
    Id("_cwm_interface_list_rp"),
    MultiSelectionBox(
      Id("_cwm_interface_list"),
      # transaltors: selection box title
      _("&Network Interfaces with Open Port in Firewall"),
      @interface_items
    )
  )
  # mark open ifaces as open
  UI.ChangeWidget(
    Id("_cwm_interface_list"),
    :SelectedItems,
    @allowed_interfaces
  )

  nil
end

- (Object) InterfacesInitWrapper(key)

Init function of the widget

Parameters:

  • key (String)

    strnig the widget key



652
653
654
655
656
# File '../../src/modules/CWMFirewallInterfaces.rb', line 652

def InterfacesInitWrapper(key)
  InterfacesInit(CWM.GetProcessedWidget, key)

  nil
end

- (Object) InterfacesStore(_widget, _key, _event)

Store function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



452
453
454
455
456
457
458
459
460
461
462
# File '../../src/modules/CWMFirewallInterfaces.rb', line 452

def InterfacesStore(_widget, _key, _event)
  @allowed_interfaces = Convert.convert(
    UI.QueryWidget(Id("_cwm_interface_list"), :SelectedItems),
    from: "any",
    to:   "list <string>"
  )
  @allowed_interfaces = Selected2Opened(@allowed_interfaces, false)
  @configuration_changed = true

  nil
end

- (Object) InterfacesStoreWrapper(key, event)

Store function of the widget

Parameters:

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



670
671
672
673
674
675
# File '../../src/modules/CWMFirewallInterfaces.rb', line 670

def InterfacesStoreWrapper(key, event)
  event = deep_copy(event)
  InterfacesStore(CWM.GetProcessedWidget, key, event)

  nil
end

- (Object) InterfacesValidate(_widget, _key, _event)

Validate function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map event that caused the validation

Returns:

  • true if validation succeeded, false otherwise



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

def InterfacesValidate(_widget, _key, _event)
  ifaces = Convert.convert(
    UI.QueryWidget(Id("_cwm_interface_list"), :SelectedItems),
    from: "any",
    to:   "list <string>"
  )
  ifaces = Builtins.toset(ifaces)
  Builtins.y2milestone("Selected ifaces: %1", ifaces)

  # Check the INT zone, it's not protected by default
  # See bnc #382686
  internal_interfaces = SuSEFirewall.GetInterfacesInZone("INT")

  if Ops.greater_than(Builtins.size(internal_interfaces), 0) &&
      SuSEFirewall.GetProtectFromInternalZone == false
    int_not_selected = []
    Builtins.foreach(internal_interfaces) do |one_internal|
      if !Builtins.contains(ifaces, one_internal)
        int_not_selected = Builtins.add(int_not_selected, one_internal)
      end
    end

    if Ops.greater_than(Builtins.size(int_not_selected), 0)
      Builtins.y2warning(
        "Unprotected internal interfaces not selected: %1",
        int_not_selected
      )

      Report.Message(
        Builtins.sformat(
          _(
            "These network interfaces assigned to internal network cannot be deselected:\n%1\n"
          ),
          Builtins.mergestring(int_not_selected, "\n")
        )
      )

      ifaces = Convert.convert(
        Builtins.union(ifaces, int_not_selected),
        from: "list",
        to:   "list <string>"
      )
      Builtins.y2milestone("Selected interfaces: %1", ifaces)
      UI.ChangeWidget(Id("_cwm_interface_list"), :SelectedItems, ifaces)
      return false
    end
  end

  if Builtins.size(ifaces) == 0
    # question popup
    if !Popup.YesNo(
        _(
          "No interface is selected. Service will not\n" \
            "be available for other computers.\n" \
            "\n" \
            "Continue?"
        )
      )
      return false
    end
  end

  firewall_ifaces = Builtins.toset(Selected2Opened(ifaces, false))
  Builtins.y2milestone("firewall_ifaces: %1", firewall_ifaces)

  added_ifaces = Builtins.filter(firewall_ifaces) do |i|
    !Builtins.contains(ifaces, i)
  end
  Builtins.y2milestone("added_ifaces: %1", added_ifaces)

  removed_ifaces = Builtins.filter(ifaces) do |i|
    !Builtins.contains(firewall_ifaces, i)
  end
  Builtins.y2milestone("removed_ifaces: %1", removed_ifaces)

  # to hide that special string
  if Ops.greater_than(Builtins.size(added_ifaces), 0)
    ifaces_list = Builtins.mergestring(added_ifaces, "\n")
    if !Popup.YesNo(
        Builtins.sformat(
          # yes-no popup
          _(
            "Because of SuSE Firewall settings, the port\n" \
              "on the following interfaces will additionally be open:\n" \
              "%1\n" \
              "\n" \
              "Continue?"
          ),
          ifaces_list
        )
      )
      return false
    end
  end
  # to hide that special string
  if Ops.greater_than(Builtins.size(removed_ifaces), 0)
    ifaces_list = Builtins.mergestring(removed_ifaces, "\n")
    if !Popup.YesNo(
        Builtins.sformat(
          # yes-no popup
          _(
            "Because of SuSE Firewall settings, the port\n" \
              "on the following interfaces cannot be opened:\n" \
              "%1\n" \
              "\n" \
              "Continue?"
          ),
          ifaces_list
        )
      )
      return false
    end
  end
  true
end

- (Object) InterfacesValidateWrapper(key, event)

Validate function of the widget

Parameters:

  • key (String)

    strnig the widget key

  • event (Hash)

    map event that caused the validation

Returns:

  • true if validation succeeded, false otherwise



681
682
683
684
# File '../../src/modules/CWMFirewallInterfaces.rb', line 681

def InterfacesValidateWrapper(key, event)
  event = deep_copy(event)
  InterfacesValidate(CWM.GetProcessedWidget, key, event)
end

- (Object) main



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

def main
  Yast.import "UI"
  textdomain "base"

  Yast.import "CWM"
  Yast.import "Label"
  Yast.import "Mode"
  Yast.import "NetworkInterfaces"
  Yast.import "Popup"
  Yast.import "SuSEFirewall"
  Yast.import "Report"
  Yast.import "Stage"
  Yast.import "String"

  # used only for (Mode::installation() || Mode::update())
  Yast.import "SuSEFirewallProposal"

  # private variables

  # List of all interfaces relevant for firewall settings
  @all_interfaces = nil

  # List of all items of interfaces to the selection box
  @interface_items = nil

  # List of interfaces that are allowed
  @allowed_interfaces = nil

  # Information if configuration was changed by user
  @configuration_changed = false

  # `Any`-feature is supported in the firewall configuration
  @any_iface_supported = nil

  @buggy_ifaces = []
end

- (Boolean) Modified

Check if settings were modified by the user

Returns:

  • (Boolean)

    true if settings were modified



1149
1150
1151
# File '../../src/modules/CWMFirewallInterfaces.rb', line 1149

def Modified
  SuSEFirewall.GetModified
end

- (Object) OpenFirewallHandle(widget, _key, event)

Handle the immediate start and stop of the service

Parameters:

  • widget (Hash{String => Object})

    a map describing the widget

  • key (String)

    strnig the widget key

  • event_id

    any the ID of the occurred event

Returns:

  • always nil



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
# File '../../src/modules/CWMFirewallInterfaces.rb', line 874

def OpenFirewallHandle(widget, _key, event)
  widget = deep_copy(widget)
  event = deep_copy(event)
  event_id = Ops.get(event, "ID")
  if event_id == "_cwm_firewall_details"
    handle_firewall_details = Convert.convert(
      Ops.get(widget, "firewall_details_handler"),
      from: "any",
      to:   "symbol ()"
    )
    Builtins.y2milestone("FD: %1", handle_firewall_details)
    ret = nil
    Builtins.y2milestone("RT: %1", ret)
    if !handle_firewall_details.nil?
      ret = handle_firewall_details.call
    else
      w = Builtins.filter(widget) { |k, _v| "services" == k }
      DisplayDetailsPopup(w)
    end
    UpdateFirewallStatus()
    EnableOrDisableFirewallDetails()
    return ret
  end
  if event_id == "_cwm_open_firewall"
    value = Convert.to_boolean(
      UI.QueryWidget(Id("_cwm_open_firewall"), :Value)
    )
    Builtins.y2milestone("OF: %1", value)
    if value
      @allowed_interfaces = deep_copy(@all_interfaces)
    else
      @allowed_interfaces = []
    end

    @buggy_ifaces = []
    # Checks whether it's possible to enable or disable the service for all interfaces
    # opens a popup message when needed
    if !CheckPossbilityToChangeFirewall(value)
      # change the checkbox state back
      UI.ChangeWidget(Id("_cwm_open_firewall"), :Value, !value)
    end
    # Filtering out buggy ifaces
    Builtins.foreach(@buggy_ifaces) do |one_iface|
      @allowed_interfaces = Builtins.filter(@allowed_interfaces) do |one_allowed|
        one_allowed != one_iface
      end
    end

    UpdateFirewallStatus()
    EnableOrDisableFirewallDetails()
    @configuration_changed = true
  end
  nil
end

- (Object) OpenFirewallHandleWrapper(key, event)

Handle the immediate start and stop of the service

Parameters:

  • key (String)

    strnig the widget key

  • event_id

    any the ID of the occurred event

Returns:

  • always nil



951
952
953
954
# File '../../src/modules/CWMFirewallInterfaces.rb', line 951

def OpenFirewallHandleWrapper(key, event)
  event = deep_copy(event)
  OpenFirewallHandle(CWM.GetProcessedWidget, key, event)
end

- (String) OpenFirewallHelp(restart_displayed)

Get the help text to the firewall opening widget

Parameters:

  • restart_displayed (Boolean)

    shold be true if “Save and restart” is displayed

Returns:

  • (String)

    help text



1025
1026
1027
1028
1029
1030
1031
1032
1033
# File '../../src/modules/CWMFirewallInterfaces.rb', line 1025

def OpenFirewallHelp(restart_displayed)
  Builtins.sformat(
    OpenFirewallHelpTemplate(restart_displayed),
    # part of help text - check box label, NO SHORTCUT!!!
    _("Open Port in Firewall"),
    # part of help text - push button label, NO SHORTCUT!!!
    _("Firewall Details")
  )
end

- (String) OpenFirewallHelpTemplate(restart_displayed)

Get the template for the help text to the firewall opening widget

Parameters:

  • restart_displayed (Boolean)

    shold be true if “Save and restart” is displayed

Returns:

  • (String)

    help text template with %1 and %2 placeholders



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

def OpenFirewallHelpTemplate(restart_displayed)
  # help text for firewall settings widget 1/3,
  # %1 is check box label, eg. "Open Port in Firewall" (without quotes)
  help = _(
    "<p><b><big>Firewall Settings</big></b><br>\n" \
      "To open the firewall to allow access to the service from remote computers,\n" \
      "set <b>%1</b>.<br>"
  )
  if restart_displayed
    # help text for firewall port openning widget 2/3, optional
    # %1 is push button label, eg. "Firewall &Details" (without quotes)
    # note: %2 is correct, do not replace with %1!!!
    help = Ops.add(
      help,
      _(
        "To select interfaces on which to open the port,\nclick <b>%2</b>.<br>"
      )
    )
  end
  # help text for firewall settings widget 3/3,
  help = Ops.add(
    help,
    _("This option is available only if the firewall\nis enabled.</p>")
  )
  help
end

- (Object) OpenFirewallInit(widget, _key)

Initialize the open firewall widget

Parameters:

  • widget (Hash{String => Object})

    a map describing the whole widget



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

def OpenFirewallInit(widget, _key)
  widget = deep_copy(widget)
  if !UI.WidgetExists(Id("_cwm_open_firewall"))
    Builtins.y2error("Firewall widget doesn't exist")
    return
  end
  services = Ops.get_list(widget, "services", [])
  InitAllInterfacesList()

  begin
    InitAllowedInterfaces(services)
  rescue SuSEFirewalServiceNotFound => e
    Report.Error(
      # TRANSLATORS: Error message, do not translate %{details}
      _("Error checking service status:\n%{details}") % { details: e.message }
    )
  end

  open_firewall = Ops.greater_than(Builtins.size(@allowed_interfaces), 0)
  firewall_enabled = SuSEFirewall.GetEnableService &&
    Ops.greater_than(Builtins.size(@all_interfaces), 0)
  if !firewall_enabled
    open_firewall = false
    UI.ChangeWidget(Id("_cwm_open_firewall"), :Enabled, false)
  end
  UI.ChangeWidget(Id("_cwm_open_firewall"), :Value, open_firewall)
  UpdateFirewallStatus()
  EnableOrDisableFirewallDetails()

  nil
end

- (Object) OpenFirewallInitWrapper(key)

Init function of the widget

Parameters:

  • key (String)

    strnig the widget key



931
932
933
934
935
# File '../../src/modules/CWMFirewallInterfaces.rb', line 931

def OpenFirewallInitWrapper(key)
  OpenFirewallInit(CWM.GetProcessedWidget, key)

  nil
end

- (Boolean) OpenFirewallModified(_key)

Check if the widget was modified

Parameters:

  • key (String)

    strnig the widget key

Returns:

  • (Boolean)

    true if widget was modified



959
960
961
# File '../../src/modules/CWMFirewallInterfaces.rb', line 959

def OpenFirewallModified(_key)
  @configuration_changed
end

- (Object) OpenFirewallStore(widget, _key, _event)

Store function of the widget

Parameters:

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
# File '../../src/modules/CWMFirewallInterfaces.rb', line 849

def OpenFirewallStore(widget, _key, _event)
  widget = deep_copy(widget)
  if !UI.WidgetExists(Id("_cwm_open_firewall"))
    Builtins.y2error("Widget _cwm_open_firewall does not exist")
    return
  end
  services = Ops.get_list(widget, "services", [])

  begin
    StoreAllowedInterfaces(services)
  rescue SuSEFirewalServiceNotFound => e
    Report.Error(
      # TRANSLATORS: Error message, do not translate %{details}
      _("Error setting service status:\n%{details}") % { details: e.message }
    )
  end

  nil
end

- (Object) OpenFirewallStoreWrapper(key, event)

Store function of the widget

Parameters:

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



940
941
942
943
944
945
# File '../../src/modules/CWMFirewallInterfaces.rb', line 940

def OpenFirewallStoreWrapper(key, event)
  event = deep_copy(event)
  OpenFirewallStore(CWM.GetProcessedWidget, key, event)

  nil
end

- (Boolean) OpenFirewallWidgetExists

Check whether the whole firewall widget ( open port checkbox and fw details button) exists

Returns:

  • (Boolean)

    true if both widgets exist



988
989
990
991
# File '../../src/modules/CWMFirewallInterfaces.rb', line 988

def OpenFirewallWidgetExists
  UI.WidgetExists(Id("_cwm_open_firewall")) &&
    UI.WidgetExists(Id("_cwm_firewall_details"))
end

- (Object) Selected2Opened(ifaces, _nm_ifaces_have_to_be_selected)

Get the list of all interfaces that will be selected

Parameters:

  • ifaces (Array<String>)

    a list of interfaces selected by the user

  • nm_ifaces_have_to_be_selected (Boolean)

    defines whether also NetworkManager have to be selected too

Returns:

  • a list of interfaces that will be opened



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

def Selected2Opened(ifaces, _nm_ifaces_have_to_be_selected)
  ifaces = deep_copy(ifaces)
  Builtins.y2milestone("Selected ifaces: %1", ifaces)
  groups = Builtins.maplist(ifaces) do |i|
    SuSEFirewall.GetZoneOfInterface(i)
  end

  # string 'any' is in the EXT zone
  # all interfaces without zone assigned are covered by this case
  # so, check also the EXT zone
  if SuSEFirewall.IsAnyNetworkInterfaceSupported
    groups = Builtins.add(groups, SuSEFirewall.special_all_interface_zone)
  end

  groups = String.NonEmpty(Builtins.toset(groups))
  groups = Builtins.filter(groups) { |g| !g.nil? }
  iface_groups = Builtins.maplist(groups) do |g|
    ifaces_also_supported_by_any = SuSEFirewall.GetInterfacesInZoneSupportingAnyFeature(
      g
    )
    # If all interfaces in EXT zone are covered by the special 'any' string
    # and none of these interfaces are selected to be open, we can remove all of them
    # disable the service in whole EXT zone
    if g == SuSEFirewall.special_all_interface_zone
      ifaces_left_explicitely = Builtins.filter(
        ifaces_also_supported_by_any
      ) do |iface|
        Builtins.contains(ifaces, iface)
      end
      Builtins.y2milestone(
        "Ifaces left in zone: %1",
        ifaces_left_explicitely
      )
      # there are no interfaces left that would be explicitely mentioned in the EXT zone
      if ifaces_left_explicitely == []
        next []
        # Hmm, some interfaces left
      else
        next deep_copy(ifaces_also_supported_by_any)
      end
      # Just report all interfaces mentioned in zone
    else
      next deep_copy(ifaces_also_supported_by_any)
    end
  end
  Builtins.y2milestone("Ifaces touched: %1", iface_groups)
  new_ifaces = Builtins.toset(Builtins.flatten(iface_groups))
  new_ifaces = Builtins.filter(new_ifaces) { |i| !i.nil? }

  Builtins.toset(new_ifaces)
end

- (Object) SetFirewallLabel(status)

Set the firewall status label

Parameters:

  • status (Symbol)

    symbol one of off,closed, open_all,custom, `not_installed



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

def SetFirewallLabel(status)
  label = ""
  if status == :not_installed
    # bnc #429861
    if Stage.initial
      # label
      label = _(
        "Firewall cannot be adjusted during first stage installation."
      )
    else
      # label
      label = _("Firewall package is not installed.")
    end
  elsif status == :off
    # label
    label = _("Firewall is disabled")
  elsif status == :closed
    # label
    label = _("Firewall port is closed")
  elsif status == :open_all
    # label
    label = _("Firewall port is open on all interfaces")
  elsif status == :custom
    # label
    label = _("Firewall port is open on selected interfaces")
  elsif status == :no_ifaces
    # label
    label = _("No network interfaces are configured")
  end
  UI.ReplaceWidget(Id(:_cwm_firewall_status_rp), Label(label))

  nil
end

- (Object) StoreAllowedInterfaces(services)

Store the list of allowed interfaces Users the internal variables

Parameters:

  • services (Array<String>)

    a list of services



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File '../../src/modules/CWMFirewallInterfaces.rb', line 376

def StoreAllowedInterfaces(services)
  services = deep_copy(services)
  # do not save anything if configuration didn't change
  return if !@configuration_changed
  forbidden_interfaces = Builtins.filter(@all_interfaces) do |i|
    !Builtins.contains(@allowed_interfaces, i)
  end

  # If configuring firewall in any type of installation
  # proposal must be set to 'modified'
  if Mode.installation || Mode.update
    Builtins.y2milestone("Firewall proposal modified by user")
    SuSEFirewallProposal.SetChangedByUser(true)
  end

  if Ops.greater_than(Builtins.size(forbidden_interfaces), 0)
    SuSEFirewall.SetServices(services, forbidden_interfaces, false)
  end
  if Ops.greater_than(Builtins.size(@allowed_interfaces), 0)
    SuSEFirewall.SetServices(services, @allowed_interfaces, true)
  end

  nil
end

- (Object) UpdateFirewallStatus

Update the firewall status label according to the current status



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

def UpdateFirewallStatus
  InitAllInterfacesList() if @all_interfaces.nil?
  status = :custom

  # bnc #429861
  if Stage.initial || !SuSEFirewall.SuSEFirewallIsInstalled
    status = :not_installed
  elsif !SuSEFirewall.GetEnableService
    status = :off
  elsif Builtins.size(@all_interfaces) == 0
    status = :no_ifaces
  elsif Builtins.size(@all_interfaces) == Builtins.size(@allowed_interfaces)
    status = :open_all
  elsif Builtins.size(@allowed_interfaces) == 0
    status = :closed
  end

  Builtins.y2milestone(
    "Status: %1, All: %2, Allowed: %3",
    status,
    @all_interfaces,
    @allowed_interfaces
  )
  SetFirewallLabel(status)
  open = status == :open_all || status == :custom
  UI.ChangeWidget(Id("_cwm_open_firewall"), :Value, open)

  nil
end