File: bubbles

package info (click to toggle)
dnssec-tools 1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 16,064 kB
  • sloc: perl: 44,399; ansic: 31,547; cpp: 21,306; sh: 15,813; xml: 2,113; makefile: 1,390; pascal: 836; python: 290; csh: 11
file content (1499 lines) | stat: -rwxr-xr-x 33,286 bytes parent folder | download
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
#!/usr/bin/perl
#
# Copyright 2009-2012 SPARTA, Inc.  All rights reserved.  See the COPYING
# file distributed with this software for details.
#
# DNSSEC-Tools:  bubbles
#
#	bubbles provides a simple overview of the roll-state of a set
#	of zones.
#

use strict;

use Net::DNS::SEC::Tools::dnssectools;
use Net::DNS::SEC::Tools::conf;
use Net::DNS::SEC::Tools::rollmgr;
use Net::DNS::SEC::Tools::rollrec;
use Net::DNS::SEC::Tools::BootStrap;

use Getopt::Long qw(:config no_ignore_case_always);

#
# Version information.
#
my $NAME   = "bubbles";
my $VERS   = "$NAME version: 1.13.0";
my $DTVERS = "DNSSEC-Tools Version: 1.13";

my %key_lists;
my @ssnames;
my @krnames;

######################################################################
#
# Detect required Perl modules.
#
dnssec_tools_load_mods(
			'Tk'			=> "",
			'Tk::Dialog'		=> "",
			'Tk::DialogBox'		=> "",
			'Tk::FileSelect'	=> "",
			'Tk::Pane'		=> "",
			'Tk::Table'		=> "",
		      );

#######################################################################
#
#			program (non-GUI) data
#

#
# Variables for command options.
#
my %options = ();				# Filled option array.
my @opts =
(
	"kskcolor=s",				# Color for KSK rollers.
	"zskcolor=s",				# Color for ZSK rollers.
	"noncolor=s",				# Color for non-rollers.

	"showksk",				# Show KSK-rolling zones.
	"showzsk",				# Show ZSK-rolling zones.
	"showrolls",				# Show rolling zones.
	"shownonrolls",				# Show non-rolling zones.

	"columns=i",				# Columns in button window.
	"interval=s",				# Interval between file checks.
	"no-filter",				# No-name-filtering flag.
	"ignore-display",			# Ignore rollrec display flag.

	"Version",				# Display the version number.
	"help",					# Give a usage message and exit.
);

#
# Default colors for zone buttons.
#
my $RRTAB_KSKROLL  = 'red';
my $RRTAB_ZSKROLL  = 'yellow';
my $RRTAB_NONROLL  = 'green';

#
# Values for options.
#
my $kskclr = $RRTAB_KSKROLL;			# Color for KSK rollers.
my $zskclr = $RRTAB_ZSKROLL;			# Color for ZSK rollers.
my $nonclr = $RRTAB_NONROLL;			# Color for non-rollers.
my $showksk = 0;				# Show KSK-rolling zones.
my $showzsk = 0;				# Show ZSK-rolling zones.
my $shownon = 0;				# Show non-rolling zones.
my $igndisp = 0;				# Ignore rollrec display flag.

my $namefilter	= 1;				# Use-name-filter flag (FS).

#
# File name variables.
#
my $rrfile  = "dummy";				# Rollrec file we're examining.
my $curnode = "dummy";				# Node of rrfile.
my $lastmod = 0;				# Last mod. time for rrf.

#
# Lists of rollrecs.
#
my %rollrecs = ();				# Rollrec hash.
my @rollrecs = ();				# Rollrec array.
my @rrnames = ();				# List of rollrec names.
my $numrrnames;					# Number of rollrec names.

my $DEFAULT_INTERVAL = 60;			# Default interval in seconds.
my $SMALL_INT	     = 10;			# Smallest interval.
my $interval	     = $DEFAULT_INTERVAL;	# Interval between file checks.

###########################################################################
#
#			Tk GUI data
#

########################################################
#
# Main window data.
#
my $MAINTITLE	= "DNSSEC-Tools Zone States";

my $title   = "dummy";				# Node for title.

#
# The main window and help window.
#
my $wm;						# Main window.
my $helpwin;					# Help window.
my $inhelpwind	 = 0;				# Showing help window flag.

#
# The contents of the main window and its frames.
#
my $mbar;					# Menubar frame.
my $rrfl;					# Keyrec frame.
my $body;					# Window body frame.
my $bodylist;					# Listbox for body.
my $null;					# Empty frame.

