Commit 1b24c047 authored by Eric's avatar Eric
Browse files

ajout de quelques verifications d'existence reelle du domaine avant de lancer...

ajout de quelques verifications d'existence reelle du domaine avant de lancer la demande de certificats
parent 1200822e
......@@ -3,13 +3,35 @@
# 2017 - Eric Seigne <eric.seigne@abul.org>
# automatic renew let's encrypt certificates
function ldebug()
{
DEBUG=0
if [ ${DEBUG} == 1 ]; then
echo $1
fi
}
rm -f /etc/dehydrated/domains.txt
if [ -f /etc/apache2/reference_soo.new ]; then
FIC=/etc/apache2/reference_soo.new
else
FIC=/etc/apache2/reference_soo
fi
cat /etc/dehydrated/domains.txt_origine ${FIC} > /etc/dehydrated/domains.txt
rm -f ${FIc}.ok
for domaine in `cat ${FIC}`
do
ldebug "on bosse sur ${domaine} .."
#test si le domaine existe ...
TESTDOMAINE=`getent hosts ${domaine} | head -n1`
if [ -n "${TESTDOMAINE}" ]; then
echo ${domaine} >> ${FIC}.ok
fi
done
cat /etc/dehydrated/domains.txt_origine ${FIC}.ok > /etc/dehydrated/domains.txt
dehydrated -c
service apache2 restart
......@@ -7,9 +7,23 @@ FIC=`tempfile`
LADATE=`date "+%Y%m%d %H:%M"`
echo "------------- ${LADATE}"
function ldebug()
{
DEBUG=0
if [ ${DEBUG} == 1 ]; then
echo $1
fi
}
wget -q https://sud-ouest2.org/dolibarr/public/soo/get_liste_virtualhosts.php -O ${FIC}
if [ $? != 0 ]; then
#erreur wget -> exit
ldebug "Erreur wget ...."
exit
fi
#detection d'erreur http ... normalement on a que des lignes qui commencent par "listes."
TESTLISTES=`grep "^listes." ${FIC}`
if [ -z "${TESTLISTES}" ]; then
exit
fi
......@@ -29,18 +43,32 @@ cp ${FIC} /etc/apache2/reference_soo.new
cd /etc/apache2/sites-enabled
for domaine in listes.*
do
#echo "on bosse sur ${domaine} .."
ldebug "on bosse sur ${domaine} .."
dom=`echo ${domaine} | sed s/".conf$"/""/`
/usr/sbin/a2dissite ${dom}
#test si le domaine existe ...
TESTDOMAINE=`getent hosts ${dom} | head -n1`
if [ -n "${TESTDOMAINE}" ]; then
/usr/sbin/a2dissite ${dom}
fi
done
for liste in `cat ${FIC}`
do
#echo "on bosse(2) sur ${liste} .."
ldebug "on bosse(2) sur ${liste} .."
domaine=`echo ${liste} | sed s/"^listes."/""/`
autoconfig=`echo ${liste} | sed s/"listes"/"autoconfig"/`
cat /etc/apache2/sites-available/virtualhost_sympa.maquette /etc/apache2/sites-available/virtualhost_sympa.maquette_ssl | sed s/"DOMAINE"/"${domaine}"/ | sed s/"MAQUETTE"/"${liste}"/ | sed s/"AUTOCONFIG"/"${autoconfig}"/ > /etc/apache2/sites-available/${liste}.conf
/usr/sbin/a2ensite ${liste}
#test si le domaine existe ...
TESTDOMAINE=`getent hosts ${domaine} | head -n1`
#test si le sous domaine existe ... car certin ont le sous domaine mais pas le domaine
TESTSOUSDOMAINE=`getent hosts ${liste} | head -n1`
if [ -n "${TESTDOMAINE}" -o -n "${TESTSOUSDOMAINE}" ]; then
ldebug " on active ${liste}"
autoconfig=`echo ${liste} | sed s/"listes"/"autoconfig"/`
cat /etc/apache2/sites-available/virtualhost_sympa.maquette /etc/apache2/sites-available/virtualhost_sympa.maquette_ssl | sed s/"DOMAINE"/"${domaine}"/ | sed s/"MAQUETTE"/"${liste}"/ | sed s/"AUTOCONFIG"/"${autoconfig}"/ > /etc/apache2/sites-available/${liste}.conf
/usr/sbin/a2ensite ${liste}
else
ldebug " on supprime ${liste} car le getent sur le domaine ${domaine} n'a rien retourné"
sed -i -e "/${domaine}/d" ${FIC}
fi
done
cp ${FIC} /etc/apache2/reference_soo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment