From bcb80b94f70d93c322f8cb5c5754a9a12657286f Mon Sep 17 00:00:00 2001 From: Kload Date: Sun, 20 Apr 2014 19:33:07 +0200 Subject: [PATCH] Init --- .gitignore | 1 + README.md | 4 +++ conf/ldap.conf | 6 ++++ conf/nginx.conf | 12 ++++++++ manifest.json | 52 ++++++++++++++++++++++++++++++++ scripts/install | 75 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/remove | 13 ++++++++ scripts/upgrade | 35 ++++++++++++++++++++++ sources/index.html | 17 +++++++++++ 9 files changed, 215 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 conf/ldap.conf create mode 100644 conf/nginx.conf create mode 100644 manifest.json create mode 100644 scripts/install create mode 100644 scripts/remove create mode 100644 scripts/upgrade create mode 100644 sources/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/README.md b/README.md new file mode 100644 index 0000000..92a5d10 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Roundcube for YunoHost +---------------------- + +http://roundcube.net/ diff --git a/conf/ldap.conf b/conf/ldap.conf new file mode 100644 index 0000000..5c18435 --- /dev/null +++ b/conf/ldap.conf @@ -0,0 +1,6 @@ +LDAPBaseDN ou=users,dc=yunohost,dc=org +LDAPFilter (&(objectClass=mailAccount)(uid=FTPUSER)) +LDAPHomeDir FTPDIR +LDAPAuthMethod BIND +LDAPDefaultHomeDirectory FTPDIR + diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..9df087e --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,12 @@ +location PATHTOCHANGE { + alias ALIASTOCHANGE; + index index.php index.html index.htm; + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + } +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..308a6da --- /dev/null +++ b/manifest.json @@ -0,0 +1,52 @@ +{ + "name": "Custom Webapp + FTP", + "id": "my_webapp", + "description": { + "en": "Empty App with FTP access to the web directory", + "fr": "App vide avec un accès FTP au répertoire Web" + }, + "developer": { + "name": "kload", + "email": "kload@kload.fr", + "url": "http://kload.fr" + }, + "multi_instance": "false", + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain for your Webapp", + "fr": "Choisissez un domaine pour votre Webapp" + }, + "example": "domain.org" + }, + { + "name": "path", + "ask": { + "en": "Choose a path for your Webapp", + "fr": "Choisissez un chemin pour votre Webapp" + }, + "example": "/site", + "default": "/site" + }, + { + "name": "admin", + "ask": { + "en": "Choose the YunoHost user who will be able to upload documents via FTP", + "fr": "Choisissez l'utilisateur YunoHost qui sera capable d'envoyer des documents via FTP" + }, + "example": "johndoe" + }, + { + "name": "is_public", + "ask": { + "en": "Is it a public website ?", + "fr": "Est-ce un site public ?" + }, + "choices": ["Yes", "No"], + "default": "Yes" + } + ] + } +} diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..1d0c315 --- /dev/null +++ b/scripts/install @@ -0,0 +1,75 @@ +#!/bin/bash + +# Retrieve arguments +domain=$1 +path=$2 +user=$3 +is_public=$4 +final_path=/var/www/my_webapp + +# Check domain/path availability +sudo yunohost app checkurl $domain$path -a my_webapp +if [[ ! $? -eq 0 ]]; then + exit 1 +fi + +# Check user +ls /home | grep $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 + +# Install debian dependencies +sudo apt-get install pure-ftpd-ldap -y -qq + +# 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 + +# Copy files to the right place +sudo mkdir -p $final_path +sudo cp ../sources/index.html $final_path/ + +# Set permissions +sudo chmod 775 -R $final_path +sudo chown -hR $user:www-data $final_path + +# Modify Nginx configuration file and copy it to Nginx conf directory +sed -i "s@PATHTOCHANGE@$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 + +# Make app public if necessary +sudo yunohost app setting my_webapp is_public -v "$is_public" +if [ $is_public = "Yes" ]; +then + sudo yunohost app setting my_webapp skipped_uris -v "/" +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 app service pure-ftpd-ldap --log "/var/log/pure-ftpd/transfer.log" + +# Reload Nginx, restart PureFTPd and regenerate SSOwat conf +sudo service nginx reload +sudo service pure-ftpd-ldap restart +sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..077e6d6 --- /dev/null +++ b/scripts/remove @@ -0,0 +1,13 @@ +#!/bin/bash + +domain=$(sudo yunohost app setting my_webapp domain) + +sudo service pure-ftpd-ldap stop +sudo apt-get remove -y -qq pure-ftpd-ldap pure-ftpd-common +sudo yunohost app service -R pure-ftpd-ldap + +sudo rm -rf /var/www/my_webapp +sudo rm -f /etc/nginx/conf.d/$domain.d/my_webapp.conf + +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..a457f9f --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,35 @@ +#!/bin/bash + +# Retrieve arguments +domain=$(sudo yunohost app setting my_webapp domain) +path=$(sudo yunohost app setting my_webapp path) +user=$(sudo yunohost app setting my_webapp ftp_user) +is_public=$(sudo yunohost app setting my_webapp is_public) +final_path=/var/www/my_webapp + +# Change user ID in configurations +sed -i "s/FTPUSER/$user/g" ../conf/ldap.conf +sed -i "s/FTPDIR/$final_path/g" ../conf/ldap.conf + +# Modify Nginx configuration file and copy it to Nginx conf directory +sed -i "s@PATHTOCHANGE@$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 + +# Make app public if necessary +if [ $is_public = "Yes" ]; +then + sudo yunohost app setting my_webapp skipped_uris -v "/" +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' + +# Reload Nginx, restart PureFTPd and regenerate SSOwat conf +sudo service nginx reload +sudo service pure-ftpd-ldap restart +sudo yunohost app ssowatconf diff --git a/sources/index.html b/sources/index.html new file mode 100644 index 0000000..6dd1acc --- /dev/null +++ b/sources/index.html @@ -0,0 +1,17 @@ + + + + +

It works !

+ +

Congratulation, you have just installed your custom web app.

+

You can access to the directory of this web page by connecting as FTPUSER to your server HOST via FTP on the standard port 21.

+ +
+ +

As a reward, here is a random cat picture:

+

+ + + +