From 64f75b74e08d7166ff4a5cb6bbe985e1ddfe9a3c Mon Sep 17 00:00:00 2001 From: Yadd Date: Wed, 10 Apr 2024 06:43:31 +0400 Subject: [PATCH] Add > and < in lemonldap-ng-sessions conditions --- .../lib/Lemonldap/NG/Common/Apache/Session.pm | 23 +++++++++++++++++++ .../lib/Lemonldap/NG/Common/CliSessions.pm | 8 +++++++ .../scripts/lemonldap-ng-sessions | 3 +++ 3 files changed, 34 insertions(+) diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session.pm index 2d57012c09..3bcc9e3cc1 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Apache/Session.pm @@ -137,6 +137,29 @@ sub searchOnExpr { return \%res; } +sub searchGt { + my ( $class, $args, $selectField, $value, @fields ) = splice @_; + return $args->{backend}->searchGt( $args, $selectField, $value, @fields ) + if ( _load( $args->{backend}, 'searchGt' ) ); + my %res = (); + $class->get_key_from_all_sessions( + $args, + sub { + my $entry = shift; + my $id = shift; + return undef unless ( $entry->{$selectField} > $value ); + if (@fields) { + $res{$id}->{$_} = $entry->{$_} foreach (@fields); + } + else { + $res{$id} = $entry; + } + undef; + } + ); + return \%res; +} + sub searchLt { my ( $class, $args, $selectField, $value, @fields ) = splice @_; return $args->{backend}->searchLt( $args, $selectField, $value, @fields ) diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/CliSessions.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/CliSessions.pm index 5c855e79b8..9863b59ea0 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/CliSessions.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/CliSessions.pm @@ -73,6 +73,14 @@ sub _search { $res = Lemonldap::NG::Common::Apache::Session->searchOn( $args, $selectField, $value, @fields ); } + elsif ( $self->opts->{where} =~ /^(\w+)\s*<\s*(.*)/ ) { + $res = Lemonldap::NG::Common::Apache::Session->searchLt( $args, + $1, $2, @fields ); + } + elsif ( $self->opts->{where} =~ /^(\w+)\s*>\s*(.*)/ ) { + $res = Lemonldap::NG::Common::Apache::Session->searchGt( $args, + $1, $2, @fields ); + } else { die "Invalid --where option : " . $self->opts->{where}; } diff --git a/lemonldap-ng-common/scripts/lemonldap-ng-sessions b/lemonldap-ng-common/scripts/lemonldap-ng-sessions index d68e21060b..19dbf8f639 100755 --- a/lemonldap-ng-common/scripts/lemonldap-ng-sessions +++ b/lemonldap-ng-common/scripts/lemonldap-ng-sessions @@ -179,6 +179,9 @@ Examples lemonldap-ng-sessions search --where uid=dwho \ --select authenticationLevel + lemonldap-ng-sessions search --where '_startTime>20240410063538' + lemonldap-ng-sessions search --where '_startTime<20240410063538' + =head2 Delete lemonldap-ng-sessions delete [ ...] -- GitLab