diff --git a/conf/app.src b/conf/app.src index b8c853e..26c1c75 100755 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ SOURCE_URL=https://codeberg.org/zot/osada/archive/0c22781a2271170d0557881ac58a202148351c64.tar.gz -SOURCE_SUM=0cdd761aac0f1a382f6593868bd66d9919333fda4edeb1f2904d13a01febbeed +SOURCE_SUM= SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR= diff --git a/conf/cron b/conf/cron new file mode 100755 index 0000000..fb39087 --- /dev/null +++ b/conf/cron @@ -0,0 +1,2 @@ +# Run poller periodically to update Osada +*/10 * * * * __APP__ cd __FINALPATH__; /usr/bin/php__PHPVERSION__ Zotlabs/Daemon/Master.php Cron > /dev/null 2>&1 diff --git a/conf/htconfig.sample.php b/conf/htconfig.sample.php new file mode 100644 index 0000000..fad9a67 --- /dev/null +++ b/conf/htconfig.sample.php @@ -0,0 +1,95 @@ +}t tag +; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t ; %T: time the log has been written (the request has finished) ; it can accept a strftime(3) format: ; %d/%b/%Y:%H:%M:%S %z (default) +; The strftime(3) format must be encapsuled in a %{}t tag +; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t ; %u: remote user ; ; Default: "%R - %u %t \"%m %r\" %s" ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" - + ; The log file for slow requests ; Default Value: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set -slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log - +;slowlog = log/$pool.log.slow + ; The timeout for serving a single request after which a PHP backtrace will be ; dumped to the 'slowlog' file. A value of '0s' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 -request_slowlog_timeout = 5s - +;request_slowlog_timeout = 0 + ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 request_terminate_timeout = 1d - + ; Set open file descriptor rlimit. ; Default Value: system defined value ;rlimit_files = 1024 - + ; Set max core size rlimit. ; Possible Values: 'unlimited' or an integer greater or equal to 0 ; Default Value: system defined value ;rlimit_core = 0 - + ; Chroot to this directory at the start. This value must be defined as an ; absolute path. When this value is not set, chroot is not used. ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one ; of its subdirectories. If the pool prefix is not set, the global prefix ; will be used instead. -; Note: chrooting is a great security feature and should be used whenever +; Note: chrooting is a great security feature and should be used whenever ; possible. However, all PHP paths will be relative to the chroot ; (error_log, sessions.save_path, ...). ; Default Value: not set @@ -347,16 +365,25 @@ chdir = __FINALPATH__ ; Note: on highloaded environement, this can cause some delay in the page ; process time (several ms). ; Default Value: no -catch_workers_output = yes +;catch_workers_output = yes + +; Clear environment in FPM workers +; Prevents arbitrary environment variables from reaching FPM worker processes +; by clearing the environment in workers before env vars specified in this +; pool configuration are added. +; Setting to "no" will make all environment variables available to PHP code +; via getenv(), $_ENV and $_SERVER. +; Default Value: yes +;clear_env = no ; Limits the extensions of the main script FPM will allow to parse. This can ; prevent configuration mistakes on the web server side. You should only limit ; FPM to .php extensions to prevent malicious users to use other extensions to -; exectute php code. +; execute php code. ; Note: set an empty value to allow all extensions. ; Default Value: .php -;security.limit_extensions = .php .php3 .php4 .php5 - +;security.limit_extensions = .php .php3 .php4 .php5 .php7 + ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from ; the current environment. ; Default Value: clean env @@ -370,7 +397,7 @@ catch_workers_output = yes ; overwrite the values previously defined in the php.ini. The directives are the ; same as the PHP SAPI: ; php_value/php_flag - you can set classic ini defines which can -; be overwritten from PHP call 'ini_set'. +; be overwritten from PHP call 'ini_set'. ; php_admin_value/php_admin_flag - these directives won't be overwritten by ; PHP call 'ini_set' ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. @@ -392,13 +419,12 @@ catch_workers_output = yes ;php_admin_value[memory_limit] = 32M ; Common values to change to increase file upload limit -; upload_max_filesize = 50M -; post_max_size = 50M -; mail.add_x_header = Off +; php_admin_value[upload_max_filesize] = 50M +; php_admin_value[post_max_size] = 50M +; php_admin_flag[mail.add_x_header] = Off ; Other common parameters -; max_execution_time = 600 -; max_input_time = 300 -; memory_limit = 256M -; short_open_tag = On -; cgi.fix_pathinfo = 0; +; php_admin_value[max_execution_time] = 600 +; php_admin_value[max_input_time] = 300 +; php_admin_value[memory_limit] = 256M +; php_admin_flag[short_open_tag] = On diff --git a/conf/poller-cron b/conf/poller-cron deleted file mode 100755 index 0808434..0000000 --- a/conf/poller-cron +++ /dev/null @@ -1,2 +0,0 @@ -# Run poller periodically to update Osada -*/10 * * * * __USER__ cd YNH_WWW_PATH; /usr/bin/php Zotlabs/Daemon/Master.php Cron > /dev/null 2>&1 diff --git a/manifest.json b/manifest.json index 55eb103..b5ef8c9 100755 --- a/manifest.json +++ b/manifest.json @@ -3,8 +3,8 @@ "id": "osada", "name": "osada", "description": { - "en": "Osada is a decentralized publication platform and social network.", - "fr": "Osada est une plateforme de publication décentralisée et un réseau social." + "en": "Decentralized publication platform and social network", + "fr": "Plateforme de publication décentralisée et un réseau social" }, "url": "http://zotlabs.com/osada/", "license": "MIT", @@ -15,12 +15,12 @@ }, "services": [ "nginx", - "php7.0-fpm", + "php7.3-fpm", "mysql", "postgresql" ], "requirements": { - "yunohost": ">= 4.0.0" + "yunohost": ">= 4.2.4" }, "multi_instance": true, "arguments": { @@ -28,18 +28,12 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain for your Osada. Osada must run in the root of this domain. It means no other app can be accessed/run from this domain. We advise to use a dedicated subdomain such as osada.domain.tld", - "fr": "Indiquez un domain pour Osada. Osada doit être installé à la racine du domaine. Cela implique qu'aucune autre app ne pourra être installée ou accessible sur ce domain. Nous conseillons un sous-domaine dédié par exemple osada.domain.tld." - } + "example": "example.com" }, { "name": "admin", "type": "user", - "ask": { - "en": "Choose the Osada administrator (must be an existing YunoHost user)", - "fr": "Choisissez l'administrateur de Osada (doit être un utilisateur YunoHost existant)" - } + "example": "johndoe" }, { "name": "database", diff --git a/scripts/backup b/scripts/backup index 337578d..524c6cc 100755 --- a/scripts/backup +++ b/scripts/backup @@ -23,7 +23,8 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_print_info --message="Loading installation settings..." + app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) diff --git a/scripts/install b/scripts/install index 2d7bb74..ae10fba 100755 --- a/scripts/install +++ b/scripts/install @@ -27,7 +27,7 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" admin=$YNH_APP_ARG_ADMIN -email=$(yunohost user info $admin | grep "mail:" | cut -d' ' -f2) +email=$(ynh_user_get_info --username=$admin --key=mail) upload="256M" random_string="$(ynh_string_random)$(ynh_string_random)$(ynh_string_random)" database=`expr $YNH_APP_ARG_DATABASE` @@ -69,6 +69,14 @@ if [ $database -eq 2 ]; then ynh_install_app_dependencies $pkg_dependencies fi +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -114,7 +122,6 @@ pushd "$final_path" ln -s ../extend/addon/zaddons/$base $base done - popd @@ -123,17 +130,17 @@ ynh_script_progression --message="Creating smarty3 folder for personal data..." mkdir -p "${final_path}/store" mkdir -p "${final_path}/cache/smarty3" -chmod -R 777 $final_path/store $final_path/cache - -# Copy the template install/htconfig.sample.php to .htconfig.php -ynh_script_progression --message="Moving .htconfig.php to root of Osada ..." -config="$final_path/.htconfig.php" -cp $final_path/install/htconfig.sample.php $config # Create php.log inside Osada for logs ynh_script_progression --message="Create php.log for the Osada debuging..." + touch "$final_path/php.log" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" +chmod -R 755 $final_path/store $final_path/cache + #================================================= # CREATE A DATABASE #================================================= @@ -161,46 +168,6 @@ else ynh_die --message="Some problem occured in creating the database, contact maintainer" fi -#================================================= -# MODIFY A CONFIG FILE -#================================================= - -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -ynh_replace_string --match_string="your.mysqlhost.com" --replace_string="localhost" --target_file="$config" -ynh_replace_string --match_string= "mysqlpassword" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="mysqlusername" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string= "mysqldatabasename" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string= "mysite.example" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string= "if the auto install failed, put a unique random string here" --replace_string="$random_string" --target_file="$config" -sed -i "s/\['admin_email'\] = '';/\['admin_email'\] = '$email';/g" "$config" -ynh_replace_string --match_string= "//error_reporting(E_ERROR | E_WARNING | E_PARSE );" --replace_string="error_reporting(E_ERROR | E_WARNING | E_PARSE );" --target_file="$config" -ynh_replace_string --match_string= "//ini_set('error_log','php.out');" --replace_string="ini_set('error_log','php.log');" --target_file="$config" -ynh_replace_string --match_string= "//ini_set('log_errors','1');" --replace_string="ini_set('log_errors','1');" --target_file="$config" -ynh_replace_string --match_string= "//ini_set('display_errors', '0');" --replace_string="ini_set('display_errors', '0');" --target_file="$config" -sed -i "s/\['php_path'\] = 'php';/\['php_path'\] = 'php$phpversion';/g" "$config" - -# addon ldap config -ynh_script_progression --message="Push LDAP configuration to .htconfig.php..." - -cat ../conf/ldap_conf.php >> $final_path/.htconfig.php - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." -### `ynh_add_nginx_config` will use the file conf/nginx.conf - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -208,17 +175,31 @@ ynh_script_progression --message="Configuring PHP-FPM..." # Create a dedicated PHP-FPM config ynh_add_fpm_config --package="$extra_php_dependencies" +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -# Set right permissions for Osada -ynh_script_progression --message="Set right for Osada..." -chown -R $app: $final_path +#================================================= +# MODIFY A CONFIG FILE +#================================================= -# Set up cron job +ynh_add_config --template="../conf/htconfig.sample.php" --destination="$final_path/.htconfig.php" + +# addon ldap config +ynh_add_config --template="../conf/ldap_conf.php" --destination="$final_path/.htconfig.php" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring NGINX web server..." + +# Create a dedicated NGINX config +ynh_add_nginx_config + +#================================================= +# SETUP CRON JOB +#================================================= ynh_script_progression --message="Setting up cron job..." -ynh_replace_string --match_string="YNH_WWW_PATH" --replace_string="$final_path" --target_file="../conf/poller-cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/poller-cron" -ynh_replace_string --match_string="__PHP_VERSION__" --replace_string="$phpversion" --target_file="../conf/poller-cron" -cp ../conf/poller-cron /etc/cron.d/$app + +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -239,13 +220,15 @@ ynh_use_logrotate "$final_path/php.log" # SETUP FAIL2BAN #================================================= ynh_script_progression --message="Add Fail2Ban..." + ynh_add_fail2ban_config --logpath="$final_path/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring permissions..." + # As Osada is social network and have its own permission there is no need to keep Osada behind SSO -ynh_script_progression --message="Configuring SSOwat..." ynh_permission_update --permission="main" --add="visitors" #================================================= diff --git a/scripts/restore b/scripts/restore index 5f8af87..22de558 100755 --- a/scripts/restore +++ b/scripts/restore @@ -55,6 +55,14 @@ test ! -d $final_path \ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_print_info "Recreating the dedicated system user..." + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -84,14 +92,6 @@ elif [ $database -eq 2 ]; then ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" fi -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_print_info "Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -ynh_system_user_create $app - #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= @@ -125,9 +125,6 @@ ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" ynh_systemd_action --action=restart --service_name=fail2ban -# Make app public -ynh_app_setting_set $app skipped_uris "/" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 9d03e17..29eb5af 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -25,14 +25,10 @@ database=$(ynh_app_setting_get --app=$app --key=database) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= -# ENSURE DOWNWARD COMPATIBILITY +# CHECK VERSION #================================================= -# If db_name doesn't exist, create it -if [ -z "$db_name" ]; then - db_name=$(ynh_sanitize_dbid --db_name=$app) - ynh_app_setting_set --app=$app --key=db_name --value=$db_name -fi +upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -49,21 +45,14 @@ ynh_clean_setup () { ynh_abort_if_errors #================================================= -# STANDARD UPGRADE STEPS +# ENSURE DOWNWARD COMPATIBILITY #================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_print_info "Upgrading source files..." -# Create a temporary directory -# tmpdir="$(ynh_smart_mktemp 6000)" -# Backup the config file in the temp dir -# cp -a "$final_path/.htconfig.php" "$tmpdir/.htconfig.php" -# cp -a "$final_path/store" "$tmpdir/store" -# cp -a "$final_path/php.log" "$tmpdir/php.log" - -# Remove the app directory securely -# ynh_secure_remove "$final_path" +# If db_name doesn't exist, create it +if [ -z "$db_name" ]; then + db_name=$(ynh_sanitize_dbid --db_name=$app) + ynh_app_setting_set --app=$app --key=db_name --value=$db_name +fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then @@ -71,6 +60,14 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -123,7 +120,7 @@ if [ `cd $final_path && git rev-parse --is-inside-work-tree` ]; then fi; done popd - chmod -R 777 $final_path/store + chmod -R 775 $final_path/store else # Create a temporary directory @@ -151,6 +148,10 @@ else fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -159,17 +160,6 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - -# Set right permissions for curl install -chown -R $app: $final_path - #================================================= # PHP-FPM CONFIGURATION #================================================= @@ -192,27 +182,25 @@ ynh_script_progression --message="Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append +#================================================= # UPGRADE FAIL2BAN #================================================= ynh_script_progression --message="Re-configure Fail2Ban..." ynh_add_fail2ban_config --logpath="$final_path/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" -# Set cron job -ynh_print_info "Setting up cron job..." -ynh_replace_string --match_string="YNH_WWW_PATH" --replace_string="$final_path" --target_file="../conf/poller-cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/poller-cron" -ynh_replace_string --match_string="__PHP_VERSION__" --replace_string="$phpversion" --target_file="../conf/poller-cron" -cp -f ../conf/poller-cron /etc/cron.d/$app +#================================================= +# SETUP CRON JOB +#================================================= + +ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." + if [ $database -eq 1 ]; then - #================================================= - # CHECK VERSION FOR SPECIFIC MYSQL UPDATE - #================================================= # Check version and if this version was a fresh install push mysql query db_name=$(ynh_app_setting_get --app=$app --key=db_name) @@ -222,13 +210,6 @@ elif [ $database -eq 2 ]; then ynh_install_app_dependencies $pkg_dependencies fi -#================================================= -# SETUP SSOWAT -#================================================= -# As Osada is social network and have its own permission there is no need to keep Osada behind SSO -ynh_script_progression --message="Upgrading SSOwat configuration..." -ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" - #================================================= # RELOAD NGINX #=================================================