From 7c8332932a378c2449dd004ecbf0eb1f27f1eaa2 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Sun, 30 Jan 2011 12:45:53 +0000 Subject: [PATCH] Hop-la --- .gitattributes | 5 +- src/{dns.sh => functions_dns.sh} | 0 ...g_functions_v2.sh => functions_hosting.sh} | 86 +++++++++++-------- src/hosting_functions.sh | 62 ------------- src/update_domains.sh | 8 +- 5 files changed, 54 insertions(+), 107 deletions(-) rename src/{dns.sh => functions_dns.sh} (100%) rename src/{hosting_functions_v2.sh => functions_hosting.sh} (70%) delete mode 100644 src/hosting_functions.sh diff --git a/.gitattributes b/.gitattributes index ffd9ec72..e6daa364 100644 --- a/.gitattributes +++ b/.gitattributes @@ -433,16 +433,15 @@ src/alternc-check -text src/alternc-passwd -text src/alternc_reload -text src/basedir_prot.sh -text -src/dns.sh -text src/du.pl -text src/fixperms.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_redirect.sh -text src/hosting_functions/hosting_vhost.sh -text src/hosting_functions/hosting_webmail.sh -text -src/hosting_functions_v2.sh -text src/mail_add -text src/mail_del -text src/mem_add -text diff --git a/src/dns.sh b/src/functions_dns.sh similarity index 100% rename from src/dns.sh rename to src/functions_dns.sh diff --git a/src/hosting_functions_v2.sh b/src/functions_hosting.sh similarity index 70% rename from src/hosting_functions_v2.sh rename to src/functions_hosting.sh index 3dab574c..f3a97531 100644 --- a/src/hosting_functions_v2.sh +++ b/src/functions_hosting.sh @@ -8,6 +8,26 @@ HOSTING_DIR="/usr/lib/alternc/hosting_functions" HTML_HOME="$ALTERNC_LOC/html" 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() { # Function to create a vhost for a website @@ -18,20 +38,12 @@ host_create() { 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" $@ - local returnval=$? - - # 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 + launch_hooks "create" $@ + if [ $? -gt 10 ] ; then + # If the hooks return a value > 10 + # it's mean we do not continue the + # "default" actions + return $? fi # There is no special script, I use the standart template @@ -86,9 +98,17 @@ host_create() { mkdir -p "$(dirname "$FILE_TARGET")" mv -f "$TMP_FILE" "$FILE_TARGET" - # Execute post-install if there is some for this VTYPE - [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] && "$HOSTING_DIR/hosting_$VTYPE.sh" "postint" $@ + # Execute post-install hooks + 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() { @@ -103,13 +123,13 @@ host_change_enable() { # Function to enable or disable a host local STATE=$1 - # If there is a VTYPE precised and a specific script exist - if [ $3 ] ; then - local VTYPE=$3 - if [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] ; then - "$HOSTING_DIR/hosting_$VTYPE.sh" $@ - return - fi + # Execute hooks + launch_hooks $@ + if [ $? -gt 10 ] ; then + # If the hooks return a value > 10 + # it's mean we do not continue the + # "default" actions + return $? fi local FQDN=$2 @@ -143,19 +163,13 @@ host_change_enable() { host_delete() { local FQDN=$1 - - # If there is a VTYPE precised and a specific script exist - if [ $2 ] ; then - local VTYPE=$2 - if [ -x "$HOSTING_DIR/hosting_$VTYPE.sh" ] ; then - "$HOSTING_DIR/hosting_$VTYPE.sh" "delete" $@ - local returnval=$? - # 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 + # Execute post-install hooks + launch_hooks "delete" $@ + if [ $? -gt 10 ] ; then + # If the hooks return a value > 10 + # it's mean we do not continue the + # "default" actions + return $? fi local USER=`get_account_by_domain $FQDN` diff --git a/src/hosting_functions.sh b/src/hosting_functions.sh deleted file mode 100644 index b6c5a1c4..00000000 --- a/src/hosting_functions.sh +++ /dev/null @@ -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 -} diff --git a/src/update_domains.sh b/src/update_domains.sh index 86653fa5..e9801988 100644 --- a/src/update_domains.sh +++ b/src/update_domains.sh @@ -4,8 +4,8 @@ for CONFIG_FILE in \ /etc/alternc/local.sh \ /usr/lib/alternc/functions.sh \ - /usr/lib/alternc/hosting_functions_v2.sh \ - /usr/lib/alternc/dns.sh + /usr/lib/alternc/functions_hosting.sh \ + /usr/lib/alternc/functions_dns.sh do if [ ! -r "$CONFIG_FILE" ]; then echo "Can't access $CONFIG_FILE." @@ -107,10 +107,6 @@ fi mv "$tempo" "$VHOST_FILE" -echo Exitbefore reload everything, we are testing, FUCK -rm "$LOCK_FILE" -exit 1 - # Reload web and dns alternc_reload all