Class: Yast::SuSEFirewallCMDLineClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) CheckZone(zone, optional)

Function checks zone string for existency

Parameters:

  • zone (String)
  • optional, (Boolean)

    true=is optional, false=has to be set

Returns:

  • (Boolean)

    if zone exists or not set if optional



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 395

def CheckZone(zone, optional)
  # any zone defined
  if zone != "" && zone != nil
    # unknown zone
    if !Builtins.contains(SuSEFirewall.GetKnownFirewallZones, zone)
      # TRANSLATORS: CommandLine error, %1 is a firewall zone shortcut
      CommandLine.Error(Builtins.sformat(_("Unknown zone %1."), zone))
      return false 
      # defined, known zone
    else
      return true
    end 
    # no zone defined
  else
    # not needed, OK
    return true if optional

    # TRANSLATORS: CommandLine error, %1 is needed parameter name
    CommandLine.Error(
      Builtins.sformat(_("Parameter %1 must be set."), "zone")
    )
    return false
  end
end

- (Array<String>) CommaSeparatedList(comma_separated_string)

Returns list of strings made from the comma-separated string got as param.

Parameters:

  • comma_separated_string (Object)

Returns:

  • (Array<String>)

    items



385
386
387
388
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 385

def CommaSeparatedList(comma_separated_string)
  comma_separated_string = deep_copy(comma_separated_string)
  Builtins.splitstring(Convert.to_string(comma_separated_string), ",")
end

- (Boolean) FWCMDBroadcast(options)

Sets broadcast

Parameters:

  • options (Hash)

Returns:

  • (Boolean)

    if write is needed



861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
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
955
956
957
958
959
960
961
962
963
964
965
966
967
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 861

def FWCMDBroadcast(options)
  options = deep_copy(options)
  if Ops.get(options, "show") != nil
    # all zones if no zone is defined
    for_zones = SuSEFirewall.GetKnownFirewallZones
    zone = Ops.get_string(options, "zone", "")
    if zone != ""
      if !CheckZone(zone, false)
        return false
      else
        for_zones = [zone]
      end
    end

    CommandLine.Print("")
    # TRANSLATORS: CommandLine header
    CommandLine.Print(
      String.UnderlinedHeader(_("Allowed Broadcast Ports:"), 0)
    )
    CommandLine.Print("")
    table_items = []
    broadcast_ports = SuSEFirewall.GetBroadcastAllowedPorts
    Builtins.foreach(for_zones) do |zone2|
      zone_name = SuSEFirewall.GetZoneFullName(zone2)
      Builtins.foreach(Ops.get(broadcast_ports, zone2, [])) do |port|
        table_items = Builtins.add(table_items, [zone2, zone_name, port])
      end
    end
    CommandLine.Print(
      String.TextTable(
        [
          # TRANSLATORS: CommandLine header item
          _("Short"),
          # TRANSLATORS: CommandLine header item
          _("Zone Name"),
          # TRANSLATORS: CommandLine header item
          _("Port")
        ],
        table_items,
        {}
      )
    )
    CommandLine.Print("")

    return false
  elsif Ops.get(options, "add") != nil && Ops.get(options, "remove") != nil
    # TRANSLATORS: CommandLine error message
    CommandLine.Error(_("Only one action command is allowed here."))
    return false
  elsif Ops.get(options, "add") != nil || Ops.get(options, "remove") != nil
    # undefined zone
    if Ops.get(options, "zone") == nil
      # TRANSLATORS: CommandLine error, %1 is needed parameter name
      CommandLine.Error(
        Builtins.sformat(_("Parameter %1 must be set."), "zone")
      )
      return false
    end
    # unknown zone
    zone = Ops.get_string(options, "zone")
    return false if !CheckZone(zone, false)

    # undefined port
    if Ops.get(options, "port") == nil
      # TRANSLATORS: CommandLine error, %1 is needed parameter name
      CommandLine.Error(
        Builtins.sformat(_("Parameter %1 must be set."), "port")
      )
      return false
    end

    todo = ""
    if Ops.get(options, "add") != nil
      todo = "add"
    elsif Ops.get(options, "remove") != nil
      todo = "remove"
    end

    broadcast_ports = SuSEFirewall.GetBroadcastAllowedPorts
    Builtins.foreach(
      CommaSeparatedList(Ops.get_string(options, "port", ""))
    ) do |port|
      if todo == "add"
        Ops.set(
          broadcast_ports,
          zone,
          Builtins.toset(
            Builtins.add(Ops.get(broadcast_ports, zone, []), port)
          )
        )
      else
        Ops.set(
          broadcast_ports,
          zone,
          Builtins.filter(Ops.get(broadcast_ports, zone, [])) do |filter_port|
            filter_port != port
          end
        )
      end
    end

    SuSEFirewall.SetBroadcastAllowedPorts(broadcast_ports)
    return true
  end

  false
end

- (Boolean) FWCMDDisable(options)

Overall firewall manual disabling handler

Parameters:

  • options (Hash)

    ignored (no special options)

Returns:

  • (Boolean)

    whether write call is needed



1580
1581
1582
1583
1584
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1580

def FWCMDDisable(options)
  options = deep_copy(options)
  SuSEFirewall.SetStartService(false)
  SuSEFirewall.StartServices
end

- (Boolean) FWCMDEnable(options)

Overall firewall manual enabling handler

Parameters:

  • options (Hash)

    ignored (no special options)

Returns:

  • (Boolean)

    whether write call is needed



1570
1571
1572
1573
1574
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1570

def FWCMDEnable(options)
  options = deep_copy(options)
  SuSEFirewall.SetStartService(true)
  SuSEFirewall.StartServices
end

- (Boolean) FWCMDInterfaces(options)

Sets network interface assignment

