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
|
#!/usr/bin/perl
#
# Copyright 2006-2012 SPARTA, Inc. All rights reserved. See the COPYING
# file distributed with this software for details.
#
# DNSSEC-Tools: signset-editor
#
# signset-editor provides the capability for easy management of signing
# sets in a GUI. The signing sets found in the given keyrec file are
# displayed in a new window. The new signing sets may be created and
# existing signing sets may be modified or deleted from signset-editor.
# The command is used in this way:
#
# signset-editor [-V] <keyrec-file>
#
# The -v option will cause signset-editor to print a version message
# and exit.
# The keyrec-file is a DNSSEC-Tools keyrec file that maintains
# information about a zone and its encryption keys.
#
#
# Keyboard Accelerators:
# Ctrl-d Delete Signing Set
# Ctrl-e Display Extended Data / Do Not Display Extended Data
# Ctrl-h Help
# Ctrl-m Modify Signing Set
# Ctrl-n New Signing Set
# Ctrl-o Open
# Ctrl-q Quit
# Ctrl-s Save
# Ctrl-u Undo Changes
# Ctrl-v View Signing Sets / View Keyrecs
# Ctrl-w Close Window (New Signing Set, Modify Signing Set, Help)
#
#
# To Be Done:
# - create signing set
# - bind enter key to button
#
# - modify signing set
# - bind enter key to button
#
# - help
# - bind enter key to button
#
use strict;
use Net::DNS::SEC::Tools::conf;
use Net::DNS::SEC::Tools::keyrec;
use Net::DNS::SEC::Tools::BootStrap;
#
# Version information.
#
my $NAME = "signset-editor";
my $VERS = "$NAME version: 1.13.0";
my $DTVERS = "DNSSEC-Tools Version: 1.13";
######################################################################
#
# Detect required Perl modules.
#
dnssec_tools_load_mods(
'Tk' => "",
'Tk::Dialog' => "",
'Tk::Pane' => "",
'Tk::Table' => "",
);
#
# File name variables.
#
my $krfile = "dummy"; # Keyrec file we're examining.
my $curnode = "dummy"; # Node of krfile.
my $title = "dummy"; # Node for title.
#
# Main window constants.
#
my $MAINGEOM = "550x245";
my $MAINTITLE = "DNSSEC-Tools Signing Set Editor";
#
# Arrays and lists of keyrecs and signing sets.
#
my %key_lists = ();
my @key_lists = ();
my %sign_sets = ();
my @sign_sets = ();
#
# Various flags.
#
my $inhelpwind = 0; # Showing help window.
my $insubwind = 0; # Creating/not creating signset.
my $modified = 0; # Modified-krfile flag.
my $showing_extended = 1; # Show extended/terse data.
my $showing_sets; # Displaying sets/keyrecs.
#
# Data from the keyrec file.
#
my @krnames; # Keyrec names.
my @ssnames; # Signing Set names.
#
# Undo data.
#
my @undo_stack; # Stack for undo commands.
#
# The main window and its frames.
#
my $wm; # Main window.
my $subwin; # Create/Modify window.
my $helpwin; # Help window.
my $mbar; # Menubar frame.
my $krfl; # Keyrec frame.
my $body; # Window body frame.
my $bodylist; # Listbox for body.
my $null; # Empty frame.
my $whichwind = "Signing Sets Display"; # Window indicator for null.
#
# Menu item widgets.
#
my $fm_open; # Open keyrec file item.
my $fm_save; # Save keyrec file item.
my $fm_svas; # Save-as keyrec file item.
my $fm_quit; # Quit file item.
my $em_undo; # Undo edit item.
my $cm_create; # Create signing set item.
my $cm_delete; # Delete signing set item.
my $cm_modify; # Modify signing set item.
my $dm_togl; # View signsets/keyrecs item.
my $dm_extd; # Toggle extended data item.
my $hm_help; # Help item.
#
# Data for the New Signing Set and Modify commands.
#
my %keyrecbox = (); # Checkbuttons for keyrecs.
my %signsetbox = (); # Checkbuttons for signing sets.
my $modkey = ''; # Name of modified key.
my $modset = ''; # Name of modified signing set.
my $newset = ''; # Name of new signing set.
###########################################################################
main();
exit(0);
#---------------------------------------------------------------------------
# Routine: main()
#
sub main
{
my $argc = @ARGV;
erraction(ERR_EXIT);
#
# Check for the -V option and usage on other options.
#
if($ARGV[0] =~ /^-/)
{
usage() if($ARGV[0] ne "-V");
version();
}
#
# Usage if we were given more than a single keyrec file.
#
usage() if($argc != 1);
#
# Get the keyrec filename and the path's node.
#
$krfile = $ARGV[0];
$curnode = getnode($krfile);
settitle($curnode);
#
# Ensure this keyrec file actually exists.
#
if(! -e $krfile)
{
print STDERR "$krfile does not exist\n";
exit(1);
}
#
# Build the main window.
#
buildmainwind();
#
# Start the whole shebang rollin'.
#
MainLoop();
}
#---------------------------------------------------------------------------
# Routine: buildmainwind()
#
sub buildmainwind
{
my $file; # File menu.
my $edit; # Edit menu.
my $cmds; # Commands menu.
my $dspy; # Display menu.
my $help; # Help menu.
my $curfile; # Current keyrec.
my $keyrecs; # Keyrec listbox.
my $nulline; # Empty line.
#
# Create the main window and set its size.
#
$wm = MainWindow->new(-title => $MAINTITLE);
$wm->geometry($MAINGEOM);
#
# Get the keyrec file info.
#
readkrf($krfile);
#
# Create the frames we'll need.
#
$mbar = $wm->Frame(-relief => 'raised', -borderwidth => 1);
$krfl = $wm->Frame(-relief => 'raised', -borderwidth => 1);
$body = $wm->Frame(-relief => 'raised', -borderwidth => 1);
$null = $wm->Frame(-relief => 'raised', -borderwidth => 1);
$mbar->pack(-fill => 'x');
$krfl->pack(-fill => 'x');
$body->pack(-fill => 'x');
$null->pack(-fill => 'x');
#
# Create our menus.
#
$file = $mbar->Menubutton(-text => 'File',
-tearoff => 0,
-underline => 0);
$edit = $mbar->Menubutton(-text => 'Edit',
-tearoff => 0,
-underline => 0);
$cmds = $mbar->Menubutton(-text => 'Commands',
-tearoff => 0,
-underline => 0);
$dspy = $mbar->Menubutton(-text => 'Display',
-tearoff => 0,
-underline => 0);
$help = $mbar->Menubutton(-text => 'Help',
-tearoff => 0,
-underline => 0);
##################################################
#
# Add the File menu entries.
#
$fm_open = $file->command(-label => 'Open...',
-command => \&file_open,
-accelerator => 'Ctrl+O',
-underline => 0);
$fm_save = $file->command(-label => 'Save',
-command => \&file_save,
-accelerator => 'Ctrl+S',
-underline => 0);
$fm_svas = $file->command(-label => 'Save As...',
-command => \&file_saveas,
-underline => 0);
$file->separator();
$fm_quit = $file->command(-label => 'Quit',
-command => \&file_quit,
-accelerator => 'Ctrl+Q',
-underline => 0);
$file->pack(-side => 'left');
$wm->bind('<Control-Key-o>',\&file_open);
$wm->bind('<Control-Key-s>',\&file_save);
$wm->bind('<Control-Key-q>',\&file_quit);
##################################################
#
# Add the Edit menu entries.
#
$em_undo = $edit->command(-label => 'Undo Changes',
-command => \&edit_undo,
-accelerator => 'Ctrl+U',
-state => 'disabled',
-underline => 0);
$edit->pack(-side => 'left');
$wm->bind('<Control-Key-u>',\&edit_undo);
##################################################
#
# Add the Commands menu entries.
#
$cm_create = $cmds->command(-label => 'New Signing Set...',
-command => \&cmds_create,
-accelerator => 'Ctrl+N',
-underline => 0);
$cm_delete = $cmds->command(-label => 'Delete Signing Set',
-command => \&cmds_delete,
-accelerator => 'Ctrl+D',
-underline => 0);
$cm_modify = $cmds->command(-label => 'Modify Signing Set...',
-command => \&cmds_modify,
-accelerator => 'Ctrl+M',
-underline => 0);
$cmds->pack(-side => 'left');
$wm->bind('<Control-Key-n>',\&cmds_create);
$wm->bind('<Control-Key-d>',\&cmds_delete);
$wm->bind('<Control-Key-m>',\&cmds_modify);
##################################################
#
# Add the Display menu entries.
#
$dm_togl = $dspy->command(-label => 'View Keyrecs',
-command => \&display_toggle,
-accelerator => 'Ctrl+V',
-underline => 0);
$dm_extd = $dspy->command(-label => 'Do Not Display Extended Data',
-command => \&display_extdata,
-accelerator => 'Ctrl+E',
-underline => 19);
$dspy->pack(-side => 'left');
$wm->bind('<Control-Key-v>',\&display_toggle);
$wm->bind('<Control-Key-e>',\&display_extdata);
##################################################
#
# Add the Help menu entries.
#
$hm_help = $help->command(-label => 'Help',
-command => \&help_help,
-accelerator => 'Ctrl+H',
-underline => 0);
$help->pack(-side => 'right');
$wm->bind('<Control-Key-h>',\&help_help);
##################################################
#
# Create a line holding the current keyrec filename.
#
$curfile = $krfl->Label(-text => "Editing Keyrec File: ");
$curfile->pack(-side => 'left');
$curfile = $krfl->Label(-textvariable => \$title);
$curfile->pack(-side => 'left');
$krfl->pack(-side => 'top', -fill => 'x');
#
# Add a label saying which display mode we're in.
#
$krfl->Label(-textvariable => \$whichwind)->pack(-side => 'right');
##################################################
#
# Create a listbox with scrollbars to hold shtuff.
#
$bodylist = $body->Listbox(-relief => 'raised', -borderwidth => 1);
$body->AddScrollbars($bodylist);
$body->configure(-scrollbars => 'se');
signingsets();
#
# Create a line holding the current keyrec filename.
#
$nulline = $null->Label(-text => " ");
$nulline->pack();
$null->pack(-side => 'top', -fill => 'x');
}
##############################################################################
#
# Menu widget interface routines.
#
##############################################################################
#---------------------------------------------------------------------------
# Routine: file_open()
#
sub file_open
{
my $fowin; # File-open widget.
my $newfile; # New file name.
#
# Warn the user if this file has been modified. We'll also give
# the user a chance to save the file, not save the file, or cancel
# the process of opening the new file.
#
if($modified)
{
my $dlg; # Warning dialog widget.
my $ret; # Warning response.
$dlg = $wm->Dialog(-title => 'Warning',
-text => "$curnode has been modified; save before proceeding?",
-buttons => ["Save","Don't Save","Cancel"]);
$ret = $dlg->Show();
return if($ret eq "Cancel");
keyrec_close() if($ret eq "Save");
}
#
# Prompt for the new file. Return to our caller if nothing was chosen.
#
$fowin = $wm->FileSelect(-directory => '.' );
$newfile = $fowin->Show;
return if($newfile eq "");
#
# Save the new filename and its node.
#
$krfile = $newfile;
$curnode = getnode($krfile);
settitle($curnode);
#
# Read the new keyrec file.
#
readkrf($krfile);
updatewindow();
}
#---------------------------------------------------------------------------
# Routine: file_save()
#
sub file_save
{
return if(!$modified);
#
# Save and re-open the keyrec file. We'll also toss in a window
# update, just to be safe...
#
keyrec_close();
readkrf($krfile);
updatewindow();
#
# Disable the undo menu option, reset our undo stack, and mark
# the file as unmodified.
#
$em_undo->configure(-state => 'disabled');
@undo_stack = ();
}
#---------------------------------------------------------------------------
# Routine: file_saveas()
#
sub file_saveas
{
my $fowin; # File-open widget.
my $newfile; # New file's name.
#
# Prompt for the new file.
#
$fowin = $wm->FileSelect(-directory => '.' );
$newfile = $fowin->Show;
return if($newfile eq "");
#
# Make sure the user *really* wants to overwrite an existing file.
# Continue if they do, return if they don't.
#
if(-e $newfile)
{
my $dlg; # Warning dialog widget.
my $ret; # Warning response.
$dlg = $wm->Dialog(-title => 'Warning',
-text => "$newfile already exists; overwrite?",
-buttons => ["Overwrite","Cancel"]);
$ret = $dlg->Show();
return if($ret eq "Cancel");
}
#
# Save the file.
#
keyrec_saveas($newfile);
}
#---------------------------------------------------------------------------
# Routine: file_quit()
#
sub file_quit
{
#
# Warn the user if this file has been modified. We'll also give
# the user a chance to save the file, not save the file, or cancel
# the process of opening the new file.
#
if($modified)
{
my $dlg; # Warning dialog widget.
my $ret; # Warning response.
$dlg = $wm->Dialog(-title => 'Warning',
-text => "$curnode has been modified; save before proceeding?",
-buttons => ["Save","Don't Save","Cancel"]);
$ret = $dlg->Show();
return if($ret eq "Cancel");
keyrec_close() if($ret eq "Save");
}
#
# Destroy the main window. This will cause MainLoop() to return,
# leading to the program exiting.
#
$wm->destroy;
}
#---------------------------------------------------------------------------
# Routine: edit_undo()
#
sub edit_undo
{
my $undohash; # First hash from undo stack.
my $type; # Undo type.
my $op; # Undo operation.
my $field; # Undo field.
my $value; # Undo value.
#
# Ensure we have something to undo.
#
return if(@undo_stack == 0);
#
# Get the undo entry fields.
#
$undohash = shift @undo_stack;
$type = $undohash->{'type'};
$op = $undohash->{'op'};
$field = $undohash->{'field'};
$value = $undohash->{'value'};
#
# Undo based on the operation. This means that creates are deleted,
# deletes are re-created, and modifies are returned to the old ways.
#
if($op eq "create")
{
my @signset; # Signing set's keyrecs.
#
# Since we can only create signing sets, that's the only
# create operation we'll be able to undo.
#
if($type eq "signing_set")
{
#
# Delete the signing set name from each keyrec
# in the set.
#
@signset = keyrec_signsets($field);
foreach my $kr (@signset)
{
keyrec_signset_delkey($field,$kr);
}
#
# Delete the signing set name from our list of names.
#
for(my $ind=0; $ind < @ssnames; $ind++)
{
if($ssnames[$ind] eq $field)
{
splice @ssnames, $ind, 1;
last;
}
}
}
}
elsif($op eq "delete")
{
my @signset; # Signing set's keyrecs.
#
# If the signing set was deleted, we'll add the signing set
# to each keyrec in the set.
# If the keyrec was deleted, we'll add each signing set in
# the record to the named keyrec.
#
if($type eq "signing_set")
{
#
# Add the signing set name to each keyrec in the set.
#
@signset = split / /, $value;
foreach my $kr (sort(@signset))
{
keyrec_signset_addkey($field,$kr);
}
#
# Add the new set's name to the list of signing sets.
#
push @ssnames, $field;
@ssnames = sort(@ssnames);
}
elsif($type eq "keyrec")
{
#
# Add each signing set name to the keyrec.
#
@signset = split / /, $value;
foreach my $ssn (@signset)
{
keyrec_signset_addkey($ssn,$field);
}
#
# Add the keyrec's set list back to the keyrec list.
#
$key_lists{$field} = $value;
push @krnames, $field;
@krnames = sort(@krnames);
}
}
elsif($op eq "modify")
{
#
# Handle the modify command for signing sets.
#
if($type eq "signing_set")
{
my @keylist; # List of keys.
my $newlist; # Keys to be replaced.
#
# Delete the keys from the signing set.
#
$newlist = keyrec_recval($field,'keys');
@keylist = split / /, $newlist;
foreach my $key (@keylist)
{
keyrec_signset_delkey($field,$key);
}
#
# Restore the old keys to the signing set.
#
@keylist = split / /, $value;
foreach my $key (@keylist)
{
keyrec_signset_addkey($field,$key);
}
}
elsif($type eq "keyrec")
{
#
# Handle the modify command for keys.
#
my $kk = $field; # Key we're undoing.
#
# Go through all the signing sets to see which need
# an undo operation.
#
foreach my $set (keyrec_signsets())
{
my $kfound; # Key-found flag.
my $sfound = 0; # Set-found flag.
my @undosets = split / /, $value;
#
# Figure out if this set holds this key.
#
$kfound = keyrec_signset_haskey($set,$kk);
#
# Go through the undo set to see if it
# contains this set.
#
foreach my $sset (@undosets)
{
if($set eq $sset)
{
$sfound = 1;
last;
}
}
#
# If the set is in the undo set and it doesn't
# have the key, add it back in.
# If the set is not in the undo set and it has
# the key, take it back out.
#
if($sfound)
{
if(!$kfound)
{
keyrec_signset_addkey($set,$kk);
}
}
else
{
if($kfound)
{
keyrec_signset_delkey($set,$kk);
}
}
}
}
}
#
# Disable the undo menu option if this was the last undo item.
#
$em_undo->configure(-state => 'disabled') if(@undo_stack == 0);
#
# Update the window and decrement our modifications counter.
#
updatewindow();
$modified--;
settitle($curnode);
}
#---------------------------------------------------------------------------
# Routine: undo_add()
#
sub undo_add
{
my %undo = (); # Undo hash.
#
# Add the arguments to our undo hash.
#
$undo{'type'} = shift;
$undo{'op'} = shift;
$undo{'field'} = shift;
$undo{'value'} = shift;
#
# Add the undo hash to the beginning of the undo stack.
#
unshift @undo_stack, \%undo;
#
# Make sure the undo menu option is enabled.
#
$em_undo->configure(-state => 'normal');
return;
}
#---------------------------------------------------------------------------
# Routine: cmds_create()
#
sub cmds_create
{
my $nameframe; # Frame for ssname.
my $krframe; # Frame for keyrecs.
my $btnframe; # Frame for buttons.
my $wdgt; # General widget.
my $krbox; # Keyrec checkboxen.
# print "cmds_create: down in New Signing Set\n";
#
# If we're mid-operation already, we'll give an error and return.
# Otherwise, we'll turn on our in-subwindow flag.
#
if($insubwind)
{
error($subwin,"You are already in the middle of a command");
return;
}
$insubwind = 1;
#
# Create a new window to hold our creation shtuff. Bind up some
# key accelerators, too.
#
$subwin = MainWindow->new(-relief => 'raised',
-title => 'Signing Set Creation',
-takefocus => 1,
-borderwidth => 1);
$subwin->bind('<Control-Key-q>',\&file_quit);
# $subwin->bind('<Enter-Key>',\&creator);
$subwin->bind('<Control-Key-w>',\&cancelit);
#
# Now make the containers for the window.
#
$nameframe = $subwin->Frame(-relief => 'raised', -borderwidth => 1);
$krframe = $subwin->Scrolled("Frame",
-relief => 'raised',
-borderwidth => 1,
-height => 245,
-scrollbars => 'oe');
$btnframe = $subwin->Frame(-relief => 'raised', -borderwidth => 1);
$nameframe->pack(-fill => 'x');
$krframe->pack(-fill => 'both');
$btnframe->pack(-fill => 'x');
#
# Add some fields to the name stripe.
#
$wdgt = $nameframe->Label(-text => 'Name of new signing set: ');
$wdgt->pack(-side => 'left');
$wdgt = $nameframe->Entry(-text => '',
-textvariable => \$newset,
-font => '*-*-bold-*-*-*-*-*-*-*-*-*-*-*',
-takefocus => 1);
$wdgt->pack(-side => 'left');
#
# Start building the body of the window.
#
$wdgt = $krframe->Label(-text => 'Check to include keyrecs, uncheck to exclude keyrecs');
$wdgt->pack(-side => 'top');
#
# Build a collection of keyrec checkboxen.
#
%keyrecbox = ();
foreach my $kr (@krnames)
{
$keyrecbox{$kr} = $krframe->Checkbutton(-text => $kr);
$keyrecbox{$kr}->pack(-side => 'top', -fill => 'both');
}
$krframe->pack(-fill => 'x');
#
# Create a set of buttons to accept or cancel this operation.
#
$wdgt = $btnframe->Button(-text => 'Create Signing Set',
-command => \&creator);
$wdgt->pack(-side => 'left');
$wdgt = $btnframe->Button(-text => 'Cancel',
-command => \&cancelit);
$wdgt->pack(-side => 'left');
$wdgt = $btnframe->Button(-text => 'Select All',
-command => \&keyrecbox_setall);
$wdgt->pack(-side => 'left');
$wdgt = $btnframe->Button(-text => 'Clear All',
-command => \&keyrecbox_setnone);
$wdgt->pack(-side => 'left');
}
#---------------------------------------------------------------------------
# Routine: cmds_delete()
#
sub cmds_delete
{
my $lab; # Window's text.
my $name; # Entity we're deleting.
my $nlist; # Entity's containers.
my @lsel; # Listbox selections.
my $lsel; # Selected element.
#
# Get the user's selection.
#
if($bodylist->curselection eq '')
{
my $thing = "keyrec"; # Thing to select.
$thing = "signing set" if($showing_sets);
error($wm,"Please select a $thing to delete");
return;
}
@lsel = $bodylist->curselection;
$lsel = $lsel[0];
#
# If we're displaying signing sets, we'll delete the selected
# signing set from all the keyrecs which reference it.
# If we're displaying keyrecs, we'll delete all signing sets
# from that keyrec.
#
if($showing_sets)
{
my @krlist; # Keyrec list.
#
# Delete the selected thingy from the display.
#
$bodylist->delete($lsel);
#
# Get the selected signing set's name and the list of
# keyrecs which include that set. (We only need the
# keyrecs for the undo record.)
#
$name = $sign_sets[$lsel];
$nlist = $sign_sets{$name};
#
# Delete this signing set's keyrec.
#
keyrec_del($name);
#
# Add an undo record.
#
undo_add("signing_set", "delete", $name, $nlist);
#
# Delete the signing set name from our list of names.
#
for(my $ind=0; $ind < @ssnames; $ind++)
{
if($ssnames[$ind] eq $name)
{
splice @ssnames, $ind, 1;
last;
}
}
}
else
{
#
# Get the name of the keyrec whose signing sets will be zapped.
#
$name = $key_lists[$lsel];
#
# Add an undo record.
#
undo_add("keyrec", "delete", $name, $key_lists{$name});
#
# Zap the signing set for the selected keyrec.
#
$key_lists{$name} = '';
foreach my $ssn (keyrec_signsets())
{
keyrec_signset_delkey($ssn,$name);
}
#
# Delete the key name from our list of keys.
#
for(my $ind=0; $ind < @krnames; $ind++)
{
if($krnames[$ind] eq $name)
{
splice @krnames, $ind, 1;
last;
}
}
}
#
# Update the window.
#
updatewindow();
#
# Set the file-modified flag.
#
$modified++;
settitle($curnode);
}
#---------------------------------------------------------------------------
# Routine: cmds_modify()
#
sub cmds_modify
{
# print "cmds_modify: down in Modify Signing Set\n";
#
# Get the user's selection.
#
if($bodylist->curselection eq '')
{
my $thing = "keyrec"; # Thing to select.
$thing = "signing set" if($showing_sets);
error($wm,"Please select a $thing to modify");
return;
}
#
# If we're mid-operation already, we'll give an error and return.
# Otherwise, we'll turn on our in-subwindow flag.
#
if($insubwind)
{
error($subwin,"You are already in the middle of a command");
return;
}
$insubwind = 1;
#
# Make sure the signing sets are being displayed.
#
if($showing_sets)
{
modify_signset();
}
else
{
modify_key();
}
}
##############################################################################
#
# Utility routines
#
##############################################################################
#---------------------------------------------------------------------------
# Routine: readkrf()
#
sub readkrf
{
my $krf = shift; # Keyrec file.
my @names; # Keyrec names.
#
# If the specified file doesn't exist, ask the user if we should
# continue or quit.
#
if(! -e $krf)
{
my $dlg; # Warning dialog widget.
my $ret; # Warning response.
$dlg = $wm->Dialog(-title => 'Warning',
-text => "$curnode does not exist",
-buttons => ["Continue", "Quit" ]);
$ret = $dlg->Show();
return if($ret eq "Continue");
file_quit();
}
#
# Zap the old data.
#
@krnames = ();
@ssnames = ();
#
# Get data from the keyrec file.
#
keyrec_read($krf);
@ssnames = keyrec_signsets();
@names = keyrec_names();
#
# Get the names of the key keyrecs.
#
foreach my $kn (sort(@names))
{
my $ktype = keyrec_recval($kn,'keyrec_type');
push @krnames, $kn if($ktype =~ /^[kz]sk/);
}
#
# Reset the modified-keyrec file flag.
#
$modified = 0;
settitle($curnode);
}
#---------------------------------------------------------------------------
# Routine: display_toggle()
#
sub display_toggle
{
if($showing_sets)
{
$dm_togl->configure(-label => 'View Signing Sets');
$whichwind = "Keyrecs Display";
$showing_sets = 0;
}
else
{
$dm_togl->configure(-label => 'View Keyrecs');
$whichwind = "Signing Sets Display";
$showing_sets = 1;
}
updatewindow();
}
#---------------------------------------------------------------------------
# Routine: display_extdata()
#
sub display_extdata
{
if($showing_extended == 0)
{
$showing_extended = 1;
$dm_extd->configure(-label => 'Do Not Display Extended Data');
}
else
{
$showing_extended = 0;
$dm_extd->configure(-label => 'Display Extended Data');
}
updatewindow();
}
#---------------------------------------------------------------------------
# Routine: updatewindow()
#
# Purpose: Repaint the window based on the type of data we're displaying.
#
sub updatewindow
{
if($showing_sets)
{
signingsets();
}
else
{
keyrecs();
}
}
#---------------------------------------------------------------------------
# Routine: keyrecs()
#
# Purpose: Build a list of the keyrecs and all the signing sets
# they're in.
#
sub keyrecs
{
my $llen = $bodylist->size(); # Listbox length.
#
# Change the "Modify" menu item's label.
#
$cm_modify->configure(-label => 'Modify Keyrec...');
#
# Delete any existing entries in the listbox.
#
$bodylist->delete(0,$llen) if($llen);
%key_lists = ();
@key_lists = ();
#
# Indicate that we're showing keyrecs, not signing sets.
#
$showing_sets = 0;
#
# Add the key keyrecs to our listbox, sorted by name.
#
foreach my $kr (sort(@krnames))
{
my $keyrec; # Keyrec entry.
my $keytype; # Keyrec's type.
my $krstr; # Listbox text.
my $kss; # Keyrec's signing sets.
my @kss; # Signing set array.
#
# Get the complete keyrec and skip any non-KSK and non-ZSK
# keyrecs.
#
$keytype = keyrec_recval($kr,'keyrec_type');
next if($keytype !~ /^[kz]sk/);
#
# Collect the signing sets that include this key.
#
foreach my $ss (@ssnames)
{
my $keylist = keyrec_recval($ss,'keys');
my @keylist = split / /, $keylist;
foreach my $kn (@keylist)
{
push @kss, $ss if($kn eq $kr);
}
}
#
# Put the keyrec's signing sets into a nicely formatted string.
#
$kss = join(' ',sort(@kss));
#
# Add this keyrec to the listbox.
#
if($showing_extended) { $krstr = "$kr: $kss"; }
else { $krstr = "$kr"; }
$bodylist->insert("end",$krstr);
$key_lists{$kr} = $kss;
push @key_lists, $kr;
}
#
# Pack 'er up.
#
$bodylist->pack(-fill => 'x');
}
#---------------------------------------------------------------------------
# Routine: signingsets()
#
# Purpose: Build a list of the signing sets and all the keyrecs
# they contain.
#
sub signingsets
{
my $llen = $bodylist->size(); # Listbox length.
#
# Change the "Modify" menu item's label.
#
$cm_modify->configure(-label => 'Modify Signing Set...');
#
# Delete any existing entries in the listbox.
#
$bodylist->delete(0,$llen) if($llen);
%sign_sets = ();
@sign_sets = ();
#
# Indicate that we're showing signing sets, not keyrecs.
#
$showing_sets = 1;
#
# Add the signing sets to our listbox, sorted by name.
#
foreach my $sset (sort(@ssnames))
{
my $outstr; # List string.
my $signlist; # Signing set's keys.
my @signlist; # Signing set's keys.
$signlist = keyrec_recval($sset,'keys');
@signlist = split / /, $signlist;
$signlist = join ' ', sort @signlist;
if($showing_extended) { $outstr = "$sset: $signlist"; }
else { $outstr = "$sset"; }
$bodylist->insert("end",$outstr);
$sign_sets{$sset} = $signlist;
push @sign_sets, $sset;
}
#
# Pack 'er up.
#
$bodylist->pack(-fill => 'x');
}
#---------------------------------------------------------------------------
# Routine: creator()
#
# Purpose: Create a new signing set. Each selected key is added to
# the new set.
#
sub creator
{
my @krlist = (); # Keyrecs for signset.
my $undoarg = ''; # Keyrec list for undo.
#
# Make sure we were given a name.
#
if($newset eq '')
{
error($subwin,"The new signing set must be named");
return;
}
#
# Make sure we were given a *valid* name.
#
if($newset =~ /[ \t\n]/)
{
error($subwin,"Whitespace is not allowed in a signing set name");
return;
}
#
# Make sure this name isn't taken yet.
#
foreach my $ssn (@ssnames)
{
if($ssn eq $newset)
{
error($subwin,"\"$newset\" is already a signing set");
return;
}
}
#
# Add the signing set to the selected keyrecs.
#
foreach my $krn (sort(keys(%keyrecbox)))
{
my $cbh = $keyrecbox{$krn}; # Checkbox hash.
if($cbh->{'Value'} == 1)
{
keyrec_signset_addkey($newset,$krn);
$undoarg .= "$krn, ";
}
}
#
# Add the new set's name to the list of signing sets.
#
push @ssnames, $newset;
@ssnames = sort(@ssnames);
#
# Add an undo record.
#
$undoarg =~ s/, $//;
undo_add("signing_set", "create", $newset, $undoarg);
#
# Set the file-modified flag and reset the new signing set's name.
#
$newset = '';
$modified++;
settitle($curnode);
#
# Destroy our creation window and update the main window.
#
$subwin->destroy();
updatewindow();
$insubwind = 0;
}
#---------------------------------------------------------------------------
# Routine: modify_signset()
#
# Purpose: Build a window to allow modification of a signing set.
#
sub modify_signset
{
my $nameframe; # Frame for ssname.
my $ssframe; # Frame for keyrecs.
my $btnframe; # Frame for buttons.
my $wdgt; # General widget.
my $krbox; # Keyrec checkboxen.
my @lsel; # Listbox selections.
my $lsel; # Selected element.
my $name; # Name of signing set.
my @boxen; # Keyrecs in set.
#
# Get the name of the selected signing set.
#
@lsel = $bodylist->curselection;
$lsel = $lsel[0];
$name = $sign_sets[$lsel];
$modset = $name;
#
# Create a new window to hold our modification shtuff. Bind up some
# key accelerators, too.
#
$subwin = MainWindow->new(-relief => 'raised',
-title => 'Signing Set Modification',
-borderwidth => 1);
$subwin->bind('<Control-Key-q>',\&file_quit);
$subwin->bind('<Control-Key-w>',\&cancelit);
#
# Now make the containers for the window.
#
$nameframe = $subwin->Frame(-relief => 'raised', -borderwidth => 1);
$ssframe = $subwin->Scrolled("Frame",
-relief => 'raised',
-borderwidth => 1,
-height => 245,
-scrollbars => 'oe');
$btnframe = $subwin->Frame(-relief => 'raised', -borderwidth => 1);
$nameframe->pack(-fill => 'x');
$ssframe->pack(-fill => 'x');
$btnframe->pack(-fill => 'x');
#
# Add some fields to the name stripe.
#
$wdgt = $nameframe->Label(-text => "Modifying signing set: $name");
$wdgt->pack(-side => 'left');
#
# Start building the body of the window.
#
$wdgt = $ssframe->Label(-text => 'Check to include keyrecs, uncheck to exclude keyrecs');
$wdgt->pack(-side => 'top');
#
# Build a collection of keyrec checkboxen.
#
%keyrecbox = ();
foreach my $kr (@krnames)
{
$keyrecbox{$kr} = $ssframe->Checkbutton(-text => $kr);
$keyrecbox{$kr}->pack(-side => 'top');
}
#
# Select the checkboxes for each keyrec in the signing set.
#
@boxen = split / /, $sign_sets{$name};
foreach my $kr (@boxen)
{
$keyrecbox{$kr}->select();
}
#
# Create a set of buttons to accept or cancel this operation.
#
$wdgt = $btnframe->Button(-text => 'Modify Signing Set',
-command => \&modifier_signset);
$wdgt->pack(-side => 'left');
$wdgt = $btnframe->Button(-text => 'Cancel',
-command => \&cancelit);
$wdgt->pack(-side => 'left');
$wdgt = $btnframe->Button(-text => 'Select All',
-command => \&keyrecbox_setall);
$wdgt->pack(-side => 'left');
$wdgt = $btnframe->Button(-text => 'Clear All',
-command => \&keyrecbox_setnone);
$wdgt->pack(-side => 'left');
}
#---------------------------------------------------------------------------
# Routine: modify_key()
#
# Purpose: Build a window to allow modification of a key.
#
sub modify_key
{
my $nameframe; # Frame for ssname.
my $ssframe; # Frame for ssets.
my $btnframe; # Frame for buttons.
my $wdgt; # General widget.
my $krbox; # Keyrec checkboxen.
my @lsel; # Listbox selections.
my $lsel; # Selected element.
my $name; # Name of key.
my @boxen; # Key's signing sets.
#
# Get the name of the selected key.
#
@lsel = $bodylist->curselection;
$lsel = $lsel[0];
$name = $key_lists[$lsel];
$modkey = $name;
#
# Create a new window to hold our modification shtuff. Bind up some
# key accelerators, too.
#
$subwin = MainWindow->new(-relief => 'raised',
-title => 'Key Use Modification',
-borderwidth => 1);
$subwin->bind('<Control-Key-q>',\&file_quit);
$subwin->bind('<Control-Key-w>',\&cancelit);
#
# Now make the containers for the window.
#
$nameframe = $subwin->Frame(-relief => 'raised', -borderwidth => 1);
$ssframe = $subwin->Scrolled("Frame",
-relief => 'raised',
-borderwidth => 1,
-height => 245,
-scrollbars => 'oe');
$btnframe = $subwin->Frame(-relief => 'raised', -borderwidth => 1);
$nameframe->pack(-fill => 'x');
$ssframe->pack(-fill => 'x');
$btnframe->pack(-fill => 'x');
#
# Add some fields to the name stripe.
#
$wdgt = $nameframe->Label(-text => "Modifying keyrec: $name");
$wdgt->pack(-side => 'left');
#
# Start building the body of the window.
#
$wdgt = $ssframe->Label(-text => 'Check to include signing sets, uncheck to exclude signing sets');
$wdgt->pack(-side => 'top');
#
# Build a collection of signing set checkboxen.
#
%signsetbox = ();
foreach my $sset (sort(@ssnames))
{
$signsetbox{$sset} = $ssframe->Checkbutton(-text => $sset);
$signsetbox{$sset}->select() if(keyrec_signset_haskey($sset,$modkey));
$signsetbox{$sset}->pack(-side => 'top');
}
#
# Create a set of buttons to accept or cancel this operation.
#
$wdgt = $btnframe->Button(-text => 'Modify Key',
-command => \&modifier_key);
$wdgt->pack(-side => 'left');
$wdgt = $btnframe->Button(-text => 'Cancel',
-command => \&cancelit);
$wdgt->pack(-side => 'left');
$wdgt = $btnframe->Button(-text => 'Select All',
-command => \&signsetbox_setall);
$wdgt->pack(-side => 'left');
$wdgt = $btnframe->Button(-text => 'Clear All',
-command => \&signsetbox_setnone);
$wdgt->pack(-side => 'left');
}
#---------------------------------------------------------------------------
# Routine: modifier_signset()
#
# Purpose: Modify an existing signing set. Selected keys are added,
# unselected keys are deleted.
#
sub modifier_signset
{
my $curlist; # Current list of keys.
#
# Save the signing set's current set of keys.
#
$curlist = keyrec_recval($modset,'keys');
#
# Modify the signing set so that only those keyrecs selected by the
# user are included.
#
foreach my $krn (keyrec_names())
{
my $kr; # Keyrec hash.
my $sset; # Keyrec's signing set.
my @ssns; # Signing set array.
my $found = 0; # Found flag.
#
# Get this keyrec and skip any zone and set keyrecs.
#
$kr = keyrec_fullrec($krn);
next if(($kr->{'keyrec_type'} eq "zone") ||
($kr->{'keyrec_type'} eq "set"));
#
# Build a list of signing sets that contain this key.
#
foreach my $ss (@ssnames)
{
push @ssns, $ss if(keyrec_signset_haskey($ss,$krn));
}
#
# Set a flag if this keyrec contains the selected signing set.
#
foreach my $k (@ssns)
{
$found = 1 if($k eq $modset);
}
#
# If the user checked this keyrec, we'll be sure the keyrec's
# signing set contains the selected signing set.
# Otherwise, we'll make sure it isn't in the keyrec's signing
# set.
#
if($keyrecbox{$krn}->{'Value'} == 1)
{
if(!$found)
{
keyrec_signset_addkey($modset,$krn);
}
}
else
{
if($found)
{
keyrec_signset_delkey($modset,$krn);
}
}
}
#
# Add an undo record.
#
undo_add("signing_set", "modify", $modset, $curlist);
#
# Set the file-modified flag and reset the modified signing set's name.
#
$modset = '';
$modified++;
settitle($curnode);
#
# Destroy our modification window and update the main window.
#
$subwin->destroy();
updatewindow();
$insubwind = 0;
}
#---------------------------------------------------------------------------
# Routine: modifier_key()
#
# Purpose: Modify the signing sets so that the chosen key is added to
# selected signing sets and deleted from unselected signing sets.
#
sub modifier_key
{
my $curlist; # Combined signing set list.
my @curlist = (); # Combined signing set list.
# print "modifier_key: down in\n";
#
# Modify the signing sets so that the key is in selected sets and
# not in unselected sets.
#
foreach my $sset (sort(keyrec_signsets()))
{
push @curlist, $sset if(keyrec_signset_haskey($sset,$modkey));
}
$curlist = join ' ', @curlist;
#
# Modify the signing sets so that the key is in selected sets and
# not in unselected sets.
#
foreach my $sset (sort(keyrec_signsets()))
{
#
# If the user checked this keyrec, we'll be sure the keyrec's
# signing set contains the selected signing set.
# Otherwise, we'll make sure it isn't in the keyrec's signing
# set.
#
if($signsetbox{$sset}->{'Value'} == 1)
{
if(!keyrec_signset_haskey($sset,$modkey))
{
keyrec_signset_addkey($sset,$modkey);
}
}
else
{
if(keyrec_signset_haskey($sset,$modkey))
{
keyrec_signset_delkey($sset,$modkey);
}
}
}
#
# Add an undo record.
#
undo_add("keyrec", "modify", $modkey, $curlist);
#
# Set the file-modified flag and reset the modified keyrec's name.
#
$modkey = '';
$modified++;
settitle($curnode);
#
# Destroy our modification window and update the main window.
#
$subwin->destroy();
updatewindow();
$insubwind = 0;
}
#---------------------------------------------------------------------------
# Routine: keyrecbox_setall()
#
# Purpose: Set all the fields in a collection of checkboxen.
#
sub keyrecbox_setall
{
my $cbh; # Checkbox hash.
foreach my $krn (sort(keys(%keyrecbox)))
{
$cbh = $keyrecbox{$krn};
$cbh->{'Value'} = 1;
}
}
#---------------------------------------------------------------------------
# Routine: keyrecbox_setnone()
#
# Purpose: Unset all the fields in a collection of checkboxen.
#
sub keyrecbox_setnone
{
my $cbh; # Checkbox hash.
#
# Add the signing set to the selected keyrecs.
#
foreach my $krn (sort(keys(%keyrecbox)))
{
$cbh = $keyrecbox{$krn};
$cbh->{'Value'} = 0;
}
}
#---------------------------------------------------------------------------
# Routine: signsetbox_setall()
#
# Purpose: Set all the fields in a collection of checkboxen.
#
sub signsetbox_setall
{
my $cbh; # Checkbox hash.
foreach my $krn (sort(keys(%signsetbox)))
{
$cbh = $signsetbox{$krn};
$cbh->{'Value'} = 1;
}
}
#---------------------------------------------------------------------------
# Routine: signsetbox_setnone()
#
# Purpose: Unset all the fields in a collection of checkboxen.
#
sub signsetbox_setnone
{
my $cbh; # Checkbox hash.
#
# Add the signing set to the selected keyrecs.
#
foreach my $krn (sort(keys(%signsetbox)))
{
$cbh = $signsetbox{$krn};
$cbh->{'Value'} = 0;
}
}
#---------------------------------------------------------------------------
# Routine: getnode()
#
# Purpose: Get the node of a pathname.
#
sub getnode
{
my @pathelts; # Path elements.
my $pathnode; # Last path elements.
@pathelts = split /\//, $krfile;
$pathnode = pop @pathelts;
return($pathnode);
}
#---------------------------------------------------------------------------
# Routine: cancelit()
#
# Purpose: Destroy a subwindow.
#
sub cancelit
{
$subwin->destroy();
$insubwind = 0;
$newset = '';
$modset = '';
}
#---------------------------------------------------------------------------
# Routine: helpbegone()
#
# Purpose: Destroy a help window.
#
sub helpbegone
{
$helpwin->destroy();
$inhelpwind = 0;
}
#---------------------------------------------------------------------------
# Routine: error()
#
# Purpose: Display an error dialog box.
#
sub error
{
my $wind = shift; # Parent window.
my $msg = shift; # Warning message.
my $dlg; # Warning dialog widget.
$dlg = $wind->Dialog(-title => "$NAME Warning",
-text => $msg,
-default_button => "Okay",
-buttons => ["Okay"]);
$dlg->Show();
}
#---------------------------------------------------------------------------
# Routine: help_help()
#
# Purpose: Display a help window.
#
sub help_help
{
my $hframe; # Help frame.
my $wdgt; # General widget.
my $helpstr;
$helpstr = "
signset-editor - DNSSEC-Tools Signing Set GUI Editor
SYNOPSIS
signset-editor <keyrec-file>
DESCRIPTION
signset-editor provides the capability for easy management of signing sets in
a GUI. The signing sets found in the given keyrec file are displayed in a new
window. The new signing sets may be created and existing signing sets may be
modified or deleted from signset-editor.
A signing set consists of zero or more keyrec names. These sets are used by
other DNSSEC-Tools utilities for signing zones.
signset-editor has two display modes. The Signing Set Display shows the names
of all the signing sets in the given keyrec file. The Keyrec Display shows
the names of all the keyrecs in the given keyrec file. signset-editor starts
in Signing Set Display mode, but the mode can be toggled back and forth as
needed.
An additional toggle controls the display of additional data. If the Extended
Data toggle is turned on, then the Signing Set Display shows the names of the
keyrecs in each signing set and the Keyrec Display shows the names of each
signing set in a keyrec. If the Extended Data toggle is turned off, then the
Signing Set Display only shows the names of the signing sets and the Keyrec
Display only shows the names keyrecs.
signset-editor has a small number of commands. These commands are all
available through the menus, and must have a keyboard accelerator.
Management of signing sets may be handled using a normal text editor.
However, signset-editor provides a nice GUI that only manipulates signing sets
without the potential visual clutter of the rest of the keyrec entries.
";
#
# If we've already got another help window, we'll give an error and
# return. Otherwise, we'll turn on our in-helpwindow flag.
#
if($inhelpwind)
{
error($helpwin,"Multiple help windows cannot be created\n");
return;
}
$inhelpwind = 1;
#
# Create a new window to hold our help info. Bind up some
# key accelerators, too.
#
$helpwin = MainWindow->new(-relief => 'raised',
-title => 'Help!',
-borderwidth => 1);
$helpwin->bind('<Control-Key-q>',\&file_quit);
$helpwin->bind('<Control-Key-w>',\&helpbegone);
#
# Now make the containers for the window.
#
$hframe = $helpwin->Frame(-relief => 'raised', -borderwidth => 1);
$hframe->pack(-fill => 'x');
#
# Add the help data to the frame.
#
$wdgt = $hframe->Label(-text => $helpstr,
-justify => 'left');
$wdgt->pack(-side => 'top');
#
# Add a button to dismiss the window.
#
$wdgt = $hframe->Button(-text => 'Done',
-command => \&helpbegone);
$wdgt->pack(-side => 'top');
}
#----------------------------------------------------------------------
#
# Routine: settitle()
#
# Purpose: Set the title for use in the "Editing File" line.
#
sub settitle
{
my $name = shift; # Name to use.
$name .= " *" if($modified);
$title = $name;
}
#----------------------------------------------------------------------
#
# Routine: version()
#
# Purpose: Print the version number(s) and exit.
#
sub version
{
print STDERR "$VERS\n";
print STDERR "$DTVERS\n";
exit(0);
}
#---------------------------------------------------------------------------
# Routine: usage()
#
# Purpose: Print a usage message and exit.
#
sub usage
{
print STDERR "usage: signset-editor [-v] <keyrec-file>\n";
exit(0);
}
1;
#############################################################################
=pod
=head1 NAME
signset-editor - DNSSEC-Tools Signing Set GUI Editor
=head1 SYNOPSIS
signset-editor <keyrec-file>
=head1 DESCRIPTION
B<signset-editor> provides the capability for easy management of signing sets
in a GUI. A signing set contains zero or more names of key I<keyrec>s. These
sets are used by other DNSSEC-Tools utilities for signing zones. The signing
sets found in the given I<keyrec> file are displayed in a new window. New
signing sets may be created and existing signing sets may be modified or
deleted from B<signset-editor>.
B<signset-editor> has two display modes. The Signing Set Display shows the
names of all the set I<keyrec>s in the given I<keyrec> file. The Keyrec
Display shows the names of all the key I<keyrec>s in the given I<keyrec> file.
B<signset-editor> starts in Signing Set Display mode, but the mode can be
toggled back and forth as needed.
An additional toggle controls the display of additional data. If the Extended
Data toggle is turned on, then the Signing Set Display shows the names of the
key I<keyrec>s in each signing set and the Keyrec Display shows the names of
each signing set each key I<keyrec> is in. If the Extended Data toggle is
turned off, then the Signing Set Display only shows the names of the set
I<keyrec>s and the Keyrec Display only shows the names key I<keyrec>s.
B<signset-editor> has a small number of commands. These commands are all
available through the menus, and most have a keyboard accelerator. The
commands are described in the next section.
Management of signing sets may be handled using a normal text editor.
However, B<signset-editor> provides a nice GUI that B<only> manipulates
signing sets without the potential visual clutter of the rest of the
I<keyrec> entries.
=head2 UNDOING MODIFICATIONS
B<signset-editor> has the ability to reverse modifications it has made to a
I<keyrec> file. This historical restoration will only work for modifications
made during a particular execution of B<signset-editor>; modifications made
during a previous execution may not be undone.
When undoing modifications, B<signset-editor> does not necessarily restore
name-ordering within a I<keyrec>'s B<signing_set> field. However, the
signing-set data are maintained. This means that an "undone" I<keyrec> file
may not be exactly the same, byte-for-byte, as the original file, but the
proper meaning of the data is kept.
After a "Save" operation, the data required for reversing modifications are
deleted. This is not the case for the "Save As" operation.
=head1 OPTIONS
B<signset-editor> takes the following options:
=over 4
=item B<-Version>
Displays the version information for B<signset-editor> and the DNSSEC-Tools
package.
=item B<-help>
Displays a usage message.
=back
=head1 COMMANDS
B<signset-editor> provides the following commands, organized by menus:
=over 4
=item B<Open> (File menu)
Open a new I<keyrec> file. If the specified file does not exist, the user
will be prompted for the action to take. If the user chooses the "Continue"
action, then B<signset-editor> will continue editing the current I<keyrec>
file. If the "Quit" action is selected, then B<signset-editor> will exit.
=item B<Save> (File menu)
Save the current I<keyrec> file. The data for the "Undo Changes" command are
purged, so this file will appear to be unmodified.
Nothing will happen if no changes have been made.
=item B<Save As> (File menu)
Save the current I<keyrec> file to a name selected by the user.
=item B<Quit> (File menu)
Exit B<signset-editor>.
=item B<Undo Changes> (Edit menu)
Reverse modifications made to the signing sets and keyrecs. This is B<only>
for the in-memory version of the I<keyrec> file.
=item B<New Signing Set> (Commands menu)
Create a new signing set. The user is given the option of adding key
I<keyrec>s to the new set.
This command is available from both viewing modes.
=item B<Delete Signing Set/Key> (Commands menu)
Delete the selected signing set or key.
This command is available from both viewing modes. If used from the Signing
Set Display mode, then all the keys in the selected signing set will be
removed from that set. If used from the Keyrec Display mode, then the
selected key will no longer be part of any signing set.
=item B<Modify Signing Set/Key> (Commands menu)
Modify the selected signing set or key.
This command is available from both viewing modes. If used from the Signing
Set Display mode, then the selected signing set may be modified by adding keys
to that set or deleting them from that set. If used from the Keyrec Display
mode, then the selected key may be added to or deleted from any of the defined
signing sets.
=item B<View Signing Sets> (Display menu)
The main window will display the I<keyrec> file's signing sets. If Extended
Data are to be displayed, then each key I<keyrec> in the signing set will also
be shown. If Extended data are not to be displayed, then only the signing set
names will be shown.
This command is a toggle that switches between View Signing Sets mode and
View Keyrecs mode.
=item B<View Keyrecs> (Display menu)
The main window will display the names of the I<keyrec> file's key I<keyrec>s.
If Extended Data are to be displayed, then the name of each signing set of the
I<keyrec> will also be shown. If Extended data are not to be shown, then only
the I<keyrec> names will be displayed.
This command is a toggle that switches between View Keyrecs mode and View
Signing Sets mode.
=item B<Display Extended Data> (Display menu)
Additional data will be shown in the main window. For Signing Sets Display
mode, the names of the signing set and their constituent key I<keyrec>s will
be displayed. For Keyrec Display mode, the names of the key I<keyrec>s and
the Signing Sets it is in will be displayed.
This command is a toggle that switches between Extended Data display and
No Extended Data display.
=item B<Do Not Display Extended Data> (Display menu)
No additional data will be shown in the main window. For Signing Sets Display
mode, only the names of the Signing Sets will be displayed. For Keyrec Display
mode, only the names of the I<keyrec>s will be displayed.
This command is a toggle that switches between No Extended Data display and
Extended Data display.
=item B<Help> (Help menu)
Display a help window.
=back
=head1 KEYBOARD ACCELERATORS
Below are the keyboard accelerators for the B<signset-editor> commands:
Ctrl-D Delete Signing Set
Ctrl-E Display Extended Data / Do Not Display Extended Data
Ctrl-H Help
Ctrl-M Modify Signing Set
Ctrl-N New Signing Set
Ctrl-O Open
Ctrl-Q Quit
Ctrl-S Save
Ctrl-U Undo Changes
Ctrl-V View Signing Sets / View Keyrecs
Ctrl-W Close Window (New Signing Set, Modify Signing Set, Help)
These accelerators are all lowercase letters.
=head1 REQUIREMENTS
B<signset-editor> is implemented in Perl/Tk, so both Perl and Perl/Tk must be
installed on your system.
=head1 COPYRIGHT
Copyright 2006-2012 SPARTA, Inc. All rights reserved.
See the COPYING file included with the DNSSEC-Tools package for details.
=head1 AUTHOR
Wayne Morrison, tewok@tislabs.com
=head1 SEE ALSO
B<cleankrf(8)>,
B<fixkrf(8)>,
B<genkrf(8)>,
B<krfcheck(8)>,
B<lskrf(1)>,
B<zonesigner(8)>
B<Net::DNS::SEC::Tools::keyrec(3)>
B<file-keyrec(5)>
=cut
|