-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0vpn-handle-client-announcements
executable file
·42 lines (35 loc) · 1.28 KB
/
0vpn-handle-client-announcements
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
set +e
my_path=$(dirname "$0")
device="$1"
keyfile="$2"
root_public_announce_port="$3"
tmpdir="$4"
tld="$5"
IFS=' '
nc -ulkp "$root_public_announce_port" | while read -r line; do
# echo Got line: $line;
read -ra tokens <<< "$line"
# echo " host: ${tokens[0]} public: ${tokens[1]}"
host=${tokens[0]}
public=${tokens[1]}
client_private=$("$my_path"/0vpn-tool mixin "$keyfile" "$host")
# echo " Private: $client_private"
client_public=$(echo "$client_private" | wg pubkey)
client_wg_ipv6="$("$my_path"/0vpn-ipv6-address "$keyfile" "$host")"
# echo " Public: $client_public Leaf IP: $client_wg_ip"
# echo " Checking if they match:"
if [ "$public" == "$client_public" ]; then
if [ ! -f "$tmpdir"/hosts/"$host" ]; then
echo -e -n "\nMatch! adding the client: Host: $host Public key: $client_public IP: $client_wg_ipv6\n"
wg set "$device" peer "$client_public" persistent-keepalive 10 allowed-ips "$client_wg_ipv6"
{
echo "$client_wg_ipv6" "$host"
# echo "$client_wg_ipv6" "$host"."$tld"
} > "$tmpdir"/hosts/"$host"
kill -1 $(cat "$tmpdir/dnsmasq.pid")
fi
else
echo " key mismatch. not adding client..."
fi
done