HEX
Server: nginx/1.16.1
System: Linux ecs-04358622 4.19.90-2107.6.0.0100.oe1.bclinux.x86_64 #1 SMP Wed Dec 1 19:59:44 CST 2021 x86_64
User: nginx (994)
PHP: 8.0.0
Disabled: NONE
Upload Files
File: //opt/BCLinux/bse/common/bclinux_common.sh
#VER_ID="SecurityHarden,  by bclinux, 2016-08-30"
#TMP_DIR=`dirname $0`


#
############################################################################
# distro Detection
############################################################################
#
distro_detection()
{
    if [ -f /etc/bclinux-release ];then
	OS_ID="BCLinux"
	is_Euler=$(cat /etc/bclinux-release | egrep Euler |wc -l)
	if [ $is_Euler != 0 ];then
	    OS_DISTRO=$(cat /etc/bclinux-release | egrep -io [0-9]\{1,2\}.[0-9]\{1,2\})
        else
            OS_DISTRO=$(cat /etc/bclinux-release | egrep -io [0-9].[0-9] | head -1 | cut -d '.' -f 1 )
	fi
        logtext "Detected this system is  ${OS_ID}-${OS_DISTRO}"
        Display --indent 2 --text "- Get the OS-ID:${OS_ID} and OS-version:${OS_DISTRO} " --result OK  --color GREEN
    elif [ -f /etc/os-release ];then
        OS_ID=`cat /etc/os-release | grep -Eiw '^ID' | cut -d = -f 2` # like ID="centos" ID="sles" ID=debian
        OS_DISTRO=`cat /etc/os-release | grep -Eiw '^VERSION_ID' | cut -d = -f 2` #like VERSION_ID="7"
        case ${OS_ID} in
            "centos" | "\"centos\"" |"CentOS" | "\"CentOS\"" | "rhel" | "\"rhel\"" | "redhat" | "\"redhat\"" | "bclinux" | "\"bclinux\"" )
                logtext "Detected this system is  ${OS_ID}-${OS_DISTRO}"
                Display --indent 2 --text "- Get the OS-ID:${OS_ID} and OS-version:${OS_DISTRO}... " --result OK  --color GREEN
	    ;;
            * )
                logtext "This is not RHEL Distro, we do not support ${OS_ID}-${OS_DISTRO} at this moment, accroding to /etc/os-release"
                Display --indent 2 --text "- Can't detect system type by /etc/os-release... " --result WARNING --color RED
            ;;
        esac
    elif [ -f /etc/redhat-release ];then
        for i in $(cat /etc/redhat-release)
        do
            if [ $(echo  $i | grep -E '6|7' |wc -l) -gt 0 ];then  #like VERSION_ID="6"
                OS_DISTRO=`echo $i| cut -d '.' -f 1`
            else
                case $i in
                    "CentOS" | "centos") # like ID="centos"
                        OS_ID="centos"
                    ;;
                    "Red" | "red")
                        OS_ID="rhel"
                    ;;
                    "BigCloud" | "bigcloud" | "Big" | "big")
                        OS_ID="bclinux"
                    ;;
                    *)
                    #logtext "Can't detect the OS_ID(such as rhel) and OS_DISTRO(such as 6) by /etc/redhat-release file"
                    #Display --indent 2 --text "- Can't detect system type by /etc/redhat-release..." --result WARNING --color RED
                    ;;
                esac
            fi
        done
        if [ ! -z ${OS_ID} ] || [ ! -z ${OS_DISTRO} ];then
            logtext "Detected this system is  ${OS_ID}-${OS_DISTRO}"
            Display --indent 2 --text "- Get the OS-ID:${OS_ID} and OS-version:${OS_DISTRO}... " --result OK  --color GREEN
        fi
    else
        logtext "no os-release and redhat-release file, can not detect the OS_ID(such as redhat) and OS_DISTRO(such as 6)"
        Display --indent 2 --text "- No os-release and redhat-release file... " --result WARNING --color RED
    fi
}



