dynacc/ 0040755 0000000 0000000 00000000000 07433753521 011032 5 ustar root root dynacc/info.txt 0100644 0000000 0000000 00000002267 07433753521 012532 0 ustar root root This is a simple perl script to use with mrtg to monitor any set of ip-s even if there isnt't an interface for them, you can also use it to keep an accounting database for the same sets of ips.
It is pretty much self explanatory, is has a configuration file named dynacc.conf that has to reside in /etc/ but you can both renameit and change it's location, and ... it's writen by me...
I've included here an example config from mrtg.cfg...
Target[terra]: `/usr/local/bin/dynacc -m terra`
MaxBytes[terra]: 4125
XSize[terra]: 600
Title[terra]: terra -- braille.fcc.ro
PageTop[terra]:
LL to Top Terra Trade
| System: | braille.fcc.ro in Focsani, Romania |
| Maintainer: | Razvan Radu <rot@fcc.ro> |
| Description: | Terra |
| ifType: | ppp |
| Max Speed: | 4125.0 Bytes/s |
| Ip: | 194.102.241.42 |
################################################################################
#
# Razvan Radu
# Focsani, Romania
# rot@fcc.ro
################################################################################
dynacc/dynacc 0100744 0000000 0000000 00000005120 07433753175 012217 0 ustar root root #!/usr/bin/perl
use Mysql;
$CONF='/etc/dynacc.conf';
$FILTER='/sbin/iptables';
$DB_HOST='localhost';
#$DB_HOST='braille.fcc.ro';
$DB_USER='root';
$DB_PASS='';
$DATABASE='acct';
sub set
{
# Check if the chain exists and all traffic goes through it
$vezi=`$FILTER -L|grep "Chain ac"`;
if ($vezi eq '') {$execline="$FILTER -N ac; $FILTER -I FORWARD 2 -j ac"; }
elsif (index($vezi,'1') == "-1") {$execline="$FILTER -I FORWARD 2 -j ac"; }
else {$execline=''; }
$execline ne '' && system("$execline");
system("$FILTER -F ac");
open(conf,$CONF) || die "Cannot open $CONF";
while($line=)
{
chop($line);
if ($line =~ /^#/ || $line =~ /^\s*$/) { next; };
@rule{name,prot,src,sport,dst,dport} = split(/\|/,$line,6);
$execline="$FILTER -A ac";
if ($rule{prot} ne '') {$execline.=" -p $rule{prot}"; };
if ($rule{src} ne '') {$execline.=" -s $rule{src}"; };
if ($rule{sport} ne '') {$execline.=" --sport $rule{sport}"; };
if ($rule{dst} ne '') {$execline.=" -d $rule{dst}"; };
if ($rule{dport} ne '') {$execline.=" --dport $rule{dport}"; };
$execline.=" -j ACCEPT";
print $rule{name},"\n";
system("$execline");
}
close(conf);
}
sub zii
{
($prot,$src,$dst,$sport,$dport) = @_;
if ($prot eq '') { $prot='all';}
if ($src eq '0/0') { $src='0.0.0.0/0';}
if ($dst eq '0/0') { $dst='0.0.0.0/0';}
open(all,"$FILTER -nL ac -vx|"); @altceva=; close(all);
for($i=2; $i<@altceva; $i++)
{
@ceva=(split(/ +/,$altceva[$i]))[2,4,8,9,11,12];
if($ceva[4] =~ /^dpt/) {$ceva[5]=$ceva[4]; $ceva[4]='';}
if($prot eq $ceva[1] && $src eq $ceva[2] && $dst eq $ceva[3] && index($ceva[4],$sport) != -1 && index($ceva[5],$dport) != -1) { return $ceva[0];}
}
}
sub get
{
open(conf,$CONF) || die "Cannot open $CONF";
while($line=)
{
chop($line);
if ($line =~ /^#/ || $line =~ /^\s*$/) { next; };
@rule{name,prot,src,sport,dst,dport} = split(/\|/,$line,6);
if (index($rule{name},$_[0]) ne '-1')
{ return &zii("$rule{prot}","$rule{src}","$rule{dst}","$rule{sport}","$rule{dport}");
}
}
close(conf);
}
sub mrtg
{
$ce=$_[0];
$in=&get("$ce in");
$out=&get("$ce out");
$uptime=`uptime |cut -b 14-27`;
$hostname=`hostname`;
print "$in\n$out\n$uptime$hostname";
}
sub mysql
{
$dbh=Mysql->connect($DB_HOST,$DATABASE,$DB_USER,$DB_PASS);
$ce=$_[0];
$in=&get("$ce in");
$out=&get("$ce out");
$qry="insert into $ce (inBytes, outBytes, time_stamp) values ($in, $out, now())";
$dbq=$dbh->query($qry);
}
(@ARGV >= 1) || die "Usage: razacc {-s | -m rulename | -u rulename}";
while($opt=shift(@ARGV))
{
if ($opt eq "-s") {&set;}
if ($opt eq "-m") { $x=shift @ARGV; &mrtg($x); }
if ($opt eq "-u") { $x=shift @ARGV; &mysql($x);}
}
# Razvan Radu
dynacc/dynacc.conf 0100644 0000000 0000000 00000002061 07433753337 013143 0 ustar root root # /etc/dynacc.conf
# config file for dynacc...
#
# Format:
# name_of_rule|prot|src|src_port|dst|dst_port
# the options's format is tha same as in iptables..
#
# where:
# name_of_rule any string to indentify this rule
# prot protocol
# src source in ipchains/iptables format
# src_port source port
# dst destination in ipchains/iptables format
# dst_port obious...
#
#geneza in||0/0||194.102.241.128/25
#geneza out||194.102.241.128/25||0/0
euroclub in||0/0||194.102.241.64/28
euroclub out||194.102.241.64/28||0/0
gagoi in||0/0||194.102.241.32/29
gagoi out||194.102.241.32/29||0/0
terra in||0/0||194.102.241.42
terra out||194.102.241.42||0/0
codrut in||0/0||194.102.241.41
codrut out||194.102.241.41||0/0
comtel in||0/0||194.102.241.48/29
comtel out||194.102.241.48/29||0/0
cyro in||0/0||194.102.241.96/28
cyro out||194.102.241.96/28||0/0
tudorprest in||0/0||194.102.241.112/28
tudorprest out||194.102.241.112/28||0/0
dialup in||0/0||194.102.241.16/28
dialup out||194.102.241.16/28||0/0
mara in||0/0||194.102.241.80/28
mara out||194.102.241.80/28||0/0