Skip to content

Instantly share code, notes, and snippets.

@arivero
Created October 10, 2017 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arivero/cd3acd3f71d4851dd5b95999b3ec645c to your computer and use it in GitHub Desktop.
Save arivero/cd3acd3f71d4851dd5b95999b3ec645c to your computer and use it in GitHub Desktop.
CGI para detectar e insertar citas a las paginas web
#!/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 "<h1>Error</h1> 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 "<h1>Error</h1> 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 "^</HEAD>"`) then
# This "if" changued for speed...
if test "$linea" = "</HEAD>" -o "$linea" = "</head>"; then
for bklink in `cat ${B_DIR}/${SCRIPT_NAME}.backs`
do
echo -n "<LINK HREF=\""
echo -n $bklink
echo "\" REV=\"X-Default\" > "
#
# 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 "^</BODY>"`; then
# again, this "if" changed to optimize output speed
if test "$linea" = "</BODY>" -o "$linea" = "</body>"; then
echo "<p><hr><i>"
echo "Note that we have"
echo "detected some pages probably pointing to this one:<menu>"
# would be better UL COMPACT?
for bklink in `cat ${B_DIR}/${SCRIPT_NAME}.backs`
do
echo -n "<li><A HREF=\""
echo -n $bklink
echo -n "\" REV=\"X-Default\">"
echo -n $bklink
echo "</A>"
done
echo "</menu>"
echo "you could be interested on checking them."
echo "</i>"
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
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment