diff --git a/conf/nginx.conf b/conf/nginx.conf index c5d0284..7046cac 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -16,6 +16,7 @@ location __PATH__/ { fastcgi_index index.php; include fastcgi_params; + fastcgi_param DC_BLOG_ID __BLOG_ID__; fastcgi_param REMOTE_USER $remote_user; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $request_filename; diff --git a/config_panel.toml b/config_panel.toml index 88867ad..c2c069d 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -103,3 +103,26 @@ help = "These permissions apply to the first connection of the user, the super u yes = "true" no = "false" 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. + """ diff --git a/scripts/config b/scripts/config index f6a09fa..d6bc1ad 100644 --- a/scripts/config +++ b/scripts/config @@ -16,6 +16,9 @@ ynh_abort_if_errors install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) 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 @@ -25,13 +28,15 @@ set__blogs_list() { declare -A domain_array declare -A path_array + default_present=false for blog in $(echo $blogs_list | sed "s/,/ /"); do id=$(echo $blog | cut -d@ -f1) - domain=$(echo $blog | cut -d@ -f2 | cut -d/ -f1) - path="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)" + d=$(echo $blog | cut -d@ -f2 | cut -d/ -f1) + p="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)" + [ $id = "default" ] && default_present=true - domain_array+=([$id]=$domain) - path_array+=([$id]=$path) + domain_array+=([$id]=$d) + path_array+=([$id]=$p) done declare -A old_domain_array @@ -39,43 +44,65 @@ set__blogs_list() { for blog in $(echo ${old[blogs_list]} | sed "s/,/ /"); do id=$(echo $blog | cut -d@ -f1) - domain=$(echo $blog | cut -d@ -f2 | cut -d/ -f1) - path="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)" + d=$(echo $blog | cut -d@ -f2 | cut -d/ -f1) + p="/$(echo $blog | cut -d@ -f2 | cut -d/ -f2)" - old_domain_array+=([$id]=$domain) - old_path_array+=([$id]=$path) + old_domain_array+=([$id]=$d) + old_path_array+=([$id]=$p) 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 # Get added and removed blogs - added_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 `) + difference_ids_array=(`echo ${!domain_array[@]} ${!old_domain_array[@]} | tr ' ' '\n' | sort | uniq -u `) + 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 - if [ ynh_permission_exists --permission="$id" ]; then - ynh_permission_delete --permission="$id" + ynh_print_info --message="Added blogs: ${added_ids_array[@]}" + ynh_print_info --message="Removed blogs: ${removed_ids_array[@]}" + + 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 - ynh_secure_remove --file="/etc/nginx/conf.d/${old_domain_array[$id]}.d/$app.conf" done - for id in $domain_array; do - - if [ $domain_array[$id] != $old_domain_array[$id] ]; then - mv /etc/nginx/conf.d/${old_domain_array[$id]}.d/$app.conf /etc/nginx/conf.d/${domain_array[$id]}.d/$app.conf - fi - - if [ $path_array[$id] != $old_path_array[$id] ]; then - domain=$domain_array[$id] - path=$path_array[$id] - ynh_add_config --template="nginx.conf" --destination="/etc/nginx/conf.d/${domain_array[$id]}.d/$app.conf" - fi + for id in ${!domain_array[@]}; do + if [ $id != "default" ]; then + if [ "${domain_array[$id]:-}" != "${old_domain_array[$id]:-}" ] || + [ "${path_array[$id]:-}" != "${old_path_array[$id]:-}" ]; then + domain=${domain_array[$id]} + path=${path_array[$id]} + blog_id=$id + [ ! -z ${old_domain_array[$id]:-} ] && ynh_secure_remove --file="/etc/nginx/conf.d/${old_domain_array[$id]}.d/$app-$id.conf" + ynh_add_config --template="nginx.conf" --destination="/etc/nginx/conf.d/${domain_array[$id]}.d/$app-$id.conf" + fi - if [ ynh_permission_exists --permission="$id" ]; then - 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" - else - ynh_permission_create --permission="$id" --url="$domain_array[$id]$path_array[$id]" - ynh_permission_create --permission="$id.admin" --url="$domain_array[$id]$path_array[$id]/admin" + if ynh_permission_exists --permission="$id"; then + 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" + else + 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" --show_tile=false --allowed=admins + fi fi done diff --git a/scripts/install b/scripts/install index 619e9c0..d990398 100755 --- a/scripts/install +++ b/scripts/install @@ -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" +# Initializing blogs_list (excluding default) +ynh_app_setting_set --app=$app --key=blogs_list --value="default@$domain$path" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 93e457e..f5dc93b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -55,6 +55,11 @@ if [ -z "${blog_admin:-}" ] || ynh_app_setting_set --app=$app --key=blog_blogroll --value=$blog_blogroll 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 #=================================================