From 7b67808af0afac4c5e96e576247735b6e177d36a Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 1 Apr 2024 10:38:17 +0200 Subject: [PATCH] build User Agent --- .../gluon-mesh-wireguard-vxlan/checkuplink | 19 ++++++++++++--- .../get-user-agent-infos.lua | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 ffmuc-mesh-vpn-wireguard-vxlan/luasrc/lib/gluon/gluon-mesh-wireguard-vxlan/get-user-agent-infos.lua diff --git a/ffmuc-mesh-vpn-wireguard-vxlan/files/lib/gluon/gluon-mesh-wireguard-vxlan/checkuplink b/ffmuc-mesh-vpn-wireguard-vxlan/files/lib/gluon/gluon-mesh-wireguard-vxlan/checkuplink index 9ececc4f..3b5afdae 100755 --- a/ffmuc-mesh-vpn-wireguard-vxlan/files/lib/gluon/gluon-mesh-wireguard-vxlan/checkuplink +++ b/ffmuc-mesh-vpn-wireguard-vxlan/files/lib/gluon/gluon-mesh-wireguard-vxlan/checkuplink @@ -117,12 +117,25 @@ is_loadbalancing_enabled() { return 0 } +get_user_agent(){ + local userAgentInfos=$(lua /lib/gluon/gluon-mesh-wireguard-vxlan/get-user-agent-infos.lua) + + #OpenWrt/21.02.0 (kernel/5.10.206; gluon/v2023.1.2+; firmware/v2024.3.1) checkuplink/2.0 VMware, Inc. VMware Virtual Platform + openwrt_version="$(echo "$userAgentInfos" | sed -n 1p)" + kernel="$(echo "$userAgentInfos" | sed -n 2p)" + gluon_version="$(echo "$userAgentInfos" | sed -n 3p)" + firmware_release="$(echo "$userAgentInfos" | sed -n 4p)" + model="$(echo "$userAgentInfos" | sed -n 4p)" + + local user_agent="OpenWrt/$openwrt_version (kernel/$kernel; gluon/$gluon_version; firmware/$firmware_release) checkuplink/2.0 $model" + + echo $user_agent +} + get_wgkex_data(){ local version="$1" WGKEX_BROKER="$PROTO://$WGKEX_BROKER_BASE_PATH/api/$version/wg/key/exchange" - local user_agent="Mozilla/5.0 OpenWrt xx.xx Gluon xx.xx Modell/xxx checkuplink/1.0" -#more examples -#OpenWrt/21.02.0 (GLUON/2024.1; Checkuplink/2.0) x64 + local user_agent=$(get_user_agent()) 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 diff --git a/ffmuc-mesh-vpn-wireguard-vxlan/luasrc/lib/gluon/gluon-mesh-wireguard-vxlan/get-user-agent-infos.lua b/ffmuc-mesh-vpn-wireguard-vxlan/luasrc/lib/gluon/gluon-mesh-wireguard-vxlan/get-user-agent-infos.lua new file mode 100644 index 00000000..3ad2d375 --- /dev/null +++ b/ffmuc-mesh-vpn-wireguard-vxlan/luasrc/lib/gluon/gluon-mesh-wireguard-vxlan/get-user-agent-infos.lua @@ -0,0 +1,24 @@ +local json = require 'jsonc' +local util = require 'gluon.util' +local info = require 'gluon.info' + +-- Get System Infos +local data = assert(json.parse(util.exec('ubus call system board')), "Malformed JSON response, wrong JSON format") + +assert(data.release, "Malformed JSON response, missing required value: release") +local Openwrt_version = assert(data.release.version, "Malformed JSON response, missing required value: version") +local kernel = assert(data.kernel, "Malformed JSON response, missing required value: kernel") + +local model = assert(data.model, "Malformed JSON response, missing required value: model") + +-- Get Gluon Infos +local infos = info.get_info() + +local gluon_version = assert(infos.gluon_version, "Malformed gluon-info, missing required value: gluon version") +local firmware_release = assert(infos.firmware_release, "Malformed gluon-info, missing required value: firmware release") + +print(Openwrt_version) +print(kernel) +print(gluon_version) +print(firmware_release) +print(model)