diff --git a/README.md b/README.md index 33722bb..df792f6 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in Flow-based programming for the Internet of Things -**Shipped version:** 1.3.5 +**Shipped version:** 1.3.5~ynh1 @@ -38,6 +38,7 @@ Flow-based programming for the Internet of Things * YunoHost's permissions system enables to select which users can have access to Node-RED. Upon installation, the selected administrator is the sole user to have access. * A `ui` permission is available in case you install the `node-red-dashboard` nodes. It makes the dashboard accessible to any authorized user or visitor, at `/ui` under Node-RED's address. +* A `nodes` permission is available in case you need to use the HTTP nodes. By default, visitors have access to these endpoints at `/red-nodes/...` under Node-RED's address. diff --git a/README_fr.md b/README_fr.md index 2f1ee1e..0de65e5 100644 --- a/README_fr.md +++ b/README_fr.md @@ -30,6 +30,8 @@ Programmation par flux de données pour l'Internet des objets * Le système de permissions de YunoHost permet de paramétrer les accès à Node-RED. Par défaut, seul l'administrateur sélectionné lors de l'installation y a accès. * Une permission `ui` est diponible au cas où vous installeriez les nodes de `node-red-dashboard`. Elle donne accès au tableau de bord à tout utilisateur ou visiteur autorisé, au chemin `/ui` après l'adresse spécifiée pour Node-RED. +* Une permission `nodes` est disponible au cas où vous utiliseriez les nodes HTTP. Par défaut, les visiteurs auront accès à ces nodes, au chemin `/red-nodes/...` après l'adresse spécifiée pour Node-RED. + diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md index 5b17396..1c57e41 100644 --- a/doc/DISCLAIMER.md +++ b/doc/DISCLAIMER.md @@ -1,2 +1,3 @@ * YunoHost's permissions system enables to select which users can have access to Node-RED. Upon installation, the selected administrator is the sole user to have access. * A `ui` permission is available in case you install the `node-red-dashboard` nodes. It makes the dashboard accessible to any authorized user or visitor, at `/ui` under Node-RED's address. +* A `nodes` permission is available in case you need to use the HTTP nodes. By default, visitors have access to these endpoints at `/red-nodes/...` under Node-RED's address. diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md index 7391c45..8e10ddf 100644 --- a/doc/DISCLAIMER_fr.md +++ b/doc/DISCLAIMER_fr.md @@ -1,2 +1,4 @@ * Le système de permissions de YunoHost permet de paramétrer les accès à Node-RED. Par défaut, seul l'administrateur sélectionné lors de l'installation y a accès. * Une permission `ui` est diponible au cas où vous installeriez les nodes de `node-red-dashboard`. Elle donne accès au tableau de bord à tout utilisateur ou visiteur autorisé, au chemin `/ui` après l'adresse spécifiée pour Node-RED. +* Une permission `nodes` est disponible au cas où vous utiliseriez les nodes HTTP. Par défaut, les visiteurs auront accès à ces nodes, au chemin `/red-nodes/...` après l'adresse spécifiée pour Node-RED. + diff --git a/scripts/install b/scripts/install index a214e20..1d32ebd 100755 --- a/scripts/install +++ b/scripts/install @@ -25,6 +25,13 @@ path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN app=$YNH_APP_INSTANCE_NAME +if [ $path_url = "/" ] +then + nodes_url="/red-nodes" +else + nodes_url="$path_url/red-nodes" +fi + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -103,7 +110,14 @@ ynh_add_nginx_config #================================================= mkdir -p $final_path/data cp $final_path/settings.js $final_path/data/settings.js -ynh_replace_string --match_string="//httpRoot: '/red'," --replace_string="httpRoot: '$path_url'," --target_file="$final_path/data/settings.js" + +# Set editor path +ynh_replace_string --match_string="//httpAdminRoot: '/admin'," --replace_string="httpAdminRoot: '$path_url'," --target_file="$final_path/data/settings.js" + +# Set nodes endpoints path +ynh_replace_string --match_string="//httpNodeRoot: '/red-nodes'," --replace_string="httpNodeRoot: '$nodes_url'," --target_file="$final_path/data/settings.js" + +# Set dashboard path ynh_replace_string --match_string="//ui: { path: "ui" }," --replace_string="ui: { path: "/ui/" }," --target_file="$final_path/data/settings.js" #================================================= @@ -156,7 +170,8 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap ynh_script_progression --message="Configuring permissions..." --weight=1 ynh_permission_update --permission="main" --remove="all_users" --add="$admin" -ynh_permission_create --permission="ui" --url="/ui" --allowed="$admin" +ynh_permission_create --permission="nodes" --url="$nodes_path" --allowed="visitors" --label="nodes endpoints" +ynh_permission_create --permission="ui" --url="/ui" --allowed="$admin" --label="dashboard" #================================================= # RELOAD NGINX diff --git a/scripts/upgrade b/scripts/upgrade index 12e2791..41ba26f 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,12 +21,33 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) +if [ $path_url = "/" ] +then + nodes_url="/red-nodes/" +else + nodes_url="$path_url/red-nodes/" +fi + #================================================= # CHECK VERSION #================================================= upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up Node-RED before upgrading (may take a while)..." --weight=1 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -45,19 +66,15 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up Node-RED before upgrading (may take a while)..." --weight=1 +if ! ynh_permission_exists --permission="nodes"; then + # Create the required permissions + ynh_permission_create --permission="nodes" --url="$nodes_path" --allowed="visitors" --label="nodes endpoints" +fi -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +if ! ynh_permission_exists --permission="ui"; then + # Create the required permissions + ynh_permission_create --permission="ui" --url="/ui" --label="dashboard" +fi #================================================= # CLOSING PORT @@ -132,7 +149,17 @@ ynh_add_nginx_config if [ ! -f $final_path/data/settings.js ]; then cp $final_path/settings.js $final_path/data/settings.js fi -ynh_replace_string --match_string="//httpRoot: '/red'," --replace_string="httpRoot: '$path_url'," --target_file="$final_path/data/settings.js" + +# Disable httpRoot from older installs +ynh_replace_string --match_string="httpRoot: '$path_url'," --replace_string="//httpRoot: '/'," --target_file="$final_path/data/settings.js" + +# Set editor path +ynh_replace_string --match_string="//httpAdminRoot: '/admin'," --replace_string="httpAdminRoot: '$path_url'," --target_file="$final_path/data/settings.js" + +# Set nodes endpoints path +ynh_replace_string --match_string="//httpNodeRoot: '/red-nodes'," --replace_string="httpNodeRoot: '$nodes_url'," --target_file="$final_path/data/settings.js" + +# Set dashboard path ynh_replace_string --match_string="//ui: { path: "ui" }," --replace_string="ui: { path: "/ui/" }," --target_file="$final_path/data/settings.js" #=================================================