#!/bin/sh

LOGIN=$1
IP=$2
CASH=$3
ID=$4
SPEED=`/etc/stargazer/GetSpeed $LOGIN`
UPSPEED=`/etc/stargazer/GetUpSpeed $LOGIN`
MAC=`/etc/stargazer/GetMac $LOGIN`
SCOUNT="Kbit/s"

fwcmd="/sbin/ipfw -q"
arpcmd="/usr/sbin/arp"

cur_date=`date \+\%Y.\%m.\%d`
cur_time=`date \+\%H:\%M:\%S`



# fix user mac to ip
${arpcmd} -S $IP $MAC

#SPEED CONTROL
${fwcmd} pipe `expr $ID + 101` config bw $UPSPEED$SCOUNT queue 32Kbytes
${fwcmd} pipe `expr $ID + 18101` config bw $SPEED$SCOUNT queue 32Kbytes

# SHAPER
${fwcmd} table 3 add $IP `expr $ID + 101`
${fwcmd} table 4 add $IP `expr $ID + 18101`

${fwcmd} table 47 delete $IP


# DAY/NIGHT switcher
/bin/echo $SPEED:`expr $ID + 18101` > /etc/stargazer/dn/$LOGIN
/bin/chmod 777 /etc/stargazer/dn/$LOGIN


# ADD TO LOG
echo "$cur_date $cur_time CONNECT: ID-$ID;LOGIN-$LOGIN;IP-$IP;CASH-$CASH;SPEED-$SPEED;UPSPEED-$UPSPEED,MAC-$MAC" >> /var/stargazer/allconnect.log