#
############################################################################
# Machine Detection( virtual or physical )
############################################################################
#
machine_detection()
{
    PLANTFORM=`dmidecode -s system-product-name | egrep -i 'VMware|VirtualBox|KVM|Bochs|HVM|OpenStack'`

    if [ "${PLANTFORM}" = "" ]; then
        MachineType="physical"
    else
        MachineType="virtual"
    fi
}


#
############################################################################
# OS Detection
############################################################################
#
#os_detection()
#{
#
#    SafePerms ${INCLUDEDIR}/osdetection
#    . ${INCLUDEDIR}/osdetection
#    Display --indent 2 --text "- Detecting OS... " --result DONE --color GREEN
#}


#
############################################################################
#check all scripts
############################################################################
#
check_info()
{
    checkDir="include secure_check secure_set common option_set soft_changelog"
    checkFile=" "
    for i in $checkDir
    do
        if [ ! -d ${rundir}/$i ]; then
            echo "Can't find dir: ${rundir}/${i}"
            exit 1;
	#else
	    #echo "has ${rundir}/${i} dir"
	fi
    done
}

#
############################################################################
## write the text to log file.
############################################################################
#
#logtext()
#{
#    if [ ! "${LOGFILE}" = "" ]; then
#        CDATE=`date "+[%Y/%m/%d %H:%M:%S]"`
#        echo "${CDATE} $1" >> ${LOGFILE}
#    fi
#}
# write break line to log file to seprate different sector
#logtextbreak()
#{
#   if [ ! "${LOGFILE}" = "" ]; then
#       CDATE=`date "+[%Y/%m/%d %H:%M:%S]"`
#       echo "${CDATE} ===---------------------------------------------------------------===" >> ${LOGFILE}
#   fi
#}


#
############################################################################
# Insert section block
############################################################################
#
#InsertSection()
#{
#  echo ""
#  echo -e "[+] ${SECTION} $1 ${NORMAL}"
#  echo "------------------------------------"
#
#  echo "" >>${LOGFILE}
#  echo "${CDATE} $1" >> ${LOGFILE}
#  echo "------------------------------------">>${LOGFILE}
#}


#
############################################################################
# log the user info, out put info to console
############################################################################
#
log()
{
    echo ""
    #echo -e "\e[1m $1 \e[0;39m"
    echo -e "${PURPLE} $1 ${NORMAL}"
}


#
############################################################################
# out put the error info
############################################################################
#
error()  # 打印出错信息,并退出
{
    echo -e "\e[1;5;31m$1\e[0;39m"
    exit 1
}


#
############################################################################
# clean up the tmp file
############################################################################
#
cleanup()
{
    if [ -d $TMP_DIR ];then
        #echo "Clean the TMP file"
        rm -rf "$TMP_DIR"
    fi
  #return 0
}


#
############################################################################
# exit the proc
############################################################################
#
die()
{
  echo "$*"

  cleanup

  exit 1
}



##
#############################################################################
## count the harding points
#############################################################################
##
#COUNT_HP()
#  {
#    HPADD=$1; HPADDMAX=$2
#    #bc_HPPOINTS=$(expr ${bc_HPPOINTS} + ${HPADD})
#    #bc_HPTOTAL=$(expr ${bc_HPTOTAL} + ${HPADDMAX})
#    bc_HPPOINTS=`expr "$bc_HPPOINTS" + "$HPADD"`
#    bc_HPTOTAL=`expr "$bc_HPTOTAL" + "$HPADDMAX" `
#    echo "HP_ADD: ${HPADD},  HD_MAX: ${HPADDMAX}),   BC_HPPOINTS: ${bc_HPPOINTS},  total: ${bc_HPTOTAL}"
#    #LogText "Hardening: assigned ${HPADD} hardening points (max for this item: ${HPADDMAX}), current: ${bc_HPPOINTS}, total: ${bc_HPTOTAL}"
#  }
#
#
##
#############################################################################
## overwrite the lynis AddHP func
#############################################################################
##
#AddHP()
#{
#   COUNT_HP $1 $2
#}




