From d1e27f24764d52f3c695474a5236335bfbb707d3 Mon Sep 17 00:00:00 2001 From: anmol Date: Thu, 8 Nov 2018 20:35:36 +0530 Subject: [PATCH] Added option to open registration and make user moderator --- check_process | 1 + conf/nginx.conf | 3 +++ conf/prod.secret.exs | 2 +- manifest.json | 8 ++++++++ scripts/install | 46 ++++++++++++++++++++++++++++++++++++-------- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/check_process b/check_process index e49deaa..f55768e 100755 --- a/check_process +++ b/check_process @@ -8,6 +8,7 @@ domain="domain.tld" (DOMAIN) admin="john" (USER) name="pleroma" + registration=0 (BOOLEAN) is_public=1 (PUBLIC|public=1|private=0) ; Checks pkg_linter=1 diff --git a/conf/nginx.conf b/conf/nginx.conf index bf1f473..7de2dd3 100755 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,6 +1,9 @@ location / { # if you do not want remote frontends to be able to access your Pleroma backend # server, remove these lines. + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Methods' 'POST, PUT, DELETE, GET, PATCH, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Idempotency-Key' always; diff --git a/conf/prod.secret.exs b/conf/prod.secret.exs index 769d3a7..2530335 100644 --- a/conf/prod.secret.exs +++ b/conf/prod.secret.exs @@ -10,7 +10,7 @@ config :pleroma, :instance, name: "__INSTANCE_NAME__", email: "__ADMIN_EMAIL__", limit: 5000, - registrations_open: true, + registrations_open: __REG__, dedupe_media: false config :pleroma, :media_proxy, diff --git a/manifest.json b/manifest.json index 8efd13f..58efbfb 100755 --- a/manifest.json +++ b/manifest.json @@ -44,6 +44,14 @@ } }, { + "name": "registration", + "type": "boolean", + "ask": { + "en": "Is registrations are open to everyone?" + }, + "default": false + }, + { "name": "is_public", "type": "boolean", "ask": { diff --git a/scripts/install b/scripts/install index 0854d9a..8c78e39 100755 --- a/scripts/install +++ b/scripts/install @@ -25,9 +25,11 @@ domain=$YNH_APP_ARG_DOMAIN path_url="/" admin=$YNH_APP_ARG_ADMIN admin_email=$(ynh_user_get_info $admin 'mail') +admin_pass=$(ynh_string_random 24) is_public=$YNH_APP_ARG_IS_PUBLIC random_key=$(ynh_random 64) name=$YNH_APP_ARG_NAME +registration=$YNH_APP_ARG_REGISTRATION # This is a multi-instance app, meaning it can be installed several times independently @@ -58,13 +60,13 @@ ynh_webpath_register "$app" "$domain" "$path_url" # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set "$app" domain "$domain" -ynh_app_setting_set "$app" admin_email "$admin_email" -ynh_app_setting_set "$app" is_public "$is_public" -ynh_app_setting_set "$app" random_key "$random_key" -ynh_app_setting_set "$app" admin "$admin" -ynh_app_setting_set "$app" name "$name" - +ynh_app_setting_set "$app" domain "$domain" +ynh_app_setting_set "$app" admin_email "$admin_email" +ynh_app_setting_set "$app" is_public "$is_public" +ynh_app_setting_set "$app" random_key "$random_key" +ynh_app_setting_set "$app" admin "$admin" +ynh_app_setting_set "$app" name "$name" +ynh_app_setting_set "$app" registration "$registration" #================================================= # STANDARD MODIFICATIONS #================================================= @@ -154,15 +156,29 @@ ynh_replace_string "__PORT__" "$port" "$final_path/$app/config ynh_replace_string "__DB_NAME__" "$app" "$final_path/$app/config/setup_db.psql" ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/setup_db.psql" +# Set registrations open/closed +if [ $registration -eq 1 ] +then + ynh_replace_string "__REG__" "true" "$final_path/$app/config/prod.secret.exs" +else + ynh_replace_string "__REG__" "false" "$final_path/$app/config/prod.secret.exs" +fi + + #================================================= # SETUP #================================================= # Give permisiion to the final_path chown -R "$app":"$app" "$final_path" +# App setup and db migration ( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix local.hex --force ) ( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix local.rebar --force ) ( cd $final_path/$app && sudo -u "$app" mix deps.get ) ( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix ecto.migrate --force ) +# Add user +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix register_user "$admin" "$admin" "$admin_email" "Moderator of this instance" "$admin_pass" ) +# Make user moderator +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix set_moderator "$admin" true ) #================================================= # SETUP SSOWAT @@ -186,10 +202,24 @@ chown -R "$app":"$app" "$final_path" ynh_add_systemd_config systemctl enable "$app" systemctl start "$app" - +sleep 30 #================================================= # RELOAD NGINX #================================================= systemctl reload nginx +#================================================= +# SEND A README FOR THE ADMIN +#================================================= + +message=" $app was successfully installed :) +Please open your $app domain: https://$domain$path_url + +The moderator username is: $admin +The moderator password is: $admin_pass + +If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/pleroma_ynh/ +If you are not afraid of the terminal, check out https://git.pleroma.social/pleroma/pleroma/wikis/home to see what more you can do with your awesome instance!" + +ynh_send_readme_to_admin "$message" "$admin"