One config per domain + /var/lib/byod/ to store this info #1
30
admin.sh
30
admin.sh
|
@ -2,20 +2,30 @@
|
||||||
|
|
||||||
bestip=$(dig +short a tilde.best)
|
bestip=$(dig +short a tilde.best)
|
||||||
|
|
||||||
|
[! -d /var/lib/byod] && mkdir /var/lib/byod
|
||||||
|
|
||||||
for byod in /home/*/byod; do
|
for byod in /home/*/byod; do
|
||||||
user=$(stat -c '%U' $byod)
|
user=$(stat -c '%U' $byod)
|
||||||
domain=$(cat $byod)
|
domain=$(cat $byod)
|
||||||
echo "$user is requesting $domain"
|
echo "$user is requesting $domain"
|
||||||
if [ -s /etc/nginx/sites-enabled/byod-$user-$domain.conf ]; then
|
if [ -s /etc/nginx/sites-enabled/byod-$domain.conf ]; then
|
||||||
echo "byod already configured for $user at $domain"
|
echo "byod already configured for $domain"
|
||||||
continue
|
previousUser=$(cat /var/lib/byod/user/$user)
|
||||||
|
if [! "$user" -eq "$previousUser"]; then
|
||||||
|
error="ERROR: The domain $domain was already reclaimed by $previousUser"
|
||||||
|
echo "$error"
|
||||||
|
mail=$(printf "From: root@tilde.best\nTo: $user\nSubject: BYOD failed to add domain $domain\n$error\n.\n")
|
||||||
|
echo "$mail" | sendmail -t
|
||||||
|
continue
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
domainip=$(dig +short a $domain)
|
domainip=$(dig +short a $domain)
|
||||||
if [ "$bestip" == "$domainip" ]
|
if [ "$bestip" == "$domainip"]; then
|
||||||
then
|
echo "$domain" > /var/lib/byod/user/$user
|
||||||
|
echo "$user" > /var/lib/byod/domain/$domain
|
||||||
sed -e "s/<user>/$user/" -e "s/<domain>/$domain/" template.conf \
|
sed -e "s/<user>/$user/" -e "s/<domain>/$domain/" template.conf \
|
||||||
> /etc/nginx/sites-available/byod-$user-$domain.conf
|
> /etc/nginx/sites-available/byod-$domain.conf
|
||||||
ln -s ../sites-available/byod-$user-$domain.conf /etc/nginx/sites-enabled/byod-$user-$domain.conf
|
ln -s ../sites-available/byod-$domain.conf /etc/nginx/sites-enabled/byod-$domain.conf
|
||||||
certbot --nginx -d $domain --non-interactive --redirect
|
certbot --nginx -d $domain --non-interactive --redirect
|
||||||
else
|
else
|
||||||
echo "domain's dns not configured correctly"
|
echo "domain's dns not configured correctly"
|
||||||
|
@ -24,5 +34,9 @@ for byod in /home/*/byod; do
|
||||||
done
|
done
|
||||||
|
|
||||||
nginx -t
|
nginx -t
|
||||||
systemctl reload nginx
|
|
||||||
|
|
||||||
|
if ["$?" -eq "0"]; then
|
||||||
|
nginx -s reload
|
||||||
|
else
|
||||||
|
echo "failed to validate new nginx config, see previous error"
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue