| oct96.tar |
Listing 1: mail2html
#! /bin/bash - # MAIL2HTML - Changing mail messages to HTML files # This scripts gets a mail message through standard input, parses a # "__PARAMS__" field on top of message for parameters (title, heading, # filename to be created and language to be used) and creates an HTML file # encapsulating it in site-standard headers and footers. # File maybe later moved to final on-line location. # Processing is made using a guest account (non-privileged), in order to # minimize security risks. # A Logfile is maintained with all entries logged on mail sender, file # created, and time. # # Luca Salvadori <lsalvadori@aeroweb.laben.it> - June 1996 # # HISTORY # v.1.0 - June 1996 # Basic behaviour # Defining temporary file and other variables # # TODO's # - Check on parameters syntax # - Check on existence of destination directory, to be eventually created # # Initialize variables and constants PATH=~truser/public_html/work/scripts:$PATH export PATH ME=truser # Non-privileged user for doing the work... ROOT=~$ME/public_html/work # ... and his homedir TMPFILE=tmp.$$ # Temporary file to work on PARAMS=params.$$ # Parameters file MAILHEADER=mailheader.$$ # Mail headers file TMPDIR=/tmp # Scratch directory LOGFILE=`eval echo ~$ME/mail2html.log` # Logfile ERRORFILE=`eval echo ~$ME/mail2html.err` # Error file DATE=`date` # Actual processing time TRUSER=truser@host.domain.it # Trusted user allowed to process mail from # # Changing to working directory cd $TMPDIR # Capturing standard input to scratch file cat > $TMPFILE # Extracting mail headers in MAILHEADER file # tags. ed -s $TMPFILE << END /^$/ 1,.-1w $MAILHEADER Q END # Getting sender name SENDER=`cat $MAILHEADER | tr [:upper:] [:lower:] | grep "^from:" | cut -d" " -f2 | tr -d "<>"` # Checking is sender is a trusted user if [ $SENDER != $TRUSER ] then echo "REJECTED: Mail coming from untrusted user $SENDER - $DATE" >> $ERRORFILE mail $TRUSER -s "Security alarm from MAIL2HTML" << END SECURITY ALERT FROM MAIL2HTML -------------------------------------- Untrusted user $SENDER attempted to process a mail file through MAIL2HTML at $DATE. Submitted message follows: `cat $TMPFILE` END # Now, clean up and exit [ -f $TMPFILE ] && rm $TMPFILE [ -f $PARAMS ] && rm $PARAMS [ -f $MAILHEADER ] && rm $MAILHEADER exit fi # Extracting $PARAMS file, saving lines between BEGIN_PARAMS and # END_PARAMS tags. ed -s $TMPFILE << END /^BEGIN_PARAMS$/ 1,.d /^END_PARAMS$/ 1,.-1w $PARAMS Q END # Extracting working parameters from $PARAMS file. TITLE=`cat $PARAMS | grep "^T=" | cut -d"=" -f2-` HEADING=`cat $PARAMS | grep "^H=" | cut -d"=" -f2-` FILE=`cat $PARAMS | grep "^F=" | cut -d"=" -f2-` FILE=`eval echo $ROOT/$FILE` LANG=`cat $PARAMS | grep "^L=" | cut -d"=" -f2-` # Getting rid of mail and PARAMS headers and saving file back ed -s $TMPFILE << END /^END_PARAMS$/ 1,.d w q END # Build the file with headers and footers, substituting titles and other # stuff build $TMPFILE $LANG ed -s $TMPFILE << END />TITLE</ .s/>TITLE</>$TITLE</ 1 />HEADING</ .s/>HEADING</>$HEADING</ w q END # # Now, move the file to final destination and add an entry in logfile mv $TMPFILE $FILE && echo From $SENDER - Received file $FILE at $DATE. >> $LOGFILE # Now, clean up and exit [ -f $TMPFILE ] && rm $TMPFILE [ -f $PARAMS ] && rm $PARAMS [ -f $MAILHEADER ] && rm $MAILHEADER exit ------------------------------------------------------------ STANDARD HEADER (English version) <HTML> <TITLE>TITLE</TITLE> <BODY BGCOLOR="#ff ff ff" TEXT="#00 00 88"> <H1><IMG SRC = "/gifs/awb.gif" align = "middle">HEADING</H1> ------------------------------------------------------------ STANDARD HEADER (Italian version) <HTML> <TITLE>TITLE</TITLE> <BODY BGCOLOR="#ff ff ff" TEXT="#00 00 88"> <H1><IMG SRC = "/gifs/awb.gif" align = "middle">HEADING</H1> ------------------------------------------------------------ STANDARD FOOTER (English version) <HR> <A HREF = "/en/index.htm"><IMG SRC = "/gifs/back.gif" >Back to AeroWEB Home Page</A> <P> <HR><I><ADDRESS>Wish to appear on AeroWEB? Contact us via e-mail at <A HREF = "mailto:info@aeroweb.lucia.it">Info@Aeroweb.lucia.it</A></ADDRESS></><P > <HR> For any comment on this page: <A HREF = "mailto:WebMaster@aeroweb.lucia.it">WebMaster.</A> <P> <I><ADDRESS><IMG SRC = "/gifs/linux.gif" > This server is powered by LINUX, the first free UNIX &trade Operating System for INTEL 80x86 Processors (and beyond).</ADDRESS></I><P> <I><ADDRESS>AeroWEB © 00/00/0000</ADDRESS></I> </BODY> </HTML> ------------------------------------------------------------ STANDARD FOOTER (Italian version) <HR> <A HREF = "/it/index.htm"><IMG SRC = "/gifs/back.gif" align = "middle">Ritorno alla AeroWEB Home Page</A> <P> <I><ADDRESS>Se siete interessati a comparire su AeroWEB potete contattarci direttamente via <A HREF = "mailto:info@aeroweb.lucia.it">Email ad Info@Aeroweb.lucia.it</A></ADDRESS></I><P> <HR> Per ogni commento su questa pagina: <A HREF = "mailto:WebMaster@aeroweb.lucia.it">WebMaster.</A> <P> <I><ADDRESS><IMG SRC = "/gifs/linux.gif" > Questo server gira su LINUX, il primo Sistema Operativo UNIX di pubblico dominio per processori INTEL 80x86 (ed oltre).</ADDRESS></I><P> <I><ADDRESS>AeroWEB © 00/00/0000</ADDRESS></I> </BODY> </HTML> <lsalvadori@batman.laben.it> INCLUDED FILES: build setdate setvar issue mail2html top_en.htm top_it.htm bot_en.htm bot_it.htm # End of File
|