This commit is contained in:
Éric Gaspar 2023-11-25 19:16:11 +01:00
parent a6bbb0d7cb
commit fc5f7521f2
9 changed files with 126 additions and 66 deletions

View file

@ -18,7 +18,7 @@ location @__NAME__--proxy {
# Support relative URLs
__REDIRECT_BLOCK__
location __PATH_URL_SLASH__ {
location __PATH_SLASH__ {
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;

60
manifest.toml Normal file
View file

@ -0,0 +1,60 @@
packaging_format = 2
id = "reverseproxy"
name = "Reverse Proxy"
description.en = "Create a reverse proxy to a socket/port, optionally serve static files from folder"
description.fr = "Créer un reverse proxy vers un socket/port, optionnellement servir des fichiers statiques depuis un dossier"
version = "0.2~ynh1"
maintainers = ["selfhoster1312"]
[upstream]
website = "https://en.wikipedia.org/wiki/Reverse_proxy"
license = "AGPL-3.0-or-later"
cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number)
fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin.
[integration]
yunohost = ">= 11.2"
architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"]
multi_instance = true
ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials.
sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal.
disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ...
ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
[install]
[install.domain]
# this is a generic question - ask strings are automatically handled by Yunohost's core
type = "domain"
[install.path]
# this is a generic question - ask strings are automatically handled by Yunohost's core
type = "path"
[install.proxy_path]
ask.en = "Redirect destination path (unix:/file for socket)"
ask.fr = "Emplacement de destination (unix:/fichier pour socket)"
type = "string"
example = "http://127.0.0.1:8080"
[install.init_main_permission]
type = "group"
default = false
[install.assets_path]
ask.en = "Static assets folder"
ask.fr = "Dossier pour les fichiers statiques"
type = "string"
optional = true
example = "/opt/foo/www/"
[resources]
[resources.system_user]
[resources.install_dir]
[resources.permissions]
main.url = "/"

View file

@ -47,14 +47,14 @@ rp_validate_assets_path() {
fi
}
# When the app is not in the webroot (path_url = /), need to add a redirect block
# When the app is not in the webroot (path = /), need to add a redirect block
# to app/ so relative URLs work
rp_handle_webroot() {
if [[ "$path_url" = "/" ]]; then
path_url_slash="/"
if [[ "$path" = "/" ]]; then
path_slash="/"
redirect_block="# Not needed for webroot"
else
path_url_slash=""$path_url"/"
redirect_block="location = "$path_url" { return 302 "$path_url_slash"; }"
path_slash=""$path"/"
redirect_block="location = "$path" { return 302 "$path_slash"; }"
fi
}

View file

@ -14,16 +14,16 @@ source /usr/share/yunohost/helpers
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
#REMOVEME? ynh_print_info --message="Loading installation settings..."
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
# BACKUP THE NGINX CONFIGURATION

View file

@ -14,17 +14,17 @@ source _common.sh
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
app=$YNH_APP_INSTANCE_NAME
old_domain=$YNH_APP_OLD_DOMAIN
new_domain=$YNH_APP_NEW_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_path=$YNH_APP_NEW_PATH
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN
#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN
#REMOVEME? old_path=$YNH_APP_OLD_PATH
#REMOVEME? new_path=$YNH_APP_NEW_PATH
# Path availability is already checked for
@ -34,11 +34,11 @@ new_path=$YNH_APP_NEW_PATH
# Nginx configuration
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
path_url="$new_path"
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
path="$new_path"
domain="$old_domain"
proxy_path="$(ynh_app_setting_get --app=$app --key=proxy_path)"
assets_path="$(ynh_app_setting_get --app=$app --key=assets_path)"
#REMOVEME? proxy_path="$(ynh_app_setting_get --app=$app --key=proxy_path)"
#REMOVEME? assets_path="$(ynh_app_setting_get --app=$app --key=assets_path)"
# Validate reverse proxy destination
rp_validate_proxy_path
@ -46,20 +46,20 @@ rp_validate_proxy_path
# Validate assets_path
rp_validate_assets_path
# Special case for "/" path_url
# Special case for "/" path
rp_handle_webroot
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
#REMOVEME? nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
ynh_add_nginx_config
#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
#REMOVEME? ynh_add_nginx_config
# Move file to new domain if domain has changed
if [[ "$old_domain" != "$new_domain" ]]; then
new_nginx_conf_path=/etc/nginx/conf.d/$new_domain.d/$app.conf
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path $new_nginx_conf_path
ynh_store_file_checksum --file="$new_nginx_conf_path"
#REMOVEME? if [[ "$old_domain" != "$new_domain" ]]; then
#REMOVEME? new_nginx_conf_path=/etc/nginx/conf.d/$new_domain.d/$app.conf
#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path"
#REMOVEME? mv $nginx_conf_path $new_nginx_conf_path
#REMOVEME? ynh_store_file_checksum --file="$new_nginx_conf_path"
fi

View file

@ -14,26 +14,26 @@ source /usr/share/yunohost/helpers
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
proxy_path=$YNH_APP_ARG_PROXY_PATH
assets_path=$YNH_APP_ARG_ASSETS_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$YNH_APP_ARG_DOMAIN
#REMOVEME? path=$YNH_APP_ARG_PATH
#REMOVEME? proxy_path=$YNH_APP_ARG_PROXY_PATH
#REMOVEME? assets_path=$YNH_APP_ARG_ASSETS_PATH
#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC
#=================================================
# REVERSEPROXY_YNH
#=================================================
# Check domain/path availability
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
# Validate reverse proxy destination
rp_validate_proxy_path
@ -41,22 +41,22 @@ rp_validate_proxy_path
# Validate assets_path
rp_validate_assets_path
# Special case for "/" path_url
# Special case for "/" path
rp_handle_webroot
# Save extra settings
ynh_app_setting_set --app=$app --key=proxy_path --value=$proxy_path
ynh_app_setting_set --app=$app --key=assets_path --value=$assets_path
#REMOVEME? ynh_app_setting_set --app=$app --key=proxy_path --value=$proxy_path
#REMOVEME? ynh_app_setting_set --app=$app --key=assets_path --value=$assets_path
# Configure nginx
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
ynh_add_nginx_config
# Make app public if necessary (yunohost setting boolean is 1 when true)
ynh_script_progression --message="Configuring permissions..." --weight=2
if [ $is_public -eq 1 ]; then
ynh_permission_update --permission="main" --add="visitors"
#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=2
#REMOVEME? if [ $is_public -eq 1 ]; then
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
fi
#=================================================

View file

@ -12,11 +12,11 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
# REVERSEPROXY_YNH
@ -26,8 +26,8 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf
# Reload nginx
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT

View file

@ -14,18 +14,18 @@ source /usr/share/yunohost/helpers
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
proxy_path=$(ynh_app_setting_get --app=$app --key=proxy_path)
assets_path=$(ynh_app_setting_get --app=$app --key=assets_path)
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? proxy_path=$(ynh_app_setting_get --app=$app --key=proxy_path)
#REMOVEME? assets_path=$(ynh_app_setting_get --app=$app --key=assets_path)
#=================================================
# REVERSEPROXY_YNH

View file

@ -15,24 +15,24 @@ source /usr/share/yunohost/helpers
#=================================================
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
proxy_path=$(ynh_app_setting_get --app=$app --key=proxy_path)
assets_path=$(ynh_app_setting_get --app=$app --key=assets_path)
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? proxy_path=$(ynh_app_setting_get --app=$app --key=proxy_path)
#REMOVEME? assets_path=$(ynh_app_setting_get --app=$app --key=assets_path)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# REVERSEPROXY_YNH
@ -44,12 +44,12 @@ rp_validate_proxy_path
# Validate assets_path
rp_validate_assets_path
# Special case for "/" path_url
# Special case for "/" path
rp_handle_webroot
# Configure nginx
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
ynh_add_nginx_config
#=================================================