#!/usr/bin/perl
# -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# sessionls - list sessions in db.
# (c) 1996-2002 ABC Startsiden AS, see the file AUTHORS.
#
# See the file LICENSE in the Giza top source distribution tree for
# licensing information. If this file is not present you are *not*
# allowed to view, run, copy or change this software or it's sourcecode.
# -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#####


#%include <config.pimpx>

#%ifdef PREFIX
#%  define INCLUDE "%{PREFIX}/include"
#%endif

#%print use lib '%{INCLUDE}';
use strict;
use Giza;
use Giza::User;
use Giza::User::SDB;

my $g = new Giza;
my $sdb = new Giza::User::SDB (giza=>$g);
$sdb->open or die $g->error, "\n";
my $sessions = $sdb->content;
my($sid, $uname, $salt, $addr, $start, $expire);

format SESSION_TOP =
ID	Username	Salt		Remote Addr	Start				Expire
-----------------------------------------------------------------------------------------------------------------
.

format SESSION =
@<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<	@<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<	@<<<<<<<<<<<<<<<<<<<<<<<<<<<
$sid,	$uname,			$salt,			$addr,				$start,					$expire
.

$^ = "SESSION_TOP";
$~ = "SESSION";


foreach $sid (sort keys %$sessions) {
	($uname, $salt, $addr, $start, $expire)
		= split ':', $sessions->{$sid};
	$start  = scalar localtime($start);
	$expire = scalar localtime($expire);
	write;
}
$sdb->close or die $g->error, "\n";

