forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_sessions.cgi
executable file
·86 lines (79 loc) · 2.34 KB
/
list_sessions.cgi
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
#!/usr/local/bin/perl
# list_sessions.cgi
# Display current login sessions
use strict;
use warnings;
require './acl-lib.pl';
our (%in, %text, %config, %access, %sessiondb);
$access{'sessions'} || &error($text{'sessions_ecannot'});
&ui_print_header(undef, $text{'sessions_title'}, "");
&ReadParse();
my %miniserv;
&get_miniserv_config(\%miniserv);
&open_session_db(\%miniserv);
my $time_now = time();
my %hasuser;
foreach my $u (&list_users()) {
$hasuser{$u->{'name'}}++;
}
my $haslog = &foreign_available("webminlog");
print &ui_columns_start([ $text{'sessions_id'},
$text{'sessions_state'},
$text{'sessions_user'},
$text{'sessions_host'},
$text{'sessions_login'},
$text{'sessions_actions'},
], 100);
foreach my $k (sort { my @a = split(/\s+/, $sessiondb{$a});
my @b = split(/\s+/, $sessiondb{$b}); $b[1] <=> $a[1] }
(grep { $sessiondb{$_} } keys %sessiondb)) {
next if ($k =~ /^1111111/);
my ($user, $ltime, $lip) = split(/\s+/, $sessiondb{$k});
next if ($user =~ /^\!/ && !$in{'logouts'});
next if ($miniserv{'logouttime'} &&
$time_now - $ltime > $miniserv{'logouttime'}*60);
my @cols;
my $candel = 0;
if ($k eq $main::session_id ||
$k eq &hash_session_id($main::session_id)) {
# Cannot self-terminate
push(@cols, "<b><tt>$k</tt></b>");
push(@cols, $text{'sessions_this'});
}
elsif ($user =~ s/^\!//) {
# Already logged out
push(@cols, "<tt>$k</tt>");
push(@cols, $text{'sessions_out'});
}
else {
push(@cols, "<tt>$k</tt>");
push(@cols, $text{'sessions_in'});
$candel = 1;
}
if ($hasuser{$user}) {
push(@cols, ui_link("edit_user.cgi?user=$user", $user));
}
elsif ($miniserv{'unixauth'}) {
push(@cols, "$user (" . ui_link("edit_user.cgi?user=$miniserv{'unixauth'}", $miniserv{'unixauth'}) . ")");
}
else {
push(@cols, $user);
}
push(@cols, $lip);
push(@cols, &make_date($ltime));
my @links;
if ($haslog) {
push(@links, ui_link("../webminlog/search.cgi?uall=1&mall=1&tall=1&wall=1&fall=1&sid=$k", $text{'sessions_lview'}));
}
if ($candel) {
push(@links, ui_link("delete_session.cgi?id=$k", $text{'sessions_kill'}));
}
push(@cols, ui_links_row(\@links));
print &ui_columns_row(\@cols);
}
print &ui_columns_end();
if (!$in{'logouts'}) {
print &ui_link("list_sessions.cgi?logouts=1",
$text{'sessions_logouts'}),"<p>\n";
}
&ui_print_footer("", $text{'index_return'});