Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ "$#" -eq "1" ]; then
- givenuser="$1"
- else
- givenuser=":"
- fi
- confile="/etc/connections"
- if [ ! -f $confile ]; then echo "ERROR 00001: $confile does not exist" ; exit ; fi
- check1afile=`cat $confile | tr -cd '[A-Za-z0-9_-=]\n' | wc -c`
- check1bfile=`cat $confile | wc -c`
- if [ $check1afile -ne $check1bfile ]; then echo "ERROR 00002: illegal characters in $confile" ; exit ; fi
- defaultlimit=`grep '^default=' $confile | cut -f2 -d'='`
- confilelist=`cat /etc/connections`
- irconnections=`sockstat -c | grep ":" | grep 'tcp4' | awk '{ print $1 " " $7 }' | egrep ':666[0-9]$|:6670$|:7000$|:7777$' | cut -f1 -d' ' | sort | uniq -c | sort -n | awk '{ print $2 "=" $1 }'`
- for a in `echo "$irconnections"`
- do
- username=`echo "$a" | cut -f1 -d'='`
- connections=`echo "$a" | cut -f2 -d'='`
- check2file=`echo "$confilelist" | grep "^$username=" | wc -l`
- if [ $check2file -gt "1" ]; then echo "double account ($username) found in $confile" ; exit ; fi
- if [ $check2file -lt "1" ]; then
- usernamelimit="$defaultlimit"
- else
- usernamelimit=`echo "$confilelist" | grep "^$username=" | cut -f2 -d"="`
- fi
- usernamelimitkill=`expr $usernamelimit + 2`
- if [ "$connections" -gt "$usernamelimit" ]; then
- echo
- if [ "$connections" -gt "$usernamelimitkill" ]; then
- echo "CRITICAL: $username = $connections IRC Connections (AlertLimit: $usernamelimit, CriticalLimit: $usernamelimitkill)"
- echo "Actions: abused $username & inform server admin with logs"
- else
- echo "ALERT: $username = $connections IRC Connections (AlertLimit: $usernamelimit, CriticalLimit: $usernamelimitkill)"
- echo "Actions: inform server admin with logs"
- fi
- else
- if [ "$givenuser" != ":" ]; then echo "NORMAL: $username = $connections IRC Connections (AlertLimit: $usernamelimit, CriticalLimit: $usernamelimitkill)" ; fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement