#!/bin/sh

. /etc/blackPanther-default-apps.conf
#*********************************************************************************************************
#*   __     __               __     ______                __   __                      _______ _______   *
#*  |  |--.|  |.---.-..----.|  |--.|   __ \.---.-..-----.|  |_|  |--..-----..----.    |       |     __|  *
#*  |  _  ||  ||  _  ||  __||    < |    __/|  _  ||     ||   _|     ||  -__||   _|    |   -   |__     |  *
#*  |_____||__||___._||____||__|__||___|   |___._||__|__||____|__|__||_____||__|      |_______|_______|  *
#* http://www.blackpantheros.eu | http://www.blackpanther.hu - kbarcza[]blackpanther.hu * Charles Barcza *
#*************************************************************************************(c)2002-2011********
## THIS PROJECT THE INTERNET AND NETWORK CHECKING FOR BLACKPANTHER OS  
##

inet() {
if [ ! -n "`ping -c 1 google.com | grep 'PING google.com'`" ]; then 
    if [ "$1" = "2" ];then
	echo -en ${YEL}DNSERROR${DEF}
    fi
	iNET=DNSERROR
    if [ ! -n "`ping -c 1 8.8.8.8 | grep 'icmp_seq'`" ]; then 
	echo FAIL
	iNET=FAIL
	exit 1
      else
	# try fix DNS servers 
	if [ BP_AUTODNSFIX = yes ];then
	    mv -f /etc/resolv.conf  /etc/resolv.conf.DNSFIX
	    echo "nameserver 8.8.8.8" > /etc/resolv.conf
	    echo "nameserver 8.8.4.4" >> /etc/resolv.conf
	fi
	if [ "$1" = "2" ];then
	    echo -e OK
	    #iNET=OK
	    DNS=FAIL
	 exit
	fi

	inet 2
    fi
    else
	echo OK
	iNET=OK
	exit
fi
}

lnet() {
    echo "NO IMPLEMENTED YET"
}


if [ "$1" = "-h" -o "$1" = "--help" ];then
    echo ""
    echo -e "${GRN}This is a$BLK blackPanther OS$GRN specific tool"
    echo ""
    echo -e "$MAG  Usage:"
    echo -e "$YEL       `basename $0` internet $DEF Check the Internet connection status 
		$DEF(Also follwing too: i, web OR run without parameter) "
    echo -e "$YEL       `basename $0` local $DEF Check the local network status
		$DEF(Also follwing too: l, network OR run without parameter) "
    echo -e "$YEL       `basename $0` -h $DEF This screen"
    echo ""
    echo -e "$CYN  [$RED Example:$CYN `basename $0` i$RED OR to autodetect:$CYN `basename $0` ]$DEF"
    echo ""

    exit
fi

if [ "$1" = "i" -o "$1" = "internet" -o "$1" = "web" -o "$1" = "" ];then
    inet
elif [ "$1" = "l" -o "$1" = "local" -o "$1" = "network" ];then
    lnet
fi

exit 0