#!/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 "
"; if ($show ne "active" and $showmac eq "") { print "
Информация о соединениях пользователя $username
";} elsif ($showmac ne "") { print "
Информация о соединениях с устройства $showmac
";} print ""; if ($show eq "active" or $showmac ne "") { print "";} print ""; if ($show ne "active") {print "";} print ""; if ($show eq "active") {print "";} print ""; if ($show ne "active") {print "";} print ""; 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 = "[ 1 ]";} else {$pstr = "[ 1 ]";} if ($page > (int($pagsel / 2) + 1)) {$pstr = sprintf("%s ... ", $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 [ %s ]", $pstr, $np, $np);} else {$pstr = sprintf ("%s [ %s ]", $pstr, $np, $np);} $pc1++; $np++; } } if ($pg > 1) { if ($page + (int($pagsel / 2)) < $pg) {$pstr = sprintf("%s ... ", $pstr); } if ($page eq $pg) {$pstr = sprintf ("%s [ %s ]", $pstr, $pg, $pg);} else {$pstr = sprintf ("%s [ %s ]", $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 = "[ 1 ]";} else {$pstr = "[ 1 ]";} if ($page > (($pagsel / 2) + 1)) {$pstr = sprintf("%s ... ", $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 [ %s ]", $pstr, $np, $np);} else {$pstr = sprintf ("%s [ %s ]", $pstr, $np, $np);} $pc1++; $np++; } } if ($pg > 1) { if ($page + int($pagsel / 2) < $pg) {$pstr = sprintf("%s ... ", $pstr); } if ($page eq $pg) {$pstr = sprintf ("%s [ %s ]", $pstr, $pg, $pg);} else {$pstr = sprintf ("%s [ %s ]", $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 ""; ($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 = "$mac"; $arp = lc($mac); $arp =~ s/-/:/g; open(ARP1, "/proc/net/arp") || die "can't open arp file"; $ipaddr = ""; while () { 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 "";} # $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 ""; if ($show ne "active") {print "";} print ""; if ($show eq "active") {print "";} print ""; if ($show ne "active") {print "";} print ""; } print "
ПользовательNAS СтартСтопДлительность
RX (МБ)
TX (МБ)
IP адресMAC адрес ПроизводительЗавершено
$username$nasname $start$stop$time
$rx
$tx
$ipaddr$macv $ven$reason
$showall
";