debian-cis/lib/common.sh

58 lines
1.0 KiB
Bash
Raw Normal View History

# CIS Debian 7 Hardening common functions
2016-04-01 16:48:31 +02:00
# Logging functions
case $LOGLEVEL in
error )
MACHINE_LOG_LEVEL=1
;;
warning )
MACHINE_LOG_LEVEL=2
;;
2016-04-04 11:23:03 +02:00
ok )
2016-04-01 16:48:31 +02:00
MACHINE_LOG_LEVEL=3
;;
2016-04-04 11:23:03 +02:00
info )
2016-04-01 16:48:31 +02:00
MACHINE_LOG_LEVEL=4
;;
2016-04-04 11:23:03 +02:00
debug )
MACHINE_LOG_LEVEL=5
;;
2016-04-01 16:48:31 +02:00
*)
2016-04-04 11:23:03 +02:00
MACHINE_LOG_LEVEL=4 ## Default loglevel value to info
2016-04-01 16:48:31 +02:00
esac
_logger() {
COLOR=$1
shift
test -z "$SCRIPT_NAME" && SCRIPT_NAME=$(basename $0)
2016-04-01 16:48:31 +02:00
/usr/bin/logger -t "[CIS_Hardening] $SCRIPT_NAME" -p "user.info" "$*"
test -t 1 && cecho $COLOR "$SCRIPT_NAME $*"
}
cecho () {
COLOR=$1
shift
echo -e "${COLOR}$*${NC}"
}
2016-04-04 11:23:03 +02:00
crit () {
[ $MACHINE_LOG_LEVEL -ge 1 ] && _logger $BRED "[ KO ] $*"
2016-04-01 16:48:31 +02:00
}
warn () {
[ $MACHINE_LOG_LEVEL -ge 2 ] && _logger $BYELLOW "[WARN] $*"
}
2016-04-04 11:23:03 +02:00
ok () {
[ $MACHINE_LOG_LEVEL -ge 3 ] && _logger $BGREEN "[ OK ] $*"
}
info () {
[ $MACHINE_LOG_LEVEL -ge 4 ] && _logger $BWHITE "[INFO] $*"
2016-04-01 16:48:31 +02:00
}
debug () {
2016-04-04 11:23:03 +02:00
[ $MACHINE_LOG_LEVEL -ge 5 ] && _logger $GRAY "[DBG ] $*"
}