#!/bin/sh
onlinefile="/var/lib/linesrv/clients_online"
script=`echo "$0"|sed s/.*\\\///`
beep=`which beep`

if [ "$1" == "--add" ] || [ "$script" == "client_on" ]; then
  if [ "$2" != "" ]; then client=$2; else client=$1; fi
  echo "$client/32" >> $onlinefile
  if [ -n $beep ]; then 
    $beep -f 600 -l 1 && beep -f 800 -l 1
  fi
elif [ "$1" == "--remove" ] || [ "$script" == "client_off" ]; then
  if [ "$2" != "" ]; then
    client=$2
  else
    client=$1
  fi
  temp="0"
  for i in `cat $onlinefile`; do
    if [ "$temp" == "0" ]; then
      echo -n "" > $onlinefile
      temp="1"  
    fi
    if [ "$i" != "$client/32" ]; then
      echo "$i" >> $onlinefile
    fi
  done
  if [ -n $beep ]; then 
    $beep -f 800 -l 1 && beep -f 600 -l 1
  fi
elif [ "$1" == "--clear" ] || [ "$script" == "client_clear" ]; then
  echo -n "" > $onlinefile
fi
