Compare commits

..

11 Commits

Author SHA1 Message Date
61ac064215 ...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 07:06:58 +03:00
77b5a12a21 more cleanup and tweaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 07:04:05 +03:00
aca1c1c013 another fix...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 06:53:29 +03:00
8ae33ab734 cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 06:49:14 +03:00
f5bc6ce095 bugfix...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 06:45:49 +03:00
044bff7e8c wireguard mostly done...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 06:40:46 +03:00
29ccc82581 ...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 06:31:42 +03:00
72be4b3b62 ...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 06:17:00 +03:00
96c6b07fe7 ...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 06:09:25 +03:00
15bad014b4 ...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 06:04:59 +03:00
e27df50ee3 added ip generation...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-10 06:01:28 +03:00
4 changed files with 35 additions and 15 deletions

View File

@ -347,7 +347,7 @@ buildAssets(){
) )
for var in ${DFL_VARS[@]} ; do for var in ${DFL_VARS[@]} ; do
local val=${!var} local val=${!var}
PATTERNS+=("-e 's/\\\${${var}}/${val/\//\\/}/g'") PATTERNS+=("-e 's/\\\${${var}}/${val//\//\\/}/g'")
done done
local IP_VARS=( local IP_VARS=(
GATE_LAN_IPn GATE_LAN_IPn
@ -365,7 +365,7 @@ buildAssets(){
# args... # args...
for var in $@ ; do for var in $@ ; do
local val=${!var} local val=${!var}
PATTERNS+=("-e 's/\\\${${var}}/${val/\//\\/}/g'") PATTERNS+=("-e 's/\\\${${var}}/${val//\//\\/}/g'")
done done
local TEMPLATES=($(find "$template_dir" -type f)) local TEMPLATES=($(find "$template_dir" -type f))

View File

@ -35,12 +35,16 @@ LAN_GATE=-
REBOOT=${REBOOT:=1} REBOOT=${REBOOT:=1}
# Wireguard config...
DFL_ENDPOINT=${DFL_ENDPOINT:=$(dig +short ${DOMAIN:-$DFL_DOMAIN} | tail -1)} DFL_ENDPOINT=${DFL_ENDPOINT:=$(dig +short ${DOMAIN:-$DFL_DOMAIN} | tail -1)}
xread "Wireguard endpoint: " ENDPOINT xread "Wireguard endpoint: " ENDPOINT
DFL_ENDPOINT_PORT=${DFL_ENDPOINT_PORT:=51820} DFL_ENDPOINT_PORT=${DFL_ENDPOINT_PORT:=51820}
xread "Wireguard endpoint port: " ENDPOINT_PORT xread "Wireguard endpoint port: " ENDPOINT_PORT
CLIENT_IPS=${CLIENT_IPS:-10.42.0.0/16}
ALLOWED_IPS=${ALLOWED_IPS:-0.0.0.0/0,${CLIENT_IPS}}
readVars readVars
@ -73,7 +77,7 @@ OPTS_STAGE_2="\
#---------------------------------------------------------------------- #----------------------------------------------------------------------
echo "# Building config..." echo "# Building config..."
buildAssets ENDPOINT ENDPOINT_PORT DNS buildAssets ENDPOINT ENDPOINT_PORT DNS CLIENT_IPS ALLOWED_IPS
echo "# Creating CT..." echo "# Creating CT..."
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS" pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
@ -83,15 +87,13 @@ echo "# Installing dependencies..."
echo "# Copying assets..." echo "# Copying assets..."
@ pct-push-r $ID ./assets / @ pct-push-r $ID ./assets /
@ lxc-attach $ID -- chmod +x /root/getFreeClientIP
#echo "# Setup: wireguard server..." #echo "# Setup: wireguard server..."
@ lxc-attach $ID -- bash -c 'cd /root && make server' @ lxc-attach $ID -- bash -c 'cd /root && make server'
echo "# Setup: wireguard default profile..." echo "# Setup: wireguard default profile..."
@ lxc-attach $ID -- bash -c "cd /root && \ @ lxc-attach $ID -- bash -c "cd /root && make default.client"
CLIENT_IP=10.42.0.1/32 \
ALLOWED_IPS=0.0.0.0/0 \
make default.client"
@ lxc-attach $ID -- chmod 600 /etc/wireguard/wg0.conf @ lxc-attach $ID -- chmod 600 /etc/wireguard/wg0.conf
echo "# client config:" echo "# client config:"

View File

@ -11,14 +11,13 @@ SERVER_PUBLIC_KEY := $(SERVER_DIR)/server_id.pub
CLIENT_TPL := templates/client.conf CLIENT_TPL := templates/client.conf
CLIENT_DIR := $(SERVER_DIR)/clients/ CLIENT_DIR := $(SERVER_DIR)/clients/
CLIENT_IPS ?= 10.42.0.0/16
ENDPOINT_PORT ?= ${ENDPOINT_PORT}
ENDPOINT ?= ${ENDPOINT}
ENDPOINT ?= ${ENDPOINT}
ENDPOINT_PORT ?= ${ENDPOINT_PORT}
DNS ?= ${DNS} DNS ?= ${DNS}
ALLOWED_IPS ?= 0.0.0.0/0 CLIENT_IPS ?= ${CLIENT_IPS}
# XXX need to generate this... ALLOWED_IPS ?= ${ALLOWED_IPS}
CLIENT_IP ?= 10.42.0.1/32
%_id: %_id:
@ -50,13 +49,13 @@ $(SERVER_CONF): $(SERVER_TPL) $(SERVER_KEY)
-e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \ -e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \
-e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \ -e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \
-e 's/\$${\ALLOWED_IPS}/$(subst /,\/,$(ALLOWED_IPS))/g' \ -e 's/\$${\ALLOWED_IPS}/$(subst /,\/,$(ALLOWED_IPS))/g' \
-e 's/\$${\CLIENT_IP}/$(subst /,\/,$(CLIENT_IP))/g' \ -e 's/\$${\CLIENT_IP}/$(shell ./getFreeClientIP)\/32/g' \
-e 's/\$${\CLIENT_PRIVATE_KEY}/'$$(sed -e 's/\//\\\//g' "$(CLIENT_DIR)/$*_id")'/g' \ -e 's/\$${\CLIENT_PRIVATE_KEY}/'$$(sed -e 's/\//\\\//g' "$(CLIENT_DIR)/$*_id")'/g' \
-e 's/\$${\SERVER_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")'/g' \ -e 's/\$${\SERVER_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")'/g' \
> "$(CLIENT_DIR)/$*.conf" > "$(CLIENT_DIR)/$*.conf"
cat "$(SERVER_CLIENT_TPL)" \ cat "$(SERVER_CLIENT_TPL)" \
| sed \ | sed \
-e 's/\$${\CLIENT_IP}/$(subst /,\/,$(CLIENT_IP))/g' \ -e 's/\$${\CLIENT_IP}/$(shell ./getFreeClientIP)\/32/g' \
-e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \ -e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \
-e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \ -e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \
-e 's/\$${\CLIENT_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(CLIENT_DIR)/$*_id.pub")'/g' \ -e 's/\$${\CLIENT_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(CLIENT_DIR)/$*_id.pub")'/g' \

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
CLIENT_IPS=${CLIENT_IPS}
BASE_IP=${CLIENT_IPS/.0\/*}
IPs=($(cat /etc/wireguard/clients/* 2> /dev/null \
| grep Address \
| cut -d'.' -f 4 \
| cut -d '/' -f 1 \
| sort))
IPs=${IPs[@]}
i=1
while [ "$( echo $IPs | fgrep -w $i )" ] ; do
i=$(( i + 1 ))
done
echo $BASE_IP.$i