########################################################
#
# Menubar and menu data.
#

#
# Menu item widgets.
#

my $tog_namefilt = 1;				# Use-name-filter toggle.

########################################################
#
# Button window data.
#

#
# Column and row data for button windows.
#
my $MAXCOLS = 12;			# Maximum allowable button columns.
my $MINCOLS = 3;			# Minimum allowable button columns.

my $numcols;				# Current number of table cols.
my $numrows;				# Current number of table rows.

my $columncount;			# Column count.

#
# Font data for text in button window.
#
my $fontsize    = 18;
my $font        = "*-*-bold-r-*-*-$fontsize-*-*-*-*-*-*-*";

#
# Constants for message text colors.
#

my $rrnametab;					# Rollrec name table widget.

###########################################################################

main();
exit(0);

#---------------------------------------------------------------------------
# Routine:	main()
#
sub main
{
	my $argc = @ARGV;

	erraction(ERR_EXIT);

	#
	# Check our options.
	#
	doopts();

	#
	# Get the rollrec filename and the path's node.
	#
	$rrfile = $ARGV[0];
	$curnode = getnode($rrfile);
	settitle($curnode);

	#
	# Ensure this rollrec file actually exists.
	#
	if(! -e $rrfile)
	{
		print STDERR "$rrfile does not exist\n";
		exit(1);
	}

	#
	# Build the main window.
	#
	buildmainwind();

	#
	# Start the whole shebang rollin'.
	#
	MainLoop();
}

#-----------------------------------------------------------------------------
# Routine:	doopts()
#
# Purpose:	This routine gets the options from the command line.
#
sub doopts
{
	my $argc = @ARGV;		# Number of command line arguments.
	my $tmprolls = 0;		# Temporary argument variable.
	my $tmpnons  = 0;		# Temporary argument variable.
	my $tmpival  = '';		# Temporary interval value.

	usage()   if($argc == 0);

	GetOptions(\%options,@opts) || usage();

	#
	# Show the version number or help info if requested.
	#
	version() if(defined($options{'Version'}));
	usage()   if(defined($options{'help'}));

	#
	# Set some flags based on the command line.
	#
	$tmpival    = $options{'interval'} if(defined($options{'interval'}));
	$namefilter = 0 if(defined($options{'no-filter'}));
	$kskclr	    = $options{'kskcolor'} if(defined($options{'kskcolor'}));
	$zskclr	    = $options{'zskcolor'} if(defined($options{'zskcolor'}));
	$nonclr	    = $options{'noncolor'} if(defined($options{'noncolor'}));
	$showksk    = $options{'showksk'}  if(defined($options{'showksk'}));
	$showzsk    = $options{'showzsk'}  if(defined($options{'showzsk'}));
	$shownon    = $options{'shownonrolls'}  if(defined($options{'shownonrolls'}));
	$igndisp    = $options{'ignore-display'}  if(defined($options{'ignore-display'}));
	$tmprolls   = $options{'showrolls'} if(defined($options{'showrolls'}));

	#
	# Check for the column-count option.
	#
	if(defined($options{'columns'}))
	{
		$columncount  = $options{'columns'};
		if($columncount < $MINCOLS)
		{
			print STDERR "column count must be at least $MINCOLS\n";
			exit(1);
		}
	}

	#
	# Parse the interval argument.  If a time unit isn't given, we'll 
	# assume we're dealing in minutes.
	#
	if($tmpival ne '')
	{
		my $nums;				# Number of time units.
		my $unit;				# Time unit.
		my $mult;				# Time-unit multiplier.

		#
		# Pull the number/units tuple out of the argument.
		#
		if(! ($tmpival =~ /^([0-9]+)([smh])$/))
		{
			if(! ($tmpival =~ /^([0-9]+)$/))
			{
				print STDERR "invalid interval\n";
				usage();
			}

			$nums = $tmpival;
			$unit = 'm';
		}
		else
		{
			$nums = $1;
			$unit = $2;
		}

		#
		# Get the unit multiplier.
		#
		if($unit eq 's')
		{
			$mult = 1;
		}
		elsif($unit eq 'm')
		{
			$mult = 60;
		}
		elsif($unit eq 'h')
		{
			$mult = 60 * 60;
		}

		#
		# Calculate the number of seconds in our interval.
		#
		$interval = $nums * $mult;
	}

	#
	# Ensure the file-check interval isn't too small, then bump it up
	# into the realm of milliseconds.
	#
	if($interval < $SMALL_INT)
	{
		print STDERR "smallest interval is $SMALL_INT seconds\n";
		exit(1);
	}
	$interval = $interval * 1000;

	#
	# Adjust the display flags.
	#
	if($tmprolls)
	{
		$showksk = 1;
		$showzsk = 1;
	}
	if(!$showksk && !$showzsk && !$shownon)
	{
		$showksk = 1;
		$showzsk = 1;
		$shownon = 1;
	}

}

