2014-10-23 15:47:21 +04:00
|
|
|
##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
2014-10-23 21:26:42 +04:00
|
|
|
## Outils de haut niveau pour gérer apache et sa configuration
|
2014-10-23 15:47:21 +04:00
|
|
|
##@cooked nocomments
|
|
|
|
##@require base
|
|
|
|
##@require sysinfos
|
2014-10-23 21:26:42 +04:00
|
|
|
##@require apache
|
|
|
|
uprovide apache.tools
|
2016-12-30 18:10:59 +04:00
|
|
|
urequire base sysinfos template apache
|
2014-10-23 15:47:21 +04:00
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
function __apache_rc_destdir() {
|
2017-03-01 22:34:59 +04:00
|
|
|
[ -z "$3" ] && setv "${1:-certsdir}" "$(get_APACHESSLCERTSDIR_prefix)"
|
|
|
|
[ -z "$4" ] && setv "${2:-keysdir}" "$(get_APACHESSLKEYSDIR_prefix)"
|
2016-12-30 18:10:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function __apache_rc_loadconf() {
|
2014-10-23 15:47:21 +04:00
|
|
|
[ -n "$__rc_dir" ] || __rc_dir="$(dirname "$__rc_conf")"
|
|
|
|
eval "$(
|
|
|
|
source "$__rc_conf"
|
2016-12-30 18:10:59 +04:00
|
|
|
echo_setv __rc_cert "$cert"
|
|
|
|
echo_setv __rc_key "$key"
|
|
|
|
echo_setv __rc_ca "$ca"
|
2014-10-23 15:47:21 +04:00
|
|
|
)"
|
|
|
|
[ -n "$__rc_cert" ] && __rc_cert="$(abspath "$__rc_cert" "$__rc_dir")"
|
|
|
|
[ -n "$__rc_key" ] && __rc_key="$(abspath "$__rc_key" "$__rc_dir")"
|
|
|
|
[ -n "$__rc_ca" ] && __rc_ca="$(abspath "$__rc_ca" "$__rc_dir")"
|
|
|
|
}
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
function __apache_rc_resolveprefix() {
|
|
|
|
local __prefix __cert __key
|
|
|
|
local __certsdir="$1" __keysdir="$2"
|
|
|
|
__apache_rc_destdir __certsdir __keysdir "$__certsdir" "$__keysdir"
|
|
|
|
|
|
|
|
if [ -z "$__rc_cert" ]; then
|
|
|
|
# si pas de certificat, alors générer un préfixe pour chercher les
|
|
|
|
# fichiers
|
|
|
|
setx __prefix=basename "$__rc_conf"
|
|
|
|
__prefix="${__prefix%certs.conf}"
|
|
|
|
elif [ ! -f "$__rc_cert" ]; then
|
|
|
|
# si le fichier source n'existe pas, vérifier s'il existe dans la
|
|
|
|
# destination
|
|
|
|
setx __cert=basename "$__rc_cert"
|
|
|
|
setx __key=basename "$__rc_key"
|
|
|
|
if [ -f "$__certsdir/$__cert" -a -f "$__keysdir/$__key" ]; then
|
|
|
|
# parfait, les fichiers existent déjà à l'endroit prévu
|
|
|
|
:
|
|
|
|
else
|
|
|
|
# construire un préfixe avec le nom du fichier
|
|
|
|
__prefix="$__cert"
|
|
|
|
if [ "${__prefix%.pem}" != "$__prefix" ]; then
|
|
|
|
__prefix="${__prefix%.pem}"
|
|
|
|
elif [ "${__prefix%.crt}" != "$__prefix" ]; then
|
|
|
|
__prefix="${__prefix%.crt}"
|
|
|
|
fi
|
|
|
|
if [ -n "${__prefix//[0-9]/}" ]; then
|
|
|
|
# enlever le suffixe numérique, uniquement si le nom ne contient
|
|
|
|
# pas que des chiffres
|
|
|
|
while [ -n "$__prefix" -a "${__prefix%[0-9]}" != "$__prefix" ]; do
|
|
|
|
__prefix="${__prefix%[0-9]}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$__prefix" ]; then
|
|
|
|
local -a __certs
|
|
|
|
array_from_lines __certs "$(list_files "$__certsdir" "$__prefix*" | LANG=C sort -r)"
|
|
|
|
if [ ${#__certs[*]} -gt 0 ]; then
|
|
|
|
__cert="${__certs[0]}"
|
|
|
|
__key="${__cert%.*}.key"
|
|
|
|
__rc_cert="$__rc_dir/$__cert"
|
|
|
|
__rc_key="$__rc_dir/$__key"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function __apache_rc_checkfiles() {
|
|
|
|
local destdir="$1"; shift
|
|
|
|
local file
|
|
|
|
for file in "$@"; do
|
|
|
|
[ -n "$file" ] || continue
|
|
|
|
[ -f "$file" ] && continue
|
|
|
|
if [ -n "$destdir" -a -f "$destdir/$(basename "$file")" ]; then
|
|
|
|
[ -z "$__apache_rc_quiet" ] && ewarn "$file: fichier introuvable
|
|
|
|
Le fichier existant $destdir/$(basename "$file") sera utilisé"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
eerror "$file: fichier introuvable"
|
|
|
|
return 1
|
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function __apache_rc_checkvars() {
|
|
|
|
local __certsdir="$1" __keysdir="$2"
|
|
|
|
__apache_rc_destdir __certsdir __keysdir "$__certsdir" "$__keysdir"
|
|
|
|
|
2014-10-23 15:47:21 +04:00
|
|
|
if [ -n "$__rc_cert" -a -z "$__rc_key" ]; then
|
|
|
|
local __rc_name __rc_ext
|
|
|
|
splitname "$__rc_cert" __rc_name __rc_ext
|
|
|
|
if [ "$__rc_ext" == "crt" -o "$__rc_ext" == "pem" ]; then
|
|
|
|
__rc_key="$__rc_name.key"
|
2016-12-30 18:10:59 +04:00
|
|
|
[ -z "$__apache_rc_quiet" ] && enote "La clé privée n'a pas été spécifiée. La valeur $(ppath "$__rc_key") sera utilisée"
|
2014-10-23 15:47:21 +04:00
|
|
|
else
|
|
|
|
eerror "Impossible de trouver la clé privée correspondant au certificat $(ppath "$__rc_cert")"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -z "$__rc_cert" -a -z "$__rc_ca" ]; then
|
|
|
|
eerror "Vous devez spécifier le certificat à installer"
|
|
|
|
return 1
|
|
|
|
elif [ -z "$__rc_cert" ]; then
|
2016-12-30 18:10:59 +04:00
|
|
|
[ -z "$__apache_rc_quiet" ] && eattention "Seul le certificat autorité a été spécifié."
|
2014-10-23 15:47:21 +04:00
|
|
|
elif [ -z "$__rc_ca" ]; then
|
2016-12-30 18:10:59 +04:00
|
|
|
[ -z "$__apache_rc_quiet" ] && ewarn "Aucun certificat autorité n'a pas été spécifié. Cela ne peut marcher que si le certificat est autosigné"
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
__apache_rc_checkfiles "$__certsdir" "$__rc_ca" "$__rc_cert" || return 1
|
|
|
|
__apache_rc_checkfiles "$__keysdir" "$__rc_key" || return 1
|
|
|
|
return 0
|
2014-10-23 15:47:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function apache_resolvecert() {
|
|
|
|
# Calculer l'emplacement des certificats correspondant aux arguments $1 et
|
|
|
|
# $2 (qui correspondent aux options --conf et --dir de apache_addcert()),
|
|
|
|
# puis initialiser les variables $3(=cert), $4(=key) et $5(=ca)
|
2016-12-30 18:10:59 +04:00
|
|
|
# Si ces valeurs sont déjà calculées, on peut fournir $6=certsdir et
|
|
|
|
# $7=keysdir
|
2014-10-23 15:47:21 +04:00
|
|
|
local __rc_conf="$1" __rc_dir="$2"
|
|
|
|
local __rc_cert __rc_key __rc_ca
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
local __certsdir="$6" __keysdir="$7"
|
|
|
|
__apache_rc_destdir __certsdir __keysdir "$__certsdir" "$__keysdir"
|
|
|
|
|
|
|
|
__apache_rc_loadconf
|
|
|
|
__apache_rc_resolveprefix "$__certsdir" "$__keysdir"
|
|
|
|
__apache_rc_checkvars "$__certsdir" "$__keysdir" || return 1
|
2017-03-01 22:34:59 +04:00
|
|
|
setv "${3:-cert}" "$__rc_cert"
|
|
|
|
setv "${4:-key}" "$__rc_key"
|
|
|
|
setv "${5:-ca}" "$__rc_ca"
|
2014-10-23 15:47:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function apache_addcert() {
|
|
|
|
function __apache_addcert_display_help() {
|
|
|
|
uecho "apache_addcert: Installer un certificat sur le serveur
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
apache_addcert [options] [cert.pem [cert.key [ca.pem]]]
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
--conf certsconf
|
|
|
|
--dir certsdir
|
|
|
|
Spécifier un fichier de configuration et un répertoire depuis lesquels
|
|
|
|
prendre les informations sur les certificats à utiliser.
|
|
|
|
Le fichier de configuration doit définir les variables cert, key et ca
|
|
|
|
avec les noms des fichiers contenant respectivement le certificat, la
|
|
|
|
clé privée, et les certificats autorités, exprimés relativement au
|
|
|
|
répertoire certsdir.
|
|
|
|
Si ces options ne sont pas spécifiées, les fichiers doivent être donnés
|
|
|
|
sur la ligne de commande.
|
|
|
|
|
|
|
|
--out-cert cert
|
|
|
|
--out-key key
|
|
|
|
--out-ca ca
|
|
|
|
Au lieu d'installer les certificats, placer les chemins vers les
|
|
|
|
fichiers correspondant dans les variables spécifiées"
|
|
|
|
}
|
|
|
|
|
|
|
|
eval "$(utools_local)"
|
|
|
|
local action=install
|
2016-12-30 18:10:59 +04:00
|
|
|
local certsconf certssrcdir cert key ca
|
2014-10-23 15:47:21 +04:00
|
|
|
local __out_cert __out_key __out_ca
|
|
|
|
parse_opts "${PRETTYOPTS[@]}" \
|
|
|
|
--help '$exit_with __apache_addcert_display_help' \
|
|
|
|
-C:,--conf: certsconf= \
|
2016-12-30 18:10:59 +04:00
|
|
|
-d:,--dir: certssrcdir= \
|
2014-10-23 15:47:21 +04:00
|
|
|
--out-cert: '$set@ __out_cert; action=dump' \
|
|
|
|
--out-key: '$set@ __out_key; action=dump' \
|
|
|
|
--out-ca: '$set@ __out_ca; action=dump' \
|
|
|
|
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
local certsdir keysdir
|
|
|
|
__apache_rc_destdir certsdir keysdir
|
|
|
|
|
2014-10-23 15:47:21 +04:00
|
|
|
local __rc_conf __rc_dir
|
|
|
|
local __rc_cert __rc_key __rc_ca
|
|
|
|
if [ -n "$certsconf" ]; then
|
|
|
|
__rc_conf="$certsconf"
|
2016-12-30 18:10:59 +04:00
|
|
|
__rc_dir="$certssrcdir"
|
|
|
|
__apache_rc_loadconf
|
|
|
|
__apache_rc_resolveprefix "$certsdir" "$keysdir"
|
|
|
|
__apache_rc_checkvars "$certsdir" "$keysdir" || return 1
|
2014-10-23 15:47:21 +04:00
|
|
|
else
|
|
|
|
__rc_cert="$1"
|
|
|
|
__rc_key="$2"
|
|
|
|
__rc_ca="$3"
|
2016-12-30 18:10:59 +04:00
|
|
|
__apache_rc_checkvars "$certsdir" "$keysdir" || return 1
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
|
|
|
cert="$__rc_cert"
|
|
|
|
key="$__rc_key"
|
|
|
|
ca="$__rc_ca"
|
|
|
|
|
|
|
|
if [ -n "$cert" ]; then
|
|
|
|
estepi "Certificat: $(ppath "$cert")"
|
|
|
|
estepi "Clé privée: $(ppath "$key")"
|
|
|
|
fi
|
|
|
|
[ -n "$ca" ] && estepi "CAutorités: $(ppath "$ca")"
|
|
|
|
ask_yesno "Voulez-vous continuer?" O || return 1
|
|
|
|
urequire install
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
etitled "Copie des fichiers"
|
2014-10-23 15:47:21 +04:00
|
|
|
if [ ! -d "$certsdir" ]; then
|
|
|
|
mkdir -p "$certsdir" || return 1
|
|
|
|
chmod 755 "$certsdir" || return 1
|
|
|
|
fi
|
|
|
|
if [ ! -d "$keysdir" ]; then
|
|
|
|
mkdir -p "$keysdir" || return 1
|
|
|
|
chmod 710 "$keysdir" || return 1
|
|
|
|
fi
|
2016-12-30 18:10:59 +04:00
|
|
|
if [ -n "$cert" -a -f "$cert" ]; then
|
|
|
|
if copy_update "$cert" "$certsdir"; then
|
|
|
|
chmod 644 "$certsdir/$(basename "$cert")" || return 1
|
|
|
|
fi
|
|
|
|
if copy_update "$key" "$keysdir"; then
|
|
|
|
chmod 640 "$keysdir/$(basename "$key")" || return 1
|
|
|
|
fi
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
2016-12-30 18:10:59 +04:00
|
|
|
if [ -n "$ca" -a -f "$ca" ]; then
|
|
|
|
if copy_update "$ca" "$certsdir"; then
|
|
|
|
chmod 644 "$certsdir/$(basename "$ca")" || return 1
|
|
|
|
fi
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
|
|
|
eend
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2015-12-07 04:43:46 +04:00
|
|
|
function __apache_autoconf_setup() {
|
2015-12-24 09:58:09 +04:00
|
|
|
if ! check_sysinfos --vars sysname sysdist sysver bits -s linux64 linux32 linux -d debian; then
|
2016-12-30 18:10:59 +04:00
|
|
|
eerror "$(get_sysinfos_desc): système non supporté. debian linux est requis"
|
2015-12-07 04:43:46 +04:00
|
|
|
return 1
|
|
|
|
fi
|
2016-12-30 18:10:59 +04:00
|
|
|
urequire debian install
|
|
|
|
if [ -z "$__apache_autoconf_no_require_apache" ]; then
|
|
|
|
pkg_check apache2 || {
|
|
|
|
eerror "apache2 non installé. impossible de continuer"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
fi
|
2015-12-07 04:43:46 +04:00
|
|
|
compute_apache_prefixes
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
function __apache_autoconf_fillxxx() {
|
|
|
|
local var name value first=1
|
|
|
|
for var in "$@"; do
|
|
|
|
splitvar "$var" name value
|
|
|
|
array_addu FILLVARS "$name"
|
|
|
|
[ -n "$first" ] || FILLSCRIPT="$FILLSCRIPT"$'\n'
|
|
|
|
FILLSCRIPT="${FILLSCRIPT}s/@@${name}@@/$(qseds "${value}")/g"
|
|
|
|
first=
|
|
|
|
done
|
|
|
|
# Il faut un fichier temporaire pour les remplacement de fichiers
|
|
|
|
ac_set_tmpfile FILLTEMP
|
|
|
|
}
|
2014-11-29 23:02:48 +04:00
|
|
|
function __apache_autoconf_fillcopy() {
|
|
|
|
# copier le fichier $1 vers le fichier $2. Si le fichier $1 contient l'une
|
|
|
|
# des variables du tableau $FILLVARS, corriger d'abord le fichier avec le
|
|
|
|
# script sed $FILLSCRIPT. Le fichier temporaire $FILLTEMP est utilisé pour
|
|
|
|
# le remplacement des valeurs. $3 contient le cas échéant des commandes sed
|
|
|
|
# supplémentaires
|
2015-04-20 01:15:27 +04:00
|
|
|
local src="$1" dest="$2" sedscript="$3" perms="${4:-go+rX}"
|
2014-11-29 23:02:48 +04:00
|
|
|
|
2016-04-07 23:55:50 +04:00
|
|
|
# valeurs à remplacer dans le fichier
|
|
|
|
local var found_var
|
2014-11-29 23:02:48 +04:00
|
|
|
for var in "${FILLVARS[@]}"; do
|
2016-04-07 23:55:50 +04:00
|
|
|
if quietgrep "@@${var}@@" "$src"; then
|
|
|
|
found_var=1
|
2014-11-29 23:02:48 +04:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2016-04-07 23:55:50 +04:00
|
|
|
if [ "$found_var" ]; then
|
2014-11-29 23:02:48 +04:00
|
|
|
sed "$FILLSCRIPT
|
2015-04-20 17:43:19 +04:00
|
|
|
$sedscript" <"$src" >"$FILLTEMP"
|
2014-11-29 23:02:48 +04:00
|
|
|
src="$FILLTEMP"
|
|
|
|
fi
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
copy_update "$src" "$dest" "$perms" && return
|
|
|
|
estepn "$(basename -- "$dest")"
|
|
|
|
return 1
|
2014-11-29 23:02:48 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 12:43:19 +04:00
|
|
|
__APACHE_AUTOCONF_HELP="\
|
|
|
|
--confdir CONFDIR
|
|
|
|
Spécifier l'emplacement des fichiers de configuration apache ainsi que des
|
2016-12-30 18:10:59 +04:00
|
|
|
fichiers 'syspkgs.conf', 'confs.conf', 'modules.conf' et 'sites.conf'. Par
|
|
|
|
défaut, prendre le répertoire local DESTDIR.
|
2015-10-29 12:43:19 +04:00
|
|
|
--confsdir CONFSDIR
|
2015-12-07 04:43:46 +04:00
|
|
|
Spécifier l'emplacement des fichiers des configuration. Par défaut, utiliser
|
|
|
|
DESTDIR/confs si ce répertoire existe.
|
2015-10-29 12:43:19 +04:00
|
|
|
--modulesdir MODULESDIR
|
2015-12-07 04:43:46 +04:00
|
|
|
Spécifier l'emplacement des fichiers des modules. Par défaut, utiliser
|
|
|
|
DESTDIR/modules si ce répertoire existe.
|
2015-10-29 12:43:19 +04:00
|
|
|
--sitesdir SITESDIR
|
2015-12-07 04:43:46 +04:00
|
|
|
Spécifier l'emplacement des fichiers des sites. Par défaut, utiliser
|
|
|
|
DESTDIR/sites si ce répertoire existe.
|
2015-10-29 12:43:19 +04:00
|
|
|
--cgibindir CGIBINDIR
|
|
|
|
Spécifier l'emplacement des scripts cgi à installer. Par défaut, utiliser
|
|
|
|
DESTDIR/cgi-bin si ce répertoire existe.
|
|
|
|
--wwwdir WWWDIR
|
|
|
|
Spécifier l'emplacement des fichiers du serveur web. Par défaut, utiliser
|
|
|
|
DESTDIR/www si ce répertoire existe.
|
|
|
|
--certsconfdir CERTSCONFDIR
|
|
|
|
Spécifier l'emplacement des fichiers de configuration des certificats. Par
|
|
|
|
défaut, utiliser DESTDIR/certsconf si ce répertoire existe. Il faut alors
|
|
|
|
spécifier aussi CERTSDIR, l'emplacement des certificats à installer.
|
|
|
|
--rrdir RRDIR
|
|
|
|
Spécifier l'emplacement des fichiers de réécriture. Par défaut, utiliser
|
|
|
|
DESTDIR/RewriteRules si ce répertoire existe.
|
|
|
|
--no-restart
|
|
|
|
Ne pas redémarrer apache en cas de modification de la configuration"
|
|
|
|
function __display_apache_autoconf_help() { eecho "$__APACHE_AUTOCONF_HELP"; }
|
2014-10-23 15:47:21 +04:00
|
|
|
function apache_autoconf() {
|
|
|
|
eval "$(utools_local)"
|
2015-10-30 21:46:49 +04:00
|
|
|
local -a ignores
|
2015-12-07 04:43:46 +04:00
|
|
|
local autoconfdir certsdir confdir confsdir oneconf modulesdir onemodule
|
|
|
|
local sitesdir onesite cgibindir wwwdir certsconfdir rrdir onecms
|
2015-12-24 09:58:09 +04:00
|
|
|
local sysname sysdist sysver bits
|
2016-12-30 18:10:59 +04:00
|
|
|
local netconf destconfsdir a2xconf
|
2017-03-24 15:06:40 +04:00
|
|
|
local fixip
|
2014-10-23 15:47:21 +04:00
|
|
|
local restart=1
|
|
|
|
parse_opts "${PRETTYOPTS[@]}" \
|
2015-10-29 12:43:19 +04:00
|
|
|
--help '$exit_with __display_apache_autoconf_help' \
|
2015-10-30 21:46:49 +04:00
|
|
|
--ignore: ignores \
|
2014-10-23 15:47:21 +04:00
|
|
|
--confdir: confdir= \
|
2015-10-30 21:46:49 +04:00
|
|
|
--confsdir: confsdir= \
|
2015-12-07 04:43:46 +04:00
|
|
|
--one-conf: oneconf= \
|
2014-10-23 15:47:21 +04:00
|
|
|
--modulesdir: modulesdir= \
|
2015-12-07 04:43:46 +04:00
|
|
|
--one-module: onemodule= \
|
2014-10-23 15:47:21 +04:00
|
|
|
--sitesdir: sitesdir= \
|
2015-12-07 04:43:46 +04:00
|
|
|
--one-site: onesite= \
|
2014-10-23 15:47:21 +04:00
|
|
|
--cgibindir: cgibindir= \
|
|
|
|
--wwwdir: wwwdir= \
|
|
|
|
--certsconfdir: certsconfdir= \
|
|
|
|
--rrdir: rrdir= \
|
|
|
|
--no-restart restart= \
|
2015-12-24 09:58:09 +04:00
|
|
|
--sysname: sysname= \
|
|
|
|
--sysdist: sysdist= \
|
|
|
|
--sysver: sysver= \
|
|
|
|
-6,--squeeze sysver=squeeze \
|
|
|
|
-7,--wheezy sysver=wheezy \
|
|
|
|
-8,--jessie sysver=jessie \
|
|
|
|
--bits: bits= \
|
2016-12-30 18:10:59 +04:00
|
|
|
--network-config netconf=1 \
|
2017-03-24 15:06:40 +04:00
|
|
|
--fix-ip fixip=1 \
|
2014-10-23 15:47:21 +04:00
|
|
|
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
|
|
|
|
2015-12-24 09:58:09 +04:00
|
|
|
if [ -n "$sysname" -o -n "$sysdist" -o -n "$sysver" ]; then
|
|
|
|
ensure_sysinfos sysname sysdist sysver
|
|
|
|
else
|
|
|
|
sysname=("${MYSYSNAME[@]}")
|
|
|
|
sysdist=("${MYSYSDIST[@]}")
|
|
|
|
sysver=("${MYSYSVER[@]}")
|
|
|
|
bits="$MYBITS"
|
|
|
|
fi
|
2016-12-30 18:10:59 +04:00
|
|
|
__apache_autoconf_no_require_apache= __apache_autoconf_setup || return 1
|
|
|
|
if check_sysinfos --vars sysname sysdist sysver bits -d debian -v jessie+; then
|
2016-04-07 23:55:50 +04:00
|
|
|
confdefault=000-default.conf
|
|
|
|
confdefaultssl=default-ssl.conf
|
2015-12-24 09:58:09 +04:00
|
|
|
destconfsdir="$APACHECONFDIR/conf-available"
|
|
|
|
a2xconf=1
|
2016-12-30 18:10:59 +04:00
|
|
|
elif check_sysinfos --vars sysname sysdist sysver bits -d debian; then
|
2016-04-07 23:55:50 +04:00
|
|
|
confdefault=default
|
|
|
|
confdefaultssl=default-ssl
|
2015-12-24 09:58:09 +04:00
|
|
|
destconfsdir="$APACHECONFDIR/conf.d"
|
|
|
|
fi
|
2014-10-23 15:47:21 +04:00
|
|
|
|
2014-11-29 23:02:48 +04:00
|
|
|
# Configuration
|
|
|
|
autoconfdir="$1"; shift
|
2014-10-23 15:47:21 +04:00
|
|
|
[ -n "$autoconfdir" ] || {
|
|
|
|
eerror "Vous devez spécifier le répertoire de base de la configuration apache"
|
|
|
|
return 1
|
|
|
|
}
|
2014-11-29 23:02:48 +04:00
|
|
|
certsdir="$1"; shift
|
2015-10-30 21:46:49 +04:00
|
|
|
if [ -z "$confdir" -o -z "$confsdir" -o -z "$modulesdir" \
|
|
|
|
-o -z "$sitesdir" -o -z "$cgibindir" -o -z "$wwwdir" \
|
|
|
|
-o -z "$certsconfdir" -o -z "$rrdir" ]; then
|
2014-10-23 15:47:21 +04:00
|
|
|
[ -d "$autoconfdir" ] || {
|
|
|
|
eerror "$autoconfdir: répertoire invalide"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
[ -n "$confdir" ] || confdir="$autoconfdir"
|
2015-10-30 21:46:49 +04:00
|
|
|
[ -n "$confsdir" ] || confsdir="$autoconfdir/confs"
|
2014-10-23 15:47:21 +04:00
|
|
|
[ -n "$modulesdir" ] || modulesdir="$autoconfdir/modules"
|
|
|
|
[ -n "$sitesdir" ] || sitesdir="$autoconfdir/sites"
|
|
|
|
[ -n "$cgibindir" ] || cgibindir="$autoconfdir/cgi-bin"
|
|
|
|
[ -n "$wwwdir" ] || wwwdir="$autoconfdir/www"
|
|
|
|
[ -n "$certsconfdir" ] || certsconfdir="$autoconfdir/certsconf"
|
|
|
|
[ -n "$rrdir" ] || rrdir="$autoconfdir/RewriteRules"
|
2015-12-07 04:43:46 +04:00
|
|
|
[ -n "$oneconf" -o -n "$onemodule" -o -n "$onesite" ] && onecms=1
|
2014-10-23 15:47:21 +04:00
|
|
|
|
2014-11-29 23:02:48 +04:00
|
|
|
# Faire un script sed pour remplacer les variables spécifiées par leur
|
|
|
|
# valeur dans les fichiers
|
|
|
|
local -a FILLVARS; local FILLSCRIPT FILLTEMP
|
2016-03-08 11:51:46 +04:00
|
|
|
__apache_autoconf_fillxxx "$@"
|
2017-03-24 15:06:40 +04:00
|
|
|
if [ -n "$fixip" ]; then
|
|
|
|
FILLSCRIPT="$FILLSCRIPT
|
|
|
|
"'s/<VirtualHost \*:\([0-9][0-9]*\)>#\*ip:\(.*\)$/<VirtualHost \2:\1>/'
|
|
|
|
fi
|
2014-11-29 23:02:48 +04:00
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
# Installation des packages système
|
|
|
|
if [ -f "$confdir/syspkgs.conf" ]; then
|
|
|
|
local -a syspkgs
|
|
|
|
local syspkg
|
|
|
|
array_from_lines syspkgs "$(<"$confdir/syspkgs.conf" filter_conf)"
|
|
|
|
if ! pkg_check "${syspkgs[@]}"; then
|
|
|
|
etitle "Installation de paquets système"
|
|
|
|
estep "${syspkgs[@]}"
|
|
|
|
pkg_install "${syspkgs[@]}" || return 1
|
|
|
|
eend
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2014-11-29 23:02:48 +04:00
|
|
|
# Copie des certificats
|
2015-11-12 15:40:08 +04:00
|
|
|
local modified rehash conf
|
2014-10-23 15:47:21 +04:00
|
|
|
if [ -d "$certsconfdir" ]; then
|
2015-11-12 15:40:08 +04:00
|
|
|
local -a certsconfs certspems
|
|
|
|
local certsconf certspem cert key ca
|
2015-04-20 17:55:10 +04:00
|
|
|
array_addu FILLVARS cert
|
|
|
|
array_addu FILLVARS key
|
|
|
|
array_addu FILLVARS ca
|
|
|
|
|
2014-10-23 15:47:21 +04:00
|
|
|
etitle "Installation des certificats"
|
2016-12-30 18:10:59 +04:00
|
|
|
[ -n "$certsdir" -a ! -d "$certsdir" ] && ewarn "$certsdir: répertoire invalide"
|
2014-10-23 15:47:21 +04:00
|
|
|
array_lsfiles certsconfs "$certsconfdir" "*.conf"
|
|
|
|
for certsconf in "${certsconfs[@]}"; do
|
2016-12-30 18:10:59 +04:00
|
|
|
apache_addcert -y -C "$certsconf" -d "$certsdir" "$cert" "$key" "$ca" || return 1
|
2014-10-23 15:47:21 +04:00
|
|
|
modified=1
|
|
|
|
done
|
2015-11-12 15:40:08 +04:00
|
|
|
array_lsfiles certspems "$certsconfdir" "*.crt" "*.pem"
|
|
|
|
for certspem in "${certspems[@]}"; do
|
|
|
|
if copy_update "$certspem" "$APACHESSLCERTSDIR/$(basename -- "$certspem")"; then
|
|
|
|
modified=1
|
|
|
|
rehash=1
|
|
|
|
fi
|
|
|
|
done
|
2014-10-23 15:47:21 +04:00
|
|
|
eend
|
|
|
|
fi
|
|
|
|
|
2015-10-30 21:46:49 +04:00
|
|
|
# Gestion des configurations
|
2015-12-24 09:58:09 +04:00
|
|
|
if [ -d "$confsdir" -a \( -z "$onecms" -o -n "$oneconf" \) ]; then
|
2015-10-30 21:46:49 +04:00
|
|
|
local -a confs
|
|
|
|
local conf
|
|
|
|
etitle "Installation des configurations"
|
2016-12-30 18:10:59 +04:00
|
|
|
array_from_lines confs "$(list_files "$confsdir" "*.conf")"
|
2015-10-30 21:46:49 +04:00
|
|
|
for conf in "${confs[@]}"; do
|
2015-12-07 04:43:46 +04:00
|
|
|
[ -z "$oneconf" -o "$conf" == "$oneconf" ] || continue
|
2015-10-30 21:46:49 +04:00
|
|
|
__apache_autoconf_fillcopy \
|
|
|
|
"$confsdir/$conf" \
|
2015-12-24 09:58:09 +04:00
|
|
|
"$destconfsdir/$conf" && modified=1
|
2015-10-30 21:46:49 +04:00
|
|
|
done
|
|
|
|
eend
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Gestion des modules
|
2015-12-24 09:58:09 +04:00
|
|
|
if [ -d "$modulesdir" -a \( -z "$onecms" -o -n "$onemodule" \) ]; then
|
2014-10-23 15:47:21 +04:00
|
|
|
local -a confs
|
|
|
|
local conf
|
|
|
|
etitle "Installation des configurations des modules"
|
2016-12-30 18:10:59 +04:00
|
|
|
array_from_lines confs "$(list_files "$modulesdir" "*.conf")"
|
2014-10-23 15:47:21 +04:00
|
|
|
for conf in "${confs[@]}"; do
|
2015-12-07 04:43:46 +04:00
|
|
|
[ -z "$onemodule" -o "$conf" == "$onemodule" ] || continue
|
2014-11-29 23:02:48 +04:00
|
|
|
__apache_autoconf_fillcopy \
|
|
|
|
"$modulesdir/$conf" \
|
|
|
|
"$APACHECONFDIR/mods-available/$conf" && modified=1
|
2014-10-23 15:47:21 +04:00
|
|
|
done
|
|
|
|
eend
|
|
|
|
fi
|
|
|
|
|
2014-11-29 23:02:48 +04:00
|
|
|
# Règles de réécriture
|
2015-12-07 04:43:46 +04:00
|
|
|
if [ -d "$rrdir" -a -z "$onecms" ]; then
|
2016-12-30 18:10:59 +04:00
|
|
|
# legacy... remplacé par des fichiers de règles directement dans le répertoire de configuration
|
2014-10-23 15:47:21 +04:00
|
|
|
local -a confs
|
|
|
|
local conf
|
|
|
|
etitle "Installation des règles de réécriture"
|
|
|
|
array_from_lines confs "$(list_files "$rrdir" "RewriteRules*.conf")"
|
|
|
|
for conf in "${confs[@]}"; do
|
2014-11-29 23:02:48 +04:00
|
|
|
__apache_autoconf_fillcopy \
|
|
|
|
"$rrdir/$conf" \
|
|
|
|
"$APACHECONFDIR/$conf" && modified=1
|
2014-10-23 15:47:21 +04:00
|
|
|
done
|
|
|
|
eend
|
|
|
|
fi
|
|
|
|
|
2014-11-29 23:02:48 +04:00
|
|
|
# Sites
|
2014-10-23 15:47:21 +04:00
|
|
|
local -a enablesites disablesites
|
2015-12-24 09:58:09 +04:00
|
|
|
if [ -d "$sitesdir" -a \( -z "$onecms" -o -n "$onesite" \) ]; then
|
2014-10-23 15:47:21 +04:00
|
|
|
local -a confs
|
2016-12-30 18:10:59 +04:00
|
|
|
local conf confname destconf certsconf sedscript copied
|
2014-10-23 15:47:21 +04:00
|
|
|
etitle "Installation des sites"
|
2016-12-30 18:10:59 +04:00
|
|
|
array_from_lines confs "$(list_files "$sitesdir" "*.conf")"
|
2016-04-07 23:55:50 +04:00
|
|
|
for confname in "${confs[@]}"; do
|
|
|
|
conf="$sitesdir/$confname"
|
2015-12-07 04:43:46 +04:00
|
|
|
[ -z "$onesite" -o "$confname" == "$onesite" ] || continue
|
|
|
|
|
2014-10-23 15:47:21 +04:00
|
|
|
certsconf=
|
2015-12-07 04:43:46 +04:00
|
|
|
if [ "${confname%.ssl.conf}" != "$confname" ]; then
|
2016-10-20 10:28:06 +04:00
|
|
|
if quietgrep -E '^[^#]*@@(cert|key|ca)@@' "$conf"; then
|
|
|
|
if [ -d "$certsconfdir" ]; then
|
|
|
|
certsconf="${confname%.ssl.conf}-certs.conf"
|
|
|
|
else
|
|
|
|
ewarn "$conf: fichier ignoré parce que --certsconfdir n'a pas été spécifié"
|
|
|
|
fi
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
|
|
|
fi
|
2015-12-24 10:09:29 +04:00
|
|
|
case "$confname" in
|
2016-04-07 23:55:50 +04:00
|
|
|
default.conf) destconf="$confdefault";;
|
|
|
|
default.ssl.conf) destconf="$confdefaultssl";;
|
2015-12-07 04:43:46 +04:00
|
|
|
*) destconf="$confname";;
|
2014-10-23 15:47:21 +04:00
|
|
|
esac
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
copied=
|
2014-10-23 15:47:21 +04:00
|
|
|
if [ -n "$certsconf" ]; then
|
|
|
|
certsconf="$certsconfdir/$certsconf"
|
|
|
|
if [ -f "$certsconf" ]; then
|
2016-12-30 18:10:59 +04:00
|
|
|
__apache_rc_quiet=1 apache_resolvecert "$certsconf" "$certsdir" cert key ca || return 1
|
|
|
|
if [ -n "$cert" -a -n "$key" ]; then
|
|
|
|
sedscript="\
|
2014-10-23 15:47:21 +04:00
|
|
|
s#@@cert@@#$APACHESSLCERTSDIR/$(basename "$cert")#g
|
2016-12-30 18:10:59 +04:00
|
|
|
s#@@key@@#$APACHESSLKEYSDIR/$(basename "$key")#g"
|
|
|
|
if [ -n "$ca" ]; then
|
|
|
|
sedscript="$sedscript
|
|
|
|
s#@@ca@@#$APACHESSLCERTSDIR/$(basename "$ca")#g"
|
|
|
|
else
|
|
|
|
sedscript="$sedscript
|
|
|
|
/@@ca@@/s/^/#/g"
|
|
|
|
fi
|
|
|
|
__apache_autoconf_fillcopy \
|
|
|
|
"$conf" \
|
|
|
|
"$APACHEAVSITESDIR/$destconf" "$sedscript"
|
|
|
|
copied=1
|
|
|
|
else
|
|
|
|
eerror "$(ppath "$certsconf"): définition des certificats introuvable
|
|
|
|
Le fichier de configuration $confname a été ignoré"
|
|
|
|
fi
|
2014-10-23 15:47:21 +04:00
|
|
|
else
|
2016-12-30 18:10:59 +04:00
|
|
|
eerror "$(ppath "$certsconf"): fichier introuvable
|
|
|
|
Le fichier de configuration $confname a été ignoré"
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
|
|
|
else
|
2014-11-29 23:02:48 +04:00
|
|
|
__apache_autoconf_fillcopy \
|
|
|
|
"$conf" \
|
|
|
|
"$APACHEAVSITESDIR/$destconf"
|
2016-12-30 18:10:59 +04:00
|
|
|
copied=1
|
|
|
|
fi
|
|
|
|
if [ -n "$copied" ]; then
|
|
|
|
enablesites=("${enablesites[@]}" "$destconf")
|
|
|
|
modified=1
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
eend
|
|
|
|
fi
|
2014-11-29 23:02:48 +04:00
|
|
|
|
|
|
|
# Fichiers de configuration
|
2015-12-07 04:43:46 +04:00
|
|
|
if [ -d "$confdir" -a -z "$onecms" ]; then
|
2014-10-23 15:47:21 +04:00
|
|
|
local -a confs
|
|
|
|
local conf
|
2016-12-30 18:10:59 +04:00
|
|
|
|
2014-10-23 15:47:21 +04:00
|
|
|
etitle "Configuration de base"
|
2017-07-18 10:49:45 +04:00
|
|
|
array_add ignores syspkgs.conf confs.conf modules.conf sites.conf network.conf post-update.sh
|
2016-12-30 18:10:59 +04:00
|
|
|
array_from_lines confs "$(list_files "$confdir")"
|
2014-10-23 15:47:21 +04:00
|
|
|
for conf in "${confs[@]}"; do
|
2015-10-30 21:46:49 +04:00
|
|
|
array_contains ignores "$conf" && continue
|
2014-11-29 23:02:48 +04:00
|
|
|
__apache_autoconf_fillcopy \
|
|
|
|
"$confdir/$conf" \
|
|
|
|
"$APACHECONFDIR/$conf" && modified=1
|
2014-10-23 15:47:21 +04:00
|
|
|
done
|
2016-12-30 18:10:59 +04:00
|
|
|
|
|
|
|
array_from_lines confs "$(list_files "$confdir" "*rewrite*.rules")"
|
|
|
|
if [ ${#confs[*]} -gt 0 ]; then
|
|
|
|
etitle "Règles de réécriture"
|
|
|
|
for conf in "${confs[@]}"; do
|
|
|
|
[ -f "$APACHECONFDIR/$conf" ] || continue
|
|
|
|
estep "$conf"
|
|
|
|
legacy_mkRewriteRules "$APACHECONFDIR/$conf" && modified=1
|
|
|
|
done
|
|
|
|
eend
|
|
|
|
fi
|
|
|
|
|
2015-12-24 09:58:09 +04:00
|
|
|
if [ -f "$confdir/confs.conf" -a -n "$a2xconf" ]; then
|
2015-10-30 21:46:49 +04:00
|
|
|
local -a confs
|
|
|
|
local conf
|
|
|
|
array_from_lines confs "$(<"$confdir/confs.conf" filter_conf)"
|
|
|
|
for conf in "${confs[@]}"; do
|
|
|
|
if [ "${conf#-}" != "$conf" ]; then
|
|
|
|
conf="${conf#-}"
|
|
|
|
estep "Désactivation de la configuration $conf"
|
|
|
|
a2disconf "$conf" && modified=1
|
|
|
|
else
|
|
|
|
conf="${conf#+}"
|
|
|
|
estep "Activation de la configuration $conf"
|
|
|
|
a2enconf "$conf" && modified=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2014-10-23 15:47:21 +04:00
|
|
|
if [ -f "$confdir/modules.conf" ]; then
|
|
|
|
local -a modules
|
|
|
|
local module
|
|
|
|
array_from_lines modules "$(<"$confdir/modules.conf" filter_conf)"
|
|
|
|
for module in "${modules[@]}"; do
|
|
|
|
if [ "${module#-}" != "$module" ]; then
|
|
|
|
module="${module#-}"
|
2014-12-02 17:40:28 +04:00
|
|
|
estep "Désactivation du module $module"
|
|
|
|
a2dismod "$module" && modified=1
|
2014-10-23 15:47:21 +04:00
|
|
|
else
|
|
|
|
module="${module#+}"
|
2014-12-02 17:40:28 +04:00
|
|
|
estep "Activation du module $module"
|
|
|
|
a2enmod "$module" && modified=1
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
if [ -f "$confdir/sites.conf" ]; then
|
2016-04-07 23:55:50 +04:00
|
|
|
local -a sitesconfs; local sitesconf enable
|
2014-10-23 15:47:21 +04:00
|
|
|
array_from_lines sitesconfs "$(<"$confdir/sites.conf" filter_conf)"
|
|
|
|
if [ ${#sitesconfs[*]} -gt 0 ]; then
|
|
|
|
# si une configuration existe, ignorer la configuration
|
|
|
|
# automatique
|
|
|
|
enablesites=()
|
|
|
|
disablesites=()
|
|
|
|
for sitesconf in "${sitesconfs[@]}"; do
|
|
|
|
if [ "${sitesconf#+}" != "$sitesconf" ]; then
|
2016-04-07 23:55:50 +04:00
|
|
|
enable=1
|
|
|
|
sitesconf="${sitesconf#+}"
|
2014-10-23 15:47:21 +04:00
|
|
|
elif [ "${sitesconf#-}" != "$sitesconf" ]; then
|
2016-04-07 23:55:50 +04:00
|
|
|
enable=
|
|
|
|
sitesconf="${sitesconf#-}"
|
2014-10-23 15:47:21 +04:00
|
|
|
else
|
2016-04-07 23:55:50 +04:00
|
|
|
enable=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$sitesconf" in
|
|
|
|
default.conf) sitesconf="$confdefault";;
|
|
|
|
default.ssl.conf) sitesconf="$confdefaultssl";;
|
|
|
|
esac
|
|
|
|
if [ -n "$enable" ]; then
|
2014-10-23 15:47:21 +04:00
|
|
|
array_del disablesites "$sitesconf"
|
|
|
|
array_add enablesites "$sitesconf"
|
2016-04-07 23:55:50 +04:00
|
|
|
else
|
|
|
|
array_del enablesites "$sitesconf"
|
|
|
|
array_add disablesites "$sitesconf"
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
eend
|
|
|
|
fi
|
2014-11-29 23:02:48 +04:00
|
|
|
|
|
|
|
# Scripts CGI
|
2015-12-07 04:43:46 +04:00
|
|
|
if [ -d "$cgibindir" -a -z "$onecms" ]; then
|
2014-10-23 15:47:21 +04:00
|
|
|
etitle "Installation des scripts CGI"
|
|
|
|
cpdirnovcs "$cgibindir" "$CGIBINDIR"
|
|
|
|
eend
|
|
|
|
fi
|
2014-11-29 23:02:48 +04:00
|
|
|
|
|
|
|
# Contenu web
|
2016-12-30 18:10:59 +04:00
|
|
|
if [ -z "$onecms" ]; then
|
|
|
|
etitled "Installation des fichiers du serveur web"
|
|
|
|
if is_defined HTDMAPPINGS; then
|
|
|
|
local htdmapping src dest
|
|
|
|
for htdmapping in "${HTDMAPPINGS[@]}"; do
|
|
|
|
splitpair "$htdmapping" dest src
|
|
|
|
[ -n "$dest" ] || dest=html
|
|
|
|
case "$dest" in
|
|
|
|
html) [ -n "$src" ] || src=www;;
|
|
|
|
*) [ -n "$src" ] || src="$dest";;
|
|
|
|
esac
|
|
|
|
withpath "$src" || src="$confdir/$src"
|
|
|
|
withpath "$dest" || dest="$HTDOCSBASE/$dest"
|
|
|
|
estep "$src --> $dest"
|
|
|
|
cpdirnovcs "$src" "$dest"
|
|
|
|
# par défaut, le propriétaire est root. est-ce nécessaire?
|
|
|
|
#chown -R www-data: "$dest"
|
|
|
|
done
|
|
|
|
elif [ -d "$wwwdir" ]; then
|
|
|
|
estep "$wwwdir --> $HTDOCSDIR"
|
|
|
|
cpdirnovcs "$wwwdir" "$HTDOCSDIR"
|
|
|
|
# par défaut, le propriétaire est root. est-ce nécessaire?
|
|
|
|
#chown -R www-data: "$HTDOCSDIR"
|
|
|
|
fi
|
2014-10-23 15:47:21 +04:00
|
|
|
eend
|
|
|
|
fi
|
|
|
|
|
2014-11-29 23:02:48 +04:00
|
|
|
# Nettoyer le fichier temporaire
|
|
|
|
ac_clean "$FILLTEMP"
|
|
|
|
|
2014-10-23 15:47:21 +04:00
|
|
|
if [ -n "${enablesites[*]}" -o -n "${disablesites[*]}" ]; then
|
|
|
|
etitle "(dés)Activation des sites"
|
|
|
|
local site
|
|
|
|
for site in "${enablesites[@]}"; do
|
2014-12-02 17:42:14 +04:00
|
|
|
estep "Activation du site $site"
|
2014-10-23 15:47:21 +04:00
|
|
|
a2ensite "$site"
|
|
|
|
done
|
|
|
|
for site in "${disablesites[@]}"; do
|
2014-12-02 17:42:14 +04:00
|
|
|
estep "Désactivation du site $site"
|
2014-10-23 15:47:21 +04:00
|
|
|
a2dissite "$site"
|
|
|
|
done
|
|
|
|
eend
|
|
|
|
fi
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
# Mettre à jour la configuration réseau
|
|
|
|
if [ -z "$onecms" -a -n "$netconf" -a -f "$confdir/network.conf" ]; then
|
|
|
|
local -a ips brs; local host etc_networks
|
|
|
|
eval "$(
|
|
|
|
source "$confdir/network.conf"
|
|
|
|
set_array_cmd ips
|
|
|
|
set_array_cmd brs
|
|
|
|
echo_setv host "$host"
|
|
|
|
echo_setv etc_networks "$etc_networks"
|
|
|
|
)"
|
|
|
|
etitled "Vérification de la configuration du réseau"
|
|
|
|
if [ -n "$FULLCONF" ]; then
|
|
|
|
if [ ${#ips[*]} -gt 0 -o ${#brs[*]} -gt 0 -o -n "$hosts" ]; then
|
|
|
|
network_config "$host" ips brs && modified=1
|
|
|
|
fi
|
|
|
|
[ -n "$etc_networks" ] && network_update_etc_networks "$etc_networks"
|
|
|
|
else
|
|
|
|
if [ ${#ips[*]} -gt 0 ]; then
|
|
|
|
network_config_partial ips && modified=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
eend
|
|
|
|
fi
|
|
|
|
|
2015-11-12 15:40:08 +04:00
|
|
|
if [ -n "$modified" ]; then
|
|
|
|
[ -n "$rehash" ] && elinedots "Hashage des certificats" c_rehash
|
|
|
|
if [ -n "$restart" ]; then
|
|
|
|
estep "Redémarrage d'apache"
|
|
|
|
"$APACHECTL" restart
|
|
|
|
fi
|
2014-10-23 15:47:21 +04:00
|
|
|
fi
|
|
|
|
}
|
2015-12-07 04:43:46 +04:00
|
|
|
|
|
|
|
function apache_autoconf_localhosts() {
|
|
|
|
eval "$(utools_local)"
|
2015-12-07 11:14:29 +04:00
|
|
|
local autoconfdir sitesdir onesite
|
2015-12-07 04:43:46 +04:00
|
|
|
parse_opts "${PRETTYOPTS[@]}" \
|
|
|
|
--sitesdir: sitesdir= \
|
2015-12-07 11:14:29 +04:00
|
|
|
--one-site: onesite= \
|
2015-12-07 04:43:46 +04:00
|
|
|
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
__apache_autoconf_no_require_apache=1 __apache_autoconf_setup || return 1
|
2015-12-07 04:43:46 +04:00
|
|
|
|
|
|
|
# Configuration
|
|
|
|
autoconfdir="$1"; shift
|
|
|
|
[ -n "$autoconfdir" ] || {
|
|
|
|
eerror "Vous devez spécifier le répertoire de base de la configuration apache"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
[ -n "$sitesdir" ] || sitesdir="$autoconfdir/sites"
|
|
|
|
|
|
|
|
# Faire un script sed pour remplacer les variables spécifiées par leur
|
|
|
|
# valeur dans les fichiers
|
|
|
|
local -a FILLVARS; local FILLSCRIPT FILLTEMP ULIB_INSTALL_VERBOSE
|
2016-03-08 11:51:46 +04:00
|
|
|
__apache_autoconf_fillxxx "$@"
|
2015-12-07 04:43:46 +04:00
|
|
|
|
|
|
|
local -a newhosts
|
|
|
|
if [ -d "$sitesdir" ]; then
|
|
|
|
local -a localips localhosts confs candidates newhosts
|
|
|
|
local conf tmpconf candidate
|
|
|
|
|
|
|
|
array_from_lines localips "$(</etc/hosts awk '$1 ~ /127\./ { print $1 }' | sort -u)"
|
|
|
|
array_from_lines localhosts "$(</etc/hosts awk '$1 ~ /127\./ { for (i = 2; i <= NF; i++) { if ($i ~ /\.local$/) print $i } }' | sort -u)"
|
|
|
|
|
|
|
|
ac_set_tmpfile tmpconf
|
2015-12-07 11:14:29 +04:00
|
|
|
array_lsfiles confs "$sitesdir" "*.conf"
|
2015-12-07 04:43:46 +04:00
|
|
|
for conf in "${confs[@]}"; do
|
2015-12-07 11:14:29 +04:00
|
|
|
confname="$(basename "$conf")"
|
|
|
|
[ -z "$onesite" -o "$confname" == "$onesite" ] || continue
|
|
|
|
|
2015-12-07 04:43:46 +04:00
|
|
|
__apache_autoconf_fillcopy "$conf" "$tmpconf"
|
|
|
|
array_from_lines candidates "$(<"$tmpconf" awk '
|
|
|
|
$1 == "ServerName" && $2 ~ /\.local$/ { print $2 }
|
|
|
|
$1 == "ServerAlias" { for (i = 2; i <= NF; i++) { if ($i ~ /\.local$/) print $i } }
|
|
|
|
')"
|
|
|
|
for candidate in "${candidates[@]}"; do
|
|
|
|
array_contains localhosts "$candidate" || array_addu newhosts "$candidate"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
local ip host i=0
|
|
|
|
for host in "${newhosts[@]}"; do
|
|
|
|
i=$(($i + 1)); ip="127.0.1.$i"
|
|
|
|
while array_contains localips "$ip"; do
|
|
|
|
i=$(($i + 1)); ip="127.0.1.$i"
|
|
|
|
done
|
|
|
|
estep "Ajout de $ip $host"
|
|
|
|
echo "$ip $host" >>/etc/hosts
|
|
|
|
done
|
|
|
|
}
|
2016-08-18 17:01:49 +04:00
|
|
|
|
|
|
|
function __template_defaultf_host() {
|
|
|
|
myhost
|
|
|
|
}
|
|
|
|
function __template_updatef_host() {
|
|
|
|
if [ "$host" == "@@dhost@@" ]; then
|
|
|
|
__template_set_var hostname @@dhostname@@
|
|
|
|
__template_set_var aliases @@daliases@@
|
|
|
|
else
|
|
|
|
local update_aliases
|
|
|
|
[ "$aliases" == "$hostname" ] && update_aliases=1
|
|
|
|
__template_set_var hostname "${host%%.*}"
|
|
|
|
[ -n "$update_aliases" ] && __template_set_var aliases "$hostname"
|
|
|
|
[ -n "$ips" ] || __template_set_var ips ""
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function __template_defaultf_ips() {
|
|
|
|
local -a ips
|
|
|
|
if [ "$host" != "@@dhost@@" ]; then
|
|
|
|
resolv_ips ips "$host"
|
|
|
|
else
|
|
|
|
resolv_ips ips "$dhost"
|
|
|
|
fi
|
|
|
|
echo "${ips[*]}"
|
|
|
|
}
|
|
|
|
function __template_updatef_ips() {
|
|
|
|
local -a ipports; local ipport ip port
|
|
|
|
local nvhs ls
|
|
|
|
nvhs=
|
|
|
|
ls=
|
|
|
|
array_split ipports "$ips" " "
|
|
|
|
for ipport in "${ipports[@]}"; do
|
|
|
|
splitpair "$ipport" ip port
|
|
|
|
[ -n "$port" ] || port=443
|
|
|
|
[ -n "$nvhs" ] || nvhs="#ips_namevirtualhosts"
|
|
|
|
nvhs="$nvhs
|
|
|
|
NameVirtualHost $ip:$port"
|
|
|
|
[ -n "$ls" ] || ls="#ips_listens"
|
|
|
|
ls="$ls
|
|
|
|
Listen $ip:$port"
|
|
|
|
done
|
|
|
|
[ -n "$nvhs" ] && __template_set_var ips_namevirtualhosts "$nvhs"
|
|
|
|
[ -n "$ls" ] && __template_set_var ips_listens "$ls"
|
|
|
|
}
|
|
|
|
|
|
|
|
function __template_defaultf_dhost() {
|
|
|
|
myhost
|
|
|
|
}
|
|
|
|
function __template_updatef_dhost() {
|
|
|
|
local update_daliases
|
|
|
|
[ "$daliases" == "$dhostname" ] && update_daliases=1
|
|
|
|
__template_set_var dhostname "${dhost%%.*}"
|
|
|
|
[ -n "$update_daliases" ] && __template_set_var daliases "$dhostname"
|
|
|
|
[ -n "$ips" ] || __template_set_var ips ""
|
|
|
|
}
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
# syntaxe: var[:depvars,...][=desc]
|
2016-08-18 17:01:49 +04:00
|
|
|
APACHECONFIG_TEMPLATE_STATIC_VARS=(
|
2016-12-30 18:10:59 +04:00
|
|
|
host:hostname,aliases="hôte pour lequel ce template a été créé.
|
|
|
|
# les variables hostname et aliases sont automatiquement générées.
|
|
|
|
# utiliser @@dhost@@ pour déployer dynamiquement avec le nom d'hôte courant."
|
|
|
|
certsdir="répertoire par défaut contenant les certificats à déployer"
|
|
|
|
caname="nom de l'autorité par défaut"
|
2016-08-18 17:01:49 +04:00
|
|
|
)
|
|
|
|
APACHECONFIG_TEMPLATE_DYNAMIC_VARS=(
|
2016-12-30 18:10:59 +04:00
|
|
|
ips:ips_namevirtualhosts,ips_listens="liste d'adresses de la forme ip[:port], séparées par un espace.
|
|
|
|
# ces adresses sont celles sur lesquelles apache doit écouter. ce paramètre n'a
|
|
|
|
# de sens que sur squeeze. en effet, la configuration par défaut sur jessie rend
|
|
|
|
# ce paramétrage inutile."
|
|
|
|
dhost:dhostname,daliases="hôte pour lequel les fichiers doivent être déployés.
|
|
|
|
# les variables dhostname et daliases sont automatiquement générées.
|
|
|
|
# cette variable n'a besoin d'être modifiée que si host=@@dhost@@ ci-dessous"
|
|
|
|
admin="mail de l'administrateur du serveur"
|
|
|
|
configdir="répertoire dans lequel le template a été généré"
|
|
|
|
)
|
|
|
|
APACHECONFIG_TEMPLATE_NOWRITE_VARS=(configdir)
|
|
|
|
APACHECONFIG_TEMPLATE_USER_VARS=(
|
|
|
|
FULLCONF="Est-on en mode configuration complète?"
|
|
|
|
HTDMAPPINGS="Mapping des répertoires destination dans /var/www vers le répertoire local, e.g. html:www"
|
2016-08-18 17:01:49 +04:00
|
|
|
)
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
function __apacheconfig_initsrcdirs() {
|
|
|
|
if check_sysinfos "$@" -d debian -v jessie+; then
|
|
|
|
TEMPLATECTL_SRCDIRS=(apacheconfig.d8)
|
|
|
|
else
|
|
|
|
TEMPLATECTL_SRCDIRS=(apacheconfig)
|
|
|
|
fi
|
|
|
|
}
|
2016-08-18 17:01:49 +04:00
|
|
|
function apacheconfig_initvars() {
|
|
|
|
DEFAULT_ADMIN=supervision-gdrsi@listes.univ-reunion.fr
|
|
|
|
DEFAULT_CERTSDIR=1507-renater
|
|
|
|
DEFAULT_CANAME=1507-DigiCertCA.crt
|
2017-03-24 09:42:38 +04:00
|
|
|
PUBDOMAINS=(univ-reunion.fr)
|
|
|
|
PRIDOMAINS=(univ.run)
|
|
|
|
VSPREFIX=vs-
|
2016-08-18 17:01:49 +04:00
|
|
|
set_defaults apacheconfig
|
|
|
|
|
|
|
|
TEMPLATE_NOWRITE_VARS=("${APACHECONFIG_TEMPLATE_NOWRITE_VARS[@]}")
|
2016-12-30 18:10:59 +04:00
|
|
|
template_build_vars TEMPLATE_STATIC_VARS TEMPLATE_NOWRITE_VARS "${APACHECONFIG_TEMPLATE_STATIC_VARS[@]}"
|
|
|
|
template_build_vars TEMPLATE_DYNAMIC_VARS TEMPLATE_NOWRITE_VARS "${APACHECONFIG_TEMPLATE_DYNAMIC_VARS[@]}"
|
|
|
|
template_build_vars TEMPLATE_USER_VARS "" "${APACHECONFIG_TEMPLATE_USER_VARS[@]}"
|
2016-08-18 17:01:49 +04:00
|
|
|
__TEMPLATE_DEFAULTF_host=__template_defaultf_host
|
|
|
|
__TEMPLATE_UPDATEF_host=__template_updatef_host
|
|
|
|
__TEMPLATE_DEFAULTF_ips=__template_defaultf_ips
|
|
|
|
__TEMPLATE_UPDATEF_ips=__template_updatef_ips
|
|
|
|
__TEMPLATE_DEFAULTF_dhost=__template_defaultf_dhost
|
|
|
|
__TEMPLATE_UPDATEF_dhost=__template_updatef_dhost
|
|
|
|
|
|
|
|
TEMPLATECTL_NAME=apacheconfig
|
2016-12-30 18:10:59 +04:00
|
|
|
__apacheconfig_initsrcdirs
|
2016-08-18 17:01:49 +04:00
|
|
|
TEMPLATECTL_CONFIG="$TEMPLATECTL_NAME"
|
|
|
|
TEMPLATECTL_DEFAULTS=(
|
|
|
|
admin="$DEFAULT_ADMIN"
|
|
|
|
certsdir="$DEFAULT_CERTSDIR"
|
|
|
|
caname="$DEFAULT_CANAME"
|
|
|
|
)
|
|
|
|
TEMPLATECTL_VARS=()
|
|
|
|
}
|
|
|
|
|
|
|
|
function apacheconfig_loadconf() {
|
2016-12-30 18:10:59 +04:00
|
|
|
local config modified autocreate
|
|
|
|
local destdir="$1" nohideconfig="$2"
|
|
|
|
|
|
|
|
# valeurs par défaut
|
|
|
|
is_defined HTDMAPPINGS || HTDMAPPINGS=(html:www)
|
2016-08-18 17:01:49 +04:00
|
|
|
|
|
|
|
__template_set_destdir destdir autocreate "$TEMPLATECTL_NAME" || return 1
|
2016-12-30 18:10:59 +04:00
|
|
|
setx config=templatectl_config "$destdir" ${nohideconfig:+nohideconfig}
|
2016-08-18 17:01:49 +04:00
|
|
|
modified=
|
|
|
|
templatectl_loadvars "$config" && modified=1
|
|
|
|
|
2016-10-19 11:57:35 +04:00
|
|
|
upvars config "$config" modified "$modified" \
|
|
|
|
destdir "$destdir" autocreate "$autocreate"
|
2016-08-18 17:01:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function apacheconfig_sysinfos() {
|
|
|
|
local sysname="$1" sysdist="$2" sysver="$3" bits="$4" custom_sysinfos
|
|
|
|
|
|
|
|
if [ -n "$sysname" -o -n "$sysdist" -o -n "$sysver" ]; then
|
|
|
|
ensure_sysinfos sysname sysdist sysver
|
|
|
|
custom_sysinfos=1
|
|
|
|
else
|
|
|
|
sysname="$MYSYSNAME"
|
|
|
|
sysdist="$MYSYSDIST"
|
|
|
|
sysver="$MYSYSVER"
|
|
|
|
bits="$MYBITS"
|
|
|
|
custom_sysinfos=
|
|
|
|
fi
|
|
|
|
__template_set_var sysname "$sysname"
|
|
|
|
__template_set_var sysdist "$sysdist"
|
|
|
|
__template_set_var sysver "$sysver"
|
2016-12-30 18:10:59 +04:00
|
|
|
# mettre à jour la source en fonction du système cible
|
|
|
|
__apacheconfig_initsrcdirs --vars sysname sysdist sysver bits
|
2016-08-18 17:01:49 +04:00
|
|
|
|
|
|
|
upvars sysname "$sysname" sysdist "$sysdist" sysver "$sysver" bits "$bits" \
|
|
|
|
custom_sysinfos "$custom_sysinfos"
|
|
|
|
}
|
|
|
|
|
|
|
|
function apacheconfig_deploy() {
|
|
|
|
local destdir="$1" certsdir="$2"; shift; shift
|
|
|
|
local config="$1" oneconf="$2" onemodule="$3"; onesite="$4"; shift; shift; shift; shift
|
|
|
|
local custom_sysinfos="$1" sysname="$2" sysdist="$3" sysver="$4" bits="$5"; shift; shift; shift; shift; shift
|
2017-07-18 10:49:45 +04:00
|
|
|
local netconf="$1" fixip="$2" no_post_update="$3"; shift; shift; shift
|
|
|
|
local configdir="$(basename -- "$config")"
|
2016-08-18 17:01:49 +04:00
|
|
|
|
|
|
|
local -a args
|
2017-07-18 10:49:45 +04:00
|
|
|
args=(--ignore "$configdir")
|
2016-08-18 17:01:49 +04:00
|
|
|
[ -n "$oneconf" ] && array_add args --one-conf "$(basename -- "$oneconf")"
|
|
|
|
[ -n "$onemodule" ] && array_add args --one-module "$(basename -- "$onemodule")"
|
|
|
|
[ -n "$onesite" ] && array_add args --one-site "$(basename -- "$onesite")"
|
|
|
|
[ -n "$custom_sysinfos" ] && array_add args --sysname "$sysname" --sysdist "$sysdist" --sysver "$sysver" --bits "$bits"
|
2016-12-30 18:10:59 +04:00
|
|
|
[ -n "$netconf" ] && array_add args --network-config
|
2017-03-24 15:06:40 +04:00
|
|
|
[ -n "$fixip" ] && array_add args --fix-ip
|
2016-08-18 17:01:49 +04:00
|
|
|
array_add args "$destdir" "$certsdir"
|
|
|
|
for __name in "${TEMPLATE_DYNAMIC_VARS[@]}"; do
|
|
|
|
array_add args "$__name=${!__name}"
|
|
|
|
done
|
2017-07-18 10:49:45 +04:00
|
|
|
apache_autoconf "${args[@]}" "$@" || return 1
|
|
|
|
if [ -x "$configdir/post-update.sh" ]; then
|
|
|
|
"$configdir/post-update.sh" \
|
|
|
|
"$destdir" "$certsdir" \
|
|
|
|
"$config" "$oneconf" "$onemodule" "$onesite" \
|
|
|
|
"$custom_sysinfos" "$sysname" "$sysdist" "$sysver" "$bits" \
|
|
|
|
"$netconf" "$fixip" || return 2
|
|
|
|
fi
|
|
|
|
return 0
|
2016-08-18 17:01:49 +04:00
|
|
|
}
|
|
|
|
|
2016-12-30 18:10:59 +04:00
|
|
|
function apacheconfig_qs() {
|
|
|
|
# fonction pour simplifier l'utilisation de apacheconfig_deploy pour un
|
|
|
|
# répertoire spécifique
|
2017-03-24 15:06:40 +04:00
|
|
|
# $1=destdir $2=certsdir $3=netconf $4=fixip
|
2016-12-30 18:10:59 +04:00
|
|
|
local config modified destdir autocreate
|
|
|
|
apacheconfig_initvars
|
|
|
|
apacheconfig_loadconf "$1"
|
|
|
|
apacheconfig_deploy \
|
|
|
|
"$destdir" "$2" \
|
|
|
|
"$config" "" "" "" \
|
|
|
|
"" "" "" "" "" \
|
2017-07-18 10:49:45 +04:00
|
|
|
"$3" "$4" ""
|
2016-12-30 18:10:59 +04:00
|
|
|
}
|
|
|
|
|
2016-08-18 17:01:49 +04:00
|
|
|
function apacheconfig_localhosts() {
|
|
|
|
local destdir="$1" certsdir="$2"; shift; shift
|
|
|
|
local onesite="$1"; shift
|
|
|
|
|
|
|
|
local -a args
|
|
|
|
[ -n "$onesite" ] && array_add args --one-site "$(basename -- "$onesite")"
|
|
|
|
array_add args "$destdir" "$certsdir"
|
|
|
|
for __name in "${TEMPLATE_DYNAMIC_VARS[@]}"; do
|
|
|
|
array_add args "$__name=${!__name}"
|
|
|
|
done
|
|
|
|
apache_autoconf_localhosts "${args[@]}" "$@"
|
|
|
|
}
|
2016-12-30 18:10:59 +04:00
|
|
|
|
|
|
|
function __mrr_joinurl() {
|
|
|
|
# joindre chaque élément de $1..@ par /, en évitant les slashes en double
|
|
|
|
local i url
|
|
|
|
for i in "$@"; do
|
|
|
|
[ -n "$i" ] || continue
|
|
|
|
if [ -n "$url" ]; then
|
|
|
|
url="${url%/}/${i#/}"
|
|
|
|
else
|
|
|
|
url="$i"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
[ -n "$url" ] && echo "$url"
|
|
|
|
}
|
|
|
|
function __mrr_has_proxy() {
|
|
|
|
# vérifier que les options $1 contiennent 'P'
|
|
|
|
local -a options
|
|
|
|
array_split options "$1" ","
|
|
|
|
array_contains options P
|
|
|
|
}
|
|
|
|
function legacy_mkRewriteRules() {
|
|
|
|
# $1=infile, $2=thishost, $3=outfile, $4=htmlfile, $5=proxy_enabled?
|
|
|
|
local infile="$1" thishost="$2" outfile="$3" htmlfile="$4" proxy_enabled="$5"
|
|
|
|
local -a rules; local rule prefix index done current
|
|
|
|
local tmpinfile tmpoutfile
|
|
|
|
local src dest host suffix options prot proxy_acls usrc trail noslash proxy_url proxy_use
|
|
|
|
|
|
|
|
if [ -z "$infile" -o "$infile" == - ]; then
|
|
|
|
infile=/dev/stdin
|
|
|
|
elif [ -z "$outfile" ]; then
|
|
|
|
local outdir="$(dirname -- "$infile")"
|
|
|
|
outfile="$(basename -- "$infile")"
|
|
|
|
if [[ "$outfile" == *rewrite*.rules ]]; then
|
|
|
|
outfile="${outfile/rewrite/RewriteRules}"
|
|
|
|
outfile="${outfile/.rules/.conf}"
|
|
|
|
else
|
|
|
|
outfile="$outfile-RewriteRules.conf"
|
|
|
|
fi
|
|
|
|
outfile="$outdir/$outfile"
|
|
|
|
fi
|
|
|
|
[ -n "$outfile" -a "$outfile" != - ] || outfile=/dev/stdout
|
|
|
|
|
|
|
|
if [ -z "$thishost" -o -z "$proxy_enabled" ]; then
|
|
|
|
# le cas échéant, lire les paramètres manquant depuis le fichier
|
|
|
|
if [ "$infile" == /dev/stdin ]; then
|
|
|
|
ac_set_tmpfile tmpinfile
|
|
|
|
cat >"$tmpinfile"
|
|
|
|
infile="$tmpinfile"
|
|
|
|
fi
|
|
|
|
eval "$(awkrun -f <"$infile" '
|
|
|
|
/^[^#]/ { exit 0 }
|
|
|
|
/^#+ *host *=/ { sub(/^#+ *host *= */, ""); sub(/ *$/, ""); print "thishost=" qval($0); next }
|
|
|
|
/^#+ *enable_proxy *=/ { sub(/^#+ *enable_proxy *= */, ""); sub(/ *$/, ""); print "proxy_enabled=" qval($0); next }
|
|
|
|
')"
|
|
|
|
fi
|
|
|
|
[ -n "$thishost" ] || thishost="$(myhost)"
|
|
|
|
normyesval proxy_enabled
|
|
|
|
|
|
|
|
if [ -n "$htmlfile" ]; then
|
|
|
|
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
|
|
<!-- -*- coding: utf-8 mode: html -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
|
|
-->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<title>'"$thishost</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h2>$thishost</h2>
|
|
|
|
<ul>" >"$htmlfile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ac_set_tmpfile tmpoutfile
|
|
|
|
array_from_lines rules "$(<"$infile" filter_comment)"
|
|
|
|
prefix=
|
|
|
|
for rule in "${rules[@]}"; do
|
|
|
|
if beginswith "$rule" ^; then
|
|
|
|
# Collecter les préfixe pour la règle suivante
|
|
|
|
prefix="${prefix:+$prefix
|
|
|
|
}${rule#^}"
|
|
|
|
continue
|
|
|
|
elif beginswith "$rule" =; then
|
|
|
|
# ligne litérale
|
|
|
|
echo "${rule#=}" >>"$tmpoutfile"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
local IFS=:; set -- $rule; unset IFS
|
|
|
|
index=1
|
|
|
|
done=
|
|
|
|
while [ -z "$done" ]; do
|
|
|
|
current="$1"; shift
|
|
|
|
while [ "${current%\\}" != "$current" ]; do
|
|
|
|
current="${current%\\}:$1"; shift
|
|
|
|
done
|
|
|
|
case $index in
|
|
|
|
1) src="$current";;
|
|
|
|
2) dest="$current";;
|
|
|
|
3) host="$current";;
|
|
|
|
4) suffix="$current";;
|
|
|
|
5) options="$current";;
|
|
|
|
6) prot="${current:-http}";;
|
|
|
|
7) proxy_acls="$current";;
|
|
|
|
*) done=1;;
|
|
|
|
esac
|
|
|
|
index=$(($index + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
# mettre en forme prefix s'il est défini
|
|
|
|
[ -n "$prefix" ] && prefix="$prefix
|
|
|
|
"
|
|
|
|
|
|
|
|
[ "$thishost" == "$host" ] && host=
|
|
|
|
|
|
|
|
usrc="$src"
|
|
|
|
|
|
|
|
trail=1
|
|
|
|
if endswith "$src" '$'; then
|
|
|
|
trail=
|
|
|
|
usrc="${src%$}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
noslash=
|
|
|
|
if endswith "$suffix" '$'; then
|
|
|
|
noslash=1
|
|
|
|
suffix="${suffix%$}"
|
|
|
|
fi
|
|
|
|
if endswith "$dest" '$'; then
|
|
|
|
noslash=1
|
|
|
|
dest="${dest%$}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
proxy_url=
|
|
|
|
proxy_use=
|
|
|
|
|
|
|
|
if endswith "$dest" .woa; then
|
|
|
|
# lien vers une application
|
|
|
|
if [ -n "$host" ]; then
|
|
|
|
# sur un autre hôte
|
|
|
|
if [ -n "$noslash" ]; then
|
|
|
|
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(__mrr_joinurl "$prot://$host/cgi-bin/WebObjects" "$dest" "$suffix")${trail:+\$1} [L${options:+,$options}]" >>"$tmpoutfile"
|
|
|
|
setx url __mrr_joinurl "http://$thishost" "$usrc"
|
|
|
|
setx proxy_url __mrr_joinurl "$prot://$host/cgi-bin/WebObjects" "$dest" "$suffix"
|
|
|
|
else
|
|
|
|
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$tmpoutfile"
|
|
|
|
echo "${prefix}RewriteRule ^/$src/(.*) $(__mrr_joinurl "$prot://$host/cgi-bin/WebObjects" "$dest" "$suffix" "\$1") [L${options:+,$options}]" >>"$tmpoutfile"
|
|
|
|
setx url __mrr_joinurl "http://$thishost" "$usrc/"
|
|
|
|
setx proxy_url __mrr_joinurl "$prot://$host/cgi-bin/WebObjects" "$dest" "$suffix/"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# sur le même hôte
|
|
|
|
if [ -n "$noslash" ]; then
|
|
|
|
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(__mrr_joinurl /cgi-bin/WebObjects "$dest" "$suffix")${trail:+\$1} [L,P${options:+,$options}]" >>"$tmpoutfile"
|
|
|
|
setx url __mrr_joinurl "http://$thishost" "$usrc"
|
|
|
|
setx proxy_url __mrr_joinurl "$prot://$thishost/cgi-bin/WebObjects" "$dest" "$suffix"
|
|
|
|
proxy_use=1
|
|
|
|
else
|
|
|
|
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$tmpoutfile"
|
|
|
|
echo "${prefix}RewriteRule ^/$src/(.*) $(__mrr_joinurl /cgi-bin/WebObjects "$dest" "$suffix" "\$1") [L,P${options:+,$options}]" >>"$tmpoutfile"
|
|
|
|
setx url __mrr_joinurl "http://$thishost" "$usrc/"
|
|
|
|
setx proxy_url __mrr_joinurl "$prot://$thishost/cgi-bin/WebObjects" "$dest" "$suffix/"
|
|
|
|
proxy_use=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# lien vers une url
|
|
|
|
if [ -n "$host" ]; then
|
|
|
|
# sur un autre hôte
|
|
|
|
if [ -n "$noslash" ]; then
|
|
|
|
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(__mrr_joinurl "$prot://$host" "$dest" "$suffix")${trail:+\$1} [L${options:+,$options}]" >>"$tmpoutfile"
|
|
|
|
setx url __mrr_joinurl "http://$thishost" "$usrc"
|
|
|
|
setx proxy_url __mrr_joinurl "$prot://$host" "$dest" "$suffix"
|
|
|
|
else
|
|
|
|
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$tmpoutfile"
|
|
|
|
echo "${prefix}RewriteRule ^/$src/(.*) $(__mrr_joinurl "$prot://$host" "$dest" "$suffix" "\$1") [L${options:+,$options}]" >>"$tmpoutfile"
|
|
|
|
setx url __mrr_joinurl "http://$thishost" "$usrc/"
|
|
|
|
setx proxy_url __mrr_joinurl "$prot://$host" "$dest" "$suffix/"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# sur le même hôte
|
|
|
|
if [ -n "$noslash" ]; then
|
|
|
|
echo "${prefix}RewriteRule ^/$src${trail:+(.*)} $(__mrr_joinurl / "$dest" "$suffix")${trail:+\$1}${options:+ [$options]}" >>"$tmpoutfile"
|
|
|
|
setx url __mrr_joinurl "http://$thishost" "$usrc"
|
|
|
|
setx proxy_url __mrr_joinurl "http://$thishost" "$dest" "$suffix"
|
|
|
|
else
|
|
|
|
echo "${prefix}RewriteRule ^/$src\$ /$src/" >>"$tmpoutfile"
|
|
|
|
echo "${prefix}RewriteRule ^/$src/(.*) $(__mrr_joinurl / "$dest" "$suffix" "\$1")${options:+ [$options]}" >>"$tmpoutfile"
|
|
|
|
setx url __mrr_joinurl "http://$thishost" "$usrc/"
|
|
|
|
setx proxy_url __mrr_joinurl "http://$thishost" "$dest" "$suffix/"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
__mrr_has_proxy "$options" && proxy_use=1
|
|
|
|
if [ -n "$proxy_enabled" -a -n "$proxy_use" ]; then
|
|
|
|
if [ "$proxy_acls" == "None" ]; then
|
|
|
|
:
|
|
|
|
elif [ -z "$proxy_acls" ]; then
|
|
|
|
echo "\
|
|
|
|
<Proxy $proxy_url*>
|
|
|
|
AddDefaultCharset off
|
|
|
|
Order Deny,Allow
|
|
|
|
Allow from all
|
|
|
|
</Proxy>" >>"$tmpoutfile"
|
|
|
|
else
|
|
|
|
echo "\
|
|
|
|
<Proxy $proxy_url*>
|
|
|
|
AddDefaultCharset off
|
|
|
|
Order Allow,Deny
|
|
|
|
Allow from $proxy_acls
|
|
|
|
</Proxy>" >>"$tmpoutfile"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "" >>"$tmpoutfile"
|
|
|
|
if [ -n "$htmlfile" ]; then
|
|
|
|
echo "<li><a href=\"$url\">$url</a></li>" >>"$htmlfile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Réinitialiser les préfixes pour chaque règle
|
|
|
|
prefix=
|
|
|
|
done
|
|
|
|
|
|
|
|
local modified
|
|
|
|
if testupdated "$tmpoutfile" "$outfile"; then
|
|
|
|
cat "$tmpoutfile" >"$outfile"
|
|
|
|
modified=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$htmlfile" ]; then
|
|
|
|
echo '</ul>
|
|
|
|
</body>
|
|
|
|
</html>' >>"$htmlfile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$tmpinfile" ] && ac_clean "$tmpinfile"
|
|
|
|
ac_clean "$tmpoutfile"
|
|
|
|
[ -n "$modified" ]
|
|
|
|
}
|