2021-03-04 19:55:51 +00:00
#!/bin/bash
#User input parameters:
#$1 filter start date 'yyyy-mm-dd'
#$2 filter end date 'yyyy-mm-dd'
2021-03-16 14:16:17 +00:00
#$3 ACA address, default is localhost if not given
2021-03-04 19:55:51 +00:00
2021-05-04 17:46:09 +00:00
#check for getopt(1) on local system
getopt --test > /dev/null
if [ [ ${ PIPESTATUS [0] } -ne 4 ] ]
then
echo "getopt is required to use this script, please ensure installation!"
else
echo "getopt detected"
2021-03-16 14:16:17 +00:00
fi
2021-05-04 17:46:09 +00:00
#set parameter names and call getopts on inputsi, then parse/assign arguments
2021-05-19 21:48:10 +00:00
SHORTOPTS = d:e:i:ypm:s:jh
LONGOPTS = start-date:,end-date:,ip:,system-only,component-only,manufacturer:,serial:,json,help
2021-05-04 17:46:09 +00:00
PARSED = $( getopt --options= $SHORTOPTS --longoptions= $LONGOPTS --name " $0 " -- " $@ " )
if [ [ ${ PIPESTATUS [0] } -ne 0 ] ]
then
exit 2
fi
eval set -- " $PARSED "
startDate =
endDate =
ip = localhost
system =
component =
manufacturer =
serial =
2021-05-19 21:48:10 +00:00
json =
2021-05-10 17:53:18 +00:00
2021-05-19 21:48:10 +00:00
helpText = "\n\n\nHELP MENU\n\nThe following options are available:\n-d|--start-date\t\t<yyyy-mm-dd>\tDefault: 1970-01-01\tThe earliest date to return validation reports from.\n"
helpText += "-e|--end-date\t\t<yyyy-mm-dd>\tDefault: current time\tThe latest date to return validation reports from.\n"
helpText += "-i|--ip\t\t\t<ACA address>\tDefault: localhost\tThe IP address where the ACA is located.\n"
helpText += "-y|--system-only\t\t\t\t\t\tReturn only system information from validation reports.\n"
helpText += "-p|--component-only\t\t\t\t\t\tReturn only component information from validation reports.\n"
2021-05-10 17:53:18 +00:00
helpText += "-m|--manufacturer\t<manufacturer's name>\t\t\tReturn only the validation report of the device from this manufacturer.\n"
helpText += "-s|--serial\t\t<serial number>\t\t\t\tReturn only the validation report of the device with this serial number.\n"
2021-05-19 21:48:10 +00:00
helpText += "-j|--json\t\t\t\t\t\t\tReturn output in JSON format. Only --start-date, --end-date,\n\t\t\t\t\t\t\t\tand --ip parameters are read with this option, all others are ignored.\n"
2021-05-10 17:53:18 +00:00
2021-05-04 17:46:09 +00:00
while true
do
case " $1 " in
2021-05-19 21:48:10 +00:00
-d| --start-date)
2021-05-04 17:46:09 +00:00
startDate = " $2 "
shift 2
; ;
2021-05-19 21:48:10 +00:00
-e| --end-date)
2021-05-04 17:46:09 +00:00
endDate = " $2 "
shift 2
; ;
2021-05-19 21:48:10 +00:00
-i| --ip)
2021-05-04 17:46:09 +00:00
ip = " $2 "
shift 2
; ;
2021-05-19 21:48:10 +00:00
-y| --system-only)
2021-05-04 17:46:09 +00:00
system = true
shift
; ;
2021-05-19 21:48:10 +00:00
-p| --component-only)
2021-05-04 17:46:09 +00:00
component = true
shift
; ;
-m| --manufacturer)
manufacturer = " $2 "
shift 2
; ;
-s| --serial)
serial = " $2 "
shift 2
; ;
2021-05-19 21:48:10 +00:00
-j| --json)
json = true
shift
; ;
2021-05-10 17:53:18 +00:00
-h| --help)
printf " $helpText "
exit 0
; ;
2021-05-04 17:46:09 +00:00
--)
shift
break
; ;
*)
echo "Programming error"
exit 3
; ;
esac
done
#call ACA for validation report
endpoint = " https:// $ip :8443/HIRS_AttestationCAPortal/portal/validation-reports "
2021-03-16 14:16:17 +00:00
echo " $endpoint "
2021-03-04 19:55:51 +00:00
content = $( curl --insecure $endpoint /list)
2021-05-10 17:53:18 +00:00
#Parse JSON response for create times and device names
2021-03-04 19:55:51 +00:00
rawTimes = $( jq -r '.data | map(.createTime | tostring) | join(",")' <<< " $content " )
createTimes = ""
for i in ${ rawTimes //,/ }
do
createTimes += " $( date -u +"%Y-%m-%d %H:%M:%S" -d @" $(( $i / 1000 )) " ) , "
done
deviceNames = $( jq -r '.data | map(.device.name) | join(",")' <<< " $content " )
2021-05-10 17:53:18 +00:00
2021-03-04 19:55:51 +00:00
echo " Create times: $createTimes "
echo " Device names: $deviceNames "
2021-05-19 21:48:10 +00:00
curlData = " dateStart= $startDate &dateEnd= $endDate &createTimes= $createTimes &deviceNames= $deviceNames "
if [ [ " $json " = true ] ]
then
curlData += "&json=true"
else
curlData += " &system= $system &component= $component &manufacturer= $manufacturer &serial= $serial "
fi
curl --data " $curlData " --insecure $endpoint /download