diff --git a/check_process b/check_process
index dbcb8a3..c8dd4a8 100644
--- a/check_process
+++ b/check_process
@@ -8,6 +8,8 @@
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
is_public=1 (PUBLIC|public=1|private=0)
+ install_extensions=1
+ access_domain="/"
; Checks
pkg_linter=1
setup_sub_dir=1
diff --git a/conf/message b/conf/message
new file mode 100644
index 0000000..8b5460d
--- /dev/null
+++ b/conf/message
@@ -0,0 +1,4 @@
+Standard Notes - syncing server was successfully __TYPE__.
+Please configure the Standard Notes web app or mobile app to use this syninc server: https://__DOMAIN____PATH_URL__/
+__CONFIG_PANEL__
+__EXTENSIONS__
diff --git a/conf/nginx.conf b/conf/nginx.conf
index 6f55e7c..6419998 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -1,8 +1,3 @@
-location = /favicon.ico {
- alias /opt/yunohost/snserver/live/public/favicon/favicon.ico;
- expires 30d;
-}
-
location __PATH__/ {
alias __FINALPATH__/live/public ;
@@ -18,5 +13,5 @@ location __PATH__/ {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
- more_set_headers "X-Frame-Options" : "allow-from __ACCESS_DOMAIN__";
+ more_set_headers "X-Frame-Options: allow-from __ACCESS_DOMAIN__";
}
diff --git a/scripts/_common.sh b/scripts/_common.sh
index 02ec33c..dc6d9da 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -43,6 +43,145 @@ exec_as() {
# EXPERIMENTAL HELPERS
#=================================================
+# Send an email to inform the administrator
+#
+# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
+# | arg: -m --app_message= - The file with the content to send to the administrator.
+# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
+# example: "root admin@domain"
+# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
+# example: "root admin@domain user1 user2"
+# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
+ynh_send_readme_to_admin() {
+ # Declare an array to define the options of this helper.
+ declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
+ local app_message
+ local recipients
+ local type
+ # Manage arguments with getopts
+
+ ynh_handle_getopts_args "$@"
+ app_message="${app_message:-}"
+ recipients="${recipients:-root}"
+ type="${type:-install}"
+
+ # Get the value of admin_mail_html
+ admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
+ admin_mail_html="${admin_mail_html:-0}"
+
+ # Retrieve the email of users
+ find_mails () {
+ local list_mails="$1"
+ local mail
+ local recipients=" "
+ # Read each mail in argument
+ for mail in $list_mails
+ do
+ # Keep root or a real email address as it is
+ if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
+ then
+ recipients="$recipients $mail"
+ else
+ # But replace an user name without a domain after by its email
+ if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
+ then
+ recipients="$recipients $mail"
+ fi
+ fi
+ done
+ echo "$recipients"
+ }
+ recipients=$(find_mails "$recipients")
+
+ # Subject base
+ local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
+
+ # Adapt the subject according to the type of mail required.
+ if [ "$type" = "backup" ]; then
+ mail_subject="$mail_subject has just been backup."
+ elif [ "$type" = "change_url" ]; then
+ mail_subject="$mail_subject has just been moved to a new URL!"
+ elif [ "$type" = "remove" ]; then
+ mail_subject="$mail_subject has just been removed!"
+ elif [ "$type" = "restore" ]; then
+ mail_subject="$mail_subject has just been restored!"
+ elif [ "$type" = "upgrade" ]; then
+ mail_subject="$mail_subject has just been upgraded!"
+ else # install
+ mail_subject="$mail_subject has just been installed!"
+ fi
+
+ local mail_message="This is an automated message from your beloved YunoHost server.
+
+Specific information for the application $app.
+
+$(if [ -n "$app_message" ]
+then
+ cat "$app_message"
+else
+ echo "...No specific information..."
+fi)
+
+---
+Automatic diagnosis data from YunoHost
+
+__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
+
+ # Store the message into a file for further modifications.
+ echo "$mail_message" > mail_to_send
+
+ # If a html email is required. Apply html tags to the message.
+ if [ "$admin_mail_html" -eq 1 ]
+ then
+ # Insert 'br' tags at each ending of lines.
+ ynh_replace_string "$" "
" mail_to_send
+
+ # Insert starting HTML tags
+ sed --in-place '1s@^@\n\n
" mail_to_send + ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send + + # Insert finishing HTML tags + echo -e "\n\n" >> mail_to_send + + # Otherwise, remove tags to keep a plain text. + else + # Remove URL tags + ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send + ynh_replace_string "__URL_TAG2__" ": " mail_to_send + + # Remove PRE tags + ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send + fi + + # Define binary to use for mail command + if [ -e /usr/bin/bsd-mailx ] + then + local mail_bin=/usr/bin/bsd-mailx + else + local mail_bin=/usr/bin/mail.mailutils + fi + + if [ "$admin_mail_html" -eq 1 ] + then + content_type="text/html" + else + content_type="text/plain" + fi + + # Send the email to the recipients + cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients" +} + #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/change_url b/scripts/change_url index 29023a0..8aefeb4 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -167,6 +167,31 @@ ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# SEND A README FOR THE ADMIN +#================================================= +ynh_script_progression --message="Sending a readme for the admin..." + +admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" + +message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\ +You changed the url of the syncing server. All extensions installed from here must be reinstalled by the users." +config_panel="You can configure this app by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__" + +ynh_replace_string --match_string="__TYPE__" --replace_string="changed the url" --target_file="../conf/message" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message" + +if [ $install_extensions ] +then + ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_extensions" --target_file="../conf/message" +else + ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="" --target_file="../conf/message" +fi +ynh_replace_string --match_string="__CONFIG_PANEL__" --replace_string="$config_panel" --target_file="../conf/message" + +ynh_send_readme_to_admin --app_message="../conf/message" --type='upgrade' + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index f5c91a9..1060cb2 100755 --- a/scripts/install +++ b/scripts/install @@ -279,6 +279,34 @@ ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# SEND A README FOR THE ADMIN +#================================================= +ynh_script_progression --message="Sending a readme for the admin..." + +message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\ +If you want to change the url of the syncing server all extensions from here have to be reinstalled be the users." +message_no_extensions="You have no extensions installed.\ +You can configure this app by using the config-panel" + +admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" +config_panel="You can configure this app by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__" + +ynh_replace_string --match_string="__TYPE__" --replace_string="installed" --target_file="../conf/message" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message" + +if [ $install_extensions ] +then + ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_extensions" --target_file="../conf/message" +else + ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_no_extensions" --target_file="../conf/message" +fi +ynh_replace_string --match_string="__CONFIG_PANEL__" --replace_string="$config_panel" --target_file="../conf/message" + +ynh_send_readme_to_admin --app_message="../conf/message" --type='install' + +echo ../conf/message #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 62997c3..b5fe754 100755 --- a/scripts/restore +++ b/scripts/restore @@ -35,6 +35,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +install_extensions=$(ynh_app_setting_get --app=$app --key=install_extensions) #================================================= # CHECK IF THE APP CAN BE RESTORED diff --git a/scripts/upgrade b/scripts/upgrade index 7a7cdc3..1ba1cf7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -25,6 +25,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) port=$(ynh_app_setting_get --app=$app --key=port) +install_extensions=(ynh_app_setting_get --app=$app --key=install_extensions) access_domain=(ynh_app_setting_get --app=$app --key=access_domain) #================================================= @@ -305,6 +306,33 @@ ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# SEND A README FOR THE ADMIN +#================================================= +ynh_script_progression --message="Sending a readme for the admin..." + +message_extensions="To install extensions open this page: https://$domain$path_url/extensions/\ +If you want to change the url of the syncing server all extensions from here have to be reinstalled be the users." +message_no_extensions="You have no extensions installed.\ +You can configure this app by using the config-panel" + +admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app" +config_panel="You can configure this app by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__" + +ynh_replace_string --match_string="__TYPE__" --replace_string="installed" --target_file="../conf/message" +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" +ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message" + +if [ $install_extensions ] +then + ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_extensions" --target_file="../conf/message" +else + ynh_replace_string --match_string="__EXTENSIONS__" --replace_string="$message_no_extensions" --target_file="../conf/message" +fi +ynh_replace_string --match_string="__CONFIG_PANEL__" --replace_string="$config_panel" --target_file="../conf/message" + +ynh_send_readme_to_admin --app_message="../conf/message" --type='upgrade' + #================================================= # END OF SCRIPT #=================================================