mirror of
https://github.com/YunoHost-Apps/flarum_ynh.git
synced 2024-09-03 18:36:24 +02:00
SSOwat integration and other improvements
Closes #5, closes #12, closes #19 and closes #21 Breaks /folder nginx configuration ?
This commit is contained in:
parent
98d664c45d
commit
ff45b2c39b
5 changed files with 93 additions and 20 deletions
|
@ -56,5 +56,5 @@ location ^~ YNH_WWW_PATH {
|
||||||
|
|
||||||
|
|
||||||
# Include SSOWAT user panel.
|
# Include SSOWAT user panel.
|
||||||
include conf.d/yunohost_panel.conf.inc;
|
# include conf.d/yunohost_panel.conf.inc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,5 +56,5 @@ location ^~ / {
|
||||||
|
|
||||||
|
|
||||||
# Include SSOWAT user panel.
|
# Include SSOWAT user panel.
|
||||||
include conf.d/yunohost_panel.conf.inc;
|
# include conf.d/yunohost_panel.conf.inc;
|
||||||
}
|
}
|
||||||
|
|
30
hooks/post_user_create
Normal file
30
hooks/post_user_create
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/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
|
|
@ -9,7 +9,7 @@
|
||||||
},
|
},
|
||||||
"url": "http://flarum.org/",
|
"url": "http://flarum.org/",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.1.0-beta.5",
|
"version": "0.1.0-beta.6",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
"name": "Titus PiJean",
|
"name": "Titus PiJean",
|
||||||
"email": "tituspijean@outlook.com"
|
"email": "tituspijean@outlook.com"
|
||||||
|
@ -50,24 +50,13 @@
|
||||||
"name": "admin",
|
"name": "admin",
|
||||||
"type": "user",
|
"type": "user",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Choose an admin user",
|
"en": "Choose the admin user",
|
||||||
"fr": "Choisissez l’administrateur",
|
"fr": "Choisissez l’administrateur",
|
||||||
"de": "Wählen einen Administrator"
|
"de": "Wählen einen Administrator"
|
||||||
},
|
},
|
||||||
"example": "johndoe",
|
"example": "johndoe",
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "adminpass",
|
|
||||||
"type": "password",
|
|
||||||
"ask": {
|
|
||||||
"en": "Put your password (8 characters minimum)",
|
|
||||||
"fr": "Insérez votre mot de passe (8 caractères minimum)",
|
|
||||||
"de": "Einfügen eure Passwort (mindestens 8 Zeichen)"
|
|
||||||
},
|
|
||||||
"example": "********",
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "title",
|
"name": "title",
|
||||||
"ask": {
|
"ask": {
|
||||||
|
|
|
@ -17,20 +17,20 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path=$YNH_APP_ARG_PATH
|
path=${YNH_APP_ARG_PATH%/}
|
||||||
admin=$YNH_APP_ARG_ADMIN
|
admin=$YNH_APP_ARG_ADMIN
|
||||||
adminpass=$YNH_APP_ARG_ADMINPASS
|
|
||||||
title=$YNH_APP_ARG_TITLE
|
title=$YNH_APP_ARG_TITLE
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
www_path=/var/www
|
www_path=/var/www
|
||||||
final_path=$www_path/$app
|
final_path=$www_path/$app
|
||||||
|
|
||||||
# Source YunoHost helpers
|
# Source YunoHost helpers$
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Save app settings
|
# Save app settings
|
||||||
ynh_app_setting_set "$app" admin "$admin"
|
ynh_app_setting_set "$app" admin "$admin"
|
||||||
ynh_app_setting_set "$app" is_public "$is_public"
|
ynh_app_setting_set "$app" is_public "$is_public"
|
||||||
|
ynh_app_setting_set "$app" path "$path"
|
||||||
|
|
||||||
# Check domain/path availability
|
# Check domain/path availability
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||||
|
@ -89,7 +89,7 @@ ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
||||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||||
|
|
||||||
### Nginx ###
|
### Nginx ###
|
||||||
if [ $path = "/" ]; then
|
if [ $path = "" ]; then
|
||||||
nginx_conf=../conf/nginx_root.conf
|
nginx_conf=../conf/nginx_root.conf
|
||||||
else
|
else
|
||||||
nginx_conf=../conf/nginx.conf
|
nginx_conf=../conf/nginx.conf
|
||||||
|
@ -113,12 +113,18 @@ if [[ $is_public -eq 1 ]]; then
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||||
fi
|
fi
|
||||||
|
ynh_app_setting_set "$app" skipped_uris "/api"
|
||||||
|
sudo yunohost app ssowatconf
|
||||||
|
|
||||||
# Reload services
|
# Reload services
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
||||||
|
# Install the SSOwat auth extension
|
||||||
|
sudo su - www-data -s /bin/bash -c "cd $final_path && composer require 'tituspijean/flarum-ext-auth-ssowat:*@dev'"
|
||||||
|
|
||||||
### POST-INSTALL ###
|
### POST-INSTALL ###
|
||||||
if [[ -n $adminpass && -n $title ]]; then
|
if [[ -n $admin && -n $title ]]; then
|
||||||
|
adminpass=$(ynh_string_random 8)
|
||||||
sed -i "s@YNH_APP_DOMAIN@$domain@g" ../sources/configuration.yml
|
sed -i "s@YNH_APP_DOMAIN@$domain@g" ../sources/configuration.yml
|
||||||
sed -i "s@/YNH_WWW_PATH@$path@g" ../sources/configuration.yml
|
sed -i "s@/YNH_WWW_PATH@$path@g" ../sources/configuration.yml
|
||||||
sed -i "s@YNH_WWW_APP@$app@g" ../sources/configuration.yml
|
sed -i "s@YNH_WWW_APP@$app@g" ../sources/configuration.yml
|
||||||
|
@ -141,3 +147,51 @@ ynh_mysql_execute_as_root "$rootsql" $dbname
|
||||||
ynh_app_setting_set "$app" root_token "$roottoken"
|
ynh_app_setting_set "$app" root_token "$roottoken"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Configure SSOwat auth extension
|
||||||
|
ssowatdomain=$(</etc/yunohost/current_host)
|
||||||
|
data='{"flarum-ext-auth-ssowat.address": "'$ssowatdomain'"}'
|
||||||
|
rep=$(curl -s -o /dev/null -w "%{http_code}" -k -i \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Token $roottoken; userId=1" \
|
||||||
|
-X POST -d "$data" \
|
||||||
|
-L https://${domain}${path}/api/settings )
|
||||||
|
echo $path
|
||||||
|
exit 0
|
||||||
|
if [[ $rep != 204 ]]; then
|
||||||
|
echo "SSOwat domain setting failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
data='{"flarum-ext-auth-ssowat.onlyUse": true}'
|
||||||
|
rep=$(curl -s -o /dev/null -w "%{http_code}" -k -i \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Token $roottoken; userId=1" \
|
||||||
|
-X POST -d "$data" \
|
||||||
|
-L https://${domain}${path}/api/settings )
|
||||||
|
if [[ $rep != 204 ]]; then
|
||||||
|
echo "SSOwat auth exclusivity failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enable the selected admin to login with SSOwat
|
||||||
|
adminsql="UPDATE users SET ssowat_id = '$admin' WHERE username = '$admin'"
|
||||||
|
ynh_mysql_execute_as_root "$adminsql" $dbname
|
||||||
|
|
||||||
|
# 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}/api/users )
|
||||||
|
if [[ $rep != 201 ]]; then
|
||||||
|
echo "Flarum account creation failed for $username"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
usersql="UPDATE users SET ssowat_id = '$username' WHERE username = '$username'"
|
||||||
|
ynh_mysql_execute_as_root "$usersql" $dbname
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
Loading…
Add table
Reference in a new issue