2021-03-01 09:43:17 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# COMMON VARIABLES
|
|
|
|
#=================================================
|
|
|
|
|
2023-05-31 09:19:09 +02:00
|
|
|
HUMHUB_AUTH_BASIC_VERSION=0.2.0
|
2022-05-18 14:52:14 +02:00
|
|
|
HUMHUB_AUTH_BASIC_PATH="/protected/modules/auth-basic"
|
|
|
|
|
2021-03-01 09:43:17 +01:00
|
|
|
#=================================================
|
|
|
|
# PERSONAL HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
local_curl_csrf () {
|
|
|
|
# Define url of page to curl
|
2023-04-27 09:42:42 +02:00
|
|
|
local local_page=$1
|
2023-04-27 09:44:41 +02:00
|
|
|
local full_path=$path$local_page
|
2021-03-01 09:43:17 +01:00
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
if [ "${path}" == "/" ]; then
|
2021-03-01 09:43:17 +01:00
|
|
|
full_path=$local_page
|
|
|
|
fi
|
|
|
|
|
|
|
|
local full_page_url=https://localhost$full_path
|
|
|
|
|
|
|
|
# Concatenate all other arguments with '&' to prepare POST data
|
|
|
|
local POST_data=""
|
|
|
|
local arg=""
|
|
|
|
for arg in "${@:2}"
|
|
|
|
do
|
|
|
|
POST_data="${POST_data}${arg}&"
|
|
|
|
done
|
|
|
|
if [ -n "$POST_data" ]
|
|
|
|
then
|
|
|
|
# Add --data arg and remove the last character, which is an unecessary '&'
|
|
|
|
POST_data="--data ${POST_data::-1}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Wait untils nginx has fully reloaded (avoid curl fail with http2)
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
local cookiefile=/tmp/ynh-$app-cookie.txt
|
|
|
|
touch $cookiefile
|
|
|
|
chown root $cookiefile
|
|
|
|
chmod 700 $cookiefile
|
|
|
|
|
|
|
|
# Curl the URL for the CSRF token
|
|
|
|
local token_line=`curl --silent --show-error --insecure --location --header "Host: $domain" --resolve $domain:443:127.0.0.1 "$full_page_url" --cookie-jar $cookiefile --cookie $cookiefile | grep 'meta name="csrf-token"'`
|
|
|
|
|
|
|
|
token_line=${token_line##*content=\"}
|
|
|
|
local csrf=${token_line%%\">*}
|
|
|
|
POST_data="${POST_data}&_csrf=${csrf}"
|
|
|
|
|
|
|
|
curl --silent --show-error --insecure --location --header "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url" --cookie-jar $cookiefile --cookie $cookiefile
|
|
|
|
}
|
|
|
|
|
|
|
|
#Convert --data to --data-urlencode before ynh_local_curl
|
|
|
|
myynh_urlencode() {
|
|
|
|
local data
|
|
|
|
if [[ $# != 1 ]]; then
|
|
|
|
echo "Usage: $0 string-to-urlencode"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
data="$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "$1" "")"
|
|
|
|
if [[ $? != 3 ]]; then
|
|
|
|
echo "Unexpected error" 1>&2
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
echo "${data##/?}"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:24:23 +02:00
|
|
|
install_sso() {
|
2022-05-18 14:52:14 +02:00
|
|
|
tmp_auth_basic_module="$(mktemp /tmp/humhub_ynh.XXXXXX)"
|
|
|
|
wget -q -O $tmp_auth_basic_module "https://github.com/smart4life/humhub-auth-basic/archive/refs/tags/$HUMHUB_AUTH_BASIC_VERSION.tar.gz"
|
|
|
|
|
2023-04-27 09:44:41 +02:00
|
|
|
tar xf $tmp_auth_basic_module -C $install_dir/protected/modules
|
|
|
|
mv $install_dir/protected/modules/humhub-auth-basic* $install_dir/$HUMHUB_AUTH_BASIC_PATH
|
2022-05-18 14:52:14 +02:00
|
|
|
|
2022-05-18 15:03:56 +02:00
|
|
|
ynh_secure_remove $tmp_auth_basic_module
|
2022-05-18 14:52:14 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 09:43:17 +01:00
|
|
|
#=================================================
|
|
|
|
# EXPERIMENTAL HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# FUTURE OFFICIAL HELPERS
|
|
|
|
#=================================================
|