diff --git a/conf/.env.example b/conf/.env.example index c829544..b7c1110 100644 --- a/conf/.env.example +++ b/conf/.env.example @@ -52,11 +52,18 @@ LDAP_SERVER=ldap://127.0.0.1:389 LDAP_BASE_DN=ou=users,dc=yunohost,dc=org LDAP_DN=false LDAP_PASS=false -LDAP_USER_FILTER="(&(|(objectclass=posixAccount))(uid={{username}})(permission=cn=__APP__.main,ou=permission,dc=yunohost,dc=org))" -LDAP_VERSION=false +LDAP_USER_FILTER=(&(|(objectclass=posixAccount))(uid={{username}})(permission=cn=__APP__.main,ou=permission,dc=yunohost,dc=org)) +LDAP_VERSION=3 LDAP_TLS_INSECURE=false LDAP_ID_ATTRIBUTE=uid LDAP_EMAIL_ATTRIBUTE=mail LDAP_DISPLAY_NAME_ATTRIBUTE=cn LDAP_FOLLOW_REFERRALS=true LDAP_DUMP_USER_DETAILS=false + +# Set both the cache and session to use Redis +CACHE_DRIVER=redis +SESSION_DRIVER=redis + +# Example of using a single local Redis server +REDIS_SERVERS=127.0.0.1:6379:__REDIS_DB__ diff --git a/scripts/_common.sh b/scripts/_common.sh index 4471fe0..57004cd 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -21,3 +21,45 @@ YNH_COMPOSER_VERSION=2.1.1 #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +#================================================= +# REDIS HELPERS +#================================================= + +# get the first available redis database +# +# usage: ynh_redis_get_free_db +# | returns: the database number to use +ynh_redis_get_free_db() { + local result max db + result="$(redis-cli INFO keyspace)" + + # get the num + max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") + + db=0 + # default Debian setting is 15 databases + for i in $(seq 0 "$max") + do + if ! echo "$result" | grep -q "db$i" + then + db=$i + break 1 + fi + db=-1 + done + + test "$db" -eq -1 && ynh_die --message="No available Redis databases..." + + echo "$db" +} + +# Create a master password and set up global settings +# Please always call this script in install and restore scripts +# +# usage: ynh_redis_remove_db database +# | arg: database - the database to erase +ynh_redis_remove_db() { + local db=$1 + redis-cli -n "$db" flushall +} diff --git a/scripts/install b/scripts/install index 4b21d41..fefddee 100644 --- a/scripts/install +++ b/scripts/install @@ -108,6 +108,10 @@ ynh_install_composer --phpversion=$phpversion --workdir=$final_path --install_ar # MODIFY A CONFIG FILE #================================================= +# Configure redis +redis_db=$(ynh_redis_get_free_db) +ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" + mail_pwd=$(ynh_string_random --length=12) ynh_add_config --template=../conf/.env.example --destination=$final_path/.env chmod 600 $final_path/.env diff --git a/scripts/remove b/scripts/remove index 5d4bbf6..b43ce7a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) +redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) #================================================= # REMOVE THE MYSQL DATABASE @@ -29,6 +30,13 @@ ynh_script_progression --message="Removing the MySQL database..." --weight=1 # Remove a database if it exists, along with the associated user ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +#================================================= +# REMOVE THE REDIS DATABASE +#================================================= +ynh_script_progression --message="Removing the redis database..." + +ynh_redis_remove_db "$redis_db" + #================================================= # REMOVE APP MAIN DIR #=================================================