File: //opt/BCLinux/bse/include/parameters
#!/bin/sh
#################################################################################
#
# BCLinux
# ------------------
#
# BCLinux comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
# welcome to redistribute it under the terms of the GNU General Public License.
# See LICENSE file for usage of this software.
#
#################################################################################
#
# Parameter checks
#
#################################################################################
#
# Check number of parameters submitted (at least one is needed)
PARAMCOUNT=$#
while [ $# -ge 1 ]; do
case $1 in
####################################################################
# Helpers first
check)
CHECK_BINARIES=0
RUN_HELPERS=1
HELPER="audit"
RUN_PLUGINS=0
RUN_TESTS=0
if [ ! $2 = "" ]; then
case $2 in
"basic")
CHECK_BINARIES=1
HELPER=""
RUN_PLUGINS=1
CHECK_SYSTEM=1 #do basic check
CHECK_ADVANCE=0
CHECK_ROOTKIT=0
shift
;;
"adv" | "advance")
CHECK_BINARIES=1
HELPER=""
RUN_PLUGINS=1
CHECK_SYSTEM=0
CHECK_ADVANCE=1 #do adv check
CHECK_ROOTKIT=0
shift
;;
"rootkit")
CHECK_BINARIES=1
HELPER=""
RUN_PLUGINS=1
CHECK_SYSTEM=0
CHECK_ADVANCE=0
CHECK_ROOTKIT=1 #do rootkit check
shift
;;
*)
echo " "
echo "${RED}Error: ${WHITE}Can't find $2, wrong target to check${NORMAL}"
echo "Examples:"
echo "$0 check [option]"
echo "option can be: basic or adv|advance or rootkit"
echo " "
ExitFatal
;;
esac
else
echo "${RED}Error: ${WHITE}Need a target to check${NORMAL}"
echo " "
echo "Examples:"
#echo "$0 audit dockerfile"
echo "$0 check basic"
echo "$0 check adv|advance"
echo "$0 check rootkit"
echo " "
ExitFatal
fi
#break
;;
####################################################################
# Helpers first
fix)
CHECK_BINARIES=0
#RUN_HELPERS=1
#HELPER="fix"
HELPER=""
RUN_PLUGINS=0
RUN_TESTS=0
if [ ! $2 = "" ]; then
case $2 in
"basic")
FIX_SYSTEM=1 #do basic fix
RUN_TESTS=0
shift
;;
"advance"|"adv")
FIX_SYSTEM=0
RUN_TESTS=0
FIX_ADVANCE=1
if [ ! $3 = "" ]; then
case $3 in
"-y" | "--yes")
#auto adv fix without human interactive
AUTO_ADV_FIX=1
shift
;;
*)
;;#do nothing
esac
fi
shift
;;
*)
FIX_SYSTEM=0 #not do basic fix
RUN_TESTS=0
FIX_ADVANCE=0 #no advance fix
TMP=`find option_set -type f| cut -d '/' -f 2 |cut -d '_' -f 2`
if [[ `find option_set -type f | grep -i $2 |wc -l` -eq 0 ]];then
echo "${RED}Error: ${WHITE}Can't find $2, wrong target to fix${NORMAL}"
echo " "
echo "Examples:"
echo "$0 fix items"
echo "Items can be: ${TMP}"
echo " "
ExitFatal
else
FIX_ITEMS=$2 #do specify fix items
FIX_SPECIFY_ITEMS=1
shift
fi
;;
esac
else
echo "${RED}Error: ${WHITE}Need a target to fix${NORMAL}"
echo " "
echo "Examples:"
echo "$0 fix basic"
echo "$0 fix adv|advance"
echo "$0 fix <items> , items=addUser, filterIP and etc."
echo " "
ExitFatal
fi
#break
;;
####################################################################
# Helpers first
restore)
CHECK_BINARIES=0
HELPER=""
RUN_PLUGINS=0
RUN_TESTS=0
if [ ! $2 = "" ]; then
case $2 in
"basic")
RESTORE_SYSTEM=1 #do basic restore
RUN_TESTS=0
RESTORE_ADVANCE=0
if [ ! $3 = "" ]; then
case $3 in
"-y" | "--yes")
#auto basic restore without human interactive
AUTO_BASIC_RESTORE=1
shift
;;
*)
;;#do nothing
esac
fi
shift
;;
"advance"|"adv")
RESOTRE_SYSTEM=0
RUN_TESTS=0
RESTORE_ADVANCE=1 #do advance restore
if [ ! $3 = "" ]; then
case $3 in
"-y" | "--yes")
#auto adv restore without human interactive
AUTO_ADV_RESTORE=1
shift
;;
*)
;;#do nothing
esac
fi
shift
;;
*)
RESTORE_SYSTEM=0 #not do basic restore
RUN_TESTS=0
RESTORE_ADVANCE=0 #no advance restore
echo "${RED}Error: ${WHITE}Need a target to restore${NORMAL}"
echo " "
echo "Examples:"
echo "$0 restore basic"
echo "$0 restore adv|advance"
echo " "
ExitFatal
;;
esac
else
echo "${RED}Error: ${WHITE}Need a target to restore${NORMAL}"
echo " "
echo "Examples:"
echo "$0 restore basic"
echo "$0 restore adv|advance"
echo " "
ExitFatal
fi
#break
;;
####################################################################
# Helpers first
auto)
CHECK_BINARIES=0
#RUN_HELPERS=1
HELPER=""
RUN_PLUGINS=0
RUN_TESTS=0
AUTOFIX_SYSTEM=1
FIX_SYSTEM=0
;;
####################################################################
# Helpers first
update)
CHECK_BINARIES=0
RUN_HELPERS=1
HELPER="update"
RUN_PLUGINS=0
RUN_TESTS=0
SHOW_PROGRAM_DETAILS=0
UPDATE_CHANGELOG=0
UPDATE_INFO=0
if [ ! $2 = "" ]; then
case $2 in
"info")
UPDATE_INFO=1
shift
;;
"database")
UPDATE_CHANGELOG=1
shift
;;
*)
UPDATE_CHANGELOG=0
UPDATE_INFO=0
echo "${RED}Error: ${WHITE}Wrong params for update${NORMAL}"
echo " "
echo "Examples:"
echo "$0 update info"
echo "$0 update database"
echo " "
ExitFatal
;;
esac
else
echo "${RED}Error: ${WHITE}Need a target for update${NORMAL}"
echo " "
echo "Examples:"
echo "$0 update info"
echo "$0 update database"
echo " "
ExitFatal
fi
;;
####################################################################
# Assign auditor to report
--auditor)
shift
AUDITORNAME=$1
;;
####################################################################
# Perform tests
-c | --check-all | --checkall)
CHECK=1
;;
####################################################################
# Show settings file
--config)
SHOW_SETTINGS_FILE=1
;;
####################################################################
# Cronjob support
--cronjob | --cron)
CRONJOB=1;
# Use some defaults (-c, -Q, no colors)
CHECK=1; QUICKMODE=1; NEVERBREAK=1
# Get rid of the colors
NORMAL=""; WARNING=""; SECTION=""; NOTICE=""; OK=""; BAD=""; CYAN=""; MAGENTA=""; PURPLE=""; YELLOW=""; WHITE=""; GREEN=""; RED=""
;;
####################################################################
# Perform tests with additional debugging information on screen
--debug)
DEBUG=1
;;
####################################################################
# Display all available options with short alias
--dump-options | --dumpoptions)
OPTIONS="--auditor
--check-all_(-c) --config --cronjob_(--cron)
--debug
--help_(-h)
--info
--license-key --log-file
--manpage_(--man)
--no-colors --no-log
--pentest --profile --plugins-dir
--quiet_(-q) --quick_(-Q)
--report-file --reverse-colors
--tests --tests-category
--upload
--version_(-V) --view-categories"
for I in ${OPTIONS}; do
echo "${I}" | tr '_' ' '
done
ExitClean
;;
####################################################################
# View help
--help | -h)
VIEWHELP=1
;;
####################################################################
# View program/database information
--check-update | --check-updates | --info)
echo "This option is deprecated"
echo "Use: $0 update info"
echo " "
ExitClean
;;
####################################################################
# License key for BCLinux Enterprise
--license-key)
shift
LICENSE_KEY=$1
;;
####################################################################
# Adjust default logfile location
--logfile | --log-file)
shift
LOGFILE=$1
;;
####################################################################
# Don't use colors
--no-colors | --nocolors)
NORMAL=""; WARNING=""; SECTION=""; NOTICE=""; OK=""; BAD=""; CYAN=""; MAGENTA=""; PURPLE=""; YELLOW=""; WHITE=""; GREEN=""; RED=""
;;
####################################################################
# Disable logging
--no-log | --nolog)
LOGFILE="/dev/null"
;;
####################################################################
--pentest | --pen-test)
PENTESTINGMODE=1
;;
####################################################################
# Define a custom profile file
--profile)
shift
PROFILE=$1
;;
####################################################################
# Define a custom plugin directory
--plugin-dir | --plugins-dir)
shift
PLUGINDIR=$1
LASTCHAR=`echo $1 | awk '{ print substr($0, length($0))}'`
if [ "${LASTCHAR}" = "/" ]; then
echo "${RED}Error:${WHITE} plugin directory path should not end with a slash${NORMAL}"
ExitCustom 65
fi
if [ ! -d ${PLUGINDIR} ]; then
echo "${RED}Error:${WHITE} invalid plugin directory ${PLUGINDIR}${NORMAL}"
ExitCustom 66
fi
;;
####################################################################
# Quiet mode
-q | --quiet)
QUIET=1
# Run non-interactive
QUICKMODE=1
;;
####################################################################
# Non-interactive mode
-Q | --quick)
QUICKMODE=1
;;
####################################################################
# Define alternative report file
--report-file)
shift
REPORTFILE=$1
;;
####################################################################
# Strip the colors which aren't clearly visible on light backgrounds
--reverse-colors)
#NORMAL="";
SECTION="${NORMAL}";
NOTICE="${NORMAL}";
#OK="";
#BAD="";
CYAN="${NORMAL}";
GREEN="${NORMAL}";
YELLOW="${NORMAL}";
WHITE="${NORMAL}";
PURPLE="${NORMAL}";
#GREEN="";
#RED=""
;;
####################################################################
# Only scan these tests
--tests)
shift
TESTS_TO_PERFORM=$1
;;
####################################################################
# Scan one or more categories only
--tests-category)
shift
TESTS_CATEGORY_TO_PERFORM=$1
;;
####################################################################
# Update changelog
--update-changelog)
UPDATE_CHANGELOG=1
#update_changelog_from_to "mirrors.bclinux.org/centos/7/updates/x86_64/Packages/" "rhel-7"
;;
####################################################################
# BCLinux Enterprise: upload data to central node
--upload)
UPLOAD_DATA=1
;;
####################################################################
# Version number
-V | --version)
echo "${PROGRAM_version}"
exit 0
;;
####################################################################
--view-categories | --list-categories | --show-categories)
ViewCategories
exit 0
;;
## View man page
#--view-manpage | --man | --manpage)
# if [ -f bclinux.8 ]; then
# nroff -man bclinux.8
# exit 0
# else
# echo "Error: man page file not found (bclinux.8)"
# echo "If you are running an installed version of ${PROGRAM_name}, use 'man ${PROGRAM_name}'"
# exit 1
# fi
#;;
# Drop out when using wrong option(s)
*)
# Wrong option used, we bail out later
WRONGOPTION=1
WRONGOPTION_value=$1
;;
esac
shift
done
#================================================================================
# BCLinux - Copyright 2007-2016