Parameters:

  • options (Hash)

Returns:

  • (Boolean)

    whether write call is needed



543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 543

def FWCMDInterfaces(options)
  options = deep_copy(options)
  unassigned_interfaces = []
  interfaces = {}
  Builtins.foreach(SuSEFirewall.GetAllKnownInterfaces) do |interface|
    Ops.set(interfaces, Ops.get(interface, "id", ""), interface)
    if Ops.get(interface, "zone") == nil
      unassigned_interfaces = Builtins.add(
        unassigned_interfaces,
        Ops.get(interface, "id")
      )
    end
  end
  for_zone = Ops.get_string(options, "zone")
  return false if !CheckZone(for_zone, true)

  CommandLine.Print("")
  # creating current configuration list
  if Ops.get(options, "show") != nil
    # TRANSLATORS: CommandLine header
    CommandLine.Print(
      String.UnderlinedHeader(_("Network Interfaces in Firewall Zones:"), 0)
    )
    CommandLine.Print("")

    table_items = []
    special_interfaces = {}
    Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
      # for_zone defined but it is not current zone
      next if for_zone != nil && for_zone != zone
      Builtins.foreach(SuSEFirewall.GetInterfacesInZone(zone)) do |interface|
        table_items = Builtins.add(
          table_items,
          [zone, interface, Ops.get(interfaces, [interface, "name"], "")]
        )
      end
      Builtins.foreach(SuSEFirewall.GetSpecialInterfacesInZone(zone)) do |spec_int|
        # TRANSLATORS: CommandLine table item (unknown/special string/interface)
        table_items = Builtins.add(
          table_items,
          [zone, spec_int, _("Special firewall string")]
        )
      end
    end
    # print unassigned only in general view
    if for_zone == nil &&
        Ops.greater_than(Builtins.size(unassigned_interfaces), 0)
      Builtins.foreach(unassigned_interfaces) do |interface|
        table_items = Builtins.add(
          table_items,
          ["---", interface, Ops.get(interfaces, [interface, "name"], "")]
        )
      end
    end
    CommandLine.Print(
      String.TextTable(
        [
          # TRANSLATORS: CommandLine table header item
          _("Zone"),
          # TRANSLATORS: CommandLine table header item
          _("Interface"),
          # TRANSLATORS: CommandLine table header item
          _("Device Name")
        ],
        table_items,
        {}
      )
    )
  elsif Ops.get(options, "add") != nil
    interface = Ops.get_string(options, "interface")
    if interface == nil
      # TRANSLATORS: CommandLine error, %1 is needed parameter name
      CommandLine.Error(
        Builtins.sformat(_("Parameter %1 must be set."), "interface")
      )
      return false
    end
    if for_zone == nil
      # TRANSLATORS: CommandLine error, %1 is needed parameter name
      CommandLine.Error(
        Builtins.sformat(_("Parameter %1 must be set."), "zone")
      )
      return false
    end
    # unknown interface
    if Ops.get(interfaces, interface, {}) == {}
      # TRANSLATORS: CommandLine progress information, %1 is the special string, %2 is the zone name
      CommandLine.Print(
        Builtins.sformat(
          _("Adding special string %1 into zone %2..."),
          interface,
          for_zone
        )
      )
      SuSEFirewall.AddSpecialInterfaceIntoZone(interface, for_zone)
    else
      # TRANSLATORS: CommandLine progress information, %1 is the network interface name, %2 is the zone name
      CommandLine.Print(
        Builtins.sformat(
          _("Adding interface %1 into zone %2..."),
          interface,
          for_zone
        )
      )
      SuSEFirewall.AddInterfaceIntoZone(interface, for_zone)
    end
  end
  if Ops.get(options, "remove") != nil
    interface = Ops.get_string(options, "interface")
    if interface == nil
      # TRANSLATORS: CommandLine error, %1 is needed parameter name
      CommandLine.Error(
        Builtins.sformat(_("Parameter %1 must be set."), "interface")
      )
      return false
    end
    if for_zone == nil
      # TRANSLATORS: CommandLine error, %1 is needed parameter name
      CommandLine.Error(
        Builtins.sformat(_("Parameter %1 must be set."), "zone")
      )
      return false
    end
    # unknown interface
    if Ops.get(interfaces, interface, {}) == {}
      # TRANSLATORS: CommandLine progress information, %1 is the special string, %2 is the zone name
      CommandLine.Print(
        Builtins.sformat(
          _("Removing special string %1 from zone %2..."),
          interface,
          for_zone
        )
      )
      SuSEFirewall.RemoveSpecialInterfaceFromZone(interface, for_zone)
    else
      # TRANSLATORS: CommandLine progress information, %1 is the network interface name, %2 is the zone name
      CommandLine.Print(
        Builtins.sformat(
          _("Removing interface %1 from zone %2..."),
          interface,
          for_zone
        )
      )
      SuSEFirewall.RemoveInterfaceFromZone(interface, for_zone)
    end
  end
  CommandLine.Print("")

  true
end

- (Boolean) FWCMDLogging(options)

Sets logging details

Parameters:

  • options (Hash)

Returns:

  • (Boolean)

    whether write is needed



698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
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
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 698

