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

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

[project @ alternc: changeset 2004-05-20 14:12:03 by anarcat]

  • various bugfixes from production tests:
  • make this work again on first run
  • do echo something because it can be very confusing to have this script output nothing for a long time
  • add a line to override_php.conf for *each* domain, in a function

Original author: anarcat
Date: 2004-05-20 14:12:03

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
52add_dom_entry() {
53        # protect ourselves from interrupts
54        trap "rm -f ${override_f}.new; exit 1" 1 2 15
55        # ajouter une entrée, seulement s'il n'y en pas déjà, pour ce domaine
56        (echo $1; [ -r $override_f ] && cat $override_f) | \
57        sort -u > ${override_f}.new && \
58        cp ${override_f}.new ${override_f} && \
59        rm ${override_f}.new
60}
61
62echo -n adding open_base_dir protection for:
63# boucle sur tous les domaines hébergés
64# XXX: je ne suis pas sûr qu'il soit véritablement nécessaire de
65# protéger redir/
66for i in `find /var/alternc/dns -type l | grep -v /var/alternc/bureau/admin/webmail; \
67        find /var/alternc/dns/redir -type d | grep -v '/redir\(/.\)\?$'`
68do
69        domain=`basename $i`
70        account=`get_account_by_domain $domain`
71        if [ "X$account" == "X" ]; then
72                continue
73        fi
74        # la première lettre de l'avant-dernière partie du domaine (e.g.
75        # www.alternc.org -> a)
76        initial_domain=`echo $domain | awk '{z=split($NF, a, ".") ; print substr(a[z-1], 1, 1)}'`
77        # la première lettre du username
78        initial_account=`echo $account | cut -c1`
79        path1=/var/alternc/dns/$initial_domain/$domain
80        path2=/var/alternc/html/$initial_account/$account
81
82        mkdir -p $override_d/$initial_domain
83        if append_no_dupe "$override_d/$initial_domain/$domain" <<EOF
84<Directory ${path1}>
85  php_admin_value open_basedir ${path2}/
86</Directory>
87EOF
88        then
89                #echo no change: $domain
90                true
91        else
92                echo -n " $domain"
93        fi
94        add_dom_entry "Include $override_d/$initial_domain/$domain"
95done
96
97echo .
Note: See TracBrowser for help on using the repository browser.