Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ALL_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- [Read the README in English](README.md)
- [Irakurri README euskaraz](README_eu.md)
- [Lire le README en français](README_fr.md)
- [Le o README en galego](README_gl.md)
40 changes: 40 additions & 0 deletions actions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[{
"id": "public_private",
"name": "Move to public or private",
"command": "/bin/bash scripts/actions/public_private",
"user": "root",
"accepted_return_codes": [0],
"description": {
"en": "Change the public access of the app."
},
"arguments": [
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Is it a public app ? (1/0) (1=yes; 0=no)"
},
"default": false
}
]
},
{
"id": "internal_users",
"name": "Allow DokuWiki internal users storage in addition to Yunohost",
"command": "/bin/bash scripts/actions/internal_users",
"user": "root",
"accepted_return_codes": [0],
"description": {
"en": "Enable DokuWiki internal users."
},
"arguments": [
{
"name": "is_internal_users",
"type": "boolean",
"ask": {
"en": "Want to enable DokuWiki users too ? (1/0) (1=yes; 0=no)"
},
"default": false
}
]
}]
52 changes: 52 additions & 0 deletions actions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[public_private]
name = "Move to public or private"
command = "/bin/bash scripts/actions/public_private"
user = "root" # optional
#cwd = "/" # optional
#accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Change the public access of the app."

[public_private.arguments]
[public_private.arguments.is_public]
type = "boolean"
ask = "Is it a public app ? (1/0) (1=yes; 0=no)"
example = "0"
default = false

[internal_users]
name = "Allow DokuWiki internal users storage in addition to Yunohost"
command = "/bin/bash scripts/actions/internal_users"
user = "root" # optional
#cwd = "/" # optional
#accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Enable DokuWiki internal users."

[internal_users.arguments]
[internal_users.arguments.is_internal_users]
type = "boolean"
ask = "Want to enable DokuWiki users too ? (1/0) (1=yes; 0=no)"
example = "0"
default = false

#[echo_plop]
#name = "echo plop"
#command = "echo plop"
#
# [echo_plop.arguments]
# [echo_plop.arguments.argument_one]
# type = "string"
# ask = "some stuff"
# example = "stuff"
#
# [echo_plop.arguments.argument_two]
# type = "string"
# ask = "some stuff"
# example = "stuff"
#
# [echo_plop.arguments.argument_three]
# type = "string"
# ask = "some stuff"
# example = "stuff"
#
14 changes: 8 additions & 6 deletions conf/local.protected.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is used for configuration settings which cannot be modified by Dokuwiki admin panel
* See here for explanations : https://www.dokuwiki.org/config
*
*
* Yunohost dedicated settings are stored here in order to be able to upgrade the Yunohost package safely latter for Yunohost packager ( Yeah \o/ )
*
* You should not modify this file direclty as it will be overwritten by Yunohost package
Expand All @@ -12,7 +12,7 @@

/* Authentication Settings */
$conf['useacl'] = 1; //Use Access Control Lists to restrict access?
$conf['authtype'] = 'authldap'; //which authentication backend should be used
$conf['authtype'] = '__YNH_AUTH_BACKEND__'; //which authentication backend should be used
$conf['passcrypt'] = 'sha1'; //Used crypt method (smd5,md5,sha1,ssha,crypt,mysql,my411)
$conf['superuser'] = '@__APP__.admin'; //The admin can be user or @group or comma separated list user1,@group1,user2
$conf['manager'] = '@__APP__.admin'; //The manager can be user or @group or comma separated list user1,@group1,user2
Expand All @@ -22,11 +22,13 @@
$conf['plugin']['authldap']['port'] = 389;
$conf['plugin']['authldap']['version'] = 3;
$conf['plugin']['authldap']['usertree'] = 'ou=users,dc=yunohost,dc=org';
$conf['plugin']['authldap']['grouptree'] = 'ou=permission,dc=yunohost,dc=org';
$conf['plugin']['authldap']['userfilter'] = '(&(objectClass=posixAccount)(uid=%{user})(permission=cn=__APP__.main,ou=permission,dc=yunohost,dc=org))';
$conf['plugin']['authldap']['groupfilter'] = '(&(objectClass=posixGroup)(memberUid=%{user}))';
#$conf['plugin']['authldap']['debug'] = 1;
$conf['plugin']['authldap']['userfilter'] = '(&(uid=%{user})(objectClass=posixAccount))';
# no groups
#$conf['plugin']['authldap']['grouptree'] = 'ou=Group, dc=server, dc=tld';
#$conf['plugin']['authldap']['groupfilter'] = '(&(objectClass=posixGroup)(|(gidNumber=%{gid})(memberUID=%{user})))';

