/usr/bin/firewallctl is in firewalld 0.4.4.6-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 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 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 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 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 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 1356 1357 1358 1359 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 1425 1426 1427 1428 1429 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 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 | #!/usr/bin/python3 -Es
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2016 Red Hat, Inc.
#
# Authors:
# Thomas Woerner <twoerner@redhat.com>
# Jiri Popelka <jpopelka@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from gi.repository import GObject
import sys
sys.modules['gobject'] = GObject
import argparse
import os
from firewall.client import FirewallClient, FirewallClientIPSetSettings, \
FirewallClientZoneSettings, FirewallClientServiceSettings, \
FirewallClientHelperSettings, FirewallClientIcmpTypeSettings
from firewall.errors import FirewallError
from firewall import errors
from firewall.functions import joinArgs, splitArgs
from firewall.core.fw_nm import nm_is_imported, \
nm_get_connection_of_interface, nm_get_zone_of_connection, \
nm_set_zone_of_connection
from firewall.core.io.zone import zone_reader
from firewall.core.io.service import service_reader
from firewall.core.io.ipset import ipset_reader
from firewall.core.io.helper import helper_reader
from firewall.core.io.icmptype import icmptype_reader
from firewall.command import FirewallCommand
#
def try_set_zone_of_interface(_zone, interface):
if nm_is_imported():
try:
connection = nm_get_connection_of_interface(interface)
except Exception:
pass
else:
if connection is not None:
if _zone == nm_get_zone_of_connection(connection):
if _zone == "":
cmd.print_warning("The interface is under control of "
"NetworkManager and already bound to "
"the default zone")
else:
cmd.print_warning("The interface is under control of "
"NetworkManager and already bound "
"to '%s'" % _zone)
if _zone == "":
cmd.print_msg("The interface is under control of "
"NetworkManager, setting zone to default.")
else:
cmd.print_msg("The interface is under control of "
"NetworkManager, setting zone "
"to '%s'." % _zone)
nm_set_zone_of_connection(_zone, connection)
return True
return False
#
parser = argparse.ArgumentParser(
description="firewall command line control utility")
subparsers = parser.add_subparsers()
# output
grp_output = parser.add_mutually_exclusive_group()
grp_output.add_argument("-v", "--verbose", action="store_true")
grp_output.add_argument("-q", "--quiet", action="store_true")
# version
grp_version = subparsers.add_parser("version", help="Show firewall version")
grp_version.set_defaults(parser="version")
# state
grp_state = subparsers.add_parser("state", help="Get firewalld state")
grp_state.set_defaults(parser="state")
# reload
grp_reload = subparsers.add_parser("reload", help="Reload firewalld")
grp_reload.set_defaults(parser="reload")
grp_reload.add_argument("-c", "--complete", action="store_true")
# runtime_to_permanent
grp_runtime_to_permanent = subparsers.add_parser(
"runtime-to-permanent", help="Save run-time as permanent configuration")
grp_runtime_to_permanent.set_defaults(parser="runtime-to-permanent")
#############################################################################
# list
grp_list = subparsers.add_parser(
"list", help="List zones, services ipsets, helpers or icmptypes")
grp_list.set_defaults(parser="list")
grp_list_subparsers = grp_list.add_subparsers(help="Commands")
grp_list_zones = grp_list_subparsers.add_parser("zones", help="List zones")
grp_list_zones.set_defaults(list="zones")
group = grp_list_zones.add_mutually_exclusive_group()
group.add_argument("-a", "--active", action="store_true")
group.add_argument("-p", "--permanent", action="store_true")
grp_list_services = grp_list_subparsers.add_parser(
"services", help="List services")
grp_list_services.set_defaults(list="services")
grp_list_services.add_argument("-p", "--permanent", action="store_true")
grp_list_ipsets = grp_list_subparsers.add_parser("ipsets", help="List ipsets")
grp_list_ipsets.set_defaults(list="ipsets")
grp_list_ipsets.add_argument("-p", "--permanent", action="store_true")
grp_list_helpers = grp_list_subparsers.add_parser(
"helpers", help="List helpers")
grp_list_helpers.set_defaults(list="helpers")
grp_list_helpers.add_argument("-p", "--permanent", action="store_true")
grp_list_icmptypes = grp_list_subparsers.add_parser(
"icmptypes", help="List icmptypes")
grp_list_icmptypes.set_defaults(list="icmptypes")
grp_list_icmptypes.add_argument("-p", "--permanent", action="store_true")
#############################################################################
# info
grp_info = subparsers.add_parser(
"info", help="Info about a zone, service, ipset, helper or icmptype")
grp_info.set_defaults(parser="info")
grp_info_subparsers = grp_info.add_subparsers(help="Commands")
grp_info_zone = grp_info_subparsers.add_parser("zone", help="Info about a zone")
grp_info_zone.set_defaults(info="zone")
grp_info_zone.add_argument("zone", action="store", metavar="<zone>")
grp_info_zone.add_argument("-p", "--permanent", action="store_true")
grp_info_zones = grp_info_subparsers.add_parser(
"zones", help="Info about all zones")
grp_info_zones.set_defaults(info="zones")
group = grp_info_zones.add_mutually_exclusive_group()
group.add_argument("-a", "--active", action="store_true")
group.add_argument("-p", "--permanent", action="store_true")
grp_info_service = grp_info_subparsers.add_parser(
"service", help="Info about a service")
grp_info_service.set_defaults(info="service")
grp_info_service.add_argument("service", action="store", metavar="<service>")
grp_info_service.add_argument("-p", "--permanent", action="store_true")
grp_info_services = grp_info_subparsers.add_parser(
"services", help="Info about all services")
grp_info_services.set_defaults(info="services")
grp_info_services.add_argument("-p", "--permanent", action="store_true")
grp_info_ipset = grp_info_subparsers.add_parser(
"ipset", help="Info about ipsets")
grp_info_ipset.set_defaults(info="ipset")
grp_info_ipset.add_argument("ipset", action="store", metavar="<ipset>")
grp_info_ipset.add_argument("-p", "--permanent", action="store_true")
grp_info_ipsets = grp_info_subparsers.add_parser(
"ipsets", help="Info about all ipsets")
grp_info_ipsets.set_defaults(info="ipsets")
grp_info_ipsets.add_argument("-p", "--permanent", action="store_true")
grp_info_helper = grp_info_subparsers.add_parser(
"helper", help="Info about a helper")
grp_info_helper.set_defaults(info="helper")
grp_info_helper.add_argument("helper", action="store", metavar="<helper>")
grp_info_helper.add_argument("-p", "--permanent", action="store_true")
grp_info_helpers = grp_info_subparsers.add_parser(
"helpers", help="Info about all helpers")
grp_info_helpers.set_defaults(info="helpers")
grp_info_helpers.add_argument("-p", "--permanent", action="store_true")
grp_info_icmptype = grp_info_subparsers.add_parser(
"icmptype", help="Info about a icmptype")
grp_info_icmptype.set_defaults(info="icmptype")
grp_info_icmptype.add_argument("icmptype", action="store", metavar="<icmptype>")
grp_info_icmptype.add_argument("-p", "--permanent", action="store_true")
grp_info_icmptypes = grp_info_subparsers.add_parser(
"icmptypes", help="Info about all icmptypes")
grp_info_icmptypes.set_defaults(info="icmptypes")
grp_info_icmptypes.add_argument("-p", "--permanent", action="store_true")
#############################################################################
# zone
grp_zone = subparsers.add_parser("zone", help="Zone commands")
grp_zone.set_defaults(parser="zone")
grp_zone.add_argument("zone", type=str, action="store", metavar="<zone>")
grp_zone.add_argument("-p", "--permanent", action="store_true")
zone_subparsers = grp_zone.add_subparsers(help="Zone Commands")
# zone.load_defaults
grp_zone_load_defaults = zone_subparsers.add_parser(
"load-defaults", help="Load defaults")
grp_zone_load_defaults.set_defaults(action="load-defaults")
# zone.add
grp_zone_add = zone_subparsers.add_parser("add", help="Add commands")
grp_zone_add.set_defaults(action="add")
zone_add_subparsers = grp_zone_add.add_subparsers()
# zone.add.interface
grp_zone_add_interface = zone_add_subparsers.add_parser(
"interface", help="Add interface")
grp_zone_add_interface.set_defaults(item="interface", required=True)
grp_zone_add_interface.add_argument("interface", metavar="<interface>",
nargs="+")
# zone.add.source
grp_zone_add_source = zone_add_subparsers.add_parser("source",
help="Add source")
grp_zone_add_source.set_defaults(item="source", required=True)
grp_zone_add_source.add_argument("source", metavar="<source>", nargs="+")
# zone.add.service
grp_zone_add_service = zone_add_subparsers.add_parser("service",
help="Add service")
grp_zone_add_service.set_defaults(item="service", required=True)
grp_zone_add_service.add_argument("service", metavar="<service>", nargs="+")
grp_zone_add_service.add_argument("-t", "--timeout", type=int, default=0,
metavar="<seconds>")
# zone.add.port
grp_zone_add_port = zone_add_subparsers.add_parser("port", help="Add port")
grp_zone_add_port.set_defaults(item="port")
grp_zone_add_port.add_argument("port", metavar="<port>", nargs="+")
grp_zone_add_port.add_argument("-t", "--timeout", type=int, default=0,
metavar="<seconds>")
# zone.add.protocol
grp_zone_add_protocol = zone_add_subparsers.add_parser("protocol",
help="Add protocol")
grp_zone_add_protocol.set_defaults(item="protocol")
grp_zone_add_protocol.add_argument("protocol", metavar="<protocol>", nargs="+")
grp_zone_add_protocol.add_argument("-t", "--timeout", type=int, default=0,
metavar="<seconds>")
# zone.add.source-port
grp_zone_add_source_port = zone_add_subparsers.add_parser(
"source-port", help="Add source port")
grp_zone_add_source_port.set_defaults(item="source-port")
grp_zone_add_source_port.add_argument("port", metavar="<source-port>",
nargs="+")
grp_zone_add_source_port.add_argument("-t", "--timeout", type=int, default=0,
metavar="<seconds>")
# zone.add.rich-rule
grp_zone_add_rich_rule = zone_add_subparsers.add_parser("rich-rule",
help="Add rich rule")
grp_zone_add_rich_rule.set_defaults(item="rich-rule", required=True)
grp_zone_add_rich_rule.add_argument("rich_rule", metavar="<rich-rule>",
nargs="+")
grp_zone_add_rich_rule.add_argument("-t", "--timeout", type=int, default=0,
metavar="<seconds>")
# zone.add.masquerade
grp_zone_add_masquerade = zone_add_subparsers.add_parser("masquerade",
help="Add masquerade")
grp_zone_add_masquerade.set_defaults(item="masquerade", required=True)
grp_zone_add_masquerade.add_argument("-t", "--timeout", type=int, default=0,
metavar="<seconds>")
# zone.add.forward-port
grp_zone_add_forward_port = zone_add_subparsers.add_parser(
"forward-port", help="Add forward-port")
grp_zone_add_forward_port.set_defaults(item="forward-port")
grp_zone_add_forward_port.add_argument("forward_port",
metavar="<forward-port>", nargs="+")
grp_zone_add_forward_port.add_argument("-t", "--timeout", type=int, default=0,
metavar="<seconds>")
# zone.add.icmp-block
grp_zone_add_icmp_block = zone_add_subparsers.add_parser("icmp-block",
help="Add icmp-block")
grp_zone_add_icmp_block.set_defaults(item="icmp-block", required=True)
grp_zone_add_icmp_block.add_argument("icmp_block", metavar="<icmp-block>",
nargs="+")
grp_zone_add_icmp_block.add_argument("-t", "--timeout", type=int, default=0,
metavar="<seconds>")
# zone.add.icmp-block-inversion
grp_zone_add_icmp_block_inversion = zone_add_subparsers.add_parser(
"icmp-block-inversion", help="Add icmp-block-inversion")
grp_zone_add_icmp_block_inversion.set_defaults(item="icmp-block-inversion",
required=True)
# zone.get
grp_zone_get = zone_subparsers.add_parser("get", help="Get commands")
grp_zone_get.set_defaults(action="get")
zone_get_subparsers = grp_zone_get.add_subparsers()
# zone.get.description
grp_zone_get_description = zone_get_subparsers.add_parser(
"description", help="Get description")
grp_zone_get_description.set_defaults(item="description")
# zone.get.short
grp_zone_get_short = zone_get_subparsers.add_parser(
"short", help="Get short")
grp_zone_get_short.set_defaults(item="short")
# zone.set
grp_zone_set = zone_subparsers.add_parser("set", help="Set commands")
grp_zone_set.set_defaults(action="set")
zone_set_subparsers = grp_zone_set.add_subparsers()
# zone.set.description
grp_zone_set_description = zone_set_subparsers.add_parser(
"description", help="Set description")
grp_zone_set_description.set_defaults(item="description")
grp_zone_set_description.add_argument("description", metavar="<description>")
# zone.set.short
grp_zone_set_short = zone_set_subparsers.add_parser(
"short", help="Set short")
grp_zone_set_short.set_defaults(item="short")
grp_zone_set_short.add_argument("short", metavar="<short>")
# zone.remove
grp_zone_remove = zone_subparsers.add_parser("remove", help="Remove commands")
grp_zone_remove.set_defaults(action="remove")
zone_remove_subparsers = grp_zone_remove.add_subparsers()
# zone.remove.interface
grp_zone_remove_interface = zone_remove_subparsers.add_parser(
"interface", help="Remove interface")
grp_zone_remove_interface.set_defaults(item="interface")
grp_zone_remove_interface.add_argument("interface", metavar="<interface>",
nargs="+")
# zone.remove.source
grp_zone_remove_source = zone_remove_subparsers.add_parser("source",
help="Remove source")
grp_zone_remove_source.set_defaults(item="source")
grp_zone_remove_source.add_argument("source", metavar="<source>", nargs="+")
# zone.remove.service
grp_zone_remove_service = zone_remove_subparsers.add_parser(
"service", help="Remove service")
grp_zone_remove_service.set_defaults(item="service")
grp_zone_remove_service.add_argument("service", metavar="<service>", nargs="+")
# zone.remove.port
grp_zone_remove_port = zone_remove_subparsers.add_parser("port",
help="Remove port")
grp_zone_remove_port.set_defaults(item="port")
grp_zone_remove_port.add_argument("port", metavar="<port>", nargs="+")
# zone.remove.protocol
grp_zone_remove_protocol = zone_remove_subparsers.add_parser(
"protocol", help="Remove protocol")
grp_zone_remove_protocol.set_defaults(item="protocol")
grp_zone_remove_protocol.add_argument("protocol", metavar="<protocol>",
nargs="+")
# zone.remove.source-port
grp_zone_remove_source_port = zone_remove_subparsers.add_parser(
"source-port", help="Remove source port")
grp_zone_remove_source_port.set_defaults(item="source-port")
grp_zone_remove_source_port.add_argument("port", metavar="<source-port>",
nargs="+")
# zone.remove.rich-rule
grp_zone_remove_rich_rule = zone_remove_subparsers.add_parser(
"rich-rule", help="Remove rich rule")
grp_zone_remove_rich_rule.set_defaults(item="rich-rule", required=True)
grp_zone_remove_rich_rule.add_argument("rich_rule", metavar="<rich-rule>",
nargs="+")
# zone.remove.masquerade
grp_zone_remove_masquerade = zone_remove_subparsers.add_parser(
"masquerade", help="Add masquerade")
grp_zone_remove_masquerade.set_defaults(item="masquerade", required=True)
# zone.remove.forward-port
grp_zone_remove_forward_port = zone_remove_subparsers.add_parser(
"forward-port", help="Remove forward port")
grp_zone_remove_forward_port.set_defaults(item="forward-port")
grp_zone_remove_forward_port.add_argument("forward_port",
metavar="<forward-port>", nargs="+")
# zone.remove.icmp-block
grp_zone_remove_icmp_block = zone_remove_subparsers.add_parser(
"icmp-block", help="Remove icmp block")
grp_zone_remove_icmp_block.set_defaults(item="icmp-block")
grp_zone_remove_icmp_block.add_argument("icmp_block", metavar="<icmp-block>",
nargs="+")
# zone.remove.icmp-block-inversion
grp_zone_remove_icmp_block_inversion = zone_remove_subparsers.add_parser(
"icmp-block-inversion", help="Remove icmp block inversion")
grp_zone_remove_icmp_block_inversion.set_defaults(item="icmp-block-inversion")
# zone.query
grp_zone_query = zone_subparsers.add_parser("query", help="Query commands")
grp_zone_query.set_defaults(action="query")
zone_query_subparsers = grp_zone_query.add_subparsers()
# zone.query.interface
grp_zone_query_interface = zone_query_subparsers.add_parser(
"interface", help="Query interface")
grp_zone_query_interface.set_defaults(item="interface")
grp_zone_query_interface.add_argument("interface", metavar="<interface>",
nargs="+")
# zone.query.source
grp_zone_query_source = zone_query_subparsers.add_parser("source",
help="Query source")
grp_zone_query_source.set_defaults(item="source")
grp_zone_query_source.add_argument("source", metavar="<source>", nargs="+")
# zone.query.service
grp_zone_query_service = zone_query_subparsers.add_parser("service",
help="Query service")
grp_zone_query_service.set_defaults(item="service")
grp_zone_query_service.add_argument("service", metavar="<service>", nargs="+")
# zone.query.port
grp_zone_query_port = zone_query_subparsers.add_parser("port",
help="Query port")
grp_zone_query_port.set_defaults(item="port")
grp_zone_query_port.add_argument("port", metavar="<port>", nargs="+")
# zone.query.protocol
grp_zone_query_protocol = zone_query_subparsers.add_parser(
"protocol", help="Query protocol")
grp_zone_query_protocol.set_defaults(item="protocol")
grp_zone_query_protocol.add_argument("protocol", metavar="<protocol>",
nargs="+")
# zone.query.source-port
grp_zone_query_source_port = zone_query_subparsers.add_parser(
"source-port", help="Query source port")
grp_zone_query_source_port.set_defaults(item="source-port")
grp_zone_query_source_port.add_argument("port", metavar="<source-port>",
nargs="+")
# zone.query.rich-rule
grp_zone_query_rich_rule = zone_query_subparsers.add_parser(
"rich-rule", help="Query rich rule")
grp_zone_query_rich_rule.set_defaults(item="rich-rule")
grp_zone_query_rich_rule.add_argument("rich_rule", metavar="<rich-rule>",
nargs="+")
# zone.query.masquerade
grp_zone_query_masquerade = zone_query_subparsers.add_parser(
"masquerade", help="Query masquerade")
grp_zone_query_masquerade.set_defaults(item="masquerade")
# zone.query.forward-port
grp_zone_query_forward_port = zone_query_subparsers.add_parser(
"forward-port", help="Query forward port")
grp_zone_query_forward_port.set_defaults(item="forward-port")
grp_zone_query_forward_port.add_argument("forward_port",
metavar="<forward-port>", nargs="+")
# zone.query.icmp-block
grp_zone_query_icmp_block = zone_query_subparsers.add_parser(
"icmp-block", help="Query icmp block")
grp_zone_query_icmp_block.set_defaults(item="icmp-block")
grp_zone_query_icmp_block.add_argument("icmp_block", metavar="<icmp-block>",
nargs="+")
# zone.query.icmp-block-inversion
grp_zone_query_icmp_block_inversion = zone_query_subparsers.add_parser(
"icmp-block-inversion", help="Query icmp block inversion")
grp_zone_query_icmp_block_inversion.set_defaults(item="icmp-block-inversion")
# zone.list
grp_zone_list = zone_subparsers.add_parser("list", help="List commands")
grp_zone_list.set_defaults(action="list")
zone_list_subparsers = grp_zone_list.add_subparsers()
# zone.list.interfaces
grp_zone_list_interfaces = zone_list_subparsers.add_parser(
"interfaces", help="List interfaces")
grp_zone_list_interfaces.set_defaults(item="interfaces")
# zone.list.sources
grp_zone_list_sources = zone_list_subparsers.add_parser("sources",
help="List sources")
grp_zone_list_sources.set_defaults(item="sources")
# zone.list.services
grp_zone_list_services = zone_list_subparsers.add_parser("services",
help="List services")
grp_zone_list_services.set_defaults(item="services")
# zone.list.ports
grp_zone_list_ports = zone_list_subparsers.add_parser("ports",
help="List ports")
grp_zone_list_ports.set_defaults(item="ports")
# zone.list.protocols
grp_zone_list_protocols = zone_list_subparsers.add_parser("protocols",
help="List protocols")
grp_zone_list_protocols.set_defaults(item="protocols")
# zone.list.source-ports
grp_zone_list_source_ports = zone_list_subparsers.add_parser(
"source-ports", help="List source-ports")
grp_zone_list_source_ports.set_defaults(item="source-ports")
# zone.list.rich-rules
grp_zone_list_rich_rules = zone_list_subparsers.add_parser(
"rich-rules", help="List rich-rules")
grp_zone_list_rich_rules.set_defaults(item="rich-rules")
# zone.list.forward-ports
grp_zone_list_forward_ports = zone_list_subparsers.add_parser(
"forward-ports", help="List forward ports")
grp_zone_list_forward_ports.set_defaults(item="forward-ports")
# zone.list.icmp-blocks
grp_zone_list_icmp_blocks = zone_list_subparsers.add_parser(
"icmp-blocks", help="List icmp blocks")
grp_zone_list_icmp_blocks.set_defaults(item="icmp-blocks")
#############################################################################
# service
grp_service = subparsers.add_parser("service", help="Service commands")
grp_service.set_defaults(parser="service")
grp_service.add_argument("service", type=str, action="store",
metavar="<service>")
grp_service.add_argument("-p", "--permanent", action="store_true")
service_subparsers = grp_service.add_subparsers(help="Service Commands")
# service.load_defaults
grp_service_load_defaults = service_subparsers.add_parser("load-defaults",
help="Load defaults")
grp_service_load_defaults.set_defaults(action="load-defaults")
# service.add
grp_service_add = service_subparsers.add_parser("add", help="Add commands")
grp_service_add.set_defaults(action="add")
service_add_subparsers = grp_service_add.add_subparsers()
# service.add.port
grp_service_add_port = service_add_subparsers.add_parser("port",
help="Add port")
grp_service_add_port.set_defaults(item="port")
grp_service_add_port.add_argument("port", metavar="<port>", nargs="+")
# service.add.protocol
grp_service_add_protocol = service_add_subparsers.add_parser(
"protocol", help="Add protocol")
grp_service_add_protocol.set_defaults(item="protocol")
grp_service_add_protocol.add_argument("protocol", metavar="<protocol>",
nargs="+")
# service.add.source-port
grp_service_add_source_port = service_add_subparsers.add_parser(
"source-port", help="Add source port")
grp_service_add_source_port.set_defaults(item="source-port")
grp_service_add_source_port.add_argument("port", metavar="<source-port>",
nargs="+")
# service.add.module
grp_service_add_module = service_add_subparsers.add_parser("module",
help="Add module")
grp_service_add_module.set_defaults(item="module")
grp_service_add_module.add_argument("module", metavar="<module>", nargs="+")
# service.add.destination
grp_service_add_destination = service_add_subparsers.add_parser(
"destination", help="Add destination")
grp_service_add_destination.set_defaults(item="destination")
grp_service_add_destination.add_argument("destination",
metavar="<destination>", nargs="+")
# service.get
grp_service_get = service_subparsers.add_parser("get", help="Get commands")
grp_service_get.set_defaults(action="get")
service_get_subparsers = grp_service_get.add_subparsers()
# service.get.description
grp_service_get_description = service_get_subparsers.add_parser(
"description", help="Get description")
grp_service_get_description.set_defaults(item="description")
# service.get.short
grp_service_get_short = service_get_subparsers.add_parser(
"short", help="Get short")
grp_service_get_short.set_defaults(item="short")
# service.set
grp_service_set = service_subparsers.add_parser("set", help="Set commands")
grp_service_set.set_defaults(action="set")
service_set_subparsers = grp_service_set.add_subparsers()
# service.set.description
grp_service_set_description = service_set_subparsers.add_parser(
"description", help="Set description")
grp_service_set_description.set_defaults(item="description")
grp_service_set_description.add_argument("description", metavar="<description>")
# service.set.short
grp_service_set_short = service_set_subparsers.add_parser(
"short", help="Set short")
grp_service_set_short.set_defaults(item="short")
grp_service_set_short.add_argument("short", metavar="<short>")
# service.remove
grp_service_remove = service_subparsers.add_parser("remove",
help="Remove commands")
grp_service_remove.set_defaults(action="remove")
service_remove_subparsers = grp_service_remove.add_subparsers()
# service.remove.port
grp_service_remove_port = service_remove_subparsers.add_parser(
"port", help="Remove port")
grp_service_remove_port.set_defaults(item="port")
grp_service_remove_port.add_argument("port", metavar="<port>", nargs="+")
# service.remove.protocol
grp_service_remove_protocol = service_remove_subparsers.add_parser(
"protocol", help="Remove protocol")
grp_service_remove_protocol.set_defaults(item="protocol")
grp_service_remove_protocol.add_argument("protocol", metavar="<protocol>",
nargs="+")
# service.remove.source-port
grp_service_remove_source_port = service_remove_subparsers.add_parser(
"source-port", help="Remove source port")
grp_service_remove_source_port.set_defaults(item="source-port")
grp_service_remove_source_port.add_argument("port", metavar="<source-port>",
nargs="+")
# service.remove.module
grp_service_remove_module = service_remove_subparsers.add_parser(
"module", help="Remove module")
grp_service_remove_module.set_defaults(item="module")
grp_service_remove_module.add_argument("module", metavar="<module>", nargs="+")
# service.remove.destination
grp_service_remove_destination = service_remove_subparsers.add_parser(
"destination", help="Remove destination")
grp_service_remove_destination.set_defaults(item="destination")
grp_service_remove_destination.add_argument("destination",
metavar="<destination>", nargs="+")
# service.query
grp_service_query = service_subparsers.add_parser("query",
help="Query commands")
grp_service_query.set_defaults(action="query")
service_query_subparsers = grp_service_query.add_subparsers()
# service.query.port
grp_service_query_port = service_query_subparsers.add_parser("port",
help="Query port")
grp_service_query_port.set_defaults(item="port")
grp_service_query_port.add_argument("port", metavar="<port>", nargs="+")
# service.query.protocol
grp_service_query_protocol = service_query_subparsers.add_parser(
"protocol", help="Query protocol")
grp_service_query_protocol.set_defaults(item="protocol")
grp_service_query_protocol.add_argument("protocol", metavar="<protocol>",
nargs="+")
# service.query.source-port
grp_service_query_source_port = service_query_subparsers.add_parser(
"source-port", help="Query source port")
grp_service_query_source_port.set_defaults(item="source-port")
grp_service_query_source_port.add_argument("port", metavar="<source-port>",
nargs="+")
# service.query.module
grp_service_query_module = service_query_subparsers.add_parser(
"module", help="Query module")
grp_service_query_module.set_defaults(item="module")
grp_service_query_module.add_argument("module", metavar="<module>", nargs="+")
# service.query.destination
grp_service_query_destination = service_query_subparsers.add_parser(
"destination", help="Query destination")
grp_service_query_destination.set_defaults(item="destination")
grp_service_query_destination.add_argument("destination",
metavar="<destination>", nargs="+")
# service.list
grp_service_list = service_subparsers.add_parser("list", help="List commands")
grp_service_list.set_defaults(action="list")
service_list_subparsers = grp_service_list.add_subparsers()
# service.list.services
grp_service_list_services = service_list_subparsers.add_parser(
"services", help="List services")
grp_service_list_services.set_defaults(item="services")
# service.list.ports
grp_service_list_ports = service_list_subparsers.add_parser("ports",
help="List ports")
grp_service_list_ports.set_defaults(item="ports")
# service.list.protocols
grp_service_list_protocols = service_list_subparsers.add_parser(
"protocols", help="List protocols")
grp_service_list_protocols.set_defaults(item="protocols")
# service.list.source-ports
grp_service_list_source_ports = service_list_subparsers.add_parser(
"source-ports", help="List source-ports")
grp_service_list_source_ports.set_defaults(item="source-ports")
# service.list.modules
grp_service_list_modules = service_list_subparsers.add_parser(
"modules", help="List modules")
grp_service_list_modules.set_defaults(item="modules")
# service.list.destinations
grp_service_list_destinations = service_list_subparsers.add_parser(
"destinations", help="List destinations")
grp_service_list_destinations.set_defaults(item="destinations")
#############################################################################
# ipset
grp_ipset = subparsers.add_parser("ipset", help="Ipset commands")
grp_ipset.set_defaults(parser="ipset")
grp_ipset.add_argument("ipset", type=str, action="store", metavar="<ipset>")
grp_ipset.add_argument("-p", "--permanent", action="store_true")
ipset_subparsers = grp_ipset.add_subparsers(help="Ipset Commands")
# ipset.load_defaults
grp_ipset_load_defaults = ipset_subparsers.add_parser("load-defaults",
help="Load defaults")
grp_ipset_load_defaults.set_defaults(action="load-defaults")
# ipset.add
grp_ipset_add = ipset_subparsers.add_parser("add", help="Add commands")
grp_ipset_add.set_defaults(action="add")
ipset_add_subparsers = grp_ipset_add.add_subparsers()
# ipset.add.entry
grp_ipset_add_entry = ipset_add_subparsers.add_parser("entry", help="Add entry")
grp_ipset_add_entry.set_defaults(item="entry")
grp_ipset_add_entry.add_argument("entry", metavar="<entry>", nargs="+")
# ipset.add.entries-from-file
grp_ipset_add_entries_from_file = ipset_add_subparsers.add_parser(
"entries-from-file", help="Add entries from file")
grp_ipset_add_entries_from_file.set_defaults(item="entries-from-file")
grp_ipset_add_entries_from_file.add_argument("entries_from_file",
metavar="<filename>", nargs="+")
# ipset.get
grp_ipset_get = ipset_subparsers.add_parser("get", help="Get commands")
grp_ipset_get.set_defaults(action="get")
ipset_get_subparsers = grp_ipset_get.add_subparsers()
# ipset.get.description
grp_ipset_get_description = ipset_get_subparsers.add_parser(
"description", help="Get description")
grp_ipset_get_description.set_defaults(item="description")
# ipset.get.short
grp_ipset_get_short = ipset_get_subparsers.add_parser("short", help="Get short")
grp_ipset_get_short.set_defaults(item="short")
# ipset.set
grp_ipset_set = ipset_subparsers.add_parser("set", help="Set commands")
grp_ipset_set.set_defaults(action="set")
ipset_set_subparsers = grp_ipset_set.add_subparsers()
# ipset.set.description
grp_ipset_set_description = ipset_set_subparsers.add_parser(
"description", help="Set description")
grp_ipset_set_description.set_defaults(item="description")
grp_ipset_set_description.add_argument("description", metavar="<description>")
# ipset.set.short
grp_ipset_set_short = ipset_set_subparsers.add_parser("short", help="Set short")
grp_ipset_set_short.set_defaults(item="short")
grp_ipset_set_short.add_argument("short", metavar="<short>")
# ipset.remove
grp_ipset_remove = ipset_subparsers.add_parser("remove", help="Remove commands")
grp_ipset_remove.set_defaults(action="remove")
ipset_remove_subparsers = grp_ipset_remove.add_subparsers()
# ipset.remove.entry
grp_ipset_remove_entry = ipset_remove_subparsers.add_parser("entry",
help="Remove entry")
grp_ipset_remove_entry.set_defaults(item="entry")
grp_ipset_remove_entry.add_argument("entry", metavar="<entry>", nargs="+")
# ipset.remove.entries-from-file
grp_ipset_remove_entries_from_file = ipset_remove_subparsers.add_parser(
"entries-from-file", help="Remove entries from file")
grp_ipset_remove_entries_from_file.set_defaults(item="entries-from-file")
grp_ipset_remove_entries_from_file.add_argument("entries_from_file",
metavar="<filename>", nargs="+")
# ipset.remove.all
grp_ipset_remove_all = ipset_remove_subparsers.add_parser(
"all", help="Remove all entries")
grp_ipset_remove_all.set_defaults(item="all")
# ipset.query
grp_ipset_query = ipset_subparsers.add_parser("query", help="Query commands")
grp_ipset_query.set_defaults(action="query")
ipset_query_subparsers = grp_ipset_query.add_subparsers()
# ipset.query.entry
grp_ipset_query_entry = ipset_query_subparsers.add_parser("entry",
help="Query entry")
grp_ipset_query_entry.set_defaults(item="entry")
grp_ipset_query_entry.add_argument("entry", metavar="<entry>", nargs="+")
# ipset.query.entries-from-file
grp_ipset_query_entries_from_file = ipset_query_subparsers.add_parser(
"entries-from-file", help="Query entries from file")
grp_ipset_query_entries_from_file.set_defaults(item="entries-from-file")
grp_ipset_query_entries_from_file.add_argument("entries_from_file",
metavar="<filename>", nargs="+")
# ipset.list
grp_ipset_list = ipset_subparsers.add_parser("list", help="List commands")
grp_ipset_list.set_defaults(action="list")
ipset_list_subparsers = grp_ipset_list.add_subparsers()
# ipset.list.entries
grp_ipset_list_entries = ipset_list_subparsers.add_parser("entries",
help="List entries")
grp_ipset_list_entries.set_defaults(item="entries")
#############################################################################
# icmptype
grp_icmptype = subparsers.add_parser("icmptype", help="Icmptype commands")
grp_icmptype.set_defaults(parser="icmptype")
grp_icmptype.add_argument("icmptype", type=str, action="store",
metavar="<icmptype>")
grp_icmptype.add_argument("-p", "--permanent", action="store_true")
icmptype_subparsers = grp_icmptype.add_subparsers(help="Icmptype Commands")
# icmptype.load_defaults
grp_icmptype_load_defaults = icmptype_subparsers.add_parser(
"load-defaults", help="Load defaults")
grp_icmptype_load_defaults.set_defaults(action="load-defaults")
# icmptype.add
grp_icmptype_add = icmptype_subparsers.add_parser("add", help="Add commands")
grp_icmptype_add.set_defaults(action="add")
icmptype_add_subparsers = grp_icmptype_add.add_subparsers()
# icmptype.add.destination
grp_icmptype_add_destination = icmptype_add_subparsers.add_parser(
"destination", help="Add destination")
grp_icmptype_add_destination.set_defaults(item="destination")
grp_icmptype_add_destination.add_argument("destination",
metavar="<destination>", nargs="+")
# icmptype.remove
grp_icmptype_remove = icmptype_subparsers.add_parser("remove",
help="Remove commands")
grp_icmptype_remove.set_defaults(action="remove")
icmptype_remove_subparsers = grp_icmptype_remove.add_subparsers()
# icmptype.remove.destination
grp_icmptype_remove_destination = icmptype_remove_subparsers.add_parser(
"destination", help="Remove destination")
grp_icmptype_remove_destination.set_defaults(item="destination")
grp_icmptype_remove_destination.add_argument("destination",
metavar="<destination>", nargs="+")
# icmptype.get
grp_icmptype_get = icmptype_subparsers.add_parser("get", help="Get commands")
grp_icmptype_get.set_defaults(action="get")
icmptype_get_subparsers = grp_icmptype_get.add_subparsers()
# icmptype.get.description
grp_icmptype_get_description = icmptype_get_subparsers.add_parser(
"description", help="Get description")
grp_icmptype_get_description.set_defaults(item="description")
# icmptype.get.short
grp_icmptype_get_short = icmptype_get_subparsers.add_parser(
"short", help="Get short")
grp_icmptype_get_short.set_defaults(item="short")
# icmptype.set
grp_icmptype_set = icmptype_subparsers.add_parser("set", help="Set commands")
grp_icmptype_set.set_defaults(action="set")
icmptype_set_subparsers = grp_icmptype_set.add_subparsers()
# icmptype.set.description
grp_icmptype_set_description = icmptype_set_subparsers.add_parser(
"description", help="Set description")
grp_icmptype_set_description.set_defaults(item="description")
grp_icmptype_set_description.add_argument("description", metavar="<description>")
# icmptype.set.short
grp_icmptype_set_short = icmptype_set_subparsers.add_parser(
"short", help="Set short")
grp_icmptype_set_short.set_defaults(item="short")
grp_icmptype_set_short.add_argument("short", metavar="<short>")
# icmptype.query
grp_icmptype_query = icmptype_subparsers.add_parser("query",
help="Query commands")
grp_icmptype_query.set_defaults(action="query")
icmptype_query_subparsers = grp_icmptype_query.add_subparsers()
# icmptype.query.destination
grp_icmptype_query_destination = icmptype_query_subparsers.add_parser(
"destination", help="Query destination")
grp_icmptype_query_destination.set_defaults(item="destination")
grp_icmptype_query_destination.add_argument("destination",
metavar="<destination>", nargs="+")
# icmptype.list
grp_icmptype_list = icmptype_subparsers.add_parser("list", help="List commands")
grp_icmptype_list.set_defaults(action="list")
icmptype_list_subparsers = grp_icmptype_list.add_subparsers()
# icmptype.list.destinations
grp_icmptype_list_destinations = icmptype_list_subparsers.add_parser(
"destinations", help="List destinations")
grp_icmptype_list_destinations.set_defaults(item="destinations")
#############################################################################
# new
grp_new = subparsers.add_parser("new", help="New commands")
grp_new.set_defaults(parser="new")
grp_new.add_argument("-p", "--permanent", action="store_true")
new_subparsers = grp_new.add_subparsers(help="New Commands")
# new.zone
grp_new_zone = new_subparsers.add_parser("zone", help="New zone")
grp_new_zone.set_defaults(action="zone")
grp_new_zone.add_argument("-n", "--name", metavar="<name>")
grp_new_zone.add_argument("-f", "--filename", metavar="<filename>")
# new.service
grp_new_service = new_subparsers.add_parser("service", help="New service")
grp_new_service.set_defaults(action="service")
grp_new_service.add_argument("-n", "--name", metavar="<name>")
grp_new_service.add_argument("-f", "--filename", metavar="<filename>")
# new.ipset
grp_new_ipset = new_subparsers.add_parser("ipset", help="New ipset")
grp_new_ipset.set_defaults(action="ipset")
grp_new_ipset.add_argument("-n", "--name", metavar="<name>")
grp_new_ipset.add_argument("-f", "--filename", metavar="<filename>")
grp_new_ipset.add_argument("-t", "--type", metavar="<ipsettype>")
grp_new_ipset.add_argument("-o", "--option", metavar="<key>[=<value>]",
nargs="*")
#--type=<ipset type> [--option=<key>[=<value>]]..
# new.icmptype
grp_new_icmptype = new_subparsers.add_parser("icmptype", help="New icmptype")
grp_new_icmptype.set_defaults(action="icmptype")
grp_new_icmptype.add_argument("-n", "--name", metavar="<name>")
grp_new_icmptype.add_argument("-f", "--filename", metavar="<filename>")
#############################################################################
# helper
grp_helper = subparsers.add_parser("helper", help="Helper commands")
grp_helper.set_defaults(parser="helper")
grp_helper.add_argument("helper", type=str, action="store",
metavar="<helper>")
grp_helper.add_argument("-p", "--permanent", action="store_true")
helper_subparsers = grp_helper.add_subparsers(help="Helper Commands")
# helper.load_defaults
grp_helper_load_defaults = helper_subparsers.add_parser(
"load-defaults", help="Load defaults")
grp_helper_load_defaults.set_defaults(action="load-defaults")
# helper.add
grp_helper_add = helper_subparsers.add_parser("add", help="Add commands")
grp_helper_add.set_defaults(action="add")
helper_add_subparsers = grp_helper_add.add_subparsers()
# helper.add.port
grp_helper_add_port = helper_add_subparsers.add_parser("port",
help="Add port")
grp_helper_add_port.set_defaults(item="port")
grp_helper_add_port.add_argument("port", metavar="<port>", nargs="+")
# helper.remove
grp_helper_remove = helper_subparsers.add_parser("remove",
help="Remove commands")
grp_helper_remove.set_defaults(action="remove")
helper_remove_subparsers = grp_helper_remove.add_subparsers()
# helper.remove.port
grp_helper_remove_port = helper_remove_subparsers.add_parser(
"port", help="Remove port")
grp_helper_remove_port.set_defaults(item="port")
grp_helper_remove_port.add_argument("port", metavar="<port>", nargs="+")
# helper.get
grp_helper_get = helper_subparsers.add_parser("get", help="Get commands")
grp_helper_get.set_defaults(action="get")
helper_get_subparsers = grp_helper_get.add_subparsers()
# helper.get.description
grp_helper_get_description = helper_get_subparsers.add_parser(
"description", help="Get description")
grp_helper_get_description.set_defaults(item="description")
# helper.get.family
grp_helper_get_family = helper_get_subparsers.add_parser(
"family", help="Get family")
grp_helper_get_family.set_defaults(item="family")
# helper.get.module
grp_helper_get_module = helper_get_subparsers.add_parser(
"module", help="Get module")
grp_helper_get_module.set_defaults(item="module")
# helper.get.short
grp_helper_get_short = helper_get_subparsers.add_parser(
"short", help="Get short")
grp_helper_get_short.set_defaults(item="short")
# helper.set
grp_helper_set = helper_subparsers.add_parser("set", help="Set commands")
grp_helper_set.set_defaults(action="set")
helper_set_subparsers = grp_helper_set.add_subparsers()
# helper.set.description
grp_helper_set_description = helper_set_subparsers.add_parser(
"description", help="Set description")
grp_helper_set_description.set_defaults(item="description")
grp_helper_set_description.add_argument("description", metavar="<description>")
# helper.set.family
grp_helper_set_family = helper_set_subparsers.add_parser(
"family", help="Set family")
grp_helper_set_family.set_defaults(item="family")
grp_helper_set_family.add_argument("family", metavar="<family>")
# helper.set.module
grp_helper_set_module = helper_set_subparsers.add_parser(
"module", help="Set module")
grp_helper_set_module.set_defaults(item="module")
grp_helper_set_module.add_argument("module", metavar="<module>")
# helper.set.short
grp_helper_set_short = helper_set_subparsers.add_parser(
"short", help="Set short")
grp_helper_set_short.set_defaults(item="short")
grp_helper_set_short.add_argument("short", metavar="<short>")
# helper.query
grp_helper_query = helper_subparsers.add_parser("query",
help="Query commands")
grp_helper_query.set_defaults(action="query")
helper_query_subparsers = grp_helper_query.add_subparsers()
# helper.query.port
grp_helper_query_port = helper_query_subparsers.add_parser("port",
help="Query port")
grp_helper_query_port.set_defaults(item="port")
grp_helper_query_port.add_argument("port", metavar="<port>", nargs="+")
# helper.list
grp_helper_list = helper_subparsers.add_parser("list", help="List commands")
grp_helper_list.set_defaults(action="list")
helper_list_subparsers = grp_helper_list.add_subparsers()
# helper.list.ports
grp_helper_list_ports = helper_list_subparsers.add_parser("ports",
help="List ports")
grp_helper_list_ports.set_defaults(item="ports")
#############################################################################
# new
grp_new = subparsers.add_parser("new", help="New commands")
grp_new.set_defaults(parser="new")
grp_new.add_argument("-p", "--permanent", action="store_true")
new_subparsers = grp_new.add_subparsers(help="New Commands")
# new.zone
grp_new_zone = new_subparsers.add_parser("zone", help="New zone")
grp_new_zone.set_defaults(action="zone")
grp_new_zone.add_argument("-n", "--name", metavar="<name>")
grp_new_zone.add_argument("-f", "--filename", metavar="<filename>")
# new.service
grp_new_service = new_subparsers.add_parser("service", help="New service")
grp_new_service.set_defaults(action="service")
grp_new_service.add_argument("-n", "--name", metavar="<name>")
grp_new_service.add_argument("-f", "--filename", metavar="<filename>")
# new.ipset
grp_new_ipset = new_subparsers.add_parser("ipset", help="New ipset")
grp_new_ipset.set_defaults(action="ipset")
grp_new_ipset.add_argument("-n", "--name", metavar="<name>")
grp_new_ipset.add_argument("-f", "--filename", metavar="<filename>")
grp_new_ipset.add_argument("-t", "--type", metavar="<ipsettype>")
grp_new_ipset.add_argument("-o", "--option", metavar="<key>[=<value>]",
nargs="*")
#--type=<ipset type> [--option=<key>[=<value>]]..
# new.helper
grp_new_helper = new_subparsers.add_parser("helper", help="New helper")
grp_new_helper.set_defaults(action="helper")
grp_new_helper.add_argument("-n", "--name", metavar="<name>")
grp_new_helper.add_argument("-f", "--filename", metavar="<filename>")
# new.icmptype
grp_new_icmptype = new_subparsers.add_parser("icmptype", help="New icmptype")
grp_new_icmptype.set_defaults(action="icmptype")
grp_new_icmptype.add_argument("-n", "--name", metavar="<name>")
grp_new_icmptype.add_argument("-f", "--filename", metavar="<filename>")
#############################################################################
# delete
grp_delete = subparsers.add_parser("delete", help="Delete commands")
grp_delete.set_defaults(parser="delete")
grp_delete.add_argument("-p", "--permanent", action="store_true")
delete_subparsers = grp_delete.add_subparsers(help="Delete Commands")
# delete.zone
grp_delete_zone = delete_subparsers.add_parser("zone", help="Delete zone")
grp_delete_zone.set_defaults(action="zone")
grp_delete_zone.add_argument("zone", metavar="<zone>")
# delete.service
grp_delete_service = delete_subparsers.add_parser("service",
help="Delete service")
grp_delete_service.set_defaults(action="service")
grp_delete_service.add_argument("service", metavar="<service>")
# delete.ipset
grp_delete_ipset = delete_subparsers.add_parser("ipset", help="Delete ipset")
grp_delete_ipset.set_defaults(action="ipset")
grp_delete_ipset.add_argument("ipset", metavar="<ipset>")
# delete.helper
grp_delete_helper = delete_subparsers.add_parser("helper",
help="Delete helper")
grp_delete_helper.set_defaults(action="helper")
grp_delete_helper.add_argument("helper", metavar="<helper>")
# delete.icmptype
grp_delete_icmptype = delete_subparsers.add_parser("icmptype",
help="Delete icmptype")
grp_delete_icmptype.set_defaults(action="icmptype")
grp_delete_icmptype.add_argument("icmptype", metavar="<icmptype>")
#############################################################################
# direct
grp_direct = subparsers.add_parser("direct", help="Direct commands")
grp_direct.set_defaults(parser="direct")
grp_direct.add_argument("-p", "--permanent", action="store_true")
direct_subparsers = grp_direct.add_subparsers(help="Direct Commands")
# direct.add
grp_direct_add = direct_subparsers.add_parser("add", help="Add commands")
grp_direct_add.set_defaults(action="add")
direct_add_subparsers = grp_direct_add.add_subparsers()
# direct.add.chain
grp_direct_add_chain = direct_add_subparsers.add_parser("chain",
help="Add chain")
grp_direct_add_chain.set_defaults(item="chain")
grp_direct_add_chain.add_argument(
"chain", nargs=3, metavar=("{ ipv4 | ipv6 | eb }", "<table>", "<chain>"))
# direct.add.rule
grp_direct_add_rule = direct_add_subparsers.add_parser("rule",
help="Add rule")
grp_direct_add_rule.set_defaults(item="rule")
grp_direct_add_rule.add_argument(
"rule", nargs=argparse.REMAINDER,
metavar=("{ ipv4 | ipv6 | eb }", "<table> <chain> <priority> <args>"))
# direct.add.passthrough
grp_direct_add_passthrough = direct_add_subparsers.add_parser(
"passthrough", help="Add passthrough")
grp_direct_add_passthrough.set_defaults(item="passthrough")
grp_direct_add_passthrough.add_argument(
"passthrough", nargs=argparse.REMAINDER,
metavar=("{ ipv4 | ipv6 | eb }", "<args>"))
# direct.passthrough
grp_direct_passthrough = direct_subparsers.add_parser(
"passthrough", help="Untracked passthrough")
grp_direct_passthrough.set_defaults(action="passthrough")
grp_direct_passthrough.add_argument("passthrough", nargs=argparse.REMAINDER,
metavar=("{ ipv4 | ipv6 | eb }", "<args>"))
# direct.query
grp_direct_query = direct_subparsers.add_parser("query", help="Query commands")
grp_direct_query.set_defaults(action="query")
direct_query_subparsers = grp_direct_query.add_subparsers()
# direct.query.chain
grp_direct_query_chain = direct_query_subparsers.add_parser(
"chain", help="Query chain")
grp_direct_query_chain.set_defaults(item="chain")
grp_direct_query_chain.add_argument(
"chain", nargs=3, metavar=("{ ipv4 | ipv6 | eb }", "<table>", "<chain>"))
# direct.query.rule
grp_direct_query_rule = direct_query_subparsers.add_parser(
"rule", help="Query rule")
grp_direct_query_rule.set_defaults(item="rule")
grp_direct_query_rule.add_argument(
"rule", nargs=argparse.REMAINDER,
metavar=("{ ipv4 | ipv6 | eb }", "<table> <chain> <priority> <args>"))
# direct.query.passthrough
grp_direct_query_passthrough = direct_query_subparsers.add_parser(
"passthrough", help="Query passthrough")
grp_direct_query_passthrough.set_defaults(item="passthrough")
grp_direct_query_passthrough.add_argument("passthrough",
metavar="<passthrough>",
nargs=argparse.REMAINDER)
# direct.remove
grp_direct_remove = direct_subparsers.add_parser("remove",
help="Remove commands")
grp_direct_remove.set_defaults(action="remove")
direct_remove_subparsers = grp_direct_remove.add_subparsers()
# direct.remove.chain
grp_direct_remove_chain = direct_remove_subparsers.add_parser(
"chain", help="Remove chain")
grp_direct_remove_chain.set_defaults(item="chain")
grp_direct_remove_chain.add_argument(
"chain", nargs=3, metavar=("{ ipv4 | ipv6 | eb }", "<table>", "<chain>"))
# direct.remove.rule
grp_direct_remove_rule = direct_remove_subparsers.add_parser("rule",
help="Remove rule")
grp_direct_remove_rule.set_defaults(item="rule")
grp_direct_remove_rule.add_argument(
"rule", nargs=argparse.REMAINDER,
metavar=("{ ipv4 | ipv6 | eb }", "<table> <chain> <priority> <args>"))
# direct.remove.passthrough
grp_direct_remove_passthrough = direct_remove_subparsers.add_parser(
"passthrough", help="Remove passthrough")
grp_direct_remove_passthrough.set_defaults(item="passthrough")
grp_direct_remove_passthrough.add_argument("passthrough",
metavar="<passthrough>",
nargs=argparse.REMAINDER)
# direct.get
grp_direct_get = direct_subparsers.add_parser("get", help="Get commands")
grp_direct_get.set_defaults(action="get")
direct_get_subparsers = grp_direct_get.add_subparsers()
# direct.get.all-chains
grp_direct_get_all_chains = direct_get_subparsers.add_parser(
"all-chains", help="Get all chains")
grp_direct_get_all_chains.set_defaults(item="all-chains")
# direct.get.chains
grp_direct_get_chains = direct_get_subparsers.add_parser("chains",
help="Get chains")
grp_direct_get_chains.set_defaults(item="chains")
grp_direct_get_chains.add_argument("chains", nargs=2,
metavar=("{ ipv4 | ipv6 | eb }", "<table>"))
# direct.get.all-rules
grp_direct_get_all_rules = direct_get_subparsers.add_parser(
"all-rules", help="Get all rules")
grp_direct_get_all_rules.set_defaults(item="all-rules")
# direct.get.rules
grp_direct_get_rules = direct_get_subparsers.add_parser("rules",
help="Get rules")
grp_direct_get_rules.set_defaults(item="rules")
grp_direct_get_rules.add_argument("rules", nargs=3,
metavar=("{ ipv4 | ipv6 | eb }",
"<table>", "<chain>"))
# direct.get.all-passthroughs
grp_direct_get_all_passthroughs = direct_get_subparsers.add_parser(
"all-passthroughs", help="Get all passthroughs")
grp_direct_get_all_passthroughs.set_defaults(item="all-passthroughs")
# direct.get.passthroughs
grp_direct_get_passthroughs = direct_get_subparsers.add_parser(
"passthroughs", help="Get passthroughs")
grp_direct_get_passthroughs.set_defaults(item="passthroughs")
grp_direct_get_passthroughs.add_argument("passthroughs", nargs=1,
metavar=("{ ipv4 | ipv6 | eb }"))
#############################################################################
# lockdown
grp_lockdown_whitelist = subparsers.add_parser(
"lockdown-whitelist", help="Lockdown whitelist commands")
grp_lockdown_whitelist.set_defaults(parser="lockdown-whitelist")
grp_lockdown_whitelist.add_argument("-p", "--permanent", action="store_true")
lockdown_whitelist_subparsers = grp_lockdown_whitelist.add_subparsers(
help="Lockdown Commands")
# lockdown.whitelist.add
grp_lockdown_whitelist_add = lockdown_whitelist_subparsers.add_parser(
"add", help="Add commands")
grp_lockdown_whitelist_add.set_defaults(action="add")
whitelist_add_subparsers = grp_lockdown_whitelist_add.add_subparsers()
# lockdown.whitelist.add.command
grp_lockdown_whitelist_add_command = whitelist_add_subparsers.add_parser(
"command", help="Add command")
grp_lockdown_whitelist_add_command.set_defaults(item="command")
grp_lockdown_whitelist_add_command.add_argument("command", metavar="<command>",
nargs="+")
# lockdown.whitelist.add.context
grp_lockdown_whitelist_add_context = whitelist_add_subparsers.add_parser(
"context", help="Add context")
grp_lockdown_whitelist_add_context.set_defaults(item="context")
grp_lockdown_whitelist_add_context.add_argument("context", metavar="<context>",
nargs="+")
# lockdown.whitelist.add.uid
grp_lockdown_whitelist_add_uid = whitelist_add_subparsers.add_parser(
"uid", help="Add uid")
grp_lockdown_whitelist_add_uid.set_defaults(item="uid")
grp_lockdown_whitelist_add_uid.add_argument("uid", metavar="<uid>", type=int,
nargs="+")
# lockdown.whitelist.add.user
grp_lockdown_whitelist_add_user = whitelist_add_subparsers.add_parser(
"user", help="Add user")
grp_lockdown_whitelist_add_user.set_defaults(item="user")
grp_lockdown_whitelist_add_user.add_argument("user", metavar="<user>",
nargs="+")
# lockdown.whitelist.query
grp_lockdown_whitelist_query = lockdown_whitelist_subparsers.add_parser(
"query", help="Query commands")
grp_lockdown_whitelist_query.set_defaults(action="query")
whitelist_query_subparsers = grp_lockdown_whitelist_query.add_subparsers()
# lockdown.whitelist.query.command
grp_lockdown_whitelist_query_command = whitelist_query_subparsers.add_parser(
"command", help="Query command")
grp_lockdown_whitelist_query_command.set_defaults(item="command")
grp_lockdown_whitelist_query_command.add_argument("command",
metavar="<command>",
nargs="+")
# lockdown.whitelist.query.context
grp_lockdown_whitelist_query_context = whitelist_query_subparsers.add_parser(
"context", help="Query context")
grp_lockdown_whitelist_query_context.set_defaults(item="context")
grp_lockdown_whitelist_query_context.add_argument("context",
metavar="<context>",
nargs="+")
# lockdown.whitelist.query.uid
grp_lockdown_whitelist_query_uid = whitelist_query_subparsers.add_parser(
"uid", help="Query uid")
grp_lockdown_whitelist_query_uid.set_defaults(item="uid")
grp_lockdown_whitelist_query_uid.add_argument("uid", metavar="<uid>", type=int,
nargs="+")
# lockdown.whitelist.query.user
grp_lockdown_whitelist_query_user = whitelist_query_subparsers.add_parser(
"user", help="Query user")
grp_lockdown_whitelist_query_user.set_defaults(item="user")
grp_lockdown_whitelist_query_user.add_argument("user", metavar="<user>",
nargs="+")
# lockdown.whitelist.remove
grp_lockdown_whitelist_remove = lockdown_whitelist_subparsers.add_parser(
"remove", help="Remove commands")
grp_lockdown_whitelist_remove.set_defaults(action="remove")
whitelist_remove_subparsers = grp_lockdown_whitelist_remove.add_subparsers()
# lockdown.whitelist.remove.command
grp_lockdown_whitelist_remove_command = whitelist_remove_subparsers.add_parser(
"command", help="Remove command")
grp_lockdown_whitelist_remove_command.set_defaults(item="command")
grp_lockdown_whitelist_remove_command.add_argument("command",
metavar="<command>",
nargs="+")
# lockdown.whitelist.remove.context
grp_lockdown_whitelist_remove_context = whitelist_remove_subparsers.add_parser(
"context", help="Remove context")
grp_lockdown_whitelist_remove_context.set_defaults(item="context")
grp_lockdown_whitelist_remove_context.add_argument("context",
metavar="<context>",
nargs="+")
# lockdown.whitelist.remove.uid
grp_lockdown_whitelist_remove_uid = whitelist_remove_subparsers.add_parser(
"uid", help="Remove uid")
grp_lockdown_whitelist_remove_uid.set_defaults(item="uid")
grp_lockdown_whitelist_remove_uid.add_argument("uid", metavar="<uid>", type=int,
nargs="+")
# lockdown.whitelist.remove.user
grp_lockdown_whitelist_remove_user = whitelist_remove_subparsers.add_parser(
"user", help="Remove user")
grp_lockdown_whitelist_remove_user.set_defaults(item="user")
grp_lockdown_whitelist_remove_user.add_argument("user", metavar="<user>",
nargs="+")
# lockdown.whitelist.list
grp_lockdown_whitelist_list = lockdown_whitelist_subparsers.add_parser(
"list", help="List commands")
grp_lockdown_whitelist_list.set_defaults(action="list")
whitelist_list_subparsers = grp_lockdown_whitelist_list.add_subparsers()
# lockdown.whitelist.list.commands
grp_lockdown_whitelist_list_commands = whitelist_list_subparsers.add_parser(
"commands", help="List commands")
grp_lockdown_whitelist_list_commands.set_defaults(item="commands")
# lockdown.whitelist.list.contexts
grp_lockdown_whitelist_list_contexts = whitelist_list_subparsers.add_parser(
"contexts", help="List contexts")
grp_lockdown_whitelist_list_contexts.set_defaults(item="contexts")
# lockdown.whitelist.list.uids
grp_lockdown_whitelist_list_uids = whitelist_list_subparsers.add_parser(
"uids", help="List uids")
grp_lockdown_whitelist_list_uids.set_defaults(item="uids")
# lockdown.whitelist.list.users
grp_lockdown_whitelist_list_users = whitelist_list_subparsers.add_parser(
"users", help="List users")
grp_lockdown_whitelist_list_users.set_defaults(item="users")
#############################################################################
# config
grp_config = subparsers.add_parser("config", help="firewalld configuration")
grp_config.set_defaults(parser="config")
config_subparsers = grp_config.add_subparsers(help="Config Commands")
# config.get
grp_config_get = config_subparsers.add_parser("get", help="Get commands")
grp_config_get.set_defaults(action="get")
config_get_subparsers = grp_config_get.add_subparsers()
# config.get.default-zone
grp_config_get_default_zone = config_get_subparsers.add_parser(
"default-zone", help="Get default zone")
grp_config_get_default_zone.set_defaults(item="default-zone")
# config.get.lockdown
grp_config_get_lockdown = config_get_subparsers.add_parser("lockdown",
help="Get lockdown")
grp_config_get_lockdown.set_defaults(item="lockdown")
# config.get.log-denied
grp_config_get_log_denied = config_get_subparsers.add_parser(
"log-denied", help="Get log denied")
grp_config_get_log_denied.set_defaults(item="log-denied")
# config.get.panic
grp_config_get_panic = config_get_subparsers.add_parser("panic",
help="Get panic")
grp_config_get_panic.set_defaults(item="panic")
# config.list
grp_config_list = config_subparsers.add_parser("list", help="List commands")
grp_config_list.set_defaults(action="list")
# config.set
grp_config_set = config_subparsers.add_parser("set", help="Set commands")
grp_config_set.set_defaults(action="set")
config_set_subparsers = grp_config_set.add_subparsers()
# config.set.default-zone
grp_config_set_default_zone = config_set_subparsers.add_parser(
"default-zone", help="Set default zone")
grp_config_set_default_zone.set_defaults(item="default-zone")
grp_config_set_default_zone.add_argument("default_zone", metavar="<zone>")
# config.set.lockdown
grp_config_set_lockdown = config_set_subparsers.add_parser("lockdown",
help="Set lockdown")
grp_config_set_lockdown.set_defaults(item="lockdown")
grp_config_set_lockdown.add_argument("lockdown", metavar="<lockdown>")
# config.set.log-denied
grp_config_set_log_denied = config_set_subparsers.add_parser(
"log-denied", help="Set log denied")
grp_config_set_log_denied.set_defaults(item="log-denied")
grp_config_set_log_denied.add_argument("log_denied", metavar="<log-denied>")
# config.set.panic
grp_config_set_panic = config_set_subparsers.add_parser("panic",
help="Set panic")
grp_config_set_panic.set_defaults(item="panic")
grp_config_set_panic.add_argument("panic", metavar="<panic>")
#############################################################################
# settings
grp_settings = subparsers.add_parser("settings", help="firewalld settings")
grp_settings.set_defaults(parser="settings")
settings_subparsers = grp_settings.add_subparsers(help="Settings Commands")
# settings.get
grp_settings_get = settings_subparsers.add_parser("get", help="Get commands")
grp_settings_get.set_defaults(action="get")
settings_get_subparsers = grp_settings_get.add_subparsers()
# settings.get.BRIDGE
grp_settings_get_BRIDGE = settings_get_subparsers.add_parser(
"BRIDGE", help="Get BRIDGE")
grp_settings_get_BRIDGE.set_defaults(item="BRIDGE")
# settings.get.CleanupOnExit
grp_settings_get_CleanupOnExit = settings_get_subparsers.add_parser(
"CleanupOnExit", help="Get CleanupOnExit")
grp_settings_get_CleanupOnExit.set_defaults(item="CleanupOnExit")
# settings.get.IPSet
grp_settings_get_IPSet = settings_get_subparsers.add_parser(
"IPSet", help="Get IPSet")
grp_settings_get_IPSet.set_defaults(item="IPSet")
# settings.get.IPSetTypes
grp_settings_get_IPSetTypes = settings_get_subparsers.add_parser(
"IPSetTypes", help="Get IPSetTypes")
grp_settings_get_IPSetTypes.set_defaults(item="IPSetTypes")
# settings.get.IPv4
grp_settings_get_IPv4 = settings_get_subparsers.add_parser(
"IPv4", help="Get IPv4")
grp_settings_get_IPv4.set_defaults(item="IPv4")
# settings.get.IPv6
grp_settings_get_IPv6 = settings_get_subparsers.add_parser(
"IPv6", help="Get IPv6")
grp_settings_get_IPv6.set_defaults(item="IPv6")
# settings.get.IPv6_rpfilter
grp_settings_get_IPv6_rpfilter = settings_get_subparsers.add_parser(
"IPv6_rpfilter", help="Get IPv6_rpfilter")
grp_settings_get_IPv6_rpfilter.set_defaults(item="IPv6_rpfilter")
# settings.get.MinimalMark
grp_settings_get_MinimalMark = settings_get_subparsers.add_parser(
"MinimalMark", help="Get MinimalMark")
grp_settings_get_MinimalMark.set_defaults(item="MinimalMark")
# settings.list
grp_settings_list = settings_subparsers.add_parser("list", help="List commands")
grp_settings_list.set_defaults(action="list")
#############################################################################
args = sys.argv[1:]
if len(args) > 1 and args[0] == "direct":
i = -1
if (len(args) > 1 and args[1] == 'passthrough') or \
(len(args) > 2 and args[2] == 'passthrough') or \
(len(args) > 3 and args[3] == 'passthrough'):
i = args.index('passthrough') + 1
elif (len(args) > 2 and args[2] == 'rule') or \
(len(args) > 3 and args[3] == 'rule'):
i = args.index('rule') + 4
# join <args> into one argument to prevent parser from parsing each iptables
# option, because they ccould conflict with firewallctl options
if (i > -1) and (i < len(args) - 1):
aux_args = args[:]
args = aux_args[:i+1] # all but not <args>
args.append(joinArgs(aux_args[i+1:])) # add <args> as one arg
args = parser.parse_args(args)
if not hasattr(args, "parser"):
parser.print_help()
sys.exit(0)
# Set quiet and verbose
cmd = FirewallCommand(args.quiet, args.verbose)
def myexcepthook(exctype, value, traceback):
cmd.exception_handler(str(value))
sys.excepthook = myexcepthook
# use firewalld
try:
fw = FirewallClient()
except FirewallError as msg:
code = FirewallError.get_code(str(msg))
cmd.print_and_exit("Error: %s" % msg, code)
fw.setExceptionHandler(cmd.exception_handler)
if fw.connected == False:
if args.parser == "state":
cmd.print_and_exit("not running", errors.NOT_RUNNING)
else:
cmd.print_and_exit("FirewallD is not running", errors.NOT_RUNNING)
cmd.set_fw(fw)
# version
if args.parser == "version":
cmd.print_and_exit(fw.get_property("version"))
# state
elif args.parser == "state":
state = fw.get_property("state")
if state == "RUNNING":
cmd.print_and_exit("running")
else:
cmd.print_and_exit(state, errors.NOT_RUNNING)
# reload
elif args.parser == "reload":
if args.complete:
fw.complete_reload()
else:
fw.reload()
# runtime_to_permanent
elif args.parser == "runtime-to-permanent":
fw.runtimeToPermanent()
#############################################################################
# list
elif args.parser == "list":
if not hasattr(args, "list"):
grp_list.print_help()
sys.exit(0)
if args.list == "zones":
if args.active:
items = fw.getActiveZones()
elif args.permanent:
items = fw.config().getZoneNames()
else:
items = fw.getZones()
cmd.print_and_exit(" ".join(sorted(items)))
elif args.list == "services":
if args.permanent:
items = fw.config().getServiceNames()
else:
items = fw.listServices()
cmd.print_and_exit(" ".join(sorted(items)))
elif args.list == "ipsets":
if args.permanent:
items = fw.config().getIPSetNames()
else:
items = fw.getIPSets()
cmd.print_and_exit(" ".join(sorted(items)))
elif args.list == "helpers":
if args.permanent:
items = fw.config().getHelperNames()
else:
items = fw.getHelpers()
cmd.print_and_exit(" ".join(sorted(items)))
elif args.list == "icmptypes":
if args.permanent:
items = fw.config().getIcmpTypeNames()
else:
items = fw.listIcmpTypes()
cmd.print_and_exit(" ".join(sorted(items)))
else:
cmd.fail("Uncaught argument")
#############################################################################
# info
elif args.parser == "info":
if not hasattr(args, "info"):
grp_info.print_help()
sys.exit(0)
if args.info == "zone":
if args.zone != "":
zone = args.zone
else:
zone = fw.getDefaultZone()
if args.permanent:
settings = fw.config().getZoneByName(zone).getSettings()
else:
settings = fw.getZoneSettings(zone)
cmd.print_zone_info(zone, settings, True)
sys.exit(0)
elif args.info == "zones":
if args.active:
for zone in fw.getActiveZones():
cmd.print_zone_info(zone, fw.getZoneSettings(zone))
cmd.print_msg("")
elif args.permanent:
names = fw.config().getZoneNames()
for zone in sorted(names):
settings = fw.config().getZoneByName(zone)
cmd.print_zone_info(zone, settings.getSettings())
cmd.print_msg("")
else:
for zone in fw.getZones():
cmd.print_zone_info(zone, fw.getZoneSettings(zone))
cmd.print_msg("")
sys.exit(0)
elif args.info == "service":
if args.permanent:
settings = fw.config().getServiceByName(args.service).getSettings()
else:
settings = fw.getServiceSettings(args.service)
cmd.print_service_info(args.service, settings)
sys.exit(0)
elif args.info == "services":
if args.permanent:
names = fw.config().getServiceNames()
for service in sorted(names):
settings = fw.config().getServiceByName(service)
cmd.print_service_info(service, settings.getSettings())
cmd.print_msg("")
else:
for service in fw.listServices():
cmd.print_service_info(service, fw.getServiceSettings(service))
cmd.print_msg("")
sys.exit(0)
elif args.info == "ipset":
if args.permanent:
settings = fw.config().getIPSetByName(args.ipset).getSettings()
else:
settings = fw.getIPSetSettings(args.ipset)
cmd.print_ipset_info(args.ipset, settings)
sys.exit(0)
elif args.info == "ipsets":
if args.permanent:
names = fw.config().getIPSetNames()
for ipset in sorted(names):
settings = fw.config().getIPSetByName(ipset)
cmd.print_ipset_info(ipset, settings.getSettings())
cmd.print_msg("")
else:
for ipset in fw.getIPSets():
cmd.print_ipset_info(ipset, fw.getIPSetSettings(ipset))
cmd.print_msg("")
sys.exit(0)
elif args.info == "helper":
if args.permanent:
settings = fw.config().getHelperByName(
args.helper).getSettings()
else:
settings = fw.getHelperSettings(args.helper)
cmd.print_helper_info(args.helper, settings)
sys.exit(0)
elif args.info == "helpers":
if args.permanent:
names = fw.config().getHelperNames()
for helper in sorted(names):
settings = fw.config().getHelperByName(helper)
cmd.print_helper_info(helper, settings.getSettings())
cmd.print_msg("")
else:
for helper in fw.getHelpers():
cmd.print_helper_info(helper,
fw.getHelperSettings(helper))
cmd.print_msg("")
sys.exit(0)
elif args.info == "icmptype":
if args.permanent:
settings = fw.config().getIcmpTypeByName(
args.icmptype).getSettings()
else:
settings = fw.getIcmpTypeSettings(args.icmptype)
cmd.print_icmptype_info(args.icmptype, settings)
sys.exit(0)
elif args.info == "icmptypes":
if args.permanent:
names = fw.config().getIcmpTypeNames()
for icmptype in sorted(names):
settings = fw.config().getIcmpTypeByName(icmptype)
cmd.print_icmptype_info(icmptype, settings.getSettings())
cmd.print_msg("")
else:
for icmptype in fw.listIcmpTypes():
cmd.print_icmptype_info(icmptype,
fw.getIcmpTypeSettings(icmptype))
cmd.print_msg("")
sys.exit(0)
else:
cmd.fail("Uncaught argument")
#############################################################################
# zone
elif args.parser == "zone":
if not hasattr(args, "action"):
grp_zone.print_help()
sys.exit(0)
if args.action == "add":
if not hasattr(args, "item"):
grp_zone_add.print_help()
sys.exit(0)
if args.permanent:
if args.zone == "":
fw_zone = fw.config().getZoneByName(fw.getDefaultZone())
else:
fw_zone = fw.config().getZoneByName(args.zone)
if args.item == "interface":
#interfaces = [ ]
#for interface in args.interface:
# if not try_set_zone_of_interface(args.zone, interface):
# interfaces.append(interface)
if args.permanent:
interfaces = [ ]
for interface in args.interface:
if not try_set_zone_of_interface(args.zone, interface):
interfaces.append(interface)
cmd.add_sequence(interfaces, fw_zone.addInterface,
fw_zone.queryInterface, None, "'%s'")
else:
#cmd.x_add_sequence(args.zone, interfaces,
cmd.x_add_sequence(args.zone, args.interface,
fw.addInterface, fw.queryInterface,
None, "'%s'")
elif args.item == "source":
if args.permanent:
cmd.add_sequence(args.source, fw_zone.addSource,
fw_zone.querySource, cmd.parse_source, "'%s'")
else:
cmd.x_add_sequence(args.zone, args.source,
fw.addSource, fw.querySource,
cmd.parse_source, "'%s'")
elif args.item == "service":
if args.permanent:
cmd.add_sequence(args.service, fw_zone.addService,
fw_zone.queryService, None, "'%s'")
else:
cmd.zone_add_timeout_sequence(args.zone, args.service,
fw.addService, fw.queryService,
None, "'%s'", args.timeout)
elif args.item == "port":
if args.permanent:
cmd.add_sequence(args.port,
fw_zone.addPort, fw_zone.queryPort,
cmd.parse_port, "'%s/%s'")
else:
cmd.zone_add_timeout_sequence(args.zone, args.port,
fw.addPort, fw.queryPort,
cmd.parse_port, "'%s/%s'",
args.timeout)
elif args.item == "protocol":
if args.permanent:
cmd.add_sequence(args.protocol,
fw_zone.addProtocol, fw_zone.queryProtocol,
None, "'%s'")
else:
cmd.zone_add_timeout_sequence(args.zone, args.protocol,
fw.addProtocol, fw.queryProtocol,
None, "'%s'", args.timeout)
elif args.item == "source-port":
if args.permanent:
cmd.add_sequence(args.port,
fw_zone.addSourcePort,
fw_zone.querySourcePort,
cmd.parse_port, "'%s/%s'")
else:
cmd.zone_add_timeout_sequence(args.zone, args.port,
fw.addSourcePort,
fw.querySourcePort,
cmd.parse_port, "'%s/%s'",
args.timeout)
elif args.item == "rich-rule":
if args.permanent:
cmd.add_sequence(args.rich_rule, fw_zone.addRichRule,
fw_zone.queryRichRule, None, "'%s'")
else:
cmd.zone_add_timeout_sequence(args.zone, args.rich_rule,
fw.addRichRule,
fw.queryRichRule, None, "'%s'",
args.timeout)
elif args.item == "masquerade":
if args.permanent:
fw_zone.addMasquerade()
else:
fw.addMasquerade(args.zone, args.timeout)
elif args.item == "forward-port":
if args.permanent:
cmd.add_sequence(args.forward_port, fw_zone.addForwardPort,
fw_zone.queryForwardPort,
cmd.parse_forward_port,
"port=%s:proto=%s:toport=%s:toaddr=%s")
else:
cmd.zone_add_timeout_sequence(
args.zone, args.forward_port,
fw.addForwardPort, fw.queryForwardPort,
cmd.parse_forward_port,
"'port=%s:proto=%s:toport=%s:toaddr=%s'",
args.timeout)
elif args.item == "icmp-block":
if args.permanent:
cmd.add_sequence(args.icmp_block, fw_zone.addIcmpBlock,
fw_zone.queryIcmpBlock, None, "'%s'")
else:
cmd.zone_add_timeout_sequence(args.zone, args.icmp_block,
fw.addIcmpBlock,
fw.queryIcmpBlock,
None, "'%s'", args.timeout)
elif args.item == "icmp-block-inversion":
if args.permanent:
fw_zone.addIcmpBlockInversion()
else:
fw.addIcmpBlockInversion(args.zone)
else:
cmd.fail("Uncaught argument")
elif args.action == "remove":
if not hasattr(args, "item"):
grp_zone_remove.print_help()
sys.exit(0)
if args.permanent:
if args.zone == "":
fw_zone = fw.config().getZoneByName(fw.getDefaultZone())
else:
fw_zone = fw.config().getZoneByName(args.zone)
if args.item == "interface":
#interfaces = [ ]
#for interface in args.interface:
# if not try_set_zone_of_interface("", interface):
# interfaces.append(interface)
if args.permanent:
interfaces = [ ]
for interface in args.interface:
if not try_set_zone_of_interface("", interface):
interfaces.append(interface)
cmd.remove_sequence(interfaces, fw_zone.removeInterface,
fw_zone.queryInterface, None, "'%s'")
else:
#cmd.x_remove_sequence(args.zone, interfaces,
cmd.x_remove_sequence(args.zone, args.interface,
fw.removeInterface, fw.queryInterface,
None, "'%s'")
elif args.item == "source":
if args.permanent:
cmd.remove_sequence(args.source, fw_zone.removeSource,
fw_zone.querySource, cmd.parse_source,
"'%s'")
else:
cmd.x_remove_sequence(args.zone, args.source,
fw.removeSource, fw.querySource,
cmd.parse_source, "'%s'")
elif args.item == "service":
if args.permanent:
cmd.remove_sequence(args.service, fw_zone.removeService,
fw_zone.queryService, None, "'%s'")
else:
cmd.x_remove_sequence(args.zone, args.service,
fw.removeService, fw.queryService,
None, "'%s'")
elif args.item == "port":
if args.permanent:
cmd.remove_sequence(args.port,
fw_zone.removePort, fw_zone.queryPort,
cmd.parse_port, "'%s/%s'")
else:
cmd.x_remove_sequence(args.zone, args.port,
fw.removePort, fw.queryPort,
cmd.parse_port, "'%s/%s'")
elif args.item == "protocol":
if args.permanent:
cmd.remove_sequence(args.protocol,
fw_zone.removeProtocol,
fw_zone.queryProtocol,
None, "'%s'")
else:
cmd.x_remove_sequence(args.zone, args.protocol,
fw.removeProtocol, fw.queryProtocol,
None, "'%s'")
elif args.item == "source-port":
if args.permanent:
cmd.remove_sequence(args.port,
fw_zone.removeSourcePort,
fw_zone.querySourcePort,
cmd.parse_port, "'%s/%s'")
else:
cmd.x_remove_sequence(args.zone, args.port,
fw.removeSourcePort, fw.querySourcePort,
cmd.parse_port, "'%s/%s'")
elif args.item == "rich-rule":
if args.permanent:
cmd.remove_sequence(args.rich_rule, fw_zone.removeRichRule,
fw_zone.queryRichRule, None, "'%s'")
else:
cmd.x_remove_sequence(args.zone, args.rich_rule,
fw.removeRichRule,
fw.queryRichRule, None, "'%s'")
elif args.item == "masquerade":
if args.permanent:
fw_zone.removeMasquerade()
else:
fw.removeMasquerade(args.zone)
elif args.item == "forward-port":
if args.permanent:
cmd.remove_sequence(args.forward_port,
fw_zone.removeForwardPort,
fw_zone.queryForwardPort,
cmd.parse_forward_port,
"port=%s:proto=%s:toport=%s:toaddr=%s")
else:
cmd.x_remove_sequence(args.zone, args.forward_port,
fw.removeForwardPort,
fw.queryForwardPort,
cmd.parse_forward_port,
"'port=%s:proto=%s:toport=%s:toaddr=%s'")
elif args.item == "icmp-block":
if args.permanent:
cmd.remove_sequence(args.icmp_block, fw_zone.removeIcmpBlock,
fw_zone.queryIcmpBlock, None, "'%s'")
else:
cmd.x_remove_sequence(args.zone, args.icmp_block,
fw.removeIcmpBlock,
fw.queryIcmpBlock,
None, "'%s'")
elif args.item == "icmp-block-inversion":
if args.permanent:
fw_zone.removeIcmpBlockInversion()
else:
fw.removeIcmpBlockInversion(args.zone)
else:
cmd.fail("Uncaught argument")
elif args.action == "get":
if not hasattr(args, "item"):
grp_zone_get.print_help()
sys.exit(0)
if args.permanent:
if args.zone == "":
fw_zone = fw.config().getZoneByName(fw.getDefaultZone())
else:
fw_zone = fw.config().getZoneByName(args.zone)
else:
fw_zone = fw.getZoneSettings(args.zone)
if args.item == "description":
cmd.print_and_exit(fw_zone.getDescription())
elif args.item == "short":
cmd.print_and_exit(fw_zone.getShort())
else:
cmd.fail("Uncaught argument")
elif args.action == "set":
if not hasattr(args, "item"):
grp_zone_set.print_help()
sys.exit(0)
if args.permanent:
if args.zone == "":
fw_zone = fw.config().getZoneByName(fw.getDefaultZone())
else:
fw_zone = fw.config().getZoneByName(args.zone)
else:
cmd.fail("Not possible to alter runtime zone settings")
if args.item == "description":
fw_zone.setDescription(args.description)
elif args.item == "short":
fw_zone.setShort(args.short)
else:
cmd.fail("Uncaught argument")
elif args.action == "query":
if not hasattr(args, "item"):
grp_zone_query.print_help()
sys.exit(0)
if args.permanent:
if args.zone == "":
fw_zone = fw.config().getZoneByName(fw.getDefaultZone())
else:
fw_zone = fw.config().getZoneByName(args.zone)
if args.item == "interface":
if args.permanent:
cmd.query_sequence(args.interface,
fw_zone.queryInterface,
None, "'%s'")
else:
cmd.x_query_sequence(args.zone, args.interface,
fw.queryInterface,
None, "'%s'")
elif args.item == "source":
if args.permanent:
cmd.query_sequence(args.source,
fw_zone.querySource,
cmd.parse_source, "'%s'")
else:
cmd.x_query_sequence(args.zone, args.source,
fw.querySource,
cmd.parse_source, "'%s'")
elif args.item == "service":
if args.permanent:
cmd.query_sequence(args.service,
fw_zone.queryService,
None, "'%s'")
else:
cmd.x_query_sequence(args.zone, args.service,
fw.queryService,
None, "'%s'")
elif args.item == "port":
if args.permanent:
cmd.query_sequence(args.port,
fw_zone.queryPort,
cmd.parse_port, "'%s/%s'")
else:
cmd.x_query_sequence(args.zone, args.port,
fw.queryPort,
cmd.parse_port, "'%s/%s'")
elif args.item == "protocol":
if args.permanent:
cmd.query_sequence(args.protocol,
fw_zone.queryProtocol,
None, "'%s'")
else:
cmd.x_query_sequence(args.zone, args.protocol,
fw.queryProtocol,
None, "'%s'")
elif args.item == "source-port":
if args.permanent:
cmd.query_sequence(args.port,
fw.querySourcePort,
cmd.parse_port, "'%s/%s'")
else:
cmd.x_query_sequence(args.zone, args.port,
fw.querySourcePort,
cmd.parse_port, "'%s/%s'")
elif args.item == "rich-rule":
if args.permanent:
cmd.query_sequence(args.rich_rule,
fw_zone.queryRichRule, None, "'%s'")
else:
cmd.x_query_sequence(args.zone, args.rich_rule,
fw.queryRichRule, None, "'%s'")
elif args.item == "masquerade":
if args.permanent:
cmd.print_query_result(fw_zone.queryMasquerade())
else:
cmd.print_query_result(fw.queryMasquerade(args.zone))
elif args.item == "forward-port":
if args.permanent:
cmd.query_sequence(args.forward_port,
fw_zone.queryForwardPort,
cmd.parse_forward_port,
"port=%s:proto=%s:toport=%s:toaddr=%s")
else:
cmd.x_query_sequence(args.zone, args.forward_port,
fw.queryForwardPort,
cmd.parse_forward_port,
"'port=%s:proto=%s:toport=%s:toaddr=%s'")
elif args.item == "icmp-block":
if args.permanent:
cmd.query_sequence(args.icmp_block,
fw_zone.queryIcmpBlock, None, "'%s'")
else:
cmd.x_query_sequence(args.zone, args.icmp_block,
fw.queryIcmpBlock,
None, "'%s'")
elif args.item == "icmp-block-inversion":
if args.permanent:
cmd.print_query_result(fw_zone.queryIcmpBlockInversion())
else:
cmd.print_query_result(fw.queryIcmpBlockInversion(args.zone))
else:
cmd.fail("Uncaught argument")
elif args.action == "list":
if not hasattr(args, "item"):
grp_zone_list.print_help()
sys.exit(0)
if args.permanent:
if args.zone == "":
fw_zone = fw.config().getZoneByName(fw.getDefaultZone())
else:
fw_zone = fw.config().getZoneByName(args.zone)
if args.item == "interfaces":
if args.permanent:
cmd.print_and_exit(" ".join(fw_zone.getInterfaces()))
else:
cmd.print_and_exit(" ".join(fw.getInterfaces(args.zone)))
elif args.item == "sources":
if args.permanent:
cmd.print_and_exit(" ".join(fw_zone.getSources()))
else:
cmd.print_and_exit(" ".join(fw.getSources(args.zone)))
elif args.item == "services":
if args.permanent:
cmd.print_and_exit(" ".join(fw_zone.getServices()))
else:
cmd.print_and_exit(" ".join(fw.getServices(args.zone)))
elif args.item == "ports":
if args.permanent:
cmd.print_and_exit(" ".join(["%s/%s" % (port[0], port[1])
for port in
fw_zone.getPorts()]))
else:
cmd.print_and_exit(" ".join(["%s/%s" % (port[0], port[1])
for port in
fw.getPorts(args.zone)]))
elif args.item == "protocols":
if args.permanent:
cmd.print_and_exit(" ".join(fw_zone.getProtocols()))
else:
cmd.print_and_exit(" ".join(fw.getProtocols(args.zone)))
elif args.item == "source-ports":
if args.permanent:
cmd.print_and_exit(" ".join(["%s/%s" % (port[0], port[1])
for port in
fw_zone.getSourcePorts()]))
else:
cmd.print_and_exit(" ".join(["%s/%s" % (port[0], port[1])
for port in
fw.getSourcePorts(args.zone)]))
elif args.item == "rich-rules":
if args.permanent:
cmd.print_and_exit("\n".join(fw_zone.getRichRules()))
else:
cmd.print_and_exit("\n".join(fw.getRichRules(args.zone)))
elif args.item == "forward-ports":
if args.permanent:
cmd.print_and_exit(
"\n".join(["port=%s:proto=%s:toport=%s:toaddr=%s" % \
(port, protocol, toport, toaddr) for
(port, protocol, toport, toaddr) in
fw_zone.getForwardPorts()]))
else:
cmd.print_and_exit(
"\n".join(["port=%s:proto=%s:toport=%s:toaddr=%s" % \
(port, protocol, toport, toaddr) for
(port, protocol, toport, toaddr) in
fw.getForwardPorts(args.zone)]))
elif args.item == "icmp-blocks":
if args.permanent:
cmd.print_and_exit(" ".join(fw_zone.getIcmpBlocks()))
else:
cmd.print_and_exit(" ".join(fw.getIcmpBlocks(args.zone)))
else:
cmd.fail("Uncaught argument")
elif args.action == "load-defaults":
if args.permanent:
fw_zone = fw.config().getZoneByName(args.zone)
fw_zone.loadDefaults()
else:
cmd.fail("Not possible to load defaults in runtime")
else:
cmd.fail("Uncaught argument")
#############################################################################
# service
elif args.parser == "service":
if not hasattr(args, "action"):
grp_service.print_help()
sys.exit(0)
if args.action == "add":
if not hasattr(args, "item"):
grp_service_add.print_help()
sys.exit(0)
if args.permanent:
fw_service = fw.config().getServiceByName(args.service)
else:
cmd.fail("Not possible to alter runtime service settings")
if args.item == "port":
cmd.add_sequence(args.port,
fw_service.addPort, fw_service.queryPort,
cmd.parse_port, "'%s/%s'")
elif args.item == "protocol":
cmd.add_sequence(args.protocol,
fw_service.addProtocol,
fw_service.queryProtocol,
None, "'%s'")
elif args.item == "source-port":
cmd.add_sequence(args.port,
fw_service.addSourcePort,
fw_service.querySourcePort,
cmd.parse_port, "'%s/%s'")
elif args.item == "module":
cmd.add_sequence(args.module,
fw_service.addModule,
fw_service.queryModule,
None, "'%s'")
elif args.item == "destination":
cmd.add_sequence(args.destination,
fw_service.setDestination,
fw_service.queryDestination,
cmd.parse_service_destination, "%s:%s")
else:
cmd.fail("Uncaught argument")
elif args.action == "remove":
if not hasattr(args, "item"):
grp_service_remove.print_help()
sys.exit(0)
if args.permanent:
fw_service = fw.config().getServiceByName(args.service)
else:
cmd.fail("Not possible to alter runtime service settings")
if args.item == "port":
cmd.remove_sequence(args.port,
fw_service.removePort,
fw_service.queryPort,
cmd.parse_port, "'%s/%s'")
elif args.item == "protocol":
cmd.remove_sequence(args.protocol,
fw_service.removeProtocol,
fw_service.queryProtocol,
None, "'%s'")
elif args.item == "source-port":
cmd.remove_sequence(args.port,
fw_service.removeSourcePort,
fw_service.querySourcePort,
cmd.parse_port, "'%s/%s'")
elif args.item == "module":
cmd.remove_sequence(args.module,
fw_service.removeModule,
fw_service.queryModule,
None, "'%s'")
elif args.item == "destination":
cmd.remove_sequence(args.destination,
fw_service.removeDestination,
fw_service.queryDestination,
cmd.parse_service_destination, "%s:%s")
else:
cmd.fail("Uncaught argument")
elif args.action == "get":
if not hasattr(args, "item"):
grp_service_get.print_help()
sys.exit(0)
if args.permanent:
fw_service = fw.config().getServiceByName(args.service)
else:
fw_service = fw.getServiceSettings(args.service)
if args.item == "description":
cmd.print_and_exit(fw_service.getDescription())
elif args.item == "short":
cmd.print_and_exit(fw_service.getShort())
else:
cmd.fail("Uncaught argument")
elif args.action == "set":
if not hasattr(args, "item"):
grp_service_set.print_help()
sys.exit(0)
if args.permanent:
fw_service = fw.config().getServiceByName(args.service)
else:
cmd.fail("Not possible to alter runtime service settings")
if args.item == "description":
fw_service.setDescription(args.description)
elif args.item == "short":
fw_service.setShort(args.short)
else:
cmd.fail("Uncaught argument")
elif args.action == "query":
if not hasattr(args, "item"):
grp_service_query.print_help()
sys.exit(0)
if args.permanent:
fw_service = fw.config().getServiceByName(args.service)
else:
fw_service = fw.getServiceSettings(args.service)
if args.item == "port":
cmd.query_sequence(args.port,
fw_service.queryPort,
cmd.parse_port, "'%s/%s'")
elif args.item == "protocol":
cmd.query_sequence(args.protocol,
fw_service.queryProtocol,
None, "'%s'")
elif args.item == "source-port":
cmd.query_sequence(args.port,
fw.querySourcePort,
cmd.parse_port, "'%s/%s'")
elif args.item == "module":
cmd.query_sequence(args.module,
fw_service.queryModule,
None, "'%s'")
elif args.item == "destination":
cmd.query_sequence(args.destination,
fw_service.queryDestination,
cmd.parse_service_destination, "%s:%s")
else:
cmd.fail("Uncaught argument")
elif args.action == "list":
if not hasattr(args, "item"):
grp_service_list.print_help()
sys.exit(0)
if args.permanent:
fw_service = fw.config().getServiceByName(args.service)
else:
fw_service = fw.getServiceSettings(args.service)
if args.item == "ports":
cmd.print_and_exit(" ".join(["%s/%s" % (port[0], port[1])
for port in
fw_service.getPorts()]))
elif args.item == "protocols":
cmd.print_and_exit(" ".join(fw_service.getProtocols()))
elif args.item == "source-ports":
cmd.print_and_exit(" ".join(["%s/%s" % (port[0], port[1])
for port in
fw_service.getSourcePorts()]))
elif args.item == "modules":
cmd.print_and_exit(" ".join(fw_service.getModules()))
elif args.item == "destinations":
cmd.print_and_exit(
" ".join(["%s:%s" % (dest[0], dest[1]) for dest in
fw_service.getDestinations().items()]))
else:
cmd.fail("Uncaught argument")
elif args.action == "load-defaults":
if args.permanent:
fw_service = fw.config().getServiceByName(args.service)
fw_service.loadDefaults()
else:
cmd.fail("Not possible to load defaults in runtime")
else:
cmd.fail("Uncaught argument")
#############################################################################
# ipset
elif args.parser == "ipset":
if not hasattr(args, "action"):
grp_ipset.print_help()
sys.exit(0)
if args.action == "add":
if not hasattr(args, "item"):
grp_ipset_add.print_help()
sys.exit(0)
if args.item == "entry":
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
cmd.add_sequence(args.entry,
fw_ipset.addEntry, fw_ipset.queryEntry,
None, "'%s'")
else:
cmd.x_add_sequence(args.ipset, args.entry,
fw.addEntry, fw.queryEntry,
None, "'%s'")
elif args.item == "entries-from-file":
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
old_entries = fw_ipset.getEntries()
else:
old_entries = fw.getEntries(args.ipset)
changed = False
for filename in args.entries_from_file:
try:
entries = cmd.get_ipset_entries_from_file(filename)
except IOError as msg:
message = "Failed to read file '%s': %s" % (filename, msg)
if len(args.entries_from_file) > 1:
cmd.print_warning(message)
else:
cmd.print_and_exit(message)
else:
entries_set = set()
for entry in old_entries:
entries_set.add(entry)
for entry in entries:
if entry not in entries_set:
old_entries.append(entry)
entries_set.add(entry)
changed = True
else:
cmd.print_if_verbose(
"Warning: ALREADY_ENABLED: %s" % entry)
if changed:
if args.permanent:
fw_ipset.setEntries(old_entries)
else:
fw.setEntries(args.ipset, old_entries)
else:
cmd.fail("Uncaught argument")
elif args.action == "get":
if not hasattr(args, "item"):
grp_ipset_get.print_help()
sys.exit(0)
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
else:
fw_ipset = fw.getIPSetSettings(args.ipset)
if args.item == "description":
cmd.print_and_exit(fw_ipset.getDescription())
elif args.item == "short":
cmd.print_and_exit(fw_ipset.getShort())
else:
cmd.fail("Uncaught argument")
elif args.action == "set":
if not hasattr(args, "item"):
grp_ipset_set.print_help()
sys.exit(0)
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
else:
cmd.fail("Not possible to alter runtime ipset settings")
if args.item == "description":
fw_ipset.setDescription(args.description)
elif args.item == "short":
fw_ipset.setShort(args.short)
else:
cmd.fail("Uncaught argument")
elif args.action == "remove":
if not hasattr(args, "item"):
grp_ipset_remove.print_help()
sys.exit(0)
if args.item == "entry":
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
cmd.remove_sequence(args.entry,
fw_ipset.removeEntry, fw_ipset.queryEntry,
None, "'%s'")
else:
cmd.x_remove_sequence(args.ipset, args.entry,
fw.removeEntry, fw.queryEntry,
None, "'%s'")
elif args.item == "entries-from-file":
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
old_entries = fw_ipset.getEntries()
else:
old_entries = fw.getEntries(args.ipset)
changed = False
for filename in args.entries_from_file:
try:
entries = cmd.get_ipset_entries_from_file(filename)
except IOError as msg:
message = "Failed to read file '%s': %s" % (filename, msg)
if len(args.entries_from_file) > 1:
cmd.print_warning(message)
else:
cmd.print_and_exit(message)
else:
entries_set = set()
for entry in old_entries:
entries_set.add(entry)
for entry in entries:
if entry in entries_set:
old_entries.remove(entry)
entries_set.discard(entry)
changed = True
else:
cmd.print_if_verbose(
"Warning: NOT_ENABLED: %s" % entry)
if changed:
if args.permanent:
fw_ipset.setEntries(old_entries)
else:
fw.setEntries(args.ipset, old_entries)
elif args.item == "all":
if args.permanent:
fw_ipset.setEntries(args.ipset, [ ])
else:
fw.setEntries(args.ipset, [ ])
else:
cmd.fail("Uncaught argument")
elif args.action == "query":
if not hasattr(args, "item"):
grp_ipset_query.print_help()
sys.exit(0)
if args.item == "entry":
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
cmd.query_sequence(args.entry,
fw_ipset.queryEntry, None, "'%s'")
else:
cmd.x_query_sequence(args.ipset, args.entry,
fw.queryEntry, None, "'%s'")
elif args.item == "entries-from-file":
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
old_entries = fw_ipset.getEntries()
else:
old_entries = fw.getEntries(args.ipset)
changed = False
for filename in args.entries_from_file:
try:
entries = cmd.get_ipset_entries_from_file(filename)
except IOError as msg:
message = "Failed to read file '%s': %s" % (filename, msg)
if len(args.entries_from_file) > 1:
cmd.print_warning(message)
else:
cmd.print_and_exit(message)
else:
for entry in entries:
cmd.print_msg("%s: %s" % \
(entry,
("no", "yes")[entry in old_entries]))
else:
cmd.fail("Uncaught argument")
elif args.action == "list":
if not hasattr(args, "item"):
grp_ipset_list.print_help()
sys.exit(0)
if args.item == "entries":
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
cmd.print_and_exit("\n".join(fw_ipset.getEntries()))
else:
cmd.print_and_exit("\n".join(fw.getEntries(args.ipset)))
else:
cmd.fail("Uncaught argument")
elif args.action == "load-defaults":
if args.permanent:
fw_ipset = fw.config().getIPSetByName(args.ipset)
fw_ipset.loadDefaults()
else:
cmd.fail("Not possible to load defaults in runtime")
else:
cmd.fail("Uncaught argument")
#############################################################################
# helper
elif args.parser == "helper":
if not hasattr(args, "action"):
grp_helper.print_help()
sys.exit(0)
if args.action == "add":
if not hasattr(args, "item"):
grp_helper_add.print_help()
sys.exit(0)
if args.permanent:
fw_helper = fw.config().getHelperByName(args.helper)
else:
cmd.fail("Not possible to alter runtime helper settings")
if args.item == "port":
cmd.add_sequence(args.port,
fw_helper.addPort, fw_helper.queryPort,
cmd.parse_port, "'%s/%s'")
else:
cmd.fail("Uncaught argument")
elif args.action == "remove":
if not hasattr(args, "item"):
grp_helper_remove.print_help()
sys.exit(0)
if args.permanent:
fw_helper = fw.config().getHelperByName(args.helper)
else:
cmd.fail("Not possible to alter runtime helper settings")
if args.item == "port":
cmd.remove_sequence(args.port,
fw_helper.removePort,
fw_helper.queryPort,
cmd.parse_port, "'%s/%s'")
else:
cmd.fail("Uncaught argument")
elif args.action == "get":
if not hasattr(args, "item"):
grp_helper_get.print_help()
sys.exit(0)
if args.permanent:
fw_helper = fw.config().getHelperByName(args.helper)
else:
fw_helper = fw.getHelperSettings(args.helper)
if args.item == "description":
cmd.print_and_exit(fw_helper.getDescription())
elif args.item == "family":
cmd.print_and_exit(fw_helper.getFamily())
elif args.item == "module":
cmd.print_and_exit(fw_helper.getModule())
elif args.item == "short":
cmd.print_and_exit(fw_helper.getShort())
else:
cmd.fail("Uncaught argument")
elif args.action == "set":
if not hasattr(args, "item"):
grp_helper_set.print_help()
sys.exit(0)
if args.permanent:
fw_helper = fw.config().getHelperByName(args.helper)
else:
cmd.fail("Not possible to alter runtime helper settings")
if args.item == "description":
fw_helper.setDescription(args.description)
elif args.item == "family":
fw_helper.setFamily(cmd.check_helper_family(args.family))
elif args.item == "module":
fw_helper.setModule(cmd.check_module(args.module))
elif args.item == "short":
fw_helper.setShort(args.short)
else:
cmd.fail("Uncaught argument")
elif args.action == "query":
if not hasattr(args, "item"):
grp_helper_query.print_help()
sys.exit(0)
if args.permanent:
fw_helper = fw.config().getHelperByName(args.helper)
else:
fw_helper = fw.getHelperSettings(args.helper)
if args.item == "port":
cmd.query_sequence(args.port,
fw_helper.queryPort,
cmd.parse_port, "'%s/%s'")
else:
cmd.fail("Uncaught argument")
elif args.action == "list":
if not hasattr(args, "item"):
grp_helper_list.print_help()
sys.exit(0)
if args.permanent:
fw_helper = fw.config().getHelperByName(args.helper)
else:
fw_helper = fw.getHelperSettings(args.helper)
if args.item == "ports":
cmd.print_and_exit(" ".join(["%s/%s" % (port[0], port[1])
for port in
fw_helper.getPorts()]))
else:
cmd.fail("Uncaught argument")
elif args.action == "load-defaults":
if args.permanent:
fw_helper = fw.config().getHelperByName(args.helper)
fw_helper.loadDefaults()
else:
cmd.fail("Not possible to load defaults in runtime")
else:
cmd.fail("Uncaught argument")
#############################################################################
# icmptype
elif args.parser == "icmptype":
if not hasattr(args, "action"):
grp_icmptype.print_help()
sys.exit(0)
if args.action == "add":
if not hasattr(args, "item"):
grp_icmptype_add.print_help()
sys.exit(0)
if args.permanent:
fw_icmptype = fw.config().getIcmpTypeByName(args.icmptype)
else:
cmd.fail("Not possible to alter runtime icmptype settings")
if args.item == "destination":
cmd.add_sequence(args.destination,
fw_icmptype.addDestination,
fw_icmptype.queryDestination,
cmd.check_destination_ipv, "'%s'")
else:
cmd.fail("Uncaught argument")
elif args.action == "remove":
if not hasattr(args, "item"):
grp_icmptype_remove.print_help()
sys.exit(0)
if args.permanent:
fw_icmptype = fw.config().getIcmpTypeByName(args.icmptype)
else:
cmd.fail("Not possible to alter runtime icmptype settings")
if args.item == "destination":
cmd.remove_sequence(args.destination,
fw_icmptype.removeDestination,
fw_icmptype.queryDestination,
cmd.check_destination_ipv, "'%s'")
else:
cmd.fail("Uncaught argument")
elif args.action == "get":
if not hasattr(args, "item"):
grp_icmptype_get.print_help()
sys.exit(0)
if args.permanent:
fw_icmptype = fw.config().getIcmpTypeByName(args.icmptype)
else:
fw_icmptype = fw.getIcmpTypeSettings(args.icmptype)
if args.item == "description":
cmd.print_and_exit(fw_icmptype.getDescription())
elif args.item == "short":
cmd.print_and_exit(fw_icmptype.getShort())
else:
cmd.fail("Uncaught argument")
elif args.action == "set":
if not hasattr(args, "item"):
grp_icmptype_set.print_help()
sys.exit(0)
if args.permanent:
fw_icmptype = fw.config().getIcmpTypeByName(args.icmptype)
else:
cmd.fail("Not possible to alter runtime icmptype settings")
if args.item == "description":
fw_icmptype.setDescription(args.description)
elif args.item == "short":
fw_icmptype.setShort(args.short)
else:
cmd.fail("Uncaught argument")
elif args.action == "query":
if not hasattr(args, "item"):
grp_icmptype_query.print_help()
sys.exit(0)
if args.permanent:
fw_icmptype = fw.config().getIcmpTypeByName(args.icmptype)
else:
fw_icmptype = fw.getIcmpTypeSettings(args.icmptype)
if args.item == "destination":
cmd.query_sequence(args.destination,
fw_icmptype.queryDestination,
cmd.check_destination_ipv, "'%s'")
else:
cmd.fail("Uncaught argument")
elif args.action == "list":
if not hasattr(args, "item"):
grp_icmptype_list.print_help()
sys.exit(0)
if args.permanent:
fw_icmptype = fw.config().getIcmpTypeByName(args.icmptype)
else:
fw_icmptype = fw.getIcmpTypeSettings(args.icmptype)
if args.item == "destinations":
items = fw_icmptype.getDestinations()
if len(items) < 1:
items = [ "ipv4", "ipv6" ]
cmd.print_and_exit(" ".join(items))
else:
cmd.fail("Uncaught argument")
elif args.action == "load-defaults":
if args.permanent:
fw_icmptype = fw.config().getIcmpTypeByName(args.icmptype)
fw_icmptype.loadDefaults()
else:
cmd.fail("Not possible to load defaults in runtime")
else:
cmd.fail("Uncaught argument")
#############################################################################
# new
elif args.parser == "new":
if not hasattr(args, "action"):
grp_new.print_help()
sys.exit(0)
if not args.permanent:
cmd.fail("Not possible to use new in runtime environment")
if args.action == "zone":
if args.name is None and args.filename is None:
cmd.fail("Missing option: -n <name> | -f <filename> [-n <name>]")
elif args.filename is not None:
filename = os.path.basename(args.filename)
dirname = os.path.dirname(args.filename)
if dirname == "":
dirname = "./"
try:
obj = zone_reader(filename, dirname)
except FirewallError as msg:
cmd.fail("Failed to load zone file '%s': %s" % \
(args.filename, msg))
except IOError as msg:
cmd.fail("Failed to load zone file: %s" % msg)
if args.name:
obj.name = args.name
config = fw.config()
config.addZone(obj.name, obj.export_config())
else:
config = fw.config()
config.addZone(args.name, FirewallClientZoneSettings())
elif args.action == "service":
if args.name is None and args.filename is None:
cmd.fail("Missing option: -n <name> | -f <filename> [-n <name>]")
elif args.filename is not None:
filename = os.path.basename(args.filename)
dirname = os.path.dirname(args.filename)
if dirname == "":
dirname = "./"
try:
obj = service_reader(filename, dirname)
except FirewallError as msg:
cmd.fail("Failed to load service file '%s': %s" % \
(args.filename, msg))
except IOError as msg:
cmd.fail("Failed to load service file: %s" % msg)
if args.name:
obj.name = args.name
config = fw.config()
config.addService(obj.name, obj.export_config())
else:
config = fw.config()
config.addService(args.name, FirewallClientServiceSettings())
elif args.action == "ipset":
if args.filename is None and (args.name is None or args.type is None):
cmd.fail("Missing option: -n <name> -t <ipsettype> | "
"-f <filename> [-n <name>]")
elif args.filename is not None:
filename = os.path.basename(args.filename)
dirname = os.path.dirname(args.filename)
if dirname == "":
dirname = "./"
try:
obj = ipset_reader(filename, dirname)
except FirewallError as msg:
cmd.fail("Failed to load ipset file '%s': %s" % \
(args.filename, msg))
except IOError as msg:
cmd.fail("Failed to load ipset file: %s" % msg)
if args.name:
obj.name = args.name
config = fw.config()
config.addIPSet(obj.name, obj.export_config())
else:
settings = FirewallClientIPSetSettings()
settings.setType(args.type)
if args.option:
for opt in args.option:
settings.addOption(*cmd.parse_ipset_option(opt))
config = fw.config()
config.addIPSet(args.name, settings)
elif args.action == "helper":
if args.name is None and args.filename is None:
cmd.fail("Missing option: -n <name> | -f <filename> [-n <name>]")
elif args.filename is not None:
filename = os.path.basename(args.filename)
dirname = os.path.dirname(args.filename)
if dirname == "":
dirname = "./"
try:
obj = helper_reader(filename, dirname)
except FirewallError as msg:
cmd.fail("Failed to load helper file '%s': %s" % \
(args.filename, msg))
except IOError as msg:
cmd.fail("Failed to load helper file: %s" % msg)
if args.name:
obj.name = args.name
config = fw.config()
config.addHelper(obj.name, obj.export_config())
else:
config = fw.config()
config.addHelper(args.name, FirewallClientHelperSettings())
elif args.action == "icmptype":
if args.name is None and args.filename is None:
cmd.fail("Missing option: -n <name> | -f <filename> [-n <name>]")
elif args.filename is not None:
filename = os.path.basename(args.filename)
dirname = os.path.dirname(args.filename)
if dirname == "":
dirname = "./"
try:
obj = icmptype_reader(filename, dirname)
except FirewallError as msg:
cmd.fail("Failed to load icmptype file '%s': %s" % \
(args.filename, msg))
except IOError as msg:
cmd.fail("Failed to load icmptype file: %s" % msg)
if args.name:
obj.name = args.name
config = fw.config()
config.addIcmpType(obj.name, obj.export_config())
else:
config = fw.config()
config.addIcmpType(args.name, FirewallClientIcmpTypeSettings())
else:
cmd.fail("Uncaught argument")
#############################################################################
# delete
elif args.parser == "delete":
if not hasattr(args, "action"):
grp_delete.print_help()
sys.exit(0)
if not args.permanent:
cmd.fail("Not possible to use delete in runtime environment")
if args.action == "zone":
zone = fw.config().getZoneByName(args.zone)
zone.remove()
elif args.action == "service":
service = fw.config().getServiceByName(args.service)
service.remove()
elif args.action == "ipset":
ipset = fw.config().getIPSetByName(args.ipset)
ipset.remove()
elif args.action == "helper":
helper = fw.config().getHelperByName(args.helper)
helper.remove()
elif args.action == "icmptype":
icmptype = fw.config().getIcmpTypeByName(args.icmptype)
icmptype.remove()
else:
cmd.fail("Uncaught argument")
#############################################################################
# direct
elif args.parser == "direct":
if not hasattr(args, "action"):
grp_direct.print_help()
sys.exit(0)
if args.action == "add":
if not hasattr(args, "item"):
grp_direct_add.print_help()
sys.exit(0)
if args.permanent:
fw_direct = fw.config().direct()
if args.item == "chain":
if args.permanent:
fw_direct.addChain(cmd.check_ipv(args.chain[0]),
args.chain[1], args.chain[2])
else:
fw.addChain(cmd.check_ipv(args.chain[0]), args.chain[1],
args.chain[2])
elif args.item == "rule":
failure_msg = "usage: direct add rule { ipv4 | ipv6 | eb }" + \
" <table> <chain> <priority> <args>"
if len(args.rule) < 5:
cmd.fail(failure_msg)
try:
priority = int(args.rule[3])
except ValueError:
cmd.fail(failure_msg)
if args.permanent:
fw_direct.addRule(cmd.check_ipv(args.rule[0]), args.rule[1],
args.rule[2], priority,
splitArgs(args.rule[4]))
else:
fw.addRule(cmd.check_ipv(args.rule[0]), args.rule[1],
args.rule[2], priority, splitArgs(args.rule[4]))
elif args.item == "passthrough":
if len(args.passthrough) < 2:
cmd.fail("usage: direct add passthrough "
"{ ipv4 | ipv6 | eb } <args>")
if args.permanent:
cmd.print_msg(
fw_direct.addPassthrough(cmd.check_ipv(args.passthrough[0]),
splitArgs(args.passthrough[1])))
else:
cmd.print_msg(
fw.addPassthrough(cmd.check_ipv(args.passthrough[0]),
splitArgs(args.passthrough[1])))
else:
cmd.fail("Uncaught argument")
elif args.action == "query":
if not hasattr(args, "item"):
grp_direct_query.print_help()
sys.exit(0)
if args.permanent:
fw_direct = fw.config().direct()
if args.item == "chain":
if args.permanent:
cmd.print_query_result(
fw_direct.queryChain(cmd.check_ipv(args.chain[0]),
args.chain[1], args.chain[2]))
else:
cmd.print_query_result(
fw.queryChain(cmd.check_ipv(args.chain[0]), args.chain[1],
args.chain[2]))
elif args.item == "rule":
failure_msg = "usage: direct query rule { ipv4 | ipv6 | eb }" + \
" <table> <chain> <priority> <args>"
if len(args.rule) < 5:
cmd.fail(failure_msg)
try:
priority = int(args.rule[3])
except ValueError:
cmd.fail(failure_msg)
if args.permanent:
cmd.print_query_result(
fw_direct.queryRule(cmd.check_ipv(args.rule[0]),
args.rule[1], args.rule[2], priority,
splitArgs(args.rule[4])))
else:
cmd.print_query_result(
fw.queryRule(cmd.check_ipv(args.rule[0]), args.rule[1],
args.rule[2], priority,
splitArgs(args.rule[4])))
elif args.item == "passthrough":
if len(args.passthrough) < 2:
cmd.fail("usage: direct query passthrough "
"{ ipv4 | ipv6 | eb } <args>")
if args.permanent:
cmd.print_query_result(
fw_direct.queryPassthrough(
cmd.check_ipv(args.passthrough[0]),
splitArgs(args.passthrough[1])))
else:
cmd.print_query_result(
fw.queryPassthrough(cmd.check_ipv(args.passthrough[0]),
splitArgs(args.passthrough[1])))
else:
cmd.fail("Uncaught argument")
elif args.action == "remove":
if not hasattr(args, "item"):
grp_direct_remove.print_help()
sys.exit(0)
if args.permanent:
fw_direct = fw.config().direct()
if args.item == "chain":
if args.permanent:
fw_direct.removeChain(cmd.check_ipv(args.chain[0]),
args.chain[1], args.chain[2])
else:
fw.removeChain(cmd.check_ipv(args.chain[0]), args.chain[1],
args.chain[2])
elif args.item == "rule":
failure_msg = "usage: direct remove rule { ipv4 | ipv6 | eb }" + \
" <table> <chain> <priority> <args>"
if len(args.rule) < 5:
cmd.fail(failure_msg)
try:
priority = int(args.rule[3])
except ValueError:
cmd.fail(failure_msg)
if args.permanent:
fw_direct.removeRule(cmd.check_ipv(args.rule[0]), args.rule[1],
args.rule[2], priority,
splitArgs(args.rule[4]))
else:
fw.removeRule(cmd.check_ipv(args.rule[0]), args.rule[1],
args.rule[2], priority, splitArgs(args.rule[4]))
elif args.item == "passthrough":
if len(args.passthrough) < 2:
cmd.fail("usage: direct remove passthrough "
"{ ipv4 | ipv6 | eb } <args>")
if args.permanent:
fw_direct.removePassthrough(cmd.check_ipv(args.passthrough[0]),
splitArgs(args.passthrough[1]))
else:
fw.removePassthrough(cmd.check_ipv(args.passthrough[0]),
splitArgs(args.passthrough[1]))
else:
cmd.fail("Uncaught argument")
elif args.action == "passthrough":
if len(args.passthrough) < 2:
cmd.fail("usage: direct passthrough { ipv4 | ipv6 | eb } <args>")
msg = fw.passthrough(cmd.check_ipv(args.passthrough[0]),
splitArgs(args.passthrough[1]))
if msg:
sys.stdout.write(msg + "\n")
elif args.action == "get":
if not hasattr(args, "item"):
grp_direct_add.print_help()
sys.exit(0)
if args.permanent:
fw_direct = fw.config().direct()
if args.item == "all-chains":
if args.permanent:
chains = fw_direct.getAllChains()
for (ipv, table, chain) in chains:
cmd.print_msg("%s %s %s" % (ipv, table, chain))
sys.exit(0)
else:
chains = fw.getAllChains()
for (ipv, table, chain) in chains:
cmd.print_msg("%s %s %s" % (ipv, table, chain))
sys.exit(0)
if args.item == "chains":
if args.permanent:
cmd.print_and_exit(" ".join(fw_direct.getChains(
cmd.check_ipv(args.chains[0]),
args.chains[1])))
else:
cmd.print_and_exit(
" ".join(fw.getChains(cmd.check_ipv(args.chains[0]),
args.chains[1])))
elif args.item == "all-rules":
if args.permanent:
rules = fw_direct.getAllRules()
for (ipv, table, chain, priority, rule) in rules:
cmd.print_msg("%s %s %s %d %s" % \
(ipv, table, chain, priority,
joinArgs(rule)))
sys.exit(0)
else:
rules = fw.getAllRules()
for (ipv, table, chain, priority, rule) in rules:
cmd.print_msg("%s %s %s %d %s" % \
(ipv, table, chain, priority,
joinArgs(rule)))
sys.exit(0)
elif args.item == "rules":
if args.permanent:
rules = fw_direct.getRules(cmd.check_ipv(args.rules[0]),
args.rules[1], args.rules[2])
for (priority, rule) in rules:
cmd.print_msg("%d %s" % (priority, joinArgs(rule)))
sys.exit(0)
else:
rules = fw.getRules(cmd.check_ipv(args.rules[0]),
args.rules[1], args.rules[2])
for (priority, rule) in rules:
cmd.print_msg("%d %s" % (priority, joinArgs(rule)))
sys.exit(0)
elif args.item == "all-passthroughs":
if args.permanent:
for (ipv, rule) in fw_direct.getAllPassthroughs():
cmd.print_msg("%s %s" % (ipv, joinArgs(rule)))
sys.exit(0)
else:
for (ipv, rule) in fw.getAllPassthroughs():
cmd.print_msg("%s %s" % (ipv, joinArgs(rule)))
sys.exit(0)
elif args.item == "passthroughs":
if args.permanent:
rules = fw_direct.getPassthroughs(cmd.check_ipv(
args.passthroughs[0]))
for rule in rules:
cmd.print_msg(joinArgs(rule))
sys.exit(0)
else:
rules = fw.getPassthroughs(cmd.check_ipv(args.passthroughs[0]))
for rule in rules:
cmd.print_msg(joinArgs(rule))
sys.exit(0)
else:
cmd.fail("Uncaught argument")
else:
cmd.fail("Uncaught argument")
#############################################################################
# lockdown
elif args.parser == "lockdown-whitelist":
if not hasattr(args, "action"):
grp_lockdown_whitelist.print_help()
sys.exit(0)
if args.action == "add":
if not hasattr(args, "item"):
grp_lockdown_whitelist_add.print_help()
sys.exit(0)
if args.permanent:
fw_policies = fw.config().policies()
else:
fw_policies = fw
if args.item == "command":
cmd.add_sequence(args.command,
fw_policies.addLockdownWhitelistCommand,
fw_policies.queryLockdownWhitelistCommand,
None, "'%s'")
elif args.item == "context":
cmd.add_sequence(args.context,
fw_policies.addLockdownWhitelistContext,
fw_policies.queryLockdownWhitelistContext,
None, "'%s'")
elif args.item == "uid":
cmd.add_sequence(args.uid,
fw_policies.addLockdownWhitelistUid,
fw_policies.queryLockdownWhitelistUid,
None, "'%s'")
elif args.item == "user":
cmd.add_sequence(args.user,
fw_policies.addLockdownWhitelistUser,
fw_policies.queryLockdownWhitelistUser,
None, "'%s'")
else:
cmd.fail("Uncaught argument")
elif args.action == "query":
if not hasattr(args, "item"):
grp_lockdown_whitelist_query.print_help()
sys.exit(0)
if args.permanent:
fw_policies = fw.config().policies()
else:
fw_policies = fw
if args.item == "command":
cmd.query_sequence(args.command,
fw_policies.queryLockdownWhitelistCommand,
None, "'%s'")
elif args.item == "context":
cmd.query_sequence(args.context,
fw_policies.queryLockdownWhitelistContext,
None, "'%s'")
elif args.item == "uid":
cmd.query_sequence(args.uid,
fw_policies.queryLockdownWhitelistUid,
None, "'%s'")
elif args.item == "user":
cmd.query_sequence(args.user,
fw_policies.queryLockdownWhitelistUser,
None, "'%s'")
else:
cmd.fail("Uncaught argument")
elif args.action == "remove":
if not hasattr(args, "item"):
grp_lockdown_whitelist_remove.print_help()
sys.exit(0)
if args.permanent:
fw_policies = fw.config().policies()
else:
fw_policies = fw
if args.item == "command":
cmd.remove_sequence(args.command,
fw_policies.removeLockdownWhitelistCommand,
fw_policies.queryLockdownWhitelistCommand,
None, "'%s'")
elif args.item == "context":
cmd.remove_sequence(args.context,
fw_policies.removeLockdownWhitelistContext,
fw_policies.queryLockdownWhitelistContext,
None, "'%s'")
elif args.item == "uid":
cmd.remove_sequence(args.uid,
fw_policies.removeLockdownWhitelistUid,
fw_policies.queryLockdownWhitelistUid,
None, "'%s'")
elif args.item == "user":
cmd.remove_sequence(args.user,
fw_policies.removeLockdownWhitelistUser,
fw_policies.queryLockdownWhitelistUser,
None, "'%s'")
else:
cmd.fail("Uncaught argument")
elif args.action == "list":
if not hasattr(args, "item"):
grp_lockdown_whitelist_list.print_help()
sys.exit(0)
if args.permanent:
fw_policies = fw.config().policies()
else:
fw_policies = fw
if args.item == "commands":
cmd.print_and_exit("\n".join(
fw_policies.getLockdownWhitelistCommands()))
elif args.item == "contexts":
cmd.print_and_exit("\n".join(
fw_policies.getLockdownWhitelistContexts()))
elif args.item == "uids":
cmd.print_and_exit("\n".join(map(
str, fw_policies.getLockdownWhitelistUids())))
elif args.item == "users":
cmd.print_and_exit("\n".join(
fw_policies.getLockdownWhitelistUsers()))
else:
cmd.fail("Uncaught argument")
else:
cmd.fail("Uncaught argument")
#############################################################################
# config
elif args.parser == "config":
if not hasattr(args, "action"):
grp_config.print_help()
sys.exit(0)
if args.action == "get":
if not hasattr(args, "item"):
grp_config_get.print_help()
sys.exit(0)
if args.item == "default-zone":
cmd.print_and_exit(fw.getDefaultZone())
elif args.item == "lockdown":
cmd.print_query_result(fw.queryLockdown())
elif args.item == "log-denied":
cmd.print_and_exit(fw.getLogDenied())
elif args.item == "panic":
cmd.print_query_result(fw.queryPanicMode())
else:
cmd.fail("Uncaught argument")
elif args.action == "list":
cmd.print_msg("default-zone %s" % fw.getDefaultZone())
cmd.print_msg("lockdown %s" % ("no", "yes")[fw.queryLockdown()])
cmd.print_msg("log-denied %s" % fw.getLogDenied())
cmd.print_msg("panic %s" % ("no", "yes")[fw.queryPanicMode()])
sys.exit(0)
elif args.action == "set":
if not hasattr(args, "item"):
grp_config_set.print_help()
sys.exit(0)
if args.item == "default-zone":
fw.setDefaultZone(args.default_zone)
elif args.item == "lockdown":
if args.lockdown in [ "yes", "on" ]:
fw.config().set_property("Lockdown", "yes")
fw.enableLockdown()
elif args.lockdown in [ "no", "off" ]:
fw.config().set_property("Lockdown", "no")
fw.disableLockdown()
else:
cmd.fail("Bad argument")
elif args.item == "log-denied":
fw.setLogDenied(args.log_denied)
elif args.item == "panic":
if args.panic in [ "yes", "on" ]:
fw.enablePanicMode()
elif args.panic in [ "no", "off" ]:
fw.disablePanicMode()
else:
cmd.fail("Bad argument")
else:
cmd.fail("Uncaught argument")
else:
cmd.fail("Uncaught argument")
#############################################################################
# settings
elif args.parser == "settings":
if not hasattr(args, "action"):
grp_settings.print_help()
sys.exit(0)
if args.action == "get":
if not hasattr(args, "item"):
grp_settings_get.print_help()
sys.exit(0)
if args.item == "BRIDGE":
cmd.print_and_exit(("no", "yes")[fw.get_property(args.item)])
elif args.item == "CleanupOnExit":
cmd.print_and_exit(fw.config().get_property(args.item))
elif args.item == "IPSet":
cmd.print_and_exit(("no", "yes")[fw.get_property(args.item)])
elif args.item == "IPSetTypes":
cmd.print_and_exit(" ".join(sorted(fw.get_property(args.item))))
elif args.item == "IPv4":
cmd.print_and_exit(("no", "yes")[fw.get_property(args.item)])
elif args.item == "IPv6":
cmd.print_and_exit(("no", "yes")[fw.get_property(args.item)])
elif args.item == "IPv6_rpfilter":
cmd.print_and_exit(("no", "yes")[fw.get_property(args.item)])
elif args.item == "IndividualCalls":
cmd.print_and_exit(fw.config().get_property(args.item))
elif args.item == "MinimalMark":
cmd.print_and_exit(fw.config().get_property(args.item))
else:
cmd.fail("Uncaught argument")
elif args.action == "list":
props = [ "BRIDGE", "IndividualCalls","IPSet", "IPSetTypes", "IPv4",
"IPv6", "IPv6_rpfilter", "CleanupOnExit", "MinimalMark" ]
l = len(max(props, key=len))
for x in sorted(props):
if x in [ "CleanupOnExit", "MinimalMark", "IndividualCalls" ]:
prop = fw.config().get_property(x)
else:
prop = fw.get_property(x)
if isinstance(prop, list):
prop = " ".join(prop)
elif isinstance(prop, bool):
prop = ("no", "yes")[prop]
cmd.print_msg("%s %s" % (x.ljust(l), prop))
sys.exit(0)
else:
cmd.fail("Uncaught argument")
else:
cmd.fail("Uncaught argument")
# final success
cmd.print_and_exit("success")
|