#!/usr/bin/perl # MimerDesk # Web based groupware and eLearning environment # www.mimerdesk.org # # Copyright (C) 2001 Ionstream Ltd. # www.ionstream.fi # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # This program is distributed with a hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # $Id: sessions.html,v 1.9 2002/07/14 09:07:24 inf Exp $ ########################################### # # # MimerDesk: Session manager # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Oy 1999 - 2001 # # # # Programmed by: Teemu Arina # # # ########################################### # Asetukset ################################## $APPLICATION = 'Tools - Sessions'; use strict; use Socket; use vars qw ($APPLICATION $ACTIVEGRP $ARTICLE $MONTH $USER $IP $trans $LAST_ACT $FORWARDED $TIME_USED $IDLE $form $ref $sth $get_already); use lib::MimerDesk; use CGI::Carp "fatalsToBrowser"; sub print_template; sub getSessions; sub delete_session; sub gen_list; # Ohjelma ################################## my ($admin_status); read_config('../config/mimerdesk.cfg'); initialize(); $form = decode_multipart(); $form->{'ID'} =~ tr/0-9//cd; $form->{'auth'} =~ tr/0-9a-z//cd; ($USER, $IP, $LAST_ACT, $FORWARDED, $TIME_USED, $IDLE, $ACTIVEGRP) = authenticate($form->{'ID'}, $form->{'auth'}, $form->{'changeGroup'}); $trans = lib::MimerDesk->new_gettext(program => 'sessions',language => $config{'language'}); $APPLICATION = $trans->gettext("Tools - Sessions"); lock_tables('READ', 'users'); db_list("SELECT * FROM users where nimi = '$USER'"); while (my $ref = $sth->fetchrow_hashref()) {$admin_status = $ref->{'flags'};} db_end(); unlock_tables(); print_template("$config{'theme'}_accfailure") if $admin_status !~ /S0/; if ($form->{'quit'} || $form->{'log_out'}) {redirect("$config{'loc_server'}$config{'bin_dir'}/index.html?ID=$form->{'ID'}&auth=$form->{'auth'}&quit=quit");} elsif ($form->{'kill'}) { my ($session) = getSessions(); my @session = @$session; $get_already = 'yes'; foreach (@session) { if ($form->{$_} eq $_) { delete_session($form->{$_}); write_log("Session $form->{$_} was killed by $USER", 'notify'); } } redirect("$config{'loc_server'}$config{'bin_dir'}/sessions.html?ID=$form->{'ID'}\&auth=$form->{'auth'}\&go=session_manager"); } else {print_template('sessions');} exit; # Aliohjelmat ################################## ############################### # Lue template ja tulosta se # ############################### sub print_template { my ($template,$ref,$fulltemplate); $template = shift; print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; $ref = get_template('js_doClock', 'js_help', 'js_gotosite'); my $stuff = join "", ($ref->{'js_doClock'},$ref->{'js_help'},$ref->{'js_gotosite'}); $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate = create_buttons($fulltemplate, 'Tools', 'Sessions', $form); $fulltemplate =~ s/<>/minea/gm; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; $fulltemplate = gen_list($fulltemplate); $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); print $fulltemplate; db_end('disconnect'); exit; } ######################### # Generate article list # ######################### sub gen_list { my $fulltemplate = shift; my ($session, $userNames, $timeUseds, $LastPage, $loginDates, $ipADDRs, $idleTimes, $hostNames) = getSessions() if $get_already ne 'yes'; my @session = @$session; my @userNames = @$userNames; my @timeUseds = @$timeUseds; my @LastPage = @$LastPage; my @loginDates = @$loginDates; my @ipADDRs = @$ipADDRs; my @idleTimes = @$idleTimes; my @hostNames = @$hostNames; my ($num1, $status, $html, $html1, @html, @list, $num); foreach (@userNames) { $status = ''; $num = $num + 1; $html = ''; foreach ("start", "center,$num,no", "left,$_,user", "left,$ipADDRs[$num1],yes", "left,$hostNames[$num1],yes", "left,$LastPage[$num1],yes", "left,$loginDates[$num1],yes", "left,$timeUseds[$num1],yes", "left,$idleTimes[$num1],yes", "center,$session[$num1],$session[$num1],no,$status", "end") { @list = split /,/, $_; $html .= html_generator(@list); } push @html, $html; $num1 = $num1 + 1; } $html1 .= join "", @html; $fulltemplate =~ s/<>/$html1/m; return $fulltemplate; } ################## # HTML generator # ################## sub html_generator { my ($white_space); if ($_[0] eq 'start'){return "\n";} elsif ($_[3]){$white_space = "";} elsif ($_[0] eq 'end'){return "\n";} elsif ($_[2] eq 'yes'){$white_space = " $_[1]";} elsif ($_[2] eq 'user') {$white_space = " $_[1]";} else {$white_space = "$_[1]";} return "$white_space\n"; } #################### # Get session list # #################### sub getSessions { my ($id, $login_date, $last_page, $login_date2, $lastAct, $ipADDR, $userName, $http_forwarded, $auth, $hostName, $idleTime, $timeUsed, @session, @userNames, @timeUseds, @LastPage, @loginDates, @ipADDRs, @idleTimes, @hostNames); my $current_date = time(); lock_tables('READ', 'sessions'); db_list("SELECT * FROM sessions"); while (my $ref = $sth->fetchrow_hashref()) { $id = $ref->{'ID'}; $last_page = $ref->{'LAST_PAGE'}; $login_date2 = $ref->{'LOGIN_DATE2'}; $lastAct = $ref->{'LAST_ACT'}; $ipADDR = $ref->{'IP'}; $userName = $ref->{'USER'}; $http_forwarded = $ref->{'FORWARDED'}; $auth = $ref->{'AUTH'}; $hostName = gethostbyaddr(inet_aton($ipADDR), AF_INET); chomp($hostName); $timeUsed = $current_date - $login_date2; $idleTime = $current_date - $lastAct; $idleTime = $idleTime / 60; $idleTime = int ($idleTime + 0.5); $timeUsed = $timeUsed / 60; $timeUsed = int ($timeUsed + 0.5); $idleTime .= " min "; $timeUsed .= " min "; my ($sec,$min,$hour,$mday,$mon,$year) = utc_epoch2date($login_date2); $login_date = "$year/$mon/$mday $hour:$min:$sec"; push @session, $id; push @userNames, $userName; push @timeUseds, $timeUsed; push @LastPage, $last_page; push @loginDates, $login_date; if ($http_forwarded ne '') { $hostName .= " ("; $hostName .= gethostbyaddr(inet_aton($http_forwarded), AF_INET) || 'unknown'; $hostName .= ") "; $ipADDR .= " ("; $ipADDR .= $http_forwarded; $ipADDR .= ") "; } push @ipADDRs, $ipADDR; push @idleTimes, $idleTime; push @hostNames, $hostName; } db_end(); unlock_tables(); return (\@session, \@userNames, \@timeUseds, \@LastPage, \@loginDates, \@ipADDRs, \@idleTimes, \@hostNames); }