| 1 |
#!/bin/sh |
|---|
| 2 |
|
|---|
| 3 |
set -e |
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
override_d=/var/alternc/apacheconf |
|---|
| 15 |
override_f=${override_d}/override_php.conf |
|---|
| 16 |
extra_paths="/var/alternc/dns/redir:/usr/share/php/:/var/alternc/tmp/:/tmp/" |
|---|
| 17 |
|
|---|
| 18 |
. /etc/alternc/local.sh |
|---|
| 19 |
if [ -z "$MYSQL_HOST" ] |
|---|
| 20 |
then |
|---|
| 21 |
MYSQL_HOST="localhost" |
|---|
| 22 |
fi |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
get_account_by_domain() { |
|---|
| 26 |
|
|---|
| 27 |
if [ -x "/usr/bin/get_account_by_domain" ] |
|---|
| 28 |
then |
|---|
| 29 |
|
|---|
| 30 |
/usr/bin/get_account_by_domain "$1" | cut -d\ -f1 | cut -d' |
|---|
| 31 |
' -f 1 |
|---|
| 32 |
else |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DATABASE -B -N -e \ |
|---|
| 36 |
'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \ |
|---|
| 37 |
CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;' |
|---|
| 38 |
fi |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
append_no_dupe() { |
|---|
| 43 |
realfile="$1" |
|---|
| 44 |
tmpfile=`mktemp` |
|---|
| 45 |
trap "rm -f $tmpfile; exit 1" 1 2 15 |
|---|
| 46 |
cat > $tmpfile |
|---|
| 47 |
if [ -r "$realfile" ] && |
|---|
| 48 |
(diff -q "$tmpfile" "$realfile" > /dev/null || \ |
|---|
| 49 |
diff -u "$tmpfile" "$realfile" | grep '^ ' | sed 's/^ //' | diff -q - "$tmpfile" > /dev/null) |
|---|
| 50 |
then |
|---|
| 51 |
ret=0 |
|---|
| 52 |
else |
|---|
| 53 |
ret=1 |
|---|
| 54 |
cat "$tmpfile" >> "$realfile" |
|---|
| 55 |
fi |
|---|
| 56 |
rm -f "$tmpfile" |
|---|
| 57 |
return "$ret" |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
add_dom_entry() { |
|---|
| 61 |
|
|---|
| 62 |
trap "rm -f ${override_f}.new; exit 1" 1 2 15 |
|---|
| 63 |
|
|---|
| 64 |
(echo "$1"; [ -r $override_f ] && cat $override_f) | \ |
|---|
| 65 |
sort -u > ${override_f}.new && \ |
|---|
| 66 |
cp ${override_f}.new ${override_f} && \ |
|---|
| 67 |
rm ${override_f}.new |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
init_dom_letter() { |
|---|
| 76 |
echo "$1" | awk '{z=split($NF, a, ".") ; print substr(a[z-1], 1, 1)}' |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
echo -n "adding open_base_dir protection for:" |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
if [ $ |
|---|
| 83 |
for i in "$*" |
|---|
| 84 |
do |
|---|
| 85 |
if echo "$i" | grep -q '^\*\.' |
|---|
| 86 |
then |
|---|
| 87 |
echo skipping wildcard "$i" >&2 |
|---|
| 88 |
continue |
|---|
| 89 |
fi |
|---|
| 90 |
if echo "$i" | grep -q /var/alternc/dns > /dev/null; then |
|---|
| 91 |
dom="$i" |
|---|
| 92 |
else |
|---|
| 93 |
initial_domain=`init_dom_letter "$i"` |
|---|
| 94 |
dom="/var/alternc/dns/$initial_domain/$i" |
|---|
| 95 |
fi |
|---|
| 96 |
doms="$doms $dom" |
|---|
| 97 |
done |
|---|
| 98 |
else |
|---|
| 99 |
doms=`find /var/alternc/dns -type l` |
|---|
| 100 |
fi |
|---|
| 101 |
|
|---|
| 102 |
for i in $doms |
|---|
| 103 |
do |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
if readlink "$i" | grep -q '^/var/alternc/bureau/admin/webmail/*$' || \ |
|---|
| 107 |
readlink "$i" | grep -q '^/var/alternc/bureau/*$' |
|---|
| 108 |
then |
|---|
| 109 |
continue |
|---|
| 110 |
fi |
|---|
| 111 |
domain=`basename "$i"` |
|---|
| 112 |
account=`get_account_by_domain $domain` |
|---|
| 113 |
if [ -z "$account" ]; then |
|---|
| 114 |
continue |
|---|
| 115 |
fi |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
initial_domain=`init_dom_letter "$domain"` |
|---|
| 119 |
|
|---|
| 120 |
initial_account=`echo "$account" | cut -c1` |
|---|
| 121 |
path1="/var/alternc/dns/$initial_domain/$domain" |
|---|
| 122 |
path2="/var/alternc/html/$initial_account/$account" |
|---|
| 123 |
|
|---|
| 124 |
mkdir -p "$override_d/$initial_domain" |
|---|
| 125 |
if append_no_dupe "$override_d/$initial_domain/$domain" <<EOF |
|---|
| 126 |
<Directory ${path1}> |
|---|
| 127 |
php_admin_value open_basedir ${path2}/:${extra_paths} |
|---|
| 128 |
</Directory> |
|---|
| 129 |
EOF |
|---|
| 130 |
then |
|---|
| 131 |
true |
|---|
| 132 |
else |
|---|
| 133 |
echo -n " $domain" |
|---|
| 134 |
add_dom_entry "Include $override_d/$initial_domain/$domain" |
|---|
| 135 |
fi |
|---|
| 136 |
done |
|---|
| 137 |
|
|---|
| 138 |
echo . |
|---|