testing: Ignore comments (lines starting with #) in pre-/eval-/posttest.dat
[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         SUBDIR="`dirname $SUBDIR`"
215     fi
216
217     if [ ! -d $TODAYDIR/$SUBDIR ]
218     then
219         mkdir $TODAYDIR/$SUBDIR
220         if [ $testnumber == 0 ]
221         then
222             FIRST="<b>Category</b>"
223         else
224             FIRST="&nbsp;"
225         fi
226
227         if [ $subdir_cnt != 0 ]
228         then
229             echo "      <td align=\"right\">$subdir_cnt</td>" >> $INDEX
230             echo "      <td>&nbsp;</td>" >> $INDEX
231             echo "    </tr>" >> $INDEX
232             subdir_cnt="0"
233         fi
234         echo "    <tr>" >> $INDEX
235     echo "      <td>$FIRST</td>">> $INDEX
236     echo "      <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
237
238         SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
239         cat > $SUBTESTSINDEX <<@EOF
240 <html>
241 <head>
242   <title>strongSwan $SUBDIR Tests</title>
243 </head>
244 <body>
245   <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
246   <h2>strongSwan $SUBDIR Tests</h2>
247   <table border="0" cellspacing="2" cellpadding="2">
248     <tr valign="top">
249       <td><b>Guest kernel</b></td>
250       <td colspan="3">$KERNELVERSION</td>
251     </tr>
252     <tr valign="top">
253       <td><b>strongSwan</b></td>
254       <td colspan="3">$SWANVERSION</td>
255     </tr>
256     <tr valign="top">
257       <td><b>Date</b></td>
258       <td colspan="3">$TESTDATE</td>
259     </tr>
260     <tr>
261       <td width="100">&nbsp;</td>
262       <td width="300">&nbsp;</td>
263       <td width=" 50">&nbsp;</td>
264       <td >&nbsp;</td>
265     </tr>
266     <tr align="left">
267        <th>Number</th>
268        <th>Test</th>
269        <th colspan="2">Result</th>
270     </tr>
271 @EOF
272     fi
273
274     for name in $SUBTESTS
275     do
276         let "testnumber += 1"
277         let "subdir_cnt += 1"
278         testname=$SUBDIR/$name
279         log_action " $testnumber $testname:"
280
281         teststart=$(date +%s)
282
283         if [ ! -d $DEFAULTTESTSDIR/${testname} ]
284         then
285             echo "is missing..skipped"
286             continue
287         fi
288
289         [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
290         [ -f $DEFAULTTESTSDIR/${testname}/test.conf ]       || die "!! File 'test.conf' is missing"
291         [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ]     || die "!! File 'pretest.dat' is missing"
292         [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ]    || die "!! File 'posttest.dat' is missing"
293         [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ]    || die "!! File 'evaltest.dat' is missing"
294
295         TESTRESULTDIR=$TODAYDIR/$testname
296         mkdir -p $TESTRESULTDIR
297         CONSOLE_LOG=$TESTRESULTDIR/console.log
298         touch $CONSOLE_LOG
299
300         TESTDIR=$TESTSDIR/${testname}
301         rm -rf $TESTDIR
302         mkdir -p $TESTDIR
303         cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
304
305
306         ##############################################################################
307         # replace IP wildcards with actual IPv4 and IPv6 addresses
308         #
309
310         for host in $STRONGSWANHOSTS
311         do
312             case $host in
313             moon)
314                 searchandreplace PH_IP_MOON1     $ipv4_moon1 $TESTDIR
315                 searchandreplace PH_IP_MOON      $ipv4_moon  $TESTDIR
316                 searchandreplace PH_IP6_MOON1    $ipv6_moon1 $TESTDIR
317                 searchandreplace PH_IP6_MOON     $ipv6_moon  $TESTDIR
318                 ;;
319             sun)
320                 searchandreplace PH_IP_SUN1      $ipv4_sun1 $TESTDIR
321                 searchandreplace PH_IP_SUN       $ipv4_sun  $TESTDIR
322                 searchandreplace PH_IP6_SUN1     $ipv6_sun1 $TESTDIR
323                 searchandreplace PH_IP6_SUN      $ipv6_sun  $TESTDIR
324                 ;;
325             alice)
326                 searchandreplace PH_IP_ALICE1    $ipv4_alice1 $TESTDIR
327                 searchandreplace PH_IP_ALICE     $ipv4_alice  $TESTDIR
328                 searchandreplace PH_IP6_ALICE1   $ipv6_alice1 $TESTDIR
329                 searchandreplace PH_IP6_ALICE    $ipv6_alice  $TESTDIR
330                 ;;
331             venus)
332                 searchandreplace PH_IP_VENUS     $ipv4_venus $TESTDIR
333                 searchandreplace PH_IP6_VENUS    $ipv6_venus $TESTDIR
334                 ;;
335             bob)
336                 searchandreplace PH_IP_BOB       $ipv4_bob $TESTDIR
337                 searchandreplace PH_IPV6_BOB     $ipv6_bob $TESTDIR
338                 ;;
339             carol)
340                 searchandreplace PH_IP_CAROL1    $ipv4_carol1 $TESTDIR
341                 searchandreplace PH_IP_CAROL     $ipv4_carol  $TESTDIR
342                 searchandreplace PH_IP6_CAROL1   $ipv6_carol1 $TESTDIR
343                 searchandreplace PH_IP6_CAROL    $ipv6_carol  $TESTDIR
344                 ;;
345             dave)
346                 searchandreplace PH_IP_DAVE1     $ipv4_dave1 $TESTDIR
347                 searchandreplace PH_IP_DAVE      $ipv4_dave  $TESTDIR
348                 searchandreplace PH_IP6_DAVE1    $ipv6_dave1 $TESTDIR
349                 searchandreplace PH_IP6_DAVE     $ipv6_dave  $TESTDIR
350                 ;;
351             winnetou)
352                 searchandreplace PH_IP_WINNETOU  $ipv4_winnetou $TESTDIR
353                 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
354                 ;;
355             esac
356         done
357
358
359         ##########################################################################
360         # copy test specific configurations to uml hosts and clear auth.log files
361         #
362
363         DBDIR=/etc/db.d
364
365         $DIR/scripts/load-testconfig $testname
366         unset RADIUSHOSTS
367         unset DBHOSTS
368         unset IPV6
369         unset SWANCTL
370         source $TESTDIR/test.conf
371
372
373         ##########################################################################
374         # run tcpdump in the background
375         #
376
377         if [ "$TCPDUMPHOSTS" != "" ]
378         then
379             echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
380
381             for host_iface in $TCPDUMPHOSTS
382             do
383                 host=`echo $host_iface | awk -F ":" '{print $1}'`
384                 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
385                 tcpdump_cmd="tcpdump -l $TCPDUMP_IM -i $iface not port ssh and not port domain >/tmp/tcpdump.log 2>/tmp/tcpdump.err.log &"
386                 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
387                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
388                 eval TDUP_${host}="true"
389             done
390         fi
391
392         ##########################################################################
393         # create database directory in RAM
394         #
395
396         for host in $DBHOSTS
397         do
398                 eval HOSTLOGIN=root@\$ipv4_${host}
399             ssh $SSHCONF $HOSTLOGIN "mkdir -p $DBDIR; mount -t ramfs -o size=5m ramfs $DBDIR" >/dev/null 2>&1
400             ssh $SSHCONF $HOSTLOGIN "chgrp www-data $DBDIR; chmod g+w $DBDIR" >/dev/null 2>&1
401         done
402
403         ##########################################################################
404         # flush conntrack table on all hosts
405         #
406
407         for host in $STRONGSWANHOSTS
408         do
409                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'conntrack -F' >/dev/null 2>&1
410         done
411
412         ##########################################################################
413         # flush IPsec state on all hosts
414         #
415
416         for host in $STRONGSWANHOSTS
417         do
418                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'ip xfrm state flush; ip xfrm policy flush' >/dev/null 2>&1
419         done
420
421         ##########################################################################
422         # execute pre-test commands
423         #
424
425         echo -n "pre.."
426         echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
427
428         eval `awk -F "::" '{
429             if ($1 !~ /^#.*/ && $2 != "")
430             {
431                 printf("echo \"%s# %s\"; ", $1, $2)
432                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
433                 printf("echo;\n")
434             }
435         }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
436
437
438         ##########################################################################
439         # stop tcpdump
440         #
441
442         function stop_tcpdump {
443             # wait for packets to get processed, but don't wait longer than 1s
444             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;\""
445             echo "${1}# killall tcpdump" >> $CONSOLE_LOG
446             eval ssh $SSHCONF root@\$ipv4_${1} "\"killall tcpdump; while true; do killall -q -0 tcpdump || break; sleep 0.01; done;\""
447             eval TDUP_${1}="false"
448             echo "" >> $CONSOLE_LOG
449         }
450
451
452         ##########################################################################
453         # get and evaluate test results
454         #
455
456         echo -n "test.."
457         echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
458
459         STATUS="passed"
460
461         eval `awk -F "::" '{
462             host=$1
463             command=$2
464             pattern=$3
465             hit=$4
466             if (host !~ /^#.*/ && command != "")
467             {
468                 if (command == "tcpdump")
469                 {
470                     printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
471                     printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047  [%s]\"; ", host, pattern, hit)
472                     printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
473                 }
474                 else
475                 {
476                     printf("echo \"%s# %s | grep \047%s\047  [%s]\"; ", host, command, pattern, hit)
477                     printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ",  host, command, pattern)
478                 }
479                 printf("cmd_exit=\044?; ")
480                 printf("echo; ")
481                 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\"  ] ", hit)
482                 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
483                 printf("; then STATUS=\"failed\"; fi; \n")
484             }
485         }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
486
487
488         ##########################################################################
489         # set counters
490         #
491
492         if [ $STATUS = "failed" ]
493         then
494             let "failed_cnt += 1"
495         else
496             let "passed_cnt += 1"
497         fi
498
499
500         ##########################################################################
501         # log statusall and listall output
502         # get copies of ipsec.conf, ipsec.secrets
503         # create index.html for the given test case
504
505         cat > $TESTRESULTDIR/index.html <<@EOF
506 <html>
507 <head>
508   <title>Test $testname</title>
509 </head>
510 <body>
511 <table border="0" cellpadding="0" cellspacing="0" width="600">
512   <tr><td>
513     <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
514     <h2>Test $testname</h2>
515     <h3>Description</h3>
516 @EOF
517
518         cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
519
520         cat >> $TESTRESULTDIR/index.html <<@EOF
521     <ul>
522       <li><a href="console.log">console.log</a></li>
523     </ul>
524     <img src="../../images/$DIAGRAM" alt="$VIRTHOSTS">
525 @EOF
526
527         if [ -n "$IPV6" ]
528         then
529             IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
530             IPROUTE_DSP=$IPROUTE_CMD
531             IPTABLES_CMD="ip6tables -v -n -L"
532             IPTABLES_DSP="ip6tables -L"
533         else
534             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
535             IPROUTE_DSP=$IPROUTE_CMD
536             IPTABLES_CMD="iptables -v -n -L"
537             IPTABLES_DSP="iptables -L"
538         fi
539
540         if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
541         then
542             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
543             IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
544             IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
545             IPTABLES_DSP="iptables -L ; ip6tables -L"
546         fi
547
548         for host in $DBHOSTS
549         do
550             eval HOSTLOGIN=root@\$ipv4_${host}
551
552                 scp $SSHCONF $HOSTLOGIN:/etc/db.d/ipsec.sql \
553                     $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
554         done
555
556         for host in $IPSECHOSTS
557         do
558             eval HOSTLOGIN=root@\$ipv4_${host}
559
560                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
561                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
562                 if [  -n "$SWANCTL" ]
563                 then
564                         scp $SSHCONF $HOSTLOGIN:/etc/swanctl/swanctl.conf \
565                         $TESTRESULTDIR/${host}.swanctl.conf  > /dev/null 2>&1
566
567                         for subsys in conns algs certs pools authorities sas pols
568                         do
569                                 ssh $SSHCONF $HOSTLOGIN swanctl --list-$subsys \
570                                         > $TESTRESULTDIR/${host}.swanctl.$subsys 2>/dev/null
571                         done
572
573                         ssh $SSHCONF $HOSTLOGIN swanctl --stats \
574                                 > $TESTRESULTDIR/${host}.swanctl.stats 2>/dev/null
575
576                         echo "" >> $TESTRESULTDIR/${host}.swanctl.sas
577                         cat $TESTRESULTDIR/${host}.swanctl.pols >> \
578                                 $TESTRESULTDIR/${host}.swanctl.sas
579                         cat $TESTRESULTDIR/${host}.swanctl.algs >> \
580                                 $TESTRESULTDIR/${host}.swanctl.stats
581                 else
582                     for file in ipsec.conf ipsec.secrets
583                     do
584                                 scp $SSHCONF $HOSTLOGIN:/etc/$file \
585                             $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
586                     done
587
588                     for command in statusall listall
589                     do
590                                 ssh $SSHCONF $HOSTLOGIN ipsec $command \
591                             > $TESTRESULTDIR/${host}.$command 2>/dev/null
592                     done
593                 fi
594
595                 if (! [ -f $TESTRESULTDIR/${host}.ipsec.sql ] ) then
596                         scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
597                                 $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
598                 fi
599
600             ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
601                     > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
602             ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
603                     > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
604             ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
605                     > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
606             ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
607                     > $TESTRESULTDIR/${host}.iptables 2>/dev/null
608             chmod a+r $TESTRESULTDIR/*
609
610                 if [ -n "$SWANCTL" ]
611                 then
612                     cat >> $TESTRESULTDIR/index.html <<@EOF
613     <h3>$host</h3>
614       <table border="0" cellspacing="0" width="600">
615       <tr>
616         <td valign="top">
617           <ul>
618             <li><a href="$host.swanctl.conf">swanctl.conf</a></li>
619             <li><a href="$host.swanctl.conns">swanctl --list-conns</a></li>
620             <li><a href="$host.swanctl.certs">swanctl --list-certs</a></li>
621             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
622             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
623           </ul>
624         </td>
625         <td valign="top">
626           <ul>
627             <li><a href="$host.swanctl.sas">swanctl --list-sas|--list-pols</a></li>
628             <li><a href="$host.swanctl.pools">swanctl --list-pools</a></li>
629             <li><a href="$host.swanctl.authorities">swanctl --list-authorities</a></li>
630             <li><a href="$host.swanctl.stats">swanctl --stats|--list-algs</a></li>
631             <li><a href="$host.daemon.log">daemon.log</a></li>
632           </ul>
633       </td>
634         <td valign="top">
635           <ul>
636             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
637             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
638             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
639             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
640             <li><a href="$host.auth.log">auth.log</a></li>
641           </ul>
642           &nbsp;
643       </td>
644     </tr>
645     </table>
646 @EOF
647
648                 else
649                     cat >> $TESTRESULTDIR/index.html <<@EOF
650     <h3>$host</h3>
651       <table border="0" cellspacing="0" width="600">
652       <tr>
653         <td valign="top">
654           <ul>
655             <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
656             <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
657             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
658             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
659           </ul>
660         </td>
661         <td valign="top">
662           <ul>
663             <li><a href="$host.statusall">ipsec statusall</a></li>
664             <li><a href="$host.listall">ipsec listall</a></li>
665             <li><a href="$host.auth.log">auth.log</a></li>
666             <li><a href="$host.daemon.log">daemon.log</a></li>
667           </ul>
668       </td>
669         <td valign="top">
670           <ul>
671             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
672             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
673             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
674             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
675           </ul>
676       </td>
677     </tr>
678     </table>
679 @EOF
680                 fi
681         done
682
683         for host in $RADIUSHOSTS
684         do
685             eval HOSTLOGIN=root@\$ipv4_${host}
686
687             for file in clients.conf eap.conf radiusd.conf proxy.conf users
688             do
689                 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
690                     $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
691             done
692
693                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
694                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
695
696             scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
697                 $TESTRESULTDIR/${host}.radius.log  > /dev/null 2>&1
698
699             ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
700                 >> $TESTRESULTDIR/${host}.daemon.log 2>/dev/null
701
702             chmod a+r $TESTRESULTDIR/*
703             cat >> $TESTRESULTDIR/index.html <<@EOF
704     <h3>$host</h3>
705       <table border="0" cellspacing="0" width="600">
706       <tr>
707         <td valign="top">
708           <ul>
709             <li><a href="$host.clients.conf">clients.conf</a></li>
710             <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
711             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
712           </ul>
713         </td>
714         <td valign="top">
715           <ul>
716             <li><a href="$host.eap.conf">eap.conf</a></li>
717             <li><a href="$host.radius.log">radius.log</a></li>
718             <li><a href="$host.daemon.log">daemon.log</a></li>
719           </ul>
720       </td>
721         <td valign="top">
722           <ul>
723             <li><a href="$host.proxy.conf">proxy.conf</a></li>
724             <li><a href="$host.users">users</a></li>
725           </ul>
726       </td>
727     </tr>
728     </table>
729 @EOF
730
731         done
732
733         cat >> $TESTRESULTDIR/index.html <<@EOF
734         <h3>tcpdump</h3>
735         <ul>
736 @EOF
737
738         for host in $TCPDUMPHOSTS
739         do
740             cat >> $TESTRESULTDIR/index.html <<@EOF
741             <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
742 @EOF
743         done
744
745         cat >> $TESTRESULTDIR/index.html <<@EOF
746         </ul>
747 @EOF
748
749         cat >> $TESTRESULTDIR/index.html <<@EOF
750   </td></tr>
751 </table>
752 </body>
753 </html>
754 @EOF
755
756
757         ##########################################################################
758         # execute post-test commands
759         #
760
761         echo -n "post"
762         echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
763
764         eval `awk -F "::" '{
765             if ($1 !~ /^#.*/ && $2 != "")
766             {
767                 printf("echo \"%s# %s\"; ", $1, $2)
768                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
769                 printf("echo;\n")
770             }
771         }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
772
773         ##########################################################################
774         # check that IPsec state was cleaned up properly
775         #
776
777         for host in $IPSECHOSTS
778         do
779                 eval HOSTLOGIN=root@\$ipv4_${host}
780                 IPSECSTATE=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm state'`
781                 IPSECPOLICY=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm policy'`
782                 if [ -n "$IPSECSTATE" -o -n "$IPSECPOLICY" ]
783                 then
784                         echo -e "\n$host# ip xfrm state [NO]" >> $CONSOLE_LOG
785                         echo "$IPSECSTATE" >> $CONSOLE_LOG
786                         echo -e "\n$host# ip xfrm policy [NO]" >> $CONSOLE_LOG
787                         echo "$IPSECPOLICY" >> $CONSOLE_LOG
788                         STATUS="failed"
789                 fi
790         done
791
792         ##########################################################################
793         # get a copy of /var/log/auth.log
794         #
795
796         for host in $IPSECHOSTS
797         do
798             eval HOSTLOGIN=root@\$ipv4_${host}
799             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv|pt-tls-client' \
800                 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
801         done
802
803
804         ##########################################################################
805         # get a copy of /var/log/daemon.log
806         #
807
808         for host in $IPSECHOSTS
809         do
810             eval HOSTLOGIN=root@\$ipv4_${host}
811             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv' \
812                 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
813         done
814
815
816         ##########################################################################
817         # stop tcpdump if necessary
818         #
819
820         for host in $TCPDUMPHOSTS
821         do
822             if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
823             then
824                         stop_tcpdump $host
825             fi
826             eval HOSTLOGIN=root@\$ipv4_${host}
827                 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
828                         $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
829         done
830
831         ##########################################################################
832         # remove database directory if needed
833         #
834
835         for host in $DBHOSTS
836         do
837                 eval HOSTLOGIN=root@\$ipv4_${host}
838             ssh $SSHCONF $HOSTLOGIN "umount $DBDIR; rm -r $DBDIR" > /dev/null 2>&1
839         done
840
841         ##########################################################################
842         # copy default host config back if necessary
843         #
844
845         $DIR/scripts/restore-defaults $testname
846
847
848         ##########################################################################
849         # write test status to html file
850         #
851         testend=$(date +%s)
852         let "testend -= teststart"
853         let "timetotal += testend"
854
855         if [ $STATUS = "passed" ]
856         then
857                 COLOR="green"
858                 log_status 0
859         else
860                 COLOR="red"
861                 log_status 1
862         fi
863
864         cat >> $TESTRESULTSHTML << @EOF
865   <tr>
866     <td>$testnumber</td>
867     <td><a href="$testname/index.html">$testname</a></td>
868     <td align="right">$testend</td>
869     <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
870   </tr>
871 @EOF
872         cat >> $SUBTESTSINDEX << @EOF
873   <tr>
874     <td>$testnumber</td>
875     <td><a href="$name/index.html">$name</a></td>
876     <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
877     <td>&nbsp;</td>
878   </tr>
879 @EOF
880
881
882         ##########################################################################
883         # remove any charon.pid files that still may exist
884         #
885
886         for host in $IPSECHOSTS
887         do
888             eval HOSTLOGIN=root@\$ipv4_${host}
889             ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo "    removed charon.pid on `hostname`"; fi'
890         done
891
892         if [ -n "$aborted" ]
893         then
894             break 2
895         fi
896
897     done
898
899 done
900
901
902 ##############################################################################
903 # finish the results html file
904 #
905
906 cat >> $TESTRESULTSHTML << @EOF
907     <tr>
908       <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
909     </tr>
910     <tr>
911       <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
912     </tr>
913     <tr>
914       <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
915     </tr>
916     <tr>
917       <td><b>Time [s]</b></td><td><b><font color="blue">$timetotal</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
918     </tr>
919   </table>
920 </body>
921 </html>
922 @EOF
923
924 if [ $subdir_cnt != 0 ]
925 then
926 cat >> $INDEX << @EOF
927       <td align="right">$subdir_cnt</td>
928       <td>&nbsp;</td>
929     </tr>
930 @EOF
931 fi
932
933 let "all_cnt = $passed_cnt + $failed_cnt"
934
935 cat >> $INDEX << @EOF
936     <tr>
937       <td>&nbsp;</td>
938       <td><a href="all.html"><b>all</b></a></td>
939       <td align="right"><b>$all_cnt</b></td>
940       <td>&nbsp;</td>
941     </tr>
942     <tr>
943       <td><b>Failed</b></td>
944       <td>&nbsp;</td>
945       <td align="right"><b><font color="red">$failed_cnt</font></b></td>
946       <td>&nbsp;</td>
947     </tr>
948   </table>
949 </body>
950 </html>
951 @EOF
952
953 echo
954 echo_ok     "Passed : $passed_cnt"
955 echo_failed "Failed : $failed_cnt"
956
957 echo
958 echo "The results are available in $TODAYDIR"
959 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
960
961 ENDDATE=`date +%Y%m%d-%H%M-%S`
962 echo
963 echo "Finished : $ENDDATE"