Skip to content
Draft
Show file tree
Hide file tree
Changes from 10 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
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
}
]
}]
9 changes: 6 additions & 3 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'] = '__YNH_ADMIN_USER__'; //The admin can be user or @group or comma separated list user1,@group1,user2
$conf['manager'] = '__YNH_ADMIN_USER__'; //The manager can be user or @group or comma separated list user1,@group1,user2
Expand All @@ -25,7 +25,10 @@
$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})))';
#$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
37 changes: 37 additions & 0 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
#!/bin/bash

# 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 "$@"

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

# 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
}

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
59 changes: 59 additions & 0 deletions scripts/actions/public_private
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

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

source /usr/share/yunohost/helpers

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

# Get is_public and set as lowercase
is_public=${YNH_ACTION_IS_PUBLIC,,}

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

#=================================================
# CHECK IF ARGUMENTS ARE CORRECT
#=================================================

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

is_public_old=$(ynh_app_setting_get $app is_public)

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

#=================================================
# SPECIFIC ACTION
#=================================================
# MOVE TO PUBLIC OR PRIVATE
#=================================================

if [ $is_public -eq 0 ];
then
ynh_app_setting_delete $app unprotected_uris
else
ynh_app_setting_set $app unprotected_uris "/"
fi

# Regen ssowat configuration
yunohost app ssowatconf

# Update the config of the app
ynh_app_setting_set $app is_public $is_public

#=================================================
# RELOAD NGINX
#=================================================

systemctl reload nginx
18 changes: 16 additions & 2 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set --app=$app --key=language --value=$language

#=================================================
# STORE DEFAULT VALUES FOR "ACTION SCRIPTS"
#=================================================

# Needed for "upgrade" to know which backend to set back after overwriting "local.protected.php"
# Can be changed by action script "internal_users"
auth_backend='authldap' # Default backend is LDAP with Yunohost, 'authldap' for DokuWiki
ynh_app_setting_set $app auth_backend $auth_backend

# Force disable the 'is_internal_users' feature
ynh_app_setting_set $app is_internal_users 0

#=================================================
# STANDARD MODIFICATIONS
#=================================================
Expand Down Expand Up @@ -110,13 +122,15 @@ ynh_script_progression --message="Configuring dokuwiki..." --weight=2
# It will only be updated by Yunohost package or directly by adventurous users
cp ../conf/local.protected.php $final_path/conf

# 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 --match_string="__YNH_ADMIN_USER__" --replace_string="$admin" --target_file="$final_path/conf/local.protected.php"


# This file might be modified by dokuwiki admin panel or by plugins
# It will not be modified by Yunohost in order to keep user settings
cp ../conf/local.php $final_path/conf
cp ../conf/local.php $final_path/conf

# Set the "language"
ynh_replace_string --match_string="__YNH_LANGUAGE__" --replace_string="$language" --target_file="$final_path/conf/local.php"
Expand All @@ -125,7 +139,7 @@ ynh_replace_string --match_string="__YNH_LANGUAGE__" --replace_string="$langua
# Restrict user rights by enforcing "read-only" mode for all users
# See https://www.dokuwiki.org/acl#background_info
# Default is "8"
cp ../conf/acl.auth.php $final_path/conf
cp ../conf/acl.auth.php $final_path/conf

#=================================================
# CREATE DEFAULT FILES
Expand Down
16 changes: 16 additions & 0 deletions scripts/upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)

upgrade_type=$(ynh_check_app_version_changed)

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

#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
Expand Down Expand Up @@ -61,6 +64,17 @@ if [ -z "$language" ]; then
ynh_app_setting_set --app=$app --key=language --value=$language
fi

# 'auth_backend' default value, if not set
if [ -z "$auth_backend" ]; then
auth_backend='authldap'
ynh_app_setting_set $app auth_backend $authldap
fi

# 'is_internal_users' default value, if not set
if [ -z "$is_internal_users" ]; then
ynh_app_setting_set $app is_internal_users 0
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test is needed as well for auth_backend



# Yunohost specific configuration, if it isn't exist already
Expand Down Expand Up @@ -247,6 +261,8 @@ ynh_backup_if_checksum_is_different --file="$final_path/conf/local.protected.php
# Always overwrite local file with the one from package.
cp ../conf/local.protected.php $final_path/conf

# 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 --match_string="__YNH_ADMIN_USER__" --replace_string="$admin" --target_file="$final_path/conf/local.protected.php"

Expand Down