mirror of
				https://github.com/jtesta/ssh-audit.git
				synced 2025-11-04 03:02:15 +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:
		@@ -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 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):
 | 
					    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)
 | 
					        out.v("WARNING: colorama module not found.  Colorized output will be disabled.", 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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # If we're outputting JSON, turn off colors and ensure 'info' level messages go through.
 | 
					    # If we're outputting JSON, turn off colors and ensure 'info' level messages go through.
 | 
				
			||||||
    if aconf.json:
 | 
					    if aconf.json:
 | 
				
			||||||
@@ -1038,6 +1032,10 @@ def main() -> int:
 | 
				
			|||||||
        out.use_colors = False
 | 
					        out.use_colors = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if aconf.manual:
 | 
					    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)
 | 
					        retval = windows_manual(out)
 | 
				
			||||||
        out.write()
 | 
					        out.write()
 | 
				
			||||||
        sys.exit(retval)
 | 
					        sys.exit(retval)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
.TH SSH-AUDIT 1 "October 19, 2020"
 | 
					.TH SSH-AUDIT 1 "February 7, 2021"
 | 
				
			||||||
.SH NAME
 | 
					.SH NAME
 | 
				
			||||||
\fBssh-audit\fP \- SSH server & client configuration auditor
 | 
					\fBssh-audit\fP \- SSH server & client configuration auditor
 | 
				
			||||||
.SH SYNOPSIS
 | 
					.SH SYNOPSIS
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -52,13 +52,18 @@ function usage {
 | 
				
			|||||||
    echo >&2 "  -h    This help message"
 | 
					    echo >&2 "  -h    This help message"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ $(uname -s) != CYGWIN* ]]; then
 | 
					PLATFORM="$(uname -s)"
 | 
				
			||||||
    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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
MAN_PAGE=ssh-audit.1
 | 
					# This script is intended for use on Linux and Cygwin only.
 | 
				
			||||||
GLOBALS_PY=src/ssh_audit/globals.py
 | 
					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
 | 
					while getopts "m: g: h" OPTION
 | 
				
			||||||
do
 | 
					do
 | 
				
			||||||
@@ -85,8 +90,10 @@ done
 | 
				
			|||||||
[ -f "$MAN_PAGE" ] || { echo >&2 "man page file not found: $MAN_PAGE"; exit 1; }
 | 
					[ -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; }
 | 
					[ -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.)
 | 
					# Check that the 'ul' (do underlining) binary exists.
 | 
				
			||||||
# command -v ul >/dev/null 2>&1 || { echo >&2 "ul not found."; exit 1; }
 | 
					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.
 | 
					# Check that the 'sed' (stream editor) binary exists.
 | 
				
			||||||
command -v sed >/dev/null 2>&1 || { echo >&2 "sed not found."; exit 1; }
 | 
					command -v sed >/dev/null 2>&1 || { echo >&2 "sed not found."; exit 1; }
 | 
				
			||||||
@@ -101,12 +108,19 @@ echo "Processing man page at ${MAN_PAGE} and placing output into ${GLOBALS_PY}..
 | 
				
			|||||||
#     sequence.
 | 
					#     sequence.
 | 
				
			||||||
#   * 'MAN_KEEP_FORMATTING' preserves the backspace-overwrite sequence when 
 | 
					#   * 'MAN_KEEP_FORMATTING' preserves the backspace-overwrite sequence when 
 | 
				
			||||||
#     redirected to a file or a pipe.
 | 
					#     redirected to a file or a pipe.
 | 
				
			||||||
#   * The 'ul' command converts the backspace-overwrite sequence to an ANSI escape 
 | 
					#   * sed converts unicode hyphens into an ASCI equivalent.
 | 
				
			||||||
#     sequence.
 | 
					#   * 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"
 | 
					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"
 | 
					if [[ "$PLATFORM" = CYGWIN* ]]; then
 | 
				
			||||||
MANWIDTH=80 MAN_KEEP_FORMATTING=1 man "./$MAN_PAGE" | sed $'s/\u2010/-/g' >> "$GLOBALS_PY"
 | 
						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 '"""' >> "$GLOBALS_PY"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
echo "Done."
 | 
					echo "Done."
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user