#---------------------------------------------------------------------------
# Routine:	reader()
#
# Purpose:	Forces a re-read of the rollrec file if it has been
#		modified since it was last read.
#
sub reader
{
	my @stat;			# Rollrec file's file info.

	@stat = stat $rrfile;

	if($stat[9] > $lastmod)
	{
		buildtable(1);
		$lastmod = $stat[9];
	}
}

#---------------------------------------------------------------------------
# Routine:	buildmainwind()
#
# Purpose:	Create and initialize the main window.
#
sub buildmainwind
{
	my $cmd;					# Command menu.
	my $view;					# View menu.
	my $opts;					# Options 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);

	#
	# Get the keyrec file info.  No error message; it was given below.
	#
	exit(1) if(readrrf($rrfile) == 0);

	#
	# Create the frames we'll need.
	#
	$mbar = $wm->Frame(-relief => 'raised', -borderwidth => 1);
	$rrfl = $wm->Frame(-relief => 'raised', -borderwidth => 1);
	$body = $wm->Frame(-relief => 'raised', -borderwidth => 1);
	$null = $wm->Frame(-relief => 'raised', -borderwidth => 1);

	$mbar->pack(-fill => 'x');
	$rrfl->pack(-fill => 'x');
	$body->pack(-fill => 'x');
	$null->pack(-fill => 'x');

	#
	# Create our menus.
	#
	$cmd = $mbar->Menubutton(-text => 'Commands',
				  -tearoff => 0,
				  -underline => 0);
	$view = $mbar->Menubutton(-text => 'View',
				  -tearoff => 0,
				  -underline => 0);
	$opts = $mbar->Menubutton(-text => 'Options',
				  -tearoff => 0,
				  -underline => 0);
	$help = $mbar->Menubutton(-text => 'Help',
				  -tearoff => 0,
				  -underline => 0);

	##################################################
	#
	# Add the File menu entries.
	#
	$cmd->command(-label => 'Open...',
		       -command => \&cmd_open,
		       -accelerator => 'Ctrl+O',
		       -underline => 0);
	$cmd->separator();
	$cmd->command(-label => 'DS Published for All Zones',
			-command => [\&cmd_dspuball]);
	$cmd->separator();
	$cmd->command(-label => 'Halt Rollerd After Current Operations',
			-command => [\&cmd_halt, '']);
	$cmd->command(-label => 'Halt Rollerd Now',
			-command => [\&cmd_halt, 'now']);
	$cmd->separator();
	$cmd->command(-label => 'Quit',
				-command => \&cmd_quit,
				-accelerator => 'Ctrl+Q',
				-underline => 0);
	$cmd->pack(-side => 'left');

	$wm->bind('<Control-Key-O>',\&cmd_open);
	$wm->bind('<Control-Key-o>',\&cmd_open);
	$wm->bind('<Control-Key-Q>',\&cmd_quit);
	$wm->bind('<Control-Key-q>',\&cmd_quit);

	##################################################
	#
	# Add the Options menu entries.
	#
	$opts->command(-label => 'Columns in Button Window',
		       -command => [\&set_btncols, 0],
		       -underline => 0);
	$opts->pack(-side => 'left');


	##################################################
	#
	# Add the Help menu entries.
	#
	$help->command( -label => 'Help',
			-command => \&help_help,
			-accelerator => 'Ctrl+H',
			-underline => 0);
	$help->command( -label => "About $NAME",
			-command => \&help_about,
			-underline => 0);
	$help->pack(-side => 'right');

	$wm->bind('<Control-Key-h>',\&help_help);

	##################################################
	#
	# Create a line holding the current rollrec filename.
	#

	$curfile = $rrfl->Label(-text => "Viewing Rollrec File:  ");
	$curfile->pack(-side => 'left');
	$curfile = $rrfl->Label(-textvariable => \$title);
	$curfile->pack(-side => 'left');
	$rrfl->pack(-side => 'top', -fill => 'x');

	##################################################
	#
	# Create a listbox to hold the button window. 
	#
	buildtable(42);

	#
	# Create a line holding the current rollrec filename.
	#
	$nulline = $null->Label(-text => " ");
	$nulline->pack();
	$null->pack(-side => 'top', -fill => 'x');

	#
	# Arrange to have the table rebuilt in a bit.
	#
	$wm->repeat($interval, \&reader);
}

#---------------------------------------------------------------------------
# Routine:	buildtable()
#
# Purpose:	Rebuild the rollrec name table.  This also re-reads the
#		current rollrec file, so the list of rollrec names may
#		increase or shrink depending on the state of that file.
#
sub buildtable
{
	my $readflag = shift;			# Rollrec-read flag.
	my $cnt = 0;				# Count of rollrec names added.

	#
	# Read the list of rollrec names.
	#
	readrrf($rrfile,1) if($readflag);

	#
	# Ask the user what to do if we don't have any rollrec names.
	# Possible actions:
	#	- stop execution
	#	- continue as-is
	#	- ignore the values of display flags and display data
	#
	if($numrrnames == 0)
	{
		my $dlg;			# Warning dialog widget.
		my $ret;			# Warning response.

		#
		# Ask the user what to do.
		#
		$dlg = $wm->Dialog(-title => 'Warning',
			   -text  => "No rollrec entries have \"display zone\" flag turned on",
			   -buttons => ["Continue", "Ignore Display", "Quit" ]);
		$ret = $dlg->Show();

		#
		# And now we'll take the requested action.
		#
		if($ret eq "Quit")
		{
			exit(0);
		}
		if($ret eq "Continue")
		{
			return;
		}
		elsif($ret eq "Ignore Display")
		{
			#
			# Set the ignore-display-flag flag and
			# re-read the list of rollrec names.
			#
			$igndisp = 1;
			readrrf($rrfile,1) if($readflag);
		}
	}

	#
	# Ensure the rollrec name list is sorted.
	#
	@rrnames = sort(@rrnames);

	#
	# Figure out the number of columns we'll use.
	#
	$columncount = int(sqrt($numrrnames));
	if($columncount < $MINCOLS)
	{
		$columncount = $MINCOLS;
	}

	#
	# Create a brand new table.
	#
	maketable();

	#
	# Re-populate and update the table.
	#
	for(my $ind = 0; $ind < $numrrnames; $ind++)
	{
		my $btn;			# Button widget.
		my $row;			# Cell's row index.
		my $col;			# Cell's column index.
		my $clr;			# Cell's background color.
		my $rrn;			# Name in rollrec.

		#
		# Get name for this rollrec.
		#
		$rrn = $rrnames[$ind];

		#
		# Get the column and row indices.
		#
		($col,$row) = ind2cr($ind);

		#
		# Set color according to roll status.
		#
		if($rollrecs{$rrn}{'kskphase'} > 0)
		{
			$clr = $kskclr;
			$rrn .= "($rollrecs{$rrn}{'kskphase'})";
		}
		elsif($rollrecs{$rrn}{'zskphase'} > 0)
		{
			$clr = $zskclr;
			$rrn .= "($rollrecs{$rrn}{'zskphase'})";
		}
		else
		{
			$clr = $nonclr;
		}

		#
		# Create the new button.
		#
		$btn = $rrnametab->Button(-text => "$rrn",
					  -font => $font,
					  -anchor => 'w',
					  -state  => 'normal',
					  -command => [\&rrname_toggle,
						       $ind],
					  -activebackground => $clr,
					  -background => $clr);

		$rrnametab->put($row,$col,$btn);
	}

	$rrnametab->update();

	#
	# Pack it all up.
	#
	$rrnametab->pack(-fill => 'both', -expand => 1);
	$body->pack(-fill => 'both', -expand => 1);
}

#---------------------------------------------------------------------------
# Routine:      rrname_toggle()
#
# Purpose:      A rollrec name's button has been pushed.  Figure out what
#		to do with it...
#
sub rrname_toggle
{
	my $rrind = shift;			# Rollrec's name index.

	my $rowind;				# Cell's row index.
	my $colind;				# Cell's column index.

	my $btn;				# Selected button.
	my $bgclr;				# New button background color.

	#
	# Get the rollrec's button.
	#
	$btn = getbutton($rrind);

	#
	# Choose an appropriate background color given the button's
	# current state...
	#
	$bgclr = $btn->cget(-background);
#	$bgclr = ($bgclr eq $RRTAB_ROLL) ? $RRTAB_NONROLL : $RRTAB_ROLL;

	#
	# ... and set the button's color.
	#
	$btn->configure(-activebackground => $bgclr, -background => $bgclr);
}

