source: install/scripts/upgrades/0.9.1.sh @ 250

Revision 250, 2.8 KB checked in by anarcat, 7 years ago (diff)

[project @ alternc: changeset 2004-05-22 00:07:41 by anonymous]
ne pas protéger dns/redir

Original author: anonymous
Date: 2004-05-22 00:07:41

Line 
1#!/bin/sh
2
3set -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# alternc-admintools
12# cut, awk, sort
13
14override_d=/etc/alternc/override_php
15override_f=${override_d}.conf
16
17# imprime le nom d'usager associé au domaine
18get_account_by_domain() {
19        # les admintools ne sont peut-être pas là
20        if [ -x "/usr/bin/get_account_by_domain" ]
21        then
22                # only first field, only first line
23                /usr/bin/get_account_by_domain $1 | cut -d\  -f1 | cut -d'
24' -f 1
25        else
26                # implantons localement ce que nous avons besoin, puisque admintools
27                # n'est pas là
28                . /etc/alternc/local.sh
29                mysql -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DATABASE -B -N -e \
30                'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
31                CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'$1'" LIMIT 1;'
32        fi
33}
34
35# add the standard input to a given file, only if not already present
36append_no_dupe() {
37        realfile=$1
38        tmpfile=`mktemp`
39        trap "rm -f $tmpfile; exit 1" 1 2 15
40        cat > $tmpfile
41        if [ -r $realfile ] &&
42                (diff -q $tmpfile $realfile > /dev/null || \
43                        diff -u $tmpfile $realfile  | grep '^ ' | sed 's/^ //' | diff -q - $tmpfile > /dev/null)
44        then
45                ret=0
46        else
47                ret=1
48                cat $tmpfile >> $realfile
49        fi
50        rm -f $tmpfile
51        return $ret
52}
53
54add_dom_entry() {
55        # protect ourselves from interrupts
56        trap "rm -f ${override_f}.new; exit 1" 1 2 15
57        # ajouter une entrée, seulement s'il n'y en pas déjà, pour ce domaine
58        (echo $1; [ -r $override_f ] && cat $override_f) | \
59        sort -u > ${override_f}.new && \
60        cp ${override_f}.new ${override_f} && \
61        rm ${override_f}.new
62}
63
64echo -n adding open_base_dir protection for:
65# boucle sur tous les domaines hébergés
66for i in `find /var/alternc/dns -type l`
67do
68        # don't "protect" squirrelmail, it legitimatly needs to consult
69        # files out of its own directory
70        if readlink $i | grep -q '^/var/alternc/bureau/admin/webmail/*$'
71        then
72                continue
73        fi
74        domain=`basename $i`
75        account=`get_account_by_domain $domain`
76        if [ "X$account" == "X" ]; then
77                continue
78        fi
79        # la première lettre de l'avant-dernière partie du domaine (e.g.
80        # www.alternc.org -> a)
81        initial_domain=`echo $domain | awk '{z=split($NF, a, ".") ; print substr(a[z-1], 1, 1)}'`
82        # la première lettre du username
83        initial_account=`echo $account | cut -c1`
84        path1=/var/alternc/dns/$initial_domain/$domain
85        path2=/var/alternc/html/$initial_account/$account
86
87        mkdir -p $override_d/$initial_domain
88        if append_no_dupe "$override_d/$initial_domain/$domain" <<EOF
89<Directory ${path1}>
90  php_admin_value open_basedir ${path2}/
91</Directory>
92EOF
93        then
94                true
95        else
96                echo -n " $domain"
97                add_dom_entry "Include $override_d/$initial_domain/$domain"
98        fi
99done
100
101echo .
Note: See TracBrowser for help on using the repository browser.