Newer
Older
tperimeter / rebuild-hosts.allow.sh
#!/bin/sh
# rebuild-hosts.allow.sh
# Rebuild /etc/hosts.allow From Standard And User-Requested Entries
# Part Of The 'tperimeter' Package
#
# Copyright (c) 2006 TundraWare Inc., Des Plaines, IL USA
# All Rights Reserved

RCSID='$Id: rebuild-hosts.allow.sh,v 1.102 2006/05/03 05:15:30 tundra Exp $'

BASE="/usr/local/etc/tperimeter"
EPILOGUE=${BASE}/epilogue
PROLOGUE=${BASE}/prologue
STDALLOW=${BASE}/allow
STDDENY=${BASE}/deny
USERREQUESTS="/www/cgi-bin/tperimeter/requests"

#####
# Function To Scan A Directory Structure To Build
# "Allow" Entries In Proper /etc/hosts.allow Format
#####

BuildEntries()
{
  if [ -d $1 ]          # Only attempt this if the target directory exists
  then
    cd $1
    for x in *
      do
        echo -n $x": "
        cd $x
        for y in *
        do
          echo -n $y" "
        done
        echo " :$2"
        cd ..
      done
  fi
}
# End Of 'BuildEntries()'

#####
# Rebuild /etc/hosts-allow
#####

# Timestamp it

echo "# Built By:  ${RCSID}"
echo "# Built On:  `date`"
echo ""

# First, the standard prologue

cat ${PROLOGUE}


# Add any user-requested temporary additions

echo "# Access Requested Via The 'tperimeter' Interface"
echo ""

BuildEntries ${USERREQUESTS} "ALLOW"


# Delete the user requests

rm -rf ${USERREQUESTS}


# Now include the standard set of access definitions

echo ""
echo "# Standard 'Deny' Entries"
echo ""

BuildEntries ${STDDENY}  "DENY"

echo ""
echo "# Standard 'Allow' Entries"
echo ""

BuildEntries ${STDALLOW} "ALLOW"
echo ""
echo ""

# Finally, add the epilogue

cat ${EPILOGUE}