SVN Form Server HowTo

The following cgi script let’s a user create a personal SVN repository by leaving their email address. The corresponding svn checkout line is emailed automatically to that address.


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

echo '<html>'
echo '<head>'
echo '<title>SVN Registration Form</title>'
echo '</head>'
echo '<body>'

  echo "Dear user, <br>"
  echo "<br>"
  echo "to register with SVN please submit your email address:"
  echo "<br><br>"

  # create a html get action for a form
  echo "<form method=GET action=\"${SCRIPT}\">"\
       '  <tr><td>Email Address: </TD><TD><input type="text" name="VAL" size=30></td></tr>'\
       '<br><input type="submit" value="Submit Form"></form>'

  # make sure we have been invoked properly
  if [ "$REQUEST_METHOD" != "GET" ]; then
     echo "<hr>script error: cannot complete request<hr>"
     exit 1

  # if no search arguments, exit gracefully
  if [ -z "$QUERY_STRING" ]; then
     exit 0
     # extract the submitted data we are looking for with sed
     VAL=`echo "$QUERY_STRING" | sed -n 's/^.*VAL=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`

     VAL="${VAL/\%40/@}" # undo replacement of @ with %40
     VAL=`echo "$VAL" | sed "s/[^a-zA-Z0-9.@_\-]//g"` # remove all meta characters for safety

     if [ "${VAL/@gmail.com/}" == "$VAL" ]; then
        echo "We are sorry! <br>"\
             "The input \"<b>$VAL</b>\" is not a valid email address!"
        # create a new user account
        echo `date`: >> ~subversion/svnform_log # write log file
        ~subversion/svnaddrepo.sh "$VAL" "$VAL" >> ~subversion/svnform_log # call script in subversion's home
        echo "" >> ~subversion/svnform_log # write log file

        echo "Thank you! <br>"\
             "Please <b>check your email</b> for instructions how to access your newly created SVN repository!"

echo '</body>'
echo '</html>'

exit 0

The above script makes the following assumptions:

  • that all users have a valid email address @ gmail.com - other addresses will be rejected for safety reasons.
  • that the script is only accessible in a sub-net to limit the number of potential users to the ones with access to the sub-net.
  • that it is run by the user “subversion” as described by the suEXEC tutorial.
  • that it is installed with proper permissions (700) and ownership (subversion:_www).
  • that the script “svnaddrepo.sh” resides in the home of the user “subversion”, so that it can be started via suEXEC to actually create the repository and email the notification.
  • that Postfix is setup for GMail as described here.