Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmuc-mesh-vpn-wireguard: add headers #111

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ local fw_release = assert(infos.firmware_release, "Malformed gluon-info, missing

print(string.format("gluon/%s (%s) OpenWrt/%s (kernel/%s; %s) firmware/%s",
gluon_version, board_name, openwrt_version, kernel, target, fw_release))

print(gluon_version)
print(board_name)
print(openwrt_version)
print(kernel)
print(target)
print(fw_release)
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,46 @@ is_loadbalancing_enabled() {
return 0
}

customwget() {
wget_infos=$(lua /lib/gluon/gluon-mesh-wireguard-vxlan/get-wget-infos.lua)
user_agent=$(echo "$wget_infos" | sed -n 1p)
gluon_version=$(echo "$wget_infos" | sed -n 2p)
board_name=$(echo "$wget_infos" | sed -n 3p)
openwrt_version=$(echo "$wget_infos" | sed -n 4p)
kernel=$(echo "$wget_infos" | sed -n 5p)
target=$(echo "$wget_infos" | sed -n 6p)
fw_release=$(echo "$wget_infos" | sed -n 7p)


# This header check is only required for OpenWrt versions <= 23.05,
# as headers are first available in OpenWrt 24.10.
headerret=0
wget -q "http://[::1]" --header="X: X" 2>/dev/null || headerret=$?
# returns Network Failure =4 if headers for wget are available,
# and Generic Error =1 if no headers for wget are available.
if [ "$headerret" -eq 1 ]; then
force_wan_connection wget -q -U "$user_agent" -O- "$@"

else
force_wan_connection wget -q -U "$user_agent" \
--header="X-Gluon-Version: $gluon_version" \
--header="X-Board-Name: $board_name" \
--header="X-Openwrt-Version: $openwrt_version" \
--header="X-Kernel-Version: $kernel" \
--header="X-Target-Name: $target" \
--header="X-Firmware-Version: $fw_release" \
-O- "$@"
fi
}

get_wgkex_data() {
local version user_agent
version="$1"
WGKEX_BROKER="$PROTO://$WGKEX_BROKER_BASE_PATH/api/$version/wg/key/exchange"
user_agent=$(lua /lib/gluon/gluon-mesh-wireguard-vxlan/get-user-agent-infos.lua)

logger -p info -t checkuplink "Contacting wgkex broker $WGKEX_BROKER"

if ! WGKEX_DATA=$(force_wan_connection wget -q -U "$user_agent" -O- --post-data='{"domain": "'"$SEGMENT"'","public_key": "'"$PUBLICKEY"'"}' "$WGKEX_BROKER"); then
if ! WGKEX_DATA=$(customwget --post-data='{"domain": "'"$SEGMENT"'","public_key": "'"$PUBLICKEY"'"}' "$WGKEX_BROKER"); then
logger -p err -t checkuplink "Contacting wgkex broker failed, response: $WGKEX_DATA"
else
logger -p info -t checkuplink "Got data from wgkex broker: $WGKEX_DATA"
Expand Down