Debian Codegraph @

contrib/filter_examples

raw
1 #!/bin/cat
2
3 #? NAME
4 #? filter_examples - examples for formatting o-saft.pl's output
5 #?
6 #? DESCRIPTION
7 #? This file contains examples for more sophisticated convertions of
8 #? o-saft.pl's output.
9 #? All examples should work just by copy&paste.
10 #?
11 #? LIMITATIONS
12 #? Some of the provided filter scripts are awk scripts. They most likely
13 #? require Gnu awk (or compatible) instead of the traditional AT&T awk.
14 #?
15 #? Depending on the operating system and/or it's configuration, the awk
16 #? scripts need to be used like:
17 #? gawk -f contrib/script
18 #? instead of (as shown in our examples):
19 #? contrib/script
20 #?
21
22 ###############################################################################
23 ###
24 ### Using filters (overview)
25 ###
26
27 o-saft.pl +cipher localhost | contrib/bunt.pl
28 o-saft.pl +info localhost | contrib/HTML-simple.awk
29 o-saft.pl +check localhost | contrib/HTML-table.awk
30 o-saft.pl +info localhost --tracekey --tab | contrib/JSON-array.awk
31 o-saft.pl +info localhost --tracekey --tab | contrib/JSON-struct.awk
32 o-saft.pl +check localhost --tracekey --tab | contrib/JSON-array.awk
33 o-saft.pl +info localhost | contrib/XML-value.awk
34 o-saft.pl +check localhost | contrib/XML-attribute.awk
35
36
37 ###############################################################################
38 ###
39 ### CSV convertions
40 ###
41
42 ### +info output: separate label and value, one per line
43
44 o-saft.pl +info --legacy=quick localhost \
45 | gawk -F'\t' '/^\s*$/{next}($1~/^[#=]/){next}{print $1","$2}'
46
47 # or
48
49 o-saft.pl +info localhost --legacy=compact --no-header --sep=,
50
51
52 ###############################################################################
53 ###
54 ### HTML convertions
55 ###
56
57 ### +info output: label and value per line (full html)
58
59 o-saft.pl +info localhost | contrib/HTML-simple.awk
60
61 # or
62
63 o-saft.pl +info --legacy=quick localhost \
64 | gawk 'BEGIN{FS="\t";print "<html><body><table>"}(NF>0){gsub(/&/,"\\&amp;");gsub(/"/,"\\&quot;");gsub(/</,"\\&lt;");gsub(/>/,"\\&gt;");}/^\s*$/{next}($1~/^[#=]/){print "<! "$0" -->";next}{print " <tr><th>"$1"</th><td>"$2"</td></tr>"}END{print "</table></body></html>"}'
65
66 ### +info output: label and value per line (html table lines only)
67
68 o-saft.pl +info --legacy=quick localhost \
69 | gawk -F'\t' '/^\s*$/{next}(NF>0){gsub(/&/,"\\&amp;");gsub(/</,"\\&lt;");gsub(/>/,"\\&gt;");}($1~/^[#=]/){print "<! "$0" -->";next}{print " <tr><th>"$1"</th><td>"$2"</td></tr>"}'
70
71 ### +check output: label and value in table; header lines
72
73 o-saft.pl +check localhost | contrib/HTML-table.awk
74
75 # or
76
77 o-saft.pl +check --legacy=quick localhost \
78 | gawk 'BEGIN{FS="\t";print "<html><body><table>"}(NF>0){gsub(/&/,"\\&amp;");gsub(/</,"\\&lt;");gsub(/>/,"\\&gt;");}/^\s*$/{next}($1~/ reading /){next;}($1~/^===/ && $NF~/===/){printf("</table><h2>%s</h2>\n<table>",$0);next}($1~/^== /){print "<tr><th colspan=2>"$0"</th></tr>";next;}($1~/^[#=]/){print "<! "$0" -->";next}{print " <tr><th>"$1"</th><td>"$2"</td></tr>"}END{print "</table></body></html>"}'
79
80
81 ###############################################################################
82 ###
83 ### JSON convertions
84 ###
85
86 ### +info output: label and value per line in JSON style array
87
88 o-saft.pl +info --legacy=quick localhost \
89 | 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];"}'
90
91 o-saft.pl +info --tracekey --tab localhost | contrib/JSON-array.awk
92 o-saft.pl +info --tracekey --tab localhost | contrib/JSON-struct.awk
93
94 ###############################################################################
95 ###
96 ### XML convertions
97 ###
98
99 ### +info output: label and value per line
100
101 o-saft.pl +info localhost | contrib/XML-value.awk
102
103 # or
104
105 o-saft.pl +info --legacy=quick localhost \
106 | gawk 'BEGIN{FS="\t";print "<infos xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"SSLResults.xsd\" >"}(NF>0){gsub(/&/,"\\&amp;");gsub(/</,"\\&lt;");gsub(/>/,"\\&gt;");}/^\s*$/{next}($1~/^[#=]/){print "<! "$0" -->";next}{print " <info>\n <label>"$1"</label>\n <value>"$2"</value>\n </info>"}END{print "</info>"}'
107
108
109 ### +info output: one line per label and value
110
111 o-saft.pl +info localhost \
112 | gawk 'BEGIN{FS="\t";print "<infos xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"SSLResults.xsd\" >"}(NF>0){gsub(/&/,"\\&amp;");gsub(/</,"\\&lt;");gsub(/>/,"\\&gt;");}/^\s*$/{next}($1~/^[#=]/){print "<! "$0" -->";next}{print " <info><label>"$1"</label><value>"$2"</value></info>"}END{print "</info>"}'
113
114 # same as before a bit more compact
115
116 o-saft.pl +info --legacy=quick localhost \
117 | gawk 'BEGIN{FS="\t";print "<infos xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"SSLResults.xsd\" >"}(NF>0){gsub(/&/,"\\&amp;");gsub(/</,"\\&lt;");gsub(/>/,"\\&gt;");}/^\s*$/{next}($1~/^[#=]/){next}{print "<info><label>"$1"</label><value>"$2"</value></info>"}END{print "</info>"}'
118
119
120 ### +info output: one line per label and value as attribute
121
122 o-saft.pl +info localhost | contrib/XML-attribute.awk
123
124 # or
125
126 o-saft.pl +info --legacy=quick localhost \
127 | gawk 'BEGIN{FS="\t";print "<infos xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"SSLResults.xsd\" >"}(NF>0){gsub(/&/,"\\&amp;");gsub(/"/,"\\&quot;");gsub(/</,"\\&lt;");gsub(/>/,"\\&gt;");}/^\s*$/{next}($1~/^[#=]/){print "<! "$0" -->";next}{i++;printf(" <info id=\"%s\" label=\"%s\" value=\"%s\" />\n",i,$1,$2);}END{print "</info>"}'
128
129
130 ###############################################################################
131 ###
132 ### Parsable SSL protocol in output
133 ###
134
135 ### +cipher output: cipher lines with SSL protocol version
136
137 o-saft.pl +cipher localhost --header --legacy=sslaudit
138 o-saft.pl +cipher localhost --header --legacy=ssldiagnose
139 o-saft.pl +cipher localhost --header --legacy=full
140
141
142 ### +cipher output: all lines are prefixed with SSL protocol version
143
144 o-saft.pl +cipher localhost --header --legacy=quick \
145 | awk '/^=== Ciphers:/{p=$(NF-1)}/^/{printf"%s\t%s\n",p,$0;}'
146
147 ### +cipher output: all lines are prefixed with SSL protocol version, no headers
148
149 o-saft.pl +cipher localhost --header --legacy=quick \
150 | awk '/^=== Ciphers:/{p=$(NF-1)}/^=/{next}/^/{printf"%s\t%s\n",p,$0;}'
151
152