#!/bin/sh set -eu # parse config file . /etc/cryptobox/cryptobox.conf function get_cgi_param() # parse the query string for a parameter { # thttpd does not set query string if it is empty set | grep -q "^QUERY_STRING=" || return 0 # filter the value echo "$QUERY_STRING" | sed 's/&/\n/g' | grep "^$1=" | cut -d '=' -f 2- } function header() { echo "Content-Type: text/html" echo echo ' CryptoBox ' echo "

Main page

" # nav bar echo '
' list_groups4generate echo '
' echo '
' list_groups4display echo '
' echo '


' if [ -n "$GROUP" ] then echo '
' list_cases "$GROUP" echo '
' fi echo '
' } function footer() { echo '
' echo '' } function list_groups4generate() { echo '

Generate report: ' local list=$($VALIDATE_SCRIPT list) if [ -z "$list" ] then echo 'none' else for a in $list do echo "$a " done fi echo '

' } function list_groups4display() { echo '

View generated report: ' local list=$(find "$REPORT_DIR" -type d -mindepth 1 -maxdepth 1 | sort | while read a do echo $(basename "$a"); done) if [ -z "$list" ] then echo 'none available' else for a in $list do echo "$a " done fi echo '

' } function list_cases() # parameter: group { echo '

' if [ -d "$REPORT_DIR/$1" ] then find "$REPORT_DIR/$1" -type f -name \*.html | while read a; do basename "${a%.html}"; done | sort | while read a do echo "$a
" done fi echo '

' } function display_case() # parameter: group case { local FILE="$REPORT_DIR/$1/${2}.html" if [ -e "$FILE" ] then cat "$FILE" | sed '1,//,$d' else echo "

File ($FILE) not found!

" fi } ########### main ############## ACTION=$(get_cgi_param action) GROUP=$(get_cgi_param group) CASE=$(get_cgi_param case) header if [ ! -e "$DEV_FEATURES_SCRIPT" ] then echo '

This action is only availbale for a development CryptoBox-CD.

' elif [ "$ACTION" = "generate" -a -n "$GROUP" ] then $VALIDATE_SCRIPT check "$GROUP" /dev/null & echo '

Validation will take some minutes ...

' elif [ "$ACTION" = "display" ] then if [ -n "$GROUP" -a -n "$CASE" ] then display_case "$GROUP" "$CASE" elif [ -n "$GROUP" ] then display_case "$GROUP" "summary" fi else [ -n "$ACTION" ] && echo "

Unknown action ($ACTION)!

" fi footer