diff --git a/README.md b/README.md index d6e36ab..a22f42f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# webapp_multi_ynh -multi instances webapp for yunohost +Multi Instances Web App +------------------- + +No FTP Support diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..1d8f87b --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,20 @@ +location PATHTOCHANGE { + alias ALIASTOCHANGE; + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + index index.php index.html index.htm; + default_type text/html; + 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; + } + + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..ffa8346 --- /dev/null +++ b/manifest.json @@ -0,0 +1,51 @@ +{ + "name": "Multi Instances Webapp", + "id": "webapp_multi", + "description": { + "en": "Multi Instances Web App without FTP access", + "fr": "Multi Instances Web App vide sans accès FTP" + }, + "maintainer": { + "name": "Polytan02", + "email": "polytan02@mcgva.org" + }, + "multi_instance": "true", + "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", + "fr": "Choisissez l'utilisateur YunoHost associé" + }, + "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..2bcf76a --- /dev/null +++ b/scripts/install @@ -0,0 +1,96 @@ +#!/bin/bash + +# Retrieve arguments +domain=$1 +path=$2 +user=$3 +is_public=$4 + +# sitename == path without "/" +sitename=$(echo $path | cut -d '/' -f 2) + +if [ $path = "/" ] +then + sitename="root" +fi + +app=webapp_multi_$domain_$sitename +final_path=/var/www/$app_$domain_$sitename + + +# Check domain/path availability +sudo yunohost app checkurl $domain$path -a $app +if [[ ! $? -eq 0 ]]; then + exit 1 +fi + +# 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 $app user -v $user + + +#sudo yunohost app setting $app ftp_user -v $user + +# Créer le dossier parent des webapp pour l'utilisateur +#if test ! -d $parent_dir +#then # Créer le dossier parent uniquement si il n'existe pas + + +# Creation of folder +sudo rm -rf $final_path +sudo mkdir $final_path + +# Base site +sudo cp ../sources/index.html $final_path/ + +# Set permissions +sudo chmod 775 -R $final_path +sudo chown -hR www-data:www-data $final_path + +#else +# echo "Création du dossier $parent_dir ignorée, le dossier existe déjà." +#fi + +# Change user ID in configurations +#sed -i "s@FTPUSER@$user@g" ../sources/index_ftp.html +#sed -i "s@HOST@$domain@g" ../sources/index_ftp.html +#sed -i "s@NET2FTP@$netftp_path@g" ../sources/index_ftp.html + +# Copy files to the right place +#sudo mkdir $final_path +#sudo cp ../sources/index.html $final_path/ + +# Vérifie si pure-ftpd est déjà installé +#if test -f /usr/sbin/pure-ftpd-ldap +#then # Si oui, vérifie si net2ftp est également installé. +# if test -d $parent_dir/netftp +# then +# sudo cp ../sources/index_ftp.html $final_path/index.html # Remplace l'index.html par celui intégrant les informations ftp +# fi +#fi + +# 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/$sitename.conf + +# Make app public if necessary +sudo yunohost app setting $app is_public -v "$is_public" +if [ "$is_public" = "Yes" ]; +then + sudo yunohost app setting $app skipped_uris -v "$domain$path" +fi + +# Reload Nginx and regenerate SSOwat conf +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..bdb0b54 --- /dev/null +++ b/scripts/remove @@ -0,0 +1,22 @@ +#!/bin/bash + +user=$(sudo yunohost app setting my_webapp user) +path=$(sudo yunohost app setting my_webapp path) +domain=$(sudo yunohost app setting my_webapp domain) +parent_dir=/var/www/webapp_$user +name=$(echo $path | cut -d '/' -f 2) +final_path=$parent_dir$path + +# Suppression du dossier de la webapp +sudo rm -rf $final_path +# Suppression de la config nginx de la webapp +sudo rm -f /etc/nginx/conf.d/$domain.d/$name.conf + +# Vérifie si le dossier parent est vide. Ce qui signifie que toutes les webapp ont été désinstallées. Ainsi que le client ftp net2ftp. +if test -z "$(ls $parent_dir | head -n1)" +then + sudo rmdir $parent_dir +fi + +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..129440b --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,29 @@ +#!/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) + +name=$(echo $2 | cut -d '/' -f 2) +parent_dir=/var/www/webapp_$user +final_path=$parent_dir$path + +netftp_path=/ftp_webapp_$user + +# 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/$name.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 + +# Reload Nginx and regenerate SSOwat conf +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/sources/index.html b/sources/index.html new file mode 100644 index 0000000..0ea42de --- /dev/null +++ b/sources/index.html @@ -0,0 +1,16 @@ + + +
+ +Congratulation, you have just installed your custom web app without ftp access.
+ +As a reward, here is a random cat picture:
+