Per user mac based bandwidth monitor for routers


Want to calculate how much bandwidth each user (mac address) is using


    ./wrtbwmon setup
   ./wrtbwmon update /tmp/usage.db offpeak
   ./wrtbwmon publish /tmp/usage.db /www/user/usage.htm /jffs/users.txt

Here is open source solution ClickHere

Below is the script  (wrtbwmon )
---------------------------

LAN_IFACE=$(nvram get lan_ifname)

lock()
{
while [ -f /tmp/wrtbwmon.lock ]; do
if [ ! -d /proc/$(cat /tmp/wrtbwmon.lock) ]; then
echo "WARNING : Lockfile detected but process $(cat /tmp/wrtbwmon.lock) does not exist !"
rm -f /tmp/wrtbwmon.lock
fi
sleep 1
done
echo $$ > /tmp/wrtbwmon.lock
}

unlock()
{
rm -f /tmp/wrtbwmon.lock
}

case ${1} in

"setup" )

#Create the RRDIPT CHAIN (it doesn't matter if it already exists).
iptables -N RRDIPT 2> /dev/null

#Add the RRDIPT CHAIN to the FORWARD chain (if non existing).
iptables -L FORWARD --line-numbers -n | grep "RRDIPT" | grep "1" > /dev/null
if [ $? -ne 0 ]; then
iptables -L FORWARD -n | grep "RRDIPT" > /dev/null
if [ $? -eq 0 ]; then
echo "DEBUG : iptables chain misplaced, recreating it..."
iptables -D FORWARD -j RRDIPT
fi
iptables -I FORWARD -j RRDIPT
fi

#For each host in the ARP table
grep ${LAN_IFACE} /proc/net/arp | while read IP TYPE FLAGS MAC MASK IFACE
do
#Add iptable rules (if non existing).
iptables -nL RRDIPT | grep "${IP} " > /dev/null
if [ $? -ne 0 ]; then
iptables -I RRDIPT -d ${IP} -j RETURN
iptables -I RRDIPT -s ${IP} -j RETURN
fi
done
;;
"update" )
[ -z "${2}" ] && echo "ERROR : Missing argument 2" && exit 1
# Uncomment this line if you want to abort if database not found
# [ -f "${2}" ] || exit 1

lock

#Read and reset counters
iptables -L RRDIPT -vnxZ -t filter > /tmp/traffic_$$.tmp

grep -v "0x0" /proc/net/arp  | while read IP TYPE FLAGS MAC MASK IFACE
do
#Add new data to the graph. Count in Kbs to deal with 16 bits signed values (up to 2G only)
#Have to use temporary files because of crappy busybox shell
grep ${IP} /tmp/traffic_$$.tmp | while read PKTS BYTES TARGET PROT OPT IFIN IFOUT SRC DST
do
[ "${DST}" = "${IP}" ] && echo $((${BYTES}/1000)) > /tmp/in_$$.tmp
[ "${SRC}" = "${IP}" ] && echo $((${BYTES}/1000)) > /tmp/out_$$.tmp
done
IN=$(cat /tmp/in_$$.tmp)
OUT=$(cat /tmp/out_$$.tmp)
rm -f /tmp/in_$$.tmp
rm -f /tmp/out_$$.tmp
if [ ${IN} -gt 0 -o ${OUT} -gt 0 ];  then
echo "DEBUG : New traffic for ${MAC} since last update : ${IN}k:${OUT}k"
LINE=$(grep ${MAC} ${2})
if [ -z "${LINE}" ]; then
echo "DEBUG : ${MAC} is a new host !"
PEAKUSAGE_IN=0
PEAKUSAGE_OUT=0
OFFPEAKUSAGE_IN=0
OFFPEAKUSAGE_OUT=0
else
PEAKUSAGE_IN=$(echo ${LINE} | cut -f2 -s -d, )
PEAKUSAGE_OUT=$(echo ${LINE} | cut -f3 -s -d, )
OFFPEAKUSAGE_IN=$(echo ${LINE} | cut -f4 -s -d, )
OFFPEAKUSAGE_OUT=$(echo ${LINE} | cut -f5 -s -d, )
fi
if [ "${3}" = "offpeak" ]; then
OFFPEAKUSAGE_IN=$((${OFFPEAKUSAGE_IN}+${IN}))
OFFPEAKUSAGE_OUT=$((${OFFPEAKUSAGE_OUT}+${OUT}))
else
PEAKUSAGE_IN=$((${PEAKUSAGE_IN}+${IN}))
PEAKUSAGE_OUT=$((${PEAKUSAGE_OUT}+${OUT}))
fi

