2011-01-28 15:55:26 +00:00
#!/bin/bash
# Update domain next-gen by fufrom
for CONFIG_FILE in \
/etc/alternc/local.sh \
/usr/lib/alternc/functions.sh \
2011-01-30 12:45:53 +00:00
/usr/lib/alternc/functions_hosting.sh \
/usr/lib/alternc/functions_dns.sh
2011-01-28 15:55:26 +00:00
do
if [ ! -r " $CONFIG_FILE " ] ; then
echo " Can't access $CONFIG_FILE . "
exit 1
fi
. " $CONFIG_FILE "
done
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# Some vars
2006-04-26 12:28:53 +00:00
umask 022
2011-01-28 15:55:26 +00:00
LOCK_FILE = " $ALTERNC_LOC /bureau/cron.lock "
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# Somes check before start operations
2006-04-26 12:28:53 +00:00
if [ ` id -u` -ne 0 ] ; then
2011-01-28 15:55:26 +00:00
log_error "must be launched as root"
elif [ -z " $DEFAULT_MX " -o -z " $PUBLIC_IP " ] ; then
log_error "Bad configuration. Please use: dpkg-reconfigure alternc"
elif [ -f " $LOCK_FILE " ] ; then
log_error " last cron unfinished or stale lock file ( $LOCK_FILE ). "
2006-04-26 12:28:53 +00:00
fi
2009-07-27 21:21:26 +00:00
# backward compatibility: single-server setup
if [ -z " $ALTERNC_SLAVES " ] ; then
ALTERNC_SLAVES = "localhost"
fi
2011-01-28 15:55:26 +00:00
# We lock the application
2006-04-26 12:28:53 +00:00
touch " $LOCK_FILE "
2011-01-28 15:55:26 +00:00
# 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';"
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# Sub_domaines we want to delete
# sub_domaines.web_action = delete
2011-01-29 17:58:19 +00:00
for sub in $( $MYSQL_DO "select concat_ws('|µ',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 '|µ' ' ' )
2011-01-28 15:55:26 +00:00
# TODO Update the entry in the DB with the result and the action
done
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# Sub domaines we want to update
# sub_domaines.web_action = update and sub_domains.only_dns = false
2011-01-29 15:12:26 +00:00
params = $( $MYSQL_DO "
select concat_ws( '|µ' ,lower( sd.type) , if ( length( sd.sub) >0,concat_ws( '.' ,sd.sub,sd.domaine) ,sd.domaine) , valeur)
2011-01-29 17:58:19 +00:00
from sub_domaines sd
2011-01-29 15:12:26 +00:00
where sd.web_action = 'UPDATE'
; " )
for sub in $params ; do
host_create $( echo $sub | tr '|µ' ' ' )
2011-01-29 17:58:19 +00:00
$MYSQL_DO " update sub_domaines sd set web_action='OK',web_result=' $? ' where concat_ws('|µ',lower(sd.type),if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),valeur)=' $sub ' "
2011-01-29 15:12:26 +00:00
done
2011-01-29 15:46:33 +00:00
# Domaine to enable
2011-01-29 17:58:19 +00:00
for sub in $( $MYSQL_DO "select concat_ws('|µ',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 '|µ' ' ' )
$MYSQL_DO " update sub_domaines sd set enable='ENABLED' where concat_ws('|µ',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) = ' $sub '; "
2011-01-29 15:46:33 +00:00
done
# Domains to disable
2011-01-29 17:58:19 +00:00
for sub in $( $MYSQL_DO "select concat_ws('|µ',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 '|µ' ' ' )
$MYSQL_DO " update sub_domaines sd set enable='DISABLED' where concat_ws('|µ',if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine),lower(sd.type)) = ' $sub '; "
2011-01-29 15:46:33 +00:00
done
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# 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
dns_delete $dom
$MYSQL_DO " update domaines set dns_action = 'OK', dns_result = ' $? ' where domaine = ' $dom ' "
done
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# 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
dns_regenerate $dom
$MYSQL_DO " update domaines set dns_action = 'OK', dns_result = ' $? ' where domaine = ' $dom ' "
done
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# 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
dns_delete $dom
# Web configurations have already bean cleaned previously
$MYSQL_DO " delete sub_domaines where domaine=' $dom '; delete domaines where domaine=' $dom '; "
done
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# Concat the apaches files
2011-01-29 15:46:33 +00:00
tempo = $( mktemp /tmp/alternc-vhost.XXXXX)
find " $VHOST_DIR " -mindepth 2 -type f -iname "*.conf" -exec cat '{}' > " $tempo " \;
2011-01-28 15:55:26 +00:00
if [ $? -ne 0 ] ; then
log_error " web file concatenation failed"
fi
2011-01-29 15:46:33 +00:00
touch " $VHOST_FILE "
if [ ! -w " $VHOST_FILE " ] ; then
2011-01-28 15:55:26 +00:00
log_error " cannot write on $VHOST_FILE "
2006-04-26 12:28:53 +00:00
fi
2011-01-28 15:55:26 +00:00
mv " $tempo " " $VHOST_FILE "
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# Reload web and dns
2011-01-30 12:59:48 +00:00
/usr/bin/alternc_reload all
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
# TODO reload slaves
2009-07-27 21:21:26 +00:00
2011-01-28 15:55:26 +00:00
rm " $LOCK_FILE "
2006-04-26 12:28:53 +00:00
2011-01-28 15:55:26 +00:00
exit 0
2006-04-26 12:28:53 +00:00