def FWCMDLogging(options)
  options = deep_copy(options)
  logging_meaning = {
    # TRANSLATORS: CommandLine table item
    "ALL"  => _("Log all"),
    # TRANSLATORS: CommandLine table item
    "CRIT" => _("Log only critical"),
    # TRANSLATORS: CommandLine table item
    "NONE" => _("Do not log any")
  }

  if Ops.get(options, "show") != nil
    log_accepted = SuSEFirewall.GetLoggingSettings("ACCEPT")
    log_nonaccepted = SuSEFirewall.GetLoggingSettings("DROP")

    CommandLine.Print("")
    # TRANSLATORS: CommandLine header
    CommandLine.Print(
      String.UnderlinedHeader(_("Global Logging Settings:"), 0)
    )
    CommandLine.Print("")

    CommandLine.Print(
      String.TextTable(
        [
          # TRANSLATORS: CommandLine table header item
          _("Rule Type"),
          # TRANSLATORS: CommandLine table header item
          _("Value"),
          _("Logging Level")
        ],
        [
          # TRANSLATORS: CommandLine table item
          [
            _("Accepted"),
            Builtins.tolower(log_accepted),
            Ops.get(logging_meaning, log_accepted, "Software Error")
          ],
          # TRANSLATORS: CommandLine table item
          [
            _("Not accepted"),
            Builtins.tolower(log_nonaccepted),
            Ops.get(logging_meaning, log_nonaccepted, "Software Error")
          ]
        ],
        {}
      )
    )
    CommandLine.Print("")

    # TRANSLATORS: CommandLine header
    CommandLine.Print(
      String.UnderlinedHeader(_("Logging Broadcast Packets:"), 0)
    )
    CommandLine.Print("")

    table_items = []
    Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
      table_items = Builtins.add(
        table_items,
        [
          zone,
          SuSEFirewall.GetZoneFullName(zone),
          SuSEFirewall.GetIgnoreLoggingBroadcast(zone) == "yes" ?
            # TRANSLATORS: CommandLine table item
            _("Logging enabled") :
            # TRANSLATORS: CommandLine table item
            _("Logging disabled")
        ]
      )
    end
    CommandLine.Print(
      String.TextTable(
        [
          # TRANSLATORS: CommandLine table header item
          _("Short"),
          # TRANSLATORS: CommandLine table header item
          _("Zone Name"),
          # TRANSLATORS: CommandLine table header item
          _("Logging Status")
        ],
        table_items,
        {}
      )
    )
    CommandLine.Print("")

    return false
  elsif Ops.get(options, "set") != nil
    possible_levels = ["all", "crit", "none"]
    if Ops.get(options, "accepted") != nil
      value = Builtins.tolower(Ops.get_string(options, "accepted"))
      if !Builtins.contains(possible_levels, value)
        # TRANSLATORS: CommandLine error message, %1 is an option value, %2 is an option name
        CommandLine.Error(
          Builtins.sformat(
            _("Value %1 is not allowed for option %2."),
            Ops.get(options, "accepted"),
            "accepted"
          )
        )
        return false
      end
      SuSEFirewall.SetLoggingSettings("ACCEPT", Builtins.toupper(value))
    end
    if Ops.get(options, "nonaccepted") != nil
      value = Builtins.tolower(Ops.get_string(options, "nonaccepted"))
      if !Builtins.contains(possible_levels, value)
        # TRANSLATORS: CommandLine error message, %1 is an option value, %2 is an option name
        CommandLine.Error(
          Builtins.sformat(
            _("Value %1 is not allowed for option %2."),
            Ops.get(options, "nonaccepted"),
            "nonaccepted"
          )
        )
        return false
      end
      SuSEFirewall.SetLoggingSettings("DROP", Builtins.toupper(value))
    end
    if Ops.get(options, "logbroadcast") != nil
      zones_to_setup = SuSEFirewall.GetKnownFirewallZones
      # zone defined
      zone = Ops.get_string(options, "zone")
      # zone is defined
      if zone != nil
        # defined, but wrong
        if !CheckZone(zone, false)
          return false 
          # defined well
        else
          zones_to_setup = [zone]
        end
      end

      value = Builtins.tolower(Ops.get_string(options, "logbroadcast"))
      if !Builtins.contains(["yes", "no"], value)
        # TRANSLATORS: CommandLine error message, %1 is an option value, %2 is an option name
        CommandLine.Error(
          Builtins.sformat(
            _("Value %1 is not allowed for option %2."),
            Ops.get(options, "logbroadcast"),
            "logbroadcast"
          )
        )
        return false
      end

      Builtins.foreach(zones_to_setup) do |zone2|
        SuSEFirewall.SetIgnoreLoggingBroadcast(zone2, value)
      end
    end

    return true
  end

  nil
end

- (Boolean) FWCMDMasqRedirect(options)

Overall handler for redirect to masqueraded network

Parameters:

  • options (Hash)

Returns:

  • (Boolean)

    whether write call is needed



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
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1430

