Mini Shell

Direktori : /opt/tier1adv/bin/
Upload File :
Current File : //opt/tier1adv/bin/downchk

#!/bin/bash

#
#   script: downchk (Can They Downgrade?)
#   author: terrenceh
#     note: FOR IMH SHARED BUSINESS CLASS ACCOUNTS ONLY
#           VPS AND DEDICATED ACCOUNTS STILL MUST BE REVIEWD BY SYSTEMS (T2S)
#
#     does: Will show the users current plan
#             + What key features they are using on that plan that determines downgrade eligibility
#             + If they can downgrade or not
#
#    usage: downchk userna5 [or]
#           downchk --about [or]
#           downchk --help
#

    VERSION=0.2

#
# info/usage
#

# about
    DisplayInfo(){
    # output:
        echo
        echo "  SCRIPT: downchk (Can They Downgrade?)"
        echo "  AUTHOR: Terrence H"
        echo
        echo "    NOTE: FOR IMH SHARED BUSINESS CLASS ACCOUNTS ONLY"
        echo "          VPS AND DEDICATED ACCOUNTS STILL MUST BE REVIEWD BY SYSTEMS (T2S)"
    echo
        echo "    DOES: Will show the users current plan"
        echo "           + What key features they are using on that plan that determines downgrade eligibility"
        echo "           + If they can downgrade or not"
    }

# usage
    DisplayUsage(){
    # output:
        echo
        echo "   USAGE: downchk userna5 [or]"
        echo "          downchk --about [or]"
        echo "          downchk --help"
        echo
        echo
    }

#
# main functions
#

# global vars
    declare CURRENT
    declare ADDONS
    declare PARKED
    declare SUBDOMS
    declare DBS
    declare FTPACCTS

# fetch account details
    GetDeterminingFactors(){
        CURRENT=$(sudo cat /var/cpanel/users/$USER|grep PLAN|cut -d= -f2);
        ADDONS=$(sudo cat /var/cpanel/userdata/$USER/main|sed -n '/addon_/,/main_/p'|sed '1d'|sed '$d'|grep -v "^$"|wc -l);
        PARKED=$(sudo cat /var/cpanel/userdata/$USER/main|sed -n '/parked_/,/sub_/p'|sed '1d'|sed '$d'|grep -v "^$"|wc -l);
        SUBDOMS=$(sudo cat /var/cpanel/userdata/$USER/main|sed -n '/sub_/,$p'|sed '1d'|sed '$d'|grep -v "^$"|wc -l);
        DBS=$(ls /var/lib/mysql|grep $USER|grep -v "^$"|wc -l);
        FTPACCTS=$(sudo cat /etc/proftpd/$USER|sed '$d'|sed '$d'|grep -v "^$"|wc -l);
    }

    DisplayEligibility(){
        if [[ "$CURRENT" != "Power" && "$CURRENT" != "Launch" ]]
        then
            if [[ "$ADDONS" -lt  6 && "$PARKED" -lt  27 && "$SUBDOMS" -lt  101 && "$DBS" -lt  51 && "$FTPACCTS" -lt 2001 ]]
            then
                echo -e " Eligible For A Power Plan?\tYES"
            else
                echo -e " Eligible For A Power Plan?\tNO"
            fi
        fi
        if [ "$CURRENT" != "Launch" ]
        then
            if [[ "$ADDONS" -lt  1 && "$PARKED" -lt  7 && "$SUBDOMS" -lt  26 && "$DBS" -lt  3 && "$FTPACCTS" -lt 1001 ]]
            then
                echo -e " Eligible For A Launch Plan?\tYES"
            else
                echo -e " Eligible For A Launch Plan?\tNO"
            fi
        fi
    }

# so, can they ?
    CanTheyDowngrade(){
    clear
        echo
        echo -e "\n Ummm...Can They Downgrade?";
        GetDeterminingFactors
    # output: results
        echo -e "\n Customer ($USER) is currently on a $CURRENT plan\n" \
                "\n The following are in use under this plan:\n" \
                "\n    $ADDONS\tAddon Domains" \
                "\n    $PARKED\tParked Domains" \
                "\n    $SUBDOMS\tSub Domains" \
                "\n    $DBS\tDatabases" \
                "\n    $FTPACCTS\tFTP Accounts"
        echo
        DisplayEligibility
        echo
        echo
    # final cleanup
        unset USER
        unset CURRENT
        unset ADDONS
        unset PARKED
        unset SUBDOMS
        unset DBS
        unset FTPACCTS
    }

#
# check input, validate and die on error [else] CanTheyDowngrade ?
#

# check for false input and display help
    if [[ -z "$1" || "$1" == "--help" || -n "$2" ]]
    then
    # output: usage
        DisplayInfo && DisplayUsage
        exit 0
# display info
    elif [ "$1" == "--about" ]
    then
    # output: about/usage
        DisplayInfo && DisplayUsage
        exit 0
    else
    #! user seems to not need help, but lets double check
        if [ -z "$(echo "$(ls /home|grep "$*"|grep -v "^$")")" ]
        then
        # error: entry appears invalid
            echo -e "$(tput setaf 1)\n   ERROR!$(tput sgr0) \"$*\" is not currently active on this server ($(hostname|cut -d\. -f1))\n          Are you sure you are logged into the right box?" && DisplayUsage
            exit 1
        else
        # ok, account exists on server
            USER=$(echo "$*")
        CanTheyDowngrade
        exit 0
         fi
    fi

# eof

Zerion Mini Shell 1.0