our
$VERSION
=
'2.0.10'
;
sub
status {
my
(
$self
,
$req
) =
@_
;
my
$code
= 200;
my
$response
= {
name
=>
"LemonLDAP::NG Manager API"
,
version
=>
$Lemonldap::NG::Manager::VERSION
,
status
=>
"ok"
,
status_config
=>
"ok"
,
status_sessions
=>
"ok"
,
status_psessions
=>
"ok"
,
};
my
$conf
=
$self
->_confAcc->getDBConf( {
cfgNum
=>
$self
->_confAcc->lastCfg } );
unless
(
$conf
->{cfgNum} ) {
$code
= 503;
$response
->{status} =
"ko"
;
$response
->{status_config} =
"ko"
;
}
my
$status
=
$self
->_getSessionDBState(
$self
->_getSSOMod );
if
(
$status
== 0 ) {
$code
= 503;
$response
->{status} =
"ko"
;
$response
->{status_sessions} =
"ko"
;
}
elsif
(
$status
== 2 ) {
$response
->{status_sessions} =
"unknown"
;
}
$status
=
$self
->_getSessionDBState(
$self
->_getPersistentMod );
if
(
$status
== 0 ) {
$code
= 503;
$response
->{status} =
"ko"
;
$response
->{status_psessions} =
"ko"
;
}
elsif
(
$status
== 2 ) {
$response
->{status_psessions} =
"unknown"
;
}
return
$self
->sendJSONresponse(
$req
,
$response
,
code
=>
$code
,
pretty
=> 1
);
}
sub
_getSessionDBState {
my
(
$self
,
$mod
) =
@_
;
my
$fakeobj
;
eval
{
$fakeobj
=
$self
->_getObjectSessionModule(
$mod
); };
return
2
unless
$fakeobj
;
my
$fakeobj_store
=
$fakeobj
->{object_store};
return
2
unless
$fakeobj_store
;
if
(
$fakeobj
->{object_store}->isa(
"Apache::Session::Store::DBI"
) ) {
eval
{
$fakeobj
->{object_store}->connection(
$fakeobj
) };
return
$@ ? 0 : 1;
}
if
(
$fakeobj
->{object_store}->isa(
"Apache::Session::Store::MongoDB"
) ) {
eval
{
$fakeobj
->{object_store}->connection(
$fakeobj
);
$fakeobj
->{object_store}->{collection}->estimated_document_count;
};
return
$@ ? 0 : 1;
}
return
2;
}
sub
_getObjectSessionModule {
my
(
$self
,
$mod
) =
@_
;
my
$class
=
$mod
->{module};
eval
"require $class;"
;
my
$fakeSession
= {
args
=>
$mod
->{options}, };
bless
$fakeSession
,
$class
;
$fakeSession
->populate;
return
$fakeSession
;
}
1;