def FWCMDMasqRedirect(options)
  options = deep_copy(options)
  if Ops.get(options, "show") != nil
    FWCMDMasqRedirectShow(options)
    return false
  elsif Ops.get(options, "add") != nil
    # checking existency
    checked = true
    Builtins.foreach(["sourcenet", "protocol", "req_port", "redir_ip"]) do |option|
      if Ops.get(options, option) == nil
        # TRANSLATORS: CommandLine error, %1 is needed parameter name
        CommandLine.Error(
          Builtins.sformat(_("Parameter %1 must be set."), option)
        )
        checked = false
      end
    end
    return false if !checked

    # filling strings
    new = {}
    Builtins.foreach(
      [
        "sourcenet",
        "protocol",
        "req_port",
        "redir_ip",
        "req_ip",
        "redir_port"
      ]
    ) { |option| Ops.set(new, option, Ops.get_string(options, option, "")) }

    # checking format
    Ops.set(new, "protocol", Builtins.tolower(Ops.get(new, "protocol", "")))
    if !Builtins.contains(["tcp", "udp"], Ops.get(new, "protocol", ""))
      # TRANSLATORS: CommandLine error message, %1 is an option value, %2 is an option name
      CommandLine.Error(
        Builtins.sformat(
          _("Value %1 is not allowed for option %2."),
          Ops.get(new, "protocol", ""),
          "protocol"
        )
      )
      return false
    end

    # checking port names (if known)
    port_errors = ""
    Builtins.foreach(["req_port", "redir_port"]) do |key|
      if Ops.get(new, key) != nil
        port_number = Builtins.tostring(
          GetPortNumber(Ops.get(new, key, ""))
        )
        if port_number != nil
          # internally using port numbers instead port names
          Ops.set(new, key, port_number)
        else
          port_errors = Ops.add(
            Ops.add(port_errors, port_errors != "" ? "\n" : ""),
            # TRANSLATORS: CommandLine error message, %1 is a port name
            Builtins.sformat(
              _("Unknown port name %1."),
              Ops.get(new, key, "")
            )
          )
        end
      end
    end
    # there were some errors in port names
    if port_errors != ""
      CommandLine.Error(port_errors)
      return false
    end

    SuSEFirewall.AddForwardIntoMasqueradeRule(
      Ops.get(new, "sourcenet", ""),
      Ops.get(new, "redir_ip", ""),
      Ops.get(new, "protocol", ""),
      Ops.get(new, "req_port", ""),
      Ops.get(new, "redir_port", ""),
      Ops.get(new, "req_ip", "")
    )
    return true
  elsif Ops.get(options, "remove") != nil
    if Ops.get(options, "record") == nil
      # TRANSLATORS: CommandLine error, %1 is needed parameter name
      CommandLine.Error(
        Builtins.sformat(_("Parameter %1 must be set."), "record")
      )
      return false
    end
    record = Ops.get_integer(options, "record", 0)
    # records are printed 1-n but internally are 0-(n-1)
    record = Ops.subtract(record, 1)
    SuSEFirewall.RemoveForwardIntoMasqueradeRule(record)
    return true
  end

  nil
end

- (Object) FWCMDMasqRedirectShow(options)

Prints the table of the current redirect-to-masquerade rules

Parameters:

  • options (Hash)


1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1360

def FWCMDMasqRedirectShow(options)
  options = deep_copy(options)
  CommandLine.Print("")
  # TRANSLATORS: CommandLine header
  CommandLine.Print(
    String.UnderlinedHeader(_("Redirect Requests to Masqueraded IP:"), 0)
  )
  CommandLine.Print("")

  table_items = []
  records = SuSEFirewall.GetListOfForwardsIntoMasquerade
  counter = 0
  Builtins.foreach(records) do |record|
    counter = Ops.add(counter, 1)
    # if redirect_to_port is not defined, use the same as requested_port
    if Ops.get(record, "to_port", "") == "" ||
        Ops.get(record, "to_port", "") == nil
      Ops.set(record, "to_port", Ops.get(record, "req_port", ""))
    end
    # using port names instead of port numbers
    if Ops.get(options, "names") != nil
      Builtins.foreach(["to_port", "req_port"]) do |key|
        port_name = GetPortName(Ops.get(record, key, ""))
        Ops.set(record, key, port_name) if port_name != nil
      end
    end
    table_items = Builtins.add(
      table_items,
      [
        Builtins.tostring(counter),
        Ops.get(record, "source_net", ""),
        Ops.get(record, "protocol", ""),
        Ops.get(record, "req_ip", ""),
        Ops.get(record, "req_port", ""),
        Ops.get(record, "forward_to", ""),
        Ops.get(record, "to_port", "")
      ]
    )
  end
  CommandLine.Print(
    String.TextTable(
      [
        # TRANSLATORS: CommandLine table header item
        _("ID"),
        # TRANSLATORS: CommandLine table header item
        _("Source Network"),
        # TRANSLATORS: CommandLine table header item
        _("Protocol"),
        # TRANSLATORS: CommandLine table header item, Req.=Requested
        _("Req. IP"),
        # TRANSLATORS: CommandLine table header item, Req.=Requested
        _("Req. Port"),
        # TRANSLATORS: CommandLine table header item, Redir.=Redirect
        _("Redir. to IP"),
        # TRANSLATORS: CommandLine table header item, Redir.=Redirect
        _("Redir. to Port")
      ],
      table_items,
      {}
    )
  )
  CommandLine.Print("")

  nil
end

- (Boolean) FWCMDMasquerade(options)

Overall masquerade-related handler

Parameters:

  • options (Hash)

Returns:

  • (Boolean)

    whether write call is needed



1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1535

def FWCMDMasquerade(options)
  options = deep_copy(options)
  if Ops.get(options, "show") != nil
    CommandLine.Print("")
    # TRANSLATORS: CommandLine header
    CommandLine.Print(
      String.UnderlinedHeader(_("Masquerading Settings:"), 0)
    )
    CommandLine.Print("")
    CommandLine.Print(
      Builtins.sformat(
        # TRANSLATORS: CommandLine informative text, %1 is "enabled" or "disabled"
        _("Masquerading is %1"),
        SuSEFirewall.GetMasquerade == true ?
          # TRANSLATORS: CommandLine masquerade status
          _("enabled") :
          # TRANSLATORS: CommandLine masquerade status
          _("disabled")
      )
    )
    CommandLine.Print("")
    return false
  elsif Ops.get(options, "enable") != nil
    SuSEFirewall.SetMasquerade(true)
  elsif Ops.get(options, "disable") != nil
    SuSEFirewall.SetMasquerade(false)
  end

  nil
end

- (Boolean) FWCMDServices(options)

Overall handler function for services

Parameters:

  • options (Hash)

Returns:

  • (Boolean)

    whether write call is needed



1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1284

