File: PortalStatus.pl

package info (click to toggle)
lemonldap-ng 0.9.4.1-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,840 kB
  • ctags: 1,187
  • sloc: perl: 10,032; makefile: 478; xml: 93; sh: 73; sql: 69
file content (108 lines) | stat: -rwxr-xr-x 2,827 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
#!/usr/bin/perl

use CGI;
use strict;

# Status page for Lemonldap::NG::Portal
#
# This CGI displays some information about Lemonldap::NG sessions
#

BEGIN {

    sub Apache::Session::get_sessions_count {
        return 0;
    }

    sub Apache::Session::MySQL::get_sessions_count {
        my $class = shift;
        my $args  = shift;
        my $dbh =
          DBI->connect( $args->{DataSource}, $args->{UserName},
            $args->{Password} )
          or die("$!$@");
        my $table = $args->{TableName} || 'sessions';
        my $sth = $dbh->prepare("SELECT count(*) from $table");
        $sth->execute;
        return ($sth->fetchrow_array)[0];
    }

    *Apache::Session::Postgres::get_sessions_count =
      \&Apache::Session::MySQL::get_sessions_count;
    *Apache::Session::Oracle::get_sessions_count =
      \&Apache::Session::MySQL::get_sessions_count;
    *Apache::Session::Sybase::get_sessions_count =
      \&Apache::Session::MySQL::get_sessions_count;
    *Apache::Session::Informix::get_sessions_count =
      \&Apache::Session::MySQL::get_sessions_count;

    sub Apache::Session::File::get_sessions_count {
        my $class = shift;
        my $args  = shift;
        $args->{Directory} ||= '__SESSIONDIR__';
        unless ( opendir DIR, $args->{Directory} ) {
            die "Cannot open directory $args->{Directory}\n";
        }
        my @t =
          grep { -f "$args->{Directory}/$_" and /^[A-Za-z0-9@\-]+$/ }
          readdir(DIR);
        closedir DIR;
        return $#t + 1;
    }

    sub Apache::Session::DB_File::get_sessions_count {
        my $class = shift;
        my $args  = shift;

        if ( !tied %{ $class->{dbm} } ) {
            my $rv = tie %{ $class->{dbm} }, 'DB_File', $args->{FileName};

            if ( !$rv ) {
                die "Could not open dbm file $args->{FileName}: $!";
            }
        }
        my @t = keys( %{ $class->{dbm} } );
        return $#t + 1;
    }
}

use Lemonldap::NG::Common::Conf;
use Lemonldap::NG::Common::Conf::Constants;
use strict;
use DBI;

my $cgi = CGI->new();

print $cgi->header(
    -charset => 'ascii',
    -type    => 'text/plain',
);

print "LEMONLDAP::NG::PORTAL STATUS\n\nConfiguration          : ";

my $lmconf = Lemonldap::NG::Common::Conf->new();

unless ($lmconf) {
    print "unable to create conf object\n";
}
else {
    my $conf = $lmconf->getConf;
    unless ($conf) {
        write "unable to get configuration ($!)\n";
    }
    else {
        print "OK\nApache::Session module : ";
        my $tmp = $conf->{globalStorage};
        eval "use $tmp";
        if ($@) {
            print "unable to load $tmp ($@)\n";
        }
        else {
            my $t = $tmp->get_sessions_count( $conf->{globalStorageOptions} );
            print "OK\nActive sessions        : $t\n";
        }
    }
}

1;