diff --git a/conf/config.yaml b/conf/config.yaml index a6afd92..6213d48 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -1,5 +1,5 @@ bind-addr: 127.0.0.1:__PORT__ -auth: "none" +auth: none cert: false disable-telemetry: true disable-update-check: true diff --git a/config_panel.toml b/config_panel.toml index 36842f6..e3c7d8a 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -10,6 +10,21 @@ version = "1.0" name = "Main configuration" services = ["__APP__"] + [main.auth] + name = "Authentication" + + [main.auth.type] + ask = "Auth type" + type = "select" + choices = ["none", "password"] + default = "none" + bind: ":/opt/yunohost/__APP__/config.yaml" + + [main.auth.password] + ask = "Password" + type = "password" + visible = "main.auth.type == 'password'" + [main.extensions] name = "Extensions" optional = false diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..6e1a499 --- /dev/null +++ b/scripts/config @@ -0,0 +1,48 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +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 +#================================================= + +get__password() { + echo YNH_NULL +} + +#================================================= +# SPECIFIC VALIDATORS FOR TOML SHORT KEYS +#================================================= + +#================================================= +# SPECIFIC SETTERS FOR TOML SHORT KEYS +#================================================= + +set__password() { + hashed_password="$(printf "$password" | sha256sum | cut -d' ' -f1)" + + sed -i "/hashed-password:.*/d" "$final_path/config.py" + + echo "hashed-password: $hashed_password" >> "$final_path/config.py" + + ynh_app_setting_set $app hashed_password $hashed_password +} + +#================================================= +# GENERIC FINALIZATION +#================================================= +ynh_app_config_run $1 diff --git a/scripts/upgrade b/scripts/upgrade index d4b8201..009b88e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,6 +21,8 @@ admin=$(ynh_app_setting_get --app=$app --key=admin) port=$(ynh_app_setting_get --app=$app --key=port) final_path=$(ynh_app_setting_get --app=$app --key=final_path) datadir=$(ynh_app_setting_get --app=$app --key=datadir) +auth_type=$(ynh_app_setting_get --app=$app --key=auth_type) +hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password) #================================================= # CHECK VERSION @@ -116,6 +118,11 @@ ynh_script_progression --message="Updating a configuration file..." --time --wei ynh_add_config --template="config.yaml" --destination="$final_path/config.yaml" +if [ $auth == "password" ] +then + echo "hashed-password: $hashed_password" >> "$final_path/config.py" +fi + chmod 440 "$final_path/config.yaml" chown root:$admin "$final_path/config.yaml"