#!/bin/sh

LAN_IF="INTERNAL_INTERFACE"
WAN_IF="EXTERNAL_INTERFACE"

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


ipt="/usr/sbin/iptables"
ips="/usr/sbin/ipset"
tc="/usr/sbin/tc"
arpcmd="/usr/sbin/arp"

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

DMARK=`expr $ID + 2`
UMARK=`expr $ID + 5001`

${ipt} -t mangle -D FORWARD -d ${IP} -j MARK --set-mark ${DMARK}
${ipt} -t mangle -D FORWARD -s ${IP} -j MARK --set-mark ${UMARK}


${tc} filter del dev ${LAN_IF} parent 1: protocol ip prio 1 handle ${DMARK} fw classid 1:${DMARK}
${tc} class del dev ${LAN_IF} parent 1:1 classid 1:${DMARK}

${tc} filter del dev ${WAN_IF} parent 1: protocol ip prio 1 handle ${UMARK} fw classid 1:${UMARK}
${tc} class del dev ${WAN_IF} parent 1:1 classid 1:${UMARK}



${ips} -A DISCON ${IP}
${ips} -D FORW ${IP}


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