mirror of
https://github.com/YunoHost-Apps/grav_ynh.git
synced 2024-09-03 19:16:01 +02:00
Add SSH and SFTP access settings
This commit is contained in:
parent
4f8af3cdc0
commit
6fa07b3149
5 changed files with 137 additions and 0 deletions
19
config_panel.toml
Normal file
19
config_panel.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
[main]
|
||||||
|
name = "Grav configuration"
|
||||||
|
|
||||||
|
[main.sftp]
|
||||||
|
name = "SSH and SFTP access"
|
||||||
|
|
||||||
|
[main.sftp.with_sftp]
|
||||||
|
ask = "Do you need an SSH and SFTP access?"
|
||||||
|
type = "boolean"
|
||||||
|
default = false
|
||||||
|
|
||||||
|
[main.sftp.password]
|
||||||
|
ask = "Set a password for the SSH and SFTP access"
|
||||||
|
type = "password"
|
||||||
|
optional = true
|
||||||
|
visible = "with_sftp"
|
||||||
|
help = "If a password already exists, leave blank and it will not be replaced."
|
|
@ -13,3 +13,38 @@ pkg_dependencies="php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-mbstring php${
|
||||||
#=================================================
|
#=================================================
|
||||||
# EXPERIMENTAL HELPERS
|
# EXPERIMENTAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
ynh_system_user_add_group() {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=uhs
|
||||||
|
local -A args_array=([u]=username= [g]=groups=)
|
||||||
|
local username
|
||||||
|
local groups
|
||||||
|
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
groups="${groups:-}"
|
||||||
|
|
||||||
|
local group
|
||||||
|
for group in $groups; do
|
||||||
|
usermod -a -G "$group" "$username"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ynh_system_user_del_group() {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=uhs
|
||||||
|
local -A args_array=([u]=username= [g]=groups=)
|
||||||
|
local username
|
||||||
|
local groups
|
||||||
|
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
groups="${groups:-}"
|
||||||
|
|
||||||
|
local group
|
||||||
|
for group in $groups; do
|
||||||
|
gpasswd -d "$username" "$group"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
72
scripts/config
Normal file
72
scripts/config
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC STARTING
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RETRIEVE ARGUMENTS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
set__password() {
|
||||||
|
if [ "$password" == "" ]
|
||||||
|
then
|
||||||
|
ynh_app_setting_set --app=$app --key=password --value="$password"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_app_config_validate() {
|
||||||
|
_ynh_app_config_validate
|
||||||
|
|
||||||
|
if [ "${changed[with_sftp]}" == "true" ] && [ $with_sftp -eq 1 ] && [ "$password" == "" ]
|
||||||
|
then
|
||||||
|
ynh_die --message="You need to set a password to enable SSH and SFTP"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_app_config_apply() {
|
||||||
|
_ynh_app_config_apply
|
||||||
|
|
||||||
|
if [ "${changed[with_sftp]}" == "true" ] && [ $with_sftp -eq 1 ]
|
||||||
|
then
|
||||||
|
ynh_system_user_add_group --username=$app --groups="sftp.app ssh.app"
|
||||||
|
usermod --shell /bin/bash $app
|
||||||
|
|
||||||
|
if [ ! "$password" == "" ]
|
||||||
|
then
|
||||||
|
chpasswd <<< "${app}:${password}"
|
||||||
|
fi
|
||||||
|
elif [ "${changed[with_sftp]}" == "true" ] && [ $with_sftp -eq 0 ]
|
||||||
|
then
|
||||||
|
ynh_system_user_del_group --username=$app --groups="sftp.app ssh.app"
|
||||||
|
usermod --shel /usr/sbin/nologin $app
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ynh_app_config_run $1
|
|
@ -48,6 +48,8 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain
|
||||||
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
||||||
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
||||||
ynh_app_setting_set --app=$app --key=language --value=$language
|
ynh_app_setting_set --app=$app --key=language --value=$language
|
||||||
|
ynh_app_setting_set --app=$app --key=with_sftp --value="false"
|
||||||
|
ynh_app_setting_set --app=$app --key=password --value=$(ynh_string_random)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
|
|
|
@ -25,6 +25,9 @@ language=$(ynh_app_setting_get --app=$app --key=language)
|
||||||
fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
|
fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
|
||||||
fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
|
fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
|
||||||
|
|
||||||
|
with_sftp=$(ynh_app_setting_get --app=$app --key=with_sftp)
|
||||||
|
password=$(ynh_app_setting_get --app=$app --key=password)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK VERSION
|
# CHECK VERSION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -79,6 +82,12 @@ if [ -z "$fpm_usage" ]; then
|
||||||
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
|
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If with_sftp or password don't exist, create them
|
||||||
|
if [ -z "$with_sftp" ] || [ -z "$password" ]; then
|
||||||
|
ynh_app_setting_set --app=$app --key=with_sftp --value="false"
|
||||||
|
ynh_app_setting_set --app=$app --key=password --value=$(ynh_string_random)
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue