From 133dd08717a9356dd8e2468773ab77d8e3ed0c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 15 May 2016 12:14:29 +0200 Subject: [PATCH] [enh] Check password strength and check if user exists at removal --- scripts/install | 18 +++++++++++------- scripts/remove | 6 ++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/install b/scripts/install index 30eeb75..e3051a4 100644 --- a/scripts/install +++ b/scripts/install @@ -21,14 +21,24 @@ with_mysql=$5 sudo yunohost app checkurl "${domain}${path}" -a "$app" \ || exit 1 +# Check password strength +[[ ${#password} -gt 5 ]] || ynh_die \ +"The password is too weak, it must be longer than 5 characters" + # Check destination directory DESTDIR="/var/www/${app}" [[ -d "$DESTDIR" ]] && ynh_die \ "The destination directory '${DESTDIR}' already exists.\ You should safely delete it before installing this app." -# Create the user account +# Save app settings user="webapp${app_nb}" +ynh_app_setting_set "$app" is_public "$is_public" +ynh_app_setting_set "$app" with_mysql "$with_mysql" +ynh_app_setting_set "$app" password "$password" +ynh_app_setting_set "$app" user "$user" + +# Create the user account sudo useradd -c "${app} user account" \ -d "$DESTDIR" -M -g www-data "$user" \ || ynh_die "Unable to create user account" @@ -70,12 +80,6 @@ sudo chown -hR "${user}:" "$DESTDIR" # SFTP connections sudo chown root: "$DESTDIR" -# Save app settings -ynh_app_setting_set "$app" is_public "$is_public" -ynh_app_setting_set "$app" with_mysql "$with_mysql" -ynh_app_setting_set "$app" password "$password" -ynh_app_setting_set "$app" user "$user" - # Set SSOwat rules [[ $is_public -eq 1 ]] \ && ynh_app_setting_set "$app" skipped_uris "/" diff --git a/scripts/remove b/scripts/remove index eac45a3..021afa4 100644 --- a/scripts/remove +++ b/scripts/remove @@ -10,6 +10,7 @@ app_nb=$YNH_APP_INSTANCE_NUMBER # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) with_mysql=$(ynh_app_setting_get "$app" with_mysql) +user=$(ynh_app_setting_get "$app" user) # Drop MySQL database and user as needed if [[ $with_mysql -eq 1 ]]; then @@ -34,5 +35,6 @@ sudo service nginx reload || true sudo service sshd reload # Remove the user account -user="webapp${app_nb}" -sudo deluser --quiet --force "$user" >/dev/null +id "$user" >/dev/null 2>&1 \ + && sudo deluser --quiet --force "$user" >/dev/null \ + || true