Ajout des hooks pour la gestion du mass virtual hosting
This commit is contained in:
parent
3cbccf5bce
commit
77e83a6ad3
|
@ -353,6 +353,7 @@ etc/alternc/apache-ssl.conf -text
|
|||
etc/alternc/apache.conf -text
|
||||
etc/alternc/apache2-ssl.conf -text
|
||||
etc/alternc/apache2.conf -text
|
||||
etc/alternc/functions_hosting/hosting_massvhost.sh -text
|
||||
etc/alternc/menulist.txt -text
|
||||
etc/alternc/phpmyadmin.inc.php -text
|
||||
etc/alternc/postfix-slave.cf -text
|
||||
|
|
|
@ -11,7 +11,6 @@ ScriptAlias /cgi-bin/ /var/alternc/cgi-bin/
|
|||
AddHandler cgi-script .cgi
|
||||
</Directory>
|
||||
|
||||
Include /var/alternc/apache-vhost/vhosts_all.conf
|
||||
|
||||
<VirtualHost *:80>
|
||||
# ***ALTERNC_ALIASES***
|
||||
|
@ -47,4 +46,5 @@ Include /var/alternc/apache-vhost/vhosts_all.conf
|
|||
Allow from all
|
||||
</Directory>
|
||||
|
||||
Include /var/alternc/apache-vhost/vhosts_all.conf
|
||||
Include /etc/alternc/bureau.conf
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
#!/bin/bash
|
||||
|
||||
ACTION=$1
|
||||
# $2 is the type
|
||||
DOMAIN=$3
|
||||
TARGET=$4
|
||||
|
||||
# Load some librairies
|
||||
. /etc/alternc/local.sh
|
||||
. /usr/lib/alternc/functions.sh
|
||||
|
||||
# To not be case-sensitive
|
||||
ACTION="`echo $ACTION|tr '[:upper:]' '[:lower:]'`"
|
||||
DOMAIN="`echo $DOMAIN|tr '[:upper:]' '[:lower:]'`"
|
||||
|
||||
if [ -z $ACTION ] || [ -z $DOMAIN ] ; then
|
||||
echo "Need at least 2 parameters ( action - fqdn )"
|
||||
fi
|
||||
|
||||
YOP="$ALTERNC_LOC/dns/$(print_domain_letter $DOMAIN)/$DOMAIN"
|
||||
|
||||
case $ACTION in
|
||||
"disable"|"delete")
|
||||
if [ ! -e "$YOP" ] ; then
|
||||
echo "Link do not exist. Nothing done"
|
||||
exit 15
|
||||
fi
|
||||
if [ ! -L "$YOP" ] ; then
|
||||
echo "Seem not to be a link ($YOP). Abord"
|
||||
exit 16
|
||||
fi
|
||||
rm -f "$YOP"
|
||||
;;
|
||||
"enable"|"create")
|
||||
if [ -z "$TARGET" ] ; then
|
||||
echo "Parameters target $TARGET missing"
|
||||
exit 13
|
||||
fi
|
||||
USER=$(get_account_by_domain "$DOMAIN")
|
||||
if [ -z $USER ] ; then
|
||||
echo "Unable to find account of $DOMAIN"
|
||||
exit 17
|
||||
fi
|
||||
TARGET="$ALTERNC_LOC/html/$(print_user_letter $USER)/$USER/$TARGET"
|
||||
if [ ! -d "$TARGET" ] ; then
|
||||
echo "Directory $TARGET missing"
|
||||
exit 14
|
||||
fi
|
||||
ln -snf "$TARGET" "$YOP"
|
||||
;;
|
||||
*)
|
||||
echo Error : $ACTION not an recognised action
|
||||
exit 11
|
||||
;;
|
||||
esac
|
||||
|
|
@ -19,6 +19,7 @@ PRIMARY KEY ( `name` )
|
|||
) COMMENT = 'Type of domains allowed';
|
||||
|
||||
INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, only_dns, need_dns) values
|
||||
('massvhost','Locally managed with Mass Virtual Hosting technologie', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'txt', false, false),
|
||||
('local','Locally managed', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'txt', false, false),
|
||||
('url','URL redirection', 'URL', '%SUB% IN A @@PUBLIC_IP@@','txt', true, true),
|
||||
('ip','IP redirection', 'IP', '%SUB% IN A %TARGET%','url,ip,ipv6,txt', false, true),
|
||||
|
@ -40,7 +41,7 @@ alter table sub_domaines add column enable enum ('ENABLED', 'ENABLE', 'DISABLED'
|
|||
drop table sub_domaines_standby;
|
||||
drop table domaines_standby;
|
||||
|
||||
update sub_domaines set type='LOCAL' where type='0';
|
||||
update sub_domaines set type='MASSVHOST' where type='0';
|
||||
update sub_domaines set type='URL' where type='1';
|
||||
update sub_domaines set type='IP' where type='2';
|
||||
update sub_domaines set type='WEBMAIL' where type='3';
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
# Init some other vars
|
||||
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"
|
||||
|
||||
|
@ -35,7 +36,7 @@ get_account_by_domain() {
|
|||
# else
|
||||
# implantons localement ce que nous avons besoin, puisque admintools
|
||||
# n'est pas là
|
||||
$MYSQL_DO 'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
|
||||
mysql_query 'SELECT a.login FROM membres a, sub_domaines b WHERE a.uid = b.compte AND \
|
||||
CONCAT(IF(sub="", "", CONCAT(sub, ".")), domaine) = "'"$1"'" LIMIT 1;'
|
||||
# fi
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
. /usr/lib/alternc/functions.sh
|
||||
|
||||
TEMPLATE_DIR="/etc/alternc/templates/apache2"
|
||||
HOSTING_DIR="/usr/lib/alternc/hosting_functions"
|
||||
HOSTING_DIR="/etc/alternc/functions_hosting"
|
||||
|
||||
HTML_HOME="$ALTERNC_LOC/html"
|
||||
VHOST_DIR="$ALTERNC_LOC/apache-vhost"
|
||||
|
@ -21,7 +21,7 @@ launch_hooks() {
|
|||
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" $@
|
||||
"$HOSTING_DIR/hosting_$VTYPE.sh" "$1" "$2" "$3" "$4"
|
||||
return $?
|
||||
fi
|
||||
|
||||
|
@ -38,7 +38,7 @@ host_create() {
|
|||
|
||||
local VTYPE="$1"
|
||||
|
||||
launch_hooks "create" $@
|
||||
launch_hooks "create" "$1" "$2" "$3" "$4"
|
||||
if [ $? -gt 10 ] ; then
|
||||
# If the hooks return a value > 10
|
||||
# it's mean we do not continue the
|
||||
|
@ -99,7 +99,7 @@ host_create() {
|
|||
mv -f "$TMP_FILE" "$FILE_TARGET"
|
||||
|
||||
# Execute post-install hooks
|
||||
launch_hooks "postinst" $@
|
||||
launch_hooks "postinst" "$1" "$2" "$3" "$4"
|
||||
if [ $? -gt 10 ] ; then
|
||||
# If the hooks return a value > 10
|
||||
# it's mean we do not continue the
|
||||
|
@ -112,11 +112,11 @@ host_create() {
|
|||
}
|
||||
|
||||
host_disable() {
|
||||
host_change_enable "disable" $@
|
||||
host_change_enable "disable" "$1" "$2" "$3" "$4"
|
||||
}
|
||||
|
||||
host_enable() {
|
||||
host_change_enable "enable" $@
|
||||
host_change_enable "enable" "$1" "$2" "$3" "$4"
|
||||
}
|
||||
|
||||
host_change_enable() {
|
||||
|
@ -124,7 +124,7 @@ host_change_enable() {
|
|||
local STATE=$1
|
||||
|
||||
# Execute hooks
|
||||
launch_hooks $@
|
||||
launch_hooks "$1" "$2" "$3" "$4"
|
||||
if [ $? -gt 10 ] ; then
|
||||
# If the hooks return a value > 10
|
||||
# it's mean we do not continue the
|
||||
|
@ -132,8 +132,8 @@ host_change_enable() {
|
|||
return $?
|
||||
fi
|
||||
|
||||
local FQDN=$2
|
||||
local TYPE=$3 # no use here, but one day, maybe... So here he is
|
||||
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"
|
||||
|
@ -164,7 +164,7 @@ host_change_enable() {
|
|||
host_delete() {
|
||||
local FQDN=$1
|
||||
# Execute post-install hooks
|
||||
launch_hooks "delete" $@
|
||||
launch_hooks "delete" "$1" "$2" "$3" "$4"
|
||||
if [ $? -gt 10 ] ; then
|
||||
# If the hooks return a value > 10
|
||||
# it's mean we do not continue the
|
||||
|
|
|
@ -17,8 +17,9 @@ done
|
|||
# Some vars
|
||||
umask 022
|
||||
LOCK_FILE="$ALTERNC_LOC/bureau/cron.lock"
|
||||
B='µµ' # Strange letters to make split in query
|
||||
|
||||
OLDIFS="$IFS"
|
||||
NEWIFS=" "
|
||||
B="µµ§§" # Strange letters to make split in query
|
||||
|
||||
# Somes check before start operations
|
||||
if [ `id -u` -ne 0 ]; then
|
||||
|
@ -39,64 +40,64 @@ touch "$LOCK_FILE"
|
|||
|
||||
# For domains we want to delete completely, make sure all the tags are all right
|
||||
# set sub_domaines.web_action = delete where domaines.dns_action = DELETE
|
||||
$MYSQL_DO "update sub_domaines sd, domaines d set sd.web_action = 'DELETE' where sd.domaine = d.domaine and sd.compte=d.compte and d.dns_action = 'DELETE';"
|
||||
mysql_query "update sub_domaines sd, domaines d set sd.web_action = 'DELETE' where sd.domaine = d.domaine and sd.compte=d.compte and d.dns_action = 'DELETE';"
|
||||
|
||||
# Sub_domaines we want to delete
|
||||
# sub_domaines.web_action = delete
|
||||
for sub in $( $MYSQL_DO "select concat_ws('$B',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),sd.type) from sub_domaines sd where web_action ='DELETE';") ; do
|
||||
host_delete $(echo $sub|tr "$B" ' ')
|
||||
$MYSQL_DO "delete from sub_domaines where concat_ws('$B',if(length(sub)>0,concat_ws('.',sub,domaine),domaine),type) = '$sub' and web_action ='DELETE';"
|
||||
for sub in $( mysql_query "select concat_ws('$B',lower(sd.type), if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine)) from sub_domaines sd where web_action ='DELETE';") ; do
|
||||
host_delete ${sub/$B/ }
|
||||
mysql_query "delete from sub_domaines where concat_ws('$B',if(length(sub)>0,concat_ws('.',sub,domaine),domaine),type) = '$sub' and web_action ='DELETE';"
|
||||
done
|
||||
|
||||
# Sub domaines we want to update
|
||||
# sub_domaines.web_action = update and sub_domains.only_dns = false
|
||||
params=$( $MYSQL_DO "
|
||||
select concat_ws('$B',lower(sd.type), if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine), valeur)
|
||||
IFS="$NEWIFS"
|
||||
mysql_query "
|
||||
select concat_ws('$IFS',lower(sd.type), if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine), sd.valeur )
|
||||
from sub_domaines sd
|
||||
where sd.web_action ='UPDATE'
|
||||
;")
|
||||
for sub in $params;do
|
||||
host_create $(echo $sub|tr "$B" ' ')
|
||||
$MYSQL_DO "update sub_domaines sd set web_action='OK',web_result='$?' where concat_ws('$B',lower(sd.type),if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),valeur)='$sub'"
|
||||
;" | while read type domain valeur ; do
|
||||
host_create "$type" "$domain" "$valeur"
|
||||
mysql_query "update sub_domaines sd set web_action='OK',web_result='$?' where lower(sd.type)='$type' and if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine)='$domain' and sd.valeur='$valeur'; "
|
||||
done
|
||||
|
||||
# Domaine to enable
|
||||
for sub in $( $MYSQL_DO "select concat_ws('$B',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) from sub_domaines sd where sd.enable ='ENABLE' ;");do
|
||||
host_enable $(echo $sub|tr "$B" ' ')
|
||||
$MYSQL_DO "update sub_domaines sd set enable='ENABLED' where concat_ws('$B',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) = '$sub';"
|
||||
mysql_query "select concat_ws('$IFS',lower(sd.type),if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),sd.valeur) from sub_domaines sd where sd.enable ='ENABLE' ;"|while read type domain valeur ; do
|
||||
host_enable "$type" "$domain" "$valeur"
|
||||
mysql_query "update sub_domaines sd set enable='ENABLED' where lower(sd.type)='$type' and if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine)='$domain' and sd.valeur='$valeur';"
|
||||
done
|
||||
|
||||
# Domains to disable
|
||||
for sub in $( $MYSQL_DO "select concat_ws('$B',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) from sub_domaines sd where sd.enable ='DISABLE' ;");do
|
||||
host_disable $(echo $sub|tr "$B" ' ')
|
||||
$MYSQL_DO "update sub_domaines sd set enable='DISABLED' where concat_ws('$B',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) = '$sub';"
|
||||
mysql_query "select concat_ws('$IFS',lower(sd.type),if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),sd.valeur) from sub_domaines sd where sd.enable ='DISABLE' ;"|while read type domain valeur ; do
|
||||
host_disable "$type" "$domain" "$valeur"
|
||||
mysql_query "update sub_domaines sd set enable='DISABLED' where lower(sd.type)='$type' and if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine)='$domain' and sd.valeur='$valeur';"
|
||||
done
|
||||
|
||||
# Domains we do not want to be the DNS serveur anymore :
|
||||
# domaines.dns_action = UPDATE and domaines.gesdns = 0
|
||||
for dom in $( $MYSQL_DO "select domaine from domaines where dns_action = 'UPDATE' and gesdns = 0;") ; do
|
||||
for dom in $( mysql_query "select domaine from domaines where dns_action = 'UPDATE' and gesdns = 0;") ; do
|
||||
dns_delete $dom
|
||||
$MYSQL_DO "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'"
|
||||
mysql_query "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'"
|
||||
done
|
||||
|
||||
# Domains we have to update the dns :
|
||||
# domaines.dns_action = UPDATE
|
||||
for dom in $( $MYSQL_DO "select domaine from domaines where dns_action = 'UPDATE';") ; do
|
||||
for dom in $( mysql_query "select domaine from domaines where dns_action = 'UPDATE';") ; do
|
||||
dns_regenerate $dom
|
||||
$MYSQL_DO "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'"
|
||||
mysql_query "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'"
|
||||
done
|
||||
|
||||
# Domains we want to delete completely, now we do it
|
||||
# domaines.dns_action = DELETE
|
||||
for dom in $( $MYSQL_DO "select domaine from domaines where dns_action = 'DELETE';") ; do
|
||||
for dom in $( mysql_query "select domaine from domaines where dns_action = 'DELETE';") ; do
|
||||
dns_delete $dom
|
||||
# Web configurations have already bean cleaned previously
|
||||
$MYSQL_DO "delete sub_domaines where domaine='$dom'; delete domaines where domaine='$dom';"
|
||||
mysql_query "delete sub_domaines where domaine='$dom'; delete domaines where domaine='$dom';"
|
||||
done
|
||||
|
||||
|
||||
# Concat the apaches files
|
||||
tempo=$(mktemp /tmp/alternc-vhost.XXXXX)
|
||||
tempo=$(mktemp "$VHOST_FILE.XXXXX")
|
||||
find "$VHOST_DIR" -mindepth 2 -type f -iname "*.conf" -exec cat '{}' > "$tempo" \;
|
||||
if [ $? -ne 0 ] ; then
|
||||
log_error " web file concatenation failed"
|
||||
|
|
Loading…
Reference in New Issue