2017-06-05 13:04:03 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|
2019-03-05 23:17:15 +01:00
|
|
|
# COMMON VARIABLES
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|
|
|
|
|
2019-03-05 23:17:15 +01:00
|
|
|
#=================================================
|
|
|
|
# PERSONAL HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|
|
|
|
# EXPERIMENTAL HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2021-02-22 11:52:00 +01:00
|
|
|
ynh_local_curl_csrf () {
|
|
|
|
# Define url of page to curl
|
2021-02-25 17:42:25 +01:00
|
|
|
local local_page=$1
|
2024-01-24 11:39:24 +01:00
|
|
|
local full_path=$path$local_page
|
2021-02-22 11:52:00 +01:00
|
|
|
|
2024-01-24 11:39:24 +01:00
|
|
|
if [ "${path}" == "/" ]; then
|
2021-02-22 11:52:00 +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
|
2024-01-24 11:39:24 +01:00
|
|
|
|
2021-02-22 11:52:00 +01:00
|
|
|
local cookiefile=/tmp/ynh-$app-cookie.txt
|
|
|
|
touch $cookiefile
|
2022-07-29 22:43:23 +02:00
|
|
|
chown $app $cookiefile
|
2021-02-22 11:52:00 +01:00
|
|
|
chmod 700 $cookiefile
|
|
|
|
|
|
|
|
# Curl the URL for the CSRF token
|
|
|
|
local code_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 "input name=\"code\""`
|
|
|
|
|
|
|
|
local code=${code_line:40:53}
|
|
|
|
POST_data="${POST_data}&code=${code}"
|
2024-01-24 11:39:24 +01:00
|
|
|
|
2021-02-22 11:52:00 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-03-26 18:20:59 +01:00
|
|
|
#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
|
|
|
|
}
|
2021-02-22 11:52:00 +01:00
|
|
|
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|
2019-02-10 20:04:23 +01:00
|
|
|
# FUTURE OFFICIAL HELPERS
|
2019-02-10 15:02:38 +01:00
|
|
|
#=================================================
|