~ubuntu-branches/ubuntu/wily/389-ds-base/wily-proposed

« back to all changes in this revision

Viewing changes to ldap/admin/src/scripts/repl-monitor.pl.in

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2014-07-08 15:50:11 UTC
  • mto: (19.1.1 experimental) (0.3.1)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20140708155011-48naeyka2x89ew8g
Tags: upstream-1.3.2.19
ImportĀ upstreamĀ versionĀ 1.3.2.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
# FILE: repl-monitor.pl
42
42
#
43
43
# SYNOPSIS:
44
 
#    repl-monitor.pl -f configuration-file [-h host] [-p port] [-r]
45
 
#                    [-u refresh-url] [-t refresh-interval]
 
44
#    repl-monitor.pl [-f configuration-file] [-h host] [-p port] [-r]
 
45
#                    [-c connection] [-a alias] [-k color] [-u refresh-url] 
 
46
#                    [-t refresh-interval] [-s] [-W]
46
47
#
47
48
#    repl-monitor.pl -v
48
49
#
111
112
#   If the color section or color entry is missing, the default color
112
113
#   set is: green for [0-5) minutes lag, yellow [5-60), and red 60 and more.
113
114
#
 
115
#   The following three options (-c, -a, -k) are used if not providing a 
 
116
#   configuration file:
 
117
#
 
118
#    -c connection
 
119
#       The connection value is the same as the configuration file value(see above):
 
120
#           -c "host:port:binddn:bindpwd:bindcert"
 
121
#
 
122
#    -a alias
 
123
#       The alias value is the same as the configuration file value(see above):
 
124
#           -a "alias=host:port"
 
125
#
 
126
#    -k color
 
127
#       The color value is written as "lowmark:color".  Where the lowmark is in minutes.
 
128
#       This option is ignored if printing a plain text report.
 
129
#           -k "5=#ccffcc"
 
130
#       
114
131
#    -h host
115
132
#       Initial replication supplier's host. Default to the current host.
116
133
#
132
149
#       the output HTML file would automatically refresh itself. This
133
150
#       is useful for continuing monitoring. See also option -t.
134
151
#
 
152
#    -s Print output in plain text, instead of HTML.
 
153
#
 
154
#    -W Prompt for connection passwords.
 
155
#
135
156
#    -v Print out the version of this script
136
157
137
158
# DIAGNOSTICS:
156
177
# If using this script standalone, be sure to set the shared lib path and
157
178
# the path to the perldap modules.
158
179
 
 
180
use strict;
 
181
use warnings;
159
182
use lib qw(@perlpath@);
160
183
 
161
 
$usage = "\nusage: $0 -f configuration-file [-h host] [-p port] [-r] [-u refresh-url] [-t refresh-interval]\n\nor   : $0 -v\n"; 
 
184
my $usage = "\nusage: $0 [-f configuration-file | --configfile configuration-file] " .
 
185
         "[-c connection, --conn connection] [-a alias, --alias alias] [-k color, --color color] " . 
 
186
         "[-h host, --host host] [-p port, --port port] [-r, --skip-header] [-s, --text] " .
 
187
         "[-u refresh-url, --url refresh-url] [-t refresh-interval, --interval refresh-interval ] " .
 
188
         "[-W, --prompt]\n\nor   : $0 -v | --version\n"; 
162
189
 
163
 
use Getopt::Std;                # parse command line arguments
 
190
use Getopt::Long;               # parse command line arguments
164
191
use Mozilla::LDAP::Conn;        # LDAP module for Perl
165
192
use Mozilla::LDAP::Utils qw(normalizeDN);       # LULU, utilities.
166
193
use Mozilla::LDAP::API qw(:api :ssl :apiv3 :constant); # Direct access to C API
169
196
#
170
197
# Global variables
171
198
#
172
 
$product = "Directory Server Replication Monitor";
173
 
$version = "Version 1.0";
 
199
my $product = "Directory Server Replication Monitor";
 
200
my $version = "Version 1.1";
174
201
#
175
202
# ldap servers given or discovered from the replication agreements:
176
 
# @servers              = (host:port=shadowport:binddn:password:cert_db)
 
203
my @servers; # = (host:port=shadowport:binddn:password:cert_db)
 
204
my $serveridx;
177
205
#
178
206
# entries read from the connection section of the configuration file:
179
 
# @allconnections       = (host:port=shadowport:binddn:password:cert_db)
 
207
my @allconnections; # = (host:port=shadowport:binddn:password:cert_db)
180
208
#
181
209
# aliases of ldap servers read from the configuration file:
182
 
# %allaliases{$host:$port}= (alias)
 
210
my %allaliases; # = {$host:$port} = (alias)
 
211
# colors
 
212
my %allcolors;
 
213
my @colorkeys;
 
214
 
183
215
#
184
216
# replicas discovered on all ldap servers
185
 
# @allreplicas          = (server#:replicaroot:replicatype:serverid:replicadn)
 
217
my @allreplicas; # = (server#:replicaroot:replicatype:serverid:replicadn)
186
218
#
187
219
# ruvs retrieved from all replicas
188
 
# @allruvs{replica#:masterid} = (rawcsn:decimalcsn;mon/day/year hh:mi:ss)
 
220
my %allruvs; # = {replica#:masterid} = (rawcsn:decimalcsn;mon/day/year hh:mi:ss)
189
221
#
190
222
# agreements discovered on all ldap supplier servers:
191
 
# @allagreements        = (supplier_replica#:consumer#:conntype:schedule:status)
 
223
my @allagreements; # = (supplier_replica#:consumer#:conntype:schedule:status)
192
224
# the array may take another format after the consumer replicas are located:
193
 
# @allagreements        = (supplier_replica#:consumer_replica#:conntype:schedule:status)
194
 
#
 
225
# @allagreements; # = (supplier_replica#:consumer_replica#:conntype:schedule:status)
 
226
#
 
227
my %ld; # ldap connection hash
 
228
#
 
229
my ($opt_f, $opt_h, $opt_p, $opt_u, $opt_t, $opt_r, $opt_s);
 
230
my (@conns, @alias, @color);
 
231
my ($section, $interval, $nowraw, $now, $mm, $dd, $tt, $yy, $wday);
 
232
my ($fn, $rc, $prompt, $last_sidx);
 
233
my %passwords = ();
 
234
my $passwd = "";
 
235
$prompt = "";
195
236
 
196
237
#main
197
238
{
199
240
        $| = 1;
200
241
 
201
242
        # Check for legal options
202
 
        if (!getopts('h:p:f:ru:t:v')) {
203
 
                print $usage;
204
 
                exit -1;
205
 
        }
 
243
        GetOptions(
 
244
                'h|host=s' => \$opt_h,
 
245
                'p|port=s' => \$opt_p,
 
246
                'f|configfile=s' => \$opt_f,
 
247
                'c|conn=s' => \@conns,
 
248
                'a|alias=s' => \@alias,
 
249
                'k|color=s' => \@color,
 
250
                'u|url=s' => \$opt_u,
 
251
                't|interval=s' => \$opt_t,
 
252
                'W|prompt' => sub { $prompt = "yes"; },
 
253
                'r|skip-header' => sub { $opt_r = "1"; },
 
254
                's|text' => sub {$opt_s = "1"; },
 
255
                'v|version' => sub { print "$product - $version\n"; exit ;}
 
256
        ) or die "Usage error: $usage\n";
206
257
 
207
 
        if ($opt_v) {
208
 
                print "$product - $version\n";
209
 
                exit;
210
 
        }
 
258
        exit -1 if &validateArgs < 0;
 
259
        exit if &read_cfg_file ($opt_f) < 0;
211
260
 
212
261
        $interval = $opt_t;
213
262
        $interval = 300 if ( !$interval || $interval <= 0 );
221
270
        if (!$opt_r) {
222
271
                # print the HTML header
223
272
                &print_html_header;
224
 
        } else {
225
 
                # print separator for new replication set
226
 
                print "<hr width=90% size=3><br>\n";
 
273
        } else  {
 
274
                if($opt_s){
 
275
                        print"\n";
 
276
                } else {
 
277
                        # print separator for new replication set
 
278
                        print "<hr width=90% size=3><br>\n";
 
279
                }
227
280
        }
228
281
 
229
 
        exit -1 if &validateArgs < 0;
230
 
        exit if &read_cfg_file ($opt_f) < 0;
231
 
 
232
282
        # Start with the given host and port
233
283
        # The index names in %ld are defined in Mozilla::LDAP::Utils::ldapArgs()
234
284
        &add_server ("$ld{host}:$ld{port}:$ld{bind}:$ld{pswd}:$ld{cert}");
235
285
 
236
286
        $serveridx = 0;
237
 
        while ($serveridx <= $#servers) {
 
287
        while ($serveridx <= $#servers) { 
238
288
                if (&get_replicas ($serveridx) != 0 && $serveridx == 0) {
239
 
                        my ($host, $port, $binddn) = split (/:/, $servers[0]);
 
289
                        my ($host, $port, $binddn) = split (/:/, $servers[$serveridx]);
240
290
                        print("Login to $host:$port as \"$binddn\" failed\n");
241
291
                        exit;
242
292
                }
253
303
 
254
304
sub validateArgs
255
305
{
256
 
        my ($rc) = 0;
 
306
        $rc = 0;
257
307
 
258
308
        %ld = Mozilla::LDAP::Utils::ldapArgs();
259
 
 
260
 
        if (!$opt_v && !$opt_f) {
261
 
                print "<p>Error: Missing configuration file.\n";
262
 
                print "<p>If you need help on the configuration file, Please go back and click the Help button.\n";
263
 
                #print $usage;  # Don't show usage in CGI
 
309
        if (!$opt_f && $#conns < 0) {
 
310
                if($opt_s){
 
311
                        print "Error: Missing configuration file or connection parameter.\n";
 
312
                        print $usage;  
 
313
                } else {
 
314
                        print "<p>Error: Missing configuration file or connection paramater.\n";
 
315
                        print "<p>If you need help on the configuration file, or script usage, " .
 
316
                        "Please go back and click the Help button.\n";
 
317
                        #print $usage; # Don't show usage in CGI
 
318
                }
264
319
                $rc = -1;
265
320
        }
266
321
        elsif (!$opt_h) {
272
327
 
273
328
sub read_cfg_file
274
329
{
275
 
        my ($fn) = @_;
276
 
        unless (open(CFGFILEHANDLE, $fn)) {
277
 
                print "<p>Error: Can't open \"$fn\": $!.\n";
278
 
                print "<p>If you need help on the configuration file, Please go back and click the Help button.\n";
279
 
                return -1;
280
 
        }
281
 
        $section = 0;
282
 
        while (<CFGFILEHANDLE>) {
283
 
                next if (/^\s*\#/ || /^\s*$/);
284
 
                chop ($_);
285
 
                if (m/^\[(.*)\]/) {
286
 
                        $section = $1;
287
 
                }
288
 
                else {
289
 
                        if ( $section =~ /conn/i ) {
290
 
                                push (@allconnections, $_);
291
 
                        }
292
 
                        elsif ( $section =~ /alias/i ) {
293
 
                                m/^\s*(\S.*)\s*=\s*(\S+)/;
294
 
                                $allaliases {$2} = $1;
295
 
                        }
296
 
                        elsif ( $section =~ /color/i ) {
297
 
                                m/^\s*(-?\d+)\s*=\s*(\S+)/;
298
 
                                $allcolors {$1} = $2;
299
 
                        }
300
 
                }
 
330
        ($fn) = @_;
 
331
        my $tmp;
 
332
        
 
333
        # process the command line config params
 
334
        @allconnections = @conns;
 
335
        if($#alias >= 0){
 
336
                foreach $tmp (@alias){
 
337
                        $tmp =~ m/^\s*(\S.*)\s*=\s*(\S+)/;
 
338
                        $allaliases{$2} = $1;
 
339
                }
 
340
        }
 
341
        if($#color >= 0){
 
342
                foreach $tmp (@color){
 
343
                        $tmp =~ m/^\s*(-?\d+)\s*=\s*(\S+)/;
 
344
                        $allcolors{$1} = $2;
 
345
                }
 
346
        }
 
347
        
 
348
        if($opt_f){
 
349
                unless (open(CFGFILEHANDLE, $fn)) {
 
350
                        if($opt_s){
 
351
                                print "Error: Can't open configuration file\"$fn\": $!.\n";
 
352
                        } else {
 
353
                                print "<p>Error: Can't open configuration file\"$fn\": $!.\n";
 
354
                                print "<p>If you need help on the configuration file, Please go back and click the Help button.\n";
 
355
                        }
 
356
                        return -1;
 
357
                }
 
358
                $section = 0;
 
359
                while (<CFGFILEHANDLE>) {
 
360
                        next if (/^\s*\#/ || /^\s*$/);
 
361
                        chop ($_);
 
362
                if (m/^\[(.*)\]/) {
 
363
                        $section = $1;
 
364
                }
 
365
                else {
 
366
                        if ( $section =~ /conn/i ) {
 
367
                                push (@allconnections, $_);
 
368
                        }
 
369
                        elsif ( $section =~ /alias/i ) {
 
370
                                m/^\s*(\S.*)\s*=\s*(\S+)/;
 
371
                                $allaliases {$2} = $1;
 
372
                        }
 
373
                        elsif ( $section =~ /color/i ) {
 
374
                                m/^\s*(-?\d+)\s*=\s*(\S+)/;
 
375
                                $allcolors {$1} = $2;
 
376
                        }
 
377
                }
 
378
        }
 
379
        close (CFGFILEHANDLE);
301
380
        }
302
381
        if ( ! keys (%allcolors) ) {
303
 
                $allcolors {0} = "#ccffcc";     #apple green
304
 
                $allcolors {5} = "#ffffcc";     #cream yellow
305
 
                $allcolors {60} = "#ffcccc";    #pale pink
 
382
                $allcolors {0} = "#ccffcc"; #apple green
 
383
                $allcolors {5} = "#ffffcc"; #cream yellow
 
384
                $allcolors {60} = "#ffcccc"; #pale pink
306
385
        }
307
386
        @colorkeys = sort (keys (%allcolors));
308
 
        close (CFGFILEHANDLE);
 
387
    
309
388
        return 0;
310
389
}
311
390
 
312
391
sub get_replicas
313
392
{
314
 
        my ($serveridx) = @_;
 
393
        $serveridx = $_[0];
315
394
        my ($conn, $host, $port, $shadowport, $binddn, $bindpwd, $bindcert);
316
395
        my ($others);
317
396
        my ($replica, $replicadn);
318
397
        my ($ruv, $replicaroot, $replicatype, $serverid, $masterid, $maxcsn);
319
398
        my ($type, $flag, $i);
320
399
        my ($myridx, $ridx, $cidx);
 
400
        my ($lastmodifiedat, $agreement);
321
401
 
322
402
        #
323
403
        # Bind to the server
324
404
        #
 
405
        if($#servers < 0 || $serveridx > $#servers + 1){
 
406
                return -1;
 
407
        }
 
408
 
325
409
        ($host, $port, $binddn, $bindpwd, $bindcert) = split (/:/, "$servers[$serveridx]", 5);
326
 
 
327
410
        ($port, $shadowport) = split (/=/, $port);
328
411
        $shadowport = $port if !$shadowport;
329
412
 
330
413
        $conn = new Mozilla::LDAP::Conn ($host, $shadowport, "$binddn", $bindpwd, $bindcert);
331
 
 
332
414
        return -1 if (!$conn);
333
415
 
334
416
        #
508
590
 
509
591
sub process_suppliers
510
592
{
511
 
        my ($ridx, $mid, $maxcsn);
512
 
 
 
593
        my ($ridx, $mid, $maxcsn, $ismaster);
 
594
        $ismaster = 0;
513
595
        $mid = "";
514
 
        $ismaster = 0;
515
596
 
516
597
        $last_sidx = -1;        # global variable for print html page
517
598
 
518
599
        for ($ridx = 0; $ridx <= $#allreplicas; $ridx++) {
519
 
 
520
600
                # Handle masters and hubs
521
601
                if ($allreplicas[$ridx] =~ /:master:(\d+):/i) {
522
602
                        $mid = $1;
523
603
 
524
604
                        # Skip replicas without agreements defined yet
525
605
                        next if (! grep {$_->{ridx} == $ridx} @allagreements);
526
 
 
527
606
                        $maxcsn = &print_master_header ($ridx, $mid);
528
 
                        if ( "$maxcsn" != "none" ) {
 
607
                        if ( "$maxcsn" ne "none" ) {
529
608
                                &print_consumer_header ();
530
609
                                &print_consumers ($ridx, $mid);
531
610
                        }
536
615
                        # Skip replicas without agreements defined yet
537
616
                        next if (! grep {$_->{ridx} == $ridx} @allagreements);
538
617
 
539
 
                    foreach $key (keys %allruvs) {
 
618
                    foreach my $key (keys %allruvs) {
540
619
                                if ( $key =~ /$ridx:/) {
541
620
                                        my ($myridx, $mymid) = split ( /:/, "$key" );
542
621
                                        $maxcsn = &print_hub_header($myridx, $mymid);
549
628
        }
550
629
 
551
630
        if ($mid eq "") {
552
 
                print "<p>The server is not a master or a hub or it has no replication agreement\n";
 
631
                if($opt_s){
 
632
                        print "The server is not a master or a hub or it has no replication agreement\n";
 
633
                } else {
 
634
                        print "<p>The server is not a master or a hub or it has no replication agreement\n";
 
635
                }
553
636
        }
554
637
}
555
638
 
560
643
        my ($maxcsnval) = split ( /;/, "$myruv" );
561
644
        my ($maxcsn) = &to_string_csn ($maxcsnval);
562
645
        my ($sidx, $replicaroot, $replicatype, $serverid) = split (/:/, $allreplicas[$ridx]);
563
 
 
564
 
        if ( $maxcsn == "" ) {
 
646
    
 
647
        if ( $maxcsn eq "" ) {
565
648
                return $maxcsn;
566
649
        }
567
650
 
568
651
        # Print the master name
569
 
        if ( $last_sidx != $sidx ) {
 
652
        if ( $last_sidx ne $sidx ) {
570
653
                my ($ldapurl) = &get_ldap_url ($sidx, $sidx);
571
654
                &print_legend if ( $last_sidx < 0);
572
 
                print "<p><p><hr><p>\n";
573
 
                print "\n<p><center class=page-subtitle><font color=#0099cc>\n";
574
 
                print "Master:&nbsp $ldapurl</center>\n";
 
655
                if($opt_s){
 
656
                        print "Master: $ldapurl\n"
 
657
                } else {
 
658
                        print "<p><p><hr><p>\n";
 
659
                        print "\n<p><center class=page-subtitle><font color=#0099cc>\n";
 
660
                        print "Master:&nbsp $ldapurl</center>\n";
 
661
                }
575
662
                $last_sidx = $sidx;
576
663
        }
577
664
 
578
665
        # Print the current replica info onthe master
579
 
        print "\n<p><table border=0 cellspacing=1 cellpadding=6 cols=10 width=100% class=bgColor9>\n";
580
 
 
581
 
        print "\n<tr><td colspan=10><center>\n";
582
 
        print "<font class=areatitle>Replica ID:&nbsp;</font>";
583
 
        print "<font class=text28>$serverid</font>\n";
584
 
 
585
 
        print "<font class=areatitle>Replica Root:&nbsp;</font>";
586
 
        print "<font class=text28>$replicaroot</font>\n";
587
 
 
588
 
        print "<font class=areatitle>Max CSN:&nbsp;</font>";
589
 
        print "<font class=text28>$maxcsn</font>\n";
590
 
 
 
666
        if($opt_s){
 
667
                print "Replica ID: $serverid\n";
 
668
                print "Replica Root: $replicaroot\n";
 
669
                print "Max CSN: $maxcsn\n";
 
670
        } else {
 
671
                print "\n<p><table border=0 cellspacing=1 cellpadding=6 cols=10 width=100% class=bgColor9>\n";
 
672
                print "\n<tr><td colspan=10><center>\n";
 
673
                print "<font class=areatitle>Replica ID:&nbsp;</font>";
 
674
                print "<font class=text28>$serverid</font>\n";
 
675
                print "<font class=areatitle>Replica Root:&nbsp;</font>";
 
676
                print "<font class=text28>$replicaroot</font>\n";
 
677
                print "<font class=areatitle>Max CSN:&nbsp;</font>";
 
678
                print "<font class=text28>$maxcsn</font>\n";
 
679
        }
591
680
        return $maxcsn;
592
681
}
593
682
 
597
686
        my ($myruv) = $allruvs {"$ridx:$mid"};
598
687
        my ($maxcsnval) = split ( /;/, "$myruv" );
599
688
        my ($maxcsn) = &to_string_csn ($maxcsnval);
600
 
        my ($sidx, $replicaroot, $replicatype, $serverid) = split (/:/, $allreplicas[$ridx]);
 
689
        my ($sidx, $last_sidx, $replicaroot, $replicatype, $serverid) = split (/:/, $allreplicas[$ridx]);
601
690
 
602
691
        # Print the master name
603
692
        if ( $last_sidx != $sidx ) {
604
693
                my ($ldapurl) = &get_ldap_url ($sidx, $sidx);
605
694
                &print_legend if ( $last_sidx < 0);
606
 
                print "<p><p><hr><p>\n";
607
 
                print "\n<p><center class=page-subtitle><font color=#0099cc>\n";
608
 
                print "Hub:&nbsp $ldapurl</center>\n";
 
695
                if($opt_s){
 
696
                        print "Hub: $ldapurl\n";
 
697
                } else {
 
698
                        print "<p><p><hr><p>\n";
 
699
                        print "\n<p><center class=page-subtitle><font color=#0099cc>\n";
 
700
                        print "Hub:&nbsp $ldapurl</center>\n";
 
701
                }
609
702
                $last_sidx = $sidx;
610
703
        }
611
704
 
612
705
        # Print the current replica info onthe master
613
 
        print "\n<p><table border=0 cellspacing=1 cellpadding=6 cols=10 width=100% class=bgColor9>\n";
614
 
 
615
 
        print "\n<tr><td colspan=10><center>\n";
616
 
        print "<font class=areatitle>Replica ID:&nbsp;</font>";
617
 
        print "<font class=text28>$serverid</font>\n";
618
 
 
619
 
        print "<font class=areatitle>Replica Root:&nbsp;</font>";
620
 
        print "<font class=text28>$replicaroot</font>\n";
621
 
 
622
 
        print "<font class=areatitle>Max CSN:&nbsp;</font>";
623
 
        print "<font class=text28>$maxcsn</font>\n";
624
 
 
 
706
        if($opt_s){
 
707
                print "Replica ID: $serverid\n";
 
708
                print "Replica Root: $replicaroot\n";
 
709
                print "Max CSN: $maxcsn\n";
 
710
        } else {
 
711
                print "\n<p><table border=0 cellspacing=1 cellpadding=6 cols=10 width=100% class=bgColor9>\n";
 
712
                print "\n<tr><td colspan=10><center>\n";
 
713
                print "<font class=areatitle>Replica ID:&nbsp;</font>";
 
714
                print "<font class=text28>$serverid</font>\n";
 
715
                print "<font class=areatitle>Replica Root:&nbsp;</font>";
 
716
                print "<font class=text28>$replicaroot</font>\n";
 
717
                print "<font class=areatitle>Max CSN:&nbsp;</font>";
 
718
                print "<font class=text28>$maxcsn</font>\n";
 
719
        }
625
720
        return $maxcsn;
626
721
}
627
722
 
628
723
sub print_consumer_header
629
724
{
 
725
        if($opt_s) { return; } # we'll do the text printing in "print_consumers"
 
726
        
630
727
        #Print the header of consumer
631
728
        print "\n<tr class=bgColor16>\n";
632
729
        print "<th nowrap>Receiver</th>\n";
648
745
        my ($m_ridx, $mid) = @_;
649
746
        my ($ignore, $m_replicaroot) = split (/:/, $allreplicas[$m_ridx]);
650
747
        my (@consumers, @ouragreements, @myagreements);
651
 
        my ($s_ridx, $c_ridx, $conntype, $schedule, $status);
652
 
        my ($c_maxcsn_str, $lag, $markcolor);
 
748
        my ($s_ridx, $c_ridx, $s_sidx, $conntype, $schedule, $status);
 
749
        my ($c_maxcsn, $c_maxcsn_str, $c_lastmodified, $c_sidx, $lag, $markcolor);
653
750
        my ($c_replicaroot, $c_replicatype);
654
 
        my ($first_entry);
 
751
        my ($first_entry, $s_ldapurl, $c_ldapurl);
655
752
        my ($nrows);
656
753
        my ($found);
657
754
 
658
755
        undef @ouragreements;
659
 
 
 
756
        $c_lastmodified = "";
 
757
    
660
758
        # Collect all the consumer replicas for the current master replica
661
759
        push (@consumers, $m_ridx);
662
760
        foreach (@consumers) {
688
786
                        $myruv = $allruvs {"$c_ridx:$mid"};
689
787
                        ($c_maxcsn, $c_lastmodified) = split ( /;/, "$myruv" );
690
788
                        ($c_maxcsn_str, $lag, $markcolor) = &cacl_time_lag ($m_maxcsn, $c_maxcsn);
691
 
                        $c_maxcsn_str =~ s/ /\<br\>/;
 
789
                        if(!$opt_s){ $c_maxcsn_str =~ s/ /\<br\>/; }
692
790
                        ($c_sidx, $c_replicaroot, $c_replicatype) = split (/:/, $allreplicas[$c_ridx]);
693
791
                        $c_replicaroot = "same as master" if $m_replicaroot eq $c_replicaroot;
694
792
                }
697
795
                        $c_sidx = -$c_ridx;
698
796
                        $c_maxcsn_str = "_";
699
797
                        $lag = "n/a";
700
 
                        $markcolor = red;
 
798
                        $markcolor = "red";
701
799
                        $c_replicaroot = "_";
702
800
                        $c_replicatype = "_";
703
801
                }
719
817
                        $s_ldapurl = &get_ldap_url ($s_sidx, "n/a");
720
818
 
721
819
                        # Print out the consumer's replica and ruvs
722
 
                        print "\n<tr class=bgColor13>\n";
 
820
                        if(!$opt_s){ print "\n<tr class=bgColor13>\n"; }
723
821
                        if ($first_entry) {
724
822
                                $first_entry = 0;
725
823
                                $c_ldapurl = &get_ldap_url ($c_sidx, $conntype);
726
 
                                print "<td rowspan=$nrows width=5% class=bgColor5>$c_ldapurl<BR>Type: $c_replicatype</td>\n";
727
 
                                print "<td rowspan=$nrows width=5% nowrap bgcolor=$markcolor><center>$lag</center></td>\n";
728
 
                                print "<td rowspan=$nrows width=15% nowrap>$c_maxcsn_str</td>\n";
729
 
                                print "<td rowspan=$nrows width=15% nowrap>$c_lastmodified</td>\n";
730
 
                        }
731
 
                        print "<td width=5% nowrap><center>$s_ldapurl</center></td>\n";
 
824
                                if($opt_s){
 
825
                                        print "Receiver: $c_ldapurl\nType: $c_replicatype\n";
 
826
                                        print "Time Lag: $lag\n";
 
827
                                        print "Max CSN: $c_maxcsn_str\n";
 
828
                                        print "Last Modify Time: $c_lastmodified\n";
 
829
                                } else {
 
830
                                        print "<td rowspan=$nrows width=5% class=bgColor5>$c_ldapurl<BR>Type: $c_replicatype</td>\n";
 
831
                                        print "<td rowspan=$nrows width=5% nowrap bgcolor=$markcolor><center>$lag</center></td>\n";
 
832
                                        print "<td rowspan=$nrows width=15% nowrap>$c_maxcsn_str</td>\n";
 
833
                                        print "<td rowspan=$nrows width=15% nowrap>$c_lastmodified</td>\n";
 
834
                                }
 
835
                        }
 
836
                        if($opt_s){ 
 
837
                                print "Supplier: $s_ldapurl\n";
 
838
                        } else {
 
839
                                print "<td width=5% nowrap><center>$s_ldapurl</center></td>\n";
 
840
                        }
732
841
                        my $changecount = $_->{nsds5replicaChangesSentSinceStartup};
733
842
                        if ( $changecount =~ /^$mid:(\d+)\/(\d+) / || $changecount =~ / $mid:(\d+)\/(\d+) / ) {
734
843
                                $changecount = "$1 / $2";
739
848
                        else {
740
849
                                $changecount = "0 / 0";
741
850
                        }
742
 
                        print "<td width=3% nowrap>$changecount</td>\n";       
 
851
                        if($opt_s){
 
852
                                print "Sent/Skipped: $changecount\n";
 
853
                        } else {
 
854
                                print "<td width=3% nowrap>$changecount</td>\n";
 
855
                        }   
743
856
                        my $redfontstart = "";
744
857
                        my $redfontend = "";
745
858
                        if ($status =~ /error/i) {
753
866
                                        $redfontend = "</font>";
754
867
                                }
755
868
                        }
756
 
                        print "<td width=20% nowrap>$redfontstart$status$redfontend</td>\n";
757
 
                        print "<td nowrap>", &format_z_time($_->{nsds5replicaLastUpdateStart}), "</td>\n";
758
 
                        print "<td nowrap>", &format_z_time($_->{nsds5replicaLastUpdateEnd}), "</td>\n";
 
869
                        if($opt_s){
 
870
                                print "Update Status: $status\n";
 
871
                                print "Update Started: ", &format_z_time($_->{nsds5replicaLastUpdateStart}), "\n";
 
872
                                print "Update Ended: ", &format_z_time($_->{nsds5replicaLastUpdateEnd}), "\n";                  
 
873
                        } else {
 
874
                                print "<td width=20% nowrap>$redfontstart$status$redfontend</td>\n";
 
875
                                print "<td nowrap>", &format_z_time($_->{nsds5replicaLastUpdateStart}), "</td>\n";
 
876
                                print "<td nowrap>", &format_z_time($_->{nsds5replicaLastUpdateEnd}), "</td>\n";
 
877
                        }
759
878
                        if ( $schedule =~ /always/i ) {
760
 
                                print "<td colspan=2 width=10% nowrap>$schedule</td>\n";
 
879
                                if($opt_s){
 
880
                                        print "Schedule: $schedule\n";
 
881
                                } else {
 
882
                                        print "<td colspan=2 width=10% nowrap>$schedule</td>\n";
 
883
                                }
761
884
                        }
762
885
                        else {
763
886
                                my ($ndays, @days);
764
887
                                $schedule =~ /(\d\d)(\d\d)-(\d\d)(\d\d) (\d+)/;
765
 
                                print "<td width=10% nowrap>$1:$2-$3:$4</td>\n";
 
888
                                if($opt_s){
 
889
                                    print "Schedule: $1:$2-$3:$4 ";
 
890
                                } else {
 
891
                                    print "<td width=10% nowrap>$1:$2-$3:$4</td>\n";
 
892
                                }
766
893
                                $ndays = $5;
767
894
                                $ndays =~ s/(\d)/$1,/g;
768
 
                                @days = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[eval $ndays];
769
 
                                print "<td width=10% nowrap>@days</td>\n";
770
 
                        }
771
 
                        print "<td width=3% nowrap class=bgColor5>$conntype</td>\n";
 
895
                                @days = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat")[eval $ndays];
 
896
                                if($opt_s){
 
897
                                    print "@days\n";
 
898
                                } else {
 
899
                                    print "<td width=10% nowrap>@days</td>\n";
 
900
                                }
 
901
                        }
 
902
                        if($opt_s){
 
903
                                print "SSL: $conntype\n";
 
904
                        } else {
 
905
                                print "<td width=3% nowrap class=bgColor5>$conntype</td>\n";
 
906
                        }
772
907
                }
773
908
        }
774
909
}
778
913
        my ($s_maxcsn, $c_maxcsn) = @_;
779
914
        my ($markcolor);
780
915
        my ($csn_str);
781
 
        my ($s_tm, $c_tm, $lag_tm, $lag_str, $hours, $minute);
 
916
        my ($s_tm, $c_tm, $lag_tm, $lag_str, $hours, $minutes);
782
917
 
783
918
        $csn_str = &to_string_csn ($c_maxcsn);
784
919
 
831
966
#
832
967
sub add_server
833
968
{
834
 
        my ($host, $port, $binddn, $bindpwd, $bindcert) = split (/:/, "@_");
 
969
        my ($host, $port, $binddn, $bindpwd, $bindcert) = split (/:/, "$_[0]");
835
970
        my ($shadowport) = $port;
836
971
        my ($domainpattern) = '\.[^:]+';
837
972
        my ($i);
846
981
        $hostnode = $1 if $host =~ /^(.+?)\./;
847
982
 
848
983
        # new host:port
849
 
        if ($binddn eq "" || $bindpwd eq "" && $bindcert eq "") {
 
984
        if (!$binddn || $binddn eq "" || !$bindpwd || $bindpwd eq "" || !$bindcert || $bindcert eq "") {
850
985
                #
851
986
                # Look up connection parameter in the order of
852
987
                #       host:port
855
990
                #       *:*
856
991
                #
857
992
                my (@myconfig, $h, $p, $d, $w, $c);
858
 
                (@myconfig = grep (/^$hostnode($domainpattern)*:$port\D/i, @allconnections)) ||
 
993
                $h = ""; $p = ""; $d = ""; $w = ""; $c = "";
 
994
                (@myconfig = grep (/^$hostnode($domainpattern)*:[0-9]+\D/i, @allconnections)) ||
859
995
                (@myconfig = grep (/^$hostnode($domainpattern)*:\*:/i, @allconnections)) ||
860
996
                (@myconfig = grep (/^\*:$port\D/, @allconnections)) ||
861
997
                (@myconfig = grep (/^\*:\*\D/, @allconnections));
862
998
                if ($#myconfig >= 0) {
863
999
                        ($h, $p, $d, $w, $c) = split (/:/, $myconfig[0]);
864
1000
                        ($p, $shadowport) = split (/=/, $p);
865
 
                        $p = "" if $p eq "*";
866
 
                        $c = "" if $c eq "*";
 
1001
                        if(!$p || $p eq "*"){
 
1002
                                $p = "";
 
1003
                        }
 
1004
                        if(!$c || $c eq "*"){
 
1005
                                $c = "";
 
1006
                        }
 
1007
                        if(!$w || $w eq "*"){
 
1008
                $w = "";
 
1009
            }
867
1010
                }
868
 
                if ($binddn eq "" || $binddn eq "*") {
 
1011
                if (!$binddn || $binddn eq "" || $binddn eq "*") {
869
1012
                        if ($d eq "" || $d eq "*") {
870
1013
                                $binddn = "cn=Directory Manager";
871
1014
                        }
873
1016
                                $binddn = $d;
874
1017
                        }
875
1018
                }
876
 
                $bindpwd = $w if ($bindpwd eq "" || $bindpwd eq "*");
877
 
                $bindcert = $c if ($bindcert eq "" || $bindcert eq "*");
 
1019
                if($prompt eq "yes" && ($w eq "" || (!$bindpwd || $bindpwd eq ""))){
 
1020
            $bindpwd = passwdPrompt($h, $p);
 
1021
                } elsif ($passwd ne ""){
 
1022
            $bindpwd = $passwd;
 
1023
                } else {
 
1024
            $bindpwd = $w if (!$bindpwd || $bindpwd eq "" || $bindpwd eq "*");
 
1025
        }
 
1026
                $bindcert = $c if (!$bindcert || $bindcert eq "" || $bindcert eq "*");
878
1027
        }
879
1028
 
880
1029
        if ($shadowport) {
885
1034
        return $i;
886
1035
}
887
1036
 
 
1037
sub
 
1038
passwdPrompt
 
1039
{
 
1040
    my ($h, $p) = @_;
 
1041
    my $key = "$h:$p";
 
1042
    my $pw = "";
 
1043
    
 
1044
    if ($passwords{$key}){
 
1045
        # we already have a password for this replica     
 
1046
        return $passwords{$key};
 
1047
    }
 
1048
    # Disable console echo
 
1049
    system("@sttyexec@ -echo") if -t STDIN;
 
1050
 
 
1051
    while ($pw eq ""){
 
1052
        if($passwd ne ""){
 
1053
            print "Enter password for ($h:$p) <hit Enter to use previous password>: ";
 
1054
            chomp($pw = <>);
 
1055
            if ($pw eq ""){
 
1056
                $pw = $passwd;
 
1057
            } else {
 
1058
                $passwords{$key} = $pw;
 
1059
                $passwd = $pw;         
 
1060
            }
 
1061
        } else {
 
1062
            print "Enter password for ($h:$p): ";
 
1063
            chomp($pw = <>);
 
1064
            $passwords{$key} = $pw;
 
1065
            $passwd = $pw;
 
1066
        }
 
1067
    }
 
1068
    # Enable console echo
 
1069
    system("@sttyexec@ echo") if -t STDIN;
 
1070
 
 
1071
    return $pw;
 
1072
}
 
1073
 
888
1074
sub get_ldap_url
889
1075
{
890
1076
        my ($sidx, $conntype) = @_;
893
1079
        ($port, $shadowport) = split (/=/, $port);
894
1080
        my ($protocol, $ldapurl);
895
1081
 
896
 
        if ($port eq 636 && $conntype eq "0" || $conntype =~ /SSL/i) {
897
 
                $protocol = ldaps;
 
1082
        if ($port == 636 && $conntype eq "0" || $conntype =~ /SSL/i) {
 
1083
                $protocol = "ldaps";
898
1084
        }
899
1085
        else {
900
 
                $protocol = ldap;
 
1086
                $protocol = "ldap";
901
1087
        }
902
1088
        my ($instance) = $allaliases { "$host:$port" };
903
1089
        $instance = "$host:$port" if !$instance;
904
1090
        if ($conntype eq "n/a") {
905
1091
                $ldapurl = $instance;
906
 
        }
907
 
        else {
908
 
                $ldapurl = "<a href=\"$protocol://$host:$port/\">$instance</a>";
 
1092
        } else {
 
1093
                if($opt_s){
 
1094
                        $ldapurl = "$instance $protocol://$host:$port/";
 
1095
                } else {
 
1096
                        $ldapurl = "<a href=\"$protocol://$host:$port/\">$instance</a>";
 
1097
                }
909
1098
        }
910
1099
        return $ldapurl;
911
1100
}
950
1139
        my ($lag_minute) = @_;
951
1140
        $lag_minute /= 60;
952
1141
        my ($color) = $allcolors { $colorkeys[0] };
953
 
        foreach (@colorkeys) {
 
1142
        
 
1143
        foreach ( keys %allcolors) {
954
1144
                last if ($lag_minute < $_);
955
1145
                $color = $allcolors {$_};
956
1146
        }
969
1159
 
970
1160
sub print_html_header
971
1161
{
972
 
        # print the HTML header
973
 
 
974
 
        print "Content-type: text/html\n\n";
975
 
        print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\"><html>\n";
976
 
        print "<head><title>Replication Status</title>\n";
977
 
        # print "<link type=text/css rel=stylesheet href=\"master-style.css\">\n";
978
 
        print "<style text/css>\n";
979
 
        print "Body, p, table, td, ul, li {color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 12px;}\n";
980
 
        print "A {color:blue; text-decoration: none;}\n";
981
 
        print "BODY {font-family: arial, helvetica, sans-serif}\n";
982
 
        print "P {font-family: arial, helvetica, sans-serif}\n";
983
 
        print "TH {font-weight: bold; font-family: arial, helvetica, sans-serif}\n";
984
 
        print "TD {font-family: arial, helvetica, sans-serif}\n";
985
 
        print ".bgColor1  {background-color: #003366;}\n";
986
 
        print ".bgColor4  {background-color: #cccccc;}\n";
987
 
        print ".bgColor5  {background-color: #999999;}\n";
988
 
        print ".bgColor9  {background-color: #336699;}\n";
989
 
        print ".bgColor13 {background-color: #ffffff;}\n";
990
 
        print ".bgColor16 {background-color: #6699cc;}\n";
991
 
        print ".text8  {color: #0099cc; font-size: 11px; font-weight: bold;}\n";
992
 
        print ".text28 {color: #ffcc33; font-size: 12px; font-weight: bold;}\n";
993
 
        print ".areatitle {font-weight: bold; color: #ffffff; font-family: arial, helvetica, sans-serif}\n";
994
 
        print ".page-title {font-weight: bold; font-size: larger; font-family: arial, helvetica, sans-serif}\n";
995
 
        print ".page-subtitle {font-weight: bold; font-family: arial, helvetica, sans-serif}\n";
996
 
 
997
 
        print "</style></head>\n<body class=bgColor4>\n";
998
 
 
999
 
        if ($opt_u) {
1000
 
                print "<meta http-equiv=refresh content=$interval; URL=$opt_u>\n";
1001
 
        }
1002
 
 
1003
 
        print "<table border=0 cellspacing=0 cellpadding=10 width=100% class=bgColor1>\n";
1004
 
        print "<tr><td><font class=text8>$now</font></td>\n";
1005
 
        print "<td align=center class=page-title><font color=#0099CC>";
1006
 
        print "Directory Server Replication Status</font>\n";
1007
 
 
1008
 
        if ($opt_u) {
1009
 
                print "<br><font class=text8>(This page updates every $interval seconds)</font>\n";
1010
 
        }
1011
 
 
1012
 
        print "</td><td align=right valign=center width=25%><font class=text8>$version";
1013
 
        print "</font></td></table>\n";
 
1162
    if(!$opt_s){
 
1163
        # print the HTML header
 
1164
    
 
1165
        print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\"><html>\n";
 
1166
        print "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">\n";
 
1167
        print "<head><title>Replication Status</title>\n";
 
1168
        # print "<link type=text/css rel=stylesheet href=\"master-style.css\">\n";
 
1169
        print "<style text/css>\n";
 
1170
        print "Body, p, table, td, ul, li {color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 12px;}\n";
 
1171
        print "A {color:blue; text-decoration: none;}\n";
 
1172
        print "BODY {font-family: arial, helvetica, sans-serif}\n";
 
1173
        print "P {font-family: arial, helvetica, sans-serif}\n";
 
1174
        print "TH {font-weight: bold; font-family: arial, helvetica, sans-serif}\n";
 
1175
        print "TD {font-family: arial, helvetica, sans-serif}\n";
 
1176
        print ".bgColor1  {background-color: #003366;}\n";
 
1177
        print ".bgColor4  {background-color: #cccccc;}\n";
 
1178
        print ".bgColor5  {background-color: #999999;}\n";
 
1179
        print ".bgColor9  {background-color: #336699;}\n";
 
1180
        print ".bgColor13 {background-color: #ffffff;}\n";
 
1181
        print ".bgColor16 {background-color: #6699cc;}\n";
 
1182
        print ".text8  {color: #0099cc; font-size: 11px; font-weight: bold;}\n";
 
1183
        print ".text28 {color: #ffcc33; font-size: 12px; font-weight: bold;}\n";
 
1184
        print ".areatitle {font-weight: bold; color: #ffffff; font-family: arial, helvetica, sans-serif}\n";
 
1185
        print ".page-title {font-weight: bold; font-size: larger; font-family: arial, helvetica, sans-serif}\n";
 
1186
        print ".page-subtitle {font-weight: bold; font-family: arial, helvetica, sans-serif}\n";
 
1187
        print "</style></head>\n<body class=bgColor4>\n";
 
1188
    
 
1189
        if ($opt_u) {
 
1190
                print "<meta http-equiv=refresh content=$interval; URL=$opt_u>\n";
 
1191
        }
 
1192
    
 
1193
        print "<table border=0 cellspacing=0 cellpadding=10 width=100% class=bgColor1>\n";
 
1194
        print "<tr><td><font class=text8>$now</font></td>\n";
 
1195
        print "<td align=center class=page-title><font color=#0099CC>";
 
1196
        print "Directory Server Replication Status</font>\n";
 
1197
    
 
1198
        if ($opt_u) {
 
1199
                print "<br><font class=text8>(This page updates every $interval seconds)</font>\n";
 
1200
        }
 
1201
    
 
1202
        print "</td><td align=right valign=center width=25%><font class=text8>$version";
 
1203
        print "</font></td></table>\n";
 
1204
    } else {
 
1205
        print "Directory Server Replication Status ($version)\n\n";
 
1206
        print "Time: $now";
 
1207
        if ($opt_u) {
 
1208
                print " - This report updates every $interval seconds\n\n";
 
1209
        } else {
 
1210
                print "\n\n";
 
1211
        }
 
1212
    }
1014
1213
}
1015
1214
 
1016
1215
sub print_legend
1017
1216
{
1018
1217
        my ($nlegends) = $#colorkeys + 1;
 
1218
        if($opt_s){ return; }
1019
1219
        print "\n<center><p><font class=page-subtitle color=#0099cc>Time Lag Legend:</font><p>\n";
1020
1220
        print "<table cellpadding=6 cols=$nlegends width=40%>\n<tr>\n";
1021
1221
        my ($i, $j);
1031
1231
 
1032
1232
sub print_supplier_end
1033
1233
{
1034
 
        print "</table>\n";
 
1234
        if(!$opt_s){ print "</table>\n"; }
1035
1235
}
1036
1236
 
1037
1237
# given a string in generalized time format, convert to ascii time