#---------------------------------------------------------------------------
# Routine:      getbutton()
#
# Purpose:      Return a rollrec's button widget given the name's index into
#		@rrnames.
#
sub getbutton
{
	my $rrind = shift;			# Rollrec's name index.

	my $rowind;				# Cell's row index.
	my $colind;				# Cell's column index.

	#
	# Get the column and row indices.
	#
	($colind,$rowind) = ind2cr($rrind);

	#
	# Return the proper button widget.
	#
	return($rrnametab->get($rowind,$colind));
}

#---------------------------------------------------------------------------
# Routine:      ind2cr()
#
# Purpose:      Convert a rollrec name table index to its table rows and
#		column indices.
#
sub ind2cr
{
	my $nind = shift;				# Rollrec name index.
	my $col;					# Column index.
	my $row;					# Row index.

	$col = int($nind / $numrows);
	$row = $nind % $numrows;

	return($col,$row);
}

#---------------------------------------------------------------------------
# Routine:      maketable()
#
# Purpose:      Create the rollrec name table.
#
sub maketable
{
	#
	# Don't do anything if we don't have any rollrec names.
	#
	return if($numrrnames == 0);

	#
	# Calculate the size of the button table.
	#
	if($numrrnames != 0)
	{
		$numrows = int($numrrnames / $columncount);
		$numrows++ if(($numrrnames % $columncount) != 0);

		$numcols = $columncount;
	}

	#
	# Destroy the rollrec-name table's widgets.
	#
	if($rrnametab)
	{
		$rrnametab->clear;
		$rrnametab->destroy;
	}

	#
	# Create the new button table.
	#
	$rrnametab = $body->Table(-rows		=> $numrows,
				  -columns	=> $numcols,
				  -scrollbars	=> 'e',
				  -relief	=> 'raised',
				  -borderwidth	=> 1,
				  -fixedrows	=> 0,
				  -takefocus	=> 1,
			         );

}

##############################################################################
#
# Menu widget interface routines.
#
##############################################################################

#---------------------------------------------------------------------------
# Routine:	cmd_open()
#
sub cmd_open
{
	my $fowin;					# File-open widget.
	my %fsopts = ();				# FileSelect() options.
	my $newfile;					# New file name.

	#
	# Set up options for FileSelect.
	#
	%fsopts = (-directory => '.');
	$fsopts{'-filter'} = '*.rrf' if($namefilter);

	#
	# Prompt for the new file.  Return to our caller if nothing was chosen.
	#
	$fowin = $wm->FileSelect(%fsopts);
	$newfile = $fowin->Show;
	return if($newfile eq "");

	#
	# Save the new filename and its node.
	#
	$rrfile = $newfile;
	$curnode = getnode($rrfile);
	settitle($curnode);

	#
	# Read the new rollrec file and rebuild the button window.
	#
	if(readrrf($rrfile))
	{
		buildtable(0);
	}
}

#---------------------------------------------------------------------------
# Routine:	cmd_halt()
#
sub cmd_halt
{
	my $opt = shift;				# Optional "now".

	#
	# Tell rollerd that it's time to go away.
	#
	system("rollctl -quiet -halt $opt");

	#
	# Pause for a moment and then shut ourself down.
	#
	sleep(2);
	cmd_quit();
}

#---------------------------------------------------------------------------
# Routine:	cmd_dspuball()
#
sub cmd_dspuball
{
	#
	# Tell rollerd that all the zones's new DS records have been
	# published.
	#
	system("rollctl -quiet -dspuball");
}

#---------------------------------------------------------------------------
# Routine:	cmd_quit()
#
sub cmd_quit
{
	#
	# Destroy the rollrec name table's widgets.
	#
	if($rrnametab)
	{
		$rrnametab->clear;
		$rrnametab->destroy;
	}

	rollrec_discard();

	#
	# Destroy the main window.  This will cause MainLoop() to return,
	# leading to the program exiting.
	#
	$wm->destroy;
}

##############################################################################
#
# Utility routines
#
##############################################################################

