#!/bin/bash # Description: # This script is designed to update a text file based # apon text entered in an HTML form. It can be used in conjuction # with the script 'text2html-collab.sh' This script creates the # necessary HTML forms and links which will point to the current cgi-script # # This script has been based directly on the 'add-comment' cgi script # and the 'poseidon-text2html-forum.sh' # # Notes: # The web server must have 'write' permission to the file inorder # for this script to achieve anything. If the web-server does not # have 'write' permission the script does not complain but the # target file is not updated. # # Some HTML textareas, notably Netscape, return strings with neither # unix nor DOS line endings, but just \r characters. For this we will just # use a simple sed conversion. # # Bugs and Ideas: # # Many browsers do not refresh the web page when they should # Dependencies: # text2html-collab.sh # iso2html.sed (used by the above script) # procgi # This is a c program which extracts submitted HTML form values from the # posted or 'getted' data sent by the web-visitors browser. This program # was found somewhere on the Internet. # See Also: # plaintext2html.sh, # Converts a plain text style document into HTML with links and a table of contents # plaintext2pdf.sh, # Converts the same type of document into PDF using the 'htmldoc' program # plaintext2html-forum.sh # Converts a document as above but allows the web-visitor to make contributions # via a CGI script called 'add-comment' # linkdoc2html.sh # Converts a text document which consists of a list of URLs and descriptions into # a hyperlinked HTML document # diary2html.sh # Converts a 'diary style' plain text document into HTML. A diary is just a # series of dates and description for those dates # linkdoc2html-index.sh, # linkdoc2html-forum.sh # Similar to the 'plaintext2html-forum.sh' script but operates on 'linkdocs' as # described above. # add-comment # A CGI script which adds a user supplied comment to a text file and regenerates an # HTML file using one of the '2html' scripts described here. The script uses a # utility called 'procgi' or 'proccgi' which extracts submitted HTML form values. # Author: # mjb # Bugs: # This script will probably currently fail for strangely named text files. In particular # text files which follow the HTML internationalizing naming convention (for use with # the 'language negotiation' feature, or 'content negotiation' feature of web-servers # and web-browsers) such as 'index.html.en'. This script will probably mangle the # name of the generated HTML file. # # If at any stage the form values are passed around 'unprotected', that is, unenclosed # in double quotes, then bash shell special characters will get 'expanded'. For example # the * character will be 'globbed', which means expanded to the listing of the current # directory. This means that the files will suddenly have directory listings inserted in # them, which is not at all good # # The line below parses the querystring or posted environment # variables. It uses a program which was found at. # http://www.fpx.de/fp/Software/ProcCGIsh.html # #-- The eval is expanding * characters as directory listings, according to the bash #-- shell. This needs to be stopped somehow #eval "`./procgi $* | sed 's/\*/{{:star:}}/g'`" sPostedString=$(/home/cgi-bin/procgi $* | sed 's/\*/{{:star:}}/g') echo "Content-type: text/html" echo "" # This second empty echo line IS necessary. A 'server error' will # be generated by the web-server if it is not present. #-- To see exactly what the procgi program is passing to this script you can #-- use the following line #/home/cgi-bin/procgi $* #echo $sPostedString #echo "
REQUEST_METHOD=$REQUEST_METHOD
HTTP_REFERER=$HTTP_REFERER
SERVER_NAME=$SERVER_NAME
sFileName=$sFileName
sDocumentText=$sDocumentText
sUserName=$sUserName
sDebug=$sDebug
"
exit 1;
fi
if [ "$sFileName" = "" ]
then
echo ""
echo "
"
echo "$sDocumentText" | sed "l"
echo ""
fi
echo
fi
if [ "$sUserName" = "" ]
then
sUserName="[anonymous]"
fi
#-- The date string below gives a full text date, with weekday and AM/PM time
#-- The code below attempts to add the last comment immediately under the
#-- comment tag.
cp $sFileName $sFileName.previous
#-- Preserve the old version of the file, just in case something goes terribly
#-- wrong. For example, if the web-server does not have permission to write to
#-- the directory in the which the text file resides, then the 'cp' command wont
#-- work, and nor will the lines below. Back to the drawing board.
datetag=$(date "+%d%B%Y-%I-%M%p")
cp $sFileName $sFileName.$datetag
# echo "last modified on $(date '+%A, %d %B %Y, %I:%M %p')"
# The web server needs write permissions on the directory.
# echo "sHtmlFileName=$sHtmlFileName"
if [ "$sSourceDocumentType" = "collab" ]
then
/usr/local/bin/text2html-collab.sh $sFileName notran > $sHtmlFileName
elif [ "$sSourceDocumentType" = "plaintext" ]
then
/usr/local/bin/plaintext2html-forum.sh $sFileName > $sHtmlFileName
else
/usr/local/bin/plaintext2html-forum.sh $sFileName > $sHtmlFileName
fi
#-- Watch out for special 'sed' characters in the sScriptResultMessage variable
#-- The translation link wont work from with the cgi directory
#cat $sHtmlFileName
sScriptResultMessage=" \
El documento ha sido puesto al día. Dentro de 15 segundos \
vas a ser traido automaticamente atrás. Tal vez, los cambios tu \
has hecho no van a aparecer en el página web hasta que tu \
pulses el boton 'actualizar' en tu hojeador. Incluso, en algunos hojeadores \
tu necesitas cerrar y abrir tu hojeador para que tu puedas ver los cambios \
(perdon por este rollo) \
Gracias