-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
195 lines (172 loc) · 4.88 KB
/
Makefile
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# A wrapper to generate server/client keys
#
# __author__: tuan t. pham
# Load environment settings
include .env
include .makefile_rc
.PHONY: volume passwd genconfig
env: volume passwd genconfig
volume:
docker volume create ${OVPN_DATA}
passwd:
${OVPN_SCRIPTS}/genpass.sh > ${OVPN_PASSWD}
# Add these if you need to customize
# -s subnet
# -r routing
genconfig:
docker run --rm \
--net=none \
--log-driver=none \
-v ${OVPN_DATA}:/etc/openvpn \
${OVPN_IMG}:${OVPN_TAG} ovpn_genconfig \
-u "${OVPN_PROTO}://${OVPN_RHOST}:${OVPN_RPORT}" \
-e 'topology subnet' \
-n ${OVPN_DNS} \
-r 192.168.42.0/24 \
-s 192.168.42.0/24 \
-C ${OVPN_CIPHER} \
-a ${OVPN_AUTH}
.PHONY: server save_server save_pki load_server load_pki client get_client get_all list help
server:
docker run \
--net=none \
--log-driver=none \
-e EASYRSA_KEY_SIZE=${OVPN_KEY_SIZE} \
-v ${OVPN_DATA}:/etc/openvpn \
--rm -it \
${OVPN_IMG}:${OVPN_TAG} \
ovpn_initpki
save_server:
docker run \
--net=none \
--log-driver=none \
-v ${OVPN_DATA}:/etc/openvpn \
--rm -it ${OVPN_IMG}:${OVPN_TAG} \
ovpn_copy_server_files
docker run -v ${OVPN_DATA}:/etc/openvpn \
--net=none \
--log-driver=none \
--rm ${OVPN_IMG}:${OVPN_TAG} \
tar -cvf - -C /etc/openvpn/server . \
| xz > ${OVPN_SERVER_FILE}
save_pki:
docker run -v ${OVPN_DATA}:/etc/openvpn \
--net=none \
--log-driver=none \
--rm ${OVPN_IMG}:${OVPN_TAG} \
tar -cvf - -C /etc/openvpn/pki . \
| xz > ${OVPN_PKI_FILE}
load_server:
xzcat ${OVPN_SERVER_FILE} | \
docker run -v ${OVPN_DATA}:/etc/openvpn \
--net=none \
--log-driver=none \
--rm -i ${OVPN_IMG}:${OVPN_TAG} \
tar -xvf - -C /etc/openvpn
load_pki:
xzcat ${OVPN_PKI_FILE} | \
docker run -v ${OVPN_DATA}:/etc/openvpn \
--net=none \
--log-driver=none \
--rm -i ${OVPN_IMG}:${OVPN_TAG} \
tar -xvf - -C /etc/openvpn
client:
docker run -e EASYRSA_KEY_SIZE=${OVPN_KEY_SIZE} \
--net=none \
--log-driver=none \
-v ${OVPN_DATA}:/etc/openvpn \
--rm -it \
${OVPN_IMG}:${OVPN_TAG} \
easyrsa build-client-full ${OVPN_CLIENT} nopass
get_client:
docker run -v ${OVPN_DATA}:/etc/openvpn \
--net=none \
--log-driver=none \
--rm -it \
${OVPN_IMG}:${OVPN_TAG} \
ovpn_getclient ${OVPN_CLIENT} > ${OVPN_OUTPUT_DIR}/${OVPN_CLIENT}.ovpn
get_all:
@echo "Get all clients to ${OVPN_OUTPUT_DIR}"
@echo -n "Running "
./scripts/save_clients.sh
list:
docker run -v ${OVPN_DATA}:/etc/openvpn \
--net=none \
--log-driver=none \
--rm \
${OVPN_IMG}:${OVPN_TAG} \
ovpn_listclients
help:
@echo "A simple Makefile to speedup openvpn keys generating and deploying."
@echo "\033[1;31mAvailable targets:\033[0m"
@echo
@echo "\033[1;31mhelp:\033[0m"
@echo "\tThis help message"
@echo
@echo "\033[1;31menv:\033[0m"
@echo "\tSetup the environment before generating server/client keys with these targets:"
@echo "\t* volume Docker volume '$(OVPN_DATA)'"
@echo "\t* passwd Random password for self-signed cert in '$(OVPN_PASSWD)'"
@echo "\t* genconfig Generate default config in docker volume '$(OVPN_DATA)'"
@echo
@echo "\033[1;31mvolume\033[0m"
@echo "\tCreate openvpn data volume"
@echo "\t* Default volume '$(OVPN_DATA)'"
@echo
@echo "\033[1;31mpasswd\033[0m"
@echo "\tGenerate random password to '$(OVPN_PASSWD)'"
@echo
@echo "\033[1;31mgenconfig\033[0m"
@echo "\tGenerate initial config"
@echo
@echo "\033[1;31mserver\033[0m"
@echo "\tGenerate server key"
@echo
@echo "\033[1;31msave_server\033[0m"
@echo "\tSave necessary server files to '$(OVPN_SERVER_FILE)'"
@echo
@echo "\033[1;31mload_server\033[0m"
@echo "\tLoad server config files from '$(OVPN_SERVER_FILE)'"
@echo
@echo "\033[1;31mclient\033[0m"
@echo "\tGenerate a client key, default name '$(OVPN_CLIENT)'"
@echo "\tCustom name"
@echo "\tmake OVPN_CLIENT=custom_name client"
@echo
@echo "\033[1;31mget_client\033[0m"
@echo "\tGet client to '$(PWD)/$(OVPN_CLIENT).ovpn'"
@echo "\tCustom name"
@echo "\tmake OVPN_CLIENT=custom_name get_client"
@echo
@echo "\033[1;31mlist\033[0m"
@echo "\tList available client keys"
@echo
@echo "\033[1;31mdump_env\033[0m"
@echo "\tDump environment settings"
@echo
@echo "__author__ tuan t. pham"
dump_env:
@echo "Dump environment variables:"
@echo "OVPN_IMG=$(OVPN_IMG)"
@echo "OVPN_TAG=$(OVPN_TAG)"
@echo "OVPN_DATA=$(OVPN_DATA)"
@echo "OVPN_PASSWD=$(OVPN_PASSWD)"
@echo "OVPN_CIPHER=$(OVPN_CIPHER)"
@echo "OVPN_AUTH=$(OVPN_AUTH)"
@echo "OVPN_PROTO=$(OVPN_PROTO)"
@echo "OVPN_CN=$(OVPN_CN)"
@echo "OVPN_RHOST=$(OVPN_RHOST)"
@echo "OVPN_RPORT=$(OVPN_RPORT)"
@echo "OVPN_DNS=$(OVPN_DNS)"
@echo "OVPN_OUTPUT_DIR=$(OVPN_OUTPUT_DIR)"
@echo "OVPN_CLIENT=$(OVPN_CLIENT)"
@echo "OVPN_KEY_SIZE=$(OVPN_KEY_SIZE)"
@echo "OVPN_SERVER_FILE=$(OVPN_SERVER_FILE)"
.PHONY: rm_env rm_volume rm_passwd
rm_env: rm_volume rm_passwd
rm_volume:
docker volume rm ${OVPN_DATA}
rm_passwd:
rm ${OVPN_PASSWD}
compose-openvpn.svg: Makefile
makefile2dot -d TB | dot -Tsvg -o compose-openvpn.svg