Подсчёт статистики PPP-пользователей
в скрипт /etc/ppp/ip-up добавить
ipt=/sbin/iptables
ip=$5
###in traf
$ipt -D FORWARD -m comment --comment "in" -d $ip -j ACCEPT
$ipt -A FORWARD -m comment --comment "in" -d $ip -j ACCEPT
###out traf
$ipt -D FORWARD -m comment --comment "out" -s $ip -j ACCEPT
$ipt -A FORWARD -m comment --comment "out" -s $ip -j ACCEPT
в скрипт /etc/ppp/ip-down добавить
ipt=/sbin/iptables
ip=$5
input=`$ipt -nL -v -x|grep $ip|grep in|awk '{print $2}'`
output=`$ipt -nL -v -x|grep $ip|grep out|awk '{print $2}'`
###in traf
$ipt -D FORWARD -m comment --comment "in" -d $ip -j ACCEPT
###out traf
$ipt -D FORWARD -m comment --comment "out" -s $ip -j ACCEPT
if [ -e /tmp/traf/${ip}_in ] && [ -e /tmp/traf/${ip}_out ]
then
in_old=`cat /tmp/traf/${ip}_in`
out_old=`cat /tmp/traf/${ip}_out`
else
in_old=0
out_old=0
fi
input=$(( ${input} + ${in_old} ))
output=$(( ${output} + ${out_old} ))
echo $input > /tmp/traf/${ip}_in
echo $output > /tmp/traf/${ip}_out
запись статистики в файл:
#!/bin/bash
in_old=`cat /tmp/traf/192.168.0.201_in`
out_old=`cat /tmp/traf/192.168.0.201_out`
let in=$in_old/1024/1024
let out=$out_old/1024/1024
echo " 1. User1 " > /var/www/reports/$(date +%Y%m)
echo $in >> /var/www/reports/$(date +%Y%m)
echo $out >> /var/www/reports/$(date +%Y%m)
вывод статистики на веб-страницу (php-скрипт)
<?
$file_array = file( date("Ym") );
?>
<html>
<head>
</head>
<body>
<table border="1">
<tr>
<td> Username </td><td> Download </td><td> Upload</td>
</tr>
<tr>
<td>
<? print $file_array[0]; ?>
</td>
<td>
<? print $file_array[1]; ?>
</td>
<td>
<? print $file_array[2]; ?>
</tr>
</table>
Webmoney кошелёк для благодарностей:
Z522680129175