1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dotclear2_ynh.git synced 2024-09-03 18:26:29 +02:00
This commit is contained in:
tituspijean 2023-10-30 09:24:59 +01:00 committed by GitHub
commit af8b8a9fda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 31 deletions

View file

@ -16,6 +16,7 @@ location __PATH__/ {
fastcgi_index index.php; fastcgi_index index.php;
include fastcgi_params; include fastcgi_params;
fastcgi_param DC_BLOG_ID __BLOG_ID__;
fastcgi_param REMOTE_USER $remote_user; fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_param SCRIPT_FILENAME $request_filename;

View file

@ -103,3 +103,26 @@ help = "These permissions apply to the first connection of the user, the super u
yes = "true" yes = "true"
no = "false" no = "false"
bind = "'blogroll':__INSTALL_DIR__/inc/class.auth.ldap.php" bind = "'blogroll':__INSTALL_DIR__/inc/class.auth.ldap.php"
[blogs]
name = "Multiple blogs management"
[blogs.blogs]
name = ""
[blogs.blogs.info]
type = "alert"
style = "info"
ask = "Here you can instruct YunoHost to handle multiple blogs. It will create the appropriate permissions and NGINX configuration files.\n You still need to add them in Dotclear's administration panel. Removing them here will not delete them from Dotclear, and vice-versa."
[blogs.blogs.blogs_list]
ask = "List of blogs"
type = "tags"
pattern.regexp = "[\\w]+@[\\w.]+\\/[\\w]*"
pattern.error = "Incorrect format. Use `id@domain.example/path`"
help = """\
- The `default` blog cannot be deleted and will be put back in the list. Use the usual Change URL method to move it to a new URL.\n\
- Additional blogs must be declared with the format `id@domain.example/path`.
Each blog will have two permissions for main and admin access. By default the former has "visitors and all_users" access and the latter has "admins" group access.
Keeping the same `id` but changing the domain or path will keep the permission but reset the NGINX configuration file to the new location.
"""

View file

@ -16,6 +16,9 @@ ynh_abort_if_errors
install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
admin=$(ynh_app_setting_get --app=$app --key=admin) admin=$(ynh_app_setting_get --app=$app --key=admin)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path=$(ynh_app_setting_get --app=$app --key=path)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#================================================= #=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS # SPECIFIC SETTERS FOR TOML SHORT KEYS
@ -25,13 +28,15 @@ set__blogs_list() {
declare -A domain_array declare -A domain_array
declare -A path_array declare -A path_array
default_present=false
for blog in $(echo $blogs_list | sed "s/,/ /"); do for blog in $(echo $blogs_list | sed "s/,/ /"); do
id=$(echo $blog | cut -d@ -f1) id=$(echo $blog | cut -d@ -f1)
domain=$(echo $blog | cut -d@ -f2 | cut -d/ -f1) d=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
path="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)" p="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
[ $id = "default" ] && default_present=true
domain_array+=([$id]=$domain) domain_array+=([$id]=$d)
path_array+=([$id]=$path) path_array+=([$id]=$p)
done done
declare -A old_domain_array declare -A old_domain_array
@ -39,43 +44,65 @@ set__blogs_list() {
for blog in $(echo ${old[blogs_list]} | sed "s/,/ /"); do for blog in $(echo ${old[blogs_list]} | sed "s/,/ /"); do
id=$(echo $blog | cut -d@ -f1) id=$(echo $blog | cut -d@ -f1)
domain=$(echo $blog | cut -d@ -f2 | cut -d/ -f1) d=$(echo $blog | cut -d@ -f2 | cut -d/ -f1)
path="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)" p="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)"
old_domain_array+=([$id]=$domain) old_domain_array+=([$id]=$d)
old_path_array+=([$id]=$path) old_path_array+=([$id]=$p)
done done
# Make sure the default blog is always listed
domain_array+=(["default"]=$domain)
path_array+=(["default"]=$path)
old_domain_array+=(["default"]=$domain)
old_path_array+=(["default"]=$path)
if [ $default_present = false ]; then
if [ -z ${blogs_list:-} ]; then
blogs_list="default@$domain$path"
else
blogs_list+=",default@$domain$path"
fi
fi
# https://stackoverflow.com/questions/2312762/compare-difference-of-two-arrays-in-bash # https://stackoverflow.com/questions/2312762/compare-difference-of-two-arrays-in-bash
# Get added and removed blogs # Get added and removed blogs
added_ids_array=(`echo ${!domain_array[@]} ${!old_domain_array[@]} | tr ' ' '\n' | sort | uniq -u `) difference_ids_array=(`echo ${!domain_array[@]} ${!old_domain_array[@]} | tr ' ' '\n' | sort | uniq -u `)
removed_ids_array=(`echo ${!old_domain_array[@]} $!domain_array[@]} | tr ' ' '\n' | sort | uniq -D | uniq `) added_ids_array=(`echo ${!domain_array[@]} ${difference_ids_array[@]} | tr ' ' '\n' | sort | uniq -D | uniq `)
removed_ids_array=(`echo ${!old_domain_array[@]} ${difference_ids_array[@]} | tr ' ' '\n' | sort | uniq -D | uniq `)
for id in $removed_ids_array; do ynh_print_info --message="Added blogs: ${added_ids_array[@]}"
if [ ynh_permission_exists --permission="$id" ]; then ynh_print_info --message="Removed blogs: ${removed_ids_array[@]}"
ynh_permission_delete --permission="$id"
for id in ${removed_ids_array[@]}; do
if [ $id != "default" ]; then
if ynh_permission_exists --permission="$id"; then
ynh_permission_delete --permission="$id"
fi
if ynh_permission_exists --permission="${id}-admin"; then
ynh_permission_delete --permission="${id}-admin"
fi
ynh_secure_remove --file="/etc/nginx/conf.d/${old_domain_array[$id]}.d/$app-$id.conf"
fi fi
ynh_secure_remove --file="/etc/nginx/conf.d/${old_domain_array[$id]}.d/$app.conf"
done done
for id in $domain_array; do for id in ${!domain_array[@]}; do
if [ $id != "default" ]; then
if [ $domain_array[$id] != $old_domain_array[$id] ]; then if [ "${domain_array[$id]:-}" != "${old_domain_array[$id]:-}" ] ||
mv /etc/nginx/conf.d/${old_domain_array[$id]}.d/$app.conf /etc/nginx/conf.d/${domain_array[$id]}.d/$app.conf [ "${path_array[$id]:-}" != "${old_path_array[$id]:-}" ]; then
fi domain=${domain_array[$id]}
path=${path_array[$id]}
if [ $path_array[$id] != $old_path_array[$id] ]; then blog_id=$id
domain=$domain_array[$id] [ ! -z ${old_domain_array[$id]:-} ] && ynh_secure_remove --file="/etc/nginx/conf.d/${old_domain_array[$id]}.d/$app-$id.conf"
path=$path_array[$id] ynh_add_config --template="nginx.conf" --destination="/etc/nginx/conf.d/${domain_array[$id]}.d/$app-$id.conf"
ynh_add_config --template="nginx.conf" --destination="/etc/nginx/conf.d/${domain_array[$id]}.d/$app.conf" fi
fi
if [ ynh_permission_exists --permission="$id" ]; then if ynh_permission_exists --permission="$id"; then
ynh_permission_url --permission="$id" --url="$domain_array[$id]$path_array[$id]" ynh_permission_url --permission="$id" --url="${domain_array[$id]}${path_array[$id]}"
ynh_permission_url --permission="$id.admin" --url="$domain_array[$id]$path_array[$id]/admin" ynh_permission_url --permission="${id}-admin" --url="${domain_array[$id]}${path_array[$id]}/admin"
else else
ynh_permission_create --permission="$id" --url="$domain_array[$id]$path_array[$id]" ynh_permission_create --permission="$id" --url="${domain_array[$id]}${path_array[$id]}" --show_tile=true --allowed=visitors all_users
ynh_permission_create --permission="$id.admin" --url="$domain_array[$id]$path_array[$id]/admin" ynh_permission_create --permission="${id}-admin" --url="${domain_array[$id]}${path_array[$id]}/admin" --show_tile=false --allowed=admins
fi
fi fi
done done

View file

@ -131,6 +131,9 @@ installUrl="/admin/install/index.php"
ynh_local_curl $installUrl "u_email=$email" "u_firstname=$firstname" "u_name=$lastname" "u_login=$admin" "u_pwd=$password" "u_pwd2=$password" ynh_local_curl $installUrl "u_email=$email" "u_firstname=$firstname" "u_name=$lastname" "u_login=$admin" "u_pwd=$password" "u_pwd2=$password"
# Initializing blogs_list (excluding default)
ynh_app_setting_set --app=$app --key=blogs_list --value="default@$domain$path"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================

View file

@ -55,6 +55,11 @@ if [ -z "${blog_admin:-}" ] ||
ynh_app_setting_set --app=$app --key=blog_blogroll --value=$blog_blogroll ynh_app_setting_set --app=$app --key=blog_blogroll --value=$blog_blogroll
fi fi
if [ -z "$blogs_list" ]; then
# Initializing blogs_list (excluding default)
ynh_app_setting_set --app=$app --key=blogs_list --value="default@$domain$path"
fi
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================