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
|
/**************************************************************************
*
* CMD.C - Icinga Command CGI
*
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Copyright (c) 2009-2015 Icinga Development Team (http://www.icinga.org)
*
* Last Modified: 08-08-2010
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*************************************************************************/
/** @file cmd.c
* @brief submits commands to Icinga command pipe
**/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/comments.h"
#include "../include/downtime.h"
#include "../include/statusdata.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
#include "../include/getcgi.h"
#include "../include/locations.h"
/** @name External vars
@{ **/
extern const char *extcmd_get_name(int id);
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_cgi_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char command_file[MAX_FILENAME_LENGTH];
extern char comment_file[MAX_FILENAME_LENGTH];
extern int check_external_commands;
extern int use_authentication;
extern int lock_author_names;
extern int persistent_ack_comments;
extern int send_ack_notifications;
extern int default_expiring_acknowledgement_duration;
extern int set_expire_ack_by_default;
extern int set_sticky_acknowledgment;
extern int default_expiring_disabled_notifications_duration;
extern int disable_cmd_cgi_csrf_protection;
extern int display_header;
extern int daemon_check;
extern int enforce_comments_on_actions;
extern int date_format;
extern int use_logging;
extern int default_downtime_duration;
extern scheduled_downtime *scheduled_downtime_list;
extern comment *comment_list;
extern char *status_file_icinga_version;
/** @} */
/** @name LIMITS
@{**/
#define MAX_AUTHOR_LENGTH 64
#define MAX_COMMENT_LENGTH 1024
#define NUMBER_OF_STRUCTS ((MAX_CGI_INPUT_PAIRS*2)+100) /**< Depends on amount of MAX_CGI_INPUT_PAIRS */
/** @}*/
/** @name ELEMET TEMPLATE TYPES
@{**/
#define PRINT_COMMON_HEADER 1
#define PRINT_AUTHOR 2
#define PRINT_STICKY_ACK 3
#define PRINT_PERSISTENT 4
#define PRINT_SEND_NOTFICATION 5
#define PRINT_COMMENT_BOX 6
#define PRINT_NOTIFICATION_DELAY 7
#define PRINT_START_TIME 8
#define PRINT_END_TIME 9
#define PRINT_CHECK_TIME 10
#define PRINT_FORCE_CHECK 11
#define PRINT_CHECK_OUTPUT_BOX 12
#define PRINT_PERFORMANCE_DATA_BOX 13
#define PRINT_FIXED_FLEXIBLE_TYPE 14
#define PRINT_BROADCAST_NOTIFICATION 15
#define PRINT_FORCE_NOTIFICATION 16
#define PRINT_EXPIRE_ACKNOWLEDGEMENT 17
#define PRINT_EXPIRE_DISABLE_NOTIFICATIONS 18
/** @}*/
/** @name OBJECT LIST TYPES
@{**/
#define PRINT_HOST_LIST 19
#define PRINT_SERVICE_LIST 20
#define PRINT_COMMENT_LIST 21
#define PRINT_DOWNTIME_LIST 22
/** @}*/
/** @brief host/service list structure
*
* Struct to hold information of hosts and services for batch processing
**/
struct hostlist {
char *host_name;
char *description;
};
/** @brief error list structure
*
* hold the errors we find during processing of @ref commit_command_data
**/
struct errorlist {
char *message;
};
/** @name Internal vars
@{ **/
char *host_name = ""; /**< requested host name */
char *hostgroup_name = ""; /**< requested hostgroup name */
char *servicegroup_name = ""; /**< requested servicegroup name */
char *service_desc = ""; /**< requested service name */
char *comment_author = ""; /**< submitted comment author */
char *comment_data = ""; /**< submitted comment data */
char *start_time_string = ""; /**< the requested start time */
char *end_time_string = ""; /**< the requested end time */
char help_text[MAX_INPUT_BUFFER] = ""; /**< help string */
char plugin_output[MAX_INPUT_BUFFER] = ""; /**< plugin output text for passive submitted check */
char performance_data[MAX_INPUT_BUFFER] = ""; /**< plugin performance data for passive submitted check */
int notification_delay = 0; /**< delay for submitted notification in minutes */
int schedule_delay = 0; /**< delay for sheduled actions in minutes (Icinga restart, Notfications enable/disable)
!not implemented in GUI! */
int persistent_comment = FALSE; /**< bool if comment should survive Icinga restart */
int sticky_ack = TRUE; /**< bool to disable notifications until recover */
int send_notification = FALSE; /**< bool sends a notification if service gets acknowledged */
int use_ack_end_time = FALSE; /**< bool if expire acknowledgement is selected or not */
int use_disabled_notif_end_time = FALSE; /**< bool if expire disabled notifications is selected or not */
int force_check = FALSE; /**< bool if check should be forced */
int plugin_state = STATE_OK; /**< plugin state for passive submitted check */
int affect_host_and_services = FALSE; /**< bool if notifiactions or else affect all host and services */
int propagate_to_children = FALSE; /**< bool if en/disable host notifications should propagated to children */
int fixed = FALSE; /**< bool if downtime is fixed or flexible */
unsigned long duration = 0L; /**< downtime duration */
unsigned long triggered_by = 0L; /**< downtime id which triggers submited downtime */
int child_options = 0; /**< if downtime should trigger child host downtimes */
int force_notification = 0; /**< force a notification to be send out through event handler */
int broadcast_notification = 0; /**< this options determines if notification should be broadcasted */
int command_type = CMD_NONE; /**< the requested command ID */
int command_mode = CMDMODE_REQUEST; /**< if command mode is request or commit */
time_t start_time = 0L; /**< start time as unix timestamp */
time_t end_time = 0L; /**< end time as unix timestamp */
int CGI_ID = CMD_CGI_ID; /**< ID to identify the cgi for functions in cgiutils.c */
unsigned long attr = MODATTR_NONE; /**< default modified_attributes */
double interval = 1.0; /**< default modified *_interval */
authdata current_authdata; /**< struct to hold current authentication data */
html_request *html_request_list = NULL; /**< contains html requested data */
/** Initialize the struct */
struct hostlist commands[NUMBER_OF_STRUCTS];
/** initialze the error list */
struct errorlist error[NUMBER_OF_STRUCTS];
/** Hold IDs of comments and downtimes */
unsigned long multi_ids[NUMBER_OF_STRUCTS];
/** store the authentication status when data gets checked to submited */
short is_authorized[NUMBER_OF_STRUCTS];
/** store the result of each object which get submited */
short submit_result[NUMBER_OF_STRUCTS];
/** @} */
/** @brief Print form for all details to submit command
* @param [in] cmd ID of requested command
*
* This function generates the form for the command with all requested
* host/services/downtimes/comments items. This is the first page you get
* when you submit a command.
**/
void request_command_data(int);
/** @brief submits the command data and checks for sanity
* @param [in] cmd ID of requested command
*
* This function checks the submitted data (@ref request_command_data)
* for sanity. If everything is alright it passes the data to @ref commit_command.
**/
void commit_command_data(int);
/** @brief checks the authorization and passes the data to cmd_submitf
* @param [in] cmd ID of requested command
* @retval OK
* @retval ERROR
* @return success / fail
*
* Here the command get formatted properly to be readable by icinga
* core. It passes the data to @c cmd_submitf .
**/
int commit_command(int);
/** @brief write the command to Icinga command pipe
* @param [in] cmd the formatted command string
* @retval OK
* @retval ERROR
* @return success / fail
*
* This function actually writes the formatted string into Icinga command pipe.
* And if configured also to Icinga CGI log.
**/
int write_command_to_file(char *);
/** @brief strips out semicolons and newlines from comment data
* @param [in,out] buffer the stringt which should be cleaned
*
* Converts semicolons, newline and carriage return to space.
**/
void clean_comment_data(char *);
/** @brief strips out semicolons and newlines from comment data
* @param [in] element ID of the element which should be printed
* @param [in] cmd ID of requested command
*
* These are templates for the different form elements. Specify
* the element you want to print with element id.
**/
void print_form_element(int, int);
/** @brief print the list of affected objects
* @param [in] list_type ID of the item list which should be printed
*
* Used to print the list of requested objects. Depending on the command
* you can specify the list (HOST/SERVICE/COMMENT/DOWNTIME).
**/
void print_object_list(int);
/** @brief print the mouseover box with help text
* @param [in] content string which should be printed as help box
*
* This writes the mousover help box.
**/
void print_help_box(char *);
/** @brief checks start and end time and if start_time is before end_time
* @param [in] e the error element list
*
* Checks if author or comment is empty. If so it adds an error to error list.
**/
void check_comment_sanity(int*);
/** @brief checks if comment and author are not empty strings
* @param [in] e the error element list
*
* Checks the sanity of given start and end time. Checks if time is
* wrong or start_time is past end_time then if found an error it
* adds an error to error list.
**/
void check_time_sanity(int*);
/** @brief Parses the requested GET/POST variables
*
* @n This function parses the request and set's the necessary variables
**/
void process_cgivars(void);
/** @brief Yes we need a main function **/
int main(void) {
int result = OK;
const char *path;
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE);
document_footer(CGI_ID);
free_html_request(html_request_list);
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE);
document_footer(CGI_ID);
free_html_request(html_request_list);
return ERROR;
}
/* read environment var ICINGA_COMMAND_FILE */
path = get_cmd_file_location();
if (path)
strcpy(command_file, path);
/* This requires the date_format parameter in the main config file */
if (strcmp(start_time_string, ""))
string_to_time(start_time_string, &start_time);
if (strcmp(end_time_string, ""))
string_to_time(end_time_string, &end_time);
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if (result == ERROR) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE);
document_footer(CGI_ID);
free_html_request(html_request_list);
return ERROR;
}
/* read all status data */
result = read_all_status_data(main_config_file, READ_ALL_STATUS_DATA);
if (result == ERROR && daemon_check == TRUE) {
document_header(CGI_ID, FALSE, "Error");
print_error(NULL, ERROR_CGI_STATUS_DATA, FALSE);
document_footer(CGI_ID);
free_memory();
free_html_request(html_request_list);
return ERROR;
}
document_header(CGI_ID, TRUE, "External Command Interface");
/* get authentication information */
get_authentication_information(¤t_authdata);
if (display_header == TRUE) {
/* Giving credits to stop.png image source */
printf("\n<!-- Image \"stop.png\" has been taken from \"http://fedoraproject.org/wiki/Template:Admon/caution\" -->\n\n");
/* begin top table */
printf("<table border='0' width='100%%'>\n");
printf("<tr>\n");
/* left column of the first row */
printf("<td align='left' valign='top' width='33%%'>\n");
display_info_table("External Command Interface", ¤t_authdata, daemon_check);
printf("</td>\n");
/* center column of the first row */
printf("<td align='center' valign='top' width='33%%'>\n");
printf("</td>\n");
/* right column of the first row */
printf("<td align='right' valign='bottom' width='33%%'>\n");
printf("</td>\n");
/* end of top table */
printf("</tr>\n");
printf("</table>\n");
}
/* if no command was specified... */
if (command_type == CMD_NONE) {
print_generic_error_message("Error: No command was specified!", NULL, 2);
}
/* if not authorized to perform commands*/
else if (is_authorized_for_read_only(¤t_authdata) == TRUE) {
print_generic_error_message("Error: It appears as though you do not have permission to perform any commands!", NULL, 1);
}
/* if this is the first request for a command, present option */
else if (command_mode == CMDMODE_REQUEST)
request_command_data(command_type);
/* the user wants to commit the command */
else if (command_mode == CMDMODE_COMMIT)
commit_command_data(command_type);
document_footer(CGI_ID);
/* free allocated memory */
free_html_request(html_request_list);
free_memory();
free_object_data();
return OK;
}
void process_cgivars(void) {
char *temp_buffer = NULL;
char *key = NULL;
char *value = NULL;
int x = 0;
int z = 0;
int sticky_ack_set = FALSE; /* default is TRUE */
html_request *temp_request_item = NULL;
html_request_list = getcgivars();
for (temp_request_item = html_request_list; temp_request_item != NULL; temp_request_item = temp_request_item->next) {
key = temp_request_item->option;
value = temp_request_item->value;
/* we found the command type */
if (!strcmp(key, "cmd_typ") && value != NULL) {
command_type = atoi(value);
temp_request_item->is_valid = TRUE;
}
/* we found the attr */
else if (!strcmp(key, "attr") && value != NULL) {
attr = strtoul(value, NULL, 10);
temp_request_item->is_valid = TRUE;
}
/* we found the attr */
else if (!strcmp(key, "interval") && value != NULL) {
#ifdef HAVE_STRTOF
interval = strtof(value, NULL);
#else
/* Solaris 8 doesn't have strtof() */
interval = (float)strtod(value, NULL);
#endif
temp_request_item->is_valid = TRUE;
}
/* we found the command mode */
else if (!strcmp(key, "cmd_mod") && value != NULL) {
command_mode = atoi(value);
temp_request_item->is_valid = TRUE;
}
/* we found a comment id or a downtime id*/
else if ((!strcmp(key, "com_id") || !strcmp(key, "down_id")) && value != NULL) {
multi_ids[z] = strtoul(value, NULL, 10);
z++;
temp_request_item->is_valid = TRUE;
}
/* we found the notification delay */
else if (!strcmp(key, "not_dly") && value != NULL) {
notification_delay = atoi(value);
temp_request_item->is_valid = TRUE;
}
/* we found the schedule delay */
else if (!strcmp(key, "sched_dly") && value != NULL) {
schedule_delay = atoi(value);
temp_request_item->is_valid = TRUE;
}
/* we found the comment author */
else if (!strcmp(key, "com_author") && value != NULL) {
if ((comment_author = (char *)strdup(value)) == NULL)
comment_author = "";
strip_html_brackets(comment_author);
temp_request_item->is_valid = TRUE;
}
/* we found the comment data */
else if (!strcmp(key, "com_data") && value != NULL) {
if ((comment_data = (char *)strdup(value)) == NULL)
comment_data = "";
strip_html_brackets(comment_data);
temp_request_item->is_valid = TRUE;
}
/* we found the host name */
else if (!strcmp(key, "host") && value != NULL) {
if ((host_name = (char *)strdup(value)) == NULL)
host_name = "";
else {
strip_html_brackets(host_name);
/* Store hostname in struct */
commands[x].host_name = host_name;
x++;
}
temp_request_item->is_valid = TRUE;
}
/* we found the hostgroup name */
else if (!strcmp(key, "hostgroup") && value != NULL) {
if ((hostgroup_name = (char *)strdup(value)) == NULL)
hostgroup_name = "";
strip_html_brackets(hostgroup_name);
temp_request_item->is_valid = TRUE;
}
/* we found the service name */
else if (!strcmp(key, "service") && value != NULL) {
if ((service_desc = (char *)strdup(value)) == NULL)
service_desc = "";
else {
strip_html_brackets(service_desc);
/* Store service description in struct */
commands[(x-1)].description = service_desc;
}
temp_request_item->is_valid = TRUE;
}
/* we found a combined host/service */
else if (!strcmp(key, "hostservice") && value != NULL) {
temp_buffer = strtok(value, "^");
if ((host_name = (char *)strdup(temp_buffer)) == NULL) {
continue;
} else {
strip_html_brackets(host_name);
commands[x].host_name = host_name;
}
temp_buffer = strtok(NULL, "");
if ((service_desc = (char *)strdup(temp_buffer)) == NULL) {
my_free(commands[x].host_name);
continue;
} else {
strip_html_brackets(service_desc);
commands[x].description = service_desc;
}
x++;
temp_request_item->is_valid = TRUE;
}
/* we found the servicegroup name */
else if (!strcmp(key, "servicegroup") && value != NULL) {
if ((servicegroup_name = (char *)strdup(value)) == NULL)
servicegroup_name = "";
strip_html_brackets(servicegroup_name);
temp_request_item->is_valid = TRUE;
}
/* we got the persistence option for a comment */
else if (!strcmp(key, "persistent")) {
persistent_comment = TRUE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we got the notification option for an acknowledgement */
else if (!strcmp(key, "send_notification")) {
send_notification = (atoi(value) > 0) ? TRUE : FALSE;
/* if the value was omitted, assume it is enabled */
if (value == NULL)
send_notification = TRUE;
temp_request_item->is_valid = TRUE;
}
/* we got the acknowledgement type */
else if (!strcmp(key, "sticky_ack")) {
sticky_ack_set = (atoi(value) > 0) ? TRUE : FALSE;
/* if the value was omitted, assume it is enabled */
if (value == NULL)
sticky_ack_set = TRUE;
temp_request_item->is_valid = TRUE;
}
/* we use the end_time as expire time */
else if (!strcmp(key, "use_ack_end_time")) {
use_ack_end_time = TRUE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we use the end_time as disabled notifcations expire time */
else if (!strcmp(key, "use_disabled_notif_end_time")) {
use_disabled_notif_end_time = TRUE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we got the service check force option */
else if (!strcmp(key, "force_check")) {
force_check = TRUE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we got the option to affect host and all its services */
else if (!strcmp(key, "ahas")) {
affect_host_and_services = TRUE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we got the option to propagate to child hosts */
else if (!strcmp(key, "ptc")) {
propagate_to_children = TRUE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we got the option for fixed downtime */
else if (!strcmp(key, "fixed") && value != NULL) {
fixed = (atoi(value) > 0) ? TRUE : FALSE;
temp_request_item->is_valid = TRUE;
}
/* we got the triggered by downtime option */
else if (!strcmp(key, "trigger") && value != NULL) {
triggered_by = strtoul(value, NULL, 10);
temp_request_item->is_valid = TRUE;
}
/* we got the child options */
else if (!strcmp(key, "childoptions") && value != NULL) {
child_options = atoi(value);
temp_request_item->is_valid = TRUE;
}
/* we found the plugin output */
else if (!strcmp(key, "plugin_output") && value != NULL) {
strncpy(plugin_output, value, MAX_INPUT_BUFFER);
temp_request_item->is_valid = TRUE;
}
/* we found the performance data */
else if (!strcmp(key, "performance_data") && value != NULL) {
strncpy(performance_data, value, MAX_INPUT_BUFFER);
temp_request_item->is_valid = TRUE;
}
/* we found the plugin state */
else if (!strcmp(key, "plugin_state") && value != NULL) {
plugin_state = atoi(value);
temp_request_item->is_valid = TRUE;
}
/* we found the hour duration */
else if (!strcmp(key, "hours") && value != NULL) {
if (atoi(value) < 0) {
continue;
}
duration += (unsigned long)(atoi(value) * 3600);
temp_request_item->is_valid = TRUE;
}
/* we found the minute duration */
else if (!strcmp(key, "minutes") && value != NULL) {
if (atoi(value) < 0) {
continue;
}
duration += (unsigned long)(atoi(value) * 60);
temp_request_item->is_valid = TRUE;
}
/* we found the start time */
else if (!strcmp(key, "start_time") && value != NULL) {
if ((start_time_string = (char *)strdup(value)) == NULL) {
start_time_string = "";
}
temp_request_item->is_valid = TRUE;
}
/* we found the end time */
else if (!strcmp(key, "end_time") && value != NULL) {
if ((end_time_string = (char *)strdup(value)) == NULL) {
end_time_string = "";
}
temp_request_item->is_valid = TRUE;
}
/* we found the forced notification option */
else if (!strcmp(key, "force_notification")) {
force_notification = NOTIFICATION_OPTION_FORCED;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we found the broadcast notification option */
else if (!strcmp(key, "broadcast_notification")) {
broadcast_notification = NOTIFICATION_OPTION_BROADCAST;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
/* we got the persistence option for a comment */
else if (!strcmp(key, "nodaemoncheck")) {
daemon_check = FALSE;
temp_request_item->is_valid = TRUE;
my_free(temp_request_item->value);
}
}
if (command_mode == CMDMODE_COMMIT) {
sticky_ack = sticky_ack_set;
}
return;
}
void print_object_list(int list_type) {
hoststatus *temp_hoststatus = NULL;
servicestatus *temp_servicestatus = NULL;
int x = 0;
int row_color = 0;
int host_passive = FALSE;
int service_passive = FALSE;
printf("<tr><td colspan='2'> </td></tr>\n");
printf("<tr class=\"sectionHeader\"><td colspan='2' >Affected Objects</td></tr>\n");
printf("<tr><td colspan='2'>\n");
printf("<script language='javascript' type=\"text/javascript\">\nchecked=false;\n");
printf("function checkAllBoxes() {\n"
" checked = (checked == false) ? true : false;\n"
" for (var i=0; i < %d; i++) {\n"
" var checkboxes = document.getElementById(\"cb_\" + i);\n"
" if (checkboxes != null ) { checkboxes.checked = checked; }\n"
" }\n"
"}\n", NUMBER_OF_STRUCTS);
printf("</script>\n");
printf("<table cellspacing='2' cellpadding='0' border='0' width='100%%'>\n");
if (list_type == PRINT_SERVICE_LIST)
printf("<tr class=\"objectTableHeader\"><td width=\"46%%\">Host</td><td width=\"46%%\">Service</td><td width='16'><input type='checkbox' onclick=\"checkAllBoxes();\" title=\"Check All\"></td></tr>\n");
else if (list_type == PRINT_HOST_LIST)
printf("<tr class=\"objectTableHeader\"><td colspan='2' width=\"96%%\">Hosts</td><td width='16'><input type='checkbox' onclick=\"checkAllBoxes();\" title=\"Check All\"></td></tr>\n");
else
printf("<tr><td colspan='3'> </td></tr>\n");
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (list_type == PRINT_HOST_LIST || list_type == PRINT_SERVICE_LIST) {
host_passive = FALSE;
service_passive = FALSE;
if (commands[x].host_name == NULL)
continue;
if (list_type == PRINT_SERVICE_LIST && commands[x].description == NULL)
continue;
if (strlen(commands[x].host_name) != 0 && (
command_type == CMD_SCHEDULE_HOST_CHECK ||
command_type == CMD_DISABLE_HOST_CHECK ||
command_type == CMD_SCHEDULE_SVC_CHECK ||
command_type == CMD_DISABLE_SVC_CHECK )) {
if((temp_hoststatus = find_hoststatus(commands[x].host_name)) != NULL) {
if (temp_hoststatus->checks_enabled == FALSE)
host_passive = TRUE;
}
if (list_type == PRINT_SERVICE_LIST && strlen(commands[x].description) != 0 ) {
if((temp_servicestatus = find_servicestatus(commands[x].host_name, commands[x].description)) != NULL) {
if (temp_servicestatus->checks_enabled == FALSE)
service_passive = TRUE;
}
}
}
} else {
if (multi_ids[x] == FALSE)
continue;
}
row_color = (row_color == 0) ? 1 : 0;
printf("<tr class=\"status%s\"><td width=\"50%%\"", (row_color == 0) ? "Even" : "Odd ");
if (list_type == PRINT_SERVICE_LIST) {
/* hostname and service description are present */
if (strlen(commands[x].host_name) != 0 && strlen(commands[x].description) != 0) {
printf(">%s</td><td>%s",
escape_string(commands[x].host_name), escape_string(commands[x].description)
);
if (service_passive == TRUE) {
printf("<img src='%s%s' align='right' border='0' style='padding-right:2px' alt='Passive' title='Passive Service'>",
url_images_path, PASSIVE_ICON
);
}
printf("</td>\n");
printf("<td align='center'><input type='checkbox' name='hostservice' id=\"cb_%d\" value='%s^%s' title=\"%s Service\" %s></td></tr>\n",
x, escape_string(commands[x].host_name), escape_string(commands[x].description),
(service_passive == FALSE) ? "Active" : "Passive", (service_passive == FALSE) ? "checked" : "");
} else {
/* if hostname is empty print inputbox instead */
if (!strcmp(commands[x].host_name, ""))
printf("><input type='text' name='host' size='30'></td>");
else
printf("><input type='hidden' name='host' value='%s'>%s</td>", escape_string(commands[x].host_name), escape_string(commands[x].host_name));
/* if service description is empty print inputbox instead */
if (!strcmp(commands[x].description, ""))
printf("<td><input type='text' name='service' size='30'></td>");
else
printf("<td><input type='hidden' name='service' value='%s'>%s</td>", escape_string(commands[x].description), escape_string(commands[x].description));
printf("<td></td></tr>\n");
}
} else if (list_type == PRINT_HOST_LIST) {
/* if hostname is empty print inputbox instead */
if (!strcmp(commands[x].host_name, ""))
printf(" style=\"font-weight:bold;\">Host:</td><td><input type='text' name='host' size='30'></td><td></td></tr>\n");
else {
printf(" style=\"font-weight:bold;\">Host:</td><td>%s", escape_string(commands[x].host_name));
if (host_passive == TRUE) {
printf("<img src='%s%s' align='right' border='0' style='padding-right:2px' alt='Passive' title='Passive Service'>",
url_images_path, PASSIVE_ICON
);
}
printf("</td>\n");
printf("<td align='center'><input type='checkbox' name='host' id=\"cb_%d\" value='%s' title=\"%s Host\" %s></td></tr>\n",
x, escape_string(commands[x].host_name),
(host_passive == FALSE) ? "Active" : "Passive", (host_passive == FALSE) ? "checked" : ""
);
}
} else if (list_type == PRINT_COMMENT_LIST) {
printf(" style=\"font-weight:bold;\">Comment ID:</td><td><input type='hidden' name='com_id' value='%lu'>%lu</td></tr>\n", multi_ids[x], multi_ids[x]);
} else if (list_type == PRINT_DOWNTIME_LIST) {
printf(" style=\"font-weight:bold;\">Scheduled Downtime ID:</td><td><input type='hidden' name='down_id' value='%lu'>%lu</td></tr>\n", multi_ids[x], multi_ids[x]);
}
}
printf("</td><tr></table>\n</td></tr>\n");
return;
}
void print_help_box(char *content) {
printf("<img src='%s%s' onMouseOver=\"return tooltip('<table border=0 width=100%% height=100%%>", url_images_path, CONTEXT_HELP_ICON);
printf("<tr><td>%s</td></tr>", content);
printf("</table>', ' Help', 'border:1, width:500, xoffset:-250, yoffset:25, bordercolor:#333399, title_padding:2px, titletextcolor:#FFFFFF, backcolor:#CCCCFF');\" onMouseOut=\"return hideTip()\"");
printf(" border='0'>");
return;
}
void print_form_element(int element, int cmd) {
time_t t;
int t_hour, t_min;
char buffer[MAX_INPUT_BUFFER];
switch (element) {
case PRINT_COMMON_HEADER:
printf("<tr><td colspan='2'> </td></tr>\n");
printf("<tr><td colspan='2' class='sectionHeader'>Common Data</td></tr>\n");
printf("<tr><td colspan='2'> </td></tr>\n");
break;
case PRINT_AUTHOR:
printf("<tr><td class=\"objectDescription descriptionleft\">Author (Your Name):</td><td align='left'>");
if (lock_author_names == TRUE)
printf("<input type='hidden' name='com_author' value='%s'>%s</td></tr>\n", escape_string(comment_author), escape_string(comment_author));
else
printf("<input type='input' name='com_author' value='%s'></td></tr>\n", escape_string(comment_author));
break;
case PRINT_COMMENT_BOX:
strcpy(help_text, "If you work with other administrators, you may find it useful to share information about a host/service "
"that is having problems if more than one of you may be working on it. "
"Make sure to enter a brief description of what you are doing.");
printf("<tr><td class=\"objectDescription descriptionleft\">Comment:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<textarea id=\"com_data\" name='com_data' cols='25' rows='2' onkeyup=\"check_input();\">%s</textarea>", escape_string(comment_data));
printf("<br><div id='com_data_error' class=\"inputError\" style=\"display:none;\">Comment data can't be sent empty</div>");
printf("</td></tr>\n");
break;
case PRINT_CHECK_OUTPUT_BOX:
snprintf(help_text, sizeof(help_text), "Fill in the exact output string which sould be sent to %s", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr><td class=\"objectDescription descriptionleft\">Check Output:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<textarea id=\"plugin_output\" name='plugin_output' cols='25' rows='2' onkeyup=\"check_input();\"></textarea>");
printf("<br><div id='plugin_output_error' class=\"inputError\" style=\"display:none;\">Output string can't be send empty</div>");
printf("</td></tr>\n");
break;
case PRINT_PERFORMANCE_DATA_BOX:
snprintf(help_text, sizeof(help_text), "Fill in the exact performance data string which sould be sent to %s", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr><td class=\"objectDescription descriptionleft\">Performance Data:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<textarea name='performance_data' cols='25' rows='2'></textarea></td></tr>\n");
break;
case PRINT_STICKY_ACK:
strcpy(help_text, "If you want acknowledgement to disable notifications until the host/service recovers, check this option.");
printf("<tr><td id=\"sticky_ack_row\" class=\"objectDescription descriptionleft\">Sticky Acknowledgement:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<input type='checkbox' id='sticky_ack_checkbox' name='sticky_ack' value='1' %s></td></tr>\n", (set_sticky_acknowledgment == TRUE) ? "CHECKED" : "");
break;
case PRINT_SEND_NOTFICATION:
strcpy(help_text, "If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck this option.");
printf("<tr><td class=\"objectDescription descriptionleft\">Send Notification:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<input type='checkbox' name='send_notification' value='1' %s></td></tr>\n", (send_ack_notifications == TRUE) ? "CHECKED" : "");
break;
case PRINT_PERSISTENT:
if (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM || cmd == CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM)
strcpy(help_text, "If you would like the comment to remain once the acknowledgement is removed, check this checkbox.");
else {
snprintf(help_text, sizeof(help_text), "If you uncheck this option, the comment will automatically be deleted the next time %s is restarted.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
}
printf("<tr><td class=\"objectDescription descriptionleft\">Persistent%s:", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM || cmd == CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM) ? " Comment" : "");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<input type='checkbox' name='persistent' %s></td></tr>\n", (persistent_ack_comments == TRUE || cmd == CMD_ADD_HOST_COMMENT || cmd == CMD_ADD_SVC_COMMENT) ? "CHECKED" : "");
break;
case PRINT_NOTIFICATION_DELAY:
strcpy(help_text, "The notification delay will be disregarded if the host/service changes state before the next notification is scheduled to be sent out.");
printf("<tr><td class=\"objectDescription descriptionleft\">Notification Delay (minutes from now):");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<input type='text' id='not_dly' name='not_dly' value='%d' size='4'>", notification_delay);
printf("<br><div id='not_dly_error' class=\"inputError\" style=\"display:none;\">Notification delay can't be zero</div>");
printf("</td></tr>\n");
break;
case PRINT_START_TIME:
case PRINT_END_TIME:
case PRINT_CHECK_TIME:
time(&t);
if (element == PRINT_END_TIME)
t += (unsigned long)default_downtime_duration;
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr><td class=\"objectDescription descriptionleft\">");
if (element == PRINT_START_TIME) {
strcpy(help_text, "Set the start date/time for the downtime.");
printf("Start Time:");
} else if (element == PRINT_END_TIME) {
strcpy(help_text, "Set the end date/time for the downtime.");
printf("End Time:");
} else {
strcpy(help_text, "Set the date/time when this check should be schedule to.");
printf("Check Time:");
}
print_help_box(help_text);
printf("</td><td align='left'><input type='text' class='timepicker' name='%s_time' value='%s' size='25'></td></tr>\n", (element == PRINT_END_TIME) ? "end" : "start", buffer);
break;
case PRINT_FIXED_FLEXIBLE_TYPE:
default_downtime_duration = default_downtime_duration / 60;
t_min = default_downtime_duration % 60;
default_downtime_duration = default_downtime_duration - t_min;
t_hour = (default_downtime_duration / 60) ;
snprintf(help_text, sizeof(help_text), "If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i> "
"option, %s will treat this as <i>flexible</i> downtime. Flexible downtime starts when the host goes down or becomes unreachable / service becomes critical (sometime between the "
"start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr><td class=\"objectDescription descriptionleft\">Type:");
print_help_box(help_text);
printf("</td><td align='left'>\n");
printf("\t<select id=\"flexible_selection\" name='fixed' onChange=\"if (document.getElementById('flexible_selection').selectedIndex == 0) document.getElementById('fd_row').style.display = 'none'; else document.getElementById('fd_row').style.display = '';\">\n");
printf("\t\t<option value='1'\">Fixed</option>\n");
printf("\t\t<option value='0'\">Flexible</option>\n");
printf("\t</select>\n");
snprintf(help_text, sizeof(help_text), "Enter here the duration of the downtime. %s will automatically delete the downtime after this time expired.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr id=\"fd_row\" style=\"display:none;\"><td class=\"objectDescription descriptionleft\">Flexible Duration:");
print_help_box(help_text);
printf("</td><td align='left'>\n");
printf("\t<table border='0' cellspacing='0' cellpadding='0'>\n");
printf("\t\t<tr>\n");
printf("\t\t\t<td><input type='text' name='hours' value='%d' size='4' maxlength='4'></td>\n", t_hour);
printf("\t\t\t<td width=\"50\"> Hours</td>\n");
printf("\t\t\t<td><input type='text' name='minutes' value='%d' size='2' maxlength='2'></td>\n", t_min);
printf("\t\t\t<td width=\"50\"> Minutes</td>\n");
printf("\t\t</tr>\n");
printf("\t</table>\n");
printf("</td></tr>\n");
break;
case PRINT_EXPIRE_ACKNOWLEDGEMENT:
strcpy(help_text, "If you want to let the acknowledgement expire, check this option.");
printf("<tr><td class=\"objectDescription descriptionleft\">Use Expire Time:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<input type='checkbox' id='expire_checkbox' name='use_ack_end_time' onClick=\"if (document.getElementById('expire_checkbox').checked == true) document.getElementById('expired_date_row').style.display = ''; else document.getElementById('expired_date_row').style.display = 'none';\" %s></td></tr>\n", (set_expire_ack_by_default == TRUE || use_ack_end_time == TRUE) ? "CHECKED" : "");
snprintf(help_text, sizeof(help_text), "Enter here the expire date/time for this acknowledgement. %s will automatically delete the acknowledgement after this time expired.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
time(&t);
t += (unsigned long)default_expiring_acknowledgement_duration;
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr id=\"expired_date_row\" style=\"display:%s;\"><td class=\"objectDescription descriptionleft\">Expire Time:", (set_expire_ack_by_default == TRUE || use_ack_end_time == TRUE) ? "" : "none");
print_help_box(help_text);
printf("</td><td align='left'><input type='text' class='timepicker' name='end_time' value='%s' size='25'></td></tr>\n", buffer);
break;
case PRINT_EXPIRE_DISABLE_NOTIFICATIONS:
strcpy(help_text, "If you want to let the disabled notifications expire, check this option.");
printf("<tr><td class=\"objectDescription descriptionleft\">Use Expire Time:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<input type='checkbox' id='expire_checkbox' name='use_disabled_notif_end_time' onClick=\"if (document.getElementById('expire_checkbox').checked == true) document.getElementById('expired_date_row').style.display = ''; else document.getElementById('expired_date_row').style.display = 'none';\"></td></tr>\n");
snprintf(help_text, sizeof(help_text), "Enter the expire date/time for disabled notifications. %s will automatically re-enable all notifications after this time expired.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
time(&t);
t += (unsigned long)default_expiring_disabled_notifications_duration;
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr id=\"expired_date_row\" style=\"display:none;\"><td class=\"objectDescription descriptionleft\">Expire Time:");
print_help_box(help_text);
printf("</td><td align='left'><input type='text' class='timepicker' name='end_time' value='%s' size='25'></td></tr>\n", buffer);
break;
case PRINT_FORCE_CHECK:
snprintf(help_text, sizeof(help_text), "If you select this option, %s will force a check of the host/service regardless of both what time the scheduled check occurs and whether or not checks are enabled for the host/service.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr><td class=\"objectDescription descriptionleft\">Force Check:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<input type='checkbox' name='force_check' %s></td></tr>\n", (force_check == TRUE) ? "CHECKED" : "");
break;
case PRINT_BROADCAST_NOTIFICATION:
strcpy(help_text, "Selecting this option causes the notification to be sent out to all normal (non-escalated) and escalated contacts. These options allow you to override the normal notification logic if you need to get an important message out.");
printf("<tr><td class=\"objectDescription descriptionleft\">Broadcast:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<input type='checkbox' name='broadcast_notification'></td></tr>\n");
break;
case PRINT_FORCE_NOTIFICATION:
snprintf(help_text, sizeof(help_text), "Custom notifications normally follow the regular notification logic in %s. Selecting this option will force the notification to be sent out, regardless of the time restrictions, whether or not notifications are enabled, etc.", PROGRAM_NAME);
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr><td class=\"objectDescription descriptionleft\">Forced:");
print_help_box(help_text);
printf("</td><td align='left'>");
printf("<input type='checkbox' name='force_notification'></td></tr>\n");
break;
default:
break;
}
return;
}
void request_command_data(int cmd) {
char start_time[MAX_DATETIME_LENGTH];
contact *temp_contact;
scheduled_downtime *temp_downtime;
host *temp_host = NULL;
char action[MAX_INPUT_BUFFER];
int found_trigger_objects = FALSE;
/* get default name to use for comment author */
temp_contact = find_contact(current_authdata.username);
if (temp_contact != NULL && temp_contact->alias != NULL)
comment_author = temp_contact->alias;
else
comment_author = current_authdata.username;
printf("<br>");
switch (cmd) {
case CMD_ADD_HOST_COMMENT:
case CMD_ADD_SVC_COMMENT:
snprintf(action, sizeof(action), "Add %s comments", (cmd == CMD_ADD_HOST_COMMENT) ? "host" : "service");
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
snprintf(action, sizeof(action), "Delete %s comments", (cmd == CMD_DEL_HOST_COMMENT) ? "host" : "service");
break;
case CMD_DELAY_HOST_NOTIFICATION:
case CMD_DELAY_SVC_NOTIFICATION:
snprintf(help_text, sizeof(help_text), "This command is used to delay the next problem notification that is sent out for specified %s. The notification delay will be disregarded if "
"the %s changes state before the next notification is scheduled to be sent out. This command has no effect if the %s are currently %s.", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "hosts" : "services", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "hosts" : "services", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "hosts" : "services", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "UP" : "in an OK state");
snprintf(action, sizeof(action), "Delay a %s notification", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "host" : "service");
break;
case CMD_SCHEDULE_HOST_CHECK:
case CMD_SCHEDULE_SVC_CHECK:
snprintf(help_text, sizeof(help_text), "This command is used to schedule the next check of these %s. %s will re-queue the %s to be checked at the time you specify.", (cmd == CMD_SCHEDULE_HOST_CHECK) ? "hosts" : "services", PROGRAM_NAME, (cmd == CMD_SCHEDULE_HOST_CHECK) ? "host" : "service");
snprintf(action, sizeof(action), "Schedule %s checks", (cmd == CMD_SCHEDULE_HOST_CHECK) ? "host" : "service");
break;
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
snprintf(action, sizeof(action), "%s active service checks on a program-wide basis", (cmd == CMD_ENABLE_SVC_CHECK) ? "Enable" : "Disable");
break;
case CMD_ENABLE_NOTIFICATIONS:
case CMD_DISABLE_NOTIFICATIONS:
snprintf(help_text, sizeof(help_text), "This command is used to %s host and service notifications on a program-wide basis", (cmd == CMD_ENABLE_NOTIFICATIONS) ? "enable" : "disable");
snprintf(action, sizeof(action), "%s notifications on a program-wide basis", (cmd == CMD_ENABLE_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_DISABLE_NOTIFICATIONS_EXPIRE_TIME:
snprintf(help_text, sizeof(help_text), "This command is used to disable host and service notifications on a program-wide basis, with a given expire time");
snprintf(action, sizeof(action), "Disable notifications on a program-wide basis, with expire time");
break;
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
snprintf(action, sizeof(action), "%s the %s process", (cmd == CMD_SHUTDOWN_PROCESS) ? "Shutdown" : "Restart", PROGRAM_NAME);
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
if (cmd == CMD_ENABLE_HOST_SVC_CHECKS)
snprintf(help_text, sizeof(help_text), "This command is used to enable active checks of all services associated with the specified host");
else {
snprintf(help_text, sizeof(help_text), "This command is used to disable active checks of all services associated with the specified host. "
"When a service is disabled %s will not monitor the service. Doing this will prevent any notifications being sent out for "
"the specified service while it is disabled. In order to have %s check the service in the future you will have to re-enable the service. "
"Note that disabling service checks may not necessarily prevent notifications from being sent out about the host which those services are associated with.", PROGRAM_NAME, PROGRAM_NAME);
}
snprintf(action, sizeof(action), "%s active checks of all services on these hosts", (cmd == CMD_ENABLE_HOST_SVC_CHECKS) ? "Enable" : "Disable");
break;
case CMD_SCHEDULE_HOST_SVC_CHECKS:
snprintf(action, sizeof(action), "Schedule a check of all services for these hosts");
break;
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_DEL_ALL_SVC_COMMENTS:
snprintf(action, sizeof(action), "Delete all comments for these %s", (cmd == CMD_DEL_ALL_HOST_COMMENTS) ? "hosts" : "services");
break;
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for these services", (cmd == CMD_ENABLE_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for these hosts", (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
snprintf(help_text, sizeof(help_text), "This command is used to %s notifications for all hosts and services that lie <i>beyond</i> the specified host (from the view of %s).", (cmd == CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST) ? "enable" : "disable", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s notifications for all hosts and services beyond these hosts", (cmd == CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all services on these hosts", (cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
case CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM:
snprintf(action, sizeof(action), "Acknowledge %s problems%s", (cmd != CMD_ACKNOWLEDGE_SVC_PROBLEM) ? "host" : "service", (cmd == CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM) ? " and all services" : "");
break;
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
snprintf(action, sizeof(action), "%s executing host checks on a program-wide basis", (cmd == CMD_START_EXECUTING_HOST_CHECKS) ? "Start" : "Stop");
break;
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
if (cmd == CMD_START_EXECUTING_SVC_CHECKS)
snprintf(help_text, sizeof(help_text), "This command is used to resume execution of active service checks on a program-wide basis. Individual services which are disabled will still not be checked.");
else
snprintf(help_text, sizeof(help_text), "This command is used to temporarily stop %s from actively executing any service checks. This will have the side effect of preventing any notifications from being sent out (for any and all services and hosts). "
"Service checks will not be executed again until you issue a command to resume service check execution.", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s executing active service checks", (cmd == CMD_START_EXECUTING_SVC_CHECKS) ? "Start" : "Stop");
break;
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
snprintf(help_text, sizeof(help_text), "This command is used to make %s %s accepting passive service check results that it finds in the external command file.", PROGRAM_NAME, (cmd == CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS) ? "start" : "stop");
snprintf(action, sizeof(action), "%s accepting passive service checks on a program-wide basis", (cmd == CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS) ? "Start" : "Stop");
break;
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
if (cmd == CMD_ENABLE_PASSIVE_SVC_CHECKS)
snprintf(help_text, sizeof(help_text), "This command is used to allow %s to accept passive service check results that it finds in the external command file for this particular service.", PROGRAM_NAME);
else
snprintf(help_text, sizeof(help_text), "This command is used to stop %s accepting passive service check results that it finds in the external command file for this particular service. All passive check results that are found for this service will be ignored.", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s accepting passive service checks for these services", (cmd == CMD_ENABLE_PASSIVE_SVC_CHECKS) ? "Start" : "Stop");
break;
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
if (cmd == CMD_ENABLE_EVENT_HANDLERS)
snprintf(help_text, sizeof(help_text), "This command is used to allow %s to run host and service event handlers.", PROGRAM_NAME);
else
snprintf(help_text, sizeof(help_text), "This command is used to temporarily prevent %s from running any host or service event handlers.", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s event handlers on a program-wide basis", (cmd == CMD_ENABLE_EVENT_HANDLERS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
snprintf(help_text, sizeof(help_text), "This command is used to %s the event handler for the selected hosts", (cmd == CMD_ENABLE_HOST_EVENT_HANDLER) ? "enable" : "disable");
snprintf(action, sizeof(action), "%s the event handler for these hosts", (cmd == CMD_ENABLE_HOST_EVENT_HANDLER) ? "Enable" : "Disable");
break;
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
snprintf(help_text, sizeof(help_text), "This command is used to %s the event handler for the selected services", (cmd == CMD_ENABLE_SVC_EVENT_HANDLER) ? "enable" : "disable");
snprintf(action, sizeof(action), "%s the event handler for these services", (cmd == CMD_ENABLE_SVC_EVENT_HANDLER) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
if (cmd == CMD_DISABLE_HOST_CHECK)
snprintf(help_text, sizeof(help_text), "This command is used to temporarily prevent %s from actively checking the status of a particular host. If %s needs to check the status of this host, it will assume that it is in the same state that it was in before checks were disabled.", PROGRAM_NAME, PROGRAM_NAME);
snprintf(action, sizeof(action), "%s active host checks", (cmd == CMD_ENABLE_HOST_CHECK) ? "Enable" : "Disable");
break;
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
if (cmd == CMD_START_OBSESSING_OVER_SVC_CHECKS)
snprintf(help_text, sizeof(help_text), "This command is used to have %s start obsessing over service checks. Read the documentation on distributed monitoring for more information on this.", PROGRAM_NAME);
snprintf(action, sizeof(action), "%s obsessing over service checks on a program-wide basis", (cmd == CMD_STOP_OBSESSING_OVER_SVC_CHECKS) ? "Stop" : "Start");
break;
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
snprintf(help_text, sizeof(help_text), "This command is used to remove an acknowledgement for %s problems. Once the acknowledgement is removed, notifications may start being "
"sent out about the %s problem.", (cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT) ? "host" : "service", (cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT) ? "host" : "service");
snprintf(action, sizeof(action), "Remove %s acknowledgements", (cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT) ? "host" : "service");
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_SVC_DOWNTIME:
snprintf(help_text, sizeof(help_text), "This command is used to schedule downtime for these %s. During the specified downtime, %s will not send notifications out about the %s. "
"When the scheduled downtime expires, %s will send out notifications for this %s as it normally would. Scheduled downtimes are preserved "
"across program shutdowns and restarts.", (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "hosts" : "services", PROGRAM_NAME, (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "hosts" : "services", PROGRAM_NAME, (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "hosts" : "services");
snprintf(action, sizeof(action), "Schedule downtime for these %s", (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "hosts" : "services");
break;
case CMD_DEL_DOWNTIME_BY_HOST_NAME:
snprintf(help_text, sizeof(help_text), "This command is used to delete all downtimes for a host and all its services specified by the host name already supplied.");
snprintf(action, sizeof(action), "Remove downtimes for all services for these hosts and the hosts themself");
break;
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
snprintf(help_text, sizeof(help_text), "This command is used to schedule downtime for a particular host and all of its services. During the specified downtime, %s will not send notifications out about the host. "
"Normally, a host in downtime will not send alerts about any services in a failed state. This option will explicitly set downtime for all services for this host. "
"When the scheduled downtime expires, %s will send out notifications for this host as it normally would. Scheduled downtimes are preserved "
"across program shutdowns and restarts.", PROGRAM_NAME, PROGRAM_NAME);
snprintf(action, sizeof(action), "Schedule downtime for all services for these hosts and the hosts themself");
break;
case CMD_PROCESS_HOST_CHECK_RESULT:
case CMD_PROCESS_SERVICE_CHECK_RESULT:
snprintf(help_text, sizeof(help_text), "This command is used to submit a passive check result for these %s. "
"It is particularly useful for resetting security-related %s to %s states once they have been dealt with.", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "hosts" : "services", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "hosts" : "services", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "UP" : "OK");
snprintf(action, sizeof(action), "Submit a passive check result for these %s", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "hosts" : "services");
break;
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
snprintf(action, sizeof(action), "%s flap detection for these hosts", (cmd == CMD_ENABLE_HOST_FLAP_DETECTION) ? "Enable" : "Disable");
break;
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
snprintf(action, sizeof(action), "%s flap detection for these services", (cmd == CMD_ENABLE_SVC_FLAP_DETECTION) ? "Enable" : "Disable");
break;
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
snprintf(action, sizeof(action), "%s flap detection for hosts and services on a program-wide basis", (cmd == CMD_ENABLE_FLAP_DETECTION) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all services in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all hosts in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
snprintf(action, sizeof(action), "%s active checks of all services in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS) ? "Enable" : "Disable");
break;
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
snprintf(action, sizeof(action), "Cancel scheduled downtime for these %s", (cmd == CMD_DEL_HOST_DOWNTIME) ? "hosts" : "services");
break;
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
snprintf(action, sizeof(action), "%s failure prediction for hosts and service on a program-wide basis", (cmd == CMD_ENABLE_FAILURE_PREDICTION) ? "Enable" : "Disable");
break;
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
snprintf(action, sizeof(action), "%s performance data processing for hosts and services on a program-wide basis", (cmd == CMD_ENABLE_PERFORMANCE_DATA) ? "Enable" : "Disable");
break;
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
snprintf(action, sizeof(action), "Schedule downtime for all %s in a particular hostgroup", (cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME) ? "hosts" : "services");
break;
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
snprintf(action, sizeof(action), "%s accepting passive host checks on a program-wide basis", (cmd == CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS) ? "Start" : "Stop");
break;
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
snprintf(action, sizeof(action), "%s accepting passive checks for these hosts", (cmd == CMD_ENABLE_PASSIVE_HOST_CHECKS) ? "Start" : "Stop");
break;
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
snprintf(action, sizeof(action), "%s obsessing over host checks on a program-wide basis", (cmd == CMD_START_OBSESSING_OVER_HOST_CHECKS) ? "Start" : "Stop");
break;
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
snprintf(action, sizeof(action), "%s obsessing over these services", (cmd == CMD_START_OBSESSING_OVER_SVC) ? "Start" : "Stop");
break;
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
snprintf(action, sizeof(action), "%s obsessing over these hosts", (cmd == CMD_START_OBSESSING_OVER_HOST) ? "Start" : "Stop");
break;
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all services in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
snprintf(action, sizeof(action), "%s notifications for all hosts in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
break;
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
snprintf(action, sizeof(action), "%s active checks of all services in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS) ? "Enable" : "Disable");
break;
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
snprintf(action, sizeof(action), "Schedule downtime for all hosts in a particular servicegroup");
break;
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
snprintf(action, sizeof(action), "Schedule downtime for all services in a particular servicegroup");
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
snprintf(help_text, sizeof(help_text), "This command is used to send a custom notification about the specified %s. Useful in emergencies when you need to notify admins of an issue regarding a monitored system or service.", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");
snprintf(action, sizeof(action), "Send a custom %s notification", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");
break;
case CMD_CHANGE_HOST_MODATTR:
snprintf(action, sizeof(action), "Reset modified attributes for Host(s).");
break;
case CMD_CHANGE_SVC_MODATTR:
snprintf(action, sizeof(action), "Reset modified attributes for Service(s).");
break;
case CMD_INTERNAL_CHANGE_HOST_CHECK_RETRY_INTERVAL:
snprintf(action, sizeof(action), "Internal change of {check,retry}_interval and forced reschedule for Host(s).");
break;
case CMD_INTERNAL_CHANGE_SVC_CHECK_RETRY_INTERVAL:
snprintf(action, sizeof(action), "Internal change of {check,retry}_interval and forced reschedule for Service(s).");
break;
default:
print_generic_error_message("Sorry Dave, I can't let you do that...", "Executing an unknown command? Shame on you!", 2);
return;
}
help_text[sizeof(help_text)-1] = '\x0';
action[sizeof(action)-1] = '\x0';
/* Javascript to check input */
printf("<script language=\"JavaScript\">\n");
printf("function check_input(){\n"
" if (document.getElementById('com_data')) {\n"
" if (document.getElementById('com_data').value == '') {\n"
" document.getElementById('com_data_error').style.display = '';\n"
" return false;\n"
" } else {\n"
" document.getElementById('com_data_error').style.display = 'none';\n"
" }\n"
" }\n"
" if (document.getElementById('plugin_output')) {\n"
" if (document.getElementById('plugin_output').value == '') {\n"
" document.getElementById('plugin_output_error').style.display = '';\n"
" return false;\n"
" } else {\n"
" document.getElementById('plugin_output_error').style.display = 'none';\n"
" }\n"
" }\n"
" if (document.getElementById('not_dly')) {\n"
" if (parseInt(document.getElementById('not_dly').value) == 0 ) {\n"
" document.getElementById('not_dly_error').style.display = '';\n"
" return false;\n"
" }\n"
" }\n"
" return true;\n"
"}\n"
"</script>\n");
printf("<div align='center'>\n");
printf("<form method='post' action='%s' onSubmit=\"return check_input();\">\n", CMD_CGI);
printf("<input type='hidden' name='cmd_typ' value='%d'><input type='hidden' name='cmd_mod' value='%d'>\n", cmd, CMDMODE_COMMIT);
/* creating an extra table to make it compatible to IE6 & IE7 to have a nice frame around the form, damn it */
printf("<table cellspacing='0' cellpadding='0'><tr><td class='boxFrame BoxWidth'>\n");
printf("<table cellspacing='2' cellpadding='0' class='contentTable'>\n");
printf("<tr class='sectionHeader'><td colspan='2'>Action</td></tr>\n");
printf("<tr><td colspan='2'>%s ", action);
if (strlen(help_text) > 2)
print_help_box(help_text);
printf("</td></tr>\n");
switch (cmd) {
case CMD_ADD_SVC_COMMENT:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
case CMD_ADD_HOST_COMMENT:
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
case CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM:
if (cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM || cmd == CMD_ADD_SVC_COMMENT)
print_object_list(PRINT_SERVICE_LIST);
else
print_object_list(PRINT_HOST_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
print_form_element(PRINT_PERSISTENT, cmd);
if (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM || cmd == CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM) {
print_form_element(PRINT_EXPIRE_ACKNOWLEDGEMENT, cmd);
print_form_element(PRINT_STICKY_ACK, cmd);
print_form_element(PRINT_SEND_NOTFICATION, cmd);
}
break;
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
if (cmd == CMD_DEL_HOST_COMMENT || cmd == CMD_DEL_SVC_COMMENT)
print_object_list(PRINT_COMMENT_LIST);
else
print_object_list(PRINT_DOWNTIME_LIST);
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
}
break;
case CMD_DEL_DOWNTIME_BY_HOST_NAME:
print_object_list(PRINT_HOST_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
}
break;
case CMD_DELAY_SVC_NOTIFICATION:
case CMD_DELAY_HOST_NOTIFICATION:
if (cmd == CMD_DELAY_SVC_NOTIFICATION)
print_object_list(PRINT_SERVICE_LIST);
else
print_object_list(PRINT_HOST_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
}
print_form_element(PRINT_NOTIFICATION_DELAY, cmd);
break;
case CMD_SCHEDULE_SVC_CHECK:
case CMD_SCHEDULE_HOST_CHECK:
case CMD_SCHEDULE_HOST_SVC_CHECKS:
if (cmd == CMD_SCHEDULE_SVC_CHECK)
print_object_list(PRINT_SERVICE_LIST);
else
print_object_list(PRINT_HOST_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
}
print_form_element(PRINT_CHECK_TIME, cmd);
print_form_element(PRINT_FORCE_CHECK, cmd);
break;
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
case CMD_DEL_ALL_SVC_COMMENTS:
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
print_object_list(PRINT_SERVICE_LIST);
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
}
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
print_object_list(PRINT_HOST_LIST);
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
}
if (cmd == CMD_ENABLE_HOST_SVC_CHECKS || cmd == CMD_DISABLE_HOST_SVC_CHECKS || cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_HOST_SVC_NOTIFICATIONS || cmd == CMD_ENABLE_HOST_NOTIFICATIONS || cmd == CMD_DISABLE_HOST_NOTIFICATIONS) {
if (enforce_comments_on_actions != TRUE)
print_form_element(PRINT_COMMON_HEADER, cmd);
}
if (cmd == CMD_ENABLE_HOST_SVC_CHECKS || cmd == CMD_DISABLE_HOST_SVC_CHECKS || cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_HOST_SVC_NOTIFICATIONS) {
snprintf(help_text, sizeof(help_text), "This %s %s of the host too.", (cmd == CMD_ENABLE_HOST_SVC_CHECKS || cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? "enables" : "disables", (cmd == CMD_ENABLE_HOST_SVC_CHECKS || cmd == CMD_DISABLE_HOST_SVC_CHECKS) ? "checks" : "notifications");
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr><td class=\"objectDescription descriptionleft\">%s For Host Too:", (cmd == CMD_ENABLE_HOST_SVC_CHECKS || cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
print_help_box(help_text);
printf("</td><td align='left'><input type='checkbox' name='ahas'></td></tr>\n");
}
if (cmd == CMD_ENABLE_HOST_NOTIFICATIONS || cmd == CMD_DISABLE_HOST_NOTIFICATIONS) {
snprintf(help_text, sizeof(help_text), "%s notifications te be sent out to child hosts.", (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr><td class=\"objectDescription descriptionleft\">%s Notifications For Child Hosts Too:", (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
print_help_box(help_text);
printf("</td><td align='left'><input type='checkbox' name='ptc'></td></tr>\n");
}
break;
case CMD_ENABLE_NOTIFICATIONS:
case CMD_DISABLE_NOTIFICATIONS:
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
if (cmd == CMD_DISABLE_NOTIFICATIONS) {
print_form_element(PRINT_EXPIRE_DISABLE_NOTIFICATIONS, cmd);
}
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
} else {
if (cmd != CMD_DISABLE_NOTIFICATIONS) {
printf("<tr><td colspan='2'> </td></tr>\n");
printf("<tr><td class='objectDescription' colspan='2'>There are no options for this command.<br>Click the 'Commit' button to submit the command.</td></tr>\n");
}
}
break;
case CMD_PROCESS_HOST_CHECK_RESULT:
case CMD_PROCESS_SERVICE_CHECK_RESULT:
if (cmd == CMD_PROCESS_SERVICE_CHECK_RESULT)
print_object_list(PRINT_SERVICE_LIST);
else
print_object_list(PRINT_HOST_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
}
snprintf(help_text, sizeof(help_text), "Set the state which should be send to %s for this %s.", PROGRAM_NAME, (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "hosts" : "services");
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr><td class=\"objectDescription descriptionleft\">Check Result:");
print_help_box(help_text);
printf("</td><td align='left'>\n");
printf("\t<select name='plugin_state'>\n");
if (cmd == CMD_PROCESS_SERVICE_CHECK_RESULT) {
printf("\t\t<option value='%d' selected>OK</option>\n", STATE_OK);
printf("\t\t<option value='%d'>WARNING</option>\n", STATE_WARNING);
printf("\t\t<option value='%d'>UNKNOWN</option>\n", STATE_UNKNOWN);
printf("\t\t<option value='%d'>CRITICAL</option>\n", STATE_CRITICAL);
} else {
printf("\t\t<option value='0' selected>UP</option>\n");
printf("\t\t<option value='1'>DOWN</option>\n");
printf("\t\t<option value='2'>UNREACHABLE</option>\n");
}
printf("\t</select>\n");
printf("</td></tr>\n");
print_form_element(PRINT_CHECK_OUTPUT_BOX, cmd);
print_form_element(PRINT_PERFORMANCE_DATA_BOX, cmd);
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
case CMD_SCHEDULE_SVC_DOWNTIME:
if (cmd == CMD_SCHEDULE_SVC_DOWNTIME)
print_object_list(PRINT_SERVICE_LIST);
else
print_object_list(PRINT_HOST_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
snprintf(help_text, sizeof(help_text), "Define here if this downtime should get triggered by another downtime of a particular %s.", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "host" : "service");
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr id=\"trigger_select\"><td class=\"objectDescription descriptionleft\">Triggered By:");
print_help_box(help_text);
printf("</td><td align='left'>\n");
printf("\t<select name='trigger'>\n");
printf("\t\t<option value='0'>N/A</option>\n");
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if (temp_downtime->type != HOST_DOWNTIME)
continue;
/* find the host... */
temp_host = find_host(temp_downtime->host_name);
/* make sure user has rights to view this host */
if (is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
continue;
printf("\t\t<option value='%lu'>", temp_downtime->downtime_id);
get_time_string(&temp_downtime->start_time, start_time, sizeof(start_time), SHORT_DATE_TIME);
printf("ID: %lu, Host '%s' starting @ %s</option>\n", temp_downtime->downtime_id, temp_downtime->host_name, start_time);
found_trigger_objects = TRUE;
}
for (temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if (temp_downtime->type != SERVICE_DOWNTIME)
continue;
printf("\t\t<option value='%lu'>", temp_downtime->downtime_id);
get_time_string(&temp_downtime->start_time, start_time, sizeof(start_time), SHORT_DATE_TIME);
printf("ID: %lu, Service '%s' on host '%s' starting @ %s</option>\n", temp_downtime->downtime_id, temp_downtime->service_description, temp_downtime->host_name, start_time);
found_trigger_objects = TRUE;
}
printf("\t</select>\n");
printf("</td></tr>\n");
/* hide "Triggerd by" selction if nothing is found to get triggered from */
if (!found_trigger_objects)
printf("<tr style=\"display:none;\"><td colspan='2'><script language=\"JavaScript\">document.getElementById('trigger_select').style.display = 'none';</script></td></tr>\n");
print_form_element(PRINT_START_TIME, cmd);
print_form_element(PRINT_END_TIME, cmd);
print_form_element(PRINT_FIXED_FLEXIBLE_TYPE, cmd);
if (cmd == CMD_SCHEDULE_HOST_DOWNTIME) {
snprintf(help_text, sizeof(help_text), "Define here what should be done with the child hosts of these hosts.");
help_text[sizeof(help_text)-1] = '\x0';
printf("<tr><td class=\"objectDescription descriptionleft\">Child Hosts:");
print_help_box(help_text);
printf("</td><td align='left'>\n");
printf("\t<select name='childoptions'>\n");
printf("\t\t<option value='0'>Do nothing with child hosts</option>\n");
printf("\t\t<option value='1'>Schedule triggered downtime for all child hosts</option>\n");
printf("\t\t<option value='2'>Schedule non-triggered downtime for all child hosts</option>\n");
printf("\t</select>\n");
printf("</td></tr>\n");
}
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
printf("<tr><td colspan='2'> </td></tr>\n");
printf("<tr class=\"statusEven\" ><td width=\"50%%\" style=\"font-weight:bold;\">Hostgroup Name:</td>");
printf("<td><input type='hidden' name='hostgroup' value='%s'>%s</td></tr>\n", escape_string(hostgroup_name), escape_string(hostgroup_name));
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
}
if (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_DISABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS) {
if (enforce_comments_on_actions != TRUE)
print_form_element(PRINT_COMMON_HEADER, cmd);
printf("<tr><td class=\"objectDescription descriptionleft\">%s For Hosts Too:</td><td align='left'>\n", (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
printf("<input type='checkbox' name='ahas'></td></tr>\n");
}
break;
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
printf("<tr><td colspan='2'> </td></tr>\n");
printf("<tr class=\"statusEven\"><td width=\"50%%\" style=\"font-weight:bold;\">Servicegroup Name:</td>");
printf("<td><input type='hidden' name='servicegroup' value='%s'>%s</td></tr>\n", escape_string(servicegroup_name), escape_string(servicegroup_name));
if (enforce_comments_on_actions == TRUE) {
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
}
if (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS || cmd == CMD_DISABLE_SERVICEGROUP_SVC_CHECKS || cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS) {
if (enforce_comments_on_actions != TRUE)
print_form_element(PRINT_COMMON_HEADER, cmd);
printf("<tr><td class=\"objectDescription descriptionleft\">%s For Hosts Too:</td><td align='left'>\n", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS || cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
printf("<input type='checkbox' name='ahas'></td></tr>\n");
}
break;
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
printf("<tr><td colspan='2'> </td></tr>\n");
printf("<tr class=\"statusEven\"><td width=\"50%%\" style=\"font-weight:bold;\">");
if (cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME)
printf("Hostgroup Name:</td><td><input type='hidden' name='hostgroup' value='%s'>%s</td></tr>\n", escape_string(hostgroup_name), escape_string(hostgroup_name));
else
printf("Servicegroup Name:</td><td><input type='hidden' name='servicegroup' value='%s'>%s</td></tr>\n", escape_string(servicegroup_name), escape_string(servicegroup_name));
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
print_form_element(PRINT_START_TIME, cmd);
print_form_element(PRINT_END_TIME, cmd);
print_form_element(PRINT_FIXED_FLEXIBLE_TYPE, cmd);
if (cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME) {
printf("<tr><td class=\"objectDescription descriptionleft\">Schedule Downtime For Hosts Too:</td><td align='left'>\n");
printf("<input type='checkbox' name='ahas'></td></tr>\n");
}
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
if (cmd == CMD_SEND_CUSTOM_SVC_NOTIFICATION)
print_object_list(PRINT_SERVICE_LIST);
else
print_object_list(PRINT_HOST_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
print_form_element(PRINT_AUTHOR, cmd);
print_form_element(PRINT_COMMENT_BOX, cmd);
print_form_element(PRINT_FORCE_NOTIFICATION, cmd);
print_form_element(PRINT_BROADCAST_NOTIFICATION, cmd);
break;
case CMD_CHANGE_HOST_MODATTR:
print_object_list(PRINT_HOST_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
printf("<tr class=\"statusEven\"><td width=\"50%%\" style=\"font-weight:bold;\">Modified Attributes:</td>");
printf("<td><input type='hidden' name='attr' value='%lu'>", attr);
print_modified_attributes(HTML_CONTENT, CMD_CGI, attr);
printf("</td></tr>\n");
break;
case CMD_CHANGE_SVC_MODATTR:
print_object_list(PRINT_SERVICE_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
printf("<tr class=\"statusEven\"><td width=\"50%%\" style=\"font-weight:bold;\">Modified Attributes:</td>");
printf("<td><input type='hidden' name='attr' value='%lu'>", attr);
print_modified_attributes(HTML_CONTENT, CMD_CGI, attr);
printf("</td></tr>\n");
break;
case CMD_INTERNAL_CHANGE_HOST_CHECK_RETRY_INTERVAL:
print_object_list(PRINT_HOST_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
printf("<tr class=\"statusEven\"><td width=\"50%%\" style=\"font-weight:bold;\">Modify Check/Retry Interval:</td>");
printf("<td><input type='hidden' name='interval' value='%lf'>", interval);
printf("%lf", interval);
printf("</td></tr>\n");
break;
case CMD_INTERNAL_CHANGE_SVC_CHECK_RETRY_INTERVAL:
print_object_list(PRINT_SERVICE_LIST);
print_form_element(PRINT_COMMON_HEADER, cmd);
printf("<tr class=\"statusEven\"><td width=\"50%%\" style=\"font-weight:bold;\">Modify Check/Retry Interval:</td>");
printf("<td><input type='hidden' name='interval' value='%lf'>", interval);
printf("%lf", interval);
printf("</td></tr>\n");
break;
default:
printf("<tr><td class='objectDescription' colspan='2'>This should not be happening... :-(</td></tr>\n");
}
printf("<tr><td colspan='2'> </td></tr>\n");
printf("<tr class='sectionHeader'><td colspan='2' class='commitButton'><input type='submit' name='btnSubmit' value='Commit' class='submitButton'> | <a href='javascript:window.history.go(-1)'>Cancel</a></td></tr>\n");
printf("</table>\n");
printf("</td></tr></table>\n"); /* Outer frame */
printf("</form>\n");
printf("</div>\n");
return;
}
void commit_command_data(int cmd) {
char error_string[MAX_INPUT_BUFFER];
service *temp_service;
host *temp_host;
hostgroup *temp_hostgroup;
comment *temp_comment;
scheduled_downtime *temp_downtime;
servicegroup *temp_servicegroup = NULL;
contact *temp_contact = NULL;
char *referer;
char *referer_check;
char *buffer;
int x = 0;
int e = 0;
short error_found = FALSE;
short cmd_has_objects = FALSE;
short row_color = 0;
/* get authentication information */
get_authentication_information(¤t_authdata);
referer = getenv("HTTP_REFERER");
asprintf(&referer_check, "%s/%s", url_cgi_path, CMD_CGI);
if (disable_cmd_cgi_csrf_protection == FALSE && (referer == NULL || !strstr(referer, referer_check))) {
if (use_logging == TRUE) {
asprintf(&buffer, "ERROR: %s;%s;%s;This appears to be a CSRF attack! The command wasn't issued via Classic-UI itself!", current_authdata.username, (getenv("REMOTE_ADDR") != NULL) ? getenv("REMOTE_ADDR") : "unknown remote address", extcmd_get_name(cmd));
write_to_cgi_log(buffer);
}
print_generic_error_message("Error: This appears to be a CSRF attack! The command wasn't issued via Classic-UI itself!", NULL, 2);
return;
}
/* allways set the first element to FALSE*/
/* If there is a single COMMAND witch is not coverd correctly throught the following cases it won't get executed */
is_authorized[x] = FALSE;
/* get name to use for author */
if (lock_author_names == TRUE) {
temp_contact = find_contact(current_authdata.username);
if (temp_contact != NULL && temp_contact->alias != NULL)
comment_author = temp_contact->alias;
else
comment_author = current_authdata.username;
}
switch (cmd) {
case CMD_ADD_HOST_COMMENT:
case CMD_ADD_SVC_COMMENT:
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
case CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM:
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
/* make sure we have author name, and comment data... */
check_comment_sanity(&e);
/* clean up the comment data */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
if (use_ack_end_time == TRUE && (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM || cmd == CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM)) {
time(&start_time);
/* make sure we have end time if required */
check_time_sanity(&e);
} else
end_time = 0L;
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL)
continue;
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_ADD_HOST_COMMENT || cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd == CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM || cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) {
temp_host = find_host(commands[x].host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
} else {
temp_service = find_service(commands[x].host_name, commands[x].description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
}
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
if (enforce_comments_on_actions == TRUE) {
check_comment_sanity(&e);
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (multi_ids[x] == FALSE)
continue;
/* check the sanity of the comment id */
if (multi_ids[x] == 0) {
error[e++].message = strdup("Comment id cannot be 0");
continue;
}
/* find the comment */
if (cmd == CMD_DEL_HOST_COMMENT)
temp_comment = find_host_comment(multi_ids[x]);
else
temp_comment = find_service_comment(multi_ids[x]);
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_DEL_HOST_COMMENT && temp_comment != NULL) {
temp_host = find_host(temp_comment->host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
if (cmd == CMD_DEL_SVC_COMMENT && temp_comment != NULL) {
temp_service = find_service(temp_comment->host_name, temp_comment->service_description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
}
/* free comment data */
free_comment_data();
break;
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
if (enforce_comments_on_actions == TRUE) {
check_comment_sanity(&e);
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (multi_ids[x] == FALSE)
continue;
/* check the sanity of the downtime id */
if (multi_ids[x] == 0) {
error[e++].message = strdup("Downtime id cannot be 0");
continue;
}
/* find the downtime entry */
if (cmd == CMD_DEL_HOST_DOWNTIME)
temp_downtime = find_host_downtime(multi_ids[x]);
else
temp_downtime = find_service_downtime(multi_ids[x]);
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_DEL_HOST_DOWNTIME && temp_downtime != NULL) {
temp_host = find_host(temp_downtime->host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
if (cmd == CMD_DEL_SVC_DOWNTIME && temp_downtime != NULL) {
temp_service = find_service(temp_downtime->host_name, temp_downtime->service_description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
}
/* free downtime data */
free_downtime_data();
break;
case CMD_SCHEDULE_SVC_CHECK:
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
case CMD_DEL_ALL_SVC_COMMENTS:
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
case CMD_PROCESS_SERVICE_CHECK_RESULT:
case CMD_SCHEDULE_SVC_DOWNTIME:
case CMD_DELAY_SVC_NOTIFICATION:
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
if (cmd == CMD_SCHEDULE_SVC_DOWNTIME || enforce_comments_on_actions == TRUE) {
/* make sure we have author and comment data */
check_comment_sanity(&e);
/* make sure we have start/end times for downtime */
if (cmd == CMD_SCHEDULE_SVC_DOWNTIME)
check_time_sanity(&e);
/* clean up the comment data if scheduling downtime */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL || commands[x].description == NULL)
continue;
is_authorized[x] = FALSE;
temp_service = find_service(commands[x].host_name, commands[x].description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
/* make sure we have passive check info (if necessary) */
if (cmd == CMD_PROCESS_SERVICE_CHECK_RESULT && !strcmp(plugin_output, ""))
error[e++].message = strdup("Check output cannot be blank");
/* make sure we have a notification delay (if necessary) */
if (cmd == CMD_DELAY_SVC_NOTIFICATION && notification_delay <= 0)
error[e++].message = strdup("Notification delay must be greater than 0");
/* make sure we have check time (if necessary) */
if (cmd == CMD_SCHEDULE_SVC_CHECK && start_time == (time_t)0)
error[e++].message = strdup("Start time must be non-zero or bad format has been submitted");
break;
case CMD_ENABLE_NOTIFICATIONS:
case CMD_DISABLE_NOTIFICATIONS:
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
if (use_disabled_notif_end_time == TRUE && cmd == CMD_DISABLE_NOTIFICATIONS) {
time(&start_time);
/* make sure we have end time if required */
check_time_sanity(&e);
} else
end_time = 0L;
if (enforce_comments_on_actions == TRUE) {
check_comment_sanity(&e);
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (is_authorized_for_system_commands(¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_SCHEDULE_HOST_SVC_CHECKS:
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
case CMD_DELAY_HOST_NOTIFICATION:
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
case CMD_PROCESS_HOST_CHECK_RESULT:
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
case CMD_SCHEDULE_HOST_CHECK:
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
case CMD_DEL_DOWNTIME_BY_HOST_NAME:
if (cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME || enforce_comments_on_actions == TRUE) {
/* make sure we have author and comment data */
check_comment_sanity(&e);
/* make sure we have start/end times for downtime */
if (cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME)
check_time_sanity(&e);
/* clean up the comment data if scheduling downtime */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL)
continue;
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
temp_host = find_host(commands[x].host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
/* make sure we have a notification delay (if necessary) */
if (cmd == CMD_DELAY_HOST_NOTIFICATION && notification_delay <= 0)
error[e++].message = strdup("Notification delay must be greater than 0");
/* make sure we have check time (if necessary) */
if ((cmd == CMD_SCHEDULE_HOST_CHECK || cmd == CMD_SCHEDULE_HOST_SVC_CHECKS) && start_time == (time_t)0)
error[e++].message = strdup("Start time must be non-zero or bad format has been submitted");
/* make sure we have passive check info (if necessary) */
if (cmd == CMD_PROCESS_HOST_CHECK_RESULT && !strcmp(plugin_output, ""))
error[e++].message = strdup("Check output cannot be blank");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
if (cmd == CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME \
|| cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) {
/* make sure we have author and comment data */
check_comment_sanity(&e);
/* make sure we have start/end times for downtime */
check_time_sanity(&e);
/* clean up the comment data if scheduling downtime */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
} else if (enforce_comments_on_actions == TRUE) {
check_comment_sanity(&e);
clean_comment_data(comment_author);
clean_comment_data(comment_data);
}
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS || \
cmd == CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS || cmd == CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS || \
cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_DISABLE_HOSTGROUP_SVC_CHECKS || \
cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) {
temp_hostgroup = find_hostgroup(hostgroup_name);
if (is_authorized_for_hostgroup_commands(temp_hostgroup, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
} else {
temp_servicegroup = find_servicegroup(servicegroup_name);
if (is_authorized_for_servicegroup_commands(temp_servicegroup, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
break;
case CMD_CHANGE_HOST_MODATTR:
case CMD_CHANGE_SVC_MODATTR:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL)
continue;
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_CHANGE_HOST_MODATTR) {
temp_host = find_host(commands[x].host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
} else {
temp_service = find_service(commands[x].host_name, commands[x].description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
/* do not allow other attributes than reset (0) */
if (attr != MODATTR_NONE) {
error[e++].message = strdup("You cannot change modified attributes other than reset them!");
}
}
break;
case CMD_INTERNAL_CHANGE_HOST_CHECK_RETRY_INTERVAL:
case CMD_INTERNAL_CHANGE_SVC_CHECK_RETRY_INTERVAL:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
cmd_has_objects = TRUE;
if (commands[x].host_name == NULL)
continue;
/* see if the user is authorized to issue a command... */
is_authorized[x] = FALSE;
if (cmd == CMD_INTERNAL_CHANGE_HOST_CHECK_RETRY_INTERVAL) {
temp_host = find_host(commands[x].host_name);
if (is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
} else {
temp_service = find_service(commands[x].host_name, commands[x].description);
if (is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
is_authorized[x] = TRUE;
}
}
break;
default:
print_generic_error_message("Sorry Dave, I can't let you do that...", "Executing an unknown command? Shame on you!", 2);
return;
}
/*
* these are supposed to be implanted inside the
* completed commands shipped off to Icinga and
* must therefore never contain ';'
*/
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (strchr(commands[x].host_name, ';')) {
snprintf(error_string, sizeof(error_string), "The hostname \"%s\" contains a semicolon", commands[x].host_name);
error_string[sizeof(error_string)-1] = '\x0';
error[e++].message = (char *)strdup(error_string);
}
if (commands[x].description != NULL && strchr(commands[x].description, ';')) {
snprintf(error_string, sizeof(error_string), "The service description \"%s\" on host \"%s\" contains a semicolon", commands[x].description, commands[x].host_name);
error_string[sizeof(error_string)-1] = '\x0';
error[e++].message = strdup(error_string);
}
}
if (hostgroup_name && strchr(hostgroup_name, ';'))
error[e++].message = strdup("The hostgroup name contains a semicolon");
if (servicegroup_name && strchr(servicegroup_name, ';'))
error[e++].message = strdup("The servicegroup name contains a semicolon");
printf("<br><div align='center'>\n");
/* if Icinga isn't checking external commands, don't do anything... */
if (check_external_commands == FALSE) {
print_generic_error_message("Sorry, but Icinga is currently not checking for external commands, so your command will not be committed!", "Read the documentation for information on how to enable external commands...", 2);
return;
}
/* to be safe, we are going to REQUIRE that the authentication functionality is enabled... */
if (use_authentication == FALSE) {
print_generic_error_message("Sorry Dave, I can't let you do that...", "It seems that you have chosen to not use the authentication functionality of the CGIs. I don't want to be personally responsible for what may happen as a result of allowing unauthorized users to issue commands to Icinga, so you'll have to disable this safeguard if you are really stubborn and want to invite trouble. Read the section on CGI authentication in the HTML documentation to learn how you can enable authentication and why you should want to.", 2);
return;
}
/* Check if we found errors which preventing us from submiting the command */
if (e > 0) {
printf("<div class='errorBox'>\n");
printf("<div class='errorMessage'><table cellspacing='0' cellpadding='0' border='0'><tr><td width='55'><img src=\"%s%s\" border='0'></td>", url_images_path, CMD_STOP_ICON);
printf("<td class='errorMessage'>Following errors occurred.</td></tr></table></div>\n");
printf("<table cellspacing='0' cellpadding='0' border='0' class='errorTable'>\n");
for (e = 0; e < NUMBER_OF_STRUCTS; e++) {
if (error[e].message == NULL)
continue;
printf("<tr><td class='errorString'>ERROR:</td><td class='errorContent'>%s</td></tr>\n", error[e].message);
}
printf("</table>\n</div>\n");
printf("<br>\n");
printf("<table cellspacing='0' cellpadding='0' border='0' class='BoxWidth'><tr>\n");
printf("<td align='left' width='50%%'><input type='submit' value='< Go back and fix it' onClick='window.history.go(-1);' class='submitButton'></td>\n");
printf("<td align='right' width='50%%'><input type='submit' value='Get me out of here' onClick='window.history.go(-2);' class='submitButton'></td>\n");
printf("</tr></table></div>");
return;
}
/* Let's see if we have a command which doesn't have any host, services or downtime/comment id's and check the authorisation */
if (cmd_has_objects == FALSE && is_authorized[0] == FALSE) {
print_generic_error_message("Sorry, but you are not authorized to commit the specified command.", "Read the section of the documentation that deals with authentication and authorization in the CGIs for more information.", 2);
return;
}
/* everything looks okay, so let's go ahead and commit the command... */
commit_command(cmd);
/* for commands without objects get the first result*/
if (cmd_has_objects == FALSE) {
if (submit_result[0] == OK) {
printf("<div class='successBox'>\n");
printf("<div class='successMessage'>Your command request was successfully submitted to %s for processing.<br><br>\n", PROGRAM_NAME);
printf("Note: It may take a while before the command is actually processed.</div>\n");
printf("</div>\n");
printf("<br><input type='submit' value='Done' onClick='window.history.go(-2);' class='submitButton'></div>\n");
} else {
print_generic_error_message("An error occurred while attempting to commit your command for processing.", "Unfortunately I can't determine the root cause of this problem.", 2);
}
} else {
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (cmd == CMD_DEL_HOST_COMMENT || cmd == CMD_DEL_SVC_COMMENT || cmd == CMD_DEL_HOST_DOWNTIME || cmd == CMD_DEL_SVC_DOWNTIME) {
if (multi_ids[x] == FALSE)
continue;
} else {
if (commands[x].host_name == NULL)
continue;
}
if (is_authorized[x] == FALSE || submit_result[x] == ERROR) {
error_found = TRUE;
break;
}
}
if (error_found) {
print_generic_error_message("An error occurred while attempting to commit your command for processing.", "Not all commands could be send off successfully...", 0);
} else {
printf("<div class='successBox'>\n");
printf("<div class='successMessage'>Your command requests were successfully submitted to %s for processing.<br><br>\n", PROGRAM_NAME);
printf("Note: It may take a while before the commands are actually processed.</div>\n");
printf("</div>\n");
}
printf("<br>\n");
printf("<table cellspacing='0' cellpadding='0' border='0' class='BoxWidth'>\n");
printf("<tr class='BoxWidth'><td width='33%%'></td><td width='33%%' align='center'><input type='submit' value='Done' onClick='window.history.go(-2);' class='submitButton'></td><td width='33%%' align='right'>\n");
if (!error_found)
printf("<input type='submit' value='Let me see what has been done' onClick=\"document.getElementById('sumCommit').style.display = '';\" class='submitButton'>\n");
printf("</td></tr></table>\n");
printf("<br><br>\n");
printf("<table cellspacing='0' cellpadding='0' id='sumCommit' %s><tr><td class='boxFrame BoxWidth'>\n", (error_found) ? "" : "style='display:none;'");
printf("<table cellspacing='2' cellpadding='0' border='0' class='contentTable'>\n");
if (cmd == CMD_DEL_HOST_COMMENT || cmd == CMD_DEL_SVC_COMMENT)
printf("<tr class='sumHeader'><td width='80%%'>Comment ID</td><td width='20%%'>Status</td></tr>\n");
else if (cmd == CMD_DEL_HOST_DOWNTIME || cmd == CMD_DEL_SVC_DOWNTIME)
printf("<tr class='sumHeader'><td width='80%%'>Downtime ID</td><td width='20%%'>Status</td></tr>\n");
else
printf("<tr class='sumHeader'><td width='40%%'>Host</td><td width='40%%'>Service</td><td width='20%%'>Status</td></tr>\n");
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (cmd == CMD_DEL_HOST_COMMENT || cmd == CMD_DEL_SVC_COMMENT || cmd == CMD_DEL_HOST_DOWNTIME || cmd == CMD_DEL_SVC_DOWNTIME) {
if (multi_ids[x] == FALSE)
continue;
row_color = (row_color == 0) ? 1 : 0;
printf("<tr class='status%s'><td>%lu</td><td>", (row_color == 0) ? "Even" : "Odd ", multi_ids[x]);
} else {
if (commands[x].host_name == NULL)
continue;
row_color = (row_color == 0) ? 1 : 0;
printf("<tr class='status%s'><td>%s</td><td>%s</td><td>", (row_color == 0) ? "Even" : "Odd ", commands[x].host_name, (commands[x].description != NULL) ? commands[x].description : "N/A");
}
if (is_authorized[x] == FALSE)
printf("<div class='commitFailed'>Not Authorized</div>");
else if (submit_result[x] == ERROR)
printf("<div class='commitFailed'>FAILED</div>");
else if (submit_result[x] == OK)
printf("<div class='commitSuccess'>Successful</div>");
else
printf("<div class='commitUnknown'>Unknown</div>");
printf("</td><tr>\n");
}
printf("</table>\n");
printf("</td></tr></table></div>\n");
}
return;
}
/** @brief doe's some checks before passing data to write_command_to_file
*
* Actually defines the command cmd_submitf.
**/
__attribute__((format(printf, 2, 3)))
static int cmd_submitf(int id, const char *fmt, ...) {
char cmd[MAX_EXTERNAL_COMMAND_LENGTH];
const char *command;
int len, len2;
va_list ap;
command = extcmd_get_name(id);
len = snprintf(cmd, sizeof(cmd) - 1, "[%lu] %s;", time(NULL), command);
if (len < 0 || len >= sizeof(cmd))
return ERROR;
if (fmt) {
va_start(ap, fmt);
len2 = vsnprintf(&cmd[len], sizeof(cmd) - len - 1, fmt, ap);
va_end(ap);
if (len2 < 0 || len2 >= sizeof(cmd) - len)
return ERROR;
}
return write_command_to_file(cmd);
}
int commit_command(int cmd) {
time_t current_time;
time_t scheduled_time;
time_t notification_time;
char *temp_buffer = NULL;
int x = 0;
/* get the current time */
time(¤t_time);
/* get the scheduled time */
scheduled_time = current_time + (schedule_delay * 60);
/* get the notification time */
notification_time = current_time + (notification_delay * 60);
/* decide how to form the command line... */
switch (cmd) {
/* commands without arguments */
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, NULL);
break;
/* simple host commands */
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", commands[x].host_name);
}
break;
/* simple service commands */
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
case CMD_DEL_ALL_SVC_COMMENTS:
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%s", commands[x].host_name, commands[x].description);
}
break;
case CMD_ADD_HOST_COMMENT:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%d;%s;%s", commands[x].host_name, persistent_comment, comment_author, comment_data);
}
break;
case CMD_ADD_SVC_COMMENT:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%s;%d;%s;%s", commands[x].host_name, commands[x].description, persistent_comment, comment_author, comment_data);
}
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (multi_ids[x] == FALSE)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%lu", multi_ids[x]);
}
break;
case CMD_DEL_DOWNTIME_BY_HOST_NAME:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", commands[x].host_name);
}
break;
case CMD_DELAY_HOST_NOTIFICATION:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu", commands[x].host_name, notification_time);
}
break;
case CMD_DELAY_SVC_NOTIFICATION:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%s;%lu", commands[x].host_name, commands[x].description, notification_time);
}
break;
case CMD_SCHEDULE_SVC_CHECK:
case CMD_SCHEDULE_FORCED_SVC_CHECK:
if (force_check == TRUE)
cmd = CMD_SCHEDULE_FORCED_SVC_CHECK;
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%s;%lu", commands[x].host_name, commands[x].description, start_time);
}
break;
case CMD_ENABLE_NOTIFICATIONS:
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%lu", scheduled_time);
break;
case CMD_DISABLE_NOTIFICATIONS:
if (is_authorized[x]) {
/* we should expire the disabled notifications */
if(end_time > 0) {
cmd = CMD_DISABLE_NOTIFICATIONS_EXPIRE_TIME;
submit_result[x] = cmd_submitf(cmd, "%lu;%lu", scheduled_time, end_time);
my_free(temp_buffer);
} else {
submit_result[x] = cmd_submitf(cmd, "%lu", scheduled_time);
}
}
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", commands[x].host_name);
}
if (affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_HOST_SVC_CHECKS) ? CMD_ENABLE_HOST_CHECK : CMD_DISABLE_HOST_CHECK;
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] |= cmd_submitf(cmd, "%s", commands[x].host_name);
}
}
break;
case CMD_SCHEDULE_HOST_SVC_CHECKS:
if (force_check == TRUE)
cmd = CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS;
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu", commands[x].host_name, scheduled_time);
}
break;
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
if (propagate_to_children == TRUE)
cmd = (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS : CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS;
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", commands[x].host_name);
}
break;
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", commands[x].host_name);
}
if (affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? CMD_ENABLE_HOST_NOTIFICATIONS : CMD_DISABLE_HOST_NOTIFICATIONS;
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] |= cmd_submitf(cmd, "%s", commands[x].host_name);
}
}
break;
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
case CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x]) {
if (end_time > 0 || cmd == CMD_ACKNOWLEDGE_HOST_SVC_PROBLEM) {
if (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM)
cmd = CMD_ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;
if (end_time > 0) {
asprintf(&temp_buffer, "%s - The acknowledgement expires at: %s.", comment_data, end_time_string);
} else {
asprintf(&temp_buffer, "%s", comment_data);
}
submit_result[x] = cmd_submitf(cmd, "%s;%d;%d;%d;%lu;%s;%s", commands[x].host_name, (sticky_ack == TRUE) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL, send_notification, persistent_comment, end_time, comment_author, temp_buffer);
my_free(temp_buffer);
} else
submit_result[x] = cmd_submitf(cmd, "%s;%d;%d;%d;%s;%s", commands[x].host_name, (sticky_ack == TRUE) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL, send_notification, persistent_comment, comment_author, comment_data);
}
}
break;
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x]) {
if (end_time > 0) {
cmd = CMD_ACKNOWLEDGE_SVC_PROBLEM_EXPIRE;
asprintf(&temp_buffer, "%s - The acknowledgement expires at: %s.", comment_data, end_time_string);
submit_result[x] = cmd_submitf(cmd, "%s;%s;%d;%d;%d;%lu;%s;%s", commands[x].host_name, commands[x].description, (sticky_ack == TRUE) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL, send_notification, persistent_comment, end_time, comment_author, temp_buffer);
my_free(temp_buffer);
} else
submit_result[x] = cmd_submitf(cmd, "%s;%s;%d;%d;%d;%s;%s", commands[x].host_name, commands[x].description, (sticky_ack == TRUE) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL, send_notification, persistent_comment, comment_author, comment_data);
}
}
break;
case CMD_PROCESS_SERVICE_CHECK_RESULT:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%s;%d;%s|%s", commands[x].host_name, commands[x].description, plugin_state, plugin_output, performance_data);
}
break;
case CMD_PROCESS_HOST_CHECK_RESULT:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%d;%s|%s", commands[x].host_name, plugin_state, plugin_output, performance_data);
}
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
/* Icinga 1.x handles that differently */
if (status_file_icinga_version != NULL && status_file_icinga_version[0] == '1') {
if (child_options == 1)
cmd = CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;
else if (child_options == 2)
cmd = CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;
}
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu;%lu;%d;%lu;%lu;%s;%s", commands[x].host_name, start_time, end_time, fixed, triggered_by, duration, comment_author, comment_data);
}
break;
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu;%lu;%d;%lu;%lu;%s;%s", commands[x].host_name, start_time, end_time, fixed, triggered_by, duration, comment_author, comment_data);
}
break;
case CMD_SCHEDULE_SVC_DOWNTIME:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%s;%lu;%lu;%d;%lu;%lu;%s;%s", commands[x].host_name, commands[x].description, start_time, end_time, fixed, triggered_by, duration, comment_author, comment_data);
}
break;
case CMD_SCHEDULE_HOST_CHECK:
if (force_check == TRUE)
cmd = CMD_SCHEDULE_FORCED_HOST_CHECK;
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu", commands[x].host_name, start_time);
}
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%d;%s;%s", commands[x].host_name, (force_notification | broadcast_notification), comment_author, comment_data);
}
break;
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%s;%d;%s;%s", commands[x].host_name, commands[x].description, (force_notification | broadcast_notification), comment_author, comment_data);
}
break;
/***** HOSTGROUP COMMANDS *****/
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", hostgroup_name);
if (affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS : CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;
if (is_authorized[x])
submit_result[x] |= cmd_submitf(cmd, "%s", hostgroup_name);
}
break;
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", hostgroup_name);
break;
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", hostgroup_name);
if (affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS) ? CMD_ENABLE_HOSTGROUP_HOST_CHECKS : CMD_DISABLE_HOSTGROUP_HOST_CHECKS;
if (is_authorized[x])
submit_result[x] |= cmd_submitf(cmd, "%s", hostgroup_name);
}
break;
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu;%s;%s", hostgroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
break;
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu;%s;%s", hostgroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
if (affect_host_and_services == TRUE) {
if (is_authorized[x])
submit_result[x] |= cmd_submitf(CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME, "%s;%lu;%lu;%d;0;%lu;%s;%s", hostgroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
}
break;
/***** SERVICEGROUP COMMANDS *****/
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", servicegroup_name);
if (affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS : CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
if (is_authorized[x])
submit_result[x] |= cmd_submitf(cmd, "%s", servicegroup_name);
}
break;
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", servicegroup_name);
break;
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s", servicegroup_name);
if (affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS) ? CMD_ENABLE_SERVICEGROUP_HOST_CHECKS : CMD_DISABLE_SERVICEGROUP_HOST_CHECKS;
if (is_authorized[x])
submit_result[x] |= cmd_submitf(cmd, "%s", servicegroup_name);
}
break;
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu;%s;%s", servicegroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
break;
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu;%s;%s", servicegroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
if (affect_host_and_services == TRUE) {
if (is_authorized[x])
submit_result[x] |= cmd_submitf(CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME, "%s;%lu;%lu;%d;0;%lu;%s;%s", servicegroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
}
break;
case CMD_CHANGE_HOST_MODATTR:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%lu", commands[x].host_name, attr);
}
break;
case CMD_CHANGE_SVC_MODATTR:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x])
submit_result[x] = cmd_submitf(cmd, "%s;%s;%lu", commands[x].host_name, commands[x].description, attr);
}
break;
case CMD_INTERNAL_CHANGE_HOST_CHECK_RETRY_INTERVAL:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x]) {
submit_result[x] = cmd_submitf(CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL, "%s;%lf", commands[x].host_name, interval);
submit_result[x] = cmd_submitf(CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL, "%s;%lf", commands[x].host_name, interval);
submit_result[x] = cmd_submitf(CMD_SCHEDULE_FORCED_HOST_CHECK, "%s;%lu", commands[x].host_name, time(NULL));
}
}
break;
case CMD_INTERNAL_CHANGE_SVC_CHECK_RETRY_INTERVAL:
for (x = 0; x < NUMBER_OF_STRUCTS; x++) {
if (commands[x].host_name == NULL)
continue;
if (is_authorized[x]) {
/* check interval, retry interval, forced rescheduled check */
submit_result[x] = cmd_submitf(CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL, "%s;%s;%lf", commands[x].host_name, commands[x].description, interval);
submit_result[x] = cmd_submitf(CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL, "%s;%s;%lf", commands[x].host_name, commands[x].description, interval);
submit_result[x] = cmd_submitf(CMD_SCHEDULE_FORCED_SVC_CHECK, "%s;%s;%lu", commands[x].host_name, commands[x].description, time(NULL));
}
}
break;
default:
submit_result[x] = ERROR;
break;
}
return OK;
}
int write_command_to_file(char *cmd) {
char *buffer;
char *ip_address = NULL;
char *p;
FILE *fp;
struct stat statbuf;
char error_string[MAX_INPUT_BUFFER];
/*
* Commands are not allowed to have newlines in them, as
* that allows malicious users to hand-craft requests that
* bypass the access-restrictions.
*/
if (!cmd || !*cmd || strchr(cmd, '\n'))
return ERROR;
/* bail out if the external command file doesn't exist */
if (stat(command_file, &statbuf)) {
snprintf(error_string, sizeof(error_string), "Error: Could not stat() command file '%s'!", command_file);
error_string[sizeof(error_string)-1] = '\x0';
print_generic_error_message(error_string, "The external command file may be missing, Icinga may not be running, and/or Icinga may not be checking external commands.", 2);
return ERROR;
}
/* open the command for writing (since this is a pipe, it will really be appended) */
fp = fopen(command_file, "w");
if (fp == NULL) {
snprintf(error_string, sizeof(error_string), "Error: Could not open command file '%s' for update!", command_file);
error_string[sizeof(error_string)-1] = '\x0';
print_generic_error_message(error_string, "The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how to setup proper permissions.", 2);
return ERROR;
}
if (use_logging == TRUE) {
// find closing bracket in cmd line
p = strchr(cmd, ']');
// if found get everything after closing bracket
if (p != NULL)
p += 2;
else // get complete command line
p = &cmd[0];
/* get remote address */
if (getenv("REMOTE_ADDR"))
ip_address = strdup(getenv("REMOTE_ADDR"));
/* construct log entry */
asprintf(&buffer, "EXTERNAL COMMAND: %s;%s;%s", current_authdata.username, (ip_address != NULL) ? ip_address : "unknown remote address", p);
/* write command to cgi log */
write_to_cgi_log(buffer);
/* log comments if forced */
if (enforce_comments_on_actions == TRUE) {
my_free(buffer);
asprintf(&buffer, "FORCED COMMENT: %s;%s;%s;%s", current_authdata.username, (ip_address != NULL) ? ip_address : "unknown remote address", comment_author, comment_data);
write_to_cgi_log(buffer);
}
my_free(buffer);
}
/* write the command to file */
fprintf(fp, "%s\n", cmd);
/* flush buffer */
fflush(fp);
fclose(fp);
return OK;
}
void clean_comment_data(char *buffer) {
int x;
int y;
y = (int)strlen(buffer);
for (x = 0; x < y; x++) {
if (buffer[x] == ';' || buffer[x] == '\n' || buffer[x] == '\r')
buffer[x] = ' ';
}
return;
}
void check_comment_sanity(int *e) {
if (!strcmp(comment_author, ""))
error[(*e)++].message = strdup("Author name was not entered");
if (!strcmp(comment_data, ""))
error[(*e)++].message = strdup("Comment data was not entered");
return;
}
void check_time_sanity(int *e) {
if (start_time == (time_t)0)
error[(*e)++].message = strdup("Start time can't be zero or date format couldn't be recognized correctly");
if (end_time == (time_t)0)
error[(*e)++].message = strdup("End time can't be zero or date format couldn't be recognized correctly");
if (end_time < start_time)
error[(*e)++].message = strdup("End date before start date");
return;
}
|