From 2fd3fe53fdcf0aa4a41612252bfcba9119d8dde0 Mon Sep 17 00:00:00 2001 From: Hystepik Date: Wed, 7 Feb 2024 10:03:39 +0100 Subject: [PATCH 1/3] modify rename remote acion to generate cert --- myaccount/index.php | 2 +- scripts/action_suspend_unsuspend.sh | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/myaccount/index.php b/myaccount/index.php index 64041abca..f194bd6cd 100644 --- a/myaccount/index.php +++ b/myaccount/index.php @@ -2438,7 +2438,7 @@ if (!$error) { //$object->context["options_websitename"] = $website->ref; $object->array_options['options_custom_url'] = urlencode($custom_url); - $result = $sellyoursaasutils->sellyoursaasRemoteAction("deploycustomurl", $object); + $result = $sellyoursaasutils->sellyoursaasRemoteAction("rename", $object); if ($result <= 0) { $error++; } diff --git a/scripts/action_suspend_unsuspend.sh b/scripts/action_suspend_unsuspend.sh index 30dc3ee86..b2816a7fc 100755 --- a/scripts/action_suspend_unsuspend.sh +++ b/scripts/action_suspend_unsuspend.sh @@ -229,7 +229,7 @@ testorconfirm="confirm" if [[ "$mode" == "rename" ]]; then - if [[ "$fqn" != "$fqnold" ]]; then + if [[ "$fqnold" !="-.-" ]] && [[ "$fqn" != "$fqnold" ]]; then echo `date +'%Y-%m-%d %H:%M:%S'`" ***** For instance in $targetdir/$osusername/$dbname, check if new virtual host $fqn exists" export apacheconf="/etc/apache2/sellyoursaas-online/$fqn.conf" @@ -356,14 +356,25 @@ if [[ "$mode" == "rename" ]]; then # because we added a custom url # Generate the letsencrypt certificate - # @TODO - - # certbot certonly --webroot -w $instancedir -d $customurl - # create links + echo "certbot certonly --webroot -w $instancedir -d $customurl" + certbot certonly --webroot -w $instancedir -d $customurl + + # create links + if [[ -e /etc/letsencrypt/live/$customurl/cert.pem ]]; then + 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/$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$fqn-$customurl.key + ln -fs /etc/letsencrypt/live/$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$fqn-$customurl.crt + ln -fs /etc/letsencrypt/live/$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$fqn-$customurl-intermediate.crt + " + ln -fs /etc/letsencrypt/live/$customurl/privkey.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$fqn-$customurl.key + ln -fs /etc/letsencrypt/live/$customurl/cert.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$fqn-$customurl.crt + ln -fs /etc/letsencrypt/live/$customurl/fullchain.pem /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$fqn-$customurl-intermediate.crt + fi fi # If custom cert not found, we fallback on the wildcard one for server (will generate a warning, but it will works !) - if [[ -e /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$fqn-custom.crt ]]; then + if [[ ! -e /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$fqn-custom.crt ]]; then export webCustomSSLCertificateCRT=$webSSLCertificateCRT export webCustomSSLCertificateKEY=$webSSLCertificateKEY export webCustomSSLCertificateIntermediate=$webSSLCertificateIntermediate @@ -473,7 +484,7 @@ if [[ "$mode" == "rename" ]]; then # If we rename instance - if [[ "$fqn" != "$fqnold" ]]; then + if [[ "$fqnold" !="-.-" ]] && [[ "$fqn" != "$fqnold" ]]; then echo `date +'%Y-%m-%d %H:%M:%S'`" ***** For instance in $targetdir/$osusername/$dbname, delete old virtual name $fqnold" export apacheconf="/etc/apache2/sellyoursaas-online/$fqnold.conf" From dfe668bb2a93809739c46b750ca8292eba534b94 Mon Sep 17 00:00:00 2001 From: Hystepik Date: Wed, 7 Feb 2024 10:05:10 +0100 Subject: [PATCH 2/3] fix typo --- scripts/action_suspend_unsuspend.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/action_suspend_unsuspend.sh b/scripts/action_suspend_unsuspend.sh index b2816a7fc..78c8aeee1 100755 --- a/scripts/action_suspend_unsuspend.sh +++ b/scripts/action_suspend_unsuspend.sh @@ -229,7 +229,7 @@ testorconfirm="confirm" if [[ "$mode" == "rename" ]]; then - if [[ "$fqnold" !="-.-" ]] && [[ "$fqn" != "$fqnold" ]]; then + if [[ "$fqnold" != "-.-" ]] && [[ "$fqn" != "$fqnold" ]]; then echo `date +'%Y-%m-%d %H:%M:%S'`" ***** For instance in $targetdir/$osusername/$dbname, check if new virtual host $fqn exists" export apacheconf="/etc/apache2/sellyoursaas-online/$fqn.conf" @@ -484,7 +484,7 @@ if [[ "$mode" == "rename" ]]; then # If we rename instance - if [[ "$fqnold" !="-.-" ]] && [[ "$fqn" != "$fqnold" ]]; then + if [[ "$fqnold" != "-.-" ]] && [[ "$fqn" != "$fqnold" ]]; then echo `date +'%Y-%m-%d %H:%M:%S'`" ***** For instance in $targetdir/$osusername/$dbname, delete old virtual name $fqnold" export apacheconf="/etc/apache2/sellyoursaas-online/$fqnold.conf" From b20d10cdca0c0e9acb409f699c1bcd18652f3f52 Mon Sep 17 00:00:00 2001 From: Hystepik Date: Fri, 9 Feb 2024 14:08:49 +0100 Subject: [PATCH 3/3] add cration of .well-known folder --- scripts/action_suspend_unsuspend.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/action_suspend_unsuspend.sh b/scripts/action_suspend_unsuspend.sh index 78c8aeee1..e8d643e2e 100755 --- a/scripts/action_suspend_unsuspend.sh +++ b/scripts/action_suspend_unsuspend.sh @@ -353,11 +353,25 @@ if [[ "$mode" == "rename" ]]; then # We must create it using letsencrypt if not yet created if [[ ! -e /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/$fqn-custom.crt ]]; then # When we rename, it may be because we change abc.with... into def.with..., or - # because we added a custom url - + # because we added a custom url + + if [[ ! -d $instancedir/htdocs/.well-known ]]; then + echo "mkdir $instancedir/htdocs/.well-known" + mkdir $instancedir/htdocs/.well-known + echo "chown $osusername:$osusername $instancedir/htdocs/.well-known" + chown $osusername:$osusername $instancedir/htdocs/.well-known + fi + + if [[ ! -d $instancedir/htdocs/.well-known/acme-challenge ]]; then + echo "mkdir $instancedir/htdocs/.well-known/acme-challenge" + mkdir $instancedir/htdocs/.well-known/acme-challenge + echo "chown $osusername:$osusername $instancedir/htdocs/.well-known/acme-challenge" + chown $osusername:$osusername $instancedir/htdocs/.well-known/acme-challenge + fi + # Generate the letsencrypt certificate - echo "certbot certonly --webroot -w $instancedir -d $customurl" - certbot certonly --webroot -w $instancedir -d $customurl + echo "certbot certonly --webroot -w $instancedir/htdocs -d $customurl" + certbot certonly --webroot -w $instancedir/htdocs -d $customurl # create links if [[ -e /etc/letsencrypt/live/$customurl/cert.pem ]]; then