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

Revision 243, 2.6 KB checked in by anarcat, 7 years ago (diff)

[project @ alternc: changeset 2004-05-20 13:57:11 by anarcat]
annuler une partie du commit précédent: utiliser le path absolu pour
get_account_by_domain, l'autre méthode bouclait faire une fonction
avec le code vérifiant si une modif est déjà présente dans un fichier
de config

Original author: anarcat
Date: 2004-05-20 13:57:11

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                /usr/bin/get_account_by_domain $1 | cut -d\  -f1
23        else
24                # implantons localement ce que nous avons besoin, puisque admintools
25                # n'est pas là
26                . /etc/alternc/local.sh
27                mysql -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DATABASE -B -N -e \
28                'select a.login from membres a, sub_domaines b where a.uid = b.compte and \
29                concat(if(sub="", "", concat(sub, ".")), domaine) = "'$1'";'
30        fi
31}
32
33# add the standard input to a given file, only if not already present
34append_no_dupe() {
35        realfile=$1
36        tmpfile=`mktemp`
37        trap "rm -f $tmpfile; exit 1" 1 2 15
38        cat > $tmpfile
39        if [ -r $realfile ] &&
40                diff -q $tmpfile $realfile > /dev/null || \
41                        diff -u $tmpfile $realfile  | grep '^ ' | sed 's/^ //' | diff -q - $tmpfile > /dev/null
42        then
43                status=0
44        else
45                status=1
46                cat $tmpfile >> $realfile
47        fi
48        rm -f $tmpfile
49        return $status
50}
51
52# boucle sur tous les domaines hébergés
53# XXX: je ne suis pas sûr qu'il soit véritablement nécessaire de
54# protéger redir/
55for i in `find /var/alternc/dns -type l | grep -v /var/alternc/bureau/admin/webmail; \
56        find /var/alternc/dns/redir -type d | grep -v '/redir\(/.\)\?$'`
57do
58        domain=`basename $i`
59        account=`get_account_by_domain $domain`
60        if [ "X$account" == "X" ]; 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=`echo $domain | awk '{z=split($NF, a, ".") ; print substr(a[z-1], 1, 1)}'`
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        append_no_dupe "$override_d/$initial_domain/$domain" <<EOF
73<Directory ${path1}>
74  php_admin_value open_basedir ${path2}/
75</Directory>
76EOF
77done
78
79# protect ourselves from interrupts
80trap "rm -f ${override_f}.new; exit 1" 1 2 15
81
82# ajouter une entrée, seulement s'il n'y en pas déjà, pour ce domaine
83(echo "Include $override_d/$initial_domain/$domain" ; \
84        [ -r $override_f ] && cat $override_f)  | \
85        sort -u > ${override_f}.new && \
86        cp ${override_f}.new ${override_f} && \
87        rm ${override_f}.new
Note: See TracBrowser for help on using the repository browser.