1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
# Common functions used by dwww shell scripts
#
# $Id: functions.sh.in 548 2011-01-16 20:41:44Z robert $
#
readonly dwww_config="/etc/dwww/dwww.conf"
readonly dwww_libdir="/usr/share/dwww"
readonly dwww_version="#VERSION#"
readonly dwww_cache_dir="/var/cache/dwww"
#
# Initialize dwww: set default variables, read config file, set umask & PATH
#
dwww_initialize() {
#DWWWVARS#
if [ -r "$dwww_config" ] ; then
. "$dwww_config"
fi
umask 022
PATH="/usr/sbin:/usr/bin:/bin:$PATH"
}
#
# Recreate /var/cache/dwww if it's removed
#
dwww_setup_cache_dir() {
if [ ! -d "$dwww_cache_dir" ]; then
mkdir "$dwww_cache_dir"
chmod 755 "$dwww_cache_dir"
chown root "$dwww_cache_dir"
fi
if [ ! -d "$dwww_cache_dir/db" ]; then
mkdir "$dwww_cache_dir/db"
chmod 755 "$dwww_cache_dir/db"
chown "$DWWW_CGIUSER" "$dwww_cache_dir/db"
fi
}
#
# Encode URLs
#
urlencode() {
echo "$@" | perl -pe 'chomp(); s/([^A-Za-z0-9\ \_\-\.\/])/"%" . unpack("H*", $1)/eg; tr/ /+/;'
}
#
# Format as table
#
table_it()
{
state=A
w1=' WIDTH="33%"'
w2=''
echo '<TABLE BORDER="0" WIDTH="95%" ALIGN="center">'
while read line ; do
case "$state" in
A)
state=B
echo "<TR>"
echo "<TD$w1 ALIGN=\"LEFT\">$line</TD>"
;;
B)
state=C
echo "<TD$w1 ALIGN=\"LEFT\">$line</TD>"
w1=""
;;
C)
state=A
echo "<TD$w2 ALIGN=\"LEFT\">$line</TD>"
echo "</TR>"
w2=""
;;
esac
done
case "$state" in
A)
;;
B)
echo "<TD$w1></TD><TD$w2></TD></TR>"
;;
C)
echo "<TD$w2></TD></TR>"
;;
esac
if [ "$first_line" != A ]; then
echo '</TABLE>'
fi
}
|