#---------------------------------------------------------------------------
# Routine:	readrrf()
#
sub readrrf
{
	my $rrf = shift;				# Rollrec file.
	my @names;					# Rollrec names.

	#
	# If the specified file doesn't exist, ask the user if we should
	# continue or quit.
	#
	if(! -e $rrf)
	{
		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(1) if($ret eq "Continue");

		cmd_quit();
	}

	#
	# Ensure the file is actually a rollrec file.
	#
	if(dt_filetype($rrf) ne "rollrec")
	{
		my $curnode = getnode($rrf);

		errorbox("$curnode is not a rollrec file; unable to continue");
		return(0);
	}

	#
	# Zap the old data.
	#
	@rrnames = ();

	#
	# Get data from the rollrec file.
	#
	rollrec_read($rrf);
	@rrnames = rollrec_names();
	$numrrnames = @rrnames;

	#
	# Initialize the rollrecs hash for each rollrec.
	#
	foreach my $rrn (@rrnames)
	{
		my $rrec;				# This rollrec's data.

		#
		# Get this rollrec's data.
		#
		$rrec = rollrec_fullrec($rrn);

		#
		# Add the rollrec's necessary data to the %rollrecs hash.
		#
		$rollrecs{$rrn}{'display'}	 = $rrec->{'display'};
		$rollrecs{$rrn}{'kskphase'}	 = $rrec->{'kskphase'};
		$rollrecs{$rrn}{'zskphase'}	 = $rrec->{'zskphase'};

		#
		# Set up the radio buttons' data areas for the record type and
		# the display flag.
		#
#		$editrbs{$rrn} = $rollrecs{$rrn}{'rollrec_type'} eq 'roll' ? 1 : 0;
	}

	#
	# Drop out the zones that aren't to be displayed.
	#
	for(my $ind=$numrrnames-1; $ind >= 0; $ind--)
	{
		my $rrec;				# This rollrec's data.
		my $rrn;

		#
		# Get the zone name and its rollrec.
		#
		$rrn = $rrnames[$ind];
		$rrec = rollrec_fullrec($rrn);

		#
		# If the zone's display flag is off, lop it out of the list.
		#
		if(($igndisp == 0) && ($rollrecs{$rrn}{'display'} == 0))
		{
			splice @rrnames, $ind, 1;
			next;
		}

		#
		# If this zone is doing a KSK roll and we aren't displaying
		# KSK-rolling zones, we'll remove it from the list.
		#
		if(($showksk == 0) && ($rollrecs{$rrn}{'kskphase'} > 0))
		{
			splice @rrnames, $ind, 1;
			next;
		}

		#
		# If this zone is doing a ZSK roll and we aren't displaying
		# ZSK-rolling zones, we'll remove it from the list.
		#
		if(($showzsk == 0) && ($rollrecs{$rrn}{'zskphase'} > 0))
		{
			splice @rrnames, $ind, 1;
			next;
		}

		#
		# If we're displaying non-rolling zones and this zone isn't
		# doing a roll, we'll remove it from the list.
		#
		if(($shownon == 0) &&
		   (($rollrecs{$rrn}{'kskphase'} == 0) &&
		    ($rollrecs{$rrn}{'zskphase'} == 0)))
		{
			splice @rrnames, $ind, 1;
			next;
		}

	}

	#
	# Recalculate the number of zones we'll track.
	#
	$numrrnames = @rrnames;

	return(1);
}

#---------------------------------------------------------------------------
# Routine:	getnode()
#
# Purpose:	Get the node of a pathname.
#
sub getnode
{
	my $path = shift;				# Path to nodify.

	my @pathelts;					# Path elements.
	my $pathnode;					# Last path elements.

	@pathelts = split /\//, $path;
	$pathnode = pop @pathelts;

	return($pathnode);
}

#---------------------------------------------------------------------------
# Routine:	set_btncols()
#
# Purpose:	
#
sub set_btncols
{
	my $err = shift;				# Error flag.

	my $dlg;					# Dialog widget.
	my $lab;					# Label for dialog box.
	my $ent;					# Entry for dialog box.

	my $col;					# New column count.
	my $ret;					# Dialog box return.

	#
	# Create the new dialog box.
	#
	$dlg = $wm->DialogBox(-title	=> 'Set Columns for Button Window',
			      -buttons	=> ["Okay", "Cancel" ]);

	#
	# Add a label to the dialog.
	#
	$lab = $dlg->Label(-text => 'Enter New Column Count:');
	$lab->pack(-side => 'left');

	#
	# Add a text entry slot and focus on the entry.
	#
	$ent = $dlg->add('Entry');
	$ent->pack(-side => 'left');
	$dlg->configure(-focus => $ent);

	#
	# Add a potential error location to the dialog.
	#
	$lab = $dlg->Label(-text => ' ');
	$lab->pack(-side => 'bottom');
	if($err)
	{
		$lab->configure(-text => "Count must be between 1 and $MAXCOLS",
				-foreground => 'red')
	}

	#
	# Show the dialog box and handle cancellations.
	#
	$ret = $dlg->Show();
	return if($ret eq 'Cancel');

	#
	# Get the user's column size.
	#
	$col = $ent->get();

	#
	# If this is an invalid column count, give an error message and
	# ask again.
	#
	set_btncols(1) if(($col < 1) || ($col > $MAXCOLS));

	#
	# Save the new column count and rebuild the table.
	#
	$columncount = $col;
	buildtable(0);
}

