From 7987a544c4ee2b9177b11209a0c22a94a8938cb0 Mon Sep 17 00:00:00 2001 From: Kayou Date: Thu, 14 Feb 2019 23:41:28 +0100 Subject: [PATCH] add admin --- conf/lstu.conf.template | 2 +- manifest.json | 8 ++++++++ scripts/install | 4 ++++ scripts/upgrade | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/conf/lstu.conf.template b/conf/lstu.conf.template index 6796cb0..76d4a50 100644 --- a/conf/lstu.conf.template +++ b/conf/lstu.conf.template @@ -29,7 +29,7 @@ # secret hashed passphrase to access some admin features # Hash your password by issuing `echo -n s3cr3T | sha256sum` on your terminal # optional, but you won't have access to admin /stats if not set and if adminpwd is not set either - #hashed_adminpwd => '94b2feede6ea5e2eec62f457ecb7d3f719b24d19c29d4e5466246a31908fc23b', + hashed_adminpwd => '__PASSWORD_HASHED__', # choose a theme. See the available themes in `themes` directory # optional, default is 'default' diff --git a/manifest.json b/manifest.json index 9e6a229..bc6aabc 100644 --- a/manifest.json +++ b/manifest.json @@ -49,6 +49,14 @@ "fr": "Est-ce une application publique ?" }, "default": false + }, + { + "name": "password", + "type": "password", + "ask": { + "en": "Choose a password", + "fr": "Choisissez un mot de passe" + } } ] } diff --git a/scripts/install b/scripts/install index 9a54996..0c6e686 100644 --- a/scripts/install +++ b/scripts/install @@ -27,6 +27,7 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC +password=$YNH_APP_ARG_PASSWORD app=$YNH_APP_INSTANCE_NAME @@ -67,6 +68,8 @@ ynh_app_setting_set $app domain $domain ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app port $port ynh_app_setting_set $app path $path_url +hashed_password=$(echo $password | sha256sum $password) +ynh_app_setting_set $app hashed_password $hashed_password #================================================= # INSTALL DEPENDENCIES @@ -122,6 +125,7 @@ ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf" ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf" ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" +ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf" secret=$(ynh_string_random 24) ynh_app_setting_set $app secret $secret diff --git a/scripts/upgrade b/scripts/upgrade index 04c96c8..02aa89e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -35,6 +35,7 @@ secret=$(ynh_app_setting_get $app secret) db_name=$(ynh_app_setting_get $app db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get $app psqlpwd) +hashed_password=$(ynh_app_setting_get $app hashed_password) #================================================= # FIX OLD THINGS @@ -68,6 +69,19 @@ if [ -z "$db_pwd" ]; then fi fi +if [ -z "$hashed_password" ]; then + # Generate random password + password=$(openssl rand -hex 15) + hashed_password=$(echo $password | sha256sum $password) + ynh_app_setting_set $app hashed_password $hashed_password + + echo "The new version of LSTU provide an admin and a stats area which required a password. + + This password is: $password" > mail_to_send + + ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="admin" --type="upgrade" +fi + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -97,6 +111,7 @@ ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf" ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf" ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf" +ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf" ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf" ynh_store_file_checksum "${final_path}/lstu.conf"