diff --git a/actions.json b/actions.json new file mode 100644 index 0000000..2f7577b --- /dev/null +++ b/actions.json @@ -0,0 +1,75 @@ +[ + { + "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 ?" + }, + "default": true + } + ] + }, + { + "id": "change_password", + "name": "Change the admin password", + "command": "/bin/bash scripts/actions/change_password", + "user": "root", + "accepted_return_codes": [ + 0 + ], + "description": { + "en": "Change the admin password of the app.", + "fr": "Change le mot de passe administrateur de l'app." + }, + "arguments": [ + { + "name": "password", + "type": "password", + "ask": { + "en": "New password", + "fr": "Nouveau mot de passe" + } + } + ] + }, + { + "id": "change_theme", + "name": "Change the theme", + "command": "/bin/bash scripts/actions/change_theme", + "user": "root", + "accepted_return_codes": [ + 0 + ], + "description": { + "en": "Change the theme of the app.", + "fr": "Change le thème de l'app." + }, + "arguments": [ + { + "name": "theme", + "type": "string", + "ask": { + "en": "Choose a theme", + "fr": "Choisissez un theme" + }, + "choices": [ + "default", + "milligram" + ], + "default": "milligram" + } + ] + } +] \ No newline at end of file diff --git a/conf/lstu.conf.template b/conf/lstu.conf.template index 7554ed2..e5be2ad 100644 --- a/conf/lstu.conf.template +++ b/conf/lstu.conf.template @@ -185,7 +185,7 @@ # bind_pwd => '', # search bind password user_attr => 'uid', # user attribute (uid, mail, sAMAccountName, etc.) # user_filter => '(!(uid=ldap_user))', # user filter (to exclude some users, etc.) - }, + }, #end of ldap conf # set `htpasswd` if you want to use an htpasswd file instead of ldap # create the file with `htpasswd -c lstu.passwd user`, update it with `htpasswd lstu.passwd user2` diff --git a/conf/nginx.conf b/conf/nginx.conf index 3e674d7..028fa01 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -3,9 +3,6 @@ location __PATH__ { rewrite ^ https://$server_name$request_uri? permanent; } - #--PRIVATE--# Include SSOWAT user panel. - #--PRIVATE--include conf.d/yunohost_panel.conf.inc; - access_log /var/log/nginx/lstu.access.log; error_log /var/log/nginx/lstu.error.log; @@ -19,4 +16,7 @@ location __PATH__ { # We expect the downsteam servers to redirect to the right hostname, so don't do any rewrite$ proxy_redirect off; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } diff --git a/scripts/_common.sh b/scripts/_common.sh index ecb2ba3..b41d451 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,5 +1,9 @@ #!/bin/bash +set_config_file() { + +} + # Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started # # usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ] diff --git a/scripts/actions/public_private b/scripts/actions/public_private new file mode 100755 index 0000000..337c444 --- /dev/null +++ b/scripts/actions/public_private @@ -0,0 +1,94 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= +ynh_script_progression --message="Retrieve arguments from the manifest" + +# Get is_public +is_public=${YNH_ACTION_IS_PUBLIC} + +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} + +final_path=$(ynh_app_setting_get $app final_path) + +#================================================= +# 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 + public_private="private" +else + public_private="public" +fi +ynh_script_progression --message="Move the application to $public_private" --weight=3 + +ynh_app_setting_set $app skipped_uris "/" +if [ $is_public -eq 0 ]; +then # If the app is private, only the shortened URLs are publics + if [ "$path_url" == "/" ]; then + path_url="" + fi + ynh_app_setting_set $app protected_regex "$domain$path_url/login$","$domain$path_url/logout$","$domain$path_url/api$","$domain$path_url/extensions$","$domain$path_url/stats$","$domain$path_url/d/.*$","$domain$path_url/a$","$domain$path_url/$" + + ynh_replace_string "#ldap => {" "ldap => {" "${final_path}/lstu.conf" + ynh_replace_string "#uri => 'ldap://localhost:389'," "uri => 'ldap://localhost:389'," "${final_path}/lstu.conf" + ynh_replace_string "#user_tree => 'dc=yunohost,dc=org'," "user_tree => 'dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "#bind_dn => 'ou=users,dc=yunohost,dc=org'," "bind_dn => 'ou=users,dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "#user_attr => 'uid'," "user_attr => 'uid'," "${final_path}/lstu.conf" + ynh_replace_string "#}, #end of ldap conf" "}, #end of ldap conf" "${final_path}/lstu.conf" +else + ynh_app_setting_delete $app protected_regex + + ynh_replace_string "ldap => {" "#ldap => {" "${final_path}/lstu.conf" + ynh_replace_string "uri => 'ldap://localhost:389'," "#uri => 'ldap://localhost:389'," "${final_path}/lstu.conf" + ynh_replace_string "user_tree => 'dc=yunohost,dc=org'," "#user_tree => 'dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "bind_dn => 'ou=users,dc=yunohost,dc=org'," "#bind_dn => 'ou=users,dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "user_attr => 'uid'," "#user_attr => 'uid'," "${final_path}/lstu.conf" + ynh_replace_string "}, #end of ldap conf" "#}, #end of ldap conf" "${final_path}/lstu.conf" +fi + +ynh_script_progression --message="Reconfigure SSOwat" +# Regen ssowat configuration +yunohost app ssowatconf + +# Update the config of the app +ynh_app_setting_set $app is_public $is_public + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reload $app" + +ynh_systemd_action -n $app -a reload -l "Reloaded Shortened URLs service." -p "systemd" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Execution completed" --last diff --git a/scripts/install b/scripts/install index 1f4d075..3986617 100644 --- a/scripts/install +++ b/scripts/install @@ -172,8 +172,22 @@ then # If the app is private, only the shortened URLs are publics path_url="" fi ynh_app_setting_set $app protected_regex "$domain$path_url/login$","$domain$path_url/logout$","$domain$path_url/api$","$domain$path_url/extensions$","$domain$path_url/stats$","$domain$path_url/d/.*$","$domain$path_url/a$","$domain$path_url/$" + + ynh_replace_string "#ldap => {" "ldap => {" "${final_path}/lstu.conf" + ynh_replace_string "#uri => 'ldap://localhost:389'," "uri => 'ldap://localhost:389'," "${final_path}/lstu.conf" + ynh_replace_string "#user_tree => 'dc=yunohost,dc=org'," "user_tree => 'dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "#bind_dn => 'ou=users,dc=yunohost,dc=org'," "bind_dn => 'ou=users,dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "#user_attr => 'uid'," "user_attr => 'uid'," "${final_path}/lstu.conf" + ynh_replace_string "#}, #end of ldap conf" "}, #end of ldap conf" "${final_path}/lstu.conf" else - ynh_replace_string "#--PRIVATE--" "" "/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_app_setting_delete $app protected_regex + + ynh_replace_string "ldap => {" "#ldap => {" "${final_path}/lstu.conf" + ynh_replace_string "uri => 'ldap://localhost:389'," "#uri => 'ldap://localhost:389'," "${final_path}/lstu.conf" + ynh_replace_string "user_tree => 'dc=yunohost,dc=org'," "#user_tree => 'dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "bind_dn => 'ou=users,dc=yunohost,dc=org'," "#bind_dn => 'ou=users,dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "user_attr => 'uid'," "#user_attr => 'uid'," "${final_path}/lstu.conf" + ynh_replace_string "}, #end of ldap conf" "#}, #end of ldap conf" "${final_path}/lstu.conf" fi #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index fed6f4f..9b41bb3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -176,8 +176,22 @@ then # If the app is private, only the shortened URLs are publics path_url="" fi ynh_app_setting_set $app protected_regex "$domain$path_url/login$","$domain$path_url/logout$","$domain$path_url/api$","$domain$path_url/extensions$","$domain$path_url/stats$","$domain$path_url/d/.*$","$domain$path_url/a$","$domain$path_url/$" + + ynh_replace_string "#ldap => {" "ldap => {" "${final_path}/lstu.conf" + ynh_replace_string "#uri => 'ldap://localhost:389'," "uri => 'ldap://localhost:389'," "${final_path}/lstu.conf" + ynh_replace_string "#user_tree => 'dc=yunohost,dc=org'," "user_tree => 'dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "#bind_dn => 'ou=users,dc=yunohost,dc=org'," "bind_dn => 'ou=users,dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "#user_attr => 'uid'," "user_attr => 'uid'," "${final_path}/lstu.conf" + ynh_replace_string "#}, #end of ldap conf" "}, #end of ldap conf" "${final_path}/lstu.conf" else - ynh_replace_string "#--PRIVATE--" "" "/etc/nginx/conf.d/$domain.d/$app.conf" + ynh_app_setting_delete $app protected_regex + + ynh_replace_string "ldap => {" "#ldap => {" "${final_path}/lstu.conf" + ynh_replace_string "uri => 'ldap://localhost:389'," "#uri => 'ldap://localhost:389'," "${final_path}/lstu.conf" + ynh_replace_string "user_tree => 'dc=yunohost,dc=org'," "#user_tree => 'dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "bind_dn => 'ou=users,dc=yunohost,dc=org'," "#bind_dn => 'ou=users,dc=yunohost,dc=org'," "${final_path}/lstu.conf" + ynh_replace_string "user_attr => 'uid'," "#user_attr => 'uid'," "${final_path}/lstu.conf" + ynh_replace_string "}, #end of ldap conf" "#}, #end of ldap conf" "${final_path}/lstu.conf" fi #================================================= diff --git a/sources/ajouts/script/lstu b/sources/ajouts/script/lstu deleted file mode 100644 index 900de99..0000000 --- a/sources/ajouts/script/lstu +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -use FindBin; -BEGIN { unshift @INC, "$FindBin::Bin/../lib" } -BEGIN { unshift @INC, "$FindBin::Bin/../local/lib/perl5" } - -# Start command line interface for application -require Mojolicious::Commands; -Mojolicious::Commands->start_app('Mounter');