mirror of
https://github.com/jtesta/ssh-audit.git
synced 2024-12-22 14:05:22 +01:00
Colour no longer disabled on older vers of Windows. If ssh-audit invoked with a manual parameter and the colorama library was not imported then colour output is disabled. (#95)
This commit is contained in:
parent
1b7cfbec71
commit
8a8c284d9a
@ -1024,13 +1024,7 @@ def main() -> int:
|
||||
|
||||
# If we're on Windows, but the colorama module could not be imported, print a warning if we're in verbose mode.
|
||||
if (sys.platform == 'win32') and ('colorama' not in sys.modules):
|
||||
out.v("WARNING: colorama module not found. Colorized output will be ddisabled.", write_now=True)
|
||||
|
||||
# Disable color output on Windiows 8 and Windows Server 2012, as they are still supported by Microsoft (until Jan. 2023 and Oct. 2023, respectively); they do not support ANSI color codes. According to https://docs.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version, the major versions of Server 2016, Server 2019, and Windows 10 are all 10.
|
||||
if (sys.platform == 'win32') and (sys.getwindowsversion().major < 10): # pylint: disable=no-member
|
||||
aconf.colors = False
|
||||
out.use_colors = False
|
||||
out.v("Disabling color output on this platform since it is not supported (Windows major version: %d)." % sys.getwindowsversion().major) # pylint: disable=no-member
|
||||
out.v("WARNING: colorama module not found. Colorized output will be disabled.", write_now=True)
|
||||
|
||||
# If we're outputting JSON, turn off colors and ensure 'info' level messages go through.
|
||||
if aconf.json:
|
||||
@ -1038,6 +1032,10 @@ def main() -> int:
|
||||
out.use_colors = False
|
||||
|
||||
if aconf.manual:
|
||||
# If the colorama module was not be imported, turn off colors in order
|
||||
# to output a plain text version of the man page.
|
||||
if (sys.platform == 'win32') and ('colorama' not in sys.modules):
|
||||
out.use_colors = False
|
||||
retval = windows_manual(out)
|
||||
out.write()
|
||||
sys.exit(retval)
|
||||
|
@ -1,4 +1,4 @@
|
||||
.TH SSH-AUDIT 1 "October 19, 2020"
|
||||
.TH SSH-AUDIT 1 "February 7, 2021"
|
||||
.SH NAME
|
||||
\fBssh-audit\fP \- SSH server & client configuration auditor
|
||||
.SH SYNOPSIS
|
||||
|
@ -52,13 +52,18 @@ function usage {
|
||||
echo >&2 " -h This help message"
|
||||
}
|
||||
|
||||
if [[ $(uname -s) != CYGWIN* ]]; then
|
||||
echo >&2 "This script is designed to be run under Cygwin only. It can potentially be extended to run under Linux, but this is not supported at this time."
|
||||
exit -1
|
||||
fi
|
||||
PLATFORM="$(uname -s)"
|
||||
|
||||
MAN_PAGE=ssh-audit.1
|
||||
GLOBALS_PY=src/ssh_audit/globals.py
|
||||
# This script is intended for use on Linux and Cygwin only.
|
||||
case "$PLATFORM" in
|
||||
Linux | CYGWIN*) ;;
|
||||
*) echo "Platform not supported: $PLATFORM"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
MAN_PAGE=./ssh-audit.1
|
||||
GLOBALS_PY=./src/ssh_audit/globals.py
|
||||
|
||||
while getopts "m: g: h" OPTION
|
||||
do
|
||||
@ -85,8 +90,10 @@ done
|
||||
[ -f "$MAN_PAGE" ] || { echo >&2 "man page file not found: $MAN_PAGE"; exit 1; }
|
||||
[ -f "$GLOBALS_PY" ] || { echo >&2 "globals.py file not found: $GLOBALS_PY"; exit 1; }
|
||||
|
||||
# Check that the 'ul' (do underlining) binary exists. (Commented out since Cygwin's man outputs ANSI escape codes automatically; re-enable if running under Linux.)
|
||||
# command -v ul >/dev/null 2>&1 || { echo >&2 "ul not found."; exit 1; }
|
||||
# Check that the 'ul' (do underlining) binary exists.
|
||||
if [[ "$PLATFORM" = Linux ]]; then
|
||||
command -v ul >/dev/null 2>&1 || { echo >&2 "ul not found."; exit 1; }
|
||||
fi
|
||||
|
||||
# Check that the 'sed' (stream editor) binary exists.
|
||||
command -v sed >/dev/null 2>&1 || { echo >&2 "sed not found."; exit 1; }
|
||||
@ -101,13 +108,20 @@ echo "Processing man page at ${MAN_PAGE} and placing output into ${GLOBALS_PY}..
|
||||
# sequence.
|
||||
# * 'MAN_KEEP_FORMATTING' preserves the backspace-overwrite sequence when
|
||||
# redirected to a file or a pipe.
|
||||
# * The 'ul' command converts the backspace-overwrite sequence to an ANSI escape
|
||||
# sequence.
|
||||
# * sed converts unicode hyphens into an ASCI equivalent.
|
||||
# * The 'ul' command converts the backspace-overwrite sequence to an ANSI
|
||||
# escape sequence. Not required under Cygwin because man outputs ANSI escape
|
||||
# codes automatically.
|
||||
|
||||
echo WINDOWS_MAN_PAGE = '"""' >> "$GLOBALS_PY"
|
||||
# The 'ul' tool would be necessary if running under Linux to convert the overstrike characters into ANSI escape sequences.
|
||||
# MANWIDTH=80 MAN_KEEP_FORMATTING=1 man "$MAN_PAGE" | ul >> "$GLOBALS_PY"
|
||||
MANWIDTH=80 MAN_KEEP_FORMATTING=1 man "./$MAN_PAGE" | sed $'s/\u2010/-/g' >> "$GLOBALS_PY"
|
||||
|
||||
if [[ "$PLATFORM" = CYGWIN* ]]; then
|
||||
MANWIDTH=80 MAN_KEEP_FORMATTING=1 man "$MAN_PAGE" | sed $'s/\u2010/-/g' >> "$GLOBALS_PY"
|
||||
else
|
||||
MANWIDTH=80 MAN_KEEP_FORMATTING=1 man "$MAN_PAGE" | ul | sed $'s/\u2010/-/g' >> "$GLOBALS_PY"
|
||||
fi
|
||||
|
||||
echo '"""' >> "$GLOBALS_PY"
|
||||
|
||||
echo "Done."
|
||||
exit 0
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user