-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_vars.sh
327 lines (269 loc) · 7.42 KB
/
server_vars.sh
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/bin/bash
#===================================================
#
# FILE: server_vars.sh
#
# AUTHOR: C0pywriting
#
# LINK: https://github.com/C0pywriting
#
# VERSION: 1.0
#
# CREATED: 04.03.2020
#
#====================================================
clear
ip a
echo -e "\n \n Bitte gebe die Variablen ein: \n"
read -p "Dateiname für Server <>.cert? " servername
read -p "Dateiname für Client01 <>.cert? " clientname01
read -p "Dateiname für Client02 <>.cert? " clientname02
read -p "VPN Netz IP bsp. (n) 10.8.0.0? " VpnNetzIp
case ${VpnNetzIp:0:1} in
n|N )
VpnNetzIp="10.8.0.0"
;;
* )
;;
esac
read -p "VPN Server IP? " serverip
echo -e "\n Diffie Hellman Parameter Engabe"
read -p "Bitte wähle: (1) 2048 / (2) 4096? " dh
case ${dh:0:1} in
1 )
dh="2048"
;;
2 )
dh="4096"
;;
esac
clear
echo -e "\n \n Easy Rsa Vars Einstellungen:"
echo -e "Standardwerte mit (1) Uebernehmen: \n"
echo "Land: DE"
echo "Bundesland: Baden-Wuerttemberg"
echo "Stadt: Mannheim"
echo "Organisation: Private Organization"
echo "E-Mail: [email protected]"
echo "OU: Private OU"
read -p "Land? " country
case ${country:0:1} in
1 )
country="DE"
;;
* )
;;
esac
read -p "Bundesland? " province
case ${province:0:1} in
1 )
province="Baden-Wuerttemberg"
;;
* )
;;
esac
read -p "Stadt? " city
case ${city:0:1} in
1 )
city="Mannheim"
;;
* )
;;
esac
read -p "Organisation? " org
case ${org:0:1} in
1 )
org="Private Organization"
;;
* )
;;
esac
read -p "E-Mail? " mail
case ${mail:0:1} in
1 )
mail="[email protected]"
;;
* )
;;
esac
read -p "OU? " ou
case ${ou:0:1} in
1 )
ou="Private OU"
;;
* )
;;
esac
read -p "Tage die das ca gültig sein soll 3650? " tageca
read -p "Tage die das crt gültig sein soll 1080? " tagecrt
clear
echo -e "\n \n"
echo "Eingaben in der Übersicht:"
echo -e "VPN \n Netz: $VpnNetzIp \n Submask: 255.255.255.0 -> /24 \n"
echo -e "VPN Server \n IP: $serverip \n"
echo -e "Diffie Hellman Parameter \n Eingabe: $dh \n"
echo -e "Server Dateien \n $servername.cert \n $servername.key \n "
echo -e "Client 01 Dateien \n $clientname01.cert \n $clientname01.key \n"
echo -e "Client 02 Dateien \n $clientname02.cert \n $clientname02.key \n"
echo -e "Easy Rsa Vars Einstellungen: \n"
echo "Land: $country"
echo "Bundesland: $province"
echo "Stadt: $city"
echo "Organisation: $org"
echo "E-Mail: $mail"
echo "OU: $ou"
read -p "Alle Eingaben Richtig (y/n)? " answer
case ${answer:0:1} in
y|Y )
#hier könnte Werbung stehen
;;
* )
echo "Abbruch es wurde noch nichts am system veraendert!!!"
exit
;;
esac
#Start
echo -e "\n Lehne dich zurück wir arbeiten jetzt für dich ....."
echo -e "\n \n \n Easy-rsa \n"
echo -e "Erstellung der Zertifikate\n"
cd /usr/share/doc/easy-rsa/
make-cadir /root/my_ca
cd /root/my_ca
#Vars Einstellungen übernehmen und in vars schreiben
echo "set_var EASYRSA_DN "org"" >> vars
echo "set_var EASYRSA_REQ_COUNTRY "$country"" >> vars
echo "set_var EASYRSA_REQ_PROVINCE "$province"" >> vars
echo "set_var EASYRSA_REQ_CITY "$city"" >> vars
echo "set_var EASYRSA_REQ_ORG "$org"" >> vars
echo "set_var EASYRSA_REQ_EMAIL "$mail"" >> vars
echo "set_var EASYRSA_REQ_OU "$ou"" >> vars
#Tage der vars einstellen
echo "set_var EASYRSA_CA_EXPIRE "$tageca"" >> vars
echo "set_var EASYRSA_CERT_EXPIRE "$tagecrt"" >> vars
echo -e "\n Initialize PKI \n"
./vars
./easyrsa clean-all
./easyrsa build-ca nopass
#./easyrsa gen-dh
echo -e "\n Create Server Certificates \n"
#Create Server Certificates
./easyrsa build-server-full $servername nopass
echo -e "\n Create Client Certificate \n"
#Create Client Certificate
./easyrsa build-client-full $clientname01 nopass
./easyrsa build-client-full $clientname02 nopass
echo -e "\n Ende Easy-rsa \n"
cd /etc/openvpn/
echo -e "Diffie Hellman Parameter erzeugen \n"
openssl dhparam -out dh.pem $dh
clear
#OpenVpn wird nun vorbereitet
echo -e "Server key / cert / ca.cert / dh.pem werden in /etc/openvpn/ kopiert \n"
cp /root/my_ca/pki/private/$servername.key /etc/openvpn/
cp /root/my_ca/pki/issued/$servername.crt /etc/openvpn/
cp /root/my_ca/pki/ca.crt /etc/openvpn/
cp /root/my_ca/pki/dh.pem /etc/openvpn/
echo -e "server.conf wird in /etc/openvpn/ erstellt \n"
path="/etc/openvpn/server.conf"
echo "server $VpnNetzIp 255.255.255.0" > $path
echo "port 1194" >> $path
echo "proto udp" >> $path
echo "dev tun" >> $path
echo "ca ca.crt" >> $path
echo "cert $servername.crt" >> $path
echo "key $servername.key" >> $path
echo "dh dh.pem" >> $path
echo "ping-timer-rem" >> $path
echo "keepalive 20 180" >> $path
echo "tls-server" >> $path
systemctl restart openvpn
echo "VPN Server ist aktiv"
#OpenVpn Client confs
echo "Client01 conf erstellen"
mkdir /home/tmp
cd /home/tmp
cp /root/my_ca/pki/issued/$clientname01.crt $clientname01.crt
cp /root/my_ca/pki/private/$clientname01.key $clientname01.key
cp /root/my_ca/pki/ca.crt ca.cert
clientpath="/home/tmp/$clientname01.conf"
echo "client" > $clientpath
echo "remote $serverip 1194" >> $clientpath
echo "proto udp" >> $clientpath
echo "dev tun" >> $clientpath
echo "ping-timer-rem" >> $clientpath
echo "keepalive 20 180" >> $clientpath
echo "tls-client" >> $clientpath
echo "<ca>" >> $clientpath
cat ca.cert >> $clientpath
echo "</ca>" >> $clientpath
echo "<cert>" >> $clientpath
cat $clientname01.crt >> $clientpath
echo "</cert>" >> $clientpath
echo "<key>" >> $clientpath
cat $clientname01.key >> $clientpath
echo "</key>" >> $clientpath
echo "Client02 conf erstellen"
cp /root/my_ca/pki/issued/$clientname02.crt $clientname02.crt
cp /root/my_ca/pki/private/$clientname02.key $clientname02.key
clientpath2="/home/tmp/$clientname02.conf"
echo "client" > $clientpath2
echo "remote $serverip 1194" >> $clientpath2
echo "proto udp" >> $clientpath2
echo "dev tun" >> $clientpath2
echo "ping-timer-rem" >> $clientpath2
echo "keepalive 20 180" >> $clientpath2
echo "tls-client" >> $clientpath2
echo "<ca>" >> $clientpath2
cat ca.cert >> $clientpath2
echo "</ca>" >> $clientpath2
echo "<cert>" >> $clientpath2
cat $clientname02.crt >> $clientpath2
echo "</cert>" >> $clientpath2
echo "<key>" >> $clientpath2
cat $clientname02.key >> $clientpath2
echo "</key>" >> $clientpath2
#Ende OpenVpn
#Weitergabe der Client confs über Webserver
apt install apache2 -y
cd /var/www/html/
rm -r index.html
cp $clientpath /var/www/html/
cp $clientpath2 /var/www/html/
clear
#User Infos
echo -e "VPN Server ist fertig!"
echo -e "Die Client .conf findest du unter:"
echo -e "http://$serverip"
echo -e "\n"
echo -e "Angaben für network_client_server.sh"
echo -e "Clientname: $clientname01"
echo -e "ServerIP: $serverip"
echo -e ""
echo -e ""
echo -e "Warten bis beim Client gemeldet wird das es hier weiter gehen kann"
read -p "Bitte warten weiter mit (y)? " ncs
case ${ncs:0:1} in
y|Y )
;;
* )
echo -e "Warten bis beim Client gemeldet wird das es hier weiter gehen kann"
read -p "Bitte warten weiter mit (y)? " ncs1
case ${ncs1:0:1} in
y|Y )
;;
* )
;;
esac
;;
esac
#Neustart
read -p "reboot? (y/n)? " re
case ${re:0:1} in
y|Y )
#hier könnte Werbung stehen
reboot
;;
* )
exit
;;
esac