2023-04-06 08:43:51 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
2023-06-30 15:36:47 +02:00
|
|
|
echo "Please supply one zipfile"
|
2023-05-29 11:53:58 +02:00
|
|
|
exit 1
|
2023-04-06 08:43:51 +02:00
|
|
|
echo "$?"
|
|
|
|
elif [ $# -ge 2 ]; then
|
|
|
|
echo "Please only give one argument"
|
2023-05-29 11:53:58 +02:00
|
|
|
exit 1
|
2023-04-06 08:43:51 +02:00
|
|
|
echo "$?"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "$HOME"
|
|
|
|
|
|
|
|
file="$1"
|
|
|
|
parent="$(dirname "$file")"
|
|
|
|
extract="${parent}/vpnconfigs"
|
|
|
|
patched="${file%.*}-patched.zip"
|
|
|
|
|
|
|
|
cd "$parent"
|
|
|
|
|
|
|
|
mkdir -p "${parent}/vpnconfigs"
|
|
|
|
|
|
|
|
unzip "$file" -d "$extract"
|
|
|
|
|
|
|
|
readarray -d '' conffiles < <(find "$extract" -name "*\.conf" -print0)
|
|
|
|
|
|
|
|
for file in "${conffiles[@]}"; do
|
|
|
|
echo "Patching $file"
|
2023-05-29 11:53:58 +02:00
|
|
|
endpointIP="$(grep "Endpoint =" "$file" | grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}")"
|
|
|
|
echo "Calculating AllowedIPs"
|
2023-06-03 21:21:25 +02:00
|
|
|
allowedIPs="$(~/GitProjects/configs/arch-config/scripts/pieces/ipexclude.py -e "$endpointIP" -e 172.16.0.0/12 -e 162.55.10.16/32)"
|
2023-05-29 11:53:58 +02:00
|
|
|
echo "Replacing AllowedIPs"
|
|
|
|
# delimiter @ is used instead of /
|
|
|
|
sed -i "s@AllowedIPs = 0.0.0.0/0,::0/0@AllowedIPs = $allowedIPs@g" "$file"
|
|
|
|
echo "Removing DNS"
|
|
|
|
sed -i 's/DNS = 10.64.0.1//g' "$file"
|
|
|
|
echo "Finished $file"
|
2023-04-06 08:43:51 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
zip -r -9 "$patched" "vpnconfigs"
|
|
|
|
|
|
|
|
rm -rf "$extract"
|