From 13c228fd2d4a4e90df1b0331532b35333e7446de Mon Sep 17 00:00:00 2001 From: Michael Boelen Date: Tue, 5 Jul 2016 19:57:11 +0200 Subject: [PATCH] Add --configured-only option to lynis show settings --- include/helper_show | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/include/helper_show b/include/helper_show index 74ece537..5aed1ba4 100644 --- a/include/helper_show +++ b/include/helper_show @@ -96,7 +96,7 @@ UPDATE_HELP=" " -SHOW_SETTINGS_ARGS="--brief --nocolors" +SHOW_SETTINGS_ARGS="--brief --configured-only --nocolors" SHOW_TESTS_ARGS="skipped" COMMANDS_AUDIT_SYSTEM_USAGE="Usage: lynis audit system" @@ -181,11 +181,14 @@ if [ $# -gt 0 ]; then "releasedate") ${ECHOCMD} "${PROGRAM_RELEASE_DATE}" ;; "settings") BRIEF_OUTPUT=0 + COLORED_OUTPUT=1 + CONFIGURED_ONLY_OUTPUT=0 while [ $# -gt 1 ]; do shift case $1 in - "--brief") BRIEF_OUTPUT=1 ;; - "--nocolors") GRAY=""; WHITE=""; CYAN="" ;; + "--brief" | "--br") BRIEF_OUTPUT=1 ;; + "--configured-only" | "--co") CONFIGURED_ONLY_OUTPUT=1 ;; + "--nocolors" | "--nc") COLORED_OUTPUT=0 ;; *) ${ECHOCMD} "${RED}Error${NORMAL}: Invalid argument provided to 'lynis show settings'\n\n" ${ECHOCMD} "Suggestions:" @@ -194,6 +197,7 @@ if [ $# -gt 0 ]; then ;; esac done + if [ ${COLORED_OUTPUT} -eq 0 ]; then BLUE=""; CYAN=""; GRAY=""; WHITE=""; fi # Sort all settings and display them SETTINGS=$(sort ${SETTINGS_FILE} | sed 's/ /:space:/g') for LINE in ${SETTINGS}; do @@ -202,14 +206,20 @@ if [ $# -gt 0 ]; then DESCRIPTION=$(echo ${LINE} | awk -F';' '{print $3}' | sed 's/:space:/ /g') LINESIZE=$(echo "${SETTING}=${VALUE}" | wc -m | tr -d ' ') SPACES=$((60 - ${LINESIZE})) - # Only show configured settings + if [ -z "${VALUE}" -a ${CONFIGURED_ONLY_OUTPUT} -eq 0 ]; then VALUE="${GRAY}[not configured]${NORMAL}"; fi if [ ! -z "${VALUE}" ]; then if [ ${BRIEF_OUTPUT} -eq 0 ]; then ${ECHOCMD} "${GRAY}# ${DESCRIPTION}${NORMAL}"; fi ${ECHOCMD} "${WHITE}${SETTING}${NORMAL}=${CYAN}${VALUE}${NORMAL}" if [ ${BRIEF_OUTPUT} -eq 0 ]; then ${ECHOCMD} ""; fi fi done - if [ ${BRIEF_OUTPUT} -eq 0 ]; then DisplayToolTip "add --brief to show just the settings, --nocolors to remove colors"; fi + if [ ${BRIEF_OUTPUT} -eq 0 -a ${CONFIGURED_ONLY_OUTPUT} -eq 0 -a ${COLORED_OUTPUT} -eq 1 ]; then + if [ ${COLORS} -eq 1 ]; then + DisplayToolTip "Add --brief to hide descriptions, --configured-only to show configured items only, or --nocolors to remove colors" + else + DisplayToolTip "Add --brief to hide descriptions, --configured-only to show configured items only" + fi + fi ;; "tests")