mirror of
https://github.com/YunoHost-Apps/flarum_ynh.git
synced 2024-09-03 18:36:24 +02:00
Merge pull request #60 from YunoHost-Apps/patch-ssowat
SSOwat reintegration
This commit is contained in:
commit
97e29191b5
2 changed files with 13 additions and 67 deletions
|
@ -1,30 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Retrieve arguments
|
|
||||||
username=$1
|
|
||||||
app=#APP#
|
|
||||||
|
|
||||||
# Source app helpers
|
|
||||||
source /usr/share/yunohost/helpers
|
|
||||||
|
|
||||||
domain=$(</etc/yunohost/current_host)
|
|
||||||
path=$(ynh_app_setting_get $app path)
|
|
||||||
|
|
||||||
# Adding trailing slash to path
|
|
||||||
len=${#path}-1
|
|
||||||
if [ "${path:len}" != "/" ]; then
|
|
||||||
path=$path"/"
|
|
||||||
fi
|
|
||||||
|
|
||||||
userpass=$(ynh_string_random 16)
|
|
||||||
usermail=$(ynh_user_get_info $username 'mail')
|
|
||||||
data='{"data":{"attributes":{"username":"'$username'","email":"'$usermail'","password":"'$userpass'","ssowat_id":"'$username'"}}}'
|
|
||||||
curl -k -i \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-H "Authentication: Token $roottoken" \
|
|
||||||
-X POST -d "$data" \
|
|
||||||
-L https://${domain}${path}api/users
|
|
||||||
usersql="UPDATE users SET ssowat_id = '$username' WHERE username = '$username'"
|
|
||||||
ynh_mysql_execute_as_root "$usersql" $dbname
|
|
|
@ -210,49 +210,25 @@ if [[ -n $admin && -n $title ]]; then
|
||||||
php -d memory_limit=-1 flarum install -f configuration.yml
|
php -d memory_limit=-1 flarum install -f configuration.yml
|
||||||
ynh_secure_remove $finalflarumconf
|
ynh_secure_remove $finalflarumconf
|
||||||
|
|
||||||
# Generate and add root token for user creation and deletion
|
|
||||||
roottoken=$(ynh_string_random 40)
|
|
||||||
apitablesql="CREATE TABLE IF NOT EXISTS api_keys (api_key TEXT(40) NOT NULL)"
|
|
||||||
rootsql="INSERT INTO api_keys VALUES ('"$roottoken"')"
|
|
||||||
ynh_mysql_execute_as_root "$apitablesql" $db_name
|
|
||||||
ynh_mysql_execute_as_root "$rootsql" $db_name
|
|
||||||
ynh_app_setting_set "$app" root_token "$roottoken"
|
|
||||||
|
|
||||||
# Install the SSOwat auth extension
|
# Install the SSOwat auth extension
|
||||||
#sudo su - www-data -s /bin/bash -c "cd $final_path && /opt/flarum_composer/composer require 'tituspijean/flarum-ext-auth-ssowat:*@dev'"
|
sudo su - www-data -s /bin/bash -c "cd $final_path && $composer_path/composer require 'tituspijean/flarum-ext-auth-ssowat:*@dev' --ansi"
|
||||||
|
|
||||||
# Configure SSOwat auth extension
|
# Configure SSOwat auth extension
|
||||||
#ssowatdomain=$(</etc/yunohost/current_host)
|
ssowatdomain=$(</etc/yunohost/current_host)
|
||||||
#data='{"flarum-ext-auth-ssowat.address": "'$ssowatdomain'","flarum-ext-auth-ssowat.onlyUse": true}'
|
sql_command="INSERT INTO \`settings\` (\`key\`, \`value\`) VALUES ('flarum-ext-auth-ssowat.address', '$ssowatdomain'), ('flarum-ext-auth-ssowat.onlyUse', '0');"
|
||||||
#rep=$(curl -s -o /dev/null -w "%{http_code}" -k -i \
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||||
# -H "Content-Type: application/json" \
|
|
||||||
# -H "Authorization: Token $roottoken; userId=1" \
|
# Enable SSOwat auth extension
|
||||||
# -X POST -d "$data" \
|
sql_command="SELECT \`value\` FROM settings WHERE \`key\` = 'extensions_enabled'"
|
||||||
# -L https://${domain}${path}/api/settings )
|
old_extensions_enabled=$(ynh_mysql_execute_as_root "$sql_command" $db_name | tail -1)
|
||||||
#
|
addition=",\"tituspijean-auth-ssowat\"]"
|
||||||
#if [[ $rep != 204 ]]; then
|
new_extensions_enabled=${old_extensions_enabled::-1}$addition
|
||||||
# ynh_die "ERROR: Could not configure SSOwat extension"
|
sql_command="UPDATE \`settings\` SET \`value\`='$new_extensions_enabled' WHERE \`key\`='extensions_enabled';"
|
||||||
#fi
|
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||||
|
|
||||||
# Create missing users
|
|
||||||
for username in $(ynh_user_list); do
|
|
||||||
if [ "$username" == "$admin" ]; then continue; else
|
|
||||||
userpass=$(ynh_string_random 16)
|
|
||||||
usermail=$(ynh_user_get_info $username 'mail')
|
|
||||||
data='{"data":{"attributes":{"username":"'$username'","email":"'$usermail'","password":"'$userpass'"}}}'
|
|
||||||
rep=$(curl -s -o /dev/null -w "%{http_code}" -k -i \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-H "Authentication: Token $roottoken" \
|
|
||||||
-X POST -d "$data" \
|
|
||||||
-L https://${domain}${path_url}/api/users )
|
|
||||||
if [[ $rep != 201 ]]; then
|
|
||||||
ynh_die "ERROR: Flarum account creation failed for $username"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
app_message="User : $admin, password : $admin_pwd
|
app_message="User : $admin, password : $admin_pwd
|
||||||
Change your password!
|
Change your password!
|
||||||
Your forum is accessible at https://$domain/$path_url"
|
Your forum is accessible at https://$domain$path_url"
|
||||||
>&2 echo $app_message
|
>&2 echo $app_message
|
||||||
ynh_send_readme_to_admin "$app_message" "$admin"
|
ynh_send_readme_to_admin "$app_message" "$admin"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue