Version bump to 5.6.0dr2
[strongswan.git] / testing / do-tests
1 #!/bin/bash
2 # Automatically execute the strongSwan test cases
3 #
4 # Copyright (C) 2004  Eric Marchionni, Patrik Rayo
5 # Zuercher Hochschule Winterthur
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 # for more details.
16
17 DIR=$(dirname `readlink -f $0`)
18 . $DIR/testing.conf
19 . $DIR/scripts/function.sh
20 SSHCONF="-F $DIR/ssh_config"
21
22 [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
23 [ -d $DIR/tests ] || die "Directory 'tests' not found"
24 [ -d $BUILDDIR ] ||
25         die "Directory '$BUILDDIR' does not exist, please run make-testing first"
26 running_any $STRONGSWANHOSTS || die "Please start test environment before running $0"
27
28 ln -sfT $DIR $TESTDIR/testing
29
30 ##############################################################################
31 # take care of new path and file variables
32 #
33
34 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
35
36 TESTDATE=`date +%Y%m%d-%H%M-%S`
37
38 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
39 mkdir $TODAYDIR
40 TESTRESULTSHTML=$TODAYDIR/all.html
41 INDEX=$TODAYDIR/index.html
42 DEFAULTTESTSDIR=$TESTDIR/testing/tests
43
44 SOURCEIP_ROUTING_TABLE=220
45
46 testnumber="0"
47 failed_cnt="0"
48 passed_cnt="0"
49 subdir_cnt="0"
50
51 ##############################################################################
52 # copy default tests to $BUILDDIR
53 #
54
55 TESTSDIR=$BUILDDIR/tests
56 [ -d $TESTSDIR ] || mkdir $TESTSDIR
57
58 ##############################################################################
59 # assign IP for each host to hostname
60 #
61
62 for host in $STRONGSWANHOSTS
63 do
64     eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
65     eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
66
67     case $host in
68     moon)
69         eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
70         eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
71         ;;
72     sun)
73         eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
74         eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
75         ;;
76     alice)
77         eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
78         eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
79         ;;
80     venus)
81         ;;
82     bob)
83         ;;
84     carol)
85         eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
86         eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
87          ;;
88     dave)
89         eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
90         eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
91         ;;
92     winnetou)
93         ;;
94     esac
95 done
96
97
98 ##############################################################################
99 # open ssh sessions
100 #
101 for host in $STRONGSWANHOSTS
102 do
103     ssh $SSHCONF -N root@`eval echo \\\$ipv4_$host` >/dev/null 2>&1 &
104     eval ssh_pid_$host="`echo $!`"
105     do_on_exit kill `eval echo \\\$ssh_pid_$host`
106 done
107
108 ##############################################################################
109 # determine actual software versions
110 #
111
112 [ -f $SHAREDDIR/.strongswan-version ] && SWANVERSION=`cat $SHAREDDIR/.strongswan-version`
113 KERNELVERSION=`ssh $SSHCONF root@\$ipv4_winnetou uname -r 2>/dev/null`
114
115 # check if tcpdump supports --immediate-mode
116 ssh $SSHCONF root@$ipv4_winnetou tcpdump --immediate-mode -c 1 >/dev/null 2>&1
117 if [ $? -eq 0 ]
118 then
119         TCPDUMP_IM=--immediate-mode
120 fi
121
122 ##############################################################################
123 # create header for the results html file
124 #
125
126 ENVIRONMENT_HEADER=$(cat <<@EOF
127   <table border="0" cellspacing="2" cellpadding="2">
128     <tr valign="top">
129       <td><b>Host</b></td>
130       <td colspan="3">`uname -a`</td>
131     </tr>
132     <tr valign="top">
133       <td><b>Guest kernel</b></td>
134       <td colspan="3">$KERNELVERSION</td>
135     </tr>
136     <tr valign="top">
137       <td><b>strongSwan</b></td>
138       <td colspan="3">$SWANVERSION</td>
139     </tr>
140     <tr valign="top">
141       <td><b>Date</b></td>
142       <td colspan="3">$TESTDATE</td>
143     </tr>
144     <tr>
145       <td width="100">&nbsp;</td>
146       <td width="300">&nbsp;</td>
147       <td width=" 80">&nbsp;</td>
148       <td >&nbsp;</td>
149     </tr>
150 @EOF
151 )
152
153 cat > $INDEX <<@EOF
154 <html>
155 <head>
156   <title>strongSwan KVM Tests</title>
157 </head>
158 <body>
159   <h2>strongSwan KVM Tests</h2>
160   $ENVIRONMENT_HEADER
161 @EOF
162
163 cat > $TESTRESULTSHTML <<@EOF
164 <html>
165 <head>
166   <title>strongSwan KVM Tests - All Tests</title>
167 </head>
168 <body>
169   <div><a href="index.html">strongSwan KVM Tests</a> / All Tests</div>
170   <h2>All Tests</h2>
171   $ENVIRONMENT_HEADER
172     <tr align="left">
173       <th>Number</th>
174       <th>Test</th>
175       <th align="right">Time [s]</th>
176       <th>Result</th>
177     </tr>
178 @EOF
179
180 echo "Guest kernel : $KERNELVERSION"
181 echo "strongSwan   : $SWANVERSION"
182 echo "Date         : $TESTDATE"
183 echo
184
185 ##############################################################################
186 # trap CTRL-C to properly terminate a long run
187 #
188
189 function abort_tests()
190 {
191         echo -n "...aborting..." > /dev/tty
192         aborted=YES
193 }
194 trap abort_tests INT
195
196 ##############################################################################
197 # enter specific test directory
198 #
199 if [ $# -gt 0 ]
200 then
201     TESTS=$(printf "%s\n" $* | sort -u)
202 else
203     TESTS=$(ls $DEFAULTTESTSDIR)
204 fi
205
206 for SUBDIR in $TESTS
207 do
208     SUBTESTS="`basename $SUBDIR`"
209
210         if [ $SUBTESTS = $SUBDIR ]
211         then
212                 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
213         else
214                 if [[ $SUBTESTS == *'*'* ]]
215                 then
216                         SUBTESTS="`basename -a $DEFAULTTESTSDIR/$SUBDIR`"
217                 fi
218                 SUBDIR="`dirname $SUBDIR`"
219         fi
220
221     if [ ! -d $TODAYDIR/$SUBDIR ]
222     then
223         mkdir $TODAYDIR/$SUBDIR
224         if [ $testnumber == 0 ]
225         then
226             FIRST="<b>Category</b>"
227         else
228             FIRST="&nbsp;"
229         fi
230
231         if [ $subdir_cnt != 0 ]
232         then
233             echo "      <td align=\"right\">$subdir_cnt</td>" >> $INDEX
234             echo "      <td>&nbsp;</td>" >> $INDEX
235             echo "    </tr>" >> $INDEX
236             subdir_cnt="0"
237         fi
238         echo "    <tr>" >> $INDEX
239     echo "      <td>$FIRST</td>">> $INDEX
240     echo "      <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
241
242         SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
243         cat > $SUBTESTSINDEX <<@EOF
244 <html>
245 <head>
246   <title>strongSwan $SUBDIR Tests</title>
247 </head>
248 <body>
249   <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
250   <h2>strongSwan $SUBDIR Tests</h2>
251   <table border="0" cellspacing="2" cellpadding="2">
252     <tr valign="top">
253       <td><b>Guest kernel</b></td>
254       <td colspan="3">$KERNELVERSION</td>
255     </tr>
256     <tr valign="top">
257       <td><b>strongSwan</b></td>
258       <td colspan="3">$SWANVERSION</td>
259     </tr>
260     <tr valign="top">
261       <td><b>Date</b></td>
262       <td colspan="3">$TESTDATE</td>
263     </tr>
264     <tr>
265       <td width="100">&nbsp;</td>
266       <td width="300">&nbsp;</td>
267       <td width=" 50">&nbsp;</td>
268       <td >&nbsp;</td>
269     </tr>
270     <tr align="left">
271        <th>Number</th>
272        <th>Test</th>
273        <th colspan="2">Result</th>
274     </tr>
275 @EOF
276     fi
277
278     for name in $SUBTESTS
279     do
280         let "testnumber += 1"
281         let "subdir_cnt += 1"
282         testname=$SUBDIR/$name
283         log_action " $testnumber $testname:"
284
285         teststart=$(date +%s)
286
287         if [ ! -d $DEFAULTTESTSDIR/${testname} ]
288         then
289             echo "is missing..skipped"
290             continue
291         fi
292
293         [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
294         [ -f $DEFAULTTESTSDIR/${testname}/test.conf ]       || die "!! File 'test.conf' is missing"
295         [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ]     || die "!! File 'pretest.dat' is missing"
296         [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ]    || die "!! File 'posttest.dat' is missing"
297         [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ]    || die "!! File 'evaltest.dat' is missing"
298
299         TESTRESULTDIR=$TODAYDIR/$testname
300         mkdir -p $TESTRESULTDIR
301         CONSOLE_LOG=$TESTRESULTDIR/console.log
302         touch $CONSOLE_LOG
303
304         TESTDIR=$TESTSDIR/${testname}
305
306         ##########################################################################
307         # copy test specific configurations to hosts and clear log files
308         #
309
310         DBDIR=/etc/db.d
311
312         $DIR/scripts/load-testconfig $testname
313         unset RADIUSHOSTS
314         unset DBHOSTS
315         unset IPV6
316         unset SWANCTL
317         source $TESTDIR/test.conf
318
319
320         ##########################################################################
321         # run tcpdump in the background
322         #
323
324         if [ "$TCPDUMPHOSTS" != "" ]
325         then
326             echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
327
328             for host_iface in $TCPDUMPHOSTS
329             do
330                 host=`echo $host_iface | awk -F ":" '{print $1}'`
331                 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
332                 tcpdump_cmd="tcpdump -l $TCPDUMP_IM -i $iface not port ssh and not port domain >/tmp/tcpdump.log 2>/tmp/tcpdump.err.log &"
333                 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
334                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
335                 eval TDUP_${host}="true"
336             done
337         fi
338
339         ##########################################################################
340         # create database directory in RAM
341         #
342
343         for host in $DBHOSTS
344         do
345                 eval HOSTLOGIN=root@\$ipv4_${host}
346             ssh $SSHCONF $HOSTLOGIN "mkdir -p $DBDIR; mount -t ramfs -o size=5m ramfs $DBDIR" >/dev/null 2>&1
347             ssh $SSHCONF $HOSTLOGIN "chgrp www-data $DBDIR; chmod g+w $DBDIR" >/dev/null 2>&1
348         done
349
350         ##########################################################################
351         # flush conntrack table on all hosts
352         #
353
354         for host in $STRONGSWANHOSTS
355         do
356                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'conntrack -F' >/dev/null 2>&1
357         done
358
359         ##########################################################################
360         # remove leak detective log on all hosts
361         #
362
363         export LEAK_DETECTIVE_LOG=/var/log/leak-detective.log
364         for host in $STRONGSWANHOSTS
365         do
366                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'rm -f $LEAK_DETECTIVE_LOG' >/dev/null 2>&1
367         done
368
369         ##########################################################################
370         # flush IPsec state on all hosts
371         #
372
373         for host in $STRONGSWANHOSTS
374         do
375                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'ip xfrm state flush; ip xfrm policy flush' >/dev/null 2>&1
376         done
377
378         ##########################################################################
379         # execute pre-test commands
380         #
381
382         echo -n "pre.."
383         echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
384
385         eval `awk -F "::" '{
386             if ($1 !~ /^#.*/ && $2 != "")
387             {
388                 printf("echo \"%s# %s\"; ", $1, $2)
389                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
390                 printf("echo;\n")
391             }
392         }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
393
394
395         ##########################################################################
396         # stop tcpdump
397         #
398
399         function stop_tcpdump {
400             # wait for packets to get processed, but don't wait longer than 1s
401             eval ssh $SSHCONF root@\$ipv4_${1} "\"i=100; while [ \\\$i -gt 0 ]; do pkill -USR1 tcpdump; tail -1 /tmp/tcpdump.err.log | perl -n -e '/(\\d+).*?(\\d+)/; exit (\\\$1 == \\\$2)' || break; sleep 0.01; i=\\\$((\\\$i-1)); done;\""
402             echo "${1}# killall tcpdump" >> $CONSOLE_LOG
403             eval ssh $SSHCONF root@\$ipv4_${1} "\"killall tcpdump; while true; do killall -q -0 tcpdump || break; sleep 0.01; done;\""
404             eval TDUP_${1}="false"
405             echo "" >> $CONSOLE_LOG
406         }
407
408
409         ##########################################################################
410         # get and evaluate test results
411         #
412
413         echo -n "test.."
414         echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
415
416         STATUS="passed"
417
418         eval `awk -F "::" '{
419             host=$1
420             command=$2
421             pattern=$3
422             hit=$4
423             if (host !~ /^#.*/ && command != "")
424             {
425                 if (command == "tcpdump")
426                 {
427                     printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
428                     printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047  [%s]\"; ", host, pattern, hit)
429                     printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
430                 }
431                 else
432                 {
433                     printf("echo \"%s# %s | grep \047%s\047  [%s]\"; ", host, command, pattern, hit)
434                     printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ",  host, command, pattern)
435                 }
436                 printf("cmd_exit=\044?; ")
437                 printf("echo; ")
438                 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\"  ] ", hit)
439                 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
440                 printf("; then STATUS=\"failed\"; fi; \n")
441             }
442         }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
443
444
445         ##########################################################################
446         # log statusall and listall output
447         # get copies of ipsec.conf, ipsec.secrets
448         # create index.html for the given test case
449
450         cat > $TESTRESULTDIR/index.html <<@EOF
451 <html>
452 <head>
453   <title>Test $testname</title>
454 </head>
455 <body>
456 <table border="0" cellpadding="0" cellspacing="0" width="600">
457   <tr><td>
458     <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
459     <h2>Test $testname</h2>
460     <h3>Description</h3>
461 @EOF
462
463         cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
464
465         cat >> $TESTRESULTDIR/index.html <<@EOF
466     <ul>
467       <li><a href="console.log">console.log</a></li>
468     </ul>
469     <img src="../../images/$DIAGRAM" alt="$VIRTHOSTS">
470 @EOF
471
472         IPTABLES_CMD_V4="echo -e '=== filter table ==='; iptables  -v -n -L; echo -e '\n=== nat table ==='; iptables  -v -n -t nat -L; echo -e '\n=== mangle table ==='; iptables  -v -n -t mangle -L"
473         IPTABLES_CMD_V6="echo -e '=== filter table ==='; ip6tables -v -n -L; echo -e '\n=== nat table ==='; ip6tables -v -n -t nat -L; echo -e '\n=== mangle table ==='; ip6tables -v -n -t mangle -L"
474
475         if [ -n "$IPV6" ]
476         then
477             IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
478             IPROUTE_DSP=$IPROUTE_CMD
479             IPTABLES_CMD="$IPTABLES_CMD_V6"
480             IPTABLES_DSP="ip6tables -L"
481             IPTABLES_SAVE_CMD="ip6tables-save"
482             IPTABLES_SAVE_DSP="ip6tables-save"
483         else
484             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
485             IPROUTE_DSP=$IPROUTE_CMD
486             IPTABLES_CMD="$IPTABLES_CMD_V4"
487             IPTABLES_DSP="iptables -L"
488             IPTABLES_SAVE_CMD="iptables-save"
489             IPTABLES_SAVE_DSP="iptables-save"
490         fi
491
492         if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
493         then
494             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
495             IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
496             IPTABLES_CMD="$IPTABLES_CMD_V4; echo; $IPTABLES_CMD_V6"
497             IPTABLES_DSP="iptables -L ; ip6tables -L"
498             IPTABLES_SAVE_CMD="iptables-save; echo; ip6tables-save"
499             IPTABLES_SAVE_DSP="iptables-save ; ip6tables-save"
500         fi
501
502         for host in $DBHOSTS
503         do
504             eval HOSTLOGIN=root@\$ipv4_${host}
505
506                 scp $SSHCONF $HOSTLOGIN:/etc/db.d/ipsec.sql \
507                     $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
508         done
509
510         for host in $IPSECHOSTS
511         do
512             eval HOSTLOGIN=root@\$ipv4_${host}
513
514                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
515                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
516                 if [  -n "$SWANCTL" ]
517                 then
518                         scp $SSHCONF $HOSTLOGIN:/etc/swanctl/swanctl.conf \
519                         $TESTRESULTDIR/${host}.swanctl.conf  > /dev/null 2>&1
520
521                         for subsys in conns algs certs pools authorities sas pols
522                         do
523                                 ssh $SSHCONF $HOSTLOGIN swanctl --list-$subsys \
524                                         > $TESTRESULTDIR/${host}.swanctl.$subsys 2>/dev/null
525                         done
526
527                         ssh $SSHCONF $HOSTLOGIN swanctl --stats \
528                                 > $TESTRESULTDIR/${host}.swanctl.stats 2>/dev/null
529
530                         echo "" >> $TESTRESULTDIR/${host}.swanctl.sas
531                         cat $TESTRESULTDIR/${host}.swanctl.pols >> \
532                                 $TESTRESULTDIR/${host}.swanctl.sas
533                         cat $TESTRESULTDIR/${host}.swanctl.algs >> \
534                                 $TESTRESULTDIR/${host}.swanctl.stats
535                 else
536                     for file in ipsec.conf ipsec.secrets
537                     do
538                                 scp $SSHCONF $HOSTLOGIN:/etc/$file \
539                             $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
540                     done
541
542                     for command in statusall listall
543                     do
544                                 ssh $SSHCONF $HOSTLOGIN ipsec $command \
545                             > $TESTRESULTDIR/${host}.$command 2>/dev/null
546                     done
547                 fi
548
549                 if (! [ -f $TESTRESULTDIR/${host}.ipsec.sql ] ) then
550                         scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
551                                 $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
552                 fi
553
554             ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
555                     > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
556             ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
557                     > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
558             ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
559                     > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
560             ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
561                     > $TESTRESULTDIR/${host}.iptables 2>/dev/null
562                 ssh $SSHCONF $HOSTLOGIN $IPTABLES_SAVE_CMD \
563                     > $TESTRESULTDIR/${host}.iptables-save 2>/dev/null
564             chmod a+r $TESTRESULTDIR/*
565
566                 if [ -n "$SWANCTL" ]
567                 then
568                     cat >> $TESTRESULTDIR/index.html <<@EOF
569     <h3>$host</h3>
570       <table border="0" cellspacing="0" width="600">
571       <tr>
572         <td valign="top">
573           <ul>
574             <li><a href="$host.swanctl.conf">swanctl.conf</a></li>
575             <li><a href="$host.swanctl.conns">swanctl --list-conns</a></li>
576             <li><a href="$host.swanctl.certs">swanctl --list-certs</a></li>
577             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
578             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
579           </ul>
580         </td>
581         <td valign="top">
582           <ul>
583             <li><a href="$host.swanctl.sas">swanctl --list-sas|--list-pols</a></li>
584             <li><a href="$host.swanctl.pools">swanctl --list-pools</a></li>
585             <li><a href="$host.swanctl.authorities">swanctl --list-authorities</a></li>
586             <li><a href="$host.swanctl.stats">swanctl --stats|--list-algs</a></li>
587             <li><a href="$host.auth.log">auth.log</a></li>
588             <li><a href="$host.daemon.log">daemon.log</a></li>
589           </ul>
590       </td>
591         <td valign="top">
592           <ul>
593             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
594             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
595             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
596             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
597             <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
598           </ul>
599           &nbsp;
600       </td>
601     </tr>
602     </table>
603 @EOF
604
605                 else
606                     cat >> $TESTRESULTDIR/index.html <<@EOF
607     <h3>$host</h3>
608       <table border="0" cellspacing="0" width="600">
609       <tr>
610         <td valign="top">
611           <ul>
612             <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
613             <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
614             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
615             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
616           </ul>
617         </td>
618         <td valign="top">
619           <ul>
620             <li><a href="$host.statusall">ipsec statusall</a></li>
621             <li><a href="$host.listall">ipsec listall</a></li>
622             <li><a href="$host.auth.log">auth.log</a></li>
623             <li><a href="$host.daemon.log">daemon.log</a></li>
624           </ul>
625       </td>
626         <td valign="top">
627           <ul>
628             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
629             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
630             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
631             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
632             <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
633           </ul>
634       </td>
635     </tr>
636     </table>
637 @EOF
638                 fi
639         done
640
641         for host in $RADIUSHOSTS
642         do
643             eval HOSTLOGIN=root@\$ipv4_${host}
644
645             for file in clients.conf eap.conf radiusd.conf proxy.conf users
646             do
647                 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
648                     $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
649             done
650
651                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
652                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
653
654             scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
655                 $TESTRESULTDIR/${host}.radius.log  > /dev/null 2>&1
656
657             ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
658                 >> $TESTRESULTDIR/${host}.daemon.log 2>/dev/null
659
660             chmod a+r $TESTRESULTDIR/*
661             cat >> $TESTRESULTDIR/index.html <<@EOF
662     <h3>$host</h3>
663       <table border="0" cellspacing="0" width="600">
664       <tr>
665         <td valign="top">
666           <ul>
667             <li><a href="$host.clients.conf">clients.conf</a></li>
668             <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
669             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
670           </ul>
671         </td>
672         <td valign="top">
673           <ul>
674             <li><a href="$host.eap.conf">eap.conf</a></li>
675             <li><a href="$host.radius.log">radius.log</a></li>
676             <li><a href="$host.daemon.log">daemon.log</a></li>
677           </ul>
678       </td>
679         <td valign="top">
680           <ul>
681             <li><a href="$host.proxy.conf">proxy.conf</a></li>
682             <li><a href="$host.users">users</a></li>
683           </ul>
684       </td>
685     </tr>
686     </table>
687 @EOF
688
689         done
690
691         cat >> $TESTRESULTDIR/index.html <<@EOF
692         <h3>tcpdump</h3>
693         <ul>
694 @EOF
695
696         for host in $TCPDUMPHOSTS
697         do
698             cat >> $TESTRESULTDIR/index.html <<@EOF
699             <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
700 @EOF
701         done
702
703         cat >> $TESTRESULTDIR/index.html <<@EOF
704         </ul>
705 @EOF
706
707         cat >> $TESTRESULTDIR/index.html <<@EOF
708   </td></tr>
709 </table>
710 </body>
711 </html>
712 @EOF
713
714
715         ##########################################################################
716         # execute post-test commands
717         #
718
719         echo -n "post"
720         echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
721
722         eval `awk -F "::" '{
723             if ($1 !~ /^#.*/ && $2 != "")
724             {
725                 printf("echo \"%s# %s\"; ", $1, $2)
726                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
727                 printf("echo;\n")
728             }
729         }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
730
731         ##########################################################################
732         # check that IPsec state was cleaned up properly
733         #
734
735         for host in $IPSECHOSTS
736         do
737                 eval HOSTLOGIN=root@\$ipv4_${host}
738                 IPSECSTATE=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm state'`
739                 IPSECPOLICY=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm policy'`
740                 if [ -n "$IPSECSTATE" -o -n "$IPSECPOLICY" ]
741                 then
742                         echo -e "\n$host# ip xfrm state [NO]" >> $CONSOLE_LOG
743                         echo "$IPSECSTATE" >> $CONSOLE_LOG
744                         echo -e "\n$host# ip xfrm policy [NO]" >> $CONSOLE_LOG
745                         echo "$IPSECPOLICY" >> $CONSOLE_LOG
746                         STATUS="failed"
747                 fi
748         done
749
750
751         ##########################################################################
752         # make sure there were no leaks
753         #
754
755         for host in $STRONGSWANHOSTS
756         do
757                 eval HOSTLOGIN=root@\$ipv4_${host}
758                 LEAKS=`ssh $SSHCONF $HOSTLOGIN 'cat $LEAK_DETECTIVE_LOG 2>/dev/null | grep -v "No leaks detected.*"'`
759                 if [ -n "$LEAKS" ]
760                 then
761                         echo -e "\n$host# cat $LEAK_DETECTIVE_LOG [NO]" >> $CONSOLE_LOG
762                         echo "$LEAKS" >> $CONSOLE_LOG
763                         echo "<<< $host $LEAK_DETECTIVE_LOG >>>" >> $CONSOLE_LOG
764                         STATUS="failed"
765                 fi
766         done
767
768
769         ##########################################################################
770         # get a copy of /var/log/auth.log
771         #
772
773         for host in $IPSECHOSTS
774         do
775             eval HOSTLOGIN=root@\$ipv4_${host}
776             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv|pt-tls-client' \
777                 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
778         done
779
780
781         ##########################################################################
782         # get a copy of /var/log/daemon.log
783         #
784
785         for host in $IPSECHOSTS
786         do
787             eval HOSTLOGIN=root@\$ipv4_${host}
788             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv' \
789                 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
790         done
791
792
793         ##########################################################################
794         # stop tcpdump if necessary
795         #
796
797         for host in $TCPDUMPHOSTS
798         do
799             if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
800             then
801                         stop_tcpdump $host
802             fi
803             eval HOSTLOGIN=root@\$ipv4_${host}
804                 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
805                         $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
806         done
807
808         ##########################################################################
809         # remove database directory if needed
810         #
811
812         for host in $DBHOSTS
813         do
814                 eval HOSTLOGIN=root@\$ipv4_${host}
815             ssh $SSHCONF $HOSTLOGIN "umount $DBDIR; rm -r $DBDIR" > /dev/null 2>&1
816         done
817
818         ##########################################################################
819         # copy default host config back if necessary
820         #
821
822         $DIR/scripts/restore-defaults $testname
823
824
825         ##########################################################################
826         # set counters
827         #
828
829         if [ $STATUS = "failed" ]
830         then
831             let "failed_cnt += 1"
832         else
833             let "passed_cnt += 1"
834         fi
835
836
837         ##########################################################################
838         # write test status to html file
839         #
840         testend=$(date +%s)
841         let "testend -= teststart"
842         let "timetotal += testend"
843
844         if [ $STATUS = "passed" ]
845         then
846                 COLOR="green"
847                 log_status 0
848         else
849                 COLOR="red"
850                 log_status 1
851         fi
852
853         cat >> $TESTRESULTSHTML << @EOF
854   <tr>
855     <td>$testnumber</td>
856     <td><a href="$testname/index.html">$testname</a></td>
857     <td align="right">$testend</td>
858     <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
859   </tr>
860 @EOF
861         cat >> $SUBTESTSINDEX << @EOF
862   <tr>
863     <td>$testnumber</td>
864     <td><a href="$name/index.html">$name</a></td>
865     <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
866     <td>&nbsp;</td>
867   </tr>
868 @EOF
869
870
871         ##########################################################################
872         # remove any charon.pid files that still may exist
873         #
874
875         for host in $IPSECHOSTS
876         do
877             eval HOSTLOGIN=root@\$ipv4_${host}
878             ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo "    removed charon.pid on `hostname`"; fi'
879         done
880
881         if [ -n "$aborted" ]
882         then
883             break 2
884         fi
885
886     done
887
888 done
889
890
891 ##############################################################################
892 # finish the results html file
893 #
894
895 cat >> $TESTRESULTSHTML << @EOF
896     <tr>
897       <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
898     </tr>
899     <tr>
900       <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
901     </tr>
902     <tr>
903       <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
904     </tr>
905     <tr>
906       <td><b>Time [s]</b></td><td><b><font color="blue">$timetotal</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
907     </tr>
908   </table>
909 </body>
910 </html>
911 @EOF
912
913 if [ $subdir_cnt != 0 ]
914 then
915 cat >> $INDEX << @EOF
916       <td align="right">$subdir_cnt</td>
917       <td>&nbsp;</td>
918     </tr>
919 @EOF
920 fi
921
922 let "all_cnt = $passed_cnt + $failed_cnt"
923
924 cat >> $INDEX << @EOF
925     <tr>
926       <td>&nbsp;</td>
927       <td><a href="all.html"><b>all</b></a></td>
928       <td align="right"><b>$all_cnt</b></td>
929       <td>&nbsp;</td>
930     </tr>
931     <tr>
932       <td><b>Failed</b></td>
933       <td>&nbsp;</td>
934       <td align="right"><b><font color="red">$failed_cnt</font></b></td>
935       <td>&nbsp;</td>
936     </tr>
937   </table>
938 </body>
939 </html>
940 @EOF
941
942 echo
943 echo_ok     "Passed : $passed_cnt"
944 echo_failed "Failed : $failed_cnt"
945
946 echo
947 echo "The results are available in $TODAYDIR"
948 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
949
950 ENDDATE=`date +%Y%m%d-%H%M-%S`
951 echo
952 echo "Finished : $ENDDATE"