move functions to a common directory to avoid code duplication
This commit is contained in:
parent
a0b2eda9bd
commit
4b68e501bb
|
@ -335,6 +335,7 @@ src/Makefile -text
|
||||||
src/basedir_prot.sh -text
|
src/basedir_prot.sh -text
|
||||||
src/du.pl -text
|
src/du.pl -text
|
||||||
src/fixperms.sh -text
|
src/fixperms.sh -text
|
||||||
|
src/functions.sh -text
|
||||||
src/mail_add -text
|
src/mail_add -text
|
||||||
src/mail_del -text
|
src/mail_del -text
|
||||||
src/mem_add -text
|
src/mem_add -text
|
||||||
|
|
|
@ -16,66 +16,13 @@ override_f=${override_d}/override_php.conf
|
||||||
extra_paths="/var/alternc/dns/redir:/usr/share/php/:/var/alternc/tmp/:/tmp/"
|
extra_paths="/var/alternc/dns/redir:/usr/share/php/:/var/alternc/tmp/:/tmp/"
|
||||||
|
|
||||||
. /etc/alternc/local.sh
|
. /etc/alternc/local.sh
|
||||||
|
. /usr/lib/alternc/functions.sh
|
||||||
|
|
||||||
if [ -z "$MYSQL_HOST" ]
|
if [ -z "$MYSQL_HOST" ]
|
||||||
then
|
then
|
||||||
MYSQL_HOST="localhost"
|
MYSQL_HOST="localhost"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# imprime le nom d'usager associé au domaine
|
|
||||||
get_account_by_domain() {
|
|
||||||
# les admintools ne sont peut-être pas là
|
|
||||||
if [ -x "/usr/bin/get_account_by_domain" ]
|
|
||||||
then
|
|
||||||
# only first field, only first line
|
|
||||||
/usr/bin/get_account_by_domain "$1" | cut -d\ -f1 | cut -d'
|
|
||||||
' -f 1
|
|
||||||
else
|
|
||||||
# implantons localement ce que nous avons besoin, puisque admintools
|
|
||||||
# n'est pas là
|
|
||||||
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DATABASE -B -N -e \
|
|
||||||
'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
|
|
||||||
CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;'
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# add the standard input to a given file, only if not already present
|
|
||||||
append_no_dupe() {
|
|
||||||
realfile="$1"
|
|
||||||
tmpfile=`mktemp`
|
|
||||||
trap "rm -f $tmpfile; exit 1" 1 2 15
|
|
||||||
cat > $tmpfile
|
|
||||||
if [ -r "$realfile" ] &&
|
|
||||||
(diff -q "$tmpfile" "$realfile" > /dev/null || \
|
|
||||||
diff -u "$tmpfile" "$realfile" | grep '^ ' | sed 's/^ //' | diff -q - "$tmpfile" > /dev/null)
|
|
||||||
then
|
|
||||||
ret=0
|
|
||||||
else
|
|
||||||
ret=1
|
|
||||||
cat "$tmpfile" >> "$realfile"
|
|
||||||
fi
|
|
||||||
rm -f "$tmpfile"
|
|
||||||
return "$ret"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_dom_entry() {
|
|
||||||
# protect ourselves from interrupts
|
|
||||||
trap "rm -f ${override_f}.new; exit 1" 1 2 15
|
|
||||||
# ajouter une entrée, seulement s'il n'y en pas déjà, pour ce domaine
|
|
||||||
(echo "$1"; [ -r $override_f ] && cat $override_f) | \
|
|
||||||
sort -u > ${override_f}.new && \
|
|
||||||
cp ${override_f}.new ${override_f} && \
|
|
||||||
rm ${override_f}.new
|
|
||||||
}
|
|
||||||
|
|
||||||
# la première lettre de l'avant-dernière partie du domaine (e.g.
|
|
||||||
# www.alternc.org -> a)
|
|
||||||
#
|
|
||||||
# argument: le domaine
|
|
||||||
# imprime: la lettre
|
|
||||||
init_dom_letter() {
|
|
||||||
echo "$1" | awk '{z=split($NF, a, ".") ; print substr(a[z-1], 1, 1)}'
|
|
||||||
}
|
|
||||||
|
|
||||||
echo -n "adding open_base_dir protection for:"
|
echo -n "adding open_base_dir protection for:"
|
||||||
# boucle sur tous les domaines hébergés, ou sur les arguments de la
|
# boucle sur tous les domaines hébergés, ou sur les arguments de la
|
||||||
# ligne de commande
|
# ligne de commande
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
# some miscellaneous shell functions
|
||||||
|
|
||||||
|
# imprime le nom d'usager associé au domaine
|
||||||
|
get_account_by_domain() {
|
||||||
|
# les admintools ne sont peut-être pas là
|
||||||
|
if [ -x "/usr/bin/get_account_by_domain" ]
|
||||||
|
then
|
||||||
|
# only first field, only first line
|
||||||
|
/usr/bin/get_account_by_domain "$1" | cut -d\ -f1 | cut -d'
|
||||||
|
' -f 1
|
||||||
|
else
|
||||||
|
# implantons localement ce que nous avons besoin, puisque admintools
|
||||||
|
# n'est pas là
|
||||||
|
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS -D$MYSQL_DATABASE -B -N -e \
|
||||||
|
'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
|
||||||
|
CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# add the standard input to a given file, only if not already present
|
||||||
|
append_no_dupe() {
|
||||||
|
realfile="$1"
|
||||||
|
tmpfile=`mktemp`
|
||||||
|
trap "rm -f $tmpfile; exit 1" 1 2 15
|
||||||
|
cat > $tmpfile
|
||||||
|
if [ -r "$realfile" ] &&
|
||||||
|
(diff -q "$tmpfile" "$realfile" > /dev/null || \
|
||||||
|
diff -u "$tmpfile" "$realfile" | grep '^ ' | sed 's/^ //' | diff -q - "$tmpfile" > /dev/null)
|
||||||
|
then
|
||||||
|
ret=0
|
||||||
|
else
|
||||||
|
ret=1
|
||||||
|
cat "$tmpfile" >> "$realfile"
|
||||||
|
fi
|
||||||
|
rm -f "$tmpfile"
|
||||||
|
return "$ret"
|
||||||
|
}
|
||||||
|
|
||||||
|
add_dom_entry() {
|
||||||
|
# protect ourselves from interrupts
|
||||||
|
trap "rm -f ${override_f}.new; exit 1" 1 2 15
|
||||||
|
# ajouter une entrée, seulement s'il n'y en pas déjà, pour ce domaine
|
||||||
|
(echo "$1"; [ -r $override_f ] && cat $override_f) | \
|
||||||
|
sort -u > ${override_f}.new && \
|
||||||
|
cp ${override_f}.new ${override_f} && \
|
||||||
|
rm ${override_f}.new
|
||||||
|
}
|
||||||
|
|
||||||
|
# la première lettre de l'avant-dernière partie du domaine (e.g.
|
||||||
|
# www.alternc.org -> a)
|
||||||
|
#
|
||||||
|
# argument: le domaine
|
||||||
|
# imprime: la lettre
|
||||||
|
init_dom_letter() {
|
||||||
|
echo "$1" | awk '{z=split($NF, a, ".") ; print substr(a[z-1], 1, 1)}'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue