From b8cecfe08d6277521cbc9ff9e549cf192667bbb8 Mon Sep 17 00:00:00 2001 From: Hystepik Date: Tue, 23 Jan 2024 15:22:46 +0100 Subject: [PATCH 1/3] Fix action_customurl while certbot not working --- scripts/action_customurl_instance.sh | 59 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/scripts/action_customurl_instance.sh b/scripts/action_customurl_instance.sh index e8111ae61..8f2f037c6 100755 --- a/scripts/action_customurl_instance.sh +++ b/scripts/action_customurl_instance.sh @@ -273,8 +273,7 @@ if [[ "$mode" == "deploycustomurl" ]]; then sed -e "s;__SELLYOURSAAS_LOGIN_FOR_SUPPORT__;$SELLYOURSAAS_LOGIN_FOR_SUPPORT;g" | \ sed -e "s;#ErrorLog;$ErrorLog;g" | \ sed -e "s;__webMyAccount__;$SELLYOURSAAS_ACCOUNT_URL;g" | \ - sed -e "s;__webAppPath__;$instancedir;g" | \ - sed -e "s/with\.sellyoursaas\.com/$CERTIFFORCUSTOMDOMAIN/g" > $apacheconf + sed -e "s;__webAppPath__;$instancedir;g" > $apacheconf export vhostko=$? echo `date +'%Y-%m-%d %H:%M:%S'`" Result of generation of file $apacheconf = $vhostko" @@ -295,38 +294,38 @@ if [[ "$mode" == "deploycustomurl" ]]; then export customcrtfolder="/home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt" if [[ ! -d $customcrtfolder ]]; then - echo "Create cert directory with mkdir /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/; chown admin.admin /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/;" - mkdir /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/; chown admin.admin /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/; + echo "Create cert directory with mkdir $customcrtfolder; chown admin.admin $customcrtfolder;" + mkdir $customcrtfolder; chown admin.admin $customcrtfolder; fi - echo `date +'%Y-%m-%d %H:%M:%S'`" Generation of cert file for custom url" + #echo `date +'%Y-%m-%d %H:%M:%S'`" Generation of cert file for custom url" - echo certbot certonly --webroot -w $instancedir/documents/website/ -d www.$customurl - certbot certonly --webroot -w $instancedir/documents/website/ -d www.$customurl - export certko=$? + #echo certbot certonly --webroot -w $instancedir/htdocs/.well-known -d www.$customurl + #certbot certonly --webroot -w $instancedir/htdocs/.well-known -d www.$customurl + #export certko=$? - echo `date +'%Y-%m-%d %H:%M:%S'`" Result of generation of cert file for custom url = $certko" - - echo "Link certificate for virtualhost with - ln -fs /etc/letsencrypt/live/www.$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.key - ln -fs /etc/letsencrypt/live/www.$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.crt - ln -fs /etc/letsencrypt/live/www.$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl-intermediate.crt - " - ln -fs /etc/letsencrypt/live/www.$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.key - ln -fs /etc/letsencrypt/live/www.$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.crt - ln -fs /etc/letsencrypt/live/www.$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl-intermediate.crt - - - echo `date +'%Y-%m-%d %H:%M:%S'`" Restart apache to have the new certificate beeing loaded" - service apache2 reload - if [[ "x$?" != "x0" ]]; then - echo Error when running service apache2 reload - echo "Failed to restart apache to validate the new virtual host $apacheconf: Error when running service apache2 reload" | mail -aFrom:$EMAILFROM -s "[Alert] Pb in apache reload to enable a new website" $EMAILTO - sleep 1 - exit 20 - else - sleep 3 - fi + #echo `date +'%Y-%m-%d %H:%M:%S'`" Result of generation of cert file for custom url = $certko" + + #echo "Link certificate for virtualhost with + # ln -fs /etc/letsencrypt/live/www.$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.key + # ln -fs /etc/letsencrypt/live/www.$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.crt + # ln -fs /etc/letsencrypt/live/www.$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl-intermediate.crt + #" + #ln -fs /etc/letsencrypt/live/www.$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.key + #ln -fs /etc/letsencrypt/live/www.$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.crt + #ln -fs /etc/letsencrypt/live/www.$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl-intermediate.crt + + + #echo `date +'%Y-%m-%d %H:%M:%S'`" Restart apache to have the new certificate beeing loaded" + #service apache2 reload + #if [[ "x$?" != "x0" ]]; then + # echo Error when running service apache2 reload + # echo "Failed to restart apache to validate the new virtual host $apacheconf: Error when running service apache2 reload" | mail -aFrom:$EMAILFROM -s "[Alert] Pb in apache reload to enable a new website" $EMAILTO + # sleep 1 + # exit 20 + #else + # sleep 3 + #fi fi From cb4aee682611d6833a1b256a6503e5b32ae7307d Mon Sep 17 00:00:00 2001 From: Hystepik Date: Tue, 6 Feb 2024 09:31:19 +0100 Subject: [PATCH 2/3] fix action custom instance cert part --- scripts/action_customurl_instance.sh | 73 ++++++++++++++++++---------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/scripts/action_customurl_instance.sh b/scripts/action_customurl_instance.sh index 8f2f037c6..5e1e1856e 100755 --- a/scripts/action_customurl_instance.sh +++ b/scripts/action_customurl_instance.sh @@ -298,34 +298,55 @@ if [[ "$mode" == "deploycustomurl" ]]; then mkdir $customcrtfolder; chown admin.admin $customcrtfolder; fi - #echo `date +'%Y-%m-%d %H:%M:%S'`" Generation of cert file for custom url" + echo `date +'%Y-%m-%d %H:%M:%S'`" Generation of cert file for custom url" - #echo certbot certonly --webroot -w $instancedir/htdocs/.well-known -d www.$customurl - #certbot certonly --webroot -w $instancedir/htdocs/.well-known -d www.$customurl - #export certko=$? + echo certbot certonly --webroot -w $instancedir/htdocs/ -d www.$customurl + certbot certonly --webroot -w $instancedir/htdocs/ -d www.$customurl + export certko=$? + echo `date +'%Y-%m-%d %H:%M:%S'`" Result of generation of cert file for custom url = $certko" - #echo `date +'%Y-%m-%d %H:%M:%S'`" Result of generation of cert file for custom url = $certko" - - #echo "Link certificate for virtualhost with - # ln -fs /etc/letsencrypt/live/www.$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.key - # ln -fs /etc/letsencrypt/live/www.$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.crt - # ln -fs /etc/letsencrypt/live/www.$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl-intermediate.crt - #" - #ln -fs /etc/letsencrypt/live/www.$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.key - #ln -fs /etc/letsencrypt/live/www.$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.crt - #ln -fs /etc/letsencrypt/live/www.$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl-intermediate.crt - - - #echo `date +'%Y-%m-%d %H:%M:%S'`" Restart apache to have the new certificate beeing loaded" - #service apache2 reload - #if [[ "x$?" != "x0" ]]; then - # echo Error when running service apache2 reload - # echo "Failed to restart apache to validate the new virtual host $apacheconf: Error when running service apache2 reload" | mail -aFrom:$EMAILFROM -s "[Alert] Pb in apache reload to enable a new website" $EMAILTO - # sleep 1 - # exit 20 - #else - # sleep 3 - #fi + if [[ "x$?" != "x0" ]]; then + echo Error when running certbot certonly --webroot -w $instancedir/htdocs/ -d www.$customurl + echo "Failed to generate custom certificate www.$customurl for virtualhost $apacheconf: certbot certonly --webroot -w $instancedir/htdocs/ -d www.$customurl" | mail -aFrom:$EMAILFROM -s "[Alert] Pb in custom certificate generation" $EMAILTO + sleep 1 + exit 20 + else + sleep 3 + fi + + echo `date +'%Y-%m-%d %H:%M:%S'`" Link of generated cert file for custom url" + echo "Link certificate for virtualhost with + ln -fs /etc/letsencrypt/live/www.$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.key + ln -fs /etc/letsencrypt/live/www.$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.crt + ln -fs /etc/letsencrypt/live/www.$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl-intermediate.crt + " + ln -fs /etc/letsencrypt/live/www.$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.key + export certkeyko=$? + ln -fs /etc/letsencrypt/live/www.$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl.crt + export certcrtko=$? + ln -fs /etc/letsencrypt/live/www.$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$instancename.$domainname-$customurl-intermediate.crt + export certinterko=$? + + if [[ "x$certkeyko" != "x0" ]] || [[ "x$certcrtko" != "x0" ]] || [[ "x$certinterko" != "x0" ]]; then + echo Error when linking certificate with error certkeyko=$certkeyko , certcrtko=$certcrtko and certinterko=$certinterko + echo "Failed to linking certificate www.$customurl for virtualhost $apacheconf: certkeyko=$certkeyko , certcrtko=$certcrtko and certinterko=$certinterko" | mail -aFrom:$EMAILFROM -s "[Alert] Pb in custom certificate linking" $EMAILTO + sleep 1 + exit 20 + else + sleep 3 + fi + + + echo `date +'%Y-%m-%d %H:%M:%S'`" Restart apache to have the new certificate beeing loaded" + service apache2 reload + if [[ "x$?" != "x0" ]]; then + echo Error when running service apache2 reload + echo "Failed to restart apache to validate the new virtual host $apacheconf: Error when running service apache2 reload" | mail -aFrom:$EMAILFROM -s "[Alert] Pb in apache reload to enable a new website" $EMAILTO + sleep 1 + exit 20 + else + sleep 3 + fi fi From 11de8f0f77e817a4608cfa57235d486d50e479d8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 6 Feb 2024 12:47:34 +0100 Subject: [PATCH 3/3] Update action_customurl_instance.sh --- scripts/action_customurl_instance.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/action_customurl_instance.sh b/scripts/action_customurl_instance.sh index 5e1e1856e..4e6957bf9 100755 --- a/scripts/action_customurl_instance.sh +++ b/scripts/action_customurl_instance.sh @@ -252,8 +252,7 @@ if [[ "$mode" == "deploycustomurl" ]]; then sed -e 's;__SELLYOURSAAS_LOGIN_FOR_SUPPORT__;$SELLYOURSAAS_LOGIN_FOR_SUPPORT;g' | \ sed -e 's;#ErrorLog;$ErrorLog;g' | \ sed -e 's;__webMyAccount__;$SELLYOURSAAS_ACCOUNT_URL;g' | \ - sed -e 's;__webAppPath__;$instancedir;g' | \ - sed -e 's/with\.sellyoursaas\.com/$CERTIFFORCUSTOMDOMAIN/g' > $apacheconf" + sed -e 's;__webAppPath__;$instancedir;g' > $apacheconf" cat $vhostfile | sed -e "s/__webAppDomain__/$customurl/g" | \ sed -e "s/__webAppAliases__/$customurl/g" | \ sed -e "s/__webAppLogName__/$instancename/g" | \