#
############################################################################
# show the check result overview
############################################################################
#
bc_show_result()
{

    echo "${WHITE}"
    echo "  ###################################################################"
    echo "  #                                                                 #"
    echo "  #   ${MAGENTA}Show the checking result overview...${WHITE}                          #"
    echo "  #                                                                 #"
    echo "  ###################################################################"
    echo "${NORMAL}"

    sleep $TEST_PAUSE_TIME

    #################################################################################
    # Show test results overview
    #################################################################################
        # Store total performed tests
        report "${PROGRAM_NAME}_tests_done=${CTESTS_PERFORMED}"
        CDATE=$(date "+%F %H:%M:%S")
        report_datetime_end=${CDATE}
        report "report_datetime_end=${CDATE}"

        # Show report
        if [ -f ${INCLUDEDIR}/report ]; then SafePerms ${INCLUDEDIR}/report; . ${INCLUDEDIR}/report; fi


}








#
############################################################################
# check the system
############################################################################
#
bc_check_sys()
{
    # clear the counter, make this function re-call-able.
    # these two counter used for bc_show_result func.
    HPPOINTS=0
    HPTOTAL=0

    echo "${WHITE}"
    echo "  ###################################################################"
    echo "  #                                                                 #"
    echo "  #   ${MAGENTA}Starting check the ${OS_NAME} system basicly...${WHITE}                  #"
    echo "  #                                                                 #"
    echo "  ###################################################################"
    echo "${NORMAL}"

    sleep $TEST_PAUSE_TIME

    #TMP_DIR=$(mktemp -d -q)
    #RESULT_FILE=$TMP_DIR/check_result.relt
    #[ -w "$TMP_DIR"  ] || mkdir "$TMP_DIR" || die "Fatal Error: Unable to create $TMP_DIR"

    RESULT_FILE=${LOGDIR}/check_result.relt

    #
    #################################################################################
    #
    if [ -w ${RESULT_FILE} ];then
         > ${RESULT_FILE}
    else
        touch $RESULT_FILE
    fi

    CHECK_ITEMS=`find secure_check/ -type f | sort`
    #echo "${WHITE} Stat check $CHECK_ITEMS ${NORAML}"
    for i in $CHECK_ITEMS
    do
        #wait_for_keypress
        logtext "checking the $i"
        . $i
        sleep $TEST_PAUSE_TIME
        #echo "Checking OK items:$bc_HPPOINTS, total check items: $bc_HPTOTAL"
        logtextbreak
    done


    bc_show_result
}




#
############################################################################
# check the system advancly
############################################################################
#
bc_check_adv()
{
    # clear the counter, make this function re-call-able.
    # these two counter used for bc_show_result func.
    HPPOINTS=0
    HPTOTAL=0

    echo "${WHITE}"
    echo "  ###################################################################"
    echo "  #                                                                 #"
    echo "  #   ${MAGENTA}Starting check the ${OS_NAME} system advancly...${WHITE}                 #"
    echo "  #                                                                 #"
    echo "  ###################################################################"
    echo "${NORMAL}"

    sleep $TEST_PAUSE_TIME

    #TMP_DIR=$(mktemp -d -q)
    #RESULT_FILE=$TMP_DIR/check_result.relt
    #[ -w "$TMP_DIR"  ] || mkdir "$TMP_DIR" || die "Fatal Error: Unable to create $TMP_DIR"

    RESULT_FILE=${LOGDIR}/check_result.relt

    #
    #################################################################################
    #
    if [ -w ${RESULT_FILE} ];then
         > ${RESULT_FILE}
    else
        touch $RESULT_FILE
    fi

    CHECK_ITEMS=`find option_check/ -type f | sort`
    #echo "${WHITE} Stat check $CHECK_ITEMS ${NORAML}"
    for i in $CHECK_ITEMS
    do
        #wait_for_keypress
        logtext "checking the $i"
        . $i
        sleep $TEST_PAUSE_TIME
        #echo "Checking OK items:$bc_HPPOINTS, total check items: $bc_HPTOTAL"
        logtextbreak
    done

    bc_show_result
}



