diff --git a/.gitattributes b/.gitattributes index ca6d93bb..9ff751de 100644 --- a/.gitattributes +++ b/.gitattributes @@ -513,6 +513,7 @@ install/upgrades/0.9.7.sql -text install/upgrades/0.9.9.sql -text install/upgrades/1.0.1.php -text install/upgrades/1.0.3.sql -text +install/upgrades/1.0.4.sh -text install/upgrades/1.0.sql -text install/upgrades/1.1.php -text install/upgrades/1.1.sh -text @@ -578,6 +579,7 @@ src/quota_delete -text src/quota_edit -text src/quota_get -text src/quota_init -text +src/rebuild_all_webconf.sh -text src/sendmail -text src/slave_dns -text src/spoolsize.php -text diff --git a/install/upgrades/1.0.4.sh b/install/upgrades/1.0.4.sh new file mode 100755 index 00000000..1e326b4b --- /dev/null +++ b/install/upgrades/1.0.4.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Rebuild all web configuration +/usr/lib/alternc/rebuild_all_webconf.sh --force diff --git a/src/Makefile b/src/Makefile index 6aa83846..1425a7bd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ # Purpose of file: Makefile des binaires de /usr/lib/alternc # ---------------------------------------------------------------------- SETUID=quota_edit quota_get mem_add mem_del du.pl -SCRIPTS=sqlbackup.sh quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh compress_logs.sh delete_logs.sh quota-warning.sh update_mails.sh alternc_add_policy_dovecot +SCRIPTS=sqlbackup.sh quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh compress_logs.sh delete_logs.sh quota-warning.sh update_mails.sh alternc_add_policy_dovecot rebuild_all_webconf.sh LIBS=functions.sh functions_hosting.sh functions_dns.sh BIN=$(DESTDIR)/usr/lib/alternc/ diff --git a/src/functions.sh b/src/functions.sh index e86af16b..37718821 100755 --- a/src/functions.sh +++ b/src/functions.sh @@ -31,6 +31,7 @@ MYSQL_DO="/usr/bin/mysql --defaults-file=/etc/alternc/my.cnf -Bs -e " mysql_query() { /usr/bin/mysql --defaults-file=/etc/alternc/my.cnf -Bs -e "$@" ; } DOMAIN_LOG_FILE="/var/log/alternc/update_domains.log" VHOST_FILE="$VHOST_DIR/vhosts_all.conf" +VHOST_MANUALCONF="$VHOST_DIR/manual/" # Some useful miscellaneous shell functions @@ -67,6 +68,10 @@ get_account_by_domain() { CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;' } +get_uid_by_domain() { + mysql_query 'SELECT b.compte as uid FROM sub_domaines b WHERE \ + CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;' +} # Log (echoes+log) an error and exit the current script with an error. log_error() { diff --git a/src/functions_hosting.sh b/src/functions_hosting.sh index ea6226a9..b9f70a1c 100644 --- a/src/functions_hosting.sh +++ b/src/functions_hosting.sh @@ -29,6 +29,15 @@ launch_hooks() { return 0 } +host_conffile() { + # Return the absolute path of a conf file for a FQDN + local FQDN="$1" + local U_ID=$(get_uid_by_domain "$FQDN") + local CONFFILE="$VHOST_DIR/${U_ID:0:1}/$U_ID/$FQDN.conf" + echo $CONFFILE + return 0 +} + host_create() { # Function to create a vhost for a website # First, it look if there is a special file for @@ -56,13 +65,13 @@ host_create() { local MAIL_ACCOUNT=$3 local REDIRECT=$4 # Yes, TARGET_DIR and REDIRECT are the same local TARGET_DIR=$4 # It's used by different template + local U_ID=$(get_uid_by_domain "$FQDN") + local G_ID="$U_ID" local USER=$(get_account_by_domain $FQDN) - local U_ID=$(get_uid_by_name "$USER") - local G_ID=$(get_uid_by_name "$USER") local user_letter=`print_user_letter "$USER"` local DOCUMENT_ROOT="${HTML_HOME}/${user_letter}/${USER}$TARGET_DIR" local ACCOUNT_ROOT="${HTML_HOME}/${user_letter}/${USER}/" - local FILE_TARGET="$VHOST_DIR/${user_letter}/$USER/$FQDN.conf" + local FILE_TARGET=$(host_conffile "$FQDN") # In case VTYPE don't have the same name as the template file, # here we can define it @@ -150,9 +159,7 @@ host_change_enable() { local TYPE=$2 # no use here, but one day, maybe... So here he is local FQDN=$3 - local USER=$(get_account_by_domain $FQDN) - local user_letter=`print_user_letter "$USER"` - local FENABLED="$VHOST_DIR/${user_letter}/$USER/$FQDN.conf" + local FENABLED=$(host_conffile "$FQDN") local FDISABLED="$FENABLED-disabled" case $STATE in @@ -189,9 +196,7 @@ host_delete() { return $? fi - local USER=`get_account_by_domain $FQDN` - local user_letter=`print_user_letter "$USER"` - local FENABLED="$VHOST_DIR/${user_letter}/$USER/$FQDN.conf" + local FENABLED=$(host_conffile "$FQDN") local FDISABLED="$FENABLED-disabled" [ -w "$FENABLED" ] && rm -f "$FENABLED" diff --git a/src/rebuild_all_webconf.sh b/src/rebuild_all_webconf.sh new file mode 100755 index 00000000..0713668c --- /dev/null +++ b/src/rebuild_all_webconf.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Get some vars +. /usr/lib/alternc/functions_hosting.sh + +if [ -z "$VHOST_DIR" ] ; then + echo "Problem: No VHOST_DIR var" + exit 2 +fi + +echo "This script empty the $VHOST_DIR directory" +echo "and rebuild all web configuration." +echo "" +echo "Only files in $VHOST_MANUALCONF will be preserved." +echo "Use --force to skip confirmation" +echo "" + +if [ ! "$1" == "--force" ] ; then + read -n1 -p "Continue (y/n)? " + [[ $REPLY = [yY] ]] || exit 1 +fi + +echo "" +echo "++ Start rebuilding ++" + +echo "Delete old configuration" +# [a-z_] for old storage schema (1.0) +for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z _ ; do + test -d "$VHOST_DIR/$i" && rm -rf "$VHOST_DIR/$i/" +done +test -f "$VHOST_FILE" && rm -f "$VHOST_FILE" +echo "Deleting complete" + +echo "Set flag to rebuild" +mysql_query "update sub_domaines set web_action = 'UPDATE';" + +echo "Launch update_domains to rebuild." +/usr/lib/alternc/update_domains.sh + +echo "Finish." +