Viewing file:
log.cgi (9.5 KB) -rwxr-xr-xSelect action/file-type:

(
+) |

(
+) |

(
+) |
Code (
+) |
Session (
+) |

(
+) |
SDB (
+) |

(
+) |

(
+) |

(
+) |

(
+) |

(
+) |
#!/usr/bin/perl
require "config.cgi";
$username = param("user");
$show = param("show");
$page = param("page");
$all = param("all");
$showmac = param("mac");
$menu = "active";
require "top.cgi";
#if ($all eq "1") {$all = ""; $epp="300";}
#if ($all ne "1") {$lim = "LIMIT $st,$epp";}
print "<center><font face=\"$fface\">";
if ($show ne "active" and $showmac eq "") {
print "<table border=0 bgcolor=$table cellspacing=2 cellpadding=2 width=$conwidth><tr><td bgcolor=$cellheadbg><font color=$menucolor><center>Информация о соединениях пользователя <b>$username</b></font></td></table>";}
elsif ($showmac ne "") {
print "<table border=0 bgcolor=$table cellspacing=2 cellpadding=2 width=$conwidth><tr><td bgcolor=$cellheadbg><font color=$menucolor><center>Информация о соединениях с устройства <b>$showmac</b></font></td></table>";}
print "<table border=0 bgcolor=$table cellspacing=2 cellpadding=2 width=$conwidth><tr>";
if ($show eq "active" or $showmac ne "") {
print "<td bgcolor=$cellheadbg><font color=$headfont>Пользователь</font></td>";}
print "<td bgcolor=$cellheadbg><font color=$headfont>NAS</font></td>
<td bgcolor=$cellheadbg><font color=$headfont>Старт</font></td>";
if ($show ne "active") {print "<td bgcolor=$cellheadbg><font color=$headfont>Стоп</font></td>";}
print "<td bgcolor=$cellheadbg><font color=$headfont>Длительность</font></td>
<td bgcolor=$cellheadbg><font color=$headfont><center>RX (МБ)</center></font></td>
<td bgcolor=$cellheadbg><font color=$headfont><center>TX (МБ)</center></font></td>";
if ($show eq "active") {print "<td bgcolor=$cellheadbg><font color=$headfont>IP адрес</font></td>";}
print "<td bgcolor=$cellheadbg><font color=$headfont>MAC адрес</font></td>
<td bgcolor=$cellheadbg><font color=$headfont>Производитель</font></td>";
if ($show ne "active") {print "<td bgcolor=$cellheadbg><font color=$headfont>Завершено</font></td>";}
print "</tr>";
if ($show ne "active" and $showmac eq "") {
$sth = $dbh->prepare("SELECT COUNT(*) FROM radacct WHERE username='$username'");
$sth->execute();
my ($cnt) = $sth->fetchrow_array();
$pg = int($cnt / $epp);
$pg1 = $cnt / $epp;
if ($pg1 ne $pg) {$pg++;}
if ($page eq "") {$page = $pg;}
$pcn = $pg;
if ($pcn > $pagsel) { $pcn = ($pagsel - 2) }
if ($page eq 1)
{$pstr = "<a href=\"log.cgi?page=1&user=$username\"><b><font color=$headfont>[ 1 ]</font></b></a>";}
else {$pstr = "<a href=\"log.cgi?page=1&user=$username\">[ 1 ]</a>";}
if ($page > (int($pagsel / 2) + 1)) {$pstr = sprintf("%s <font color=$actcolor> ... </font>", $pstr); }
$pc1 = 0;
if ($page < (int($pagsel / 2) + 1)) { $np = 2; } else { $np = $page - int($pagsel / 2) + 1; }
if (($page + (int($pagsel / 2))) > $pg) { $np = $pg - ($pagsel - 2); }
if ($np < 2) { $np = 2; $pcn = $pg - 2;}
if ($pg > 2) {
while ($pc1 ne $pcn)
{
if ($np eq $page)
{$pstr = sprintf ("%s <a href=\"log.cgi?page=%s&user=$username\"><b><font color=$headfont>[ %s ]</font></b></a>", $pstr, $np, $np);}
else {$pstr = sprintf ("%s <a href=\"log.cgi?page=%s&user=$username\">[ %s ]</a>", $pstr, $np, $np);}
$pc1++;
$np++;
}
}
if ($pg > 1) {
if ($page + (int($pagsel / 2)) < $pg) {$pstr = sprintf("%s <font color=$actcolor> ... </font>", $pstr); }
if ($page eq $pg) {$pstr = sprintf ("%s <a href=\"log.cgi?page=%s&user=$username\"><b><font color=$headfont>[ %s ]</font></b></a>", $pstr, $pg, $pg);}
else {$pstr = sprintf ("%s <a href=\"log.cgi?page=%s&user=$username\">[ %s ]</a>", $pstr, $pg, $pg);}
}
$st = (($page - 1) * $epp) + 1;
$lim = "LIMIT $st,$epp"; $showall = $pstr;
$sth = $dbh->prepare("SELECT username,nasipaddress,acctstarttime,acctstoptime,acctsessiontime,connectinfo_stop,acctinputoctets,acctoutputoctets,callingstationid,acctterminatecause FROM radacct WHERE username='$username' $lim");
$sth->execute() }
elsif ($showmac ne "") {
$sth = $dbh->prepare("SELECT COUNT(*) FROM radacct WHERE callingstationid='$showmac'");
$sth->execute();
my ($cnt) = $sth->fetchrow_array();
$pg = int($cnt / $epp);
$pg1 = $cnt / $epp;
if ($pg1 ne $pg) {$pg++;}
if ($page eq "") {$page = $pg;}
$pcn = $pg;
if ($pcn > $pagsel) { $pcn = ($pagsel - 2) }
if ($page eq 1)
{$pstr = "<a href=\"log.cgi?page=1&mac=$showmac\"><b><font color=$headfont>[ 1 ]</font></b></a>";}
else {$pstr = "<a href=\"log.cgi?page=1&mac=$showmac\">[ 1 ]</a>";}
if ($page > (($pagsel / 2) + 1)) {$pstr = sprintf("%s <font color=$actcolor> ... </font>", $pstr); }
$pc1 = 0;
if ($page < (int($pagsel / 2) + 1)) { $np = 2; } else { $np = $page - int($pagsel / 2) + 1; }
if (($page + int($pagsel / 2)) > $pg) { $np = $pg - ($pagsel - 2); }
if ($np < 2) { $np = 2; $pcn = $pg - 2;}
if ($pg > 2) {
while ($pc1 ne $pcn)
{
if ($np eq $page)
{$pstr = sprintf ("%s <a href=\"log.cgi?page=%s&mac=$showmac\"><b><font color=$headfont>[ %s ]</font></b></a>", $pstr, $np, $np);}
else {$pstr = sprintf ("%s <a href=\"log.cgi?page=%s&mac=$showmac\">[ %s ]</a>", $pstr, $np, $np);}
$pc1++;
$np++;
}
}
if ($pg > 1) {
if ($page + int($pagsel / 2) < $pg) {$pstr = sprintf("%s <font color=$actcolor> ... </font>", $pstr); }
if ($page eq $pg) {$pstr = sprintf ("%s <a href=\"log.cgi?page=%s&mac=$showmac\"><b><font color=$headfont>[ %s ]</font></b></a>", $pstr, $pg, $pg);}
else {$pstr = sprintf ("%s <a href=\"log.cgi?page=%s&mac=$showmac\">[ %s ]</a>", $pstr, $pg, $pg);}
}
$st = (($page - 1) * $epp) + 1;
$lim = "LIMIT $st,$epp"; $showall = $pstr;
$sth = $dbh->prepare("SELECT username,nasipaddress,acctstarttime,acctstoptime,acctsessiontime,connectinfo_stop,acctinputoctets,acctoutputoctets,callingstationid,acctterminatecause FROM radacct WHERE callingstationid='$showmac' $lim");
$sth->execute();}
else {
$sth = $dbh->prepare("SELECT COUNT(*) FROM radacct WHERE connectinfo_stop='' AND acctterminatecause=''");
$sth->execute();
my ($cnt) = $sth->fetchrow_array();
$sth = $dbh->prepare("SELECT username,nasipaddress,acctstarttime,acctstoptime,acctsessiontime,connectinfo_stop,acctinputoctets,acctoutputoctets,callingstationid,acctterminatecause FROM radacct WHERE connectinfo_stop='' AND acctterminatecause=''");
$sth->execute();
}
while (my ($username, $nas, $start, $stop, $time, $connected, $tx, $rx, $mac, $reason) = $sth->fetchrow_array())
{
$nasname = "";
$sth1 = $dbh->prepare("SELECT name FROM nasnames WHERE address='$nas'");
$sth1->execute();
my ($nasname) = $sth1->fetchrow_array();
if ($nasname eq "") {$nasname = $nas; }
if ($reason eq "" and $connected ne "") {$reason = "Signal-lost";}
$day = int($time / 86400);
$hour = int($time / 3600) - ($day * 24);
$min = int($time / 60) - ($day * 24) - ($hour * 60) - ($day * 1416);
$sec = $time - (int($time / 60) * 60);
$time = sprintf ("%s.%02d:%02d:%02d", $day, $hour, $min, $sec);
$tx = int($tx/1024/1024);
$rx = int($rx/1024/1024);
# print "<tr>";
($m1, $m2, $m3) = split ("-", $mac);
$oui = sprintf("%s-%s-%s", $m1, $m2, $m3);
$sth1 = $dbh->prepare("SELECT vendor FROM oui WHERE mac='$oui'");
$sth1->execute();
my ($ven) = $sth1->fetchrow_array();
$macv = "<acronym title=\"$ven\">$mac</acronym>";
$arp = lc($mac);
$arp =~ s/-/:/g;
open(ARP1, "/proc/net/arp") || die "can't open arp file";
$ipaddr = "";
while (<ARP1>) {
chomp;
if (/^[0-9]/) {
($ipa, $hwtype, $flags, $ether, $mask, $device) = split(/ +/);
if ($ether eq $arp) {$ipaddr = $ipa;}
}
}
close (ARP1);
if ($show eq "active" or $showmac ne "" ) {print "<tr><td bgcolor=$cellcolor><font color=$fontcolor size=\"2\"><a href=\"log.cgi?user=$username\">$username</a></font></td>";}
# $arp = lc($macv);
# $arp =~ s/-/:/g;
# $cmd = "/usr/sbin/arp -n |/bin/grep $arp";
# my $out=qx($cmd 2>&1);
# ($ipaddr) = split(" ", $out);
# print "$out";
print "<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\">$nasname</font></td>
<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\">$start</font></td>";
if ($show ne "active") {print "<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\">$stop</font></td>";}
print "<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\">$time</font></td>
<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\"><center>$rx</font></td>
<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\"><center>$tx</font></td>";
if ($show eq "active") {print "<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\">$ipaddr</font></td>";}
print "<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\"><a href=\"log.cgi?mac=$mac\">$macv</a></font></td>
<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\">$ven</font></td>";
if ($show ne "active") {print "<td bgcolor=$cellcolor><font color=$fontcolor size=\"2\">$reason</font></td>";}
print "</tr>";
}
print "</table><table border=0 width=$conwidth cellspacing=0 cellpadding=2 bgcolor=$cellheadbg><tr><td bgcolor=$cellheadbg><center>$showall</td></tr></table>";