2024-01-16 04:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#----------------------------------------------------------------------
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#----------------------------------------------------------------------
							 | 
						
					
						
							
								
									
										
										
										
											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-16 04:19:15 +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-16 04:07:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								%_ip:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									./getFreeClientIP > $@
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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-16 22:55:05 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# XXX build this from client files...
							 | 
						
					
						
							
								
									
										
										
										
											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-16 04:07:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.PRECIOUS: %.wg
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%.wg: $(CLIENT_TPL) $(SERVER_CLIENT_TPL) \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										%_id %_id.pub %_ip \
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-09 03:21:36 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										$(SERVER_CONF) $(SERVER_PUBLIC_KEY)
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:07:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									@ mkdir -p $(shell dirname "$*")
							 | 
						
					
						
							
								
									
										
										
										
											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-16 04:07:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											-e 's/\$${\CLIENT_IP}/$(shell cat $*_ip)\/32/g' \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											-e 's/\$${\CLIENT_PRIVATE_KEY}/$(shell sed -e 's/\//\\\//g' "$*_id")/g' \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											-e 's/\$${\SERVER_PUBLIC_KEY}/$(shell sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")/g' \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										> "$@"
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-09 03:21:36 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									cat "$(SERVER_CLIENT_TPL)" \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										| sed \
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:07:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											-e 's/\$${\CLIENT_IP}/$(shell cat $*_ip)\/32/g' \
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-10 01:22:06 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											-e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											-e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:07:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											-e 's/\$${\CLIENT_PUBLIC_KEY}/$(shell sed -e 's/\//\\\//g' "$*_id.pub")/g' \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											-e 's/\$${\SERVER_PUBLIC_KEY}/$(shell sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")/g' \
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-09 03:21:36 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										>> "$(SERVER_CONF)"
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-15 21:38:50 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.PHONY: %.show
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:07:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								%.show: %.wg
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-15 20:48:11 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									@ [ "$(QRCODE)" == "1" ] \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										&& ( echo "# Profile: $*" \
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:07:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											&& qrencode -t UTF8 -r "$<" )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									@ cat "$<"
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-15 21:11:02 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									@ echo 
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-09 03:21:36 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.PHONY: %.client
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:07:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								%.client: $(CLIENT_DIR)/%.wg update $(CLIENT_DIR)/%.show
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									@
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#----------------------------------------------------------------------
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								.PHONY: update
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-15 20:48:11 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								update:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wg syncconf $(INTERFACE) <(wg-quick strip $(INTERFACE))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.PHONY: server
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-15 21:11:02 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								server: $(SERVER_CONF)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-09 03:21:36 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-01-16 04:19:15 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#----------------------------------------------------------------------
							 |