// Authchained plugin preload configuration. Can be used by 'internal_users' action script
$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';

/* Advanced Settings */
$conf['updatecheck'] = 0; //automatically check for new releases?
Expand Down
44 changes: 25 additions & 19 deletions config_panel.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
version = "1.0"

version = "0.1"
name = "DokuWiki configuration panel"

[main]
name = "Dokuwiki configuration"
name = "DokuWiki configuration"

[main.public_access]
name = "Public access"

[main.php_fpm_config]
name = "PHP-FPM configuration"
[main.public_access.is_public]
ask = "Is it a public website ?"
type = "boolean"
default = false
help = "By activating this, people who does not have a YunoHost account will be able to reach your Wiki."

[main.php_fpm_config.fpm_footprint]
ask = "Memory footprint of the service?"
choices = ["low", "medium", "high", "specific"]
default = "low"
help = "low <= 20Mb per pool. medium between 20Mb and 40Mb per pool. high > 40Mb per pool.<br>Use specific to set a value with the following option."
[main.internal_users]
name = "Internal users"

[main.php_fpm_config.free_footprint]
ask = "Memory footprint of the service?"
type = "number"
default = "0"
help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values."
[main.internal_users.is_internal_users]
ask = "Allow local users from DokuWiki in addition to Yunohost users ?"
type = "boolean"
default = false
help = "By activating this, people will be able to create account and loggin on the wiki"

[main.php_fpm_config.fpm_usage]
ask = "Expected usage of the service?"
choices = ["low", "medium", "high"]
default = "low"
help = "low: Personal usage, behind the SSO. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.<br>medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.<br>high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding."
# WIP
#[main.internal_users.self_register]
#name = "Allow guest users to create an account ?"
#help = "By activating this, people will be able to self register and then logging"
#type = "bool"
#default = false
2 changes: 1 addition & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description.it = "Wiki aderente agli standard, semplice da usare, finalizzato pr

version = "2024.02.06a~ynh1"

maintainers = [""]
maintainers = []

[upstream]
license = "GPL-2.0-or-later"
Expand Down
47 changes: 33 additions & 14 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
#!/bin/bash

#=================================================
# COMMON VARIABLES
#=================================================
# PHP APP SPECIFIC
#=================================================
# Check available space before creating a temp directory.
#
# usage: ynh_smart_mktemp --min_size="Min size"
#
# | arg: -s, --min_size= - Minimal size needed for the temporary directory, in Mb
ynh_smart_mktemp () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=min_size= )
local min_size
# Manage arguments with getopts
ynh_handle_getopts_args "$@"

#=================================================
# PERSONAL HELPERS
#=================================================
min_size="${min_size:-300}"
# Transform the minimum size from megabytes to kilobytes
min_size=$(( $min_size * 1024 ))

#=================================================
# EXPERIMENTAL HELPERS
#=================================================
# Check if there's enough free space in a directory
is_there_enough_space () {
local free_space=$(df --output=avail "$1" | sed 1d)
test $free_space -ge $min_size
}

#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
if is_there_enough_space /tmp; then
local tmpdir=/tmp
elif is_there_enough_space /var; then
local tmpdir=/var
elif is_there_enough_space /; then
local tmpdir=/
elif is_there_enough_space /home; then
local tmpdir=/home
else
ynh_die "Insufficient free space to continue..."
fi

echo "$(sudo mktemp --directory --tmpdir="$tmpdir")"
}
146 changes: 146 additions & 0 deletions scripts/actions/internal_users
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/bin/bash

#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source scripts/_common.sh
source /usr/share/yunohost/helpers

#=================================================
# RETRIEVE ARGUMENTS
#=================================================

# Get "is_internal_users" and set as lowercase
is_internal_users=${YNH_ACTION_IS_INTERNAL_USERS,,}

# Get the full name of the app, Example: strut__3
app=$YNH_APP_INSTANCE_NAME

admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)

auth_backend_old=$(ynh_app_setting_get $app auth_backend)
is_internal_users_old=$(ynh_app_setting_get $app is_internal_users)

#=================================================
# CHECK IF ARGUMENTS AND REQUIREMENTS ARE CORRECT
#=================================================

# Ensure that app is public
if [ $is_public -eq 0 ]; then
ynh_die "Wiki must be public if you want your people to be able to reach it. Run 'public_private' and come back here" 1
fi

#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================

if [ $is_internal_users -eq $is_internal_users_old ]
then
ynh_die "is_internal_users is already set as $is_internal_users." 0
fi

#=================================================
# SPECIFIC ACTION
#=================================================

### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$final_path/conf/local.protected.php"

# Always overwrite local file with the one from package.
cp conf/local.protected.php $final_path/conf


if [ $is_internal_users -eq 1 ]; then
auth_backend="authchained"

# Automatically install "authchained" plugin
# Allows to use multiple users backend storage : LDAP + internal DokuWiki users
# See https://www.dokuwiki.org/plugin:authchained?s[]=chained

plugin_archive=dokuwiki-plugin-authchained.tar.gz
wget -nv --quiet 'https://github.com/rztuc/dokuwiki-plugin-authchained/archive/master.tar.gz' -O "$plugin_archive" -o /dev/null || true

# if "file is not zero size"
if [ -s "$plugin_archive" ]; then

tmpdir="$(ynh_smart_mktemp --min_size=1)" # Create a 1mb temporary folder
tar xzf "$plugin_archive" -C "$tmpdir" # Extract plugin to the temp folder

# Extract the "base" field from the plugin archive to create plugin folder name
# See https://www.dokuwiki.org/devel:plugin_info
#
# 'wildcard' is used to avoid having to find the name of the subfolder
# It should not change later but who knows...
plugin_folder_name=$(cat $tmpdir/*/plugin.info.txt | grep url | awk -F ':' '{print $3}')

# Define the path where plugin has to be installed
plugin_finalpath="$final_path/lib/plugins/$plugin_folder_name"
mkdir -p $plugin_finalpath

# Copy plugin files to DokuWiki plugin directory
# Doesn't work with "mv" so "cp" instead (taken from "upgrade" script)
cp -a $tmpdir/*/. "$plugin_finalpath/"

# Cleaning
ynh_secure_remove --file="$tmpdir"

# Set filesystem rights for new plugin
chown -R $app:root $plugin_finalpath
fi
else
auth_backend="authldap"
# TODO: Disable/remove "authchained"


##$plugins['authchained'] = 0; in plugins.local.php
#
#
## Use a "sub process" to start a new shell to run these commands
## Allow to use only one "cd" and to be more efficent
#(
# cd $final_path/conf
#
# cp plugins.local.php plugins.local.php.bak
#
# # Search if configuration in "config file" is present for plugin to work
# ## -F, --fixed-strings
# ## Interpret PATTERN as a list of fixed strings (instead of regular expressions), separated by newlines, any of which is to
# ## be matched.
# ## -q, --quiet, --silent
# ## Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an
# ## error was detected. Also see the -s or --no-messages option.
# grep --quiet --fixed-strings '$plugins['authchained'] = 0;' "plugins.local.php"
# if [ $? -ne 0 ]; then
# echo "not found in file"
# # If not found, add the setting to "local.protected.php" which can only be edited by Yunohost
# # "\$conf" needs the "\" to espace the dollar and avoid echo to interprate it as a (void) variable
# #echo "\$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';" >> "$final_path/conf/local.protected.php"
# else
# echo "not found in file"
# fi
# # source: https://stackoverflow.com/questions/3557037/appending-a-line-to-a-file-only-if-it-does-not-already-exist
#
#)
fi


# Set the authentification backend
ynh_replace_string "__YNH_AUTH_BACKEND__" "$auth_backend" "$final_path/conf/local.protected.php"
# Set the "admin" user
ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php"

# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/conf/local.protected.php"

# Purge cache; see https://www.dokuwiki.org/faq:pluginproblems#cache
touch $final_path/conf/local.php

# Update the config of the app
ynh_app_setting_set $app auth_backend $auth_backend
ynh_app_setting_set $app is_internal_users $is_internal_users
Loading