#---------------------------------------------------------------------------
# Routine:	helpbegone()
#
# Purpose:	Destroy a help window.
#
sub helpbegone
{
	$helpwin->destroy();
	$inhelpwind = 0;
}

#############################################################################

#---------------------------------------------------------------------------
# Routine:	errorbox()
#
# Purpose:	Display an error dialog box.
#
sub errorbox
{
	my $msg  = shift;			# Warning message.
	my $dlg;				# Warning dialog widget.

	$dlg = $wm->Dialog(-title => "$NAME Error",
			   -text  => $msg,
			   -default_button => "Okay",
			   -buttons => ["Okay"]);
	$dlg->Show();
}

#---------------------------------------------------------------------------
# Routine:	errorbox_multi()
#
# Purpose:	Display a multiline error dialog box.  Newlines in the message
#		signal a new line (implemented with a new label) in the dialog
#		box.
#
sub errorbox_multi
{
	my $msgs  = shift;			# Messages to display.

	my $dlg;				# Warning dialog widget.
	my $lab;				# Label for table.

	my @lines;				# Lines in message.
	my $line;				# Individual message line.

	$dlg = $wm->DialogBox(-title	=> "$NAME Error",
			      -buttons	=> ["Okay"]);

	@lines = split /\n/, $msgs;

	foreach $line (@lines)
	{
		$lab = $dlg->Label(-text => $line);
		$lab->pack(-side => 'top');
	}

	$dlg->Show();
}

