1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/privatebin_ynh.git synced 2024-09-03 20:15:56 +02:00

[fix] is_public boolean && add nginx configuration helper

This commit is contained in:
magikcypress 2017-05-20 19:40:39 +02:00
parent 37ce42d372
commit dd41ade2ba
No known key found for this signature in database
GPG key ID: 3B3C7CD61957AC9A
6 changed files with 59 additions and 28 deletions

View file

@ -1,5 +1,5 @@
location YNH_WWW_PATH {
alias YNH_WWW_ALIAS ;
location __PATH__ {
alias __FINALPATH__;
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
@ -7,7 +7,7 @@ location YNH_WWW_PATH {
try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REMOTE_USER $remote_user;
@ -16,5 +16,5 @@ location YNH_WWW_PATH {
}
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
# include conf.d/yunohost_panel.conf.inc;
}

View file

@ -43,12 +43,12 @@
},
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Is it a public Zerobin site ?",
"fr": "Est-ce un site public ?"
},
"choices": ["Yes", "No"],
"default": "Yes"
"default": "true"
}
]
}

View file

@ -22,7 +22,7 @@ ynh_store_checksum_config () {
ynh_app_setting_set $app $config_file_checksum $(sudo md5sum "$1" | cut -d' ' -f1)
}
extract_source() {
extract_source () {
local DESTDIR=$1
# retrieve and extract Roundcube tarball
@ -36,6 +36,41 @@ extract_source() {
sudo rm "$rc_tarball"
}
# Add config nginx
ynh_nginx_config () {
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_compare_checksum_config "$finalnginxconf" 1
sudo cp ../conf/nginx.conf "$finalnginxconf"
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
# Substitute in a nginx config file only if the variable is not empty
if test -n "${path:-}"; then
ynh_substitute_char "__PATH__" "$path" "$finalnginxconf"
fi
if test -n "${domain:-}"; then
ynh_substitute_char "__DOMAIN__" "$domain" "$finalnginxconf"
fi
if test -n "${port:-}"; then
ynh_substitute_char "__PORT__" "$port" "$finalnginxconf"
fi
if test -n "${app:-}"; then
ynh_substitute_char "__NAME__" "$app" "$finalnginxconf"
fi
if test -n "${final_path:-}"; then
ynh_substitute_char "__FINALPATH__" "$final_path" "$finalnginxconf"
fi
ynh_store_checksum_config "$finalnginxconf"
sudo systemctl reload nginx
}
# Remove config nginx
ynh_remove_nginx_config () {
ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo systemctl reload nginx
}
ynh_fpm_config () {
finalphpconf="/etc/php5/fpm/pool.d/$app.conf"
ynh_compare_checksum_config "$finalphpconf" 1

View file

@ -42,20 +42,15 @@ sudo chown -R $app:root $final_path/{data,tmp}
sudo chmod 700 $final_path/{data,tmp}
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
sudo cp ../conf/nginx.conf $nginxconf
sudo chown root: $nginxconf
sudo chmod 600 $nginxconf
ynh_nginx_config
# Create the php-fpm pool config
ynh_fpm_config
# Set ssowat config
if [ "$is_public" = "No" ];
then
ynh_app_setting_delete $app skipped_uris
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
fi
sudo systemctl reload nginx

View file

@ -61,9 +61,13 @@ sudo chown -R root:root $final_path
sudo chown -R www-data:root $final_path/{data,tmp}
sudo chmod -R 700 $final_path/{data,tmp}
# Restore configuration files
# Restore nginx configuration files
sudo cp -a ./conf/nginx.conf "${nginx_conf}"
# Restore php-fpm configuration files
sudo cp -a ./conf/php-fpm.conf "${phpfpm_conf}"
sudo cp -a ./conf/php-fpm.ini "${phpfpm_ini}"
# Set ssowat config
if [ "$is_public" = "No" ];
then

View file

@ -57,21 +57,18 @@ sudo chown -R $app:root $final_path/{data,tmp}
sudo chmod 700 $final_path/{data,tmp}
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
sudo cp ../conf/nginx.conf $nginxconf
sudo chown root: $nginxconf
sudo chmod 600 $nginxconf
ynh_nginx_config
# Create the php-fpm pool config
ynh_fpm_config
# Set ssowat config
ynh_app_setting_set "$app" is_public "$is_public"
if [ "$is_public" = "Yes" ];
then
ynh_app_setting_set "$app" unprotected_uris "/"
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen
is_public=1
else
ynh_app_setting_set $app is_public 0
is_public=0
fi
# Reload Nginx