#!/bin/sh # dl.cgi downloading CGI # Users have choice of seeing certain types in the browser # or download by right clicking. # http://domain.com/well-protected/dl.cgi?/www/d/o/domain/whatever.dat s=$1 die (){ echo "Content-type: text/html

Error: $mess
$s

" exit } case "$s" in [!/]*) mess="The path must be absolute"; die;; $HOME/*) break;; ${DOCUMENT_ROOT%/*}/*) break;; *) mess="Wrong path"; die;; esac if [ ! -f "$s" ] ;then mess="File not found"; die;fi ext=${s##*.} TYPE="text/html" case "$ext" in [gG][iI][fF]) TYPE="image/gif" ;; [jJ][pP][gG]|jpeg) TYPE="image/jpeg" ;; [pP][nN][gG]) TYPE="image/png" ;; [tT][xX][tT]|cgi|pl|sh|py|ml|mli|[ch]|cpp|log) TYPE="text/plain" ;; *html) break ;; php|php5|htm) break ;; *) echo "Content-Disposition: attachment; filename=${s##*/}" len=`wc -c $s` len=${len% /*} len=${len##* } echo "Content-length: $len" TYPE="application/octet-stream" # TYPE="application/force-download" ;; esac echo "Content-type: $TYPE" echo exec cat $s 2>/dev/null echo "OK $s" # end