Virtual Hosting updated (report from alternc-vhost)
* Provide a file by host typology * a file to generic functions (enable/disable host) * a generic directory to provide different host function Evolution du systeme de création d'hôte * Fournir un fichier par type de hote à créer (panel, webmail, redirection, ...) * Un fichier generique pour les (des)activation * Un repertoire dédié au differentes fonctions personnalisées
This commit is contained in:
parent
a55106e0e5
commit
888685bcb6
|
@ -419,6 +419,11 @@ src/basedir_prot.sh -text
|
|||
src/du.pl -text
|
||||
src/fixperms.sh -text
|
||||
src/functions.sh -text
|
||||
src/hosting_functions.sh -text
|
||||
src/hosting_functions/hosting_panel.sh -text
|
||||
src/hosting_functions/hosting_redirect.sh -text
|
||||
src/hosting_functions/hosting_vhost.sh -text
|
||||
src/hosting_functions/hosting_webmail.sh -text
|
||||
src/mail_add -text
|
||||
src/mail_del -text
|
||||
src/mem_add -text
|
||||
|
|
|
@ -127,7 +127,7 @@ change_host_ip() {
|
|||
if [ ! -f "$zone_file" ]; then
|
||||
echo "Should change $host.$domain, but can't find $zone_file."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if grep -q "$pattern" "$zone_file"; then
|
||||
cp -a -f "$zone_file" "$zone_file.$$"
|
||||
sed "s/$pattern/$a_line/" < "$zone_file" > "$zone_file.$$"
|
||||
|
@ -149,7 +149,7 @@ add_host() {
|
|||
local ip
|
||||
local fqdn
|
||||
local vhost_directory
|
||||
|
||||
|
||||
delete_host "$domain" "$host" "$host_type"
|
||||
|
||||
if [ "$host" = "@" -o -z "$host" ]; then
|
||||
|
@ -193,12 +193,11 @@ add_host() {
|
|||
|
||||
case "$host_type" in
|
||||
$TYPE_LOCAL)
|
||||
ln -snf "${HTML_HOME}/${user_letter}/${user}${value}" \
|
||||
"$vhost_directory"
|
||||
host_create_vhost $user $fqdn ${value}
|
||||
;;
|
||||
|
||||
$TYPE_WEBMAIL)
|
||||
ln -snf "${WEBMAIL_DIR}" "$vhost_directory"
|
||||
host_create_webmail $user $fqdn
|
||||
;;
|
||||
|
||||
$TYPE_URL)
|
||||
|
@ -207,12 +206,9 @@ add_host() {
|
|||
# followed by at least /
|
||||
value=`echo $value | sed -e 's#\([^/:]*://\)\?\([^/]*\)/*\(.*\)#\1\2/\3#'`
|
||||
|
||||
(echo "RewriteEngine on"
|
||||
echo "RewriteRule (.*) ${value}\$1 [R=permanent,L]"
|
||||
) > "$htaccess_directory/.htaccess"
|
||||
ln -snf "$htaccess_directory" "$vhost_directory"
|
||||
host_create_redirect $user $fqdn $value
|
||||
;;
|
||||
|
||||
|
||||
$TYPE_IP)
|
||||
rm -f "$vhost_directory"
|
||||
rm -rf "$htaccess_directory/.htaccess"
|
||||
|
@ -222,6 +218,7 @@ add_host() {
|
|||
echo "Unknow type code: $type" >> "$DOMAIN_LOG_FILE"
|
||||
;;
|
||||
esac
|
||||
host_enable_host $user $fqdn
|
||||
}
|
||||
|
||||
delete_host() {
|
||||
|
@ -233,7 +230,7 @@ delete_host() {
|
|||
local escaped_host
|
||||
local escaped_fqdn
|
||||
local pattern
|
||||
|
||||
|
||||
if [ "$host" = "@" -o -z "$host" ]; then
|
||||
fqdn="$domain"
|
||||
escaped_host=""
|
||||
|
@ -276,6 +273,7 @@ delete_host() {
|
|||
|
||||
rm -f "$HTTP_DNS/$domain_letter/$fqdn"
|
||||
rm -rf "$HTTP_DNS/redir/$domain_letter/$fqdn"
|
||||
host_disable_host $fqdn
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
HOST_DIR="/etc/apache2/sites-available"
|
||||
TEMPLATE_DIR="/etc/alternc/templates/apache2"
|
||||
DATA_ROOT="/var/alternc"
|
||||
|
||||
HTML_HOME="$DATA_ROOT/html"
|
||||
|
||||
HOSTING_DIR="/usr/lib/alternc/hosting_functions"
|
||||
|
||||
|
||||
. /usr/lib/alternc/functions.sh
|
||||
|
||||
if [ -d $HOSTING_DIR ]; then
|
||||
for i in $HOSTING_DIR/*.sh; do
|
||||
if [ -r $i ]; then
|
||||
. $i
|
||||
fi
|
||||
done
|
||||
unset i
|
||||
fi
|
||||
|
||||
|
||||
|
||||
host_prepare_conf() {
|
||||
local TEMPLATE=$1
|
||||
HOST_TMP=`mktemp`
|
||||
|
||||
cp $TEMPLATE_DIR"/"$TEMPLATE $HOST_TMP
|
||||
}
|
||||
|
||||
host_save_conf() {
|
||||
|
||||
local SOURCE=$1
|
||||
local TARGET=$2
|
||||
|
||||
TARGET_DIR=`dirname $TARGET`
|
||||
mkdir -p $TARGET_DIR
|
||||
mv $SOURCE $TARGET
|
||||
}
|
||||
|
||||
|
||||
host_enable_host() {
|
||||
local USER=$1
|
||||
local FQDN=$2
|
||||
|
||||
local FILE_TARGET="/etc/apache2/sites-enabled/"$FQDN
|
||||
local FILE_SOURCE=$HOST_DIR"/"$USER"/"$FQDN
|
||||
|
||||
if [ -L "$FILE_TARGET" ]; then
|
||||
rm $FILE_TARGET
|
||||
fi
|
||||
|
||||
ln -s $FILE_SOURCE $FILE_TARGET
|
||||
}
|
||||
|
||||
host_disable_host() {
|
||||
local FQDN=$1
|
||||
local CONF_FILE="/etc/apache2/sites-enabled/"$FQDN
|
||||
|
||||
if [ -e "$CONF_FILE" ]; then
|
||||
rm $CONF_FILE
|
||||
fi
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
host_create_panel() {
|
||||
|
||||
if [[ ( -z $1 ) || (-z $2 ) ]]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "création panel $1"
|
||||
|
||||
local USER=$1
|
||||
local FQDN=$2
|
||||
local TEMPLATE="panel.conf"
|
||||
local TARGET=$HOST_DIR"/"$USER"/"$FQDN
|
||||
host_prepare_conf $TEMPLATE #Return #HOST_TMP
|
||||
|
||||
sed -i \
|
||||
-e "s#%%fqdn%%#$FQDN#g" \
|
||||
$HOST_TMP
|
||||
|
||||
host_save_conf $HOST_TMP $TARGET
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
host_create_redirect() {
|
||||
|
||||
if [[ ( -z $1 ) || (-z $2 ) || ( -z $3) ]]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "création redirection pour $1 de $2 vers $3"
|
||||
|
||||
local USER=$1
|
||||
local FQDN=$2
|
||||
local REDIRECT=$3
|
||||
local TEMPLATE="redirect.conf"
|
||||
local TARGET=$HOST_DIR"/"$USER"/"$FQDN
|
||||
host_prepare_conf $TEMPLATE #Return #HOST_TMP
|
||||
|
||||
sed -i \
|
||||
-e "s#%%fqdn%%#${FQDN}#g" \
|
||||
-e "s#%%redirect%%#${REDIRECT}#g" \
|
||||
$HOST_TMP
|
||||
|
||||
host_save_conf $HOST_TMP $TARGET
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
host_create_vhost() {
|
||||
|
||||
if [[ ( -z $1 ) || (-z $2 ) || ( -z $3) ]]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "création vhost $1 pour $2, repertoire $3"
|
||||
|
||||
local USER=$1
|
||||
local FQDN=$2
|
||||
local TEMPLATE="vhost.conf"
|
||||
local TARGET=$HOST_DIR"/"$USER"/"$FQDN
|
||||
|
||||
local domain_letter=`print_domain_letter "$domain"`
|
||||
local user_letter=`print_user_letter "$user"`
|
||||
local DIRECTORY=${HTML_HOME}/${user_letter}/${user}$3
|
||||
|
||||
host_prepare_conf $TEMPLATE #Return #HOST_TMP
|
||||
|
||||
sed -i \
|
||||
-e "s#%%fqdn%%#$FQDN#g" \
|
||||
-e "s#%%document_root%%#$DIRECTORY#g" \
|
||||
$HOST_TMP
|
||||
|
||||
host_save_conf $HOST_TMP $TARGET
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
host_create_webmail() {
|
||||
|
||||
if [[ ( -z $1 ) || (-z $2 ) ]]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "création webmail $1 pour $2"
|
||||
|
||||
local USER=$1
|
||||
local FQDN=$2
|
||||
local TEMPLATE="webmail.conf"
|
||||
local TARGET=$HOST_DIR"/"$USER"/"$FQDN
|
||||
host_prepare_conf $TEMPLATE #Return #HOST_TMP
|
||||
|
||||
sed -i \
|
||||
-e "s#%%fqdn%%#$FQDN#g" \
|
||||
$HOST_TMP
|
||||
|
||||
host_save_conf $HOST_TMP $TARGET
|
||||
}
|
|
@ -109,7 +109,7 @@ MYSQL_DELETE="mysql --defaults-file=/etc/alternc/my.cnf "
|
|||
########################################################################
|
||||
# Functions
|
||||
#
|
||||
. /usr/lib/alternc/functions.sh
|
||||
. /usr/lib/alternc/hosting_functions.sh
|
||||
|
||||
########################################################################
|
||||
# Main
|
||||
|
|
Loading…
Reference in New Issue