@ -1,5 +1,7 @@
#!/bin/bash
#!/bin/bash
set -e
# Retrieve arguments
# Retrieve arguments
domain=$1
domain=$1
path=$2
path=$2
@ -9,45 +11,36 @@ final_path=/var/www/my_webapp
# Check domain/path availability
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a my_webapp
sudo yunohost app checkurl $domain$path -a my_webapp
if [[ ! $? -eq 0 ]]; then
exit 1
fi
path=${path%/}
# Check user
# Check user
sudo yunohost user list --json | grep -q "\"username\": \"$user\""
if [[ ! $? -eq 0 ]]; then
echo "Wrong user"
exit 1
fi
sudo yunohost app setting my_webapp ftp_user -v $user
# Check port availability
sudo yunohost app checkport 21
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Open port in firewall
sudo yunohost firewall allow TCP 21 > /dev/null 2>&1
sudo yunohost user list --json | grep -q "\"username\": \"$user\"" \
|| (echo "User '$user' does not exist" && exit 1)
sudo yunohost app setting my_webapp allowed_users -v "$user"
# Install debian dependencies
sudo apt-get install pure-ftpd-ldap -y -qq
# Update the salt in the Cheryl.php file
salt=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
sed -i "s@SALTTOCHANGE@$salt@g" ../sources/Cheryl.php
# Change user ID in configurations
sed -i "s@FTPUSER@$user@g" ../conf/ldap.conf
sed -i "s@FTPDIR@$final_path@g" ../conf/ldap.conf
sed -i "s@FTPUSER@$user@g" ../sources/index.html
sed -i "s@HOST@$domain@g" ../sources/index.html
# Modify the index.html instruction file
sed -i "s@USER@$user@g" ../sources/index.html
sed -i "s@URL@https://$domain$path/admin/@g" ../sources/index.html
# Copy files to the right place
# Copy files to the right place
sudo mkdir -p $final_path
sudo cp ../sources/index.html $final_path/
sudo mkdir -p $final_path/files
sudo cp ../sources/index.html $final_path/files
sudo cp ../sources/Cheryl.php $final_path/
# Set permissions
# Set permissions
sudo chmod 775 -R $final_path
sudo chown -hR $user:www-data $final_path
sudo chmod 775 -R $final_path/files
sudo chown -hR www-data:www-data $final_path/files
# Modify Nginx configuration file and copy it to Nginx conf directory
# Modify Nginx configuration file and copy it to Nginx conf directory
if [[ "$path" == "" ]]; then
sed -i "s@LOCATIONTOCHANGE@/@g" ../conf/nginx.conf
else
sed -i "s@LOCATIONTOCHANGE@$path@g" ../conf/nginx.conf
fi
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/my_webapp.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/my_webapp.conf
@ -59,17 +52,9 @@ then
sudo yunohost app setting my_webapp unprotected_uris -v "/"
sudo yunohost app setting my_webapp unprotected_uris -v "/"
fi
fi
# Adapt PureFTPd configuration
sudo cp ../conf/ldap.conf /etc/pure-ftpd/db/
sudo sh -c 'echo "yes" > /etc/pure-ftpd/conf/NoAnonymous'
sudo sh -c 'echo "yes" > /etc/pure-ftpd/conf/ChrootEveryone'
sudo sh -c 'echo "no" > /etc/pure-ftpd/conf/UnixAuthentication'
sudo sh -c 'echo "50000 50100" > /etc/pure-ftpd/conf/PassivePortRange'
# Register service to YunoHost monitoring
sudo yunohost service add pure-ftpd-ldap --log "/var/log/pure-ftpd/transfer.log"
# Protect the file manager
sudo yunohost app setting my_webapp protected_uris -v "/admin"
# Reload Nginx, restart PureFTPd and regenerate SSOwat conf
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo service nginx reload
sudo service pure-ftpd-ldap restart
sudo yunohost app ssowatconf
sudo yunohost app ssowatconf