Example

This is an example of a CGI program that we used to generate the license keys during the early part of the restructuring.

It would make sense to reproduce this with Flow. The logic can be simplified the role of the license generator reduced to something that can just be a function to call to get the license key. The HTML at the beginning could also be generated by Flow for consistency.

QUERY_STRING=id=FSDFSDFdsf&customer_id=acme&channels=100&iguanax=falselicense?id=FSDFSDFdsf&customer_id=acme&channels=100&iguanax=false

#!/bin/sh

echo "Content-Type: text/html"
echo ""

urldecode() {
    printf '%b' "$(echo "$1" | sed 's/+/ /g; s/%/\\x/g')"
}

get_param() {
    echo "$QUERY_STRING" |
        tr '&' '\n' |
        grep "^$1=" |
        head -n 1 |
        cut -d= -f2-
}

ID="$(urldecode "$(get_param id)")"
CUSTOMER_ID="$(urldecode "$(get_param customer_id)")"
CHANNELS="$(urldecode "$(get_param channels)")"
IGUANAX="$(urldecode "$(get_param iguanax)")"

echo "<html><body>"
echo "Iguana License Key"
echo "<pre>"

echo "ID=$ID"
echo "CUSTOMER_ID=$CUSTOMER_ID"
echo "CHANNELS=$CHANNELS"
echo "IGUANAX=$IGUANAX"
echo

if [ "$IGUANAX" = "true" ]; then
    /home/eliot/iguanax/IguanaLicense/IguanaLicense "$ID" "$CHANNELS" "$CUSTOMER_ID"
else
    /home/eliot/iguana6/IguanaLicense/IguanaLicense "$ID" "$CHANNELS" "$CUSTOMER_ID"
fi

echo "</pre>"
echo "</body></html>"