Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextcloud parameters in config panel #638

Open
wants to merge 16 commits into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
10 changes: 10 additions & 0 deletions conf/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"system": {
"maintenance": false,
"updatechecker": false,
"memcache.local": "\\OC\\Memcache\\APCu",
"integrity.check.disabled": true,
Expand All @@ -12,8 +13,17 @@
"password": ""
},
"hashing_default_password": true,
"has_internet_connection": true,
"default_phone_region": "",
"default_timezone": "Europe/Paris",
"trashbin_retention_obligation": "auto",
"version_retention_obligation": "auto",
"enable_previews": true,
"defaultapp": "dashboard,files",
"lost_password_link": "",
"localstorage.allowsymlinks": true,
"simpleSignUpLink.shown": false,
"skeletondirectory": "/home/yunohost.app/__APP__/skeleton/{lang}",
zamentur marked this conversation as resolved.
Show resolved Hide resolved
"mail_smtpmode": "smtp",
"mail_smtpport": "25",
"mail_smtpauth": 1,
Expand Down
90 changes: 86 additions & 4 deletions config_panel.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,96 @@ version = "1.0"

[main]
name = "Nextcloud configuration"
services = ["php8.2-fpm"]

[main.maintenance_mode]
name = "Maintenance mode"
[main.mode]
name = "Modes"

[main.maintenance_mode.maintenance_mode]
[main.mode.maintenance]
ask = "Enable maintenance mode"
type = "boolean"
default = "0"
bind = ":__INSTALL_DIR__/config/config.php"

[main.mode.has_internet_connection]
ask = "Internet connection available"
type = "boolean"
bind = ":__INSTALL_DIR__/config/config.php"
help = "Is Nextcloud connected to the Internet or running in a closed network?"

[main.localization]
name = "Localization"

[main.localization.default_phone_region]
ask = "Default phone region"
type = "select"
bind = ":__INSTALL_DIR__/config/config.php"
help = "It is required to allow inserting phone numbers in the user profiles starting without the country code (e.g. +49 for Germany)."

[main.localization.default_timezone]
ask = "Default timezone"
type = "select"
bind = ":__INSTALL_DIR__/config/config.php"
help = "The default timezone parameter is only used when the timezone of the user can’t be determined."

[main.account]
name = "Account"

[main.account.lost_password_link]
ask = "Lost password link"
type = "url"
bind = ":__INSTALL_DIR__/config/config.php"
help = "Allow to redirect on a custom form to require a password reset (for example to ask you to reset it from this yunohost webadmin)"
zamentur marked this conversation as resolved.
Show resolved Hide resolved

[main.account.logout_url]
ask = "Logout URL"
type = "url"
bind = ":__INSTALL_DIR__/config/config.php"
help = "Redirect on this URL when a user click on 'Logout' action"

[main.files]
name = "Files"

[main.files.skeleton]
ask = "To configure the default files created for new users, you can do it by logging on nextcloud with an admins account and edit files under `New user default files/default` or if you want to target a specific language `New user default files/FR`."
zamentur marked this conversation as resolved.
Show resolved Hide resolved
type = "alert"
style = "info"

[main.files.trashbin_retention_obligation]
ask = "Trashbin retention"
type = "string"
bind = ":__INSTALL_DIR__/config/config.php"
help = "If the trash bin app is enabled (default), this setting defines the policy for when files and folders in the trash bin will be permanently deleted."

[main.files.version_retention_obligation]
ask = "Version retention"
type = "string"
bind = ":__INSTALL_DIR__/config/config.php"
help = "If the versions app is enabled (default), this setting defines the policy for when versions will be permanently deleted."

[main.files.enable_previews]
ask = "Enable previews"
type = "boolean"
bind = ":__INSTALL_DIR__/config/config.php"
help = "Info: Previews of photos and text documents could consume a lot of resources."

[main.apps]
name = "Apps"

[main.apps.auto_upgrade_apps]
ask = "Upgrade apps"
type = "select"
choices.manual = "Manually"
choices.daily = "Daily at 00:10"
choices.weekly = "Weekly at 00:10 on Sunday"
choices.monthly = "Monthly at 00:10 on the 1st"
help = "Keep in mind that upgrade apps could break things in your instance, so you need to strike the right balance between reliability and safety."

