mirror of
https://github.com/YunoHost-Apps/wikijs_ynh.git
synced 2024-09-03 20:36:09 +02:00
Sanitize ldap_user
This commit is contained in:
parent
c367e46820
commit
1168c040d7
4 changed files with 25 additions and 4 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
source _common.sh
|
||||
source ynh_send_readme_to_admin__2
|
||||
source ynh_sanitize_name
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -30,7 +31,7 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
|
|||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
ldap_user="${app}_ldap"
|
||||
ldap_user=$(ynh_sanitize_name --name="${app}ldap")
|
||||
ldap_password=$(ynh_string_random --length=8)
|
||||
|
||||
#=================================================
|
||||
|
@ -120,7 +121,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path"
|
|||
#=================================================
|
||||
ynh_print_info --message="Creating LDAP user..."
|
||||
|
||||
yunohost user create $ldap_user --firstname $app --lastname $app --mail ${ldap_user}@$domain --password $ldap_password -q 0
|
||||
yunohost user create $ldap_user --firstname $ldap_user --lastname $ldap_user --mail ${ldap_user}@$domain --password $ldap_password -q 0
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
|
|
|
@ -125,7 +125,7 @@ sleep 30
|
|||
#=================================================
|
||||
ynh_print_info --message="Creating LDAP user..."
|
||||
|
||||
yunohost user create $ldap_user --firstname $app --lastname $app --mail ${ldap_user}@$domain --password $ldap_password -q 0
|
||||
yunohost user create $ldap_user --firstname $ldap_user --lastname $ldap_user --mail ${ldap_user}@$domain --password $ldap_password -q 0
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
|
|
|
@ -63,7 +63,7 @@ fi
|
|||
|
||||
# If ldap_user doesn't exist, retrieve it or create it
|
||||
if [[ -z "$ldap_user" ]]; then
|
||||
ldap_user="${app}_ldap"
|
||||
ldap_user=$(ynh_sanitize_name --name="${app}ldap")
|
||||
ldap_password=$(ynh_string_random --length=8)
|
||||
ynh_app_setting_set "$app" ldap_user "$ldap_user"
|
||||
ynh_app_setting_set "$app" ldap_password "$ldap_password"
|
||||
|
|
20
scripts/ynh_sanitize_name
Normal file
20
scripts/ynh_sanitize_name
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Sanitize a string intended to be the firstname lastname
|
||||
# (More specifically : removing - . and _)
|
||||
#
|
||||
# example: username=$(ynh_sanitize_name --name=$app)
|
||||
#
|
||||
# usage: ynh_sanitize_name --name=name
|
||||
# | arg: -n, --name - name to correct/sanitize
|
||||
# | ret: the corrected name
|
||||
#
|
||||
ynh_sanitize_name () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=n
|
||||
declare -Ar args_array=( [n]=name= )
|
||||
local name
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
# We should avoid having - and . in the name of databases. They are replaced by _
|
||||
echo ${name//[-._]/}
|
||||
}
|
Loading…
Add table
Reference in a new issue