|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Downloads a ZAP XML report from a URL and saves it to the results/ directory. |
| 4 | +# After downloading, run createScorecards.sh to generate the scorecard. |
| 5 | +# |
| 6 | +# Usage: scripts/fetchZAPResults.sh <ZAP_REPORT_URL> [OUTPUT_FILENAME] |
| 7 | +# |
| 8 | +# Examples: |
| 9 | +# scripts/fetchZAPResults.sh http://172.17.0.3:8090/OTHER/core/other/xmlreport/ |
| 10 | +# scripts/fetchZAPResults.sh "http://zap:8090/OTHER/core/other/xmlreport/?apikey=abc123" |
| 11 | +# scripts/fetchZAPResults.sh http://zap:8090/OTHER/core/other/xmlreport/ my-zap-results.xml |
| 12 | + |
| 13 | +source scripts/requireCommand.sh |
| 14 | + |
| 15 | +requireCommand curl |
| 16 | + |
| 17 | +if [ $# -eq 0 ]; then |
| 18 | + echo "Usage: $0 <ZAP_REPORT_URL> [OUTPUT_FILENAME]" |
| 19 | + echo "" |
| 20 | + echo "Downloads a ZAP XML report from the given URL and saves it to results/." |
| 21 | + echo "After downloading, run createScorecards.sh to generate the scorecard." |
| 22 | + echo "" |
| 23 | + echo "Examples:" |
| 24 | + echo " $0 http://172.17.0.3:8090/OTHER/core/other/xmlreport/" |
| 25 | + echo " $0 \"http://zap:8090/OTHER/core/other/xmlreport/?apikey=abc123\"" |
| 26 | + echo " $0 http://zap:8090/OTHER/core/other/xmlreport/ my-zap-results.xml" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +zap_url="$1" |
| 31 | + |
| 32 | +if [ $# -ge 2 ]; then |
| 33 | + filename="$2" |
| 34 | +else |
| 35 | + benchmark_version=$(scripts/getBenchmarkVersion.sh) |
| 36 | + date_stamp=$(date +%Y%m%d) |
| 37 | + filename="Benchmark_${benchmark_version}-ZAP-${date_stamp}.xml" |
| 38 | +fi |
| 39 | + |
| 40 | +output="results/${filename}" |
| 41 | + |
| 42 | +echo "Downloading ZAP report from: ${zap_url}" |
| 43 | +http_code=$(curl -sS -o "${output}" -w '%{http_code}' --connect-timeout 10 --max-time 120 "${zap_url}") |
| 44 | + |
| 45 | +if [ "${http_code}" -ne 200 ]; then |
| 46 | + echo "ERROR: Download failed with HTTP status ${http_code}" |
| 47 | + rm -f "${output}" |
| 48 | + exit 1 |
| 49 | +fi |
| 50 | + |
| 51 | +if ! head -2 "${output}" | grep -q "OWASPZAPReport"; then |
| 52 | + echo "ERROR: Downloaded file does not appear to be a ZAP XML report." |
| 53 | + echo "First 3 lines of downloaded content:" |
| 54 | + head -3 "${output}" |
| 55 | + rm -f "${output}" |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +echo "ZAP report saved to: ${output}" |
| 60 | +echo "To generate the scorecard, run: ./createScorecards.sh" |
0 commit comments