[main.apps.defaultapp]
ask = "Default app to display"
type = "tags"
bind = ":__INSTALL_DIR__/config/config.php"
help = "Set the default app to open on login."


[main.php_fpm_config]
name = "PHP-FPM configuration"
Expand Down
4 changes: 2 additions & 2 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ram.runtime = "512M"
[resources.install_dir]

[resources.data_dir]
subdirs = ["data"]
subdirs = ["data", "skeleton"]

[resources.permissions]
main.url = "/"
Expand All @@ -77,4 +77,4 @@ ram.runtime = "512M"

[resources.database]
type = "mysql"


1 change: 1 addition & 0 deletions scripts/backup
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
#=================================================

ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/etc/cron.d/${app}_upgrade_apps" --not_mandatory

#=================================================
# BACKUP THE MYSQL DATABASE
Expand Down
50 changes: 24 additions & 26 deletions scripts/config
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__default_phone_region() {
cat << EOF
value: "$(ynh_read_var_in_file --file="$install_dir/config/config.php" --key="default_phone_region")"
choices:
EOF
jq '.[][] | " \"\(.alpha_2)\": \"\(.name)\""' -r /usr/share/iso-codes/json/iso_3166-1.json

get__maintenance_mode() {
# Maintenance mode status
maintenance_mode_status="$(cd "$install_dir" && ynh_exec_as "$app" \
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi maintenance:mode)" 2> /dev/null
if echo $maintenance_mode_status | grep -q "disabled"
then
echo "0"
elif echo $maintenance_mode_status | grep -q "enabled"
then
echo "1"
else
ynh_print_err --message="Unexpected output from maintenance status check command."
exit 0
fi
}

get__default_timezone() {
cat << EOF
value: "$(ynh_read_var_in_file --file="$install_dir/config/config.php" --key="default_timezone")"
choices:
EOF
timedatectl list-timezones --no-pager | sed 's/^/ - /g'
}

get__fpm_footprint() {
Expand Down Expand Up @@ -65,19 +65,17 @@ get__fpm_free_footprint() {
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================

set__maintenance_mode() {
if [ "$maintenance_mode" -eq "0" ]; then
# If maintenance_mode was set to 0, disable maintenance mode
(cd "$install_dir" && ynh_exec_as "$app" \
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi maintenance:mode --off)
ynh_print_info "Maintenance mode disabled"
elif [ "$maintenance_mode" -eq "1" ]; then
# If maintenance_mode was set to 1, enable maintenance mode
(cd "$install_dir" && ynh_exec_as "$app" \
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi maintenance:mode --on)
ynh_print_info "Maintenance mode enabled"
set__auto_upgrade_apps() {
declare -A frequencies=( [daily]="10 00 * * *" [weekly]="10 00 * * 0" [monthly]="10 00 1 * *" )
if [ "$frequencies[$auto_upgrade_apps]" ]
then
echo "${frequencies[$auto_upgrade_apps]} $app /usr/bin/php$phpversion --define apc.enable_cli=1 -f $install_dir/occ app:update --all" > /etc/cron.d/${app}_upgrade_apps
else
ynh_secure_remove --file=/etc/cron.d/nextcloud_upgrade_apps
fi
ynh_app_setting_set --app=$app --key=maintenance_mode --value="$maintenance_mode"

ynh_app_setting_set --app=$app --key=auto_upgrade_apps --value="$auto_upgrade_apps"

}

set__fpm_footprint() {
Expand Down
47 changes: 42 additions & 5 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,27 @@ source _ynh_mysql_connect_as.sh

phpflags="--define apc.enable_cli=1"

#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================

ynh_app_setting_set --app=$app --key=maintenance --value=$maintenance_mode
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
ynh_app_setting_set --app=$app --key=phpflags --value=$phpflags

ynh_app_setting_set --app=$app --key=has_internet_connection --value=1
ynh_app_setting_set --app=$app --key=default_phone_region --value=""
ynh_app_setting_set --app=$app --key=default_timezone --value="Europe/Paris"
ynh_app_setting_set --app=$app --key=lost_password_link --value=""
ynh_app_setting_set --app=$app --key=logout_url --value=""
ynh_app_setting_set --app=$app --key=trashbin_retention_obligation --value="auto"
ynh_app_setting_set --app=$app --key=version_retention_obligation --value="auto"
ynh_app_setting_set --app=$app --key=enable_previews --value=1
ynh_app_setting_set --app=$app --key=auto_upgrade_apps --value="manual"
ynh_app_setting_set --app=$app --key=defaultapp --value="dashboard,files"

#=================================================
# CREATE A MYSQL DATABASE
#=================================================
Expand Down Expand Up @@ -119,6 +138,7 @@ ynh_secure_remove --file="$nc_conf"
nc_conf="$install_dir/config.json"
ynh_add_config --template="../conf/config.json" --destination="$nc_conf"

cat $nc_conf
exec_occ config:import "$nc_conf"

# Then remove the config file
Expand All @@ -141,11 +161,20 @@ exec_occ ldap:test-config '' \
create_external_storage() {
local mount_dir="$1"
local mount_name="$2"
local group="${3:-}"
local mount_id=`exec_occ files_external:create --output=json \
"$mount_name" 'local' 'null::null' -c "datadir=$mount_dir" || true`
! [[ $mount_id =~ ^[0-9]+$ ]] \
&& ynh_print_warn --message="Unable to create external storage" \
|| exec_occ files_external:option "$mount_id" enable_sharing true
if ! [[ $mount_id =~ ^[0-9]+$ ]]
then
ynh_print_warn --message="Unable to create external storage"
else
exec_occ files_external:option "$mount_id" enable_sharing true
if [ "$group" != "" ]
then
exec_occ group:list
exec_occ files_external:applicable "$mount_id" --add-group="$group"
fi
fi
}

# Enable External Storage and create local mount to home folder
Expand Down Expand Up @@ -229,6 +258,14 @@ create_external_storage "/home/yunohost.multimedia/share" "Shared multimedia"
# Allow nextcloud to write into these directories
ynh_multimedia_addaccess $app

#=================================================
# EASY SKELETON CONFIGURATION
#================================================
ynh_script_progression --message="Easying skeleton configuration..." --weight=1

cp -a --no-target-directory $install_dir/core/skeleton "/home/yunohost.app/$app/skeleton/default"
zamentur marked this conversation as resolved.
Show resolved Hide resolved
create_external_storage "/home/yunohost.app/$app/skeleton" "New users default files" "admins"
zamentur marked this conversation as resolved.
Show resolved Hide resolved

#=================================================
# GENERIC FINALIZATION
#=================================================
Expand All @@ -240,8 +277,8 @@ chown -R $app:www-data "$install_dir"
chown -R $app: "$data_dir"
find $install_dir/ -type f -print0 | xargs -r0 chmod 0644
find $install_dir/ -type d -print0 | xargs -r0 chmod 0755
find $data_dir/data/ -type f -print0 | xargs -r0 chmod 0640
find $data_dir/data/ -type d -print0 | xargs -r0 chmod 0750
find $data_dir/ -type f -print0 | xargs -r0 chmod 0640
find $data_dir/ -type d -print0 | xargs -r0 chmod 0750
chmod 640 "$install_dir/config/config.php"
chmod 755 /home/yunohost.app
chmod 750 $install_dir
Expand Down
1 change: 1 addition & 0 deletions scripts/remove
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ynh_remove_fail2ban_config
# Remove a cron file
# TODO: Ensure that cron job is not running (How !?)
ynh_secure_remove --file="/etc/cron.d/$app"
ynh_secure_remove --file="/etc/cron.d/${app}_upgrade_apps"

# Cleaning ACL in home directories
for i in $(ls /home); do
Expand Down
1 change: 1 addition & 0 deletions scripts/restore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fi
ynh_script_progression --message="Restoring cron job..." --weight=1

ynh_restore_file --origin_path="/etc/cron.d/$app"
ynh_restore_file --origin_path="/etc/cron.d/${app}_upgrade_apps" --not_mandatory

#=================================================
# BACKUP THE LOGROTATE CONFIGURATION
Expand Down