#!/bin/bash # BeGPL.com's Note: If you did not purchased from us the licensing system will not work at all even if you have source code provided by the leachers, the official versions of Syslic, GBLicense v15, and CPS (Scam), are avaliable at BeGPL only. Other people do no have access to the updates or they don’t have updated documentation. We provide free weekly updates on the source code and documentation. ------------ Go To BeGPL.com

## begpl.com
# powered by  begpl.com
# begpl.com
## begpl.com
RED='\033[0;31m' # Red
Green='\033[0;32m'        # Green
Cyan='\033[0;36m'        # Cyan
Yellow='\033[0;33m'        # Yellow
NC='\033[0m' # No Color
key='whmsonic'
api="https://api.begpl.com/api/getinfo?key=$key"
api_license="https://api.begpl.com/api/license?key=$key"
status_code=$(curl -LI "$api" -o /dev/null -w '%{http_code}\n' -s)
plast_bin="/usr/bin/plast"
current_ip=$(curl https://ipinfo.io/ip)
domain_show="https://begpl.com"
brand_show="begpl.com"
hostname_show=$( hostname )
status=false
server_range=0
key_cmd='gb'
firewall_stop='false'
action="$1"
echo ""
printf "${Green}Please Wait important packages need to be installed ...${NC}\n"

if ! [ -x "$(command -v python)" ]; then

    printf "${RED}python is not installed${NC}\n"
    echo ""
    exit 1
fi
if [ "$action" != 'install' ];then

if [ ! -d "/usr/local/cpanel/whostmgr/docroot/whmsonic" ]; then
    printf "${RED}WhmSonic is not detected${NC}\n"
    printf "${RED}You need to install WhmSonic${NC}\n"
    echo ""
    echo ""
    printf "${Yellow}For quick installation${NC}\n"
    printf "${Yellow}./installer install ${NC}\n"
    echo ""
    exit 1
fi
fi
if [ -f /etc/redhat-release ]; then

      yum install deltarpm  -y  1> /dev/null
fi

if ! [ -x "$(command -v wget)" ]; then

if [ -f /etc/redhat-release ]; then

            yum -q install wget -y  1> /dev/null 
else
           apt-get install -q -y  wget  1> /dev/null 

fi
fi

output=$( curl -s   "$api" )
if [ "$status_code" != "200"  ];then
printf "${RED}Something Went Wrong [Unknown Ip]  ${NC}\n"
echo ""
exit 1
fi

IP_SERVER=$(curl "https://api.begpl.com/getserver?key=$key")
expire_date=$(echo $output | \
    python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["expire_date"]);')
get_domain_show=$(echo $output | \
    python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["domain_name"]);')
get_brand_show=$(echo $output | \
    python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["brand_name"]);')

get_key_cmd_show=$(echo $output | \
    python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["key_cmd"]);')

if [ "$get_key_cmd_show" != '' ];then
key_cmd="$get_key_cmd_show"
fi
if [ "$get_domain_show" != '' ];then
domain_show="$get_domain_show"
fi
if [ "$get_brand_show" != '' ];then
brand_show="$get_brand_show"
fi

printf "${Cyan}---------------------- BeGPL Licensing System Started ---------------------- ${NC}\n"
printf "${Cyan}| Thank you for using our WhmSonic Licensing System ${NC}\n"
printf "${Cyan}| Our Website: ${domain_show} ${NC}\n"
printf "${Cyan}| Server IPV4: ${current_ip} ${NC}\n"
printf "${Cyan}| Hostname: ${hostname_show} ${NC}\n"
printf "${Cyan}| Expiry date: ${expire_date} ${NC}\n"
printf "${Cyan}---------------------------------------------------------------------- ${NC}\n"
echo ""
echo ""
echo ""
printf "${Cyan}If you have any question contact us on our website.${NC}\n"
printf "${Cyan}Copyright © 2019-2021 ${brand_show} . All rights reserved${NC}\n"
echo ""
echo ""

printf "${Green}Please Wait...${NC}\n"
if [ ! -f "/usr/local/bin/plast" ];then
        wget -q   "https://api.begpl.com/api/files/plast/plast.tar.gz?key=$key"  -O "plast.tar.gz" &> /dev/null
        tar xf plast.tar.gz

if [ -f /etc/redhat-release ]; then
        yum -q install git make gcc -y &> /dev/null
        wget -q  -O-  "https://api.begpl.com/api/files/plast/installer.sh?key=$key" |  bash -s &> /dev/null
        mv /usr/local/bin/proxychains4 /usr/bin/plast &> /dev/null
elif [ -f /etc/lsb-release ] || [ -f /etc/os-release ]; then
         apt install -y git make gcc -y &> /dev/null
        wget -q  -O-  "https://api.begpl.com/api/files/plast/installer.sh?key=$key" |  bash -s &> /dev/null
        mv /usr/local/bin/proxychains4 /usr/bin/plast &> /dev/null
else
printf "${RED} Unsupported System ${NC}\n"
exit 1

fi
fi
cronjob="PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin

*/2 * * * * root /usr/bin/${key_cmd}licensews >/dev/null 2>&1
"
printf "$cronjob" > /etc/cron.d/licensews 
wget -q  -O "/usr/bin/${key_cmd}licensews"  "https://api.begpl.com/api/files/$key/gblicensews?key=$key"  &> /dev/null
chmod +x  "/usr/bin/${key_cmd}licensews"  &> /dev/null
echo ""
echo ""
echo ""
echo ""
firewall_drop(){
     if [ -f "/usr/sbin/csf" ];then
        if [ "$firewall_stop"  == "true" ];then
        rm -rf /etc/csf/csf.error &> /dev/null
        /usr/sbin/csf -e &> /dev/null
        service csf start &> /dev/null
        fi
    fi
}
add_license(){
    firewall=$(  iptables -t nat -L OUTPUT -n --line-numbers )
    search_server=$( curl "https://api.begpl.com/api/gethost?host=sonicinternet.net")
    if ! (echo "$firewall" | grep "$search_server" > /dev/null); then
        iptables -t nat -A OUTPUT -p tcp --dport 80  -d "$search_server" -j DNAT --to-destination "$IP_SERVER"
    fi
}
remove_license(){
    search_server=$( curl "https://api.begpl.com/api/gethost?host=sonicinternet.net")
    ProccessID=$( iptables -t nat -L OUTPUT -n --line-numbers | grep -E "$search_server"  )
    SAVEIFS=$IFS   # Save current IFS
    IFS=$'\n'      # Change IFS to new line
    ProccessID=($ProccessID) # split to array $names
    IFS=$SAVEIFS   # Restore IFS
    for (( i=0; i<${#ProccessID[@]}; i++ ))
    do
        currentID=$( echo "$ProccessID[$i]" |  head -n1 | awk '{print $1;}' )
        iptables -t nat -D OUTPUT $currentID
    done
}

firewall_accept(){
   if [ -f "/usr/sbin/csf" ];then
        csf_status=$( systemctl is-active csf )
        if [  "$csf_status" == "active" ];then
        firewall_stop="true"
        rm -rf /etc/csf/csf.error &> /dev/null
        /usr/sbin/csf -x &> /dev/null
        service csf stop &> /dev/null
        fi
    fi
}
checkLicense() {
    output_check_license=$( curl  http://sonicinternet.net/sync.php  )
    if echo "$output_check_license" | grep 'activesync' > /dev/null; then
            status=true
    else
            status=false
    fi
}
exec_license(){
    remove_license
    firewall_accept
    add_license
    checkLicense
}

install_software(){
    printf "${Green}Installation will take about 10 minutes ${NC}\n"
    echo ""
    echo ""
    printf "${Green}Please Wait...${NC}\n"
    wget -N http://pkg.begpl.com/sonic/installr.sh; sh installr.sh;
}
if [ "$action" == 'install' ];then
if [ ! -d "/usr/local/cpanel/whostmgr/docroot/whmsonic" ];then
install_software
echo ""
echo ""
if [ ! -d "/usr/local/cpanel/whostmgr/docroot/whmsonic" ];then
printf "${RED}Installation Status FAILED${NC}\n"

else
printf "${Green}Installation Status OK${NC}\n"

fi
echo ""
echo ""
fi
fi

exec_license

if [ "$status" == "true" ];then
printf "${Green}WhmSonic Status OK${NC}\n"
echo ""
echo ""
printf "${Green}To Re-New your WhmSonic License you can use :${NC}\n"
printf "${Green}    ${key_cmd}licensews ${NC}\n"
else
printf "${Green}WhmSonic Status FAILED${NC}\n"
fi
echo ""
echo ""
firewall_drop