#
############################################################################
# check the system rootkit
############################################################################
#
bc_check_rootkit()
{
    # clear the counter, make this function re-call-able.
    # these two counter used for bc_show_result func.
    HPPOINTS=0
    HPTOTAL=0
    echo "${WHITE}"
    echo "  ###################################################################"
    echo "  #                                                                 #"
    echo "  #   ${MAGENTA}Starting check the ${OS_NAME} system rootkit...${WHITE}                  #"
    echo "  #                                                                 #"
    echo "  ###################################################################"
    echo "${NORMAL}"

    sleep $TEST_PAUSE_TIME
    RESULT_FILE=${LOGDIR}/check_result.relt

    #
    #################################################################################
    #
    if [ -w ${RESULT_FILE} ];then
         > ${RESULT_FILE}
    else
        touch $RESULT_FILE
    fi

    CHECK_ITEMS=`find intrusion_check/ -type f | sort`
    #echo "${WHITE} Stat check $CHECK_ITEMS ${NORAML}"
    for i in $CHECK_ITEMS
    do
        #wait_for_keypress
        logtext "checking the $i"
        . $i
        sleep $TEST_PAUSE_TIME
        #echo "Checking OK items:$bc_HPPOINTS, total check items: $bc_HPTOTAL"
        logtextbreak
    done

    bc_show_result
}





#
############################################################################
# fix the system
############################################################################
#
bc_fix_sys()
{
    echo "${WHITE}"
    echo "  ###################################################################"
    echo "  #                                                                 #"
    echo "  #   ${MAGENTA}Basicly fix the ${OS_NAME} system...${WHITE}                             #"
    echo "  #                                                                 #"
    echo "  ###################################################################"
    echo "${NORMAL}"

    sleep $TEST_PAUSE_TIME

    if [ -f $RESULT_FILE ] && [ -s $RESULT_FILE ]; then
        CHECK_SET=`find secure_set/ -type f | sort`
        log "Begin to fix the ${OS_NAME} system warnings, accroding to checking-result..."
        #wait_for_keypress
        for iFix in `cat $RESULT_FILE| grep -Ev '^$|^#' | sort | cut -d ' ' -f 1 | uniq | cut -d 'c' -f 2`
        do
            SET_ITEM=`find secure_set/ -type f | sort | grep $iFix`
            if [ $(find secure_set/ -type f | sort | grep $iFix |wc -l)  -gt 0  ];then
                . $SET_ITEM
                sleep $TEST_PAUSE_TIME
            else
               log "can't fix items $(find secure_check/ -type f | sort | grep $iFix | cut -d '/' -f 2 | cut -d '_' -f 2) in this status, try '$0 fix adv'"
               logtext "can't fix items $(find secure_check/ -type f | sort | grep $iFix | cut -d '/' -f 2 | cut -d '_' -f 2) in this status, try '$0 fix adv'"
            fi
        done
        > $RESULT_FILE # clean the result file
        rm $RESULT_FILE #remove the check_result.relt
    else
        CHECK_SET=`find secure_set/ -type f | sort`
        log "Begin to fix the ${OS_NAME} system warnings, without checking-result..."
        for iFix in ${CHECK_SET}
        do
            . ${iFix}
            sleep $TEST_PAUSE_TIME
        done
    fi

# restart service
#

    systemctl is-active sshd > /dev/null 2>&1
    if [ $? -eq 0 ];then
            systemctl restart sshd
            echo ""
            echo "${GREEN} Finish restart sshd.service${NORMAL}"
            echo ""
    else
            systemctl start sshd
            echo ""
            echo "${GREEN} Finish start sshd.service${NORMAL}"
            echo ""

    fi

    systemctl is-active rsyslog > /dev/null 2>&1
    if [ $? -eq 0 ];then
            systemctl restart rsyslog
            echo ""
            echo "${GREEN} Finish restart rsyslog.service${NORMAL}"
            echo ""
    else
            systemctl start rsyslog
            echo ""
            echo "${GREEN} Finish start rsyslog.service${NORMAL}"
            echo ""

    fi

    echo ""
    echo "${GREEN} Fix system finished... Now you can recheck the system${NORMAL}"
    echo ""
}







