Project

General

Profile

Download (673 Bytes) Statistics
| Branch: | Revision:

root / scripts / stat_openldap @ 865f4ff4

1
#!/usr/bin/perl
2

    
3
# example parameter: /operations/add/monitorOpCompleted
4

    
5
use warnings;
6
use strict;
7
use File::Basename;
8
use IO::File;
9
use Data::Dumper;
10

    
11
my $param = $ARGV[0];
12
unless ($param =~ m#^(/[a-zA-Z0-9 ]+)+$#)
13
{
14
	exit 1;
15
}
16

    
17
my $location = 'cn=' . join(',cn=', reverse(split(qr(/), dirname($param)))) . "monitor";
18
my $attr = basename($param);
19

    
20
my $fh = IO::File->new;
21
# shell escapes are not possible, $param was check earlier using regex
22
$fh->open('ldapsearch -Q -Y EXTERNAL -H ldapi:/// -b "' . $location . '" -s base -LLL "' . $attr . '" 2>/dev/null |');
23
while (my $line = $fh->getline)
24
{
25
	if ($line =~ m/^$attr: (.*)$/)
26
	{
27
		print "$1\n";
28
		exit 0;
29
	}
30
}
31

    
32
exit 2;
(7-7/8)