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

Revision 247, 2.9 KB checked in by anarcat, 7 years ago (diff)

[project @ alternc: changeset 2004-05-20 16:50:46 by anarcat]
ne pas utiliser la variable "status" qui a une signification
particuliere dans certains shell

Original author: anarcat
Date: 2004-05-20 16:50:46

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 $status
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
66# XXX: je ne suis pas sûr qu'il soit véritablement nécessaire de
67# protéger redir/
68for i in `find /var/alternc/dns -type l | grep -v /var/alternc/bureau/admin/webmail; \
69        find /var/alternc/dns/redir -type d | grep -v '/redir\(/.\)\?$'`
70do
71        domain=`basename $i`
72        account=`get_account_by_domain $domain`
73        if [ "X$account" == "X" ]; then
74                continue
75        fi
76        # la première lettre de l'avant-dernière partie du domaine (e.g.
77        # www.alternc.org -> a)
78        initial_domain=`echo $domain | awk '{z=split($NF, a, ".") ; print substr(a[z-1], 1, 1)}'`
79        # la première lettre du username
80        initial_account=`echo $account | cut -c1`
81        path1=/var/alternc/dns/$initial_domain/$domain
82        path2=/var/alternc/html/$initial_account/$account
83
84        mkdir -p $override_d/$initial_domain
85        if append_no_dupe "$override_d/$initial_domain/$domain" <<EOF
86<Directory ${path1}>
87  php_admin_value open_basedir ${path2}/
88</Directory>
89EOF
90        then
91                #echo no change: $domain
92                true
93        else
94                echo -n " $domain"
95        fi
96        add_dom_entry "Include $override_d/$initial_domain/$domain"
97done
98
99echo .
Note: See TracBrowser for help on using the repository browser.