This commit is contained in:
Alan Garcia 2011-01-30 12:45:53 +00:00
parent c3ed3a7ecc
commit 7c8332932a
5 changed files with 54 additions and 107 deletions

5
.gitattributes vendored
View File

@ -433,16 +433,15 @@ src/alternc-check -text
src/alternc-passwd -text src/alternc-passwd -text
src/alternc_reload -text src/alternc_reload -text
src/basedir_prot.sh -text src/basedir_prot.sh -text
src/dns.sh -text
src/du.pl -text src/du.pl -text
src/fixperms.sh -text src/fixperms.sh -text
src/functions.sh -text src/functions.sh -text
src/hosting_functions.sh -text src/functions_dns.sh -text
src/functions_hosting.sh -text
src/hosting_functions/hosting_panel.sh -text src/hosting_functions/hosting_panel.sh -text
src/hosting_functions/hosting_redirect.sh -text src/hosting_functions/hosting_redirect.sh -text
src/hosting_functions/hosting_vhost.sh -text src/hosting_functions/hosting_vhost.sh -text
src/hosting_functions/hosting_webmail.sh -text src/hosting_functions/hosting_webmail.sh -text
src/hosting_functions_v2.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

View File

@ -8,6 +8,26 @@ HOSTING_DIR="/usr/lib/alternc/hosting_functions"
HTML_HOME="$ALTERNC_LOC/html" HTML_HOME="$ALTERNC_LOC/html"
VHOST_DIR="$ALTERNC_LOC/apache-vhost" VHOST_DIR="$ALTERNC_LOC/apache-vhost"
launch_hooks() {
local ACTION=$1
if [ ! $2 ] ; then
# If no VTYPE specified
return 0
fi
local VTYPE=$2
if [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] ; then
# If a specific script exist for this VTYPE,
# we launch it, and return his return code
"$HOSTING_DIR/hosting_$VTYPE.sh" $@
return $?
fi
# No specific script, return 0
return 0
}
host_create() { host_create() {
# Function to create a vhost for a website # Function to create a vhost for a website
@ -18,20 +38,12 @@ host_create() {
local VTYPE="$1" local VTYPE="$1"
if [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] ; then launch_hooks "create" $@
# There is a script special for this type, if [ $? -gt 10 ] ; then
# I launch it and quit the host_create function # If the hooks return a value > 10
# (I precise to the script this is for a "enable" task) # it's mean we do not continue the
"$HOSTING_DIR/hosting_$VTYPE.sh" "create" $@ # "default" actions
local returnval=$? return $?
# 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.
if [ $returnval -lt 20 ] || [ $returnval -gt 25 ] ; then
return
fi
fi fi
# There is no special script, I use the standart template # There is no special script, I use the standart template
@ -86,9 +98,17 @@ host_create() {
mkdir -p "$(dirname "$FILE_TARGET")" mkdir -p "$(dirname "$FILE_TARGET")"
mv -f "$TMP_FILE" "$FILE_TARGET" mv -f "$TMP_FILE" "$FILE_TARGET"
# Execute post-install if there is some for this VTYPE # Execute post-install hooks
[ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] && "$HOSTING_DIR/hosting_$VTYPE.sh" "postint" $@ launch_hooks "postinst" $@
if [ $? -gt 10 ] ; then
# If the hooks return a value > 10
# it's mean we do not continue the
# "default" actions
return $?
fi
# All is quit, we return 0
return 0
} }
host_disable() { host_disable() {
@ -103,13 +123,13 @@ host_change_enable() {
# Function to enable or disable a host # Function to enable or disable a host
local STATE=$1 local STATE=$1
# If there is a VTYPE precised and a specific script exist # Execute hooks
if [ $3 ] ; then launch_hooks $@
local VTYPE=$3 if [ $? -gt 10 ] ; then
if [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] ; then # If the hooks return a value > 10
"$HOSTING_DIR/hosting_$VTYPE.sh" $@ # it's mean we do not continue the
return # "default" actions
fi return $?
fi fi
local FQDN=$2 local FQDN=$2
@ -143,19 +163,13 @@ host_change_enable() {
host_delete() { host_delete() {
local FQDN=$1 local FQDN=$1
# Execute post-install hooks
# If there is a VTYPE precised and a specific script exist launch_hooks "delete" $@
if [ $2 ] ; then if [ $? -gt 10 ] ; then
local VTYPE=$2 # If the hooks return a value > 10
if [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] ; then # it's mean we do not continue the
"$HOSTING_DIR/hosting_$VTYPE.sh" "delete" $@ # "default" actions
local returnval=$? return $?
# If the exit value of the VTYPE script is between 20 and 25,
# continue the delete like it didn't exist
if [ $returnval -lt 20 ] || [ $returnval -gt 25 ] ; then
return
fi
fi
fi fi
local USER=`get_account_by_domain $FQDN` local USER=`get_account_by_domain $FQDN`

View File

@ -1,62 +0,0 @@
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
}

View File

@ -4,8 +4,8 @@
for CONFIG_FILE in \ for CONFIG_FILE in \
/etc/alternc/local.sh \ /etc/alternc/local.sh \
/usr/lib/alternc/functions.sh \ /usr/lib/alternc/functions.sh \
/usr/lib/alternc/hosting_functions_v2.sh \ /usr/lib/alternc/functions_hosting.sh \
/usr/lib/alternc/dns.sh /usr/lib/alternc/functions_dns.sh
do do
if [ ! -r "$CONFIG_FILE" ]; then if [ ! -r "$CONFIG_FILE" ]; then
echo "Can't access $CONFIG_FILE." echo "Can't access $CONFIG_FILE."
@ -107,10 +107,6 @@ fi
mv "$tempo" "$VHOST_FILE" mv "$tempo" "$VHOST_FILE"
echo Exitbefore reload everything, we are testing, FUCK
rm "$LOCK_FILE"
exit 1
# Reload web and dns # Reload web and dns
alternc_reload all alternc_reload all