def FWCMDServices(options)
  options = deep_copy(options)
  # listing all known defined services
  if Ops.get(options, "list") != nil
    FWCMDServicesList()
    return false
  elsif Ops.get(options, "show") != nil
    known_zones = SuSEFirewall.GetKnownFirewallZones
    for_zone = Ops.get_string(options, "zone")
    if for_zone != nil
      if !CheckZone(for_zone, true)
        return false
      else
        known_zones = [for_zone]
      end
    end
    FWCMDServicesShow(known_zones, Ops.get(options, "detailed") != nil)
    return false
  elsif Ops.get(options, "add") != nil && Ops.get(options, "remove") != nil
    # TRANSLATORS: CommandLine error message
    CommandLine.Error(_("Only one action command is allowed here."))
  elsif Ops.get(options, "add") != nil || Ops.get(options, "remove") != nil
    zone = Ops.get_string(options, "zone", "")
    return false if !CheckZone(zone, false)

    # add o remove
    action = "add"
    action = "remove" if Ops.get(options, "remove") != nil

    count_entries = 0
    Builtins.foreach(
      ["service", "tcpport", "udpport", "rpcport", "ipprotocol"]
    ) do |type|
      items = CommaSeparatedList(Ops.get_string(options, type, ""))
      if Ops.greater_than(Builtins.size(items), 0)
        count_entries = Ops.add(count_entries, 1)
        if type == "service"
          FWCMDServicesDefinedServicesManagement(action, zone, items)
        else
          FWCMDServicesAdditionalPortsManagement(action, zone, items, type)
        end
      end
    end

    # checking if any action was set along with an action command
    if count_entries == 0
      CommandLine.Error(
        Builtins.sformat(
          # TRANSLATORS: CommandLine error message, %1 is a list of possible entries (without translation)
          _("At least one of %1 must be set."),
          "service, tcpport, udpport, rpcport, protocol"
        )
      )
    end
    return true
  elsif Ops.get(options, "protect") != nil
    zone = Ops.get_string(options, "zone", "")
    return false if !CheckZone(zone, false)

    FWCMDServicesProtect(zone, Ops.get_string(options, "protect"))
  else
    CommandLine.Error(
      Builtins.sformat(
        # TRANSLATORS: CommandLine error message, %1 is a list of possible action commands
        _("At least one action command from %1 must be set."),
        "list, show, add, remove"
      )
    )
  end

  nil
end

- (Object) FWCMDServicesAdditionalPortsManagement(action, zone, ports_or_protocols, type)

Adds/removes ports to/from zone.

Parameters:

  • action (String)

    (“add” or “remove”)

  • zone (String)
  • ports_or_protocols (Array<String>)
  • type (String)


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

def FWCMDServicesAdditionalPortsManagement(action, zone, ports_or_protocols, type)
  ports_or_protocols = deep_copy(ports_or_protocols)
  types = {
    "tcpport"    => "TCP",
    "udpport"    => "UDP",
    "rpcport"    => "RPC",
    "ipprotocol" => "IP"
  }
  protocol = Ops.get(types, type)

  if protocol != nil
    current = SuSEFirewall.GetAdditionalServices(protocol, zone)
    if action == "add"
      current = Convert.convert(
        Builtins.union(current, ports_or_protocols),
        :from => "list",
        :to   => "list <string>"
      )
    else
      current = Builtins.filter(current) do |check_item|
        !Builtins.contains(ports_or_protocols, check_item)
      end
    end
    SuSEFirewall.SetAdditionalServices(protocol, zone, current)
  else
    Builtins.y2error("Software error %1", type)
  end

  nil
end

- (Object) FWCMDServicesDefinedServicesManagement(action, zone, services)

Adds/removes services to/from zone.

Parameters:

  • action (String)

    (“add” or “remove”)

  • zone (String)
  • services (Array<String>)


1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1194

def FWCMDServicesDefinedServicesManagement(action, zone, services)
  services = deep_copy(services)
  Builtins.foreach(services) do |service|
    if !SuSEFirewallServices.IsKnownService(service)
      # TRANSLATORS: CommandLine error message, %1 is a service id
      CommandLine.Error(Builtins.sformat(_("Unknown service %1."), service))
      services = Builtins.filter(services) do |service_item|
        service_item != service
      end
    end
  end

  if action == "add"
    SuSEFirewall.SetServicesForZones(services, [zone], true)
  else
    SuSEFirewall.SetServicesForZones(services, [zone], false)
  end

  nil
end

- (Object) FWCMDServicesList

Prints all known firewall services



970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 970

def FWCMDServicesList
  CommandLine.Print("")
  # TRANSLATORS: CommandLine header
  CommandLine.Print(
    String.UnderlinedHeader(_("Defined Firewall Services:"), 0)
  )
  table_items = []
  Builtins.foreach(SuSEFirewallServices.GetSupportedServices) do |service_id, service_name|
    table_items = Builtins.add(table_items, [service_id, service_name])
  end
  CommandLine.Print("")
  CommandLine.Print(
    String.TextTable(
      [
        # TRANSLATORS: CommandLine table header item
        _("ID"),
        # TRANSLATORS: CommandLine table header item
        _("Service Name")
      ],
      table_items,
      {}
    )
  )
  CommandLine.Print("")

  nil
end

- (Object) FWCMDServicesProtect(zone, protect)

Sets protect-from value

Parameters:

  • zone (String)

    (only “INT” is supported)

  • protect (String)

    “yes” or “no”



1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1256

def FWCMDServicesProtect(zone, protect)
  protect = Builtins.tolower(protect)
  if !Builtins.contains(["yes", "no"], protect)
    # TRANSLATORS: CommandLine error message, %1 is an option value, %2 is an option name
    CommandLine.Error(
      Builtins.sformat(
        _("Value %1 is not allowed for option %2."),
        protect,
        "protect"
      )
    )
    return nil
  end
  # Only Protect from Internal is supported
  if zone != "INT"
    # TRANSLATORS: CommandLine error message
    CommandLine.Error(_("Protection can only be set for internal zones."))
    return nil
  end
  SuSEFirewall.SetProtectFromInternalZone(protect == "yes")

  nil
end

- (Object) FWCMDServicesShow(for_zones, detailed)

Prints currently allowed services

Parameters:

  • for_zones (Array<String>)
  • detailed (Boolean)


1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
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
1146
1147
1148
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
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1002

def FWCMDServicesShow(for_zones, detailed)
  for_zones = deep_copy(for_zones)
  known_services = SuSEFirewallServices.GetSupportedServices
  protect_from_INT = SuSEFirewall.GetProtectFromInternalZone

  detailed_def = {
    # TRANSLATORS: CommandLine table item
    "tcp_ports"    => _("TCP port"),
    # TRANSLATORS: CommandLine table item
    "udp_ports"    => _("UDP port"),
    # TRANSLATORS: CommandLine table item
    "rpc_ports"    => _("RPC port"),
    # TRANSLATORS: CommandLine table item
    "ip_protocols" => _("IP protocol")
  }

  CommandLine.Print("")
  # TRANSLATORS: CommandLine header
  CommandLine.Print(
    String.UnderlinedHeader(_("Allowed Services in Zones:"), 0)
  )
  CommandLine.Print("")
  table_items = []
  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
    next if !Builtins.contains(for_zones, zone)
    if zone == "INT" && protect_from_INT == false
      table_items = Builtins.add(
        table_items,
        [
          zone,
          # TRANSLATORS: CommandLine table item (all firewall services are allowed in this zone)
          "*" +
            _("All services") + "*",
          # TRANSLATORS: CommandLine table item (this zone is not protected at all)
          "*" +
            _("Entire zone unprotected") + "*"
        ]
      )
      next
    end
    Builtins.foreach(known_services) do |service_id, service_name|
      if SuSEFirewall.IsServiceSupportedInZone(service_id, zone)
        table_items = Builtins.add(
          table_items,
          [zone, service_id, service_name]
        )
        # detailed listing of used ports
        if detailed
          needed_ports = SuSEFirewallServices.GetNeededPortsAndProtocols(
            service_id
          )
          Builtins.foreach(
            ["tcp_ports", "udp_ports", "rpc_ports", "ip_protocols"]
          ) do |short_def|
            if Ops.greater_than(
                Builtins.size(Ops.get(needed_ports, short_def, [])),
                0
              )
              Builtins.foreach(Ops.get(needed_ports, short_def, [])) do |port|
                table_items = Builtins.add(
                  table_items,
                  [
                    "",
                    Builtins.sformat(
                      "> %1: %2",
                      Ops.get(detailed_def, short_def, ""),
                      port
                    )
                  ]
                )
                table_items = Builtins.add(table_items, [""])
              end
            end
          end
        end
      end
    end
  end
  CommandLine.Print(
    String.TextTable(
      [
        # TRANSLATORS: CommandLine table header item
        _("Zone"),
        # TRANSLATORS: CommandLine table header item
        _("Service ID"),
        # TRANSLATORS: CommandLine table header item
        _("Service Name")
      ],
      table_items,
      {}
    )
  )

  CommandLine.Print("")
  # TRANSLATORS: CommandLine header
  CommandLine.Print(
    String.UnderlinedHeader(_("Additional Allowed Ports:"), 0)
  )
  CommandLine.Print("")
  table_items = []
  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
    next if !Builtins.contains(for_zones, zone)
    if zone == "INT" && protect_from_INT == false
      table_items = Builtins.add(
        table_items,
        [
          zone,
          # TRANSLATORS: CommandLine table item (all ports are allowed in this zone)
          "*" +
            _("All ports") + "*",
          # TRANSLATORS: CommandLine table item (this zone is not protected at all)
          "*" +
            _("Entire zone unprotected") + "*"
        ]
      )
      next
    end
    Builtins.foreach(["TCP", "UDP", "RPC"]) do |protocol|
      Builtins.foreach(SuSEFirewall.GetAdditionalServices(protocol, zone)) do |port|
        table_items = Builtins.add(table_items, [zone, protocol, port])
      end
    end
  end
  CommandLine.Print(
    String.TextTable(
      [
        # TRANSLATORS: CommandLine table header item
        _("Zone"),
        # TRANSLATORS: CommandLine table header item
        _("Protocol"),
        # TRANSLATORS: CommandLine table header item
        _("Port")
      ],
      table_items,
      {}
    )
  )
  CommandLine.Print("")

  CommandLine.Print("")
  # TRANSLATORS: CommandLine header
  CommandLine.Print(
    String.UnderlinedHeader(
      _("Allowed Additional IP Protocols in Zones:"),
      0
    )
  )
  CommandLine.Print("")
  table_items = []
  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
    next if !Builtins.contains(for_zones, zone)
    if zone == "INT" && protect_from_INT == false
      table_items = Builtins.add(
        table_items,
        [
          zone,
          # TRANSLATORS: CommandLine table item (all protocols are allowed in this zone)
          "*" +
            _("All IP protocols") + "*",
          # TRANSLATORS: CommandLine table item (this zone is not protected at all)
          "*" +
            _("Entire zone unprotected") + "*"
        ]
      )
      next
    end
    Builtins.foreach(SuSEFirewall.GetAdditionalServices("IP", zone)) do |protocol|
      table_items = Builtins.add(table_items, [zone, protocol])
    end
  end
  CommandLine.Print(
    String.TextTable(
      [
        # TRANSLATORS: CommandLine table header item
        _("Zone"),
        # TRANSLATORS: CommandLine table header item
        _("IP Protocol")
      ],
      table_items,
      {}
    )
  )
  CommandLine.Print("")

  nil
end

- (Boolean) FWCMDStartup(options)

Sets startup details

