Class: Yast::CWMFirewallInterfacesClass
- Inherits:
-
Module
- Object
- Module
- Yast::CWMFirewallInterfacesClass
- Includes:
- Y2Firewall::Helpers::Interfaces, Logger
- Defined in:
- library/network/src/modules/CWMFirewallInterfaces.rb
Overview
This class provide a set of methods to define a widget for handling with firewall interfaces configuration.
Instance Attribute Summary collapse
-
#all_interfaces ⇒ Object
readonly
[Array
] List of all the system network interfaces. -
#allowed_interfaces ⇒ Object
readonly
[Array
] List of all interfaces relevant for firewall settings. -
#configuration_changed ⇒ Object
readonly
[Boolean] Information if configuration was changed by user.
Instance Method Summary collapse
-
#CreateInterfacesWidget(settings) ⇒ Hash
Get the widget description map
.
-
#CreateOpenFirewallWidget(settings) ⇒ Hash
Get the widget description map of the firewall enablement widget
.
-
#current_firewall_status ⇒ Symbol
Return the current status of the firewall related to the interfaces opened or available.
-
#DisableOpenFirewallWidget ⇒ Object
Disable the whole firewal widget.
-
#DisplayDetailsPopup(settings) ⇒ Symbol
Display the firewall interfaces selection as a popup.
-
#DisplayFirewallDetailsPopupHandler(widget) ⇒ Object
Display popup with firewall settings details.
-
#EnableOpenFirewallWidget ⇒ Object
Enable the whole firewal widget.
-
#EnableOrDisableFirewallDetails ⇒ Object
Enable or disable the firewall details widget according to the status of "open firewall" checkbox.
-
#firewall_status_label(status) ⇒ String
Return the firewall status label for the given status.
-
#InitAllInterfacesList ⇒ Object
Initialize the list of all known interfaces.
-
#InitAllowedInterfaces(services) ⇒ Object
Initialize the list of allowed interfaces Changes the internal variables.
-
#InterfacesHandle(_widget, _key, event) ⇒ Symbol
Handle function of the widget.
-
#InterfacesHandleWrapper(key, event) ⇒ Symbol
Handle function of the widget.
-
#InterfacesInit(_widget, _key) ⇒ Object
Init function of the widget.
-
#InterfacesInitWrapper(key) ⇒ Object
Init function of the widget.
-
#InterfacesStore(_widget, _key, _event) ⇒ Object
Store function of the widget.
-
#InterfacesStoreWrapper(key, event) ⇒ Object
Store function of the widget.
-
#InterfacesValidate(_widget, _key, _event) ⇒ Object
Validate function of the widget.
-
#InterfacesValidateWrapper(key, event) ⇒ Object
Validate function of the widget.
- #main ⇒ Object
-
#Modified ⇒ Boolean
Check if settings were modified by the user.
-
#OpenFirewallHandle(widget, _key, event) ⇒ Object
Handle the immediate start and stop of the service.
-
#OpenFirewallHandleWrapper(key, event) ⇒ Object
Handle the immediate start and stop of the service.
-
#OpenFirewallHelp(restart_displayed) ⇒ String
Get the help text to the firewall opening widget.
-
#OpenFirewallHelpTemplate(restart_displayed) ⇒ String
Get the template for the help text to the firewall opening widget.
-
#OpenFirewallInit(widget, _key) ⇒ Object
Initialize the open firewall widget.
-
#OpenFirewallInitWrapper(key) ⇒ Object
Init function of the widget.
-
#OpenFirewallModified(_key) ⇒ Boolean
Check if the widget was modified.
-
#OpenFirewallStore(widget, _key, _event) ⇒ Object
Store function of the widget.
-
#OpenFirewallStoreWrapper(key, event) ⇒ Object
Store function of the widget.
-
#OpenFirewallWidgetExists ⇒ Boolean
Check whether the whole firewall widget ( open port checkbox and fw details button) exists.
-
#Selected2Opened(ifaces, _nm_ifaces_have_to_be_selected) ⇒ Object
Get the list of all interfaces that will be selected.
-
#SetFirewallLabel(status) ⇒ Object
Set the firewall status label.
-
#StoreAllowedInterfaces(services) ⇒ Object
Store the list of allowed interfaces Users the internal variables.
-
#UpdateFirewallStatus ⇒ Object
Update the firewall status label according to the current status.
Methods included from Y2Firewall::Helpers::Interfaces
#default_interfaces, #default_zone, #interface_zone, #known_interfaces, #unknown_interfaces
Instance Attribute Details
#all_interfaces ⇒ Object (readonly)
[Array
75 76 77 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 75 def all_interfaces @all_interfaces end |
#allowed_interfaces ⇒ Object (readonly)
[Array
73 74 75 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 73 def allowed_interfaces @allowed_interfaces end |
#configuration_changed ⇒ Object (readonly)
[Boolean] Information if configuration was changed by user
78 79 80 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 78 def configuration_changed @configuration_changed end |
Instance Method Details
#CreateInterfacesWidget(settings) ⇒ Hash
Get the widget description map
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)
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 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 492 def CreateInterfacesWidget(settings) settings = deep_copy(settings) = 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 help = Ops.get_string(settings, "help", "") if Builtins.haskey(settings, "help") ret = Convert.convert( Builtins.union( settings, "widget" => :custom, "custom_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 |
#CreateOpenFirewallWidget(settings) ⇒ Hash
Get the widget description map of the firewall enablement widget
- "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
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 879 880 881 882 883 884 885 886 887 888 889 890 891 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 811 def CreateOpenFirewallWidget(settings) settings = deep_copy(settings) services = adapt_settings_services!(settings) if services.empty? log.error("Firewall services not specified") if services.empty? return { "widget" => :custom, "custom_widget" => VBox(), "help" => "" } end if !firewalld.installed? log.error("Firewall is not installed") if !firewalld.installed? return { "widget" => :custom, "custom_widget" => , "help" => "" } end if services.any? { |s| !firewalld.current_service_names.include?(s) } return { "widget" => :custom, "custom_widget" => (services), "help" => "" } end open_firewall_checkbox = settings.fetch("open_firewall_checkbox", _("Open Port in &Firewall")) = settings.fetch("firewall_details_button", _("Firewall &Details...")) display_firewall_details = settings.fetch("firewall_details_handler", settings.fetch("display_details", false)) help = settings.fetch("help", OpenFirewallHelp(display_firewall_details)) 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"), ) ) end firewall_settings = VBox( Frame( format(_("Firewall Settings for %{firewall}"), firewall: Y2Firewall::Firewalld::SERVICE), VBox( Left(firewall_settings), Left( ReplacePoint( Id(:_cwm_firewall_status_rp), # label text Label(_("Firewall is open")) ) ) ) ) ) { "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"] }.merge(settings) end |
#current_firewall_status ⇒ Symbol
Return the current status of the firewall related to the interfaces opened or available
903 904 905 906 907 908 909 910 911 912 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 903 def current_firewall_status # bnc #429861 return :not_installed if Stage.initial || !firewalld.installed? return :off unless firewalld.enabled? return :no_ifaces if all_interfaces.empty? return :open_all if all_interfaces.size == allowed_interfaces.size return :closed if allowed_interfaces.empty? :custom end |
#DisableOpenFirewallWidget ⇒ Object
Disable the whole firewal widget
731 732 733 734 735 736 737 738 739 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 731 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 |
#DisplayDetailsPopup(settings) ⇒ Symbol
Display the firewall interfaces selection as a popup
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 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 571 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 |
#DisplayFirewallDetailsPopupHandler(widget) ⇒ Object
Display popup with firewall settings details
194 195 196 197 198 199 200 201 202 203 204 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 194 def DisplayFirewallDetailsPopupHandler() = deep_copy() common_details_handler = Convert.convert( Ops.get(, "common_details_handler"), from: "any", to: "void (map <string, any>)" ) common_details_handler&.call() nil end |
#EnableOpenFirewallWidget ⇒ Object
Enable the whole firewal widget
720 721 722 723 724 725 726 727 728 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 720 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 |
#EnableOrDisableFirewallDetails ⇒ Object
Enable or disable the firewall details widget according to the status of "open firewall" checkbox
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 107 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? || all_interfaces.empty? UI.ChangeWidget(Id("_cwm_firewall_details"), :Enabled, enabled) nil end |
#firewall_status_label(status) ⇒ String
Return the firewall status label for the given status
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 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 918 def firewall_status_label(status) case status when :not_installed # bnc #429861 if Stage.initial # label _( "Firewall cannot be adjusted during first stage installation." ) else # label _("Firewall package is not installed.") end when :off # label _("Firewall is disabled") when :closed # label _("Firewall port is closed") when :open_all # label _("Firewall port is open on all interfaces") when :custom # label _("Firewall port is open on selected interfaces") when :no_ifaces # label _("No network interfaces are configured") end end |
#InitAllInterfacesList ⇒ Object
Initialize the list of all known interfaces
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 130 def InitAllInterfacesList # Do not read NetworkInterfaces when they are already read if !Mode.config && !Mode.installation && !Mode.update log.info("Reading NetworkInterfaces...") NetworkInterfaces.Read end @all_interfaces = NetworkInterfaces.List("").reject { |i| i == "lo" } @interface_items = all_interfaces.map { |i| Item(Id(i), interface_label(i)) } nil end |
#InitAllowedInterfaces(services) ⇒ Object
Initialize the list of allowed interfaces Changes the internal variables
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 213 def InitAllowedInterfaces(services) service_status = {} zone_services(services).each do |_s, status| status.each do |iface, en| service_status[iface] = service_status.fetch(iface, true) && en end end service_status.select! { |_iface, en| en == true } log.info("Status: #{service_status}") @allowed_interfaces = service_status.keys log.info "Default zone name: #{default_zone.name}" log.info "Default interfaces: #{default_interfaces}" log.info "Default_zone services: #{default_zone.services}" if !default_interfaces.empty? services.each do |service| service_status[firewalld.default_zone] = default_zone&.services&.include?(service) end @allowed_interfaces = (allowed_interfaces + default_interfaces).uniq if service_status[firewalld.default_zone] end log.info "Allowed interfaces: #{allowed_interfaces}" @configuration_changed = false nil end |
#InterfacesHandle(_widget, _key, event) ⇒ Symbol
Handle function of the widget
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 306 def InterfacesHandle(, _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 |
#InterfacesHandleWrapper(key, event) ⇒ Symbol
Handle function of the widget
453 454 455 456 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 453 def InterfacesHandleWrapper(key, event) event = deep_copy(event) InterfacesHandle(CWM.GetProcessedWidget, key, event) end |
#InterfacesInit(_widget, _key) ⇒ Object
Init function of the widget
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 279 def InterfacesInit(, _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 |
#InterfacesInitWrapper(key) ⇒ Object
Init function of the widget
443 444 445 446 447 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 443 def InterfacesInitWrapper(key) InterfacesInit(CWM.GetProcessedWidget, key) nil end |
#InterfacesStore(_widget, _key, _event) ⇒ Object
Store function of the widget
327 328 329 330 331 332 333 334 335 336 337 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 327 def InterfacesStore(, _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 |
#InterfacesStoreWrapper(key, event) ⇒ Object
Store function of the widget
461 462 463 464 465 466 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 461 def InterfacesStoreWrapper(key, event) event = deep_copy(event) InterfacesStore(CWM.GetProcessedWidget, key, event) nil end |
#InterfacesValidate(_widget, _key, _event) ⇒ Object
Validate function of the widget
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 344 def InterfacesValidate(, _key, _event) trusted_zone = firewalld.find_zone("trusted") ifaces = Convert.convert( UI.QueryWidget(Id("_cwm_interface_list"), :SelectedItems), from: "any", to: "list <string>" ) || [] log.info("Selected ifaces: #{ifaces}") trusted_interfaces = trusted_zone ? trusted_zone.interfaces : [] if !trusted_interfaces.empty? int_not_selected = [] trusted_interfaces.each do |interface| int_not_selected << interface unless ifaces.include?(interface) end if !int_not_selected.empty? log.warn("Unprotected internal interfaces not selected: #{int_not_selected}") Report.Message( Builtins.sformat( _( "These network interfaces assigned to internal network cannot be deselected:\n%1\n" ), int_not_selected.join("\n") ) ) ifaces = Convert.convert( Builtins.union(ifaces, int_not_selected), from: "list", to: "list <string>" ) log.info("Selected interfaces: #{ifaces}") UI.ChangeWidget(Id("_cwm_interface_list"), :SelectedItems, ifaces) return false end end if ifaces.empty? && !Popup.YesNo( _( "No interface is selected. Service will not\n" \ "be available for other computers.\n" \ "\n" \ "Continue?" ) ) return false end firewall_ifaces = Selected2Opened(ifaces, false) log.info("firewall_ifaces: #{firewall_ifaces}") added_ifaces = firewall_ifaces.reject { |i| ifaces.include?(i) } log.info("added_ifaces: #{added_ifaces}") removed_ifaces = ifaces.reject { |i| firewall_ifaces.include?(i) } log.info("removed_ifaces: #{removed_ifaces}") # to hide that special string if !added_ifaces.empty? && !Popup.YesNo( Builtins.sformat( # yes-no popup _( "Because of firewalld settings, the port\n" \ "on the following interfaces will additionally be open:\n" \ "%1\n" \ "\n" \ "Continue?" ), added_ifaces.join("\n") ) ) return false end # to hide that special string if !removed_ifaces.empty? && !Popup.YesNo( Builtins.sformat( # yes-no popup _( "Because of firewalld settings, the port\n" \ "on the following interfaces cannot be opened:\n" \ "%1\n" \ "\n" \ "Continue?" ), removed_ifaces.join("\n") ) ) return false end true end |
#InterfacesValidateWrapper(key, event) ⇒ Object
Validate function of the widget
472 473 474 475 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 472 def InterfacesValidateWrapper(key, event) event = deep_copy(event) InterfacesValidate(CWM.GetProcessedWidget, key, event) end |
#main ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 80 def main Yast.import "UI" textdomain "base" Yast.import "CWM" Yast.import "Label" Yast.import "Mode" Yast.import "NetworkInterfaces" Yast.import "Popup" Yast.import "Report" Yast.import "Stage" Yast.import "String" # private variables # List of all items of interfaces to the selection box @interface_items = nil @configuration_changed = false @buggy_ifaces = [] end |
#Modified ⇒ Boolean
Check if settings were modified by the user
895 896 897 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 895 def Modified firewalld.modified? end |
#OpenFirewallHandle(widget, _key, event) ⇒ Object
Handle the immediate start and stop of the service
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 639 def OpenFirewallHandle(, _key, event) = deep_copy() event = deep_copy(event) event_id = Ops.get(event, "ID") if event_id == "_cwm_firewall_details" handle_firewall_details = Convert.convert( Ops.get(, "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? w = Builtins.filter() { |k, _v| "services" == k } DisplayDetailsPopup(w) else ret = handle_firewall_details.call 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) @allowed_interfaces = value ? deep_copy(all_interfaces) : [] @buggy_ifaces = [] # 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 |
#OpenFirewallHandleWrapper(key, event) ⇒ Object
Handle the immediate start and stop of the service
707 708 709 710 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 707 def OpenFirewallHandleWrapper(key, event) event = deep_copy(event) OpenFirewallHandle(CWM.GetProcessedWidget, key, event) end |
#OpenFirewallHelp(restart_displayed) ⇒ String
Get the help text to the firewall opening widget
781 782 783 784 785 786 787 788 789 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 781 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 |
#OpenFirewallHelpTemplate(restart_displayed) ⇒ String
Get the template for the help text to the firewall opening widget
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 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 752 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, Ops.add( help, _("This option is available only if the firewall\nis enabled.</p>") ) end |
#OpenFirewallInit(widget, _key) ⇒ Object
Initialize the open firewall widget
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 601 def OpenFirewallInit(, _key) return unless services = .fetch("services", []) InitAllInterfacesList() InitAllowedInterfaces(services) open_firewall = !allowed_interfaces.empty? firewall_enabled = firewalld.enabled? && !all_interfaces.empty? 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 |
#OpenFirewallInitWrapper(key) ⇒ Object
Init function of the widget
687 688 689 690 691 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 687 def OpenFirewallInitWrapper(key) OpenFirewallInit(CWM.GetProcessedWidget, key) nil end |
#OpenFirewallModified(_key) ⇒ Boolean
Check if the widget was modified
715 716 717 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 715 def OpenFirewallModified(_key) @configuration_changed end |
#OpenFirewallStore(widget, _key, _event) ⇒ Object
Store function of the widget
626 627 628 629 630 631 632 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 626 def OpenFirewallStore(, _key, _event) return unless services = .fetch("services", []) StoreAllowedInterfaces(services) nil end |
#OpenFirewallStoreWrapper(key, event) ⇒ Object
Store function of the widget
696 697 698 699 700 701 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 696 def OpenFirewallStoreWrapper(key, event) event = deep_copy(event) OpenFirewallStore(CWM.GetProcessedWidget, key, event) nil end |
#OpenFirewallWidgetExists ⇒ Boolean
Check whether the whole firewall widget ( open port checkbox and fw details button) exists
744 745 746 747 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 744 def OpenFirewallWidgetExists UI.WidgetExists(Id("_cwm_open_firewall")) && UI.WidgetExists(Id("_cwm_firewall_details")) end |
#Selected2Opened(ifaces, _nm_ifaces_have_to_be_selected) ⇒ Object
Get the list of all interfaces that will be selected
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 162 def Selected2Opened(ifaces, _nm_ifaces_have_to_be_selected) log.info("Selected ifaces: #{ifaces}") zone_names = ifaces.map do |name| zone = interface_zone(name) zone ? zone.name : default_zone.name end zone_names.uniq! log.info("Ifaces zone names: #{zone_names}") zone_ifaces = zone_names.map do |zone_name| zone = firewalld.find_zone(zone_name) next [] unless zone interfaces = zone.interfaces next(interfaces) unless zone_name == default_zone.name interfaces += default_interfaces left_explicitly = interfaces.select { |i| ifaces.include?(i) }.uniq log.info("Ifaces left in zone: #{left_explicitly}") next [] if left_explicitly.empty? interfaces end zone_ifaces.flatten.uniq end |
#SetFirewallLabel(status) ⇒ Object
Set the firewall status label
123 124 125 126 127 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 123 def SetFirewallLabel(status) UI.ReplaceWidget(Id(:_cwm_firewall_status_rp), Label(firewall_status_label(status))) nil end |
#StoreAllowedInterfaces(services) ⇒ Object
Store the list of allowed interfaces Users the internal variables
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 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 248 def StoreAllowedInterfaces(services) services = deep_copy(services) # do not save anything if configuration didn't change return if !configuration_changed zones = known_interfaces.each_with_object([]) do |iface, memo| if allowed_interfaces.include?(iface.name) zone_name = iface.zone ? iface.zone.name : firewalld.default_zone memo << zone_name end end firewalld.zones.each do |zone| if zones.include?(zone.name) services.each do |service| zone.add_service(service) unless zone.services.include?(service) end else services.each do |service| zone.remove_service(service) if zone.services.include?(service) end end end nil end |
#UpdateFirewallStatus ⇒ Object
Update the firewall status label according to the current status
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'library/network/src/modules/CWMFirewallInterfaces.rb', line 144 def UpdateFirewallStatus InitAllInterfacesList() if all_interfaces.nil? status = current_firewall_status log.info("Status: #{status}, All: #{all_interfaces}, Allowed: #{allowed_interfaces}") SetFirewallLabel(status) open = [:open_all, :custom].include?(status) UI.ChangeWidget(Id("_cwm_open_firewall"), :Value, open) nil end |