/usr/bin/tcpquotatop is in tcpquota 1.6.15-13.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | #!/usr/bin/perl -w
#
#
#
#
# Tcpquotatop.. Visar vilka som blir debiterade tcpquota just nu, interaktivt.
#
# $Header: /us/usr/lib/tcpquota/cvs/root/tcpquota/tcpquotatop,v 1.16 1998/08/01 19:57:58 turbo Exp $
#
# $Log: tcpquotatop,v $
# Revision 1.16 1998/08/01 19:57:58 turbo
# * First quick port to use the generic database interface 'DBI' instead of
# the 'Msql' interface. This is so that we can go from using mSQL as
# database, to use the much quicker mySQL server. But by using this generic
# interface, we can have both... More or less :)
# # Any reference to the Msql function 'query' had to be replaced with, first
# a 'prepare' then a 'execute'. If the execute fails, then die, or log, or
# what evere takes us fancy...
# * Any reference to the Msql functions 'fetchrow' and 'numrows', had to be
# replaced with 'fetchrow_array' and 'rows'.
# * Found a 'open_sql_server()' function in the 'tcp_masq_openfw' script. Move
# that to the library, so that we can reuse the function all over the board.
# # Added a lot of '&' to the call of our own functions... They glow with such
# a pretty blue color in X... :)
#
# Revision 1.15 1998/03/31 12:16:09 turbo
# Make sure we search and opens the correct config file,
# set by the variables '{lib|conf}_dir' at the top...
#
# Revision 1.14 1998/03/14 23:02:59 turbo
# If we can't open a connection to the mSQL database, say so and include the
# information to _WHICH_ server we can not connect to...
#
# Revision 1.13 1997/11/26 21:29:57 turbo
# Removed a lot of config file variables, that could possibly confuse a new
# user/admin of the package... We asume that whoever chooses to install the
# package, use our default... If not, they can go in and change the stuff
# themselvs!!
#
# Revision 1.12 1997/11/04 14:53:33 turbo
# We should require '/usr/lib/tcpquota/tcpquota.pl' instead of 'lib/tcpquota.pl'...
#
# Revision 1.11 1997/10/02 11:57:19 turbo
# Found a bugg conserning a money variable...
#
# Revision 1.10 1997/08/17 17:29:14 turbo
# * We should require '/usr/lib/tcpquota/tcpquota.pl' instead of 'lib/tcpquota.pl'...
# * Moved some functions to the library file.
# * Deleted some variables, they exists in the config file.
# * Added the global config variables 'LANGUAGE' and 'MONEY_VALUE' in the
# config file...
# * Changed some hardcoded site specific entries, and language. We can´t
# release it if much of it is specific to CCW...
# * Made sure that all the script's understand '--help', '-h' and '?', just
# in case...
# * Some of the config file variables can be used by all the scripts, therefor
# made non-program specific ('TABLE=xxx', instead of 'tcpquotad.TABLE=xxx').
# * Fixed some calculation buggs in the admin program, and also more information
# in the menu.
#
# Revision 1.9 1997/04/13 03:54:30 marbud
# forsok till hel-krona-pling, men det funkar inte an.. hmmm
#
# Revision 1.8 1997/04/13 03:22:42 marbud
# Oppss. = bugg vid gamforelse..
#
# Revision 1.7 1997/04/13 03:21:34 marbud
# ny verre som klarar haller reda pa hur manga kronor som det har gatt at
# totalt sedan vi startade..
#
# Revision 1.6 1997/04/13 00:40:43 marbud
# Snyggar utskrift. Fick ordning på lyttals utskrifterna oxo, så de hamna
# under rubrikerna som de bör.
#
# Revision 1.5 1997/04/12 20:33:37 marbud
# Nu funkar SEK visarna, både total och diffar.
#
# Revision 1.4 1997/04/12 20:27:34 marbud
# Total summor, samt diff SEK uträknad.. Hmm funkar inte riktigt än, men
# det kommer nog snart..
#
# Revision 1.3 1997/04/12 19:49:25 marbud
# Tillsnyggad, och visar nu vilken period som avses..
#
# Revision 1.2 1997/04/12 19:24:01 marbud
# Första versionen som går att använda.. Verkar funka ganska bra..
#
# Revision 1.1 1997/04/12 18:55:49 marbud
# Lagt till tcpquotatop i Makefile
#
# tcpquota top är en ny produkt som visar vilka som debiteras och hur mycket.
#
#
#
use DBI;
use POSIX;
use English;
package main;
$lib_dir = "/usr/lib/tcpquota";
$conf_dir = "/etc/tcpquota";
require "$lib_dir/tcpquota.pl";
$VERSION='$Revision: 1.16 $ ';
$DEBUG=0;
$PROG="tcpquotatop";
$CF_FILE="tcpquota.cf";
$CF_FILE="tcpquota.debug.cf" if (defined $ENV{DEBUG} or $DEBUG);
%cf=(); # config array.
&readconfig("$conf_dir/$CF_FILE",$PROG);
$dbh=""; # holds our connections to msql..
$sth=""; # holds general query handle...
sub init() {
$OUTPUT_AUTOFLUSH=1;
print "Tcpquotatop $VERSION\n";
print "Connecting to database.\n";
# Open up the database connection...
&open_sql_server();
}
sub fetch_quota_snapshot() {
local($name,$quota);
local($sth);
local(%tmp)=();
$sth= $dbh->prepare("select name, quota from tcptab");
$sth->execute || die "Can't talk to the database server.\n";
while ( ($name,$quota)= $sth->fetchrow_array ) {
$tmp{$name}=$quota;
}
return %tmp;
}
sub main() {
local(%all_user,%act_user);
local($sth,%new);
local($starttime);
local(@tmp,$diff,$sleeptime);
local($totalMONdiff, $totalMONdiffint)=(0,0);
$sleeptime=10;
print "Fetching start quotas\n";
# fill upp our arrays.
%act_user=();
%all_user=&fetch_quota_snapshot();
@starttime=localtime;
print "Waiting for the next period.\n";
sleep $sleeptime;
$OUTPUT_AUTOFLUSH=0;
while (1) {
%new=&fetch_quota_snapshot();
foreach (keys(%new)) {
if ($new{$_} != $all_user{$_}) {
$act_user{$_}=$all_user{$_};
}
}
system('/usr/bin/clear');
print " tcpquotatop $VERSION\n";
printf " Start:%s Now:%s\n\n",
strftime("%Y-%m-%d %H:%M.%S", @starttime),
strftime("%Y-%m-%d %H:%M.%S", localtime);
printf "%-15s %7s %7s %9s %9s\n",
"Username", "quota", "diff", "$cf{'MONEY_VALUE'}", "$cf{'MONEY_VALUE'} diff";
print "----------------------------------------------------------------------\n";
foreach (sort {$act_user{$a} <=> $act_user{$b} } keys(%act_user)) {
$diff=$new{$_} - $all_user{$_};
printf "%-15s %7d %7d %9.3f %9.3f\n", $_, $new{$_},
$diff, - $new{$_} / 60 * $cf{'RATE_QUOTA'},
$diff / 60 * $cf{'RATE_QUOTA'};
}
# use new values next time.
print "----------------------------------------------------------------------\n";
{
local($t_quota,$t_diff,$t_MON,$t_MONdiff)=(0,0,0,0);
# calc sums
foreach (keys(%act_user)) {
$t_quota +=$act_user{$_};
$t_diff +=$new{$_} - $all_user{$_};
$t_MON += - $new{$_} / 60 * $cf{'RATE_QUOTA'};
$t_MONdiff += ($new{$_} - $all_user{$_}) / 60 * $cf{'RATE_QUOTA'};
}
printf "%-15s %7d %7d %9.3f %9.3f\n", "Total:", $t_quota,
$t_diff, $t_MON, $t_MONdiff;
$totalMONdiff+=$t_MONdiff;
}
@tmp=keys(%act_user);
$OUTPUT_AUTOFLUSH=1;
# let's sound the bell for every even crown (or whatever).
if ( $totalMONdiffint != int($totalMONdiff)) {
print "";
$totalMONdiffint=int($totalMONdiff);
}
printf " Total %d active users used %9.3f $cf{'MONEY_VALUE'} since starttime.",
$#tmp + 1, $totalMONdiff;
$OUTPUT_AUTOFLUSH=0;
%all_user=%new;
# don't rush it..
sleep $sleeptime;
}
}
&init();
&main();
|