File: lights

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 (1179 lines) | stat: -rwxr-xr-x 26,421 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
#!/usr/bin/perl
#
# Copyright 2010-2012 SPARTA, Inc.  All rights reserved.  See the COPYING
# file distributed with this software for details.
#
# DNSSEC-Tools:  lights
#
#	lights provides a very simple overview of the rollover state
#	of a set of zones.
#

use strict;

use Getopt::Long qw(:config no_ignore_case_always);
use Net::DNS::SEC::Tools::BootStrap;
use Net::DNS::SEC::Tools::rollrec;

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

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

#
# Variables for command options.
#
my %options = ();				# Filled option array.
my @opts =
(
	"interval=s",			# Interval between zone checks.
	"rrf=s",			# Rollrec file to read.
	"labels",			# Give labels in GUI.
	"verbose",			# Give a verbose output.

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

my $interval = 10;				# Time to wait between checks.
my $labels   = 0;				# Give labels in GUI.
my $rrf	     = '';				# Rollrec file to read.
my $verbose  = 0;				# Verbose flag.

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

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

my $cmd = "rollctl -zonestatus";	# Command to get zone status.

######################################################################
#
# Data for zones.
#

my $ored	= -1;		# Old count of KSK-6 rolling zones.
my $oyellow	= -1;		# Old count of non-KSK-6 rolling zones.
my $ogreen	= -1;		# Old count of non-rolling zones.

my $okyellow	= -1;		# Old count of KSK non-KSK-6 rolling zones.
my $ozyellow	= -1;		# Old count of ZSK rolling zones.

my $skipcnt = 0;		# Number of skipped zones.

my $red	   = 0;			# Number of KSK-6 rolling zones.
my $yellow = 0;			# Number of non-KSK-6 rolling zones.
my $green  = 0;			# Number of non-rolling zones.

my $kyellow = 0;		# Number of KSK non-KSK-6 rolling zones.
my $zyellow = 0;		# Number of ZSK rolling zones.

my @greenzones = ();		# Zones in normal state.
my @kyellowzones = ();		# Zones in KSK rollover state.
my @zyellowzones = ();		# Zones in ZSK rollover state.
my @redzones = ();		# Zones in KSK rollover phase 6.

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


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

########################################################
#
# Main window data.
#
my $MAINTITLE	= "DNSSEC-Tools Rollover Overview";

#
# 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 $body;					# Window body frame.

my $skipframe;					# Frame for skip counts.

my $lights;					# Lights table.

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

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

########################################################
#
# Data about the rows to be displayed.
#

my $numrows = 3;				# Number of rows to display.

#
# Rows for specific colors.
#
my $REDROW	= 0;
my $YELLOWROW	= 1;
my $GREENROW	= 2;

#
# Colors used as backgrounds in the GUI.
#
my $COLOR_RED = 'red';
my $COLOR_DARKRED = 'DarkRed';
my $COLOR_GREEN = 'green';
my $COLOR_DARKGREEN = 'DarkGreen';
my $COLOR_YELLOW = 'yellow';
my $COLOR_DARKYELLOW = 'goldenrod';

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

main();
exit(0);

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

	#
	# Check our options.
	#
	doopts();

	#
	# 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 $tmpival  = '';		# Temporary interval value.

	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.
	#
	$rrf	 = $options{'rrf'}	if(defined($options{'rrf'}));
	$tmpival = $options{'interval'}	if(defined($options{'interval'}));
	$verbose = $options{'verbose'};
	$labels	 = $options{'labels'};

	#
	# 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;

		print "checking status every $interval seconds\n";
	}

	#
	# 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;

}

