1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/baikal_ynh.git synced 2024-09-03 18:16:11 +02:00

add reset_admin_password action

This commit is contained in:
Kay0u 2020-09-15 16:09:15 +02:00
parent 04cb7942a8
commit f3530632ba
No known key found for this signature in database
GPG key ID: AAFEEB16CFA2AE2D
3 changed files with 70 additions and 0 deletions

View file

@ -46,6 +46,9 @@ this package:
## Additional information
* There is a breaking change in the management of the administrator password when upgrading to 0.7.0. You must change the admin password!
* To be able to change the admin password, please visit the page: `https://you.domain.tld/yunohost/admin/#/apps/baikal/actions` and set a new password.
## Links
* Report a bug: https://github.com/YunoHost-Apps/baikal_ynh/issues

10
actions.toml Normal file
View file

@ -0,0 +1,10 @@
[reset_admin_password]
name = "Reset the admin password"
command = "/bin/bash scripts/actions/reset_admin_password"
accepted_return_codes = [0]
description = "Change the admin password of the app."
[reset_admin_password.arguments]
[reset_admin_password.arguments.password]
type = "password"
ask.en = "Set the password for the administration"
ask.fr = "Définissez le mot de passe pour l'administration"

View file

@ -0,0 +1,57 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
# Get password
password=${YNH_ACTION_PASSWORD}
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# CHECK IF ARGUMENTS ARE CORRECT
#=================================================
#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
password_hash_old=$(ynh_app_setting_get --app=$app --key=password_hash)
password_hash=$(echo -n admin:BaikalDAV:$password | sha256sum | cut -d ' ' -f 1)
if [ $password_hash == $password_hash_old ]
then
ynh_die "This is the same password." 0
fi
#=================================================
# SPECIFIC ACTION
#=================================================
# CHANGE THE PASSWORD
#=================================================
ynh_script_progression --message="Changing the password..." --weight=1
bk_conf="${final_path}/config/baikal.yaml"
ynh_backup_if_checksum_is_different --file="${final_path}/config/baikal.yaml"
ynh_replace_string --match_string="${password_hash_old}" --replace_string="${password_hash}" --target_file="$bk_conf"
ynh_app_setting_set --app=$app --key=password_hash --value=$password_hash
ynh_store_file_checksum --file="${final_path}/config/baikal.yaml"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last