grep -v "${MAC}" ${2} > /tmp/db_$$.tmp
mv /tmp/db_$$.tmp ${2}
echo ${MAC},${PEAKUSAGE_IN},${PEAKUSAGE_OUT},${OFFPEAKUSAGE_IN},${OFFPEAKUSAGE_OUT},$(date "+%d-%m-%Y %H:%M") >> ${2}
fi
done
#Free some memory
rm -f /tmp/*_$$.tmp
unlock
;;
"publish" )

[ -z "${2}" ] && echo "ERROR : Missing argument 2" && exit 1
[ -z "${3}" ] && echo "ERROR : Missing argument 3" && exit 1
USERSFILE="/etc/dnsmasq.conf"
[ -f "${USERSFILE}" ] || USERSFILE="/tmp/dnsmasq.conf"
[ -z "${4}" ] || USERSFILE=${4}
[ -f "${USERSFILE}" ] || USERSFILE="/dev/null"

# first do some number crunching - rewrite the database so that it is sorted
lock
touch /tmp/sorted_$$.tmp
cat ${2} | while IFS=, read MAC PEAKUSAGE_IN PEAKUSAGE_OUT OFFPEAKUSAGE_IN OFFPEAKUSAGE_OUT LASTSEEN
do
echo ${PEAKUSAGE_IN},${PEAKUSAGE_OUT},${OFFPEAKUSAGE_IN},${OFFPEAKUSAGE_OUT},${MAC},${LASTSEEN} >> /tmp/sorted_$$.tmp
done
unlock

        # create HTML page
        echo "Traffic

Total Usage :

" >> ${3}
        echo "" >> ${3}
        echo "
UserPeak downloadPeak uploadOffpeak downloadOffpeak uploadLast seen
" >> ${3}
        echo "
This page was generated on `date`" 2>&1 >> ${3}
        echo "" >> ${3}

        #Free some memory
        rm -f /tmp/*_$$.tmp
        ;;

*)
echo "Usage : $0 {setup|update|publish} [options...]"
echo "Options : "
echo "   $0 setup"
echo "   $0 update database_file [offpeak]"
echo "   $0 publish database_file path_of_html_report [user_file]"
echo "Examples : "
echo "   $0 setup"
echo "   $0 update /tmp/usage.db offpeak"
echo "   $0 publish /tmp/usage.db /www/user/usage.htm /jffs/users.txt"
echo "Note : [user_file] is an optional file to match users with their MAC address"
echo "       Its format is : 00:MA:CA:DD:RE:SS,username , with one entry per line"
exit
;;
esac

How to extract 7zip files in ubuntu

First install 7zip package

sudo apt-get install p7zip  

( you will need universal repository to run the above command )


after installing

7z x my7Zzipfile




Script to check weather user is root or not

if [ "$UID" -ne "$ROOT_UID" ]
then
 echo "Must be root to run this script."
 exit $E_NOTROOT
fi

Script to check weather user is root or not

if [ "$UID" -ne "$ROOT_UID" ]
then
 echo "Must be root to run this script."
 exit $E_NOTROOT
fi

How to Restore Vyatta grub

 grub> linux /boot/vmlinuz root=/dev/sda1

 grub> initrd /boot/initrd

 grub> boot

once we boot OS using this commands, We have to re-install grub to make it perminant

grub-install /dev/sda

will install grub now just reboot and relax !!

Make a Deal fraud in Hyderabad Victim's Society, In orbit mall city center

Hi all,
ha ha... laughing seeing the title Victim's society......

I am one of the victim of "make a deal" fraud done in hyderabad ( lost 50K)
My name is Naresh
Contact no : 9000608609

 this fraud happened in "In-Orbit" and "City Center" Malls in Hyderabad.

Here is what happened..
Stalls were setup in these malls attracting customers to pay Rs 50 and get gift vouchers/mobile recharge worth Rs 250, immediately.
Customers were promised to get Reebok vouchers to be mailed to their address.
The caveat however is the customer has to use his/her "Debit Card" to make initial Rs 50 payment.
As soon as the card is swiped and pin entered the details were captured, i believe in the card swipe machine.
After a few days when salaries were credited to the account, these fraudsters had cleaned the account.
I heard of customers who were happy getting Baskin Robins vouchers immediately, and these "satisfied customers" informed friends and family to avail this amazing "Make a deal" offer.


Lets all fight in common.....Lets join our hands 


I posted this to unite all victims so that we can fight back !!!


Feel free to contact me and join in group


Police told we will be gathered to record a statement...Don't know how far police will help us.





Lessons we learnt:
--------------------------------


1) Use credit cards, We have time to block the transaction if it is Unauthorized
2) Don't reveal Debit Card pins even to your friends.
3) Don't use Debit card of your salary account anywhere. ( Transaction done once salary got credited)
   Maintain alternative Debit cards with small amounts
4) Frequently change ATM pins, account passwords. 


News about this scam on DC
-----------------------------------------

How to add apache user to SVN repository ?

Add user and password

htpasswd -m /etc/apache2/dav_svn.passwd username1

Add entry for that user in the following file

vi /etc/apache2/dav_svn.authz