#!/bin/cat
#? NAME
#? filter_examples - examples for formatting o-saft.pl's output
#?
#? DESCRIPTION
#? This file contains examples for more sophisticated convertions of
#? o-saft.pl's output.
#? All examples should work just by copy&paste.
#?
#? LIMITATIONS
#? Some of the provided filter scripts are awk scripts. They most likely
#? require Gnu awk (or compatible) instead of the traditional AT&T awk.
#?
#? Depending on the operating system and/or it's configuration, the awk
#? scripts need to be used like:
#? gawk -f usr/script
#? instead of (as shown in our examples):
#? usr/script
#?
#? VERSION
#? @(#) %M% %I% %E% %U%
#?
#? AUTHOR
#? 24-jan24 Achim Hoffmann
###############################################################################
###
### Using filters (overview)
###
o-saft.pl +cipher localhost | usr/bunt.pl
o-saft.pl +info localhost | usr/HTML-simple.awk
o-saft.pl +check localhost | usr/HTML-table.awk
o-saft.pl +info localhost --showkey --tab | usr/JSON-array.awk
o-saft.pl +info localhost --showkey --tab | usr/JSON-struct.awk
o-saft.pl +check localhost --showkey --tab | usr/JSON-array.awk
o-saft.pl +info localhost | usr/XML-value.awk
o-saft.pl +check localhost | usr/XML-attribute.awk
###############################################################################
###
### CSV convertions
###
### +info output: separate label and value, one per line
o-saft.pl +info --legacy=quick localhost \
| gawk -F'\t' '/^\s*$/{next}($1~/^[#=]/){next}{print $1","$2}'
# or
o-saft.pl +info localhost --legacy=compact --no-header --sep=,
###############################################################################
###
### HTML convertions
###
### +info output: label and value per line (full html)
o-saft.pl +info localhost | usr/HTML-simple.awk
# or
o-saft.pl +info --legacy=quick localhost \
| gawk 'BEGIN{FS="\t";print "
"}(NF>0){gsub(/&/,"\\&");gsub(/"/,"\\"");gsub(/,"\\<");gsub(/>/,"\\>");}/^\s*$/{next}($1~/^[#=]/){print "";next}{print " "$1" | "$2" |
"}END{print "
"}'
### +info output: label and value per line (html table lines only)
o-saft.pl +info --legacy=quick localhost \
| gawk -F'\t' '/^\s*$/{next}(NF>0){gsub(/&/,"\\&");gsub(/,"\\<");gsub(/>/,"\\>");}($1~/^[#=]/){print "";next}{print " "$1" | "$2" |
"}'
### +check output: label and value in table; header lines
o-saft.pl +check localhost | usr/HTML-table.awk
# or
o-saft.pl +check --legacy=quick localhost \
| gawk 'BEGIN{FS="\t";print ""}(NF>0){gsub(/&/,"\\&");gsub(/,"\\<");gsub(/>/,"\\>");}/^\s*$/{next}($1~/ reading /){next;}($1~/^===/ && $NF~/===/){printf("
%s
\n",$0);next}($1~/^== /){print ""$0" |
";next;}($1~/^[#=]/){print "";next}{print " "$1" | "$2" |
"}END{print "
"}'
###############################################################################
###
### JSON convertions
###
### +info output: label and value per line in JSON style array
o-saft.pl +info --legacy=quick localhost \
| gawk 'BEGIN{FS="\t";print "info=["}(NF>0){gsub(/\\/,"&&");gsub(/"/,"\\\"");}/^\s*$/{next}($1~/^[#=]/){print "// "$0;next}{printf(" \"%s\": \"%s\",\n",$1,$NF)}END{print " dumm:\"dumm\"\n];"}'
o-saft.pl +info --showkey --tab localhost | usr/JSON-array.awk
o-saft.pl +info --showkey --tab localhost | usr/JSON-struct.awk
###############################################################################
###
### XML convertions
###
### +info output: label and value per line
o-saft.pl +info localhost | usr/XML-value.awk
# or
o-saft.pl +info --legacy=quick localhost \
| gawk 'BEGIN{FS="\t";print ""}(NF>0){gsub(/&/,"\\&");gsub(/,"\\<");gsub(/>/,"\\>");}/^\s*$/{next}($1~/^[#=]/){print "";next}{print " \n \n "$2"\n "}END{print ""}'
### +info output: one line per label and value
o-saft.pl +info localhost \
| gawk 'BEGIN{FS="\t";print ""}(NF>0){gsub(/&/,"\\&");gsub(/,"\\<");gsub(/>/,"\\>");}/^\s*$/{next}($1~/^[#=]/){print "";next}{print " "$2""}END{print ""}'
# same as before a bit more compact
o-saft.pl +info --legacy=quick localhost \
| gawk 'BEGIN{FS="\t";print ""}(NF>0){gsub(/&/,"\\&");gsub(/,"\\<");gsub(/>/,"\\>");}/^\s*$/{next}($1~/^[#=]/){next}{print ""$2""}END{print ""}'
### +info output: one line per label and value as attribute
o-saft.pl +info localhost | usr/XML-attribute.awk
# or
o-saft.pl +info --legacy=quick localhost \
| gawk 'BEGIN{FS="\t";print ""}(NF>0){gsub(/&/,"\\&");gsub(/"/,"\\"");gsub(/,"\\<");gsub(/>/,"\\>");}/^\s*$/{next}($1~/^[#=]/){print "";next}{i++;printf(" \n",i,$1,$2);}END{print ""}'
###############################################################################
###
### Parsable SSL protocol in output
###
### +cipher output: cipher lines with SSL protocol version
o-saft.pl +cipher localhost --header --legacy=sslaudit
o-saft.pl +cipher localhost --header --legacy=ssldiagnose
o-saft.pl +cipher localhost --header --legacy=full
### +cipher output: all lines are prefixed with SSL protocol version
o-saft.pl +cipher localhost --header --legacy=quick \
| awk '/^=== Ciphers:/{p=$(NF-1)}/^/{printf"%s\t%s\n",p,$0;}'
### +cipher output: all lines are prefixed with SSL protocol version, no headers
o-saft.pl +cipher localhost --header --legacy=quick \
| awk '/^=== Ciphers:/{p=$(NF-1)}/^=/{next}/^/{printf"%s\t%s\n",p,$0;}'