|
@ -1,8 +1,7 @@ |
|
|
#!/bin/sh |
|
|
#!/bin/sh |
|
|
|
|
|
|
|
|
# TODO : |
|
|
# TODO : |
|
|
# - add root user detection |
|
|
|
|
|
# - verify curl output to prevent overwriting config file with an HTTP answer |
|
|
|
|
|
|
|
|
# - add root user detection (only warn) |
|
|
# - verify trailling slash existenz at the end of the URL param |
|
|
# - verify trailling slash existenz at the end of the URL param |
|
|
|
|
|
|
|
|
VER=0.1 |
|
|
VER=0.1 |
|
@ -139,18 +138,23 @@ _download() { |
|
|
|
|
|
|
|
|
WGPORTAL_APIURL=$WGPORTAL_URL"api/v1/provisioning/peer" |
|
|
WGPORTAL_APIURL=$WGPORTAL_URL"api/v1/provisioning/peer" |
|
|
_debug "GET request to $WGPORTAL_APIURL" |
|
|
_debug "GET request to $WGPORTAL_APIURL" |
|
|
HTTP_STATUS=$(curl -w "%{http_code}" -G -s -o $WG_CONFFILE --user $username:$password --data-urlencode "PublicKey=$wgpubkey" -X GET $WGPORTAL_APIURL -H "accept: text/plain") |
|
|
|
|
|
|
|
|
HTTP_RESPONSE=$(curl -G -s --write-out "HTTPSTATUS:%{http_code}" --user $username:$password --data-urlencode "PublicKey=$wgpubkey" -X GET $WGPORTAL_APIURL -H "accept: text/plain") |
|
|
res=$? |
|
|
res=$? |
|
|
if [ "$res" != "0" ]; then |
|
|
if [ "$res" != "0" ]; then |
|
|
echo "the curl command failed with: $res" |
|
|
echo "the curl command failed with: $res" |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ $HTTP_STATUS -ne 200 ]; then |
|
|
|
|
|
printf "Curl returned HTTP code %s\n" "$HTTP_STATUS" |
|
|
|
|
|
exit 1; |
|
|
|
|
|
|
|
|
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -E 's/HTTPSTATUS\:[0-9]{3}$//') |
|
|
|
|
|
HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -E 's/.*HTTPSTATUS:([0-9]{3})$/\1/') |
|
|
|
|
|
|
|
|
|
|
|
if [ $HTTP_STATUS = "200" ]; then |
|
|
|
|
|
echo "$HTTP_BODY" > $WG_CONFFILE |
|
|
|
|
|
printf "WG config successfully downloaded at %s\n" "$WG_CONFFILE" |
|
|
|
|
|
return |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
printf "WG config successfully download at %s\n" "$WG_CONFFILE" |
|
|
|
|
|
|
|
|
printf "Curl returned HTTP code %s\n" "$HTTP_STATUS" |
|
|
|
|
|
exit 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_install() { |
|
|
_install() { |
|
|