Returns:

  • (Boolean)

    always true



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

def FWCMDStartup(options)
  options = deep_copy(options)
  if Ops.get(options, "atboot") != nil && Ops.get(options, "manual") != nil
    # TRANSLATORS: CommandLine error message
    CommandLine.Error(_("Only one parameter is allowed."))
  elsif Ops.get(options, "atboot") != nil
    CommandLine.Print("")
    # TRANSLATORS: CommandLine header
    CommandLine.Print(String.UnderlinedHeader(_("Start-Up:"), 0))
    CommandLine.Print("")
    # TRANSLATORS: CommandLine progress information
    CommandLine.Print(_("Enabling firewall in the boot process..."))
    CommandLine.Print("")
    SuSEFirewall.SetEnableService(true)
  elsif Ops.get(options, "manual") != nil
    CommandLine.Print("")
    # TRANSLATORS: CommandLine header
    CommandLine.Print(String.UnderlinedHeader(_("Start-Up:"), 0))
    CommandLine.Print("")
    # TRANSLATORS: CommandLine progress information
    CommandLine.Print(_("Removing firewall from the boot process..."))
    CommandLine.Print("")
    SuSEFirewall.SetEnableService(false)
  elsif Ops.get(options, "show") != nil
    CommandLine.Print("")
    # TRANSLATORS: CommandLine header
    CommandLine.Print(String.UnderlinedHeader(_("Start-Up:"), 0))
    CommandLine.Print("")
    if SuSEFirewall.GetEnableService
      # TRANSLATORS: CommandLine informative text
      CommandLine.Print(_("Firewall is enabled in the boot process"))
    else
      # TRANSLATORS: CommandLine informative text
      CommandLine.Print(_("Firewall needs manual starting"))
    end
    CommandLine.Print("")
  end

  true
end

- (Boolean) FWCMDSummary(options)

Prints firewall summary for zones

Parameters:

  • options (Hash)

Returns:

  • (Boolean)

    always false



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 470

def FWCMDSummary(options)
  options = deep_copy(options)
  # printing summary

  # no zone => all zones
  for_zone = Ops.get_string(options, "zone")
  for_zones = []
  if for_zone != nil
    if !CheckZone(for_zone, false)
      return false
    else
      for_zones = [for_zone]
    end
  end

  CommandLine.Print("")
  # TRANSLATORS: CommandLine header
  CommandLine.Print(String.UnderlinedHeader(_("Summary:"), 0))
  CommandLine.Print("")
  CommandLine.Print(InitBoxSummary(for_zones))

  # Do not call Write()
  false
end

- (Boolean) FWCMDZones(options)

Calls ListFirewallZones

Returns:

  • (Boolean)

    always false



457
458
459
460
461
462
463
464
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 457

def FWCMDZones(options)
  options = deep_copy(options)
  # listing known zones
  ListFirewallZones() if Ops.get(options, "list") != nil

  # Do not call Write()
  false
end

- (Object) ListFirewallZones

Function prints table of known firewall zones



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

def ListFirewallZones
  CommandLine.Print("")
  # TRANSLATORS: CommandLine header
  CommandLine.Print(
    String.UnderlinedHeader(_("Listing Known Firewall Zones:"), 0)
  )
  CommandLine.Print("")

  table_items = []
  Builtins.foreach(SuSEFirewall.GetKnownFirewallZones) do |zone|
    table_items = Builtins.add(
      table_items,
      [zone, SuSEFirewall.GetZoneFullName(zone)]
    )
  end
  CommandLine.Print(
    String.TextTable(
      [
        # TRANSLATORS: CommandLine table header item
        _("Shortcut"),
        # TRANSLATORS: CommandLine table header item
        _("Zone Name")
      ],
      table_items,
      {}
    )
  )

  CommandLine.Print("")

  nil
end

- (Object) main



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 36

