2010-12-23 20:48:08 +00:00
|
|
|
TEMPLATE_DIR="/etc/alternc/templates/apache2"
|
|
|
|
HOSTING_DIR="/usr/lib/alternc/hosting_functions"
|
|
|
|
|
|
|
|
DATA_ROOT="/var/alternc"
|
|
|
|
HTML_HOME="$DATA_ROOT/html"
|
|
|
|
VHOST_DIR="$DATA_ROOT/apache-vhost"
|
|
|
|
VHOST_FILE="$VHOST_DIR/vhosts_all.conf"
|
|
|
|
|
|
|
|
. /usr/lib/alternc/functions.sh
|
|
|
|
|
|
|
|
host_create() {
|
|
|
|
# Function to create a vhost for a website
|
|
|
|
# First, it look if there is a special file for
|
2010-12-23 23:10:47 +00:00
|
|
|
# this type of vhost
|
2010-12-23 20:48:08 +00:00
|
|
|
# If there isn't, it use the default function
|
|
|
|
# and the template file provided
|
|
|
|
|
|
|
|
local VTYPE="$1"
|
|
|
|
|
|
|
|
if [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] ; then
|
|
|
|
# There is a script special for this type,
|
|
|
|
# I launch it and quit the host_create function
|
|
|
|
# (I precise to the script this is for a "enable" task)
|
|
|
|
"$HOSTING_DIR/hosting_$VTYPE.sh" "create" $@
|
2010-12-23 23:25:47 +00:00
|
|
|
local returnval=$?
|
|
|
|
|
2010-12-24 10:10:19 +00:00
|
|
|
# If the special script for this type exit with a code between
|
|
|
|
# 20 and 25, it means I have to continue like it didn't exist.
|
|
|
|
# It allow for example creation a script to exist only for deletion,
|
|
|
|
# or to do pre-inst or post-inst.
|
2010-12-23 23:25:47 +00:00
|
|
|
if [ $returnval -lt 20 ] || [ $returnval -gt 25 ] ; then
|
|
|
|
return
|
|
|
|
fi
|
2010-12-23 20:48:08 +00:00
|
|
|
fi
|
|
|
|
|
2010-12-23 23:10:47 +00:00
|
|
|
# There is no special script, I use the standart template
|
2010-12-23 20:48:08 +00:00
|
|
|
# If I do not found template manualy define, I look
|
|
|
|
# If there is an existing template with the good name
|
|
|
|
|
2010-12-23 23:10:47 +00:00
|
|
|
# First, usefull vars. Some may be empty or false, it's
|
2010-12-23 20:48:08 +00:00
|
|
|
# OK, it will be solve in the "case" below
|
|
|
|
local USER=$2
|
|
|
|
local FQDN=$3
|
|
|
|
local REDIRECT=$4 # Yes, TARGET_DIR and REDIRECT are the same
|
2010-12-23 23:10:47 +00:00
|
|
|
local TARGET_DIR=$4 # It's used by different template
|
2010-12-23 20:48:08 +00:00
|
|
|
local user_letter=`print_user_letter "$USER"`
|
|
|
|
local DOCUMENT_ROOT="${HTML_HOME}/${user_letter}/${USER}/$TARGET_DIR"
|
|
|
|
local FILE_TARGET="$VHOST_DIR/${user_letter}/$USER/$FQDN.conf"
|
|
|
|
|
|
|
|
|
2010-12-23 23:10:47 +00:00
|
|
|
# In case VTYPE don't have the same name as the template file,
|
|
|
|
# here we can define it
|
2010-12-23 20:48:08 +00:00
|
|
|
case $VTYPE in
|
2010-12-23 23:10:47 +00:00
|
|
|
# "example")
|
|
|
|
# TEMPLATE="$TEMPLATE_DIR/an-example.conf"
|
|
|
|
# ;;
|
2010-12-23 20:48:08 +00:00
|
|
|
*)
|
|
|
|
# No template found, look if there is some in the
|
2010-12-23 23:10:47 +00:00
|
|
|
# template dir
|
2010-12-23 20:48:08 +00:00
|
|
|
[ -r "$TEMPLATE_DIR/$VTYPE" ] && TEMPLATE="$TEMPLATE_DIR/$VTYPE"
|
|
|
|
[ ! "$TEMPLATE" ] && [ -r "$TEMPLATE_DIR/$VTYPE.conf" ] && TEMPLATE="$TEMPLATE_DIR/$VTYPE.conf"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-12-24 10:10:19 +00:00
|
|
|
# If TEMPLATE is empty, stop right here
|
|
|
|
[ ! "$TEMPLATE" ] && return 6
|
2010-12-23 23:25:47 +00:00
|
|
|
|
2010-12-23 23:10:47 +00:00
|
|
|
# Create a new conf file
|
2010-12-23 20:48:08 +00:00
|
|
|
local TMP_FILE=$(mktemp "/tmp/alternc_host.XXXXXX")
|
|
|
|
cp "$TEMPLATE" "$TMP_FILE"
|
|
|
|
|
|
|
|
# Put the good value in the conf file
|
|
|
|
sed -i \
|
|
|
|
-e "s#%%fqdn%%#$FQDN#g" \
|
|
|
|
-e "s#%%document_root%%#$DOCUMENT_ROOT#g" \
|
|
|
|
-e "s#%%redirect%%#$REDIRECT#g" \
|
|
|
|
$TMP_FILE
|
|
|
|
|
2010-12-23 23:10:47 +00:00
|
|
|
# Check if all is right in the conf file
|
2010-12-23 20:48:08 +00:00
|
|
|
# If not, put a debug message
|
|
|
|
local ISNOTGOOD=$(grep "%%" "$TMP_FILE")
|
|
|
|
[ "$ISNOTGOOD" ] && (echo "# There was a probleme in the generation : $ISNOTGOOD" > "$TMP_FILE"
|
|
|
|
|
|
|
|
# Put the conf file in prod
|
|
|
|
mkdir -p "$(dirname "$FILE_TARGET")"
|
|
|
|
mv -f "$TMP_FILE" "$FILE_TARGET"
|
|
|
|
|
2010-12-24 10:10:19 +00:00
|
|
|
# Execute post-install if there is some for this VTYPE
|
2010-12-23 23:25:47 +00:00
|
|
|
[ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] && "$HOSTING_DIR/hosting_$VTYPE.sh" "postint" $@
|
|
|
|
|
2010-12-23 20:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
host_disable() {
|
|
|
|
host_change_enable "disable" $@
|
|
|
|
}
|
|
|
|
|
|
|
|
host_enable() {
|
|
|
|
host_change_enable "enable" $@
|
|
|
|
}
|
|
|
|
|
|
|
|
host_change_enable() {
|
|
|
|
# Function to enable or disable a host
|
|
|
|
local STATE=$1
|
2010-12-23 23:10:47 +00:00
|
|
|
|
2010-12-24 10:10:19 +00:00
|
|
|
# If there is a VTYPE precised and a specific script exist
|
2010-12-23 23:10:47 +00:00
|
|
|
if [ $3 ] ; then
|
|
|
|
local VTYPE=$3
|
|
|
|
if [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] ; then
|
|
|
|
"$HOSTING_DIR/hosting_$VTYPE.sh" $@
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-12-23 20:48:08 +00:00
|
|
|
local FQDN=$2
|
|
|
|
local USER=`get_account_by_domain $FQDN`
|
|
|
|
local user_letter=`print_user_letter "$USER"`
|
|
|
|
local FENABLED="$VHOST_DIR/${user_letter}/$USER/$FQDN.conf"
|
|
|
|
local FDISABLED="$FENABLED-disabled"
|
|
|
|
|
|
|
|
case $STATE in
|
|
|
|
"enable")
|
|
|
|
local SOURCE="$FDISABLED"
|
|
|
|
local TARGET="$FENABLED"
|
|
|
|
;;
|
|
|
|
"disable")
|
|
|
|
local TARGET="$FDISABLED"
|
|
|
|
local SOURCE="$FENABLED"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-12-23 23:10:47 +00:00
|
|
|
if [ ! -e "$TARGET" ] && [ -e "$SOURCE" ] ; then
|
|
|
|
# If the "target" file do not exist and the "source" file exist
|
2010-12-23 20:48:08 +00:00
|
|
|
rename -f "$SOURCE" "$TARGET"
|
|
|
|
else
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
host_delete() {
|
|
|
|
local FQDN=$1
|
2010-12-23 23:10:47 +00:00
|
|
|
|
2010-12-24 10:10:19 +00:00
|
|
|
# If there is a VTYPE precised and a specific script exist
|
2010-12-23 23:10:47 +00:00
|
|
|
if [ $2 ] ; then
|
|
|
|
local VTYPE=$2
|
|
|
|
if [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] ; then
|
|
|
|
"$HOSTING_DIR/hosting_$VTYPE.sh" "delete" $@
|
2010-12-23 23:25:47 +00:00
|
|
|
local returnval=$?
|
|
|
|
# If the exit value of the VTYPE script is between 20 and 25,
|
2010-12-24 10:10:19 +00:00
|
|
|
# continue the delete like it didn't exist
|
2010-12-23 23:25:47 +00:00
|
|
|
if [ $returnval -lt 20 ] || [ $returnval -gt 25 ] ; then
|
|
|
|
return
|
|
|
|
fi
|
2010-12-23 23:10:47 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-12-23 20:48:08 +00:00
|
|
|
local USER=`get_account_by_domain $FQDN`
|
|
|
|
local user_letter=`print_user_letter "$USER"`
|
|
|
|
local FENABLED="$VHOST_DIR/${user_letter}/$USER/$FQDN.conf"
|
|
|
|
local FDISABLED="$FENABLED-disabled"
|
|
|
|
|
2010-12-23 21:52:34 +00:00
|
|
|
[ -w "$FENABLED" ] && rm -f "$FENABLED"
|
|
|
|
[ -w "$FDISABLED" ] && rm -f "$FDISABLED"
|
2010-12-23 20:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|