#!/bin/bash
#	$Id: faxsurvey.sh.in,v 1.11 1996/06/24 03:03:39 sam Rel $
#
# Copyright (c) 1994-1995 Sam Leffler
# Copyright (c) 1994-1995 Silicon Graphics, Inc.
# 
# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
# 
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
# 
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

#
# User survey form for HylaFAX
#
PATH=/bin:/usr/bin
test -d /usr/sbin && PATH=$PATH:/usr/sbin		# SGI and others
test -d /usr/5bin && PATH=/usr/5bin:$PATH		# Sun and others
test -d /usr/local/bin && PATH=/usr/local/bin:$PATH	# for GNU stuff

SENDMAIL=/usr/sbin/sendmail
ECHO=/bin/echo
SED=/bin/sed
CAT=/bin/cat
UNQUOTE=/var/httpd/cgi-bin/unquote

$ECHO 'Content-type: text/html'
$ECHO ''

#
# Be careful here.
#
eval `$ECHO "$QUERY_STRING" | $UNQUOTE -qn | $SED 's/PATH=[^;]*;//g'`

echoMail()
{
    $ECHO "To: flexfax-survey@$ToAddr"
    $ECHO "Subject: Survey for $Vendor $Model from $RealName"
    $ECHO ""
    (for i in RealName Affiliation Mailaddr Address VoiceNumber FAXNumber
    do
	eval "test \"\$$i\" && $ECHO \"$i: \$$i\""
    done
    $ECHO "HostHardware: $HostHardware"
    $ECHO "HostOS: $HostOS"
    test "$Uname" && $ECHO "Uname: $Uname"
    $ECHO "ModemType: $ModemType"
    $ECHO "Vendor: $Vendor"
    $ECHO "Model: $Model"
    test "$ATFMDL" && $ECHO "ATFMDL: $ATFMDL"
    test "$ATFMFR" && $ECHO "ATFMFR: $ATFMFR"
    test "$ATFREV" && $ECHO "ATFREV: $ATFREV"
    $ECHO "PortDevice: $PortDevice"
    $ECHO "PortHardware: $PortHardware"
    $ECHO "FlowControl: $FlowControl"
    $ECHO "DCDHandling: $DCD"
    $ECHO "DTRHandling: $DTR"
    test "$ModemSettings" && $ECHO "ModemSettings: $ModemSettings"
    Inbound=
    for i in DATA FAX VOICE
    do
	eval "test \"\$${i}in\" && Inbound=\"\$Inbound $i\""
    done
    $ECHO "Inbound: $Inbound"
    Outbound=
    for i in DATA FAX VOICE
    do
	eval "test \"\$${i}out\" && Outbound=\"\$Outbound $i\""
    done
    $ECHO "Outbound: $Outbound"
    for i in cu tip kermit login uucp slip ppp
    do
	eval "test \"\$$i\" && DATAapps=\"\$DATAapps $i\""
    done
    test "$DATAapps" && $ECHO "DATAapps: $DATAapps"
    $ECHO "HylaFAXVersion: $Version"
    $ECHO "HylaFAXFormat: $Format"
    $ECHO "HylaFAXSource: $FromWhere $FromWhereOther"
    test "$HylaFAXConfig" && $ECHO "HylaFAXConfig: $HylaFAXConfig") | $UNQUOTE
}

$CAT<<EOF
<HEAD>
<TITLE>HylaFAX Survey Submission</TITLE>
</HEAD>
EOF
#$ECHO '<PRE>';printenv; $ECHO '</PRE>'

if [ -z "$Mailaddr" ]; then
    $ECHO '<H1>Error: No E-mail Address Specified</H1>'
    $ECHO 'Your survey was not posted because you failed to'
    $ECHO 'fillin your electronic mail address.  Go back to the previous'
    $ECHO 'page, fill in the address, and resubmit your request.'
    exit
fi
test "$HostHardware" = "other" && HostHardware="$HostHardwareOther"
if [ -z "$HostHardware" ]; then
    $ECHO '<H1>Error: No Host Hardware Configuration Specified</H1>'
    $ECHO 'You did not specify the host hardware configuration.'
    $ECHO 'Please return to the survey form and select the hardware'
    $ECHO 'configuration you are using to run HylaFAX.'
    exit
