#!/bin/sh ###################################################################### # Nombre: PutBacks # Descripcion: CGI para detectar e insertar citas a las paginas web # Author: Alejandro Rivero (rivero@sol.unizar.es) # Date: noviembre 1996 ########################################################################## # Usage: # With CERN httpd (3.0 or near) add to the config file some lines # indicating the directories to monitorize for backlinks # Exec /wwwlab/experiences/*.html /home/http/cgi-bin/PutBacks # Exec /alejo/*htm /home/http/cgi-bin/PutBacks # Path comes from start of data tree, as always. # Warnings: # - Provided as proof of concept only. A lot of work must we made to make # the script fool-proof. # - Use it at your OWN risk. ########################################################################## # variables for testing only. #SCRIPT_NAME="wwwlab/links.html" #HTTP_REFERER="http://some.site/nose.html" ######################################################################### # # We are sending out html files only. # echo 'Content-Type: text/html' echo '' # # base directory: root of our data tree # B_DIR=/home/http/htdocs # # Exclude file: list of nodes to exclude. Must have at least one name # EXCLUDE_FILE=/home/http/conf/hosts.noindex # # We first test for "default" http path specification, then look # for Welcome, welcome, or index files, in this order # if test -d ${B_DIR}/${SCRIPT_NAME}; then if test -f ${B_DIR}/${SCRIPT_NAME}/Welcome.html; then SCRIPT_NAME=${SCRIPT_NAME}/Welcome.html elif test -f ${B_DIR}/${SCRIPT_NAME}/welcome.html; then SCRIPT_NAME=${SCRIPT_NAME}/welcome.html elif test -f ${B_DIR}/${SCRIPT_NAME}/index.html; then SCRIPT_NAME=${SCRIPT_NAME}/index.html else echo "

Error

Can not process directory" exit 0 fi fi # # And of course we check if file exists... if not, we have a special log # for this kind of things if !(test -f ${B_DIR}/${SCRIPT_NAME}); then echo "

Error

File does not exist." echo -n `date` >> /home/http/logs/lost_files.log echo -n " " ${B_DIR}/${SCRIPT_NAME} >>/home/http/logs/lost_files.log echo " " ${HTTP_REFERER} >>/home/http/logs/lost_files.log exit 0 fi # # Now we really begin the game # # First, we test for "filename.backs", the file containing detected backlinks if (!(test -f ${B_DIR}/${SCRIPT_NAME}.backs )) then cat ${B_DIR}/$SCRIPT_NAME else #Ok, there are backlinks for this file. We are going to include them cat ${B_DIR}/${SCRIPT_NAME}| ( while read linea; do # if the html has a well separated HEAD tag, we add LINK info there # if (`echo $linea | grep -i -q "^"`) then # This "if" changued for speed... if test "$linea" = "" -o "$linea" = ""; then for bklink in `cat ${B_DIR}/${SCRIPT_NAME}.backs` do echo -n " " # # Note for developers: # If your browser can not cope with a REV flag without parameters, # please suggest me the adequate one # done fi # and if the html has well separated BODY tag, we put some # visible backlinks there, for compatibility with old browsers :-) # if `echo $linea | grep -i -q "^"`; then # again, this "if" changed to optimize output speed if test "$linea" = "" -o "$linea" = ""; then echo "


" echo "Note that we have" echo "detected some pages probably pointing to this one:" # would be better UL COMPACT? for bklink in `cat ${B_DIR}/${SCRIPT_NAME}.backs` do echo -n "
  • " echo -n $bklink echo "" done echo "
  • " echo "you could be interested on checking them." echo "
    " fi echo $linea done ) fi # Now we check if the current access can qualify as backlink, then # register it in the .backs file if (!(test -z "${HTTP_REFERER}" )) then #mini-bug: EXCLUDE_FILE must have at least one line if (!(`echo $HTTP_REFERER | grep -F -q -i -f ${EXCLUDE_FILE}`)) then # Of course, we create the file when it is needed if (!(test -f ${B_DIR}/${SCRIPT_NAME}.backs)) then touch ${B_DIR}/${SCRIPT_NAME}.backs fi # and we try to avoid reiteration... if (!(`grep -q -i $HTTP_REFERER ${B_DIR}/${SCRIPT_NAME}.backs`)) then echo $HTTP_REFERER >> ${B_DIR}/${SCRIPT_NAME}.backs fi fi fi # exit 0 #