#!/bin/bash IFS=$' \n' ########################################################## # An Access Restricting CGI Script for Web Page Delivery # # ©2022 All Rights Reserved - J. S. Gilstrap - GPL 2.0 # #######################################@################## HOME="/home/username" ThisDomain="https://www.example.com" auth=1 # Authenification Level Requirement. '1' is either a key or domain and '2' requires both. PAGE="$HOME/public_html/cgi-bin/pages/" # Storing the real page in a sub-directory under cgi-bin is recomended. ImgPath="/images/" # Starts from the webserver root and must have a trailing '/' Icon=favicon.png # URL Icon #### Data Parsing ######################################################## nam=${0##*/} ; nam=${nam%.*} ; p1=${1:0:15} ; yes=0 LOG="$HOME/public_html${ImgPath}${nam}.log" [ -r ${nam}.cfg -a -s ${nam}.cfg ] && source ${nam}.cfg PAGE="${PAGE}${nam}.html" ; DOMs=$(< ${nam}.doms) Keys=$(while read line ; do printf "${line%%:*} " ; done < ${nam}.keys) url=${HTTP_REFERER:0:128} ; url=${url/http*:\/\/} ; dom=${url%%/*} c=0 ; for d in $(date -u) ; do let c++ ; eval d$c=\$d ; done DATE="$d1 $d3 $d2 $d6 - $d4 $d5" ; unset c d d1 d2 d3 d4 d5 d6 # Domain and/or Key Verification while [ $yes -lt $auth ] do for K in $Keys ; do [ "$p1" = "$K" ] && let yes++ ; done ; [ "$yes" -eq "$auth" ] && break for D in $DOMs ; do [ "$dom" = "$D" ] && let yes++ ; done ; break done # Post Access Denied message ############################ if [ $yes -lt $auth ] then [ -n "$dom" ] && ErrMsg="From Referer Domain:
$dom" [ $auth -eq 2 ] && andor=and || andor=or while read line ; do echo "$line" ; done < Access Denied
$DATE

Access Denied

$ErrMsg

This site is only accessable through a key
$andor a link posted from the following domains:

$DOMs

Link to Post:
<a href="${ThisDomain}/cgi-bin/${nam}.html">${nam^^}</a>
(Encode Link Without Line Breaks)

EoF ########## printf "Access Denied " >> $LOG fi # Append to Access Log printf "${DATE// }   ${REMOTE_ADDR}    ${HTTP_REFERER}  ${a1}
\n" >> $LOG [ $yes -lt $auth ] && exit 1 # Post Page ########### printf "Content-type: text/html ; charset=utf-8\n\n" [ -r "$PAGE" -a -s "$PAGE" ] && \ { sed -e s#ImgPath#$ImgPathg -e s#Icon#$Icong -e s#DATE#$DATEg -e s#ThisDomain#$ThisDomaing -e s#nam#$namg "$PAGE" ; exit ; } # If not using an external page then edit the following as necessary. while read line ; do echo "$line" ; done < Page
${DATE}
EoF ###