#---------------------------------------------------------------------------
# Routine:	help_help()
#
# Purpose:	Display a help window.
#
sub help_help
{
	my $hframe;					# Help frame.
	my $wdgt;					# General widget.

	my $helpstr;

	$helpstr = "

bubbles - DNSSEC-Tools Rollrec Simple GUI Display
         
SYNOPSIS
         
    bubbles [options] <rollrec-file>

DESCRIPTION

bubbles gives a simple display of the roll status of a set of zones listed in
a rollrec file.  In contrast, blinkenlights gives a detailed display of the
roll status of a set of zones.

A rollrec file contains one or more rollrec records.  These records are used
by the DNSSEC-Tools rollover utilities (rollerd, etc.) to describe zones'
rollover states.  Each zone's rollrec record contains such information as the
zone file, the rollover phase, and logging level.  rollrec files are text
files.

When bubbles starts, a window is created that has 'bubbles' for each zone with
a rollrec record in the given rollrec file.  (Clicking on a bubble doesn't do
anything.)  By default, all zones with a display flag set on will be shown in
the bubbles window.  Options may be given to modify this behavior.

More information may be found in bubbles' man page.

";

	#
	# 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)
	{
		errorbox("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>',\&cmd_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:	help_about()
#
# Purpose:	Display an about window.
#
sub help_about
{
	my $dlg;					# About dialog widget.

	$dlg = $wm->Dialog(-title => "About $NAME",
		   -text  => "$VERS\n\n$DTVERS",
		   -buttons => ["Continue" ]);
	$dlg->Show();
}

#----------------------------------------------------------------------
#
# Routine:      settitle()
#
# Purpose:      Set the title for use in the "Editing File" line.
#
sub settitle
{
	my $name = shift;				# Name to use.

	$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:  bubbles [options] <rollrec-file>\n";
	print STDERR "\toptions:\n";
	print STDERR "\t\t-kskcolor             color for KSK rolling zones\n";
	print STDERR "\t\t-zskcolor             color for ZSK rolling zones\n";
	print STDERR "\t\t-noncolor             color for non-rolling zones\n";
	print STDERR "\n";
	print STDERR "\t\t-showksk              show KSK-rolling zones\n";
	print STDERR "\t\t-showzsk              show ZSK-rolling zones\n";
	print STDERR "\t\t-showrolls            show rolling zones\n";
	print STDERR "\t\t-shownonrolls         show non-rolling zones\n";
	print STDERR "\n";
	print STDERR "\t\t-ignore-display       ignore rollrec display flags\n";
	print STDERR "\t\t-interval n           interval between file checks\n";
	print STDERR "\t\t-no-filter            turn off name filtering\n";
	print STDERR "\t\t-columns columns      columns in button window\n";
	print STDERR "\t\t-Version              program version\n";
	exit(0);
}

1;

#############################################################################

=pod

=head1 NAME

bubbles - DNSSEC-Tools Rollrec Simple GUI Display

=head1 SYNOPSIS

  bubbles [options] <rollrec-file>

=head1 DESCRIPTION

B<bubbles> gives a simple display of the roll status of a set of zones
listed in a I<rollrec> file.  In contrast, B<blinkenlights> gives a detailed
display of the roll status of a set of zones.  B<bubbles> gives very little
control over B<rollerd>, the way B<blinkenlights> does.  B<bubbles> can halt
B<rollerd>'s execution only.

A B<rollrec> file contains one or more I<rollrec> records.  These records are
used by the DNSSEC-Tools rollover utilities (B<rollerd>, etc.) to describe
zones' rollover states.  Each zone's I<rollrec> record contains such
information as the zone file, the rollover phase, and logging level.
I<rollrec> files are text files.

When B<bubbles> starts, a window is created that has "bubbles" for each
zone with a I<rollrec> record in the given I<rollrec> file.  (Clicking on a
bubble doesn't do anything.)  By default, all zones with a I<display> flag
set on will be shown in the B<bubbles> window.  Options may be given to
modify this behavior.

The zone bubbles are color-coded according to roll-over state.  The default
colors are:

* green: not in roll-over

* yellow: in ZSK roll-over

* red: in KSK roll-over

These colors may be specified by the user via command-line options.

In building the bubble window, B<bubbles> window defaults to creating a square
window.  This may be overridden by specifying the number of columns, using the
B<-columns> option.

=head1 OPTIONS

B<bubbles> supports the following options.

=over 4

=item B<-columns columns>

This option allows the user to specify the number of columns to be used in
the Button Window.

=item B<-kskcolor color>

Set the bubble color for zones that are performing KSK roll-overs.

=item B<-zskcolor color>

Set the bubble color for zones that are performing ZSK roll-overs.

=item B<-noncolor color>

Set the bubble color for zones that are not in roll-over.

=item B<-ignore-display>

Ignore the B<rollrec> display flag and display every zone in the B<rollrec>
file.

=item B<-interval wait-time>

Interval between checks of the B<rollrec> file.  By default, I<wait-time> is
given in minutes.  This can be adjusted by specifying one of the following
time-unit suffixes.

* s - seconds

* m - minutes

* h - hours

Examples:

* I<-interval 24> - 24 minutes

* I<-interval 24s> - 24 seconds

* I<-interval 24m> - 24 minutes

* I<-interval 24h> - 24 hours

=item B<-no-filter>

This option turns off name filtering when B<bubbles> presents a
file-selection dialog for choosing a new I<rollrec> file.  If this option
is not given, then the file-selection dialog will only list regular files
with a suffix of B<.rrf>.

=item B<-showksk>

Show the zones that are performing KSK roll-overs.

=item B<-shownonrolls>

Show the zones that are not in roll-over.

=item B<-showrolls>

Show the zones that are performing either type of roll-over.

=item B<-showzsk>

Show the zones that are performing ZSK roll-overs.

=item B<-help>

Give a usage message and exit.

=item B<-Version>

Displays the version information for B<bubbles> and the DNSSEC-Tools
package.

=back

=head1 REQUIREMENTS

B<bubbles> is implemented in Perl/Tk, so both Perl and Perl/Tk must be
installed on your system.

=head1 KNOWN ISSUES

The following are known issues.  These will be resolved in the fullness of time.

=over 4

=item

Segmentation violation on exit.
This problem occurs on Mac OS X 10.4.9-10.4.11 with Perl 5.8.6;
however, it does not occur on Mac OS X 10.5.8 with Perl 5.8.8. 

=back

=head1 COPYRIGHT

Copyright 2009-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<lsroll(1)>

B<blinkenlights(8)>,
B<rollchk(8)>,
B<rollerd(8)>
B<rollinit(8)>,
B<rollrec-editor(8)>
B<rollset(8)>,

B<Net::DNS::SEC::Tools::rollrec(3)>

B<file-rollrec(5)>

=cut