| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | set -e |
|---|
| 4 | |
|---|
| 5 | # Ceci créé un hack php pour chacun des domaines hébergés par alternc |
|---|
| 6 | # ce hack consiste à restreindre chaque usager à son propre répertoire |
|---|
| 7 | # dans alternc/html/u/user avec open_base_dir |
|---|
| 8 | |
|---|
| 9 | # ce script a les dépendances suivantes: |
|---|
| 10 | # (mysql, /etc/alternc/local.sh) OR /usr/bin/get_account_by_domain dans |
|---|
| 11 | # l'ancien package alternc-admintools désormais dans alternc natif. |
|---|
| 12 | # cut, awk, sort |
|---|
| 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 | . /usr/lib/alternc/functions.sh |
|---|
| 20 | |
|---|
| 21 | if [ -z "$MYSQL_HOST" ] |
|---|
| 22 | then |
|---|
| 23 | MYSQL_HOST="localhost" |
|---|
| 24 | fi |
|---|
| 25 | |
|---|
| 26 | echo -n "adding open_base_dir protection for:" |
|---|
| 27 | # boucle sur tous les domaines hébergés, ou sur les arguments de la |
|---|
| 28 | # ligne de commande |
|---|
| 29 | if [ $# -gt 0 ]; then |
|---|
| 30 | for i in "$*" |
|---|
| 31 | do |
|---|
| 32 | if echo "$i" | grep -q '^\*\.' |
|---|
| 33 | then |
|---|
| 34 | echo skipping wildcard "$i" >&2 |
|---|
| 35 | continue |
|---|
| 36 | fi |
|---|
| 37 | if echo "$i" | grep -q /var/alternc/dns > /dev/null; then |
|---|
| 38 | dom="$i" |
|---|
| 39 | else |
|---|
| 40 | initial_domain=`init_dom_letter "$i"` |
|---|
| 41 | dom="/var/alternc/dns/$initial_domain/$i" |
|---|
| 42 | fi |
|---|
| 43 | doms="$doms $dom" |
|---|
| 44 | done |
|---|
| 45 | else |
|---|
| 46 | doms=`find /var/alternc/dns -type l` |
|---|
| 47 | fi |
|---|
| 48 | |
|---|
| 49 | for i in $doms |
|---|
| 50 | do |
|---|
| 51 | # don't "protect" squirrelmail, it legitimatly needs to consult |
|---|
| 52 | # files out of its own directory |
|---|
| 53 | if readlink "$i" | grep -q '^/var/alternc/bureau/admin/webmail/*$' || \ |
|---|
| 54 | readlink "$i" | grep -q '^/var/alternc/bureau/*$' |
|---|
| 55 | then |
|---|
| 56 | continue |
|---|
| 57 | fi |
|---|
| 58 | domain=`basename "$i"` |
|---|
| 59 | account=`get_account_by_domain $domain` |
|---|
| 60 | if [ -z "$account" ]; then |
|---|
| 61 | continue |
|---|
| 62 | fi |
|---|
| 63 | # la première lettre de l'avant-dernière partie du domaine (e.g. |
|---|
| 64 | # www.alternc.org -> a) |
|---|
| 65 | initial_domain=`init_dom_letter "$domain"` |
|---|
| 66 | # la première lettre du username |
|---|
| 67 | initial_account=`echo "$account" | cut -c1` |
|---|
| 68 | path1="/var/alternc/dns/$initial_domain/$domain" |
|---|
| 69 | path2="/var/alternc/html/$initial_account/$account" |
|---|
| 70 | |
|---|
| 71 | mkdir -p "$override_d/$initial_domain" |
|---|
| 72 | if append_no_dupe "$override_d/$initial_domain/$domain" <<EOF |
|---|
| 73 | <Directory ${path1}> |
|---|
| 74 | php_admin_value open_basedir ${path2}/:${extra_paths} |
|---|
| 75 | </Directory> |
|---|
| 76 | EOF |
|---|
| 77 | then |
|---|
| 78 | true |
|---|
| 79 | else |
|---|
| 80 | echo -n " $domain" |
|---|
| 81 | add_dom_entry "Include $override_d/$initial_domain/$domain" |
|---|
| 82 | fi |
|---|
| 83 | done |
|---|
| 84 | |
|---|
| 85 | echo . |
|---|