From d8581416b7bfce49361dd7815416407fb2dd9567 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Mon, 22 Aug 2022 04:30:06 +0300 Subject: [PATCH] add generator-config module --- config_generator/configs/wg-external.conf | 12 +++++ config_generator/configs/wg-internal.conf | 18 +++++++ .../configs/wg-mobile-client.conf | 11 ++++ config_generator/generate_cfgs.sh | 52 +++++++++++++++++++ config_generator/wg-external.conf | 12 +++++ config_generator/wg-internal.conf | 18 +++++++ config_generator/wg-mobile-client.conf | 11 ++++ 7 files changed, 134 insertions(+) create mode 100644 config_generator/configs/wg-external.conf create mode 100644 config_generator/configs/wg-internal.conf create mode 100644 config_generator/configs/wg-mobile-client.conf create mode 100644 config_generator/generate_cfgs.sh create mode 100644 config_generator/wg-external.conf create mode 100644 config_generator/wg-internal.conf create mode 100644 config_generator/wg-mobile-client.conf diff --git a/config_generator/configs/wg-external.conf b/config_generator/configs/wg-external.conf new file mode 100644 index 0000000..3627088 --- /dev/null +++ b/config_generator/configs/wg-external.conf @@ -0,0 +1,12 @@ +[Interface] +Address = 10.20.30.2/32 +PrivateKey = wFOIRBeFqxu9cU/tAvKAHCOnTDsxQCe2hR02mjF/kHo= +PostUp = iptables -t nat -A POSTROUTING -o `ip link show | awk -F ': ' '/state UP/ {print $2}'` -j MASQUERADE +PostDown = iptables -t nat -D POSTROUTING -o `ip link show | awk -F ': ' '/state UP/ {print $2}'` -j MASQUERADE + +#internal node +[Peer] +PublicKey = UG0rzuBEciN9XGWZnvyU+I8XEosm6Q8XKLumnk+k61o= +AllowedIPs = 10.20.30.0/24 +Endpoint = 195.2.79.13:17968 +PersistentKeepalive = 25 diff --git a/config_generator/configs/wg-internal.conf b/config_generator/configs/wg-internal.conf new file mode 100644 index 0000000..e21c22e --- /dev/null +++ b/config_generator/configs/wg-internal.conf @@ -0,0 +1,18 @@ +[Interface] +Address = 10.20.30.1/32 +ListenPort = 17968 +PrivateKey = iPnvzKtdDawMWNHEPDIzKq2Za2pG4EkGq1nlZmyDLlE= +PostUp = iptables -t nat -A POSTROUTING -o `ip link show | awk -F ': ' '/state UP/ {print $2}'` -j MASQUERADE +PostUp = ip rule add from `ip route | awk '/default/ {print $3; exit}'` table main +PostDown = iptables -t nat -D POSTROUTING -o `ip link show | awk -F ': ' '/state UP/ {print $2}'` -j MASQUERADE +PostDown = ip rule del from `ip route | awk '/default/ {print $3; exit}'` table main + +#external node +[Peer] +PublicKey = Kph5VVV/mCx5DPVwD2vwk8RS2Lv6J8U2reVszJKyFEU= +AllowedIPs = 10.20.30.2/32, 0.0.0.0/0 + +#mobile-client node +[Peer] +PublicKey = B+VlF5NaHyFCeA/AX7dXQbjo9pe7VVFgvLbbO+vZvnE= +AllowedIPs = 10.20.30.3/32 diff --git a/config_generator/configs/wg-mobile-client.conf b/config_generator/configs/wg-mobile-client.conf new file mode 100644 index 0000000..863d4ea --- /dev/null +++ b/config_generator/configs/wg-mobile-client.conf @@ -0,0 +1,11 @@ +[Interface] +Address = 10.20.30.3/32 +PrivateKey = OLiqlb0Q4Ryx0QihepS0fYhgWCckZCjEE8ePu6/akkk= +DNS = 1.1.1.1, 8.8.8.8 + +#internal node +[Peer] +PublicKey = UG0rzuBEciN9XGWZnvyU+I8XEosm6Q8XKLumnk+k61o= +AllowedIPs = 0.0.0.0/0 +Endpoint = 195.2.79.13:17968 +PersistentKeepalive = 25 diff --git a/config_generator/generate_cfgs.sh b/config_generator/generate_cfgs.sh new file mode 100644 index 0000000..fb73f85 --- /dev/null +++ b/config_generator/generate_cfgs.sh @@ -0,0 +1,52 @@ +#!^bin^bash + +PRIVATE_KEY_EXTERNAL=`wg genkey` +PUBLIC_KEY_EXTERNAL=`echo $PRIVATE_KEY_EXTERNAL | wg pubkey` +PRIVATE_KEY_INTERNAL=`wg genkey` +PUBLIC_KEY_INTERNAL=`echo $PRIVATE_KEY_INTERNAL | wg pubkey` +PRIVATE_KEY_CLIENT_1=`wg genkey` +PUBLIC_KEY_CLIENT_1=`echo $PRIVATE_KEY_CLIENT_1 | wg pubkey` + +mkdir configs +cp ./wg-external.conf ./configs/wg-external.conf +cp ./wg-internal.conf ./configs/wg-internal.conf +cp ./wg-mobile-client.conf ./configs/wg-mobile-client.conf + + +echo "Generating keys..." +echo "********************************" +echo "Private key for External: $PRIVATE_KEY_EXTERNAL" +echo "Public key for External: $PUBLIC_KEY_EXTERNAL" +echo "Private key for Internal: $PRIVATE_KEY_INTERNAL" +echo "Public key for Internal: $PUBLIC_KEY_INTERNAL" +echo "Private key for Client 1: $PRIVATE_KEY_CLIENT_1" +echo "Public key for Client 1: $PUBLIC_KEY_CLIENT_1" +echo "********************************" + + +echo "Replacing templates in configs..." +gsed -i "s^---PRIVATE_KEY_EXTERNAL---^$PRIVATE_KEY_EXTERNAL^" ./configs/wg-external.conf +gsed -i "s^---PRIVATE_KEY_EXTERNAL---^$PRIVATE_KEY_EXTERNAL^" ./configs/wg-internal.conf +gsed -i "s^---PRIVATE_KEY_EXTERNAL---^$PRIVATE_KEY_EXTERNAL^" ./configs/wg-mobile-client.conf + +gsed -i "s^---PUBLIC_KEY_EXTERNAL---^$PUBLIC_KEY_EXTERNAL^" ./configs/wg-external.conf +gsed -i "s^---PUBLIC_KEY_EXTERNAL---^$PUBLIC_KEY_EXTERNAL^" ./configs/wg-internal.conf +gsed -i "s^---PUBLIC_KEY_EXTERNAL---^$PUBLIC_KEY_EXTERNAL^" ./configs/wg-mobile-client.conf + +gsed -i "s^---PRIVATE_KEY_INTERNAL---^$PRIVATE_KEY_INTERNAL^" ./configs/wg-external.conf +gsed -i "s^---PRIVATE_KEY_INTERNAL---^$PRIVATE_KEY_INTERNAL^" ./configs/wg-internal.conf +gsed -i "s^---PRIVATE_KEY_INTERNAL---^$PRIVATE_KEY_INTERNAL^" ./configs/wg-mobile-client.conf + +gsed -i "s^---PUBLIC_KEY_INTERNAL---^$PUBLIC_KEY_INTERNAL^" ./configs/wg-external.conf +gsed -i "s^---PUBLIC_KEY_INTERNAL---^$PUBLIC_KEY_INTERNAL^" ./configs/wg-internal.conf +gsed -i "s^---PUBLIC_KEY_INTERNAL---^$PUBLIC_KEY_INTERNAL^" ./configs/wg-mobile-client.conf + +gsed -i "s^---PRIVATE_KEY_CLIENT_1---^$PRIVATE_KEY_CLIENT_1^" ./configs/wg-external.conf +gsed -i "s^---PRIVATE_KEY_CLIENT_1---^$PRIVATE_KEY_CLIENT_1^" ./configs/wg-internal.conf +gsed -i "s^---PRIVATE_KEY_CLIENT_1---^$PRIVATE_KEY_CLIENT_1^" ./configs/wg-mobile-client.conf + +gsed -i "s^---PUBLIC_KEY_CLIENT_1---^$PUBLIC_KEY_CLIENT_1^" ./configs/wg-external.conf +gsed -i "s^---PUBLIC_KEY_CLIENT_1---^$PUBLIC_KEY_CLIENT_1^" ./configs/wg-internal.conf +gsed -i "s^---PUBLIC_KEY_CLIENT_1---^$PUBLIC_KEY_CLIENT_1^" ./configs/wg-mobile-client.conf + +echo "Generating complete" diff --git a/config_generator/wg-external.conf b/config_generator/wg-external.conf new file mode 100644 index 0000000..84b361d --- /dev/null +++ b/config_generator/wg-external.conf @@ -0,0 +1,12 @@ +[Interface] +Address = 10.20.30.2/32 +PrivateKey = ---PRIVATE_KEY_EXTERNAL--- +PostUp = iptables -t nat -A POSTROUTING -o `ip link show | awk -F ': ' '/state UP/ {print $2}'` -j MASQUERADE +PostDown = iptables -t nat -D POSTROUTING -o `ip link show | awk -F ': ' '/state UP/ {print $2}'` -j MASQUERADE + +#internal node +[Peer] +PublicKey = ---PUBLIC_KEY_INTERNAL--- +AllowedIPs = 10.20.30.0/24 +Endpoint = 195.2.79.13:17968 +PersistentKeepalive = 25 diff --git a/config_generator/wg-internal.conf b/config_generator/wg-internal.conf new file mode 100644 index 0000000..4d8f32a --- /dev/null +++ b/config_generator/wg-internal.conf @@ -0,0 +1,18 @@ +[Interface] +Address = 10.20.30.1/32 +ListenPort = 17968 +PrivateKey = ---PRIVATE_KEY_INTERNAL--- +PostUp = iptables -t nat -A POSTROUTING -o `ip link show | awk -F ': ' '/state UP/ {print $2}'` -j MASQUERADE +PostUp = ip rule add from `ip route | awk '/default/ {print $3; exit}'` table main +PostDown = iptables -t nat -D POSTROUTING -o `ip link show | awk -F ': ' '/state UP/ {print $2}'` -j MASQUERADE +PostDown = ip rule del from `ip route | awk '/default/ {print $3; exit}'` table main + +#external node +[Peer] +PublicKey = ---PUBLIC_KEY_EXTERNAL--- +AllowedIPs = 10.20.30.2/32, 0.0.0.0/0 + +#mobile-client node +[Peer] +PublicKey = ---PUBLIC_KEY_CLIENT_1--- +AllowedIPs = 10.20.30.3/32 diff --git a/config_generator/wg-mobile-client.conf b/config_generator/wg-mobile-client.conf new file mode 100644 index 0000000..3d6d711 --- /dev/null +++ b/config_generator/wg-mobile-client.conf @@ -0,0 +1,11 @@ +[Interface] +Address = 10.20.30.3/32 +PrivateKey = ---PRIVATE_KEY_CLIENT_1--- +DNS = 1.1.1.1, 8.8.8.8 + +#internal node +[Peer] +PublicKey = ---PUBLIC_KEY_INTERNAL--- +AllowedIPs = 0.0.0.0/0 +Endpoint = 195.2.79.13:17968 +PersistentKeepalive = 25