#
############################################################################
# fix the system by specify items
############################################################################
#
bc_fix_sys_by_items()
{

    CHECK_SET=`find option_set/ -type f | sort`
    if [ $# -gt 0 ];then
        echo "${WHITE}"
        echo "  ###################################################################"
        echo "  #                                                                 #"
        echo "  #   ${MAGENTA}Fix the specify items...${WHITE}                            #"
        echo "  #                                                                 #"
        echo "  ###################################################################"
        echo "${NORMAL}"
        USER_ITEMS=`find option_set/ -type f | grep -i $1`
        if [ ! -z ${USER_ITEMS} ];then
            log "you are going to call the ${USER_ITEMS}. [y/N]: "
            read aa
            if [[ ${aa} = "y" ]];then
                . ${USER_ITEMS} #call the specify items
            elif [[ ${aa} = "N" ]];then
                echo "Exiting on user command "
            else
                echo "Wrong input"
            fi
        else
            log "wrong items, can not find $1, please check..."
        fi
    else
        echo "${WHITE}"
        echo "  ###################################################################"
        echo "  #                                                                 #"
        echo "  #   ${MAGENTA}Advance fix the ${OS_NAME} system ...${WHITE}                            #"
        echo "  #                                                                 #"
        echo "  ###################################################################"
        echo "${NORMAL}"
        logtext "no option was given, do all secure enhance"
        if [ ${AUTO_ADV_FIX} -eq 1 ];then
            for iFix in ${CHECK_SET}
            do
                . ${iFix}
                sleep $TEST_PAUSE_TIME
            done
        else
            echo "${YELLOW_BLINK} Notice${NORMAL}: Make sure you have already configed the following file:"
            echo "        ${WHITE} ${PROFILE} ${NORMAL}"
            echo ""
            echo "  You know the effect and ready to do it. ${GREEN}[y/n]${NORMAL}: "
            read bb
            if [[ ${bb} = "y" ]];then
                for iFix in ${CHECK_SET}
                do
                    . ${iFix}
                    sleep $TEST_PAUSE_TIME
                done
            else
                echo ""
                echo "  Leaving... Remain everyting unchanged."
            fi
        fi
    fi
    echo ""
    echo "${GREEN} Advancly fix finished... Now you can recheck the system${NORMAL}"
    echo ""
}





#
############################################################################
# fix the system by advance option
############################################################################
#
bc_fix_sys_avd()
{
#    #basic fix
#    bc_fix_sys

    #advance fix, no input params.
    bc_fix_sys_by_items
}

#
############################################################################
# restore unused  user
############################################################################
#
restore_unused_user()
{
   for i in $UNUSED_USER_VALUE
   do
       is_exist=`grep $i /etc/passwd | grep -v "^#"| wc -l`
       if [ "${is_exist}" != "0" ];then
           usermod -U -s /sbin/nologin $i
       fi
   done
   Display --indent 2 --text "- Restoring unused user... " --result FINISHED --color GREEN
}

#
############################################################################
# restore the basic settings
############################################################################
#
bc_restore_basic_inline()
{
    changeFile=`grep -irw cp  secure_set/ | sort | awk -F '-np' '{print $2}' | awk -F ' ' '{print $1}' | sort | uniq`
    for i in $changeFile
    do
        if [[ -f ${i}_bak ]];then
            logtext "Found bak file:$i, starting restore"
            Display --indent 2 --text "- Restoring cfg file:$i... " --result FINISHED --color GREEN
            if  [[ -f ${i} ]];then
                mv -f ${i} ${i}_user_modifyed
            fi
            mv -f ${i}_bak $i
        else
            logtext "No $i bak config file was found"
            Display --indent 2 --text "- Restoring cfg file:$i... " --result SKIPPED --color YELLOW
        fi
    done
    #restart service
    #service_cmd=` egrep -irw  "^( *)service" ./secure_set/ |grep "restart"| cut -d ":" -f 2 | sort | uniq | sed 's/\(.*\)service \(.*\) restart\(.*\)/\2/g'`
    #for i in $service_cmd
    #do
    #    logtext "Restart the service:$i"
    #    service $i restart >/dev/null 2>&1
    #    Display --indent 2 --text "- Restart service:$i... " --result FINISHED --color GREEN
    #done
    systemctl is-active sshd > /dev/null 2>&1
    if [ $? -eq 0 ];then
         systemctl restart sshd
         logtext "Restart the service:sshd"
         Display --indent 2 --text "- Restart service:sshd... " --result FINISHED --color GREEN
    fi

    systemctl is-active rsyslog > /dev/null 2>&1
    if [ $? -eq 0 ];then
         systemctl restart rsyslog
         logtext "Restart the service:rsyslog"
         Display --indent 2 --text "- Restart service:rsyslog... " --result FINISHED --color GREEN

    fi


   # restore property of file and dir
   property_file="/etc/bse.d/fdproperty_record"
   if [[ -f $property_file ]];then
       restore_file=`cat $property_file`
       for i in $restore_file;do
           name=`echo $i|awk -F'=' '{print $1}'`
           if [[ -f $name ]];then
               pro_val=`echo $i|awk -F'=' '{print $2}'`
               chmod $pro_val $name
           fi
           Display --indent 2 --text "- Restoring property of file or dir:$name..." --result FINISHED --color GREEN
       done
   fi
   #restore unused user
   restore_unused_user

   > $RESULT_FILE # clean the result file
   rm $RESULT_FILE #remove the check_result.relt
}

bc_restore_basic_settings()
{

    echo "${WHITE}"
    echo "  ###################################################################"
    echo "  #                                                                 #"
    echo "  #   ${MAGENTA}Restore Basic settings...${WHITE}                                     #"
    echo "  #                                                                 #"
    echo "  ###################################################################"
    echo "${NORMAL}"

    #auto do the restore
    if [ ${AUTO_BASIC_RESTORE} -eq 1 ];then
        bc_restore_basic_inline
    else
        echo "${YELLOW_BLINK} Notice${NORMAL}:"
        echo "  You know the effect and ready to do it. ${GREEN}[y/n]${NORMAL}: "
        read bb
        if [ ${bb}X = "y"X  -o ${bb}X = "yes"X ];then
            bc_restore_basic_inline
        else
            echo ""
            echo "  Leaving... Remain everyting unchanged."
        fi
    fi

    echo ""
    echo "${GREEN} Restore basicly finished... Now you can refix the system${NORMAL}"
    echo ""
}



#
############################################################################
# restore the advance settings
############################################################################
#
bc_restore_adv_inline()
{
    #delete the user
    logtext "Check if there exists user:$UserName, and delete it..."
    UserName=`cat ${PROFILE} | grep -E '^UserName' | cut -d '=' -f 2`
    if [ ! -z $UserName ];then
        if [ $(ls /home | grep -i $UserName | wc -l) -gt 0 ];then
            logtext "Have user:$UserName, deleting..."
            userdel -f $UserName
            rm -rf /home/${UserName}
            Display --indent 2 --text "- Deleting user:$UserName... " --result FINISHED  --color GREEN
        else
            logtext "No user:$UserName was created on this system"
            Display --indent 2 --text "- No user:$UserName was found... " --result SKIPPED --color YELLOW
        fi
    fi
    #restore the file
    changeFile=`grep -irw cp  option_set/ | sort | awk -F '-np' '{print $2}' | awk -F ' ' '{print $1}' | sort | uniq`
    for i in $changeFile
    do
        if [[ -f ${i}_bak ]];then
            logtext "Found bak file:$i, starting restore"
            Display --indent 2 --text "- Restoring cfg file:$i... " --result FINISHED --color GREEN
            if  [[ -f ${i} ]];then
                mv -f ${i} ${i}_user_modifyed
            fi
            mv -f ${i}_bak ${i}
        else
            logtext "No $i bak config file was found"
            Display --indent 2 --text "- Restoring cfg file:$i... " --result SKIPPED --color YELLOW
        fi
    done

        # restore property of logfile
        log_file="/etc/bse.d/logfile_property"
        if [[ -f $log_file ]];then
            restore_file=`cat $log_file`
            for i in $restore_file;do
                name=`echo $i|awk -F'=' '{print $1}'`
                if [[ -f $name ]];then
                    pro_val=`echo $i|awk -F'=' '{print $2}'`
                    chmod $pro_val $name
                fi
                Display --indent 2 --text "- Restoring property of file:$name... " --result FINISHED --color GREEN
            done
        fi

    #restart the service
    service_cmd=` egrep -irw  "^( *)service" ./option_set/ |grep "restart"| cut -d ":" -f 2 | sort | uniq | sed 's/\(.*\)service \(.*\) restart\(.*\)/\2/g'`
    for i in $service_cmd
    do
        logtext "Restart the service:$i"
        service $i restart >/dev/null 2>&1
        Display --indent 2 --text "- Restart service:$i... " --result FINISHED --color GREEN
    done
    > $RESULT_FILE # clean the result file
    rm $RESULT_FILE #remove the check_result.relt
}

bc_restore_adv_settings()
{
    echo "${WHITE}"
    echo "  ###################################################################"
    echo "  #                                                                 #"
    echo "  #   ${MAGENTA}Restore Advance settings...${WHITE}                                   #"
    echo "  #                                                                 #"
    echo "  ###################################################################"
    echo "${NORMAL}"

    #auto do the restore
    if [ ${AUTO_ADV_RESTORE} -eq 1 ];then
        bc_restore_adv_inline
    else
        echo "${YELLOW_BLINK} Notice${NORMAL}:"
        echo "  You know the effect and ready to do it. ${GREEN}[y/n]${NORMAL}: "
        read bb
        if [ ${bb}X = "y"X  -o ${bb}X = "yes"X ];then
            bc_restore_adv_inline
        else
            echo ""
            echo "  Leaving... Remain everyting unchanged."
        fi
    fi
    echo ""
    echo "${GREEN} Restore advancly finished... Now you can refix the system${NORMAL}"
    echo ""
}

# Implement of Update_changelog
Update_changelog_from_to(){
    SOFTLIST="bash glibc openssh openssl httpd mysql tomcat kernel sudo wget php"
    for i in $SOFTLIST;do
        echo "  - Checking rpm of $i from $1"
        #softname=$(curl -s --max-time 10 $1 | grep -o "$i-[0-9][-._a-z0-9]*x86_64.rpm" | tail -n 1)
        softname=$(curl -s --max-time 10 $1 | grep -o "$i-[0-9][-._a-z0-9]*.rpm" | tail -n 1)
        [[ -z $softname ]] && echo "  No $i found to update, check next package." && continue  #shikp if there is no update package
        packeturl=${1}${softname}
        #echo $packeturl
        CreateTempFile
        logtext "Downloading $i form ${packeturl}"
        echo "  Updating database of $i form ${packeturl}"
        curl -sf --max-time 10 $packeturl > ${TEMP_FILE}
        if [ $? -ne 0 ];then
            logtext "can't download form ${packeturl}, maybe the url or network errors."
            Display --indent 2 --text "Can't download form ${packeturl}, maybe the url or network errors" --result WARNING --color RED
        else
            rm -rf ${rundir}/soft_changelog/$2/${i}*  > /dev/null 2>&1 #remove the old file
            touch ${rundir}/soft_changelog/$2/$softname
            rpm -qp --changelog ${TEMP_FILE} > ${rundir}/soft_changelog/$2/$softname
            logtext "Successfully update changelogs of $i"
            Display --indent 2 --text "Successfully update changelogs of $i" --result FINISHED --color GREEN
        fi
    done
}


################################################################################
# Name        : bc_update_changelog()
# Description : automatic download changelog of some specific softwares from mirrors.bclinux.org
# Returns     : <nothing>
################################################################################
bc_update_changelog()
{
    echo "${WHITE}"
    echo "  ###################################################################"
    echo "  #                                                                 #"
    echo "  #              Starting update changelogs                         #"
    echo "  #                                                                 #"
    echo "  ###################################################################"
    echo "${NORMAL}"
    distro_detection
    case ${OS_ID} in
        "\"centos\"" | "centos" | "\"rhel\"" | "rhel" | "\"redhat\"" | "redhat" | "\"bclinux\"" | "bclinux" |"\"BCLinux\"" | "BCLinux")
            case ${OS_DISTRO} in
                "\"6\"" | "6")
                Update_changelog_from_to "mirrors.bclinux.org/centos/6/updates/x86_64/Packages/" "rhel-6"
                ;;
                "\"7\"" | "7")
                Update_changelog_from_to "mirrors.bclinux.org/centos/7/updates/x86_64/Packages/" "rhel-7"
                ;;
                *)
                logtext "Detected this system is  ${OS_ID}-${OS_DISTRO}, we dont support this yet"
                Display --indent 2 --text "- unsupported system detected... " --result WARNING --color RED
                ;;
            esac
        ;;
        *)
        logtext "Detected this system is  ${OS_ID}-${OS_DISTRO}, we dont support this yet"
        Display --indent 2 --text "- unsupported system detected... " --result WARNING --color RED
        ;;
    esac
}



################################################################################
# Name        : bc_update_cve_db()
# Description : automatic download nvd.db from mirrors.bclinux.org
# Returns     : <nothing>
################################################################################
bc_update_cve_db()
{
    echo "${WHITE}"
    echo "  ###################################################################"
    echo "  #                                                                 #"
    echo "  #              Starting update cve database                       #"
    echo "  #                                                                 #"
    echo "  ###################################################################"
    echo "${NORMAL}"

    cve_db_source_uri="http://mirrors.bclinux.org/security/data/metrics"
    new_cve_db_name=nvd.db.download.$(date +"%Y%m%d")
    bak_cve_db_name=nvd.db.bakup.$(date +"%Y%m%d")
    logtext "Downloading CVE db form ${cve_db_source_uri}"
    echo "  Updating cve database..."
    curl -sf --max-time 10 ${cve_db_source_uri}/nvd.db > ${rundir}/db/$new_cve_db_name
    if [ $? -ne 0 ];then
        logtext "can't download ${cve_db_source_uri}/nvd.db, maybe the url or network errors."
        Display --indent 2 --text "Can't download form ${cve_db_source_uri}, maybe the url or network errors" --result WARNING --color RED
    else
        mv  ${rundir}/db/nvd.db ${rundir}/db/$bak_cve_db_name  #bakup old cve db file
        mv  ${rundir}/db/$new_cve_db_name  ${rundir}/db/nvd.db #rename new cve db file
        logtext "Successfully update changelogs of $i"
        Display --indent 2 --text "Successfully update cve database." --result FINISHED --color GREEN
    fi

}