mirror of
https://github.com/YunoHost-Apps/reverseproxy_ynh.git
synced 2024-09-03 20:16:23 +02:00
Initial commit.
This commit is contained in:
commit
253310b8f8
10 changed files with 364 additions and 0 deletions
25
README.md
Normal file
25
README.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Redirect App
|
||||
|
||||
Create redirect and add a link on user panel. Add a simple Nginx configuration
|
||||
file with `redirect` or `proxy_pass` rule. Nothing more.
|
||||
|
||||
## Redirect type
|
||||
|
||||
### Visible redirect
|
||||
|
||||
Visitor's address bar will change. Helpfull to add a user link to another
|
||||
website
|
||||
|
||||
you-domain.com -> another-domain.net
|
||||
you-domain.com/foo -> another-domain.net/bar
|
||||
|
||||
## Invisible (proxy) redirect
|
||||
|
||||
Visitor's address bar will remain the same. Mostly use to serve local webserver
|
||||
for a personnal application.
|
||||
|
||||
you-domain.com/foo -> http://172.0.0.1:8080/app
|
||||
|
||||
## Credits
|
||||
|
||||
Insprired by [scith](https://github.com/scith) work.
|
13
conf/nginx-proxy.conf
Normal file
13
conf/nginx-proxy.conf
Normal file
|
@ -0,0 +1,13 @@
|
|||
location YNH_LOCATION {
|
||||
proxy_pass YNH_REDIRECT_PATH;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Host $server_name;
|
||||
|
||||
# Include SSOWAT user panel.
|
||||
include conf.d/yunohost_panel.conf.inc;
|
||||
more_clear_input_headers 'Accept-Encoding';
|
||||
}
|
3
conf/nginx-visible-301.conf
Normal file
3
conf/nginx-visible-301.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
location YNH_LOCATION {
|
||||
return 301 YNH_REDIRECT_PATH;
|
||||
}
|
3
conf/nginx-visible-302.conf
Normal file
3
conf/nginx-visible-302.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
location YNH_LOCATION {
|
||||
return 302 YNH_REDIRECT_PATH;
|
||||
}
|
74
manifest.json
Normal file
74
manifest.json
Normal file
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"name": "Redirect",
|
||||
"id": "redirect",
|
||||
"packaging_format": 1,
|
||||
"requirements": {
|
||||
"yunohost": ">= 2.4"
|
||||
},
|
||||
"description": {
|
||||
"en": "Create a redirection or a proxy to another path.",
|
||||
"fr": "Créer une redirection ou un proxy vers un autre emplacement"
|
||||
},
|
||||
"maintainer": {
|
||||
"name": "opi",
|
||||
"email": "opi@zeropi.net"
|
||||
},
|
||||
"multi_instance": "true",
|
||||
"services": [
|
||||
"nginx"
|
||||
],
|
||||
"arguments": {
|
||||
"install" : [
|
||||
{
|
||||
"name": "domain",
|
||||
"type": "domain",
|
||||
"ask": {
|
||||
"en": "Choose a domain for your redirect",
|
||||
"fr": "Choisissez un domaine pour votre redirection"
|
||||
},
|
||||
"example": "domain.org"
|
||||
},
|
||||
{
|
||||
"name": "path",
|
||||
"type": "path",
|
||||
"ask": {
|
||||
"en": "Choose a path for your redirect",
|
||||
"fr": "Choisissez un chemin pour votre redirection"
|
||||
},
|
||||
"example": "/redirect",
|
||||
"default": "/redirect"
|
||||
},
|
||||
{
|
||||
"name": "redirect_path",
|
||||
"ask": {
|
||||
"en": "Redirect destination path",
|
||||
"fr": "Emplacement de destination"
|
||||
},
|
||||
"example": "http://127.0.0.1:8080/app/",
|
||||
"default": "http://127.0.0.1"
|
||||
},
|
||||
{
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Is it a public redirect ?",
|
||||
"fr": "Est-ce une redirection publique ?"
|
||||
},
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"name": "redirect_type",
|
||||
"ask": {
|
||||
"en": "Redirect type",
|
||||
"fr": "Type de redirection"
|
||||
},
|
||||
"choices": {
|
||||
"visible_302" : "Visible (302 redirect)",
|
||||
"visible_301" : "Visible (301 redirect)",
|
||||
"proxy": "Proxy, invisible (Nginx proxy_pass)"
|
||||
},
|
||||
"default": "visible_302"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
26
scripts/backup
Normal file
26
scripts/backup
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
|
||||
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
||||
set -e
|
||||
|
||||
# Source YNH helpers
|
||||
. /usr/share/yunohost/helpers
|
||||
|
||||
# This is a multi-instance app, meaning it can be installed several times independently
|
||||
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
||||
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
||||
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
||||
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
||||
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
||||
# The app instance name is probably what you are interested the most, since this is
|
||||
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
||||
# db names, ...
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$(sudo yunohost app setting $app domain)
|
||||
|
||||
# Copy the conf files
|
||||
sudo mkdir -p ./conf
|
||||
sudo cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./conf/nginx.conf
|
71
scripts/install
Normal file
71
scripts/install
Normal file
|
@ -0,0 +1,71 @@
|
|||
#!/bin/bash
|
||||
|
||||
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
||||
set -ue
|
||||
|
||||
# Source app helpers
|
||||
. /usr/share/yunohost/helpers
|
||||
|
||||
# This is a multi-instance app, meaning it can be installed several times independently
|
||||
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
||||
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
||||
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
||||
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
||||
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
||||
# The app instance name is probably what you are interested the most, since this is
|
||||
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
||||
# db names, ...
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path=$YNH_APP_ARG_PATH
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
redirect_type=$YNH_APP_ARG_REDIRECT_TYPE
|
||||
redirect_path=$YNH_APP_ARG_REDIRECT_PATH
|
||||
|
||||
# Remove trailing slash to path
|
||||
path=${path%/}
|
||||
#force location to be / or /foo
|
||||
location=${path:-/}
|
||||
|
||||
# Check domain/path availability
|
||||
sudo yunohost app checkurl $domain$path -a $app \
|
||||
|| (echo "Path not available: $domain$path" && exit 1)
|
||||
|
||||
# Validate redirect path
|
||||
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
||||
[[ ! $redirect_path =~ $url_regex ]] && ynh_die \
|
||||
"Invalid destination: $redirect_path" 1
|
||||
|
||||
# Save extra settings
|
||||
sudo yunohost app setting $app is_public -v "$is_public"
|
||||
sudo yunohost app setting $app redirect_type -v "$redirect_type"
|
||||
sudo yunohost app setting $app redirect_path -v "$redirect_path"
|
||||
|
||||
# Nginx configuration
|
||||
sed -i "s@YNH_LOCATION@$location@g" ../conf/nginx-*.conf
|
||||
if [ "$redirect_type" = "visible_302" ];
|
||||
then
|
||||
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-302.conf
|
||||
sudo cp ../conf/nginx-visible-302.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
elif [ "$redirect_type" = "visible_301" ];
|
||||
then
|
||||
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-301.conf
|
||||
sudo cp ../conf/nginx-visible-301.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
elif [ "$redirect_type" = "proxy" ];
|
||||
then
|
||||
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-proxy.conf
|
||||
sudo cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
fi
|
||||
|
||||
# Make app public if necessary
|
||||
if [[ "$is_public" -ne 0 ]];
|
||||
then
|
||||
sudo yunohost app setting $app unprotected_uris -v "/"
|
||||
fi
|
||||
|
||||
# Reload Nginx and regenerate SSOwat conf
|
||||
sudo service nginx reload
|
||||
sudo yunohost app ssowatconf
|
26
scripts/remove
Normal file
26
scripts/remove
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
|
||||
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
||||
set -e
|
||||
|
||||
# This is a multi-instance app, meaning it can be installed several times independently
|
||||
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
||||
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
||||
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
||||
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
||||
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
||||
# The app instance name is probably what you are interested the most, since this is
|
||||
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
||||
# db names, ...
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$(sudo yunohost app setting $app domain)
|
||||
|
||||
# Remove configuration files
|
||||
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
|
||||
# Restart services
|
||||
sudo service nginx reload
|
||||
sudo yunohost app ssowatconf
|
57
scripts/restore
Normal file
57
scripts/restore
Normal file
|
@ -0,0 +1,57 @@
|
|||
#!/bin/bash
|
||||
|
||||
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
||||
set -e
|
||||
|
||||
# Source YNH helpers
|
||||
. /usr/share/yunohost/helpers
|
||||
|
||||
# This is a multi-instance app, meaning it can be installed several times independently
|
||||
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
||||
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
||||
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
||||
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
||||
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
||||
# The app instance name is probably what you are interested the most, since this is
|
||||
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
||||
# db names, ...
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
redirect_type=$(ynh_app_setting_get "$app" redirect_type)
|
||||
redirect_path=$(ynh_app_setting_get "$app" redirect_path)
|
||||
|
||||
# Remove trailing slash to path
|
||||
path=${path%/}
|
||||
|
||||
# Check domain/path availability
|
||||
sudo yunohost app checkurl $domain$path -a $app \
|
||||
|| die "The path ${domain}${path} is not available for app installation."
|
||||
|
||||
# Validate redirect path
|
||||
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
||||
[[ ! $redirect_path =~ $url_regex ]] && ynh_die \
|
||||
"Invalid destination: $redirect_path" 1
|
||||
|
||||
# Check configuration files
|
||||
NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
[[ -f $NGINX_CONF ]] && die \
|
||||
"The NGINX configuration already exists at '${NGINX_CONF}'.
|
||||
You should safely delete it before restoring this app."
|
||||
|
||||
# Restore configuration files
|
||||
sudo cp -a ./conf/nginx.conf "$NGINX_CONF"
|
||||
|
||||
# Make app public if necessary
|
||||
if [[ "$is_public" -ne 0 ]];
|
||||
then
|
||||
sudo yunohost app setting $app unprotected_uris -v "/"
|
||||
fi
|
||||
|
||||
# Reload Nginx and regenerate SSOwat conf
|
||||
sudo service nginx reload
|
||||
sudo yunohost app ssowatconf
|
66
scripts/upgrade
Normal file
66
scripts/upgrade
Normal file
|
@ -0,0 +1,66 @@
|
|||
#!/bin/bash
|
||||
|
||||
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
||||
set -e
|
||||
|
||||
# This is a multi-instance app, meaning it can be installed several times independently
|
||||
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
||||
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
||||
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
||||
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
||||
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
||||
# The app instance name is probably what you are interested the most, since this is
|
||||
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
||||
# db names, ...
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source app helpers
|
||||
. /usr/share/yunohost/helpers
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
redirect_type=$(ynh_app_setting_get "$app" redirect_type)
|
||||
redirect_path=$(ynh_app_setting_get "$app" redirect_path)
|
||||
|
||||
# Remove trailing slash to path
|
||||
path=${path%/}
|
||||
#force location to be / or /foo
|
||||
location=${path:-/}
|
||||
|
||||
# Check domain/path availability
|
||||
sudo yunohost app checkurl $domain$path -a $app \
|
||||
|| (echo "Path not available: $domain$path" && exit 1)
|
||||
|
||||
# Validate redirect path
|
||||
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
||||
[[ ! $redirect_path =~ $url_regex ]] && ynh_die \
|
||||
"Invalid destination: $redirect_path" 1
|
||||
|
||||
# Nginx configuration
|
||||
sed -i "s@YNH_LOCATION@$location@g" ../conf/nginx-*.conf
|
||||
if [ "$redirect_type" = "visible_302" ];
|
||||
then
|
||||
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-302.conf
|
||||
sudo cp ../conf/nginx-visible-302.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
elif [ "$redirect_type" = "visible_301" ];
|
||||
then
|
||||
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-301.conf
|
||||
sudo cp ../conf/nginx-visible-301.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
elif [ "$redirect_type" = "proxy" ];
|
||||
then
|
||||
sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-proxy.conf
|
||||
sudo cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
fi
|
||||
|
||||
# Make app public if necessary
|
||||
if [[ "$is_public" -ne 0 ]];
|
||||
then
|
||||
sudo yunohost app setting $app unprotected_uris -v "/"
|
||||
fi
|
||||
|
||||
# Reload Nginx and regenerate SSOwat conf
|
||||
sudo service nginx reload
|
||||
sudo yunohost app ssowatconf
|
Loading…
Reference in a new issue