Merge commit 'child-sa-rekey-tkm'
[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                         next
426                 }
427                 printf("cmd_err=\044(tempfile -p test -s err); ")
428                 if (command == "tcpdump")
429                 {
430                         printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
431                         printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"); ", host, pattern)
432                 }
433                 else
434                 {
435                         printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s %s 2>\044cmd_err | grep \"%s\"); ",  host, command, pattern)
436                 }
437                 printf("cmd_exit=\044?; ")
438                 printf("cmd_fail=0; ")
439                 if (hit ~ /^[0-9]+$/)
440                 {
441                         printf("if [ \044(echo \"\044cmd_out\" | wc -l) -ne %d ] ", hit)
442                 }
443                 else
444                 {
445                         printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\"  ] ", hit)
446                         printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
447                 }
448                 printf("; then STATUS=\"failed\"; cmd_fail=1; fi; \n")
449
450                 printf("if [ \044cmd_fail -ne 0 ]; then echo \"~~~~~~~ FAIL ~~~~~~~\"; fi; \n")
451                 if (command == "tcpdump")
452                 {
453                         printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047  [%s]\"; ", host, pattern, hit)
454                 }
455                 else
456                 {
457                         printf("echo \"%s# %s | grep \047%s\047  [%s]\"; ", host, command, pattern, hit)
458                 }
459                 printf("if [ -n \"\044cmd_out\" ]; then echo \"\044cmd_out\"; fi; \n")
460                 printf("cat \044cmd_err; rm -f -- \044cmd_err; \n")
461                 printf("if [ \044cmd_fail -ne 0 ]; then echo \"~~~~~~~~~~~~~~~~~~~~\"; fi; \n")
462                 printf("echo; ")
463         }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
464
465
466         ##########################################################################
467         # log statusall and listall output
468         # get copies of ipsec.conf, ipsec.secrets
469         # create index.html for the given test case
470
471         cat > $TESTRESULTDIR/index.html <<@EOF
472 <html>
473 <head>
474   <title>Test $testname</title>
475 </head>
476 <body>
477 <table border="0" cellpadding="0" cellspacing="0" width="600">
478   <tr><td>
479     <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
480     <h2>Test $testname</h2>
481     <h3>Description</h3>
482 @EOF
483
484         cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
485
486         cat >> $TESTRESULTDIR/index.html <<@EOF
487     <ul>
488       <li><a href="console.log">console.log</a></li>
489     </ul>
490     <img src="../../images/$DIAGRAM" alt="$VIRTHOSTS">
491 @EOF
492
493         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"
494         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"
495
496         if [ -n "$IPV6" ]
497         then
498             IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
499             IPROUTE_DSP=$IPROUTE_CMD
500             IPTABLES_CMD="$IPTABLES_CMD_V6"
501             IPTABLES_DSP="ip6tables -L"
502             IPTABLES_SAVE_CMD="ip6tables-save"
503             IPTABLES_SAVE_DSP="ip6tables-save"
504         else
505             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
506             IPROUTE_DSP=$IPROUTE_CMD
507             IPTABLES_CMD="$IPTABLES_CMD_V4"
508             IPTABLES_DSP="iptables -L"
509             IPTABLES_SAVE_CMD="iptables-save"
510             IPTABLES_SAVE_DSP="iptables-save"
511         fi
512
513         if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
514         then
515             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
516             IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
517             IPTABLES_CMD="$IPTABLES_CMD_V4; echo; $IPTABLES_CMD_V6"
518             IPTABLES_DSP="iptables -L ; ip6tables -L"
519             IPTABLES_SAVE_CMD="iptables-save; echo; ip6tables-save"
520             IPTABLES_SAVE_DSP="iptables-save ; ip6tables-save"
521         fi
522
523         for host in $DBHOSTS
524         do
525             eval HOSTLOGIN=root@\$ipv4_${host}
526
527                 scp $SSHCONF $HOSTLOGIN:/etc/db.d/ipsec.sql \
528                     $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
529         done
530
531         for host in $IPSECHOSTS
532         do
533             eval HOSTLOGIN=root@\$ipv4_${host}
534
535                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
536                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
537                 if [  -n "$SWANCTL" ]
538                 then
539                         scp $SSHCONF $HOSTLOGIN:/etc/swanctl/swanctl.conf \
540                         $TESTRESULTDIR/${host}.swanctl.conf  > /dev/null 2>&1
541
542                         for subsys in conns algs certs pools authorities sas pols
543                         do
544                                 ssh $SSHCONF $HOSTLOGIN swanctl --list-$subsys \
545                                         > $TESTRESULTDIR/${host}.swanctl.$subsys 2>/dev/null
546                         done
547
548                         ssh $SSHCONF $HOSTLOGIN swanctl --stats \
549                                 > $TESTRESULTDIR/${host}.swanctl.stats 2>/dev/null
550
551                         echo "" >> $TESTRESULTDIR/${host}.swanctl.sas
552                         cat $TESTRESULTDIR/${host}.swanctl.pols >> \
553                                 $TESTRESULTDIR/${host}.swanctl.sas
554                         cat $TESTRESULTDIR/${host}.swanctl.algs >> \
555                                 $TESTRESULTDIR/${host}.swanctl.stats
556                 else
557                     for file in ipsec.conf ipsec.secrets
558                     do
559                                 scp $SSHCONF $HOSTLOGIN:/etc/$file \
560                             $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
561                     done
562
563                     for command in statusall listall
564                     do
565                                 ssh $SSHCONF $HOSTLOGIN ipsec $command \
566                             > $TESTRESULTDIR/${host}.$command 2>/dev/null
567                     done
568                 fi
569
570                 if (! [ -f $TESTRESULTDIR/${host}.ipsec.sql ] ) then
571                         scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
572                                 $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
573                 fi
574
575             ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
576                     > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
577             ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
578                     > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
579             ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
580                     > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
581             ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
582                     > $TESTRESULTDIR/${host}.iptables 2>/dev/null
583                 ssh $SSHCONF $HOSTLOGIN $IPTABLES_SAVE_CMD \
584                     > $TESTRESULTDIR/${host}.iptables-save 2>/dev/null
585             chmod a+r $TESTRESULTDIR/*
586
587                 if [ -n "$SWANCTL" ]
588                 then
589                     cat >> $TESTRESULTDIR/index.html <<@EOF
590     <h3>$host</h3>
591       <table border="0" cellspacing="0" width="600">
592       <tr>
593         <td valign="top">
594           <ul>
595             <li><a href="$host.swanctl.conf">swanctl.conf</a></li>
596             <li><a href="$host.swanctl.conns">swanctl --list-conns</a></li>
597             <li><a href="$host.swanctl.certs">swanctl --list-certs</a></li>
598             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
599             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
600           </ul>
601         </td>
602         <td valign="top">
603           <ul>
604             <li><a href="$host.swanctl.sas">swanctl --list-sas|--list-pols</a></li>
605             <li><a href="$host.swanctl.pools">swanctl --list-pools</a></li>
606             <li><a href="$host.swanctl.authorities">swanctl --list-authorities</a></li>
607             <li><a href="$host.swanctl.stats">swanctl --stats|--list-algs</a></li>
608             <li><a href="$host.auth.log">auth.log</a></li>
609             <li><a href="$host.daemon.log">daemon.log</a></li>
610           </ul>
611       </td>
612         <td valign="top">
613           <ul>
614             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
615             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
616             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
617             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
618             <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
619           </ul>
620           &nbsp;
621       </td>
622     </tr>
623     </table>
624 @EOF
625
626                 else
627                     cat >> $TESTRESULTDIR/index.html <<@EOF
628     <h3>$host</h3>
629       <table border="0" cellspacing="0" width="600">
630       <tr>
631         <td valign="top">
632           <ul>
633             <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
634             <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
635             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
636             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
637           </ul>
638         </td>
639         <td valign="top">
640           <ul>
641             <li><a href="$host.statusall">ipsec statusall</a></li>
642             <li><a href="$host.listall">ipsec listall</a></li>
643             <li><a href="$host.auth.log">auth.log</a></li>
644             <li><a href="$host.daemon.log">daemon.log</a></li>
645           </ul>
646       </td>
647         <td valign="top">
648           <ul>
649             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
650             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
651             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
652             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
653             <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
654           </ul>
655       </td>
656     </tr>
657     </table>
658 @EOF
659                 fi
660         done
661
662         for host in $RADIUSHOSTS
663         do
664             eval HOSTLOGIN=root@\$ipv4_${host}
665
666             for file in clients.conf eap.conf radiusd.conf proxy.conf users
667             do
668                 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
669                     $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
670             done
671
672                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
673                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
674
675             scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
676                 $TESTRESULTDIR/${host}.radius.log  > /dev/null 2>&1
677
678             ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
679                 >> $TESTRESULTDIR/${host}.daemon.log 2>/dev/null
680
681             chmod a+r $TESTRESULTDIR/*
682             cat >> $TESTRESULTDIR/index.html <<@EOF
683     <h3>$host</h3>
684       <table border="0" cellspacing="0" width="600">
685       <tr>
686         <td valign="top">
687           <ul>
688             <li><a href="$host.clients.conf">clients.conf</a></li>
689             <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
690             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
691           </ul>
692         </td>
693         <td valign="top">
694           <ul>
695             <li><a href="$host.eap.conf">eap.conf</a></li>
696             <li><a href="$host.radius.log">radius.log</a></li>
697             <li><a href="$host.daemon.log">daemon.log</a></li>
698           </ul>
699       </td>
700         <td valign="top">
701           <ul>
702             <li><a href="$host.proxy.conf">proxy.conf</a></li>
703             <li><a href="$host.users">users</a></li>
704           </ul>
705       </td>
706     </tr>
707     </table>
708 @EOF
709
710         done
711
712         cat >> $TESTRESULTDIR/index.html <<@EOF
713         <h3>tcpdump</h3>
714         <ul>
715 @EOF
716
717         for host in $TCPDUMPHOSTS
718         do
719             cat >> $TESTRESULTDIR/index.html <<@EOF
720             <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
721 @EOF
722         done
723
724         cat >> $TESTRESULTDIR/index.html <<@EOF
725         </ul>
726 @EOF
727
728         cat >> $TESTRESULTDIR/index.html <<@EOF
729   </td></tr>
730 </table>
731 </body>
732 </html>
733 @EOF
734
735
736         ##########################################################################
737         # execute post-test commands
738         #
739
740         echo -n "post"
741         echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
742
743         eval `awk -F "::" '{
744             if ($1 !~ /^#.*/ && $2 != "")
745             {
746                 printf("echo \"%s# %s\"; ", $1, $2)
747                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
748                 printf("echo;\n")
749             }
750         }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
751
752         ##########################################################################
753         # check that IPsec state was cleaned up properly
754         #
755
756         for host in $IPSECHOSTS
757         do
758                 eval HOSTLOGIN=root@\$ipv4_${host}
759                 IPSECSTATE=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm state'`
760                 IPSECPOLICY=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm policy'`
761                 if [ -n "$IPSECSTATE" -o -n "$IPSECPOLICY" ]
762                 then
763                         echo -e "\n$host# ip xfrm state [NO]" >> $CONSOLE_LOG
764                         echo "$IPSECSTATE" >> $CONSOLE_LOG
765                         echo -e "\n$host# ip xfrm policy [NO]" >> $CONSOLE_LOG
766                         echo "$IPSECPOLICY" >> $CONSOLE_LOG
767                         STATUS="failed"
768                 fi
769         done
770
771
772         ##########################################################################
773         # make sure there were no leaks
774         #
775
776         for host in $STRONGSWANHOSTS
777         do
778                 eval HOSTLOGIN=root@\$ipv4_${host}
779                 LEAKS=`ssh $SSHCONF $HOSTLOGIN 'cat $LEAK_DETECTIVE_LOG 2>/dev/null | grep -v "No leaks detected.*"'`
780                 if [ -n "$LEAKS" ]
781                 then
782                         echo -e "\n$host# cat $LEAK_DETECTIVE_LOG [NO]" >> $CONSOLE_LOG
783                         echo "$LEAKS" >> $CONSOLE_LOG
784                         echo "<<< $host $LEAK_DETECTIVE_LOG >>>" >> $CONSOLE_LOG
785                         STATUS="failed"
786                 fi
787         done
788
789
790         ##########################################################################
791         # get a copy of /var/log/auth.log
792         #
793
794         for host in $IPSECHOSTS
795         do
796             eval HOSTLOGIN=root@\$ipv4_${host}
797             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv|pt-tls-client' \
798                 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
799         done
800
801
802         ##########################################################################
803         # get a copy of /var/log/daemon.log
804         #
805
806         for host in $IPSECHOSTS
807         do
808             eval HOSTLOGIN=root@\$ipv4_${host}
809             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv' \
810                 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
811         done
812
813
814         ##########################################################################
815         # stop tcpdump if necessary
816         #
817
818         for host in $TCPDUMPHOSTS
819         do
820             if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
821             then
822                         stop_tcpdump $host
823             fi
824             eval HOSTLOGIN=root@\$ipv4_${host}
825                 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
826                         $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
827         done
828
829         ##########################################################################
830         # remove database directory if needed
831         #
832
833         for host in $DBHOSTS
834         do
835                 eval HOSTLOGIN=root@\$ipv4_${host}
836             ssh $SSHCONF $HOSTLOGIN "umount $DBDIR; rm -r $DBDIR" > /dev/null 2>&1
837         done
838
839         ##########################################################################
840         # copy default host config back if necessary
841         #
842
843         $DIR/scripts/restore-defaults $testname
844
845
846         ##########################################################################
847         # set counters
848         #
849
850         if [ $STATUS = "failed" ]
851         then
852             let "failed_cnt += 1"
853         else
854             let "passed_cnt += 1"
855         fi
856
857
858         ##########################################################################
859         # write test status to html file
860         #
861         testend=$(date +%s)
862         let "testend -= teststart"
863         let "timetotal += testend"
864
865         if [ $STATUS = "passed" ]
866         then
867                 COLOR="green"
868                 log_status 0
869         else
870                 COLOR="red"
871                 log_status 1
872         fi
873
874         cat >> $TESTRESULTSHTML << @EOF
875   <tr>
876     <td>$testnumber</td>
877     <td><a href="$testname/index.html">$testname</a></td>
878     <td align="right">$testend</td>
879     <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
880   </tr>
881 @EOF
882         cat >> $SUBTESTSINDEX << @EOF
883   <tr>
884     <td>$testnumber</td>
885     <td><a href="$name/index.html">$name</a></td>
886     <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
887     <td>&nbsp;</td>
888   </tr>
889 @EOF
890
891
892         ##########################################################################
893         # remove any charon.pid files that still may exist
894         #
895
896         for host in $IPSECHOSTS
897         do
898             eval HOSTLOGIN=root@\$ipv4_${host}
899             ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo "    removed charon.pid on `hostname`"; fi'
900         done
901
902         if [ -n "$aborted" ]
903         then
904             break 2
905         fi
906
907     done
908
909 done
910
911
912 ##############################################################################
913 # finish the results html file
914 #
915
916 cat >> $TESTRESULTSHTML << @EOF
917     <tr>
918       <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
919     </tr>
920     <tr>
921       <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
922     </tr>
923     <tr>
924       <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
925     </tr>
926     <tr>
927       <td><b>Time [s]</b></td><td><b><font color="blue">$timetotal</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
928     </tr>
929   </table>
930 </body>
931 </html>
932 @EOF
933
934 if [ $subdir_cnt != 0 ]
935 then
936 cat >> $INDEX << @EOF
937       <td align="right">$subdir_cnt</td>
938       <td>&nbsp;</td>
939     </tr>
940 @EOF
941 fi
942
943 let "all_cnt = $passed_cnt + $failed_cnt"
944
945 cat >> $INDEX << @EOF
946     <tr>
947       <td>&nbsp;</td>
948       <td><a href="all.html"><b>all</b></a></td>
949       <td align="right"><b>$all_cnt</b></td>
950       <td>&nbsp;</td>
951     </tr>
952     <tr>
953       <td><b>Failed</b></td>
954       <td>&nbsp;</td>
955       <td align="right"><b><font color="red">$failed_cnt</font></b></td>
956       <td>&nbsp;</td>
957     </tr>
958   </table>
959 </body>
960 </html>
961 @EOF
962
963 echo
964 echo_ok     "Passed : $passed_cnt"
965 echo_failed "Failed : $failed_cnt"
966
967 echo
968 echo "The results are available in $TODAYDIR"
969 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
970
971 ENDDATE=`date +%Y%m%d-%H%M-%S`
972 echo
973 echo "Finished : $ENDDATE"