def main
  Yast.import "UI"

  textdomain "firewall"

  Yast.import "CommandLine"
  Yast.import "SuSEFirewall"
  Yast.import "SuSEFirewallServices"
  Yast.import "SuSEFirewallUI"
  Yast.import "Mode"
  Yast.import "Report"
  Yast.import "String"

  Yast.include self, "firewall/summary.rb"
  Yast.include self, "firewall/generalfunctions.rb"

  @cmdline = {
    "id"         => "firewall",
    # TRANSLATORS: CommandLine help
    "help"       => _(
      "Firewall configuration"
    ),
    "initialize" => fun_ref(SuSEFirewall.method(:Read), "boolean ()"),
    "finish"     => fun_ref(SuSEFirewall.method(:Write), "boolean ()"),
    "actions"    => {
      "startup"      => {
        "handler" => fun_ref(method(:FWCMDStartup), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _("Start-up settings"),
        "example" => ["startup show", "startup atboot", "startup manual"]
      },
      "zones"        => {
        "handler" => fun_ref(method(:FWCMDZones), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _(
          "Known firewall zones"
        ),
        "example" => "zones list"
      },
      "interfaces"   => {
        "handler" => fun_ref(method(:FWCMDInterfaces), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _(
          "Network interfaces configuration"
        ),
        "example" => [
          "interfaces show",
          "interfaces add interface=eth0 zone=INT"
        ]
      },
      "services"     => {
        "handler" => fun_ref(method(:FWCMDServices), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _(
          "Allowed services, ports, and protocols"
        ),
        "example" => [
          "services show detailed",
          "services set protect=yes zone=INT",
          "services add service=service:dhcp-server zone=EXT",
          "services remove ipprotocol=esp tcpport=12,13,ipp zone=DMZ"
        ]
      },
      "broadcast"    => {
        "handler" => fun_ref(method(:FWCMDBroadcast), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _(
          "Broadcast packet settings"
        ),
        "example" => "broadcast add zone=INT port=ipp,233"
      },
      "masquerade"   => {
        "handler" => fun_ref(method(:FWCMDMasquerade), "boolean (map)"),
        # TRANSLATORS: CommandLine
        "help"    => _("Masquerading settings"),
        "example" => ["masquerade show", "masquerade enable"]
      },
      "masqredirect" => {
        "handler" => fun_ref(method(:FWCMDMasqRedirect), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _(
          "Redirect requests to masqueraded IP"
        ),
        "example" => "masqredirect remove record=6"
      },
      "logging"      => {
        "handler" => fun_ref(method(:FWCMDLogging), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _("Logging settings"),
        "example" => [
          "logging set accepted=critical",
          "logging set logbroadcast=no zone=INT"
        ]
      },
      "summary"      => {
        "handler" => fun_ref(method(:FWCMDSummary), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _(
          "Firewall configuration summary"
        ),
        "example" => ["summary", "summary zone=EXT"]
      },
      "enable"       => {
        "handler" => fun_ref(method(:FWCMDEnable), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _("Enables firewall"),
        "example" => ["enable"]
      },
      "disable"      => {
        "handler" => fun_ref(method(:FWCMDDisable), "boolean (map)"),
        # TRANSLATORS: CommandLine help
        "help"    => _("Disables firewall"),
        "example" => ["disable"]
      }
    },
    "options"    => {
      "show"         => {
        # TRANSLATORS: CommandLine help
        "help" => _("Show current settings")
      },
      "atboot"       => {
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Start firewall in the boot process"
        )
      },
      "manual"       => {
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Start firewall manually"
        )
      },
      "list"         => {
        # TRANSLATORS: CommandLine help
        "help" => _(
          "List configured entries"
        )
      },
      "zone"         => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _("Zone short name")
      },
      "add"          => {
        # TRANSLATORS: CommandLine help
        "help" => _("Add a new record")
      },
      "remove"       => {
        # TRANSLATORS: CommandLine help
        "help" => _("Remove a record")
      },
      "interface"    => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Network interface configuration name"
        )
      },
      "accepted"     => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Logging accepted packets (all|crit|none)"
        )
      },
      "nonaccepted"  => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Logging not accepted packets (all|crit|none)"
        )
      },
      "logbroadcast" => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Logging broadcast packets (yes|no)"
        )
      },
      "set"          => {
        # TRANSLATORS: CommandLine help
        "help" => _("Set value")
      },
      "port"         => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Port name or number; comma-separate multiple ports"
        )
      },
      "service"      => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Known firewall service; comma-separate multiple services"
        )
      },
      "tcpport"      => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "TCP port name or number; comma-separate multiple ports"
        )
      },
      "udpport"      => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "UDP port name or number; comma-separate multiple ports"
        )
      },
      "rpcport"      => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "RPC port name; comma-separate multiple ports"
        )
      },
      "ipprotocol"   => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "IP protocol name; comma-separate multiple protocols"
        )
      },
      "protect"      => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Set zone protection (yes|no)"
        )
      },
      "detailed"     => {
        # TRANSLATORS: CommandLine help
        "help" => _("Detailed information")
      },
      "enable"       => {
        # TRANSLATORS: CommandLine help
        "help" => _("Enable option")
      },
      "disable"      => {
        # TRANSLATORS: CommandLine help
        "help" => _("Disable option")
      },
      "sourcenet"    => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Source network, such as 0/0 or 145.12.35.0/255.255.255.0"
        )
      },
      "protocol"     => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _("Protocol (tcp|udp)")
      },
      "req_ip"       => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Requested external IP (optional)"
        )
      },
      "req_port"     => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Requested port name or number"
        )
      },
      "redir_ip"     => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Redirect to internal IP"
        )
      },
      "redir_port"   => {
        "type" => "string",
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Redirect to port on internal IP (optional)"
        )
      },
      "record"       => {
        "type" => "integer",
        # TRANSLATORS: CommandLine help
        "help" => _("Record number")
      },
      "names"        => {
        # TRANSLATORS: CommandLine help
        "help" => _(
          "Use port names instead of port numbers"
        )
      }
    },
    "mappings"   => {
      "startup"      => ["show", "atboot", "manual"],
      "zones"        => ["list"],
      "interfaces"   => ["show", "add", "remove", "interface", "zone"],
      "services"     => [
        "list",
        "show",
        "add",
        "remove",
        "set",
        "detailed",
        "zone",
        "service",
        "tcpport",
        "udpport",
        "rpcport",
        "ipprotocol",
        "protect"
      ],
      "masquerade"   => ["show", "enable", "disable"],
      "masqredirect" => [
        "show",
        "add",
        "remove",
        "sourcenet",
        "protocol",
        "req_ip",
        "req_port",
        "redir_ip",
        "redir_port",
        "record",
        "names"
      ],
      "logging"      => [
        "show",
        "set",
        "accepted",
        "nonaccepted",
        "logbroadcast",
        "zone"
      ],
      "broadcast"    => ["show", "add", "remove", "zone", "port"],
      "summary"      => ["zone"],
      "enable"       => [],
      "disable"      => []
    }
  }
end

- (Object) Run

Runs the commandline interface for firewall



1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
# File '../../src/modules/SuSEFirewallCMDLine.rb', line 1587

def Run
  # variable from SuSEFirewallUI
  SuSEFirewallUI.simple_text_output = true

  Builtins.y2milestone("----------------------------------------")
  Builtins.y2milestone(
    Builtins.sformat("Starting CommandLine with parameters %1", WFM.Args)
  )
  SummaryInitCommandLine()
  CommandLine.Run(@cmdline)
  Builtins.y2milestone("----------------------------------------")

  nil
end