#---------------------------------------------------------------------------
# Routine:	buildmainwind()
#
# Purpose:	Create and initialize the main window.
#
sub buildmainwind
{
	my $cmdmenu;					# Commands 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);

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

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

	#
	# Create our menus.
	#
	$cmdmenu = $mbar->Menubutton(-text => 'Commands',
				  -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.
	#
	$cmdmenu->command(-label => 'DS Published for All Zones',
			  -command => [\&cmd_dspuball, '']);
	$cmdmenu->separator();
	$cmdmenu->command(-label => 'Halt Rollerd After Current Operations',
			  -command => [\&cmd_halt, '']);
	$cmdmenu->command(-label => 'Halt Rollerd Now',
			  -command => [\&cmd_halt, 'now']);
	$cmdmenu->separator();
	$cmdmenu->command(-label => 'Quit',
			  -command => \&cmd_quit,
			  -accelerator => 'Ctrl+Q',
			  -underline => 0);
	$cmdmenu->pack(-side => 'left');

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

	##################################################
	#
	# Add the Options menu entries.
	#
#	$opts->command(-label => 'Set Update Interval Window',
#		       -command => [\&set_interval, 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 listbox to hold the light table and give it an
	# initial population.
	#
	maketable();
	setlights();

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

#---------------------------------------------------------------------------
# Routine:	setlights()
#
# Purpose:	Build the display window.  The window holds three buttons,
#		red, yellow, green.  The red button holds the count of zones
#		needing attention (KSK phase 6).  The yellow button holds
#		the count of zones that are in rollover.  The green button
#		holds the count of zones not in rollover.  Clicking on each
#		button gives a list of the relevant zones.
#
sub setlights
{
	my $lab;				# Label to add to light table.
	my $clr;				# Color for zone slots.

	#
	# Figure out what to put in each light.
	#
	zonecnts();

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

	#
	# Add info on the "red" zones.
	#
	$clr = ($red > 0) ? $COLOR_RED : $COLOR_DARKRED; 
	$lab = $lights->Button( -text		  => "$red",
				-font		  => $font,
				-anchor		  => 'center',
				-state 		  => 'normal',
				-command	  => [\&showzones, 'red'],
				-activebackground => $clr,
				-background	  => $clr);
	$lights->put($REDROW,0,$lab);

	#
	# Add a label on the "red" zones.
	#
	if($labels)
	{
		$lab = $lights->Button( -text		  => "need attention",
					-font		  => $font,
					-anchor		  => 'w',
					-state 		  => 'normal',
					-command	=> [\&showzones, 'red'],
					-activebackground => $clr,
					-background	  => $clr);
		$lights->put($REDROW,1,$lab);
	}

	#
	# Add info on the "yellow" zones.
	#
	$clr = ($yellow > 0) ? $COLOR_YELLOW : $COLOR_DARKYELLOW; 
	$lab = $lights->Button( -text		  => "$kyellow / $zyellow",
				-font		  => $font,
				-anchor		  => 'center',
				-state 		  => 'normal',
				-command	  => [\&showzones, 'yellow'],
				-activebackground => $clr,
				-background	  => $clr);
	$lights->put($YELLOWROW,0,$lab);

	#
	# Add a label on the "yellow" zones.
	#
	if($labels)
	{
		$lab = $lights->Button( -text		  => "KSK/ZSK rollover",
					-font		  => $font,
					-anchor		  => 'center',
					-state 		  => 'normal',
					-command     => [\&showzones, 'yellow'],
					-activebackground => $clr,
					-background	  => $clr);
		$lights->put($YELLOWROW,1,$lab);
	}

	#
	# Add info on the "green" zones.
	#
	$clr = ($green > 0) ? $COLOR_GREEN : $COLOR_DARKGREEN; 
	$lab = $lights->Button( -text		  => "$green",
				-font		  => $font,
				-anchor		  => 'center',
				-state 		  => 'normal',
				-command	  => [\&showzones, 'green'],
				-activebackground => $clr,
				-background	  => $clr);
	$lights->put($GREENROW,0,$lab);

	#
	# Add a label on the "green" zones.
	#
	if($labels)
	{
		$lab = $lights->Button( -text		  => "normal operation",
					-font		  => $font,
					-anchor		  => 'e',
					-state 		  => 'normal',
					-command      => [\&showzones, 'green'],
					-activebackground => $clr,
					-background	  => $clr);
		$lights->put($GREENROW,1,$lab);
	}

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

#---------------------------------------------------------------------------
# Routine:      maketable()
#
# Purpose:      Create the table to hold the display buttons.
#
sub maketable
{
	my $numcols;				# Number of columns in table.

	#
	# Get the number of columns.
	#
	$numcols = ($labels == 0) ? 1 : 2;

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

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

}

#---------------------------------------------------------------------------
# Routine:	zonecnts()
#
# Purpose:      Figure out the counts of zones in various states.
#
sub zonecnts
{
	#
	# Reset the counters.
	#
	$green	 = 0;
	$kyellow = 0;
	$zyellow = 0;
	$red	 = 0;

	#
	# Reset the zone lists.
	#
	@greenzones = ();
	@kyellowzones = ();
	@zyellowzones = ();
	@redzones = ();

	#
	# Get the rollover status of all the zones.  There are two ways this
	# is done, depending on if the user specified a rollrec file on the
	# command line.  If so, then the zone data are read directly from the
	# rollrec file.  If not, then the zone data are gotten from rollerd
	# by using "rollctl -zonestatus".
	#
	if($rrf ne '')
	{
		#
		# Read the rollrec file.
		#
		rollrec_read($rrf);

		#
		# Get the relevant data from the rollrec records.
		#
		foreach my $rrn (sort(rollrec_names()))
		{
			my $rrr;			# Rollrec reference.
			my $zone;			# Zone name.

			$rrr = rollrec_fullrec($rrn);
			$zone = "$rrn/$rrr->{zonename}";

			if($rrr->{'kskphase'} > 0)
			{
				#
				# If we're waiting for DS-publishing, then
				# we'll bump our danger count.  Otherwise,
				# we'll increment our KSK-rollover count.
				#
				if($rrr->{'kskphase'} == 6)
				{
					$red++;
					push @redzones, $zone;
				}
				else
				{
					$kyellow++;
					push @kyellowzones, $zone;
				}
			}
			elsif($rrr->{'zskphase'} > 0)
			{
				#
				# Bump our ZSK-rollover count.
				#
				$zyellow++;
				push @zyellowzones, $zone;
			}
			else
			{
				#
				# If neither of the phase values are non-zero,
				# we're not rolling.
				#
				$green++;
				push @greenzones, $zone;
			}

		}

		rollrec_close();
	}
	else
	{
		open(ZS,"$cmd |");

		#
		# Set a bunch of counters based on output from the zone status.
		#
		while(<ZS>)
		{
			my $line = $_;
			my $zone;			# Zone name.
			my $state;			# Roll/skip state.
			my $roll;			# KSK/ZSK phase.
			my $num;			# Rollover phase number.

			#
			# Atomize the line.
			#
			chomp $line;
			$line =~ /^((.+)\/(.+))\s+(\S+)\s+([KZ]SK) (\d)/;
			$zone  = $1;
			$state = $4;
			$roll  = $5;
			$num   = $6;

			#
			# If the number atom is 0, we're not rolling.
			#
			if($num == 0)
			{
				$green++;
				push @greenzones, $zone;
			}
			elsif($roll eq 'KSK')
			{
				#
				# If we're waiting for DS-publishing, then
				# we'll bump our danger count.  Otherwise,
				# we'll increment our KSK-rollover count.
				#
				if($num == 6)
				{
					$red++;
					push @redzones, $zone;
				}
				else
				{
					$kyellow++;
					push @kyellowzones, $zone;
				}
			}
			elsif($roll eq 'ZSK')
			{
				#
				# Bump our ZSK-rollover count.
				#
				$zyellow++;
				push @zyellowzones, $zone;
			}
		}

		#
		# Clean up the status check command.
		#
		close(ZS);
	}

	#
	# Calculate the overall rollover count.
	#
	$yellow = $kyellow + $zyellow;

	#
	# If the counts have changed since our last check and the user
	# wants them, we'll print the latest counts to the screen.
	#
	if((($red     != $ored)		||
	    ($kyellow != $okyellow)	||
	    ($zyellow != $ozyellow)	||
	    ($green   != $ogreen))		&& $verbose)
	{
		print "red\t$red\n";
		print "yellow\t$yellow\t$kyellow\t$zyellow\n";
		print "green\t$green\n";
		print "\n";

		$ored	  = $red;
		$okyellow = $kyellow;
		$ozyellow = $zyellow;
		$ogreen	  = $green;
	}

}

#---------------------------------------------------------------------------
# Routine:	showzones()
#
sub showzones
{
	my $color = shift;			# Zone color to display.
	my $dlg;				# Dialog widget.
	my $lab;				# Label for dialog box.

	my @zones;				# Sorted list of zones.
	my $state = 'unknown';			# Text rollover state.

	#
	# Get the appropriate zone array and state label.
	#
	if($color eq 'green')
	{
		@zones = sort @greenzones;
		$state = 'normal operation';
	}
	elsif($color eq 'yellow')
	{
		@zones = sort @kyellowzones;
		$state = 'KSK rollover';
	}
	elsif($color eq 'red')
	{
		@zones = sort @redzones;
		$state = 'need of attention';
	}


	#
	# Make the dialog box.
	#
	$dlg = $wm->DialogBox(-title	=> "$NAME:  $color Zones",
			      -buttons	=> ["Okay"]);

	#
	# Add a label describing what we'll be showing.
	#
	$lab = $dlg->Label(-text   => "Zones in $state:",
			   -anchor => 'w');
	$lab->pack(-side => 'top');

	#
	# Fake a zone if we don't have any for this state.
	#
	push @zones, '(none)' if(@zones == 0);

	#
	# Add all the state's zones to the dialog box.
	#
	foreach my $zone (@zones)
	{
		$lab = $dlg->Label(-text => "$zone", -anchor => 'w');
		$lab->pack(-side => 'top');
	}

	#
	# If we're looking at the zones in rollover state, we'll have to add
	# lines for the ZSK-rolling zones.  We only added the KSK-rolling
	# zones above.
	#
	if($color eq 'yellow')
	{
		#
		# Get the ZSK zones.
		#
		@zones = sort @zyellowzones;
		$state = 'ZSK rollover';

		#
		# Add a blank line and a label.
		#
		$lab = $dlg->Label(-text => " ");
		$lab->pack(-side => 'top');
		$lab = $dlg->Label(-text => "Zones in $state:",
						-anchor => 'w');
		$lab->pack(-side => 'top');

		#
		# Maybe add a fake, empty zone name.
		#
		push @zones, '(none)' if(@zones == 0);

		#
		# Add entries to the dialog for all the ZSK zones.
		#
		foreach my $zone (@zones)
		{
			$lab = $dlg->Label(-text => "$zone", -anchor => 'w');
			$lab->pack(-side => 'top');
		}
	}

	#
	# Show the dialog box.
	#
	$dlg->Show();
}

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

#---------------------------------------------------------------------------
# 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_halt()
#
sub cmd_halt
{
	my $opt = shift;				# Optional "now".

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

	#
	# Wait a short bit then call are quitting routine.
	#
	sleep(2);
	cmd_quit();
}

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

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

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

#---------------------------------------------------------------------------
# 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:	help_help()
#
# Purpose:	Display a help window.
#
sub help_help
{
	my $hframe;					# Help frame.
	my $wdgt;					# General widget.

	my $helpstr;

	$helpstr = "

lights - DNSSEC-Tools Rollover Overview GUI Display
         
SYNOPSIS
         
    lights [options]

DESCRIPTION

lights gives a very simple overview of the roll status of a set of zones.
The rollover status is retrieved from rollerd, and then status counts are
given in a \"traffic light\" display.  In contrast, blinkenlights gives a
detailed display of the roll status of a set of zones.

A window is created that has three colored sections - green, yellow, and
red.  The green section displays a count of those zones that are in \"normal\"
status; that is, they are not in rollover.  The yellow section displays a
count of those zones that are in rollover.  The red section displays a count
of those zones that are in need of attention.  A common cause for this last
state is because a zone is in phase 6 of KSK rollover and is waiting for its
parent zone to publish the child's new DS record.

Clicking on the color rows in the main window will bring up a dialog box that
lists the zones in that state.  This list will not automatically update as
zones change rollover state.

More information may be found in lights' 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:      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:  lights [options] <rollrec-file>\n";
	print STDERR "\toptions:\n";
	print STDERR "\t\t-interval n           interval between file checks\n";
	print STDERR "\t\t-labels               give labels in GUI\n";
	print STDERR "\t\t-verbose              give verbose output\n";
	print STDERR "\t\t-Version              program version\n";
	print STDERR "\t\t-help                 display a help message\n";
	exit(0);
}

1;

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

=pod

=head1 NAME

lights - DNSSEC-Tools Rollover Overview GUI Display

=head1 SYNOPSIS

  lights [options]

=head1 DESCRIPTION

B<lights> gives a very simple overview of the rollover status of a set of
zones.  The rollover status counts are given in a "traffic light" display.
In contrast, B<blinkenlights> gives a detailed display of the roll status
of a set of zones.  B<lights> gives very little control over B<rollerd>,
the way B<blinkenlights> does.  B<lights> can halt B<rollerd>'s execution
only.

The rollover status is retrieved in one of two ways.  By default, B<rollerd>
is contacted via the B<rollctl> command.  Alternately, if the B<-rrf> option
is given, then zone status is read directly from a B<rollrec> file.  The
default method gets the status directly from B<rollerd> and the user need
not know the location of the relevant B<rollrec> file.  However, that method
will not get zone status until B<rollerd> is available to respond to the
information request.  Consequently, the alternate method allows B<lights>
to bypass communicating with B<rollerd> and not having to wait for B<rollerd>
to be available.

A window is created that has three colored sections - green, yellow, and red.
The green section displays a count of those zones that are in "normal" status;
that is, they are not in rollover.  The yellow section displays a count of
those zones that are in rollover.  The red section displays a count of those
zones that are in need of attention.  A common cause for this last state is
because a zone is in phase 6 of KSK rollover and is waiting for its parent
zone to publish the child's new DS record.

Clicking on the color rows in the main window will bring up a dialog box that
lists the zones in that state.  This list will not automatically update as
zones change rollover state.

=head1 OPTIONS

B<lights> supports the following options.

=over 4

=item B<-interval wait-time>

Interval between checks of zone rollover status  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<-rrf rollrec-file>

A B<rollrec> file to be read for zone status.

=item B<-labels>

Labels will be given for each color field in the GUI.

=item B<-verbose>

Give verbose output.

=item B<-help>

Give a usage message and exit.

=item B<-Version>

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

=back

=head1 REQUIREMENTS

B<lights> 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

Resizing the window leaves the color blobs in their original size.
This is an issue with the Tk widget used to display the color stripes.
Other display methods are being investigated...

=back

=head1 COPYRIGHT

Copyright 2010-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<blinkenlights(8)>,
B<bubbles(8)>,
B<rollerd(8)>,
B<rollrec(5)>

=cut