#! /bin/sh

# Copyright (c) 2003-2016
# Distributed Systems Software.  All rights reserved.
# See the file LICENSE for redistribution information.
#
# $Id: gridlogin 2873 2016-03-12 18:54:40Z brachman $

# This illustrates how a jurisdiction might construct a login page for
# use with auth_grid/local_grid_authenticate.
# To use it, you will need to change the value of DACS_JURIDICTION to the name
# of your authenticating jurisdiction and you may also need to change some
# paths.
#
# Note: it assumes that all grids are the same size because it does not
# know the username at the time it gets a challenge, so it cannot know
# the dimensions of that user's grid.  A real implementation might first get
# the username and then ask auth_grid for a challenge that is correct for that
# user's grid (if any).  Or, it might retrieve the dimensions of that user's
# grid (if any), build the correct arguments for auth_grid without passing the
# username, and then obtain and display a challenge.  In any case, some
# JavaScript glue must do this.

# Change these paths if necessary
challenge=`/usr/local/dacs/bin/auth_grid -uj DSS-dacs -clen 3 -challenge`
token=`/usr/local/dacs/bin/auth_grid -uj DSS-dacs -enc "${challenge}"`

echo 'Content-type: text/html'
echo ''
echo '<html><head><title>DACS Login</title>'
echo '<META HTTP-EQUIV="expires" CONTENT="0">'
echo '<META HTTP-EQUIV="pragma" CONTENT="no-cache">'
echo '<META HTTP-EQUIV="cache-control" CONTENT="no-cache">'
echo '</head>'

echo '<body>'

echo '<h2>DACS Login</h2>'
echo '<form method="post" action="/cgi-bin/dacs/dacs_authenticate">'
echo '<input type="hidden" name="DACS_JURISDICTION" value="DSS-dacs"/>'
echo '<input type="hidden" name="ENABLE_AUTH_HANDLERS" value="1"/>'
echo '<input type="hidden" name="DACS_BROWSER" value="1"/>'
echo "<input type=\"hidden\" name=\"AUXILIARY\" value=\"${token}\"/>"
echo '<table width="100%" cellspacing="10" cellpadding="0">'
echo '<tr>'
echo '<td width="15%"><font size="+1"><b>User Name</b>:</font></td>'
echo '<td width="30%"><input type="text" size="20" name="USERNAME"></td>'
echo '<td align="left">&nbsp;</td>'
echo '</tr>'

echo '<tr>'
echo '<td width="15%"><font size="+1"><b>Challenge</b>:</font></td>'
echo "<td width=\"30%\"><font size=\"+1\"><tt><b>${challenge}</b></tt></font></td>"
echo '<td align="left">&nbsp;</td>'
echo '</tr>'

echo '<tr>'
echo '<td width="15%"><font size="+1"><b>Password</b>:</font></td>'
echo '<td width="30%"><input type="password" size="20" name="PASSWORD"></td>'
echo '</tr>'

echo '<tr>'
echo '<td width="15%"></td>'
echo '<td width="30%"><font size="-1"><b>(If you have a PIN, enter it first)</b></font></td>'
echo '</tr>'

echo '<tr>'
echo '<td align="left"><input type="submit" value="Login"></td>'
echo '</tr>'
echo '</table>'

echo '</form>'

echo '</body>'

echo '</html>'

exit 0