fi
test "$HostOS" = "other" && HostOS="$HostOSOther"
if [ -z "$HostOS" ]; then
    $ECHO '<H1>Error: No Host Operating System Specified</H1>'
    $ECHO 'You did not specify the host operating system.'
    $ECHO 'Please return to the survey form and select the operating'
    $ECHO 'system you are using to run HylaFAX.'
    exit
fi
if [ "$ModemType" = "internal" ]; then
    PortHardware=""
else
    test "$PortHardware" = "other" && PortHardware="$PortHardwareOther"
    if [ -z "$PortHardware" ]; then
	$ECHO '<H1>Error: No Serial Port Hardware Specified</H1>'
	$ECHO 'You indicated that you have an external modem, but you did'
	$ECHO 'not specify the serial port hardware that you use with your'
	$ECHO 'modem.  Please return to the survey form and select the'
	$ECHO 'appropriate port hardware you are using.'
	exit
    fi
fi
if [ -z "$Model" ]; then
    $ECHO '<H1>Error: No Modem Model Specified</H1>'
    $ECHO 'You did not specify the model of the modem you are using.'
    $ECHO 'Please return to the survey form and fillin this information.'
    exit
fi
if [ -z "$Vendor" ]; then
    $ECHO '<H1>Error: No Modem Vendor Specified</H1>'
    $ECHO "You did not specify the vendor that sells the $Model modem."
    $ECHO 'Please return to the survey form and fillin this information.'
fi
test "$Version" = "other" && Version="$VersionOther"
if [ -z "$Version" ]; then
    $ECHO '<H1>Error: No HylaFAX Version Specified</H1>'
    $ECHO 'You did not specify the version of the HylaFAX software that'
    $ECHO 'you are using.  Please return to the survey form and select'
    $ECHO 'the appropriate version.  If you are uncertain of the version,'
    $ECHO 'check <A HREF="/hylafax/README/index.html#Version">here</A> for information on'
    $ECHO 'how to determine which version you have.'
    exit
fi
test "$FromWhere" = "ftp" && FromWhereOther="$FromWhereFTP"
test "$FromWhere" = "inst" && FromWhereOther="$FromWhereInst"
case "$FromWhere" in
ftp|inst|other)
    if [ -z "$FromWhereOther"]; then
	$ECHO '<H1>Error: No From Location Specified</H1>'
	$ECHO "You indicated that you obtained HylaFAX by \"$FromWhere\", but you"
	$ECHO 'did not say where you got it from.  Please return to the survey'
	$ECHO 'and fill in the appropriate text field to describe where you'
	$ECHO 'the software.  If you got the software off a CD-ROM, then use the'
	$ECHO '<I>Other</I> text field area to identify the CD-ROM publication.'
	exit
    fi
    ;;
esac

if [ "$REQUEST_METHOD" = POST ]; then
    (echoMail | $SENDMAIL -oi -f$Mailaddr flexfax-survey@$ToAddr) || {
        $ECHO 'There was a problem posting your HylaFAX survey.'
        exit
    }
    $ECHO '<H1>HylaFAX Survey Posted</H1>'
    $ECHO "Your survey was successfully posted to flexfax-survey@$ToAddr."
    $ECHO 'All surveys are processed nightly; you should receive confirmation'
    $ECHO 'by mail when it has been recorded in the database.'
    $ECHO 'Thank you for your submission!'
    $ECHO "<P><ADDRESS>flexfax-survey-owner@$ToAddr</ADDRESS>"
else
    $ECHO '<H1>Prepared HylaFAX Survey</H1>'

    $ECHO '<PRE>'; echoMail; $ECHO '</PRE><HR>'

    $ECHO "<FORM METHOD=POST ACTION=\"http:$SCRIPT_NAME?$QUERY_STRING\">"
    $ECHO 'The above survey will be posted when you'
    $ECHO 'hit <INPUT TYPE=submit VALUE="Submit">.'
    $ECHO 'If there is something wrong, return to the survey form and correct'
    $ECHO 'it, then re-prepare the submission.'
fi
