tosapol@hotmail.com
[ Home ]
[ Education ]
[ Working ]
[ Hobbies ]
[ Software ]
[ Hardware ]
[ How-To ]
[ Link ]
[ mail ]
Light and tiny /cgi-bin/footer
for Apache, allowing to
- automatically append the file
current_dir/footer
if it exists
- replace the HTTP variables :
$VAR
replaced by Value of VAR
.
- count the access to the pages, in three ways :
- access
- The number of access to the page. No interest. Counter:
$ACCESS_ACCESS
- host
- The number of different hosts which have accessed to the page. Counter:
$ACCESS_HOST
- user
- The number of user with a
HTTP_COOKIE
defines. Counter: $ACCESS_USER
- set up the
DATE
variable to the date of last modification of
the page.
Apache configuration
httpd/conf/srm.conf:
# Or to do this for all HTML files, for example, use:
Action text/html /cgi-bin/footer
The code of /cgi-bin/footer
#!/bin/sh
FICHIER=$DOCUMENT_ROOT/$REDIRECT_URL
DIR=`dirname $FICHIER`
FOOTER=$DIR/footer
DATA="$DOCUMENT_ROOT/data/`echo $FICHIER | tr '/' '_'"
echo "Content-type: text/html"
echo
cat $FICHIER
if [ ! -f $FOOTER ]; then
exit 0
fi
# Positionne les variables d'environnements
# ACCES_USER nombre d'utilisateurs authentifies par les cookies
# ACCES_ACCES nombre d'acces
# ACCES_HOST nombre de machines
# MODIF date et heure de derniere modification
FILEDATE="`dirname $SCRIPT_FILENAME`/FileDate"
MODIF="`$FILEDATE $FICHIER`"
COOKIE=$DATA.cookie
if [ ! -f $COOKIE ]; then
touch $COOKIE
fi
if [ "${HTTP_COOKIE:=x}" != "x" ]; then
echo $HTTP_COOKIE >> $COOKIE
fi
ACCES_USER="`sort -u $COOKIE | wc -l`"
if [ "${REMOTE_HOST:=x}" != "x" ]; then
REMOTE=$REMOTE_HOST
else
REMOTE=$REMOTE_ADDR
fi
HOST=$DATA.host
if [ ! -f $HOST ]; then
touch $HOST
fi
echo $REMOTE >> $HOST
ACCES_HOST="`sort -u $HOST | wc -l`"
ACCES_ACCES="`cat $HOST | wc -l`"
Send(){
IFS=" "
a="cat << EOF
`cat $1`
EOF"
eval $a
}
Send $FOOTER
The code of FileDate
#include < stdio.h >
#include < sys/types.h >
#include < sys/stat.h >
#include < time.h >
main(int argc, char **argv){
char buf[256];
struct stat Stat;
stat(argv[1],&Stat);
cftime( &(buf[0]), "%d/%m/%y à %kh%M", &(Stat.st_mtime) );
printf("%s", buf );
}
