2024-01-09 03:21:36 +03:00
|
|
|
|
2024-01-15 20:48:11 +03:00
|
|
|
INTERFACE := wg0
|
2024-01-09 03:21:36 +03:00
|
|
|
|
2024-01-09 14:05:06 +03:00
|
|
|
SERVER_DIR := /etc/wireguard/
|
2024-01-15 20:48:11 +03:00
|
|
|
SERVER_TPL := templates/server.conf
|
|
|
|
|
SERVER_CLIENT_TPL := templates/client.tpl
|
|
|
|
|
SERVER_CONF := $(SERVER_DIR)/$(INTERFACE).conf
|
2024-01-09 14:05:06 +03:00
|
|
|
SERVER_KEY := $(SERVER_DIR)/server_id
|
|
|
|
|
SERVER_PUBLIC_KEY := $(SERVER_DIR)/server_id.pub
|
2024-01-09 03:21:36 +03:00
|
|
|
|
|
|
|
|
CLIENT_TPL := templates/client.conf
|
2024-01-09 14:05:06 +03:00
|
|
|
CLIENT_DIR := $(SERVER_DIR)/clients/
|
2024-01-09 03:21:36 +03:00
|
|
|
|
2024-01-11 02:19:16 +03:00
|
|
|
QRCODE ?= 1
|
2024-01-09 15:49:42 +03:00
|
|
|
|
2024-01-10 06:40:46 +03:00
|
|
|
ENDPOINT ?= ${ENDPOINT}
|
|
|
|
|
ENDPOINT_PORT ?= ${ENDPOINT_PORT}
|
2024-01-10 04:46:43 +03:00
|
|
|
DNS ?= ${DNS}
|
2024-01-10 06:40:46 +03:00
|
|
|
CLIENT_IPS ?= ${CLIENT_IPS}
|
|
|
|
|
ALLOWED_IPS ?= ${ALLOWED_IPS}
|
2024-01-09 03:21:36 +03:00
|
|
|
|
|
|
|
|
|
2024-01-10 06:01:28 +03:00
|
|
|
|
2024-01-09 03:21:36 +03:00
|
|
|
%_id:
|
2024-01-09 14:05:06 +03:00
|
|
|
@ mkdir -p $$(dirname $@)
|
2024-01-09 15:16:25 +03:00
|
|
|
wg genkey 2> /dev/null > $@
|
|
|
|
|
chmod 600 $@
|
2024-01-09 03:21:36 +03:00
|
|
|
|
2024-01-15 21:11:02 +03:00
|
|
|
|
2024-01-09 03:21:36 +03:00
|
|
|
%_id.pub: %_id
|
|
|
|
|
cat $< | wg pubkey > $@
|
|
|
|
|
|
|
|
|
|
|
2024-01-10 02:14:36 +03:00
|
|
|
# NOTE: the first letter of each pattern is quoted to prevent it from
|
|
|
|
|
# being substituted when generating this Makefile from template.
|
2024-01-09 03:21:36 +03:00
|
|
|
$(SERVER_CONF): $(SERVER_TPL) $(SERVER_KEY)
|
|
|
|
|
cat $< \
|
|
|
|
|
| sed \
|
2024-01-10 01:22:06 +03:00
|
|
|
-e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \
|
|
|
|
|
-e 's/\$${\CLIENT_IPS}/$(subst /,\/,$(CLIENT_IPS))/g' \
|
|
|
|
|
-e 's/\$${\SERVER_PRIVATE_KEY}/'$$(sed -e 's/\//\\\//g' "$(SERVER_KEY)")'/g' \
|
2024-01-09 03:21:36 +03:00
|
|
|
> "$@"
|
2024-01-15 20:55:54 +03:00
|
|
|
chmod 600 $@
|
2024-01-15 21:16:10 +03:00
|
|
|
wg-quick up $(INTERFACE)
|
2024-01-09 03:21:36 +03:00
|
|
|
|
2024-01-15 21:11:02 +03:00
|
|
|
|
2024-01-13 16:39:42 +03:00
|
|
|
# XXX need to figure out a way to link this to the .config file without
|
|
|
|
|
# conflicting with the server's wg0.conf
|
2024-01-15 21:22:55 +03:00
|
|
|
%.client: $(CLIENT_TPL) $(SERVER_CLIENT_TPL) \
|
2024-01-09 03:21:36 +03:00
|
|
|
$(CLIENT_DIR)/%_id $(CLIENT_DIR)/%_id.pub \
|
|
|
|
|
$(SERVER_CONF) $(SERVER_PUBLIC_KEY)
|
2024-01-09 15:16:25 +03:00
|
|
|
@ mkdir -p $(CLIENT_DIR)
|
2024-01-09 03:21:36 +03:00
|
|
|
cat "$<" \
|
|
|
|
|
| sed \
|
2024-01-10 01:22:06 +03:00
|
|
|
-e 's/\$${\DNS}/$(DNS)/g' \
|
|
|
|
|
-e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \
|
|
|
|
|
-e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \
|
|
|
|
|
-e 's/\$${\ALLOWED_IPS}/$(subst /,\/,$(ALLOWED_IPS))/g' \
|
2024-01-10 07:06:58 +03:00
|
|
|
-e 's/\$${\CLIENT_IP}/$(shell ./getFreeClientIP)\/32/g' \
|
2024-01-10 01:22:06 +03:00
|
|
|
-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' \
|
2024-01-09 15:16:25 +03:00
|
|
|
> "$(CLIENT_DIR)/$*.conf"
|
2024-01-15 21:22:55 +03:00
|
|
|
ln -s "$(CLIENT_DIR)/$*.conf" $*.client
|
2024-01-09 03:21:36 +03:00
|
|
|
cat "$(SERVER_CLIENT_TPL)" \
|
|
|
|
|
| sed \
|
2024-01-10 07:06:58 +03:00
|
|
|
-e 's/\$${\CLIENT_IP}/$(shell ./getFreeClientIP)\/32/g' \
|
2024-01-10 01:22:06 +03:00
|
|
|
-e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \
|
|
|
|
|
-e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \
|
|
|
|
|
-e 's/\$${\CLIENT_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(CLIENT_DIR)/$*_id.pub")'/g' \
|
|
|
|
|
-e 's/\$${\SERVER_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")'/g' \
|
2024-01-09 03:21:36 +03:00
|
|
|
>> "$(SERVER_CONF)"
|
2024-01-15 20:48:11 +03:00
|
|
|
make update
|
|
|
|
|
@ [ "$(QRCODE)" == "1" ] \
|
|
|
|
|
&& ( echo "# Profile: $*" \
|
2024-01-11 02:26:54 +03:00
|
|
|
&& qrencode -t UTF8 -r "$(CLIENT_DIR)/$*.conf" )
|
2024-01-15 21:11:02 +03:00
|
|
|
@ cat "$(CLIENT_DIR)/$*.conf"
|
|
|
|
|
@ echo
|
2024-01-09 03:21:36 +03:00
|
|
|
|
|
|
|
|
|
2024-01-13 10:03:29 +03:00
|
|
|
|
2024-01-15 21:16:10 +03:00
|
|
|
%.qr: %.conf
|
2024-01-13 10:03:29 +03:00
|
|
|
@ ( echo "# Profile: $*" \
|
2024-01-13 10:20:04 +03:00
|
|
|
&& qrencode -t UTF8 -r "$*.conf" )
|
2024-01-13 10:03:29 +03:00
|
|
|
|
|
|
|
|
|
2024-01-15 20:48:11 +03:00
|
|
|
update:
|
|
|
|
|
wg syncconf $(INTERFACE) <(wg-quick strip $(INTERFACE))
|
|
|
|
|
|
|
|
|
|
|
2024-01-15 21:11:02 +03:00
|
|
|
server: $(SERVER_CONF)
|
|
|
|
|
|
|
|
|
|
|
2024-01-09 03:21:36 +03:00
|
|
|
|