diff --git a/lib/roundcube.sh b/lib/roundcube.sh new file mode 100644 index 0000000..cb0649f --- /dev/null +++ b/lib/roundcube.sh @@ -0,0 +1,234 @@ +#!/bin/bash +# +# Roundcube Service + +PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +get_appvars + +config_roundcube() { + echo -ne "\n* Configuring roundcube container.." + + if [ ! -d "/federated/apps/roundcube" ]; then + mkdir -p /federated/apps/roundcube/data/var/www/html + fi + +cat > /federated/apps/roundcube/docker-compose.yml < /federated/apps/roundcube/.env < /dev/null +docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e \"CREATE USER 'roundcube'@'%' IDENTIFIED BY '$ROUNDCUBE_SECRET';\"" &> /dev/null +docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e \"grant all privileges on roundcube.* to 'roundcube'@'%';\"" &> /dev/null +docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e 'flush privileges;'" &> /dev/null + +echo -ne "done.\n" +} +start_roundcube() { + # Start service with command to make sure it's up before proceeding + start_service "roundcube" "nc -z 172.99.0.47 80 &> /dev/null" "7" + + docker exec pdns pdnsutil add-record $DOMAIN roundcube A 86400 $EXTERNALIP &> /dev/null + [ $? -ne 0 ] && fail "Couldn't add dns record for roundcube" + docker exec pdns pdnsutil add-record $DOMAIN webmail A 86400 $EXTERNALIP &> /dev/null + [ $? -ne 0 ] && fail "Couldn't add dns record for roundcube" + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} +email_roundcube() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! + +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

Roundcube is now installed on $DOMAIN

+

+Here is your applications chart on how to access this service:
+

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
Roundcubewebmail.$DOMAINadmin@$DOMAIN
Panel password
User access using your panel user email and passwordClick hereRoundcube is a web-based IMAP email client
+

Thanks for your support!

+

+Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful +time with Federated Core. +

+Again, if we can be of any assistance, please don't hesitate to get in touch. +

+Support: https://support.federated.computer
+Phone: (970) 722-8715
+Email: support@federated.computer
+

+It's your computer. Let's make it work for you! + +EOF + + # Send out e-mail from mail container with details + docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" + rm /federated/apps/mail/data/root/certs/mailfile + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} +uninstall_roundcube() { + echo -ne "* Uninstalling roundcube container.." + spin & + SPINPID=$! + + # First stop the service + cd /federated/apps/roundcube && docker-compose -f docker-compose.yml -p roundcube down &> /dev/null + + # Delete database and user + docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e 'drop database roundcube;'" &> /dev/null + docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -e 'drop user roundcube;'" &> /dev/null + + # Delete the app directory + rm -rf /federated/apps/roundcube + + # Delete the image + docker image rm roundcube/roundcubemail:$IMAGE_VERSION &> /dev/null + + # Delete the DNS record + docker exec pdns pdnsutil delete-rrset $DOMAIN roundcube A + + # Uninstall the SSO configuration if it exists in authelia (authelia must exist too) + if [[ $(grep "### Roundcube" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]]; then + sed -i '/### Roundcube/,/### /{/### PowerDNS/!{/### /!d}}' /federated/apps/authelia/data/config/idproviders.yml + sed -i '/### Roundcube/d' /federated/apps/authelia/data/config/idproviders.yml + /federated/bin/stop authelia + /federated/bin/start authelia + fi + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} +configsso_roundcube() { + [ ! -d "/federated/apps/authelia" ] && failcheck "Authelia is not installed. You need this first before continuing." + [ ! -f "/federated/apps/authelia/data/config/idproviders.yml" ] && failcheck "Authelia idproviders.yml is missing." + [[ $(grep "### Roundcube" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null) ]] && failcheck "Authelia already has a Roundcube configuration." + + ROUNDCUBE_CLIENT_SECRET=$(create_password); + ROUNDCUBE_CLIENT_SECRET_HASH=$(docker run -it --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --password $ROUNDCUBE_CLIENT_SECRET | awk '{ print $2 }') + +cat >> /federated/apps/authelia/data/config/idproviders.yml <