]>
Commit | Line | Data |
---|---|---|
6e13d0a5 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
49abe7af | 5 | # Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> # |
70df8302 MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
54fd0535 | 21 | ### |
f527e53f | 22 | # Based on IPFireCore 77 |
54fd0535 | 23 | ### |
6e13d0a5 MT |
24 | use CGI; |
25 | use CGI qw/:standard/; | |
26 | use Net::DNS; | |
ce9abb66 | 27 | use Net::Ping; |
54fd0535 | 28 | use Net::Telnet; |
6e13d0a5 MT |
29 | use File::Copy; |
30 | use File::Temp qw/ tempfile tempdir /; | |
31 | use strict; | |
32 | use Archive::Zip qw(:ERROR_CODES :CONSTANTS); | |
eff2dbf8 | 33 | use Sort::Naturally; |
6e13d0a5 | 34 | require '/var/ipfire/general-functions.pl'; |
6e13d0a5 MT |
35 | require "${General::swroot}/lang.pl"; |
36 | require "${General::swroot}/header.pl"; | |
37 | require "${General::swroot}/countries.pl"; | |
38 | ||
39 | # enable only the following on debugging purpose | |
8c877a82 AM |
40 | #use warnings; |
41 | #use CGI::Carp 'fatalsToBrowser'; | |
6e13d0a5 | 42 | #workaround to suppress a warning when a variable is used only once |
8c877a82 | 43 | my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} ); |
6e13d0a5 MT |
44 | undef (@dummy); |
45 | ||
f2fdd0c1 CS |
46 | my %color = (); |
47 | my %mainsettings = (); | |
48 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
49 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
6e13d0a5 MT |
50 | |
51 | ### | |
52 | ### Initialize variables | |
53 | ### | |
e81be1e1 AM |
54 | my %ccdconfhash=(); |
55 | my %ccdroutehash=(); | |
56 | my %ccdroute2hash=(); | |
6e13d0a5 MT |
57 | my %netsettings=(); |
58 | my %cgiparams=(); | |
59 | my %vpnsettings=(); | |
60 | my %checked=(); | |
61 | my %confighash=(); | |
62 | my %cahash=(); | |
63 | my %selected=(); | |
64 | my $warnmessage = ''; | |
65 | my $errormessage = ''; | |
66 | my %settings=(); | |
54fd0535 | 67 | my $routes_push_file = ''; |
df9b48b7 AM |
68 | my $confighost="${General::swroot}/fwhosts/customhosts"; |
69 | my $configgrp="${General::swroot}/fwhosts/customgroups"; | |
70 | my $customnet="${General::swroot}/fwhosts/customnetworks"; | |
71 | my $name; | |
99bfa85c | 72 | my $col=""; |
6e13d0a5 MT |
73 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
74 | $cgiparams{'ENABLED'} = 'off'; | |
75 | $cgiparams{'ENABLED_BLUE'} = 'off'; | |
76 | $cgiparams{'ENABLED_ORANGE'} = 'off'; | |
77 | $cgiparams{'EDIT_ADVANCED'} = 'off'; | |
78 | $cgiparams{'NAT'} = 'off'; | |
79 | $cgiparams{'COMPRESSION'} = 'off'; | |
80 | $cgiparams{'ONLY_PROPOSED'} = 'off'; | |
81 | $cgiparams{'ACTION'} = ''; | |
82 | $cgiparams{'CA_NAME'} = ''; | |
4c962356 EK |
83 | $cgiparams{'DH_NAME'} = 'dh1024.pem'; |
84 | $cgiparams{'DHLENGHT'} = ''; | |
6e13d0a5 MT |
85 | $cgiparams{'DHCP_DOMAIN'} = ''; |
86 | $cgiparams{'DHCP_DNS'} = ''; | |
87 | $cgiparams{'DHCP_WINS'} = ''; | |
54fd0535 | 88 | $cgiparams{'ROUTES_PUSH'} = ''; |
6e13d0a5 | 89 | $cgiparams{'DCOMPLZO'} = 'off'; |
a79fa1d6 | 90 | $cgiparams{'MSSFIX'} = ''; |
8c877a82 | 91 | $cgiparams{'number'} = ''; |
2ee746be | 92 | $cgiparams{'PMTU_DISCOVERY'} = ''; |
4c962356 | 93 | $cgiparams{'DCIPHER'} = ''; |
49abe7af EK |
94 | $cgiparams{'DAUTH'} = ''; |
95 | $cgiparams{'TLSAUTH'} = ''; | |
54fd0535 MT |
96 | $routes_push_file = "${General::swroot}/ovpn/routes_push"; |
97 | unless (-e $routes_push_file) { system("touch $routes_push_file"); } | |
8c877a82 AM |
98 | unless (-e "${General::swroot}/ovpn/ccd.conf") { system("touch ${General::swroot}/ovpn/ccd.conf"); } |
99 | unless (-e "${General::swroot}/ovpn/ccdroute") { system("touch ${General::swroot}/ovpn/ccdroute"); } | |
100 | unless (-e "${General::swroot}/ovpn/ccdroute2") { system("touch ${General::swroot}/ovpn/ccdroute2"); } | |
ce9abb66 | 101 | |
6e13d0a5 MT |
102 | &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'}); |
103 | ||
104 | # prepare openvpn config file | |
105 | ### | |
106 | ### Useful functions | |
107 | ### | |
c6c9630e MT |
108 | sub haveOrangeNet |
109 | { | |
13211b21 CS |
110 | if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;} |
111 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} | |
c6c9630e MT |
112 | return 0; |
113 | } | |
114 | ||
115 | sub haveBlueNet | |
116 | { | |
13211b21 | 117 | if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;} |
c6c9630e | 118 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} |
c6c9630e MT |
119 | return 0; |
120 | } | |
121 | ||
122 | sub sizeformat{ | |
123 | my $bytesize = shift; | |
124 | my $i = 0; | |
125 | ||
126 | while(abs($bytesize) >= 1024){ | |
127 | $bytesize=$bytesize/1024; | |
128 | $i++; | |
129 | last if($i==6); | |
130 | } | |
131 | ||
132 | my @units = ("Bytes","KB","MB","GB","TB","PB","EB"); | |
133 | my $newsize=(int($bytesize*100 +0.5))/100; | |
134 | return("$newsize $units[$i]"); | |
135 | } | |
136 | ||
c6c9630e MT |
137 | sub cleanssldatabase |
138 | { | |
139 | if (open(FILE, ">${General::swroot}/ovpn/certs/serial")) { | |
140 | print FILE "01"; | |
141 | close FILE; | |
142 | } | |
143 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt")) { | |
144 | print FILE ""; | |
145 | close FILE; | |
146 | } | |
147 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
148 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
149 | unlink ("${General::swroot}/ovpn/certs/01.pem"); | |
150 | } | |
151 | ||
152 | sub newcleanssldatabase | |
153 | { | |
154 | if (! -s "${General::swroot}/ovpn/certs/serial" ) { | |
155 | open(FILE, ">${General::swroot}(ovpn/certs/serial"); | |
156 | print FILE "01"; | |
157 | close FILE; | |
158 | } | |
159 | if (! -s ">${General::swroot}/ovpn/certs/index.txt") { | |
160 | system ("touch ${General::swroot}/ovpn/certs/index.txt"); | |
161 | } | |
162 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
163 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
164 | } | |
165 | ||
166 | sub deletebackupcert | |
167 | { | |
168 | if (open(FILE, "${General::swroot}/ovpn/certs/serial.old")) { | |
169 | my $hexvalue = <FILE>; | |
170 | chomp $hexvalue; | |
171 | close FILE; | |
172 | unlink ("${General::swroot}/ovpn/certs/$hexvalue.pem"); | |
173 | } | |
174 | } | |
4c962356 | 175 | |
c6c9630e | 176 | sub writeserverconf { |
54fd0535 MT |
177 | my %sovpnsettings = (); |
178 | my @temp = (); | |
c6c9630e | 179 | &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings); |
54fd0535 MT |
180 | &read_routepushfile; |
181 | ||
c6c9630e MT |
182 | open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!"; |
183 | flock CONF, 2; | |
184 | print CONF "#OpenVPN Server conf\n"; | |
185 | print CONF "\n"; | |
186 | print CONF "daemon openvpnserver\n"; | |
187 | print CONF "writepid /var/run/openvpn.pid\n"; | |
afabe9f7 | 188 | print CONF "#DAN prepare OpenVPN for listening on blue and orange\n"; |
c6c9630e MT |
189 | print CONF ";local $sovpnsettings{'VPN_IP'}\n"; |
190 | print CONF "dev $sovpnsettings{'DDEVICE'}\n"; | |
c6c9630e MT |
191 | print CONF "proto $sovpnsettings{'DPROTOCOL'}\n"; |
192 | print CONF "port $sovpnsettings{'DDEST_PORT'}\n"; | |
2b29c22e | 193 | print CONF "script-security 3 system\n"; |
07675dc3 | 194 | print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n"; |
6140e7e0 | 195 | print CONF "client-config-dir /var/ipfire/ovpn/ccd\n"; |
c6c9630e | 196 | print CONF "tls-server\n"; |
4c962356 EK |
197 | print CONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; |
198 | print CONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
199 | print CONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
49abe7af | 200 | print CONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; |
c6c9630e MT |
201 | my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'}); |
202 | print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n"; | |
8c877a82 | 203 | #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n"; |
4c962356 | 204 | |
2ee746be SS |
205 | # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500. |
206 | # If we doesn't use one of them, we can use the configured mtu value. | |
207 | if ($sovpnsettings{'MSSFIX'} eq 'on') | |
208 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; } | |
209 | elsif ($sovpnsettings{'FRAGMENT'} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') | |
210 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; } | |
1647059d | 211 | elsif (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') || |
4c962356 EK |
212 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || |
213 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) | |
2ee746be SS |
214 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; } |
215 | else | |
216 | { print CONF "$sovpnsettings{'DDEVICE'}-mtu $sovpnsettings{'DMTU'}\n"; } | |
217 | ||
54fd0535 | 218 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { |
8c877a82 AM |
219 | @temp = split(/\n/,$vpnsettings{'ROUTES_PUSH'}); |
220 | foreach (@temp) | |
221 | { | |
222 | @tempovpnsubnet = split("\/",&General::ipcidr2msk($_)); | |
223 | print CONF "push \"route " . $tempovpnsubnet[0]. " " . $tempovpnsubnet[1] . "\"\n"; | |
224 | } | |
54fd0535 | 225 | } |
8c877a82 AM |
226 | # a.marx ccd |
227 | my %ccdconfhash=(); | |
228 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
229 | foreach my $key (keys %ccdconfhash) { | |
230 | my $a=$ccdconfhash{$key}[1]; | |
231 | my ($b,$c) = split (/\//, $a); | |
232 | print CONF "route $b ".&General::cidrtosub($c)."\n"; | |
233 | } | |
234 | my %ccdroutehash=(); | |
235 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
236 | foreach my $key (keys %ccdroutehash) { | |
237 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
238 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
239 | print CONF "route $a $b\n"; | |
240 | } | |
241 | } | |
242 | # ccd end | |
54fd0535 | 243 | |
8c877a82 | 244 | if ($sovpnsettings{CLIENT2CLIENT} eq 'on') { |
c6c9630e MT |
245 | print CONF "client-to-client\n"; |
246 | } | |
1de5c945 | 247 | if ($sovpnsettings{MSSFIX} eq 'on') { |
4c962356 | 248 | print CONF "mssfix\n"; |
1de5c945 EK |
249 | } |
250 | if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') { | |
4c962356 | 251 | print CONF "fragment $sovpnsettings{'FRAGMENT'}\n"; |
a79fa1d6 | 252 | } |
2ee746be | 253 | |
1647059d SS |
254 | # Check if a valid operating mode has been choosen and use it. |
255 | if (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
256 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
257 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) { | |
258 | print CONF "mtu-disc $sovpnsettings{'PMTU_DISCOVERY'}\n"; | |
2ee746be SS |
259 | } |
260 | ||
c6c9630e MT |
261 | if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) { |
262 | print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n"; | |
263 | } | |
264 | print CONF "status-version 1\n"; | |
4e17adad | 265 | print CONF "status /var/log/ovpnserver.log 30\n"; |
c6c9630e | 266 | print CONF "cipher $sovpnsettings{DCIPHER}\n"; |
49abe7af EK |
267 | if ($sovpnsettings{'DAUTH'} eq '') { |
268 | print CONF ""; | |
269 | } else { | |
270 | print CONF "auth $sovpnsettings{'DAUTH'}\n"; | |
271 | } | |
272 | if ($sovpnsettings{'TLSAUTH'} eq 'on') { | |
4be45949 | 273 | print CONF "tls-auth ${General::swroot}/ovpn/certs/ta.key\n"; |
49abe7af | 274 | } |
c6c9630e MT |
275 | if ($sovpnsettings{DCOMPLZO} eq 'on') { |
276 | print CONF "comp-lzo\n"; | |
277 | } | |
278 | if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') { | |
279 | print CONF "push \"redirect-gateway def1\"\n"; | |
280 | } | |
281 | if ($sovpnsettings{DHCP_DOMAIN} ne '') { | |
282 | print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n"; | |
283 | } | |
284 | ||
285 | if ($sovpnsettings{DHCP_DNS} ne '') { | |
286 | print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n"; | |
287 | } | |
288 | ||
289 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
290 | print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n"; | |
291 | } | |
292 | ||
293 | if ($sovpnsettings{DHCP_WINS} eq '') { | |
294 | print CONF "max-clients 100\n"; | |
a79fa1d6 | 295 | } |
c6c9630e MT |
296 | if ($sovpnsettings{DHCP_WINS} ne '') { |
297 | print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n"; | |
298 | } | |
1d0a260a | 299 | print CONF "tls-verify /usr/lib/openvpn/verify\n"; |
c6c9630e MT |
300 | print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n"; |
301 | print CONF "user nobody\n"; | |
302 | print CONF "group nobody\n"; | |
303 | print CONF "persist-key\n"; | |
304 | print CONF "persist-tun\n"; | |
305 | if ($sovpnsettings{LOG_VERB} ne '') { | |
306 | print CONF "verb $sovpnsettings{LOG_VERB}\n"; | |
307 | } else { | |
308 | print CONF "verb 3\n"; | |
309 | } | |
310 | print CONF "\n"; | |
311 | ||
312 | close(CONF); | |
313 | } | |
8c877a82 | 314 | |
c6c9630e | 315 | sub emptyserverlog{ |
4e17adad | 316 | if (open(FILE, ">/var/log/ovpnserver.log")) { |
c6c9630e MT |
317 | flock FILE, 2; |
318 | print FILE ""; | |
319 | close FILE; | |
320 | } | |
321 | ||
322 | } | |
323 | ||
8c877a82 AM |
324 | sub delccdnet |
325 | { | |
326 | my %ccdconfhash = (); | |
327 | my %ccdhash = (); | |
328 | my $ccdnetname=$_[0]; | |
329 | if (-f "${General::swroot}/ovpn/ovpnconfig"){ | |
330 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
331 | foreach my $key (keys %ccdhash) { | |
332 | if ($ccdhash{$key}[32] eq $ccdnetname) { | |
333 | $errormessage=$Lang::tr{'ccd err hostinnet'}; | |
334 | return; | |
335 | } | |
336 | } | |
337 | } | |
338 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
339 | foreach my $key (keys %ccdconfhash) { | |
340 | if ($ccdconfhash{$key}[0] eq $ccdnetname){ | |
341 | delete $ccdconfhash{$key}; | |
342 | } | |
343 | } | |
344 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
345 | ||
346 | &writeserverconf; | |
347 | return 0; | |
348 | } | |
349 | ||
350 | sub addccdnet | |
351 | { | |
352 | my %ccdconfhash=(); | |
353 | my @ccdconf=(); | |
354 | my $ccdname=$_[0]; | |
355 | my $ccdnet=$_[1]; | |
8c877a82 AM |
356 | my $subcidr; |
357 | my @ip2=(); | |
358 | my $checkup; | |
359 | my $ccdip; | |
360 | my $baseaddress; | |
290007b3 AM |
361 | |
362 | ||
363 | #check name | |
364 | if ($ccdname eq '') | |
365 | { | |
366 | $errormessage=$errormessage.$Lang::tr{'ccd err name'}."<br>"; | |
367 | return | |
368 | } | |
369 | ||
370 | if(!&General::validhostname($ccdname)) | |
371 | { | |
8c877a82 AM |
372 | $errormessage=$Lang::tr{'ccd err invalidname'}; |
373 | return; | |
374 | } | |
290007b3 AM |
375 | |
376 | ($ccdip,$subcidr) = split (/\//,$ccdnet); | |
377 | $subcidr=&General::iporsubtocidr($subcidr); | |
378 | #check subnet | |
379 | if ($subcidr > 30) | |
380 | { | |
8c877a82 AM |
381 | $errormessage=$Lang::tr{'ccd err invalidnet'}; |
382 | return; | |
383 | } | |
290007b3 AM |
384 | #check ip |
385 | if (!&General::validipandmask($ccdnet)){ | |
386 | $errormessage=$Lang::tr{'ccd err invalidnet'}; | |
387 | return; | |
8c877a82 | 388 | } |
290007b3 | 389 | |
e2429e8d | 390 | $errormessage=&General::checksubnets($ccdname,$ccdnet); |
290007b3 | 391 | |
8c877a82 AM |
392 | |
393 | if (!$errormessage) { | |
394 | my %ccdconfhash=(); | |
395 | $baseaddress=&General::getnetworkip($ccdip,$subcidr); | |
396 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
397 | my $key = &General::findhasharraykey (\%ccdconfhash); | |
398 | foreach my $i (0 .. 1) { $ccdconfhash{$key}[$i] = "";} | |
399 | $ccdconfhash{$key}[0] = $ccdname; | |
400 | $ccdconfhash{$key}[1] = $baseaddress."/".$subcidr; | |
401 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
402 | &writeserverconf; | |
403 | $cgiparams{'ccdname'}=''; | |
404 | $cgiparams{'ccdsubnet'}=''; | |
405 | return 1; | |
406 | } | |
407 | } | |
408 | ||
409 | sub modccdnet | |
410 | { | |
411 | ||
412 | my $newname=$_[0]; | |
413 | my $oldname=$_[1]; | |
414 | my %ccdconfhash=(); | |
415 | my %ccdhash=(); | |
416 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
417 | foreach my $key (keys %ccdconfhash) { | |
418 | if ($ccdconfhash{$key}[0] eq $oldname) { | |
419 | foreach my $key1 (keys %ccdconfhash) { | |
420 | if ($ccdconfhash{$key1}[0] eq $newname){ | |
421 | $errormessage=$errormessage.$Lang::tr{'ccd err netadrexist'}; | |
422 | return; | |
423 | }else{ | |
424 | $ccdconfhash{$key}[0]= $newname; | |
425 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
426 | last; | |
427 | } | |
428 | } | |
429 | } | |
430 | } | |
431 | ||
432 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
433 | foreach my $key (keys %ccdhash) { | |
434 | if ($ccdhash{$key}[32] eq $oldname) { | |
435 | $ccdhash{$key}[32]=$newname; | |
436 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
437 | last; | |
438 | } | |
439 | } | |
440 | ||
441 | return 0; | |
442 | } | |
443 | sub ccdmaxclients | |
444 | { | |
445 | my $ccdnetwork=$_[0]; | |
446 | my @octets=(); | |
447 | my @subnet=(); | |
448 | @octets=split("\/",$ccdnetwork); | |
449 | @subnet= split /\./, &General::cidrtosub($octets[1]); | |
450 | my ($a,$b,$c,$d,$e); | |
451 | $a=256-$subnet[0]; | |
452 | $b=256-$subnet[1]; | |
453 | $c=256-$subnet[2]; | |
454 | $d=256-$subnet[3]; | |
455 | $e=($a*$b*$c*$d)/4; | |
456 | return $e-1; | |
457 | } | |
458 | ||
459 | sub getccdadresses | |
460 | { | |
461 | my $ipin=$_[0]; | |
462 | my ($ip1,$ip2,$ip3,$ip4)=split /\./, $ipin; | |
463 | my $cidr=$_[1]; | |
464 | chomp($cidr); | |
465 | my $count=$_[2]; | |
466 | my $hasip=$_[3]; | |
467 | chomp($hasip); | |
468 | my @iprange=(); | |
469 | my %ccdhash=(); | |
470 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
d9fe5693 | 471 | $iprange[0]=$ip1.".".$ip2.".".$ip3.".".($ip4+2); |
ac87f371 | 472 | for (my $i=1;$i<=$count;$i++) { |
8c877a82 AM |
473 | my $tmpip=$iprange[$i-1]; |
474 | my $stepper=$i*4; | |
475 | $iprange[$i]= &General::getnextip($tmpip,4); | |
476 | } | |
477 | my $r=0; | |
478 | foreach my $key (keys %ccdhash) { | |
479 | $r=0; | |
480 | foreach my $tmp (@iprange){ | |
481 | my ($net,$sub) = split (/\//,$ccdhash{$key}[33]); | |
482 | if ($net eq $tmp) { | |
483 | if ( $hasip ne $ccdhash{$key}[33] ){ | |
484 | splice (@iprange,$r,1); | |
485 | } | |
486 | } | |
487 | $r++; | |
488 | } | |
489 | } | |
490 | return @iprange; | |
491 | } | |
492 | ||
493 | sub fillselectbox | |
494 | { | |
495 | my $boxname=$_[1]; | |
496 | my ($ccdip,$subcidr) = split("/",$_[0]); | |
497 | my $tz=$_[2]; | |
498 | my @allccdips=&getccdadresses($ccdip,$subcidr,&ccdmaxclients($ccdip."/".$subcidr),$tz); | |
499 | print"<select name='$boxname' STYLE='font-family : arial; font-size : 9pt; width:130px;' >"; | |
500 | foreach (@allccdips) { | |
501 | my $ip=$_."/30"; | |
502 | chomp($ip); | |
503 | print "<option value='$ip' "; | |
504 | if ( $ip eq $cgiparams{$boxname} ){ | |
505 | print"selected"; | |
506 | } | |
507 | print ">$ip</option>"; | |
508 | } | |
509 | print "</select>"; | |
510 | } | |
511 | ||
512 | sub hostsinnet | |
513 | { | |
514 | my $name=$_[0]; | |
515 | my %ccdhash=(); | |
516 | my $i=0; | |
517 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
518 | foreach my $key (keys %ccdhash) { | |
519 | if ($ccdhash{$key}[32] eq $name){ $i++;} | |
520 | } | |
521 | return $i; | |
522 | } | |
523 | ||
524 | sub check_routes_push | |
525 | { | |
526 | my $val=$_[0]; | |
527 | my ($ip,$cidr) = split (/\//, $val); | |
528 | ##check for existing routes in routes_push | |
529 | if (-e "${General::swroot}/ovpn/routes_push") { | |
530 | open(FILE,"${General::swroot}/ovpn/routes_push"); | |
531 | while (<FILE>) { | |
532 | $_=~s/\s*$//g; | |
533 | ||
534 | my ($ip2,$cidr2) = split (/\//,"$_"); | |
535 | my $val2=$ip2."/".&General::iporsubtodec($cidr2); | |
536 | ||
537 | if($val eq $val2){ | |
538 | return 0; | |
539 | } | |
540 | #subnetcheck | |
541 | if (&General::IpInSubnet ($ip,$ip2,&General::iporsubtodec($cidr2))){ | |
542 | return 0; | |
543 | } | |
544 | }; | |
545 | close(FILE); | |
546 | } | |
547 | return 1; | |
548 | } | |
549 | ||
550 | sub check_ccdroute | |
551 | { | |
552 | my %ccdroutehash=(); | |
553 | my $val=$_[0]; | |
554 | my ($ip,$cidr) = split (/\//, $val); | |
555 | #check for existing routes in ccdroute | |
556 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
557 | foreach my $key (keys %ccdroutehash) { | |
558 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
559 | if (&General::iporsubtodec($val) eq $ccdroutehash{$key}[$i] && $ccdroutehash{$key}[0] ne $cgiparams{'NAME'}){ | |
560 | return 0; | |
561 | } | |
562 | my ($ip2,$cidr2) = split (/\//,$ccdroutehash{$key}[$i]); | |
563 | #subnetcheck | |
564 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)&& $ccdroutehash{$key}[0] ne $cgiparams{'NAME'} ){ | |
565 | return 0; | |
566 | } | |
567 | } | |
568 | } | |
569 | return 1; | |
570 | } | |
571 | sub check_ccdconf | |
572 | { | |
573 | my %ccdconfhash=(); | |
574 | my $val=$_[0]; | |
575 | my ($ip,$cidr) = split (/\//, $val); | |
576 | #check for existing routes in ccdroute | |
577 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
578 | foreach my $key (keys %ccdconfhash) { | |
579 | if (&General::iporsubtocidr($val) eq $ccdconfhash{$key}[1]){ | |
580 | return 0; | |
581 | } | |
582 | my ($ip2,$cidr2) = split (/\//,$ccdconfhash{$key}[1]); | |
583 | #subnetcheck | |
584 | if (&General::IpInSubnet ($ip,$ip2,&General::cidrtosub($cidr2))){ | |
585 | return 0; | |
586 | } | |
587 | ||
588 | } | |
589 | return 1; | |
590 | } | |
591 | ||
7c1d9faf AH |
592 | ### |
593 | # m.a.d net2net | |
594 | ### | |
595 | ||
596 | sub validdotmask | |
597 | { | |
598 | my $ipdotmask = $_[0]; | |
599 | if (&General::validip($ipdotmask)) { return 0; } | |
600 | if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { } | |
601 | my $mask = $2; | |
602 | if (($mask =~ /\./ )) { return 0; } | |
603 | return 1; | |
604 | } | |
54fd0535 MT |
605 | |
606 | # ------------------------------------------------------------------- | |
607 | ||
608 | sub write_routepushfile | |
609 | { | |
610 | open(FILE, ">$routes_push_file"); | |
611 | flock(FILE, 2); | |
612 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { | |
613 | print FILE $vpnsettings{'ROUTES_PUSH'}; | |
614 | } | |
615 | close(FILE); | |
616 | } | |
617 | ||
618 | sub read_routepushfile | |
619 | { | |
620 | if (-e "$routes_push_file") { | |
621 | open(FILE,"$routes_push_file"); | |
622 | delete $vpnsettings{'ROUTES_PUSH'}; | |
623 | while (<FILE>) { $vpnsettings{'ROUTES_PUSH'} .= $_ }; | |
624 | close(FILE); | |
625 | $cgiparams{'ROUTES_PUSH'} = $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 | 626 | |
54fd0535 MT |
627 | } |
628 | } | |
7c1d9faf AH |
629 | |
630 | ||
c6c9630e MT |
631 | #hier die refresh page |
632 | if ( -e "${General::swroot}/ovpn/gencanow") { | |
633 | my $refresh = ''; | |
634 | $refresh = "<meta http-equiv='refresh' content='15;' />"; | |
635 | &Header::showhttpheaders(); | |
636 | &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh); | |
637 | &Header::openbigbox('100%', 'center'); | |
638 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
639 | print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n"; | |
640 | print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n"; | |
641 | &Header::closebox(); | |
642 | &Header::closebigbox(); | |
643 | &Header::closepage(); | |
644 | exit (0); | |
645 | } | |
646 | ##hier die refresh page | |
647 | ||
6e13d0a5 MT |
648 | |
649 | ### | |
650 | ### OpenVPN Server Control | |
651 | ### | |
652 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} || | |
653 | $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} || | |
654 | $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) { | |
6e13d0a5 MT |
655 | #start openvpn server |
656 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){ | |
c6c9630e | 657 | &emptyserverlog(); |
6e13d0a5 MT |
658 | system('/usr/local/bin/openvpnctrl', '-s'); |
659 | } | |
660 | #stop openvpn server | |
661 | if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){ | |
6e13d0a5 | 662 | system('/usr/local/bin/openvpnctrl', '-k'); |
c6c9630e | 663 | &emptyserverlog(); |
6e13d0a5 MT |
664 | } |
665 | # #restart openvpn server | |
8c877a82 | 666 | # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){ |
6e13d0a5 | 667 | #workarund, till SIGHUP also works when running as nobody |
8c877a82 AM |
668 | # system('/usr/local/bin/openvpnctrl', '-r'); |
669 | # &emptyserverlog(); | |
670 | # } | |
6e13d0a5 MT |
671 | } |
672 | ||
673 | ### | |
674 | ### Save Advanced options | |
675 | ### | |
676 | ||
677 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) { | |
678 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
679 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, | |
680 | #DAN this value has to leave. | |
681 | #new settings for daemon | |
682 | $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'}; | |
683 | $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'}; | |
684 | $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'}; | |
685 | $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'}; | |
686 | $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'}; | |
687 | $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'}; | |
688 | $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'}; | |
689 | $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'}; | |
690 | $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'}; | |
54fd0535 | 691 | $vpnsettings{'ROUTES_PUSH'} = $cgiparams{'ROUTES_PUSH'}; |
2ee746be | 692 | $vpnsettings{'PMTU_DISCOVERY'} = $cgiparams{'PMTU_DISCOVERY'}; |
4c962356 | 693 | $vpnsettings{'DAUTH'} = $cgiparams{'DAUTH'}; |
49abe7af | 694 | $vpnsettings{'TLSAUTH'} = $cgiparams{'TLSAUTH'}; |
54fd0535 | 695 | my @temp=(); |
6e13d0a5 | 696 | |
a79fa1d6 JPT |
697 | if ($cgiparams{'FRAGMENT'} eq '') { |
698 | delete $vpnsettings{'FRAGMENT'}; | |
699 | } else { | |
700 | if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) { | |
701 | $errormessage = "Incorrect value, please insert only numbers."; | |
702 | goto ADV_ERROR; | |
703 | } else { | |
704 | $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'}; | |
705 | } | |
706 | } | |
49abe7af | 707 | |
a79fa1d6 | 708 | if ($cgiparams{'MSSFIX'} ne 'on') { |
1de5c945 | 709 | delete $vpnsettings{'MSSFIX'}; |
a79fa1d6 JPT |
710 | } else { |
711 | $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'}; | |
712 | } | |
2ee746be | 713 | |
1647059d SS |
714 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || |
715 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
716 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
717 | ||
2ee746be SS |
718 | if (($cgiparams{'MSSFIX'} eq 'on') || ($cgiparams{'FRAGMENT'} ne '')) { |
719 | $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'}; | |
720 | goto ADV_ERROR; | |
721 | } | |
722 | } | |
723 | ||
6e13d0a5 | 724 | if ($cgiparams{'DHCP_DOMAIN'} ne ''){ |
81da1b01 | 725 | unless (&General::validdomainname($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) { |
6e13d0a5 MT |
726 | $errormessage = $Lang::tr{'invalid input for dhcp domain'}; |
727 | goto ADV_ERROR; | |
728 | } | |
729 | } | |
730 | if ($cgiparams{'DHCP_DNS'} ne ''){ | |
731 | unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) { | |
732 | $errormessage = $Lang::tr{'invalid input for dhcp dns'}; | |
733 | goto ADV_ERROR; | |
734 | } | |
735 | } | |
736 | if ($cgiparams{'DHCP_WINS'} ne ''){ | |
737 | unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) { | |
738 | $errormessage = $Lang::tr{'invalid input for dhcp wins'}; | |
54fd0535 MT |
739 | goto ADV_ERROR; |
740 | } | |
741 | } | |
742 | if ($cgiparams{'ROUTES_PUSH'} ne ''){ | |
743 | @temp = split(/\n/,$cgiparams{'ROUTES_PUSH'}); | |
744 | undef $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 AM |
745 | |
746 | foreach my $tmpip (@temp) | |
54fd0535 MT |
747 | { |
748 | s/^\s+//g; s/\s+$//g; | |
8c877a82 AM |
749 | |
750 | if ($tmpip) | |
54fd0535 | 751 | { |
8c877a82 AM |
752 | $tmpip=~s/\s*$//g; |
753 | unless (&General::validipandmask($tmpip)) { | |
754 | $errormessage = "$tmpip ".$Lang::tr{'ovpn errmsg invalid ip or mask'}; | |
755 | goto ADV_ERROR; | |
54fd0535 | 756 | } |
8c877a82 AM |
757 | my ($ip, $cidr) = split("\/",&General::ipcidr2msk($tmpip)); |
758 | ||
54fd0535 MT |
759 | if ($ip eq $netsettings{'GREEN_NETADDRESS'} && $cidr eq $netsettings{'GREEN_NETMASK'}) { |
760 | $errormessage = $Lang::tr{'ovpn errmsg green already pushed'}; | |
8c877a82 AM |
761 | goto ADV_ERROR; |
762 | } | |
763 | # a.marx ccd | |
764 | my %ccdroutehash=(); | |
765 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
766 | foreach my $key (keys %ccdroutehash) { | |
767 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
768 | if ( $ip."/".$cidr eq $ccdroutehash{$key}[$i] ){ | |
769 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
770 | goto ADV_ERROR; | |
771 | } | |
772 | my ($ip2,$cidr2) = split(/\//,$ccdroutehash{$key}[$i]); | |
773 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)){ | |
774 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
775 | goto ADV_ERROR; | |
776 | } | |
777 | } | |
54fd0535 | 778 | } |
8c877a82 AM |
779 | |
780 | # ccd end | |
781 | ||
782 | $vpnsettings{'ROUTES_PUSH'} .= $tmpip."\n"; | |
54fd0535 | 783 | } |
8c877a82 AM |
784 | } |
785 | &write_routepushfile; | |
54fd0535 | 786 | undef $vpnsettings{'ROUTES_PUSH'}; |
8e148dc3 NP |
787 | } |
788 | else { | |
789 | undef $vpnsettings{'ROUTES_PUSH'}; | |
790 | &write_routepushfile; | |
6e13d0a5 | 791 | } |
6e13d0a5 MT |
792 | if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 255 )) { |
793 | $errormessage = $Lang::tr{'invalid input for max clients'}; | |
794 | goto ADV_ERROR; | |
795 | } | |
796 | if ($cgiparams{'KEEPALIVE_1'} ne '') { | |
797 | if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) { | |
798 | $errormessage = $Lang::tr{'invalid input for keepalive 1'}; | |
799 | goto ADV_ERROR; | |
800 | } | |
801 | } | |
802 | if ($cgiparams{'KEEPALIVE_2'} ne ''){ | |
803 | if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) { | |
804 | $errormessage = $Lang::tr{'invalid input for keepalive 2'}; | |
805 | goto ADV_ERROR; | |
806 | } | |
807 | } | |
808 | if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){ | |
809 | $errormessage = $Lang::tr{'invalid input for keepalive 1:2'}; | |
810 | goto ADV_ERROR; | |
811 | } | |
4be45949 EK |
812 | # Create ta.key for tls-auth if not presant |
813 | if ($cgiparams{'TLSAUTH'} eq 'on') { | |
814 | if ( ! -e "${General::swroot}/ovpn/certs/ta.key") { | |
815 | system('/usr/sbin/openvpn', '--genkey', '--secret', "${General::swroot}/ovpn/certs/ta.key"); | |
816 | if ($?) { | |
817 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
818 | goto ADV_ERROR; | |
819 | } | |
820 | } | |
821 | } | |
6e13d0a5 MT |
822 | |
823 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 824 | &writeserverconf();#hier ok |
6e13d0a5 MT |
825 | } |
826 | ||
ce9abb66 | 827 | ### |
7c1d9faf | 828 | # m.a.d net2net |
ce9abb66 AH |
829 | ### |
830 | ||
831 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server') | |
832 | { | |
c6c9630e | 833 | |
ce9abb66 AH |
834 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
835 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
54fd0535 | 836 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
d96c89eb | 837 | my $tunmtu = ''; |
531f0835 AH |
838 | |
839 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
840 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
841 | |
842 | open(SERVERCONF, ">${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Unable to open ${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf: $!"; | |
843 | ||
844 | flock SERVERCONF, 2; | |
7c1d9faf | 845 | print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n"; |
ce9abb66 | 846 | print SERVERCONF "\n"; |
b278daf3 | 847 | print SERVERCONF "# User Security\n"; |
ce9abb66 AH |
848 | print SERVERCONF "user nobody\n"; |
849 | print SERVERCONF "group nobody\n"; | |
850 | print SERVERCONF "persist-tun\n"; | |
851 | print SERVERCONF "persist-key\n"; | |
7c1d9faf | 852 | print SERVERCONF "script-security 2\n"; |
60f396d7 | 853 | print SERVERCONF "# IP/DNS for remote Server Gateway\n"; |
c125d8a2 SS |
854 | |
855 | if ($cgiparams{'REMOTE'} ne '') { | |
ce9abb66 | 856 | print SERVERCONF "remote $cgiparams{'REMOTE'}\n"; |
c125d8a2 SS |
857 | } |
858 | ||
b278daf3 | 859 | print SERVERCONF "float\n"; |
60f396d7 | 860 | print SERVERCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 861 | print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n"; |
60f396d7 | 862 | print SERVERCONF "# Client Gateway Network\n"; |
54fd0535 | 863 | print SERVERCONF "route $remsubnet[0] $remsubnet[1]\n"; |
60f396d7 | 864 | print SERVERCONF "# tun Device\n"; |
ce9abb66 | 865 | print SERVERCONF "dev tun\n"; |
60f396d7 | 866 | print SERVERCONF "# Port and Protokol\n"; |
ce9abb66 | 867 | print SERVERCONF "port $cgiparams{'DEST_PORT'}\n"; |
60f396d7 AH |
868 | |
869 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
870 | print SERVERCONF "proto tcp-server\n"; | |
871 | print SERVERCONF "# Packet size\n"; | |
d96c89eb | 872 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 873 | print SERVERCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 874 | } |
60f396d7 AH |
875 | |
876 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
877 | print SERVERCONF "proto udp\n"; | |
878 | print SERVERCONF "# Paketsize\n"; | |
879 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
880 | print SERVERCONF "tun-mtu $tunmtu\n"; | |
54fd0535 MT |
881 | if ($cgiparams{'FRAGMENT'} ne '') {print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
882 | if ($cgiparams{'MSSFIX'} eq 'on') {print SERVERCONF "mssfix\n"; }; | |
d96c89eb | 883 | } |
1647059d SS |
884 | |
885 | # Check if a valid operating mode has been choosen and use it. | |
886 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || | |
887 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
888 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
2ee746be SS |
889 | if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) { |
890 | if($cgiparams{'MTU'} eq '1500') { | |
891 | print SERVERCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n"; | |
892 | } | |
893 | } | |
894 | } | |
60f396d7 | 895 | print SERVERCONF "# Auth. Server\n"; |
ce9abb66 AH |
896 | print SERVERCONF "tls-server\n"; |
897 | print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; | |
898 | print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
899 | print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
49abe7af | 900 | print SERVERCONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; |
b278daf3 | 901 | print SERVERCONF "# Cipher\n"; |
4c962356 | 902 | print SERVERCONF "cipher $cgiparams{'DCIPHER'}\n"; |
49abe7af EK |
903 | if ($cgiparams{'DAUTH'} eq '') { |
904 | print SERVERCONF "auth SHA1\n"; | |
905 | } else { | |
906 | print SERVERCONF "# HMAC algorithm\n"; | |
907 | print SERVERCONF "auth $cgiparams{'DAUTH'}\n"; | |
908 | } | |
ce9abb66 | 909 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 910 | print SERVERCONF "# Enable Compression\n"; |
66298ef2 | 911 | print SERVERCONF "comp-lzo\n"; |
b278daf3 | 912 | } |
60f396d7 | 913 | print SERVERCONF "# Debug Level\n"; |
ce9abb66 | 914 | print SERVERCONF "verb 3\n"; |
b278daf3 | 915 | print SERVERCONF "# Tunnel check\n"; |
ce9abb66 | 916 | print SERVERCONF "keepalive 10 60\n"; |
60f396d7 | 917 | print SERVERCONF "# Start as daemon\n"; |
ce9abb66 AH |
918 | print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n"; |
919 | print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 920 | print SERVERCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
921 | if ($cgiparams{'OVPN_MGMT'} eq '') {print SERVERCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
922 | else {print SERVERCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 AH |
923 | close(SERVERCONF); |
924 | ||
925 | } | |
926 | ||
927 | ### | |
7c1d9faf | 928 | # m.a.d net2net |
ce9abb66 | 929 | ### |
7c1d9faf | 930 | |
ce9abb66 AH |
931 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client') |
932 | { | |
4c962356 | 933 | |
ce9abb66 | 934 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); |
54fd0535 | 935 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 936 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
d96c89eb | 937 | my $tunmtu = ''; |
54fd0535 | 938 | |
531f0835 AH |
939 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
940 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
941 | |
942 | open(CLIENTCONF, ">${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Unable to open ${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf: $!"; | |
943 | ||
944 | flock CLIENTCONF, 2; | |
7c1d9faf | 945 | print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 946 | print CLIENTCONF "#\n"; |
b278daf3 | 947 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
948 | print CLIENTCONF "user nobody\n"; |
949 | print CLIENTCONF "group nobody\n"; | |
950 | print CLIENTCONF "persist-tun\n"; | |
951 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 952 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 953 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
ce9abb66 | 954 | print CLIENTCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 | 955 | print CLIENTCONF "float\n"; |
60f396d7 | 956 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 957 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
60f396d7 | 958 | print CLIENTCONF "# Server Gateway Network\n"; |
54fd0535 | 959 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
60f396d7 | 960 | print CLIENTCONF "# tun Device\n"; |
ce9abb66 | 961 | print CLIENTCONF "dev tun\n"; |
60f396d7 | 962 | print CLIENTCONF "# Port and Protokol\n"; |
ce9abb66 | 963 | print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n"; |
60f396d7 AH |
964 | |
965 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
966 | print CLIENTCONF "proto tcp-client\n"; | |
967 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 968 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 969 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 970 | } |
60f396d7 AH |
971 | |
972 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
973 | print CLIENTCONF "proto udp\n"; | |
974 | print CLIENTCONF "# Paketsize\n"; | |
975 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
976 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 MT |
977 | if ($cgiparams{'FRAGMENT'} ne '') {print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
978 | if ($cgiparams{'MSSFIX'} eq 'on') {print CLIENTCONF "mssfix\n"; }; | |
d96c89eb | 979 | } |
1647059d SS |
980 | |
981 | # Check if a valid operating mode has been choosen and use it. | |
982 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || | |
983 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
984 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
2ee746be SS |
985 | if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) { |
986 | if ($cgiparams{'MTU'} eq '1500') { | |
987 | print CLIENTCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n"; | |
988 | } | |
989 | } | |
1647059d SS |
990 | } |
991 | ||
54fd0535 | 992 | print CLIENTCONF "ns-cert-type server\n"; |
ce9abb66 AH |
993 | print CLIENTCONF "# Auth. Client\n"; |
994 | print CLIENTCONF "tls-client\n"; | |
b278daf3 | 995 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 996 | print CLIENTCONF "cipher $cgiparams{'DCIPHER'}\n"; |
ce9abb66 | 997 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n"; |
49abe7af EK |
998 | if ($cgiparams{'DAUTH'} eq '') { |
999 | print CLIENTCONF "auth SHA1\n"; | |
1000 | } else { | |
1001 | print CLIENTCONF "# HMAC algorithm\n"; | |
1002 | print CLIENTCONF "auth $cgiparams{'DAUTH'}\n"; | |
1003 | } | |
ce9abb66 | 1004 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 1005 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 1006 | print CLIENTCONF "comp-lzo\n"; |
4c962356 | 1007 | } |
ce9abb66 AH |
1008 | print CLIENTCONF "# Debug Level\n"; |
1009 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 1010 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 1011 | print CLIENTCONF "keepalive 10 60\n"; |
60f396d7 | 1012 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
1013 | print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n"; |
1014 | print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 1015 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
1016 | if ($cgiparams{'OVPN_MGMT'} eq '') {print CLIENTCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
1017 | else {print CLIENTCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 | 1018 | close(CLIENTCONF); |
c6c9630e | 1019 | |
ce9abb66 AH |
1020 | } |
1021 | ||
6e13d0a5 MT |
1022 | ### |
1023 | ### Save main settings | |
1024 | ### | |
ce9abb66 | 1025 | |
6e13d0a5 MT |
1026 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { |
1027 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 MT |
1028 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, |
1029 | #DAN this value has to leave. | |
1030 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
1031 | unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) { | |
1032 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
c6c9630e | 1033 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1034 | } |
1035 | } | |
f7fb5bc5 | 1036 | |
6e13d0a5 | 1037 | if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) { |
c6c9630e | 1038 | $errormessage = $Lang::tr{'ovpn subnet is invalid'}; |
4c962356 | 1039 | goto SETTINGS_ERROR; |
c6c9630e MT |
1040 | } |
1041 | my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'}); | |
1042 | ||
1043 | if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'}, | |
1044 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1045 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}"; | |
1046 | goto SETTINGS_ERROR; | |
1047 | } | |
1048 | ||
1049 | if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'}, | |
1050 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1051 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}"; | |
1052 | goto SETTINGS_ERROR; | |
1053 | } | |
1054 | ||
1055 | if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'}, | |
1056 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1057 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}"; | |
1058 | goto SETTINGS_ERROR; | |
1059 | } | |
1060 | ||
1061 | if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'}, | |
1062 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1063 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}"; | |
1064 | goto SETTINGS_ERROR; | |
1065 | } | |
1066 | open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.'; | |
1067 | while (<ALIASES>) | |
1068 | { | |
1069 | chomp($_); | |
1070 | my @tempalias = split(/\,/,$_); | |
1071 | if ($tempalias[1] eq 'on') { | |
1072 | if (&General::IpInSubnet ($tempalias[0] , | |
1073 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1074 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]"; | |
1075 | } | |
1076 | } | |
1077 | } | |
1078 | close(ALIASES); | |
6e13d0a5 | 1079 | if ($errormessage ne ''){ |
c6c9630e | 1080 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1081 | } |
1082 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
1083 | $errormessage = $Lang::tr{'invalid input'}; | |
1084 | goto SETTINGS_ERROR; | |
1085 | } | |
1086 | if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) { | |
1087 | $errormessage = $Lang::tr{'invalid mtu input'}; | |
1088 | goto SETTINGS_ERROR; | |
1089 | } | |
1090 | ||
1091 | unless (&General::validport($cgiparams{'DDEST_PORT'})) { | |
c6c9630e MT |
1092 | $errormessage = $Lang::tr{'invalid port'}; |
1093 | goto SETTINGS_ERROR; | |
6e13d0a5 | 1094 | } |
8c252e6a | 1095 | |
6e13d0a5 MT |
1096 | $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'}; |
1097 | $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'}; | |
1098 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
1099 | $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'}; | |
1100 | #new settings for daemon | |
1101 | $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'}; | |
1102 | $vpnsettings{'DDEVICE'} = $cgiparams{'DDEVICE'}; | |
1103 | $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'}; | |
1104 | $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'}; | |
1105 | $vpnsettings{'DMTU'} = $cgiparams{'DMTU'}; | |
1106 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; | |
1107 | $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'}; | |
3ffee04b CS |
1108 | #wrtie enable |
1109 | ||
1110 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable_blue 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable_blue 2>/dev/null");} | |
1111 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable_orange 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable_orange 2>/dev/null");} | |
1112 | if ( $vpnsettings{'ENABLED'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable 2>/dev/null");} | |
6e13d0a5 MT |
1113 | #new settings for daemon |
1114 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 1115 | &writeserverconf();#hier ok |
6e13d0a5 MT |
1116 | SETTINGS_ERROR: |
1117 | ### | |
1118 | ### Reset all step 2 | |
1119 | ### | |
4c962356 | 1120 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'} && $cgiparams{'AREUSURE'} eq 'yes') { |
6e13d0a5 MT |
1121 | my $file = ''; |
1122 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1123 | ||
1124 | foreach my $key (keys %confighash) { | |
c6c9630e MT |
1125 | if ($confighash{$key}[4] eq 'cert') { |
1126 | delete $confighash{$cgiparams{'$key'}}; | |
1127 | } | |
6e13d0a5 MT |
1128 | } |
1129 | while ($file = glob("${General::swroot}/ovpn/ca/*")) { | |
49abe7af | 1130 | unlink $file; |
6e13d0a5 MT |
1131 | } |
1132 | while ($file = glob("${General::swroot}/ovpn/certs/*")) { | |
49abe7af | 1133 | unlink $file; |
6e13d0a5 MT |
1134 | } |
1135 | while ($file = glob("${General::swroot}/ovpn/crls/*")) { | |
49abe7af | 1136 | unlink $file; |
6e13d0a5 | 1137 | } |
4c962356 | 1138 | &cleanssldatabase(); |
6e13d0a5 MT |
1139 | if (open(FILE, ">${General::swroot}/ovpn/caconfig")) { |
1140 | print FILE ""; | |
1141 | close FILE; | |
1142 | } | |
49abe7af EK |
1143 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute")) { |
1144 | print FILE ""; | |
1145 | close FILE; | |
1146 | } | |
1147 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute2")) { | |
1148 | print FILE ""; | |
1149 | close FILE; | |
1150 | } | |
1151 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { | |
1152 | unlink $file | |
1153 | } | |
1154 | if (open(FILE, ">${General::swroot}/ovpn/ovpn-leases.db")) { | |
1155 | print FILE ""; | |
1156 | close FILE; | |
1157 | } | |
1158 | if (open(FILE, ">${General::swroot}/ovpn/ovpnconfig")) { | |
1159 | print FILE ""; | |
1160 | close FILE; | |
1161 | } | |
1162 | while ($file = glob("${General::swroot}/ovpn/n2nconf/*")) { | |
1163 | system ("rm -rf $file"); | |
1164 | } | |
1165 | ||
c6c9630e | 1166 | #&writeserverconf(); |
6e13d0a5 MT |
1167 | ### |
1168 | ### Reset all step 1 | |
1169 | ### | |
4c962356 | 1170 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'}) { |
6e13d0a5 | 1171 | &Header::showhttpheaders(); |
4c962356 EK |
1172 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
1173 | &Header::openbigbox('100%', 'left', '', ''); | |
1174 | &Header::openbox('100%', 'left', $Lang::tr{'are you sure'}); | |
1175 | print <<END; | |
1176 | <form method='post'> | |
1177 | <table width='100%'> | |
1178 | <tr> | |
1179 | <td align='center'> | |
1180 | <input type='hidden' name='AREUSURE' value='yes' /> | |
49abe7af | 1181 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: |
4c962356 EK |
1182 | $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td> |
1183 | </tr> | |
1184 | <tr> | |
1185 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /> | |
1186 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td> | |
1187 | </tr> | |
1188 | </table> | |
1189 | </form> | |
6e13d0a5 MT |
1190 | END |
1191 | ; | |
1192 | &Header::closebox(); | |
1193 | &Header::closebigbox(); | |
1194 | &Header::closepage(); | |
1195 | exit (0); | |
1196 | ||
4c962356 EK |
1197 | ### |
1198 | ### Generate DH key step 2 | |
1199 | ### | |
1200 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
49abe7af | 1201 | # Delete if old key exists |
4c962356 EK |
1202 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { |
1203 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1204 | } | |
1205 | # Create Diffie Hellmann Parameter | |
badd8c1c | 1206 | system('/usr/bin/openssl', 'dhparam', '-out', "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); |
4c962356 EK |
1207 | if ($?) { |
1208 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1209 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
1210 | } | |
1211 | ||
1212 | ### | |
1213 | ### Generate DH key step 1 | |
1214 | ### | |
1215 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'}) { | |
1216 | &Header::showhttpheaders(); | |
1217 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
1218 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1219 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'gen dh'}:"); | |
1220 | print <<END; | |
1221 | <table width='100%'> | |
1222 | <tr> | |
f527e53f | 1223 | <td width='20%'> </td> <td width='15%'></td> <td width='65%'></td> |
49abe7af | 1224 | </tr> |
4c962356 EK |
1225 | <tr> |
1226 | <td class='base'>$Lang::tr{'ovpn dh'}:</td> | |
1227 | <td align='center'> | |
1228 | <form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
1229 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1230 | <select name='DHLENGHT'> | |
1231 | <option value='1024' $selected{'DHLENGHT'}{'1024'}>1024 $Lang::tr{'bit'}</option> | |
1232 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> | |
1233 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
1234 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
1235 | </select> | |
1236 | </td> | |
1237 | </tr> | |
1238 | <tr><td colspan='4'><br></td></tr> | |
1239 | </table> | |
1240 | <table width='100%'> | |
1241 | <tr> | |
49abe7af | 1242 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'dh key warn'} |
4c962356 | 1243 | </tr> |
49abe7af EK |
1244 | <tr> |
1245 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
1246 | </tr> | |
1247 | <tr><td colspan='2'><br></td></tr> | |
4c962356 EK |
1248 | <tr> |
1249 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> | |
1250 | </form> | |
1251 | </tr> | |
1252 | </table> | |
1253 | ||
1254 | END | |
1255 | ; | |
1256 | &Header::closebox(); | |
1257 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1258 | &Header::closebigbox(); | |
1259 | &Header::closepage(); | |
1260 | exit (0); | |
1261 | ||
1262 | ### | |
1263 | ### Upload DH key | |
1264 | ### | |
1265 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload dh key'}) { | |
4c962356 EK |
1266 | if (ref ($cgiparams{'FH'}) ne 'Fh') { |
1267 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1268 | goto UPLOADCA_ERROR; | |
1269 | } | |
49abe7af | 1270 | # Move uploaded dh key to a temporary file |
4c962356 EK |
1271 | (my $fh, my $filename) = tempfile( ); |
1272 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1273 | $errormessage = $!; | |
49abe7af | 1274 | goto UPLOADCA_ERROR; |
4c962356 | 1275 | } |
49abe7af | 1276 | my $temp = `/usr/bin/openssl dhparam -text -in $filename`; |
4c962356 EK |
1277 | if ($temp !~ /DH Parameters: \((1024|2048|3072|4096) bit\)/) { |
1278 | $errormessage = $Lang::tr{'not a valid dh key'}; | |
1279 | unlink ($filename); | |
1280 | goto UPLOADCA_ERROR; | |
1281 | } else { | |
1282 | # Delete if old key exists | |
1283 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { | |
1284 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1285 | } | |
1286 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"); | |
49abe7af EK |
1287 | if ($? ne 0) { |
1288 | $errormessage = "$Lang::tr{'dh key move failed'}: $!"; | |
1289 | unlink ($filename); | |
1290 | goto UPLOADCA_ERROR; | |
1291 | } | |
4c962356 EK |
1292 | } |
1293 | ||
6e13d0a5 MT |
1294 | ### |
1295 | ### Upload CA Certificate | |
1296 | ### | |
1297 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
1298 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1299 | ||
1300 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
1301 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
1302 | goto UPLOADCA_ERROR; | |
1303 | } | |
1304 | ||
1305 | if (length($cgiparams{'CA_NAME'}) >60) { | |
1306 | $errormessage = $Lang::tr{'name too long'}; | |
1307 | goto VPNCONF_ERROR; | |
1308 | } | |
1309 | ||
1310 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
1311 | $errormessage = $Lang::tr{'name is invalid'}; | |
4c962356 | 1312 | goto UPLOADCA_ERROR; |
6e13d0a5 MT |
1313 | } |
1314 | ||
1315 | # Check if there is no other entry with this name | |
1316 | foreach my $key (keys %cahash) { | |
c6c9630e MT |
1317 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { |
1318 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
1319 | goto UPLOADCA_ERROR; | |
1320 | } | |
6e13d0a5 MT |
1321 | } |
1322 | ||
1323 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
c6c9630e MT |
1324 | $errormessage = $Lang::tr{'there was no file upload'}; |
1325 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1326 | } |
1327 | # Move uploaded ca to a temporary file | |
1328 | (my $fh, my $filename) = tempfile( ); | |
1329 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
c6c9630e MT |
1330 | $errormessage = $!; |
1331 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1332 | } |
1333 | my $temp = `/usr/bin/openssl x509 -text -in $filename`; | |
c6c9630e MT |
1334 | if ($temp !~ /CA:TRUE/i) { |
1335 | $errormessage = $Lang::tr{'not a valid ca certificate'}; | |
1336 | unlink ($filename); | |
1337 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 1338 | } else { |
c6c9630e MT |
1339 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); |
1340 | if ($? ne 0) { | |
1341 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1342 | unlink ($filename); | |
1343 | goto UPLOADCA_ERROR; | |
1344 | } | |
6e13d0a5 MT |
1345 | } |
1346 | ||
1347 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`; | |
1348 | $casubject =~ /Subject: (.*)[\n]/; | |
1349 | $casubject = $1; | |
1350 | $casubject =~ s+/Email+, E+; | |
1351 | $casubject =~ s/ ST=/ S=/; | |
1352 | $casubject = &Header::cleanhtml($casubject); | |
1353 | ||
1354 | my $key = &General::findhasharraykey (\%cahash); | |
1355 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
1356 | $cahash{$key}[1] = $casubject; | |
1357 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e MT |
1358 | # system('/usr/local/bin/ipsecctrl', 'R'); |
1359 | ||
6e13d0a5 MT |
1360 | UPLOADCA_ERROR: |
1361 | ||
1362 | ### | |
1363 | ### Display ca certificate | |
1364 | ### | |
1365 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
c6c9630e MT |
1366 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); |
1367 | ||
1368 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
1369 | &Header::showhttpheaders(); | |
4c962356 | 1370 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1371 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1372 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:"); | |
1373 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1374 | $output = &Header::cleanhtml($output,"y"); | |
1375 | print "<pre>$output</pre>\n"; | |
1376 | &Header::closebox(); | |
1377 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1378 | &Header::closebigbox(); | |
1379 | &Header::closepage(); | |
1380 | exit(0); | |
1381 | } else { | |
1382 | $errormessage = $Lang::tr{'invalid key'}; | |
1383 | } | |
1384 | ||
6e13d0a5 MT |
1385 | ### |
1386 | ### Download ca certificate | |
1387 | ### | |
1388 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
1389 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1390 | ||
1391 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1392 | print "Content-Type: application/octet-stream\r\n"; | |
1393 | print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
1394 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1395 | exit(0); | |
1396 | } else { | |
1397 | $errormessage = $Lang::tr{'invalid key'}; | |
1398 | } | |
1399 | ||
1400 | ### | |
1401 | ### Remove ca certificate (step 2) | |
1402 | ### | |
1403 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
1404 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1405 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1406 | ||
1407 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1408 | foreach my $key (keys %confighash) { | |
1409 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
1410 | if ($test =~ /: OK/) { | |
c6c9630e MT |
1411 | # Delete connection |
1412 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1413 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
1414 | # system('/usr/local/bin/ipsecctrl', 'D', $key); | |
1415 | # } | |
6e13d0a5 MT |
1416 | unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem"); |
1417 | unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12"); | |
1418 | delete $confighash{$key}; | |
1419 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 1420 | # &writeipsecfiles(); |
6e13d0a5 MT |
1421 | } |
1422 | } | |
1423 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1424 | delete $cahash{$cgiparams{'KEY'}}; | |
1425 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e | 1426 | # system('/usr/local/bin/ipsecctrl', 'R'); |
6e13d0a5 MT |
1427 | } else { |
1428 | $errormessage = $Lang::tr{'invalid key'}; | |
1429 | } | |
1430 | ### | |
1431 | ### Remove ca certificate (step 1) | |
1432 | ### | |
1433 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
1434 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1435 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1436 | ||
1437 | my $assignedcerts = 0; | |
1438 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1439 | foreach my $key (keys %confighash) { | |
1440 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
1441 | if ($test =~ /: OK/) { | |
1442 | $assignedcerts++; | |
1443 | } | |
1444 | } | |
1445 | if ($assignedcerts) { | |
1446 | &Header::showhttpheaders(); | |
4c962356 | 1447 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1448 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1449 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
4c962356 | 1450 | print <<END; |
6e13d0a5 MT |
1451 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> |
1452 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1453 | <tr><td align='center'> | |
1454 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts | |
1455 | $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'} | |
1456 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
1457 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1458 | </form></table> | |
1459 | END | |
1460 | ; | |
1461 | &Header::closebox(); | |
1462 | &Header::closebigbox(); | |
1463 | &Header::closepage(); | |
1464 | exit (0); | |
1465 | } else { | |
1466 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1467 | delete $cahash{$cgiparams{'KEY'}}; | |
1468 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1469 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1470 | } | |
1471 | } else { | |
1472 | $errormessage = $Lang::tr{'invalid key'}; | |
1473 | } | |
1474 | ||
1475 | ### | |
1476 | ### Display root certificate | |
1477 | ### | |
c6c9630e MT |
1478 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || |
1479 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
1480 | my $output; | |
1481 | &Header::showhttpheaders(); | |
4c962356 | 1482 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1483 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1484 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
1485 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:"); | |
1486 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1487 | } else { | |
1488 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:"); | |
1489 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1490 | } | |
1491 | $output = &Header::cleanhtml($output,"y"); | |
1492 | print "<pre>$output</pre>\n"; | |
1493 | &Header::closebox(); | |
1494 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1495 | &Header::closebigbox(); | |
1496 | &Header::closepage(); | |
1497 | exit(0); | |
1498 | ||
6e13d0a5 MT |
1499 | ### |
1500 | ### Download root certificate | |
1501 | ### | |
1502 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
1503 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
1504 | print "Content-Type: application/octet-stream\r\n"; | |
1505 | print "Content-Disposition: filename=cacert.pem\r\n\r\n"; | |
1506 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1507 | exit(0); | |
1508 | } | |
1509 | ||
1510 | ### | |
1511 | ### Download host certificate | |
1512 | ### | |
1513 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
1514 | if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) { | |
1515 | print "Content-Type: application/octet-stream\r\n"; | |
1516 | print "Content-Disposition: filename=servercert.pem\r\n\r\n"; | |
1517 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1518 | exit(0); | |
1519 | } | |
f7fb5bc5 | 1520 | |
fd5ccb2d EK |
1521 | ### |
1522 | ### Download tls-auth key | |
1523 | ### | |
1524 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download tls-auth key'}) { | |
1525 | if ( -f "${General::swroot}/ovpn/certs/ta.key" ) { | |
1526 | print "Content-Type: application/octet-stream\r\n"; | |
1527 | print "Content-Disposition: filename=ta.key\r\n\r\n"; | |
1528 | print `/bin/cat ${General::swroot}/ovpn/certs/ta.key`; | |
1529 | exit(0); | |
1530 | } | |
1531 | ||
6e13d0a5 MT |
1532 | ### |
1533 | ### Form for generating a root certificate | |
1534 | ### | |
1535 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
1536 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1537 | ||
1538 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1539 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
1540 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
1541 | $cgiparams{'ACTION'} = ''; | |
1542 | goto ROOTCERT_ERROR; | |
1543 | } | |
1544 | ||
1545 | if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") { | |
1546 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
1547 | my $ipaddr = <IPADDR>; | |
1548 | close IPADDR; | |
1549 | chomp ($ipaddr); | |
1550 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
1551 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
1552 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
1553 | } | |
1554 | } | |
1555 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1556 | ||
1557 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
1558 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1559 | goto ROOTCERT_ERROR; | |
1560 | } | |
1561 | ||
1562 | # Move uploaded certificate request to a temporary file | |
1563 | (my $fh, my $filename) = tempfile( ); | |
1564 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1565 | $errormessage = $!; | |
1566 | goto ROOTCERT_ERROR; | |
1567 | } | |
1568 | ||
1569 | # Create a temporary dirctory | |
1570 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1571 | ||
1572 | # Extract the CA certificate from the file | |
1573 | my $pid = open(OPENSSL, "|-"); | |
1574 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1575 | if ($pid) { # parent | |
1576 | if ($cgiparams{'P12_PASS'} ne '') { | |
1577 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1578 | } | |
1579 | close (OPENSSL); | |
1580 | if ($?) { | |
1581 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1582 | unlink ($filename); | |
1583 | goto ROOTCERT_ERROR; | |
1584 | } | |
1585 | } else { # child | |
1586 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys', | |
1587 | '-in', $filename, | |
1588 | '-out', "$tempdir/cacert.pem")) { | |
1589 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1590 | unlink ($filename); | |
1591 | goto ROOTCERT_ERROR; | |
1592 | } | |
1593 | } | |
1594 | ||
1595 | # Extract the Host certificate from the file | |
1596 | $pid = open(OPENSSL, "|-"); | |
1597 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1598 | if ($pid) { # parent | |
1599 | if ($cgiparams{'P12_PASS'} ne '') { | |
1600 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1601 | } | |
1602 | close (OPENSSL); | |
1603 | if ($?) { | |
1604 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1605 | unlink ($filename); | |
1606 | goto ROOTCERT_ERROR; | |
1607 | } | |
1608 | } else { # child | |
1609 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys', | |
1610 | '-in', $filename, | |
1611 | '-out', "$tempdir/hostcert.pem")) { | |
1612 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1613 | unlink ($filename); | |
1614 | goto ROOTCERT_ERROR; | |
1615 | } | |
1616 | } | |
1617 | ||
1618 | # Extract the Host key from the file | |
1619 | $pid = open(OPENSSL, "|-"); | |
1620 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1621 | if ($pid) { # parent | |
1622 | if ($cgiparams{'P12_PASS'} ne '') { | |
1623 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1624 | } | |
1625 | close (OPENSSL); | |
1626 | if ($?) { | |
1627 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1628 | unlink ($filename); | |
1629 | goto ROOTCERT_ERROR; | |
1630 | } | |
1631 | } else { # child | |
1632 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts', | |
1633 | '-nodes', | |
1634 | '-in', $filename, | |
1635 | '-out', "$tempdir/serverkey.pem")) { | |
1636 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1637 | unlink ($filename); | |
1638 | goto ROOTCERT_ERROR; | |
1639 | } | |
1640 | } | |
1641 | ||
1642 | move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem"); | |
1643 | if ($? ne 0) { | |
1644 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1645 | unlink ($filename); | |
1646 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1647 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1648 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1649 | goto ROOTCERT_ERROR; | |
1650 | } | |
1651 | ||
1652 | move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem"); | |
1653 | if ($? ne 0) { | |
1654 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1655 | unlink ($filename); | |
1656 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1657 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1658 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1659 | goto ROOTCERT_ERROR; | |
1660 | } | |
1661 | ||
1662 | move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem"); | |
1663 | if ($? ne 0) { | |
1664 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1665 | unlink ($filename); | |
1666 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1667 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1668 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1669 | goto ROOTCERT_ERROR; | |
1670 | } | |
1671 | ||
1672 | goto ROOTCERT_SUCCESS; | |
1673 | ||
1674 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
1675 | ||
1676 | # Validate input since the form was submitted | |
1677 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1678 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1679 | goto ROOTCERT_ERROR; | |
1680 | } | |
1681 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1682 | $errormessage = $Lang::tr{'organization too long'}; | |
1683 | goto ROOTCERT_ERROR; | |
1684 | } | |
1685 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1686 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1687 | goto ROOTCERT_ERROR; | |
1688 | } | |
1689 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1690 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1691 | goto ROOTCERT_ERROR; | |
1692 | } | |
1693 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1694 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1695 | goto ROOTCERT_ERROR; | |
1696 | } | |
1697 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1698 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1699 | goto ROOTCERT_ERROR; | |
1700 | } | |
1701 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1702 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1703 | goto ROOTCERT_ERROR; | |
1704 | } | |
1705 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1706 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1707 | goto ROOTCERT_ERROR; | |
1708 | } | |
1709 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1710 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1711 | goto ROOTCERT_ERROR; | |
1712 | } | |
1713 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1714 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1715 | goto ROOTCERT_ERROR; | |
1716 | } | |
1717 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1718 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1719 | goto ROOTCERT_ERROR; | |
1720 | } | |
1721 | ||
1722 | # Copy the cgisettings to vpnsettings and save the configfile | |
1723 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1724 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1725 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1726 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1727 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1728 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1729 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1730 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1731 | ||
1732 | # Replace empty strings with a . | |
1733 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1734 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1735 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1736 | ||
1737 | # refresh | |
c6c9630e | 1738 | #system ('/bin/touch', "${General::swroot}/ovpn/gencanow"); |
6e13d0a5 MT |
1739 | |
1740 | # Create the CA certificate | |
1741 | my $pid = open(OPENSSL, "|-"); | |
1742 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1743 | if ($pid) { # parent | |
1744 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1745 | print OPENSSL "$state\n"; | |
1746 | print OPENSSL "$city\n"; | |
1747 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1748 | print OPENSSL "$ou\n"; | |
1749 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1750 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1751 | close (OPENSSL); | |
1752 | if ($?) { | |
1753 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1754 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1755 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1756 | goto ROOTCERT_ERROR; | |
1757 | } | |
1758 | } else { # child | |
badd8c1c | 1759 | unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', |
49abe7af | 1760 | '-days', '999999', '-newkey', 'rsa:4096', '-sha512', |
6e13d0a5 MT |
1761 | '-keyout', "${General::swroot}/ovpn/ca/cakey.pem", |
1762 | '-out', "${General::swroot}/ovpn/ca/cacert.pem", | |
1763 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
1764 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1765 | goto ROOTCERT_ERROR; | |
1766 | } | |
1767 | } | |
1768 | ||
1769 | # Create the Host certificate request | |
1770 | $pid = open(OPENSSL, "|-"); | |
1771 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1772 | if ($pid) { # parent | |
1773 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1774 | print OPENSSL "$state\n"; | |
1775 | print OPENSSL "$city\n"; | |
1776 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1777 | print OPENSSL "$ou\n"; | |
1778 | print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1779 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1780 | print OPENSSL ".\n"; | |
1781 | print OPENSSL ".\n"; | |
1782 | close (OPENSSL); | |
1783 | if ($?) { | |
1784 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1785 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1786 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1787 | goto ROOTCERT_ERROR; | |
1788 | } | |
1789 | } else { # child | |
badd8c1c | 1790 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
4c962356 | 1791 | '-newkey', 'rsa:2048', |
6e13d0a5 MT |
1792 | '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem", |
1793 | '-out', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1794 | '-extensions', 'server', | |
1795 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) { | |
1796 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1797 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1798 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1799 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1800 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1801 | goto ROOTCERT_ERROR; | |
1802 | } | |
1803 | } | |
1804 | ||
1805 | # Sign the host certificate request | |
1806 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
1807 | '-batch', '-notext', | |
1808 | '-in', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1809 | '-out', "${General::swroot}/ovpn/certs/servercert.pem", | |
1810 | '-extensions', 'server', | |
1811 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
1812 | if ($?) { | |
1813 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1814 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1815 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1816 | unlink ("${General::swroot}/ovpn/serverkey.pem"); | |
1817 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1818 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
c6c9630e | 1819 | &newcleanssldatabase(); |
6e13d0a5 MT |
1820 | goto ROOTCERT_ERROR; |
1821 | } else { | |
1822 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
c6c9630e | 1823 | &deletebackupcert(); |
6e13d0a5 MT |
1824 | } |
1825 | ||
1826 | # Create an empty CRL | |
1827 | system('/usr/bin/openssl', 'ca', '-gencrl', | |
1828 | '-out', "${General::swroot}/ovpn/crls/cacrl.pem", | |
1829 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" ); | |
1830 | if ($?) { | |
1831 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1832 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1833 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1834 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1835 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
c6c9630e | 1836 | &cleanssldatabase(); |
6e13d0a5 | 1837 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1838 | # } else { |
1839 | # &cleanssldatabase(); | |
6e13d0a5 MT |
1840 | } |
1841 | # Create Diffie Hellmann Parameter | |
badd8c1c | 1842 | system('/usr/bin/openssl', 'dhparam', '-out', "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); |
6e13d0a5 MT |
1843 | if ($?) { |
1844 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1845 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1846 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1847 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1848 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
1849 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
c6c9630e | 1850 | &cleanssldatabase(); |
6e13d0a5 | 1851 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1852 | # } else { |
1853 | # &cleanssldatabase(); | |
4be45949 EK |
1854 | } |
1855 | # Create ta.key for tls-auth | |
1856 | system('/usr/sbin/openvpn', '--genkey', '--secret', "${General::swroot}/ovpn/certs/ta.key"); | |
1857 | if ($?) { | |
1858 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1859 | &cleanssldatabase(); | |
1860 | goto ROOTCERT_ERROR; | |
1861 | } | |
6e13d0a5 MT |
1862 | goto ROOTCERT_SUCCESS; |
1863 | } | |
1864 | ROOTCERT_ERROR: | |
1865 | if ($cgiparams{'ACTION'} ne '') { | |
1866 | &Header::showhttpheaders(); | |
4c962356 | 1867 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1868 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1869 | if ($errormessage) { | |
1870 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
1871 | print "<class name='base'>$errormessage"; | |
1872 | print " </class>"; | |
1873 | &Header::closebox(); | |
1874 | } | |
1875 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:"); | |
49abe7af | 1876 | print <<END; |
6e13d0a5 MT |
1877 | <form method='post' enctype='multipart/form-data'> |
1878 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
1879 | <tr><td width='30%' class='base'>$Lang::tr{'organization name'}:</td> | |
1880 | <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td> | |
1881 | <td width='35%' colspan='2'> </td></tr> | |
1882 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}:</td> | |
1883 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td> | |
1884 | <td colspan='2'> </td></tr> | |
1885 | <tr><td class='base'>$Lang::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td> | |
1886 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td> | |
1887 | <td colspan='2'> </td></tr> | |
1888 | <tr><td class='base'>$Lang::tr{'your department'}: <img src='/blob.gif' alt'*' /></td> | |
1889 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td> | |
1890 | <td colspan='2'> </td></tr> | |
1891 | <tr><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif' alt'*' /></td> | |
1892 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td> | |
1893 | <td colspan='2'> </td></tr> | |
1894 | <tr><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td> | |
1895 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td> | |
1896 | <td colspan='2'> </td></tr> | |
1897 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
1898 | <td class='base'><select name='ROOTCERT_COUNTRY'> | |
1899 | ||
1900 | END | |
1901 | ; | |
1902 | foreach my $country (sort keys %{Countries::countries}) { | |
1903 | print "<option value='$Countries::countries{$country}'"; | |
1904 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
1905 | print " selected='selected'"; | |
1906 | } | |
1907 | print ">$country</option>"; | |
1908 | } | |
49abe7af | 1909 | print <<END; |
6e13d0a5 | 1910 | </select></td> |
4c962356 EK |
1911 | <tr><td class='base'>$Lang::tr{'ovpn dh'}:</td> |
1912 | <td class='base'><select name='DHLENGHT'> | |
1913 | <option value='1024' $selected{'DHLENGHT'}{'1024'}>1024 $Lang::tr{'bit'}</option> | |
1914 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> | |
1915 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
1916 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
1917 | </select> | |
1918 | </td> | |
1919 | </tr> | |
1920 | ||
6e13d0a5 MT |
1921 | <tr><td> </td> |
1922 | <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td> | |
1923 | <td> </td><td> </td></tr> | |
1924 | <tr><td class='base' colspan='4' align='left'> | |
1925 | <img src='/blob.gif' valign='top' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
49abe7af EK |
1926 | <tr><td colspan='2'><br></td></tr> |
1927 | <table width='100%'> | |
1928 | <tr> | |
1929 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'ovpn generating the root and host certificates'} | |
1930 | <td class='base'>$Lang::tr{'dh key warn'}</td> | |
4c962356 | 1931 | </tr> |
49abe7af EK |
1932 | <tr> |
1933 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
4c962356 | 1934 | </tr> |
49abe7af EK |
1935 | <tr><td colspan='2'><br></td></tr> |
1936 | <tr> | |
1937 | </table> | |
4c962356 | 1938 | |
49abe7af | 1939 | <table width='100%'> |
4c962356 | 1940 | <tr><td colspan='4'><hr></td></tr> |
6e13d0a5 MT |
1941 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td> |
1942 | <td nowrap='nowrap'><input type='file' name='FH' size='32'></td> | |
1943 | <td colspan='2'> </td></tr> | |
1944 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td> | |
1945 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td> | |
1946 | <td colspan='2'> </td></tr> | |
1947 | <tr><td> </td> | |
1948 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td> | |
1949 | <td colspan='2'> </td></tr> | |
1950 | <tr><td class='base' colspan='4' align='left'> | |
4c962356 EK |
1951 | <img src='/blob.gif' valign='top' al='*' > $Lang::tr{'this field may be blank'}</td> |
1952 | </tr> | |
6e13d0a5 MT |
1953 | </form></table> |
1954 | END | |
1955 | ; | |
1956 | &Header::closebox(); | |
4c962356 | 1957 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
1958 | &Header::closebigbox(); |
1959 | &Header::closepage(); | |
1960 | exit(0) | |
1961 | } | |
1962 | ||
1963 | ROOTCERT_SUCCESS: | |
1964 | system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem"); | |
c6c9630e MT |
1965 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
1966 | # $vpnsettings{'ENABLE_BLUE'} eq 'on') { | |
1967 | # system('/usr/local/bin/ipsecctrl', 'S'); | |
1968 | # } | |
6e13d0a5 MT |
1969 | |
1970 | ### | |
1971 | ### Enable/Disable connection | |
1972 | ### | |
ce9abb66 AH |
1973 | |
1974 | ### | |
7c1d9faf | 1975 | # m.a.d net2net |
ce9abb66 AH |
1976 | ### |
1977 | ||
6e13d0a5 | 1978 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
c6c9630e MT |
1979 | |
1980 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 | 1981 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
ce9abb66 AH |
1982 | # my $n2nactive = ''; |
1983 | my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`; | |
1984 | ||
6e13d0a5 | 1985 | if ($confighash{$cgiparams{'KEY'}}) { |
8c877a82 AM |
1986 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
1987 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; | |
1988 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 1989 | |
8c877a82 | 1990 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
ce9abb66 | 1991 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); |
8c877a82 AM |
1992 | } |
1993 | } else { | |
ce9abb66 | 1994 | |
8c877a82 AM |
1995 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; |
1996 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 1997 | |
8c877a82 | 1998 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
ce9abb66 | 1999 | if ($n2nactive ne ''){ |
8c877a82 AM |
2000 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); |
2001 | } | |
ce9abb66 | 2002 | |
8c877a82 | 2003 | } else { |
ce9abb66 | 2004 | $errormessage = $Lang::tr{'invalid key'}; |
8c877a82 | 2005 | } |
ce9abb66 AH |
2006 | } |
2007 | } | |
6e13d0a5 MT |
2008 | |
2009 | ### | |
2010 | ### Download OpenVPN client package | |
2011 | ### | |
ce9abb66 AH |
2012 | |
2013 | ||
6e13d0a5 MT |
2014 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) { |
2015 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2016 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2017 | my $file = ''; | |
2018 | my $clientovpn = ''; | |
2019 | my @fileholder; | |
2020 | my $tempdir = tempdir( CLEANUP => 1 ); | |
2021 | my $zippath = "$tempdir/"; | |
ce9abb66 AH |
2022 | |
2023 | ### | |
7c1d9faf AH |
2024 | # m.a.d net2net |
2025 | ### | |
ce9abb66 AH |
2026 | |
2027 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
2028 | ||
2029 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip"; | |
2030 | my $zippathname = "$zippath$zipname"; | |
2031 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf"; | |
2032 | my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]); | |
54fd0535 | 2033 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 2034 | my $tunmtu = ''; |
7c1d9faf | 2035 | my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]); |
54fd0535 | 2036 | my $n2nfragment = ''; |
ce9abb66 AH |
2037 | |
2038 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; | |
2039 | flock CLIENTCONF, 2; | |
2040 | ||
2041 | my $zip = Archive::Zip->new(); | |
7c1d9faf | 2042 | print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 2043 | print CLIENTCONF "# \n"; |
b278daf3 | 2044 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
2045 | print CLIENTCONF "user nobody\n"; |
2046 | print CLIENTCONF "group nobody\n"; | |
2047 | print CLIENTCONF "persist-tun\n"; | |
2048 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 2049 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 2050 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
531f0835 | 2051 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n"; |
b278daf3 | 2052 | print CLIENTCONF "float\n"; |
60f396d7 | 2053 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 2054 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
b278daf3 | 2055 | print CLIENTCONF "# Server Gateway Network\n"; |
7c1d9faf | 2056 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
b278daf3 | 2057 | print CLIENTCONF "# tun Device\n"; |
ce9abb66 | 2058 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\n"; |
60f396d7 | 2059 | print CLIENTCONF "# Port and Protokoll\n"; |
ce9abb66 | 2060 | print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n"; |
60f396d7 AH |
2061 | |
2062 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') { | |
2063 | print CLIENTCONF "proto tcp-client\n"; | |
2064 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 2065 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; |
60f396d7 | 2066 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 2067 | } |
60f396d7 AH |
2068 | |
2069 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') { | |
2070 | print CLIENTCONF "proto udp\n"; | |
2071 | print CLIENTCONF "# Paketsize\n"; | |
2072 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; | |
2073 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 | 2074 | if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";} |
60f396d7 | 2075 | if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";} |
d96c89eb | 2076 | } |
1647059d SS |
2077 | if (($confighash{$cgiparams{'KEY'}}[38] eq 'yes') || |
2078 | ($confighash{$cgiparams{'KEY'}}[38] eq 'maybe') || | |
2079 | ($confighash{$cgiparams{'KEY'}}[38] eq 'no' )) { | |
2ee746be SS |
2080 | if (($confighash{$cgiparams{'KEY'}}[23] ne 'on') || ($confighash{$cgiparams{'KEY'}}[24] eq '')) { |
2081 | if ($tunmtu eq '1500' ) { | |
350f2980 | 2082 | print CLIENTCONF "mtu-disc $confighash{$cgiparams{'KEY'}}[38]\n"; |
2ee746be SS |
2083 | } |
2084 | } | |
2085 | } | |
54fd0535 | 2086 | print CLIENTCONF "ns-cert-type server\n"; |
ce9abb66 AH |
2087 | print CLIENTCONF "# Auth. Client\n"; |
2088 | print CLIENTCONF "tls-client\n"; | |
49abe7af | 2089 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 2090 | print CLIENTCONF "cipher $confighash{$cgiparams{'KEY'}}[40]\n"; |
ce9abb66 AH |
2091 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
2092 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2093 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", "$confighash{$cgiparams{'KEY'}}[1].p12") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1].p12\n"; | |
49abe7af EK |
2094 | } |
2095 | if ($confighash{$cgiparams{'KEY'}}[39] eq '') { | |
2096 | print CLIENTCONF "# HMAC algorithm\n"; | |
2097 | print CLIENTCONF "auth SHA1\n"; | |
2098 | } else { | |
2099 | print CLIENTCONF "# HMAC algorithm\n"; | |
2100 | print CLIENTCONF "auth $confighash{$cgiparams{'KEY'}}[39]\n"; | |
2101 | } | |
4c962356 | 2102 | if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') { |
b278daf3 | 2103 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 2104 | print CLIENTCONF "comp-lzo\n"; |
b278daf3 | 2105 | } |
ce9abb66 AH |
2106 | print CLIENTCONF "# Debug Level\n"; |
2107 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 2108 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 2109 | print CLIENTCONF "keepalive 10 60\n"; |
b278daf3 | 2110 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
2111 | print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n"; |
2112 | print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n"; | |
b278daf3 | 2113 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
2114 | if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"} |
2115 | else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"}; | |
ce9abb66 | 2116 | print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n"; |
531f0835 | 2117 | |
ce9abb66 AH |
2118 | |
2119 | close(CLIENTCONF); | |
2120 | ||
2121 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; | |
2122 | my $status = $zip->writeToFileNamed($zippathname); | |
2123 | ||
2124 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2125 | @fileholder = <DLFILE>; | |
2126 | print "Content-Type:application/x-download\n"; | |
2127 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2128 | print @fileholder; | |
2129 | exit (0); | |
2130 | } | |
2131 | else | |
2132 | { | |
2133 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip"; | |
2134 | my $zippathname = "$zippath$zipname"; | |
2135 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn"; | |
2136 | ||
2137 | ### | |
7c1d9faf | 2138 | # m.a.d net2net |
ce9abb66 AH |
2139 | ### |
2140 | ||
c6c9630e | 2141 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; |
6e13d0a5 MT |
2142 | flock CLIENTCONF, 2; |
2143 | ||
2144 | my $zip = Archive::Zip->new(); | |
2145 | ||
8c877a82 | 2146 | print CLIENTCONF "#OpenVPN Client conf\r\n"; |
6e13d0a5 MT |
2147 | print CLIENTCONF "tls-client\r\n"; |
2148 | print CLIENTCONF "client\r\n"; | |
4f6e3ae3 | 2149 | print CLIENTCONF "nobind\r\n"; |
6e13d0a5 | 2150 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\r\n"; |
c6c9630e | 2151 | print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n"; |
2ee746be SS |
2152 | |
2153 | # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500 | |
2154 | # or use configured value. | |
2155 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) | |
4f6e3ae3 | 2156 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; } |
2ee746be | 2157 | elsif ($vpnsettings{MSSFIX} eq 'on') |
4f6e3ae3 | 2158 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; } |
1647059d SS |
2159 | elsif (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') || |
2160 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
2161 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) | |
4f6e3ae3 | 2162 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; } |
2ee746be SS |
2163 | else |
2164 | { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu $vpnsettings{'DMTU'}\r\n"; } | |
2165 | ||
6e13d0a5 MT |
2166 | if ( $vpnsettings{'ENABLED'} eq 'on'){ |
2167 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
c6c9630e MT |
2168 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ |
2169 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n"; | |
2170 | print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2171 | } | |
2172 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2173 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2174 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2175 | } | |
2176 | } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
2177 | print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2178 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2179 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2180 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2181 | } | |
2182 | } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2183 | print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
6e13d0a5 MT |
2184 | } |
2185 | ||
2186 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { | |
c6c9630e MT |
2187 | print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n"; |
2188 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", "$confighash{$cgiparams{'KEY'}}[1].p12") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1].p12\n"; | |
6e13d0a5 | 2189 | } else { |
c6c9630e MT |
2190 | print CLIENTCONF "ca cacert.pem\r\n"; |
2191 | print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n"; | |
2192 | print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; | |
2193 | $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; | |
2194 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem", "$confighash{$cgiparams{'KEY'}}[1]cert.pem") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1]cert.pem\n"; | |
6e13d0a5 MT |
2195 | } |
2196 | print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n"; | |
49abe7af EK |
2197 | if ($vpnsettings{'DAUTH'} eq '') { |
2198 | print CLIENTCONF ""; | |
2199 | } else { | |
2200 | print CLIENTCONF "auth $vpnsettings{'DAUTH'}\r\n"; | |
2201 | } | |
2202 | if ($vpnsettings{'TLSAUTH'} eq 'on') { | |
4be45949 EK |
2203 | print CLIENTCONF "tls-auth ta.key\r\n"; |
2204 | $zip->addFile( "${General::swroot}/ovpn/certs/ta.key", "ta.key") or die "Can't add file ta.key\n"; | |
49abe7af | 2205 | } |
6e13d0a5 MT |
2206 | if ($vpnsettings{DCOMPLZO} eq 'on') { |
2207 | print CLIENTCONF "comp-lzo\r\n"; | |
2208 | } | |
2209 | print CLIENTCONF "verb 3\r\n"; | |
2210 | print CLIENTCONF "ns-cert-type server\r\n"; | |
a79fa1d6 JPT |
2211 | print CLIENTCONF "tls-remote $vpnsettings{ROOTCERT_HOSTNAME}\r\n"; |
2212 | if ($vpnsettings{MSSFIX} eq 'on') { | |
2213 | print CLIENTCONF "mssfix\r\n"; | |
2214 | } | |
74225cce | 2215 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) { |
a79fa1d6 JPT |
2216 | print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n"; |
2217 | } | |
1647059d SS |
2218 | |
2219 | # Check if a valid operating mode has been choosen and use it. | |
2220 | if (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
2221 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
2222 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) { | |
2ee746be | 2223 | if(($vpnsettings{MSSFIX} ne 'on') || ($vpnsettings{FRAGMENT} eq '')) { |
4f6e3ae3 | 2224 | print CLIENTCONF "mtu-disc $vpnsettings{'PMTU_DISCOVERY'}\r\n"; |
2ee746be SS |
2225 | } |
2226 | } | |
6e13d0a5 | 2227 | close(CLIENTCONF); |
ce9abb66 | 2228 | |
6e13d0a5 MT |
2229 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; |
2230 | my $status = $zip->writeToFileNamed($zippathname); | |
2231 | ||
2232 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2233 | @fileholder = <DLFILE>; | |
2234 | print "Content-Type:application/x-download\n"; | |
2235 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2236 | print @fileholder; | |
2237 | exit (0); | |
ce9abb66 AH |
2238 | } |
2239 | ||
2240 | ||
2241 | ||
6e13d0a5 MT |
2242 | ### |
2243 | ### Remove connection | |
2244 | ### | |
ce9abb66 AH |
2245 | |
2246 | ||
6e13d0a5 MT |
2247 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
2248 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2249 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e MT |
2250 | |
2251 | if ($confighash{$cgiparams{'KEY'}}) { | |
2252 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2253 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2254 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2255 | # } | |
2256 | # | |
2257 | my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
ce9abb66 AH |
2258 | |
2259 | ### | |
7c1d9faf | 2260 | # m.a.d net2net |
ce9abb66 | 2261 | ### |
7c1d9faf | 2262 | |
8e6a8fd5 | 2263 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { |
ce9abb66 | 2264 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); |
8e6a8fd5 MT |
2265 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); |
2266 | unlink ($certfile); | |
2267 | unlink ($conffile); | |
2268 | ||
2269 | if (-e "${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") { | |
2270 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
2271 | } | |
ce9abb66 | 2272 | } |
ce9abb66 AH |
2273 | |
2274 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
8c877a82 AM |
2275 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); |
2276 | ||
2277 | # A.Marx CCD delete ccd files and routes | |
2278 | ||
2279 | ||
2280 | if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]") | |
2281 | { | |
2282 | unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]"; | |
2283 | } | |
e81be1e1 | 2284 | |
8c877a82 AM |
2285 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
2286 | foreach my $key (keys %ccdroutehash) { | |
2287 | if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2288 | delete $ccdroutehash{$key}; | |
2289 | } | |
2290 | } | |
2291 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
e81be1e1 | 2292 | |
8c877a82 AM |
2293 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
2294 | foreach my $key (keys %ccdroute2hash) { | |
2295 | if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2296 | delete $ccdroute2hash{$key}; | |
2297 | } | |
2298 | } | |
2299 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
52d08bcb | 2300 | &writeserverconf; |
8c877a82 AM |
2301 | |
2302 | ||
2303 | # CCD end | |
2304 | ||
2305 | ||
c6c9630e MT |
2306 | delete $confighash{$cgiparams{'KEY'}}; |
2307 | my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
2308 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
8c877a82 | 2309 | |
c6c9630e | 2310 | #&writeserverconf(); |
6e13d0a5 | 2311 | } else { |
c6c9630e | 2312 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 | 2313 | } |
b2e75449 | 2314 | &General::firewall_reload(); |
ce9abb66 | 2315 | |
6e13d0a5 MT |
2316 | ### |
2317 | ### Download PKCS12 file | |
2318 | ### | |
2319 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
2320 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2321 | ||
2322 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
2323 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2324 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`; | |
2325 | exit (0); | |
2326 | ||
2327 | ### | |
2328 | ### Display certificate | |
2329 | ### | |
2330 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
2331 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2332 | ||
2333 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
c6c9630e | 2334 | &Header::showhttpheaders(); |
4c962356 | 2335 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
2336 | &Header::openbigbox('100%', 'LEFT', '', ''); |
2337 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:"); | |
2338 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
2339 | $output = &Header::cleanhtml($output,"y"); | |
2340 | print "<pre>$output</pre>\n"; | |
2341 | &Header::closebox(); | |
2342 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2343 | &Header::closebigbox(); | |
2344 | &Header::closepage(); | |
2345 | exit(0); | |
6e13d0a5 | 2346 | } |
4c962356 EK |
2347 | |
2348 | ### | |
2349 | ### Display Diffie-Hellman key | |
2350 | ### | |
2351 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show dh'}) { | |
2352 | ||
2353 | if (! -e "${General::swroot}/ovpn/ca/dh1024.pem") { | |
49abe7af | 2354 | $errormessage = $Lang::tr{'not present'}; |
4c962356 EK |
2355 | } else { |
2356 | &Header::showhttpheaders(); | |
2357 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2358 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2359 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'dh'}:"); | |
2360 | my $output = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem`; | |
2361 | $output = &Header::cleanhtml($output,"y"); | |
2362 | print "<pre>$output</pre>\n"; | |
2363 | &Header::closebox(); | |
2364 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2365 | &Header::closebigbox(); | |
2366 | &Header::closepage(); | |
2367 | exit(0); | |
2368 | } | |
2369 | ||
fd5ccb2d EK |
2370 | ### |
2371 | ### Display tls-auth key | |
2372 | ### | |
2373 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show tls-auth key'}) { | |
2374 | ||
2375 | if (! -e "${General::swroot}/ovpn/certs/ta.key") { | |
2376 | $errormessage = $Lang::tr{'not present'}; | |
2377 | } else { | |
2378 | &Header::showhttpheaders(); | |
2379 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2380 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2381 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ta key'}:"); | |
2382 | my $output = `/bin/cat ${General::swroot}/ovpn/certs/ta.key`; | |
2383 | $output = &Header::cleanhtml($output,"y"); | |
2384 | print "<pre>$output</pre>\n"; | |
2385 | &Header::closebox(); | |
2386 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2387 | &Header::closebigbox(); | |
2388 | &Header::closepage(); | |
2389 | exit(0); | |
2390 | } | |
2391 | ||
6e13d0a5 MT |
2392 | ### |
2393 | ### Display Certificate Revoke List | |
2394 | ### | |
2395 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) { | |
c6c9630e MT |
2396 | # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2397 | ||
49abe7af EK |
2398 | if (! -e "${General::swroot}/ovpn/crls/cacrl.pem") { |
2399 | $errormessage = $Lang::tr{'not present'}; | |
2400 | } else { | |
b2e75449 MT |
2401 | &Header::showhttpheaders(); |
2402 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2403 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2404 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:"); | |
2405 | my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`; | |
2406 | $output = &Header::cleanhtml($output,"y"); | |
2407 | print "<pre>$output</pre>\n"; | |
2408 | &Header::closebox(); | |
2409 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2410 | &Header::closebigbox(); | |
2411 | &Header::closepage(); | |
2412 | exit(0); | |
6e13d0a5 MT |
2413 | } |
2414 | ||
2415 | ### | |
2416 | ### Advanced Server Settings | |
2417 | ### | |
2418 | ||
2419 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) { | |
2420 | %cgiparams = (); | |
2421 | %cahash = (); | |
2422 | %confighash = (); | |
8c877a82 | 2423 | my $disabled; |
6e13d0a5 | 2424 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); |
54fd0535 | 2425 | read_routepushfile; |
8c877a82 AM |
2426 | |
2427 | ||
c6c9630e MT |
2428 | # if ($cgiparams{'CLIENT2CLIENT'} eq '') { |
2429 | # $cgiparams{'CLIENT2CLIENT'} = 'on'; | |
2430 | # } | |
6e13d0a5 MT |
2431 | ADV_ERROR: |
2432 | if ($cgiparams{'MAX_CLIENTS'} eq '') { | |
4c962356 | 2433 | $cgiparams{'MAX_CLIENTS'} = '100'; |
6e13d0a5 | 2434 | } |
6e13d0a5 | 2435 | if ($cgiparams{'KEEPALIVE_1'} eq '') { |
4c962356 | 2436 | $cgiparams{'KEEPALIVE_1'} = '10'; |
6e13d0a5 MT |
2437 | } |
2438 | if ($cgiparams{'KEEPALIVE_2'} eq '') { | |
4c962356 | 2439 | $cgiparams{'KEEPALIVE_2'} = '60'; |
6e13d0a5 MT |
2440 | } |
2441 | if ($cgiparams{'LOG_VERB'} eq '') { | |
4c962356 | 2442 | $cgiparams{'LOG_VERB'} = '3'; |
ae9f6139 | 2443 | } |
92b87e17 | 2444 | if ($cgiparams{'PMTU_DISCOVERY'} eq '') { |
4c962356 EK |
2445 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; |
2446 | } | |
2447 | if ($cgiparams{'DAUTH'} eq '') { | |
2448 | $cgiparams{'DAUTH'} = 'SHA1'; | |
92b87e17 | 2449 | } |
f527e53f | 2450 | if ($cgiparams{'TLSAUTH'} eq '') { |
754066e6 | 2451 | $cgiparams{'TLSAUTH'} = 'off'; |
f527e53f | 2452 | } |
6e13d0a5 MT |
2453 | $checked{'CLIENT2CLIENT'}{'off'} = ''; |
2454 | $checked{'CLIENT2CLIENT'}{'on'} = ''; | |
2455 | $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED'; | |
2456 | $checked{'REDIRECT_GW_DEF1'}{'off'} = ''; | |
2457 | $checked{'REDIRECT_GW_DEF1'}{'on'} = ''; | |
2458 | $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED'; | |
a79fa1d6 JPT |
2459 | $checked{'MSSFIX'}{'off'} = ''; |
2460 | $checked{'MSSFIX'}{'on'} = ''; | |
2461 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
2ee746be | 2462 | $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\''; |
49abe7af | 2463 | $selected{'LOG_VERB'}{'0'} = ''; |
6e13d0a5 MT |
2464 | $selected{'LOG_VERB'}{'1'} = ''; |
2465 | $selected{'LOG_VERB'}{'2'} = ''; | |
2466 | $selected{'LOG_VERB'}{'3'} = ''; | |
2467 | $selected{'LOG_VERB'}{'4'} = ''; | |
2468 | $selected{'LOG_VERB'}{'5'} = ''; | |
2469 | $selected{'LOG_VERB'}{'6'} = ''; | |
2470 | $selected{'LOG_VERB'}{'7'} = ''; | |
2471 | $selected{'LOG_VERB'}{'8'} = ''; | |
2472 | $selected{'LOG_VERB'}{'9'} = ''; | |
2473 | $selected{'LOG_VERB'}{'10'} = ''; | |
2474 | $selected{'LOG_VERB'}{'11'} = ''; | |
6e13d0a5 | 2475 | $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED'; |
4c962356 EK |
2476 | $selected{'DAUTH'}{'whirlpool'} = ''; |
2477 | $selected{'DAUTH'}{'SHA512'} = ''; | |
2478 | $selected{'DAUTH'}{'SHA384'} = ''; | |
2479 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
2480 | $selected{'DAUTH'}{'SHA1'} = ''; |
2481 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
49abe7af EK |
2482 | $checked{'TLSAUTH'}{'off'} = ''; |
2483 | $checked{'TLSAUTH'}{'on'} = ''; | |
2484 | $checked{'TLSAUTH'}{$cgiparams{'TLSAUTH'}} = 'CHECKED'; | |
f527e53f | 2485 | |
6e13d0a5 MT |
2486 | &Header::showhttpheaders(); |
2487 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
2488 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
2489 | if ($errormessage) { | |
c6c9630e MT |
2490 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
2491 | print "<class name='base'>$errormessage\n"; | |
2492 | print " </class>\n"; | |
2493 | &Header::closebox(); | |
6e13d0a5 MT |
2494 | } |
2495 | &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'}); | |
4c962356 | 2496 | print <<END; |
b376fae4 | 2497 | <form method='post' enctype='multipart/form-data'> |
b2e75449 | 2498 | <table width='100%' border=0> |
4c962356 EK |
2499 | <tr> |
2500 | <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td> | |
6e13d0a5 MT |
2501 | </tr> |
2502 | <tr> | |
4c962356 | 2503 | <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td> |
6e13d0a5 MT |
2504 | </tr> |
2505 | <tr> | |
4c962356 | 2506 | <td class='base'>Domain</td> |
8c877a82 | 2507 | <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td> |
6e13d0a5 MT |
2508 | </tr> |
2509 | <tr> | |
4c962356 EK |
2510 | <td class='base'>DNS</td> |
2511 | <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td> | |
6e13d0a5 MT |
2512 | </tr> |
2513 | <tr> | |
4c962356 EK |
2514 | <td class='base'>WINS</td> |
2515 | <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td> | |
2516 | </tr> | |
54fd0535 | 2517 | <tr> |
4c962356 | 2518 | <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td> |
54fd0535 MT |
2519 | </tr> |
2520 | <tr> | |
4c962356 EK |
2521 | <td class='base'>$Lang::tr{'ovpn routes push'}</td> |
2522 | <td colspan='2'> | |
2523 | <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'> | |
54fd0535 MT |
2524 | END |
2525 | ; | |
2526 | ||
2527 | if ($cgiparams{'ROUTES_PUSH'} ne '') | |
2528 | { | |
2529 | print $cgiparams{'ROUTES_PUSH'}; | |
2530 | } | |
2531 | ||
8c877a82 | 2532 | print <<END; |
54fd0535 MT |
2533 | </textarea></td> |
2534 | </tr> | |
6e13d0a5 MT |
2535 | </tr> |
2536 | </table> | |
2537 | <hr size='1'> | |
4c962356 | 2538 | <table width='100%'> |
6e13d0a5 | 2539 | <tr> |
4c962356 | 2540 | <td class'base'><b>$Lang::tr{'misc-options'}</b></td> |
6e13d0a5 MT |
2541 | </tr> |
2542 | <tr> | |
4c962356 | 2543 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td> |
6e13d0a5 MT |
2544 | </tr> |
2545 | <tr> | |
4c962356 EK |
2546 | <td class='base'>Client-To-Client</td> |
2547 | <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td> | |
6e13d0a5 MT |
2548 | </tr> |
2549 | <tr> | |
4c962356 EK |
2550 | <td class='base'>Redirect-Gateway def1</td> |
2551 | <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td> | |
6e13d0a5 MT |
2552 | </tr> |
2553 | <tr> | |
2554 | <td class='base'>Max-Clients</td> | |
a79fa1d6 | 2555 | <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td> |
6e13d0a5 | 2556 | </tr> |
4c962356 | 2557 | <tr> |
f0ccae18 | 2558 | <td class='base'>Keepalive <br /> |
a79fa1d6 JPT |
2559 | (ping/ping-restart)</td> |
2560 | <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td> | |
2561 | <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td> | |
2562 | </tr> | |
4c962356 | 2563 | <tr> |
a79fa1d6 JPT |
2564 | <td class='base'>fragment <br></td> |
2565 | <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td> | |
60f396d7 | 2566 | </tr> |
a79fa1d6 JPT |
2567 | <tr> |
2568 | <td class='base'>mssfix</td> | |
2569 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
49abe7af | 2570 | <td>$Lang::tr{'openvpn default'}: off</td> |
2ee746be SS |
2571 | </tr> |
2572 | ||
2573 | <tr> | |
2574 | <td class='base'>$Lang::tr{'ovpn mtu-disc'}</td> | |
2575 | <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'}</td> | |
2576 | <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'}</td> | |
2577 | <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'}</td> | |
2578 | <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'}</td> | |
2579 | </tr> | |
a79fa1d6 JPT |
2580 | </table> |
2581 | ||
a79fa1d6 | 2582 | <hr size='1'> |
4c962356 | 2583 | <table width='100%'> |
a79fa1d6 | 2584 | <tr> |
49abe7af | 2585 | <td class'base'><b>$Lang::tr{'log-options'}</b></td> |
a79fa1d6 JPT |
2586 | </tr> |
2587 | <tr> | |
49abe7af | 2588 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> |
4c962356 EK |
2589 | </tr> |
2590 | ||
2591 | <tr><td class='base'>VERB</td> | |
2592 | <td><select name='LOG_VERB'> | |
49abe7af EK |
2593 | <option value='0' $selected{'LOG_VERB'}{'0'}>0</option> |
2594 | <option value='1' $selected{'LOG_VERB'}{'1'}>1</option> | |
2595 | <option value='2' $selected{'LOG_VERB'}{'2'}>2</option> | |
2596 | <option value='3' $selected{'LOG_VERB'}{'3'}>3</option> | |
2597 | <option value='4' $selected{'LOG_VERB'}{'4'}>4</option> | |
2598 | <option value='5' $selected{'LOG_VERB'}{'5'}>5</option> | |
2599 | <option value='6' $selected{'LOG_VERB'}{'6'}>6</option> | |
2600 | <option value='7' $selected{'LOG_VERB'}{'7'}>7</option> | |
2601 | <option value='8' $selected{'LOG_VERB'}{'8'}>8</option> | |
2602 | <option value='9' $selected{'LOG_VERB'}{'9'}>9</option> | |
2603 | <option value='10' $selected{'LOG_VERB'}{'10'}>10</option> | |
2604 | <option value='11' $selected{'LOG_VERB'}{'11'}>11</option> | |
2605 | </td></select> | |
2606 | </table> | |
4c962356 | 2607 | |
6e13d0a5 | 2608 | <hr size='1'> |
4c962356 | 2609 | <table width='100%'> |
6e13d0a5 | 2610 | <tr> |
4c962356 EK |
2611 | <td class'base'><b>$Lang::tr{'ovpn crypt options'}</b></td> |
2612 | </tr> | |
2613 | <tr> | |
2614 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> | |
6e13d0a5 | 2615 | </tr> |
4c962356 EK |
2616 | <tr><td class='base'>$Lang::tr{'ovpn ha'}</td> |
2617 | <td><select name='DAUTH'> | |
b2e75449 MT |
2618 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> |
2619 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
2620 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
2621 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
b2e75449 | 2622 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'})</option> |
4c962356 EK |
2623 | </select> |
2624 | </td> | |
040b8b0c | 2625 | <td>$Lang::tr{'openvpn default'}: <span class="base">SHA1 (160 $Lang::tr{'bit'})</span></td> |
49abe7af | 2626 | </tr> |
6e13d0a5 | 2627 | </table> |
49abe7af EK |
2628 | |
2629 | <table width='100%'> | |
6e13d0a5 | 2630 | <tr> |
49abe7af | 2631 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td> |
6e13d0a5 | 2632 | </tr> |
4c962356 | 2633 | |
6e13d0a5 | 2634 | <tr> |
49abe7af EK |
2635 | <td class='base'>HMAC tls-auth</td> |
2636 | <td><input type='checkbox' name='TLSAUTH' $checked{'TLSAUTH'}{'on'} /></td> | |
2637 | </tr> | |
2638 | </table><hr> | |
8c877a82 AM |
2639 | END |
2640 | ||
2641 | if ( -e "/var/run/openvpn.pid"){ | |
2642 | print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br> | |
2643 | $Lang::tr{'server restart'}<br><br> | |
2644 | <hr>"; | |
49abe7af | 2645 | print<<END; |
52d08bcb AM |
2646 | <table width='100%'> |
2647 | <tr> | |
2648 | <td> </td> | |
2649 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td> | |
2650 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2651 | <td> </td> | |
2652 | </tr> | |
2653 | </table> | |
2654 | </form> | |
2655 | END | |
2656 | ; | |
2657 | ||
2658 | ||
2659 | }else{ | |
8c877a82 | 2660 | |
49abe7af | 2661 | print<<END; |
6e13d0a5 MT |
2662 | <table width='100%'> |
2663 | <tr> | |
2664 | <td> </td> | |
2665 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td> | |
2666 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2667 | <td> </td> | |
2668 | </tr> | |
2669 | </table> | |
2670 | </form> | |
2671 | END | |
2672 | ; | |
52d08bcb | 2673 | } |
6e13d0a5 | 2674 | &Header::closebox(); |
c6c9630e | 2675 | # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2676 | &Header::closebigbox(); |
2677 | &Header::closepage(); | |
2678 | exit(0); | |
2679 | ||
8c877a82 AM |
2680 | |
2681 | # A.Marx CCD Add,delete or edit CCD net | |
2682 | ||
2683 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} || | |
2684 | $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} || | |
2685 | $cgiparams{'ACTION'} eq "kill" || | |
2686 | $cgiparams{'ACTION'} eq "edit" || | |
2687 | $cgiparams{'ACTION'} eq 'editsave'){ | |
2688 | &Header::showhttpheaders(); | |
2689 | &Header::openpage($Lang::tr{'ccd net'}, 1, ''); | |
2690 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2691 | ||
2692 | if ($cgiparams{'ACTION'} eq "kill"){ | |
2693 | &delccdnet($cgiparams{'net'}); | |
2694 | } | |
2695 | ||
2696 | if ($cgiparams{'ACTION'} eq 'editsave'){ | |
2697 | my ($a,$b) =split (/\|/,$cgiparams{'ccdname'}); | |
2698 | if ( $a ne $b){ &modccdnet($a,$b);} | |
5068ac38 AM |
2699 | $cgiparams{'ccdname'}=''; |
2700 | $cgiparams{'ccdsubnet'}=''; | |
8c877a82 AM |
2701 | } |
2702 | ||
2703 | if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) { | |
e2429e8d | 2704 | &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'}); |
8c877a82 AM |
2705 | } |
2706 | if ($errormessage) { | |
2707 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2708 | print "<class name='base'>$errormessage"; | |
2709 | print " </class>"; | |
2710 | &Header::closebox(); | |
2711 | } | |
2712 | if ($cgiparams{'ACTION'} eq "edit"){ | |
2713 | ||
2714 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'}); | |
2715 | ||
49abe7af | 2716 | print <<END; |
631b67b7 | 2717 | <table width='100%' border='0'> |
8c877a82 AM |
2718 | <tr><form method='post'> |
2719 | <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
a9fb14d0 | 2720 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly='readonly' /></td></tr> |
8c877a82 AM |
2721 | <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/> |
2722 | <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' /> | |
2723 | </td></tr> | |
2724 | </table></form> | |
2725 | END | |
2726 | ; | |
2727 | &Header::closebox(); | |
2728 | ||
2729 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
49abe7af | 2730 | print <<END; |
8c877a82 AM |
2731 | <table width='100%' border='0' cellpadding='0' cellspacing='1'> |
2732 | <tr> | |
2733 | <td class='boldbase' align='center'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center'><b>$Lang::tr{'network'}</td><td class='boldbase' width='15%' align='center'><b>$Lang::tr{'ccd used'}</td><td width='3%'></td><td width='3%'></td></tr> | |
2734 | END | |
2735 | ; | |
2736 | } | |
2737 | else{ | |
2738 | if (! -e "/var/run/openvpn.pid"){ | |
2739 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd add'}); | |
49abe7af | 2740 | print <<END; |
8c877a82 AM |
2741 | <table width='100%' border='0'> |
2742 | <tr><form method='post'> | |
2743 | <td colspan='4'>$Lang::tr{'ccd hint'}<br><br></td></tr> | |
2744 | <tr> | |
2745 | <td width='10%' nowrap='nwrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
2746 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' /></td></tr> | |
2747 | <tr><td colspan=4><hr /></td></tr><tr> | |
2748 | <td colspan='4' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'ccd add'}' /><input type='submit' value='$Lang::tr{'add'}' /><input type='hidden' name='DOVPN_SUBNET' value='$cgiparams{'DOVPN_SUBNET'}'/></td></tr> | |
2749 | </table></form> | |
2750 | END | |
2751 | ||
2752 | &Header::closebox(); | |
2753 | } | |
2754 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
5068ac38 AM |
2755 | if ( -e "/var/run/openvpn.pid"){ |
2756 | print "<b>$Lang::tr{'attention'}:</b><br>"; | |
2757 | print "$Lang::tr{'ccd noaddnet'}<br><hr>"; | |
2758 | } | |
2759 | ||
4c962356 | 2760 | print <<END; |
99bfa85c | 2761 | <table width='100%' cellpadding='0' cellspacing='1'> |
8c877a82 AM |
2762 | <tr> |
2763 | <td class='boldbase' align='center' nowrap='nowrap' width='20%'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center' width='8%'><b>$Lang::tr{'network'}</td><td class='boldbase' width='8%' align='center' nowrap='nowrap'><b>$Lang::tr{'ccd used'}</td><td width='1%' align='center'></td><td width='1%' align='center'></td></tr> | |
2764 | END | |
2765 | ; | |
2766 | } | |
2767 | my %ccdconfhash=(); | |
2768 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
2769 | my @ccdconf=(); | |
2770 | my $count=0; | |
df9b48b7 | 2771 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
2772 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); |
2773 | $count++; | |
2774 | my $ccdhosts = &hostsinnet($ccdconf[0]); | |
2775 | if ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";} | |
2776 | else{ print" <tr bgcolor='$color{'color20'}'>";} | |
2777 | print"<td>$ccdconf[0]</td><td align='center'>$ccdconf[1]</td><td align='center'>$ccdhosts/".(&ccdmaxclients($ccdconf[1])+1)."</td><td>"; | |
4c962356 | 2778 | print <<END; |
8c877a82 | 2779 | <form method='post' /> |
1638682b | 2780 | <input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /> |
8c877a82 AM |
2781 | <input type='hidden' name='ACTION' value='edit'/> |
2782 | <input type='hidden' name='ccdname' value='$ccdconf[0]' /> | |
2783 | <input type='hidden' name='ccdsubnet' value='$ccdconf[1]' /> | |
2784 | </form></td> | |
2785 | <form method='post' /> | |
2786 | <td><input type='hidden' name='ACTION' value='kill'/> | |
2787 | <input type='hidden' name='number' value='$count' /> | |
2788 | <input type='hidden' name='net' value='$ccdconf[0]' /> | |
1638682b | 2789 | <input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' /></form></td></tr> |
8c877a82 AM |
2790 | END |
2791 | ; | |
2792 | } | |
2793 | print "</table></form>"; | |
2794 | &Header::closebox(); | |
2795 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2796 | &Header::closebigbox(); | |
2797 | &Header::closepage(); | |
2798 | exit(0); | |
2799 | ||
2800 | #END CCD | |
2801 | ||
6e13d0a5 MT |
2802 | ### |
2803 | ### Openvpn Connections Statistics | |
2804 | ### | |
2805 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) { | |
2806 | &Header::showhttpheaders(); | |
2807 | &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); | |
2808 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2809 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); | |
2810 | ||
2811 | # | |
2812 | # <td><b>$Lang::tr{'protocol'}</b></td> | |
2813 | # protocol temp removed | |
4c962356 | 2814 | print <<END; |
99bfa85c | 2815 | <table width='100%' cellpadding='2' cellspacing='0' class='tbl'> |
6e13d0a5 | 2816 | <tr> |
99bfa85c AM |
2817 | <th><b>$Lang::tr{'common name'}</b></th> |
2818 | <th><b>$Lang::tr{'real address'}</b></th> | |
2819 | <th><b>$Lang::tr{'virtual address'}</b></th> | |
2820 | <th><b>$Lang::tr{'loged in at'}</b></th> | |
2821 | <th><b>$Lang::tr{'bytes sent'}</b></th> | |
2822 | <th><b>$Lang::tr{'bytes received'}</b></th> | |
2823 | <th><b>$Lang::tr{'last activity'}</b></th> | |
6e13d0a5 MT |
2824 | </tr> |
2825 | END | |
2826 | ; | |
4e17adad | 2827 | my $filename = "/var/log/ovpnserver.log"; |
6e13d0a5 MT |
2828 | open(FILE, $filename) or die 'Unable to open config file.'; |
2829 | my @current = <FILE>; | |
2830 | close(FILE); | |
2831 | my @users =(); | |
2832 | my $status; | |
2833 | my $uid = 0; | |
2834 | my $cn; | |
2835 | my @match = (); | |
2836 | my $proto = "udp"; | |
2837 | my $address; | |
2838 | my %userlookup = (); | |
2839 | foreach my $line (@current) | |
2840 | { | |
2841 | chomp($line); | |
2842 | if ( $line =~ /^Updated,(.+)/){ | |
2843 | @match = split( /^Updated,(.+)/, $line); | |
2844 | $status = $match[1]; | |
2845 | } | |
c6c9630e | 2846 | #gian |
6e13d0a5 MT |
2847 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { |
2848 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
2849 | if ($match[1] ne "Common Name") { | |
2850 | $cn = $match[1]; | |
2851 | $userlookup{$match[2]} = $uid; | |
2852 | $users[$uid]{'CommonName'} = $match[1]; | |
2853 | $users[$uid]{'RealAddress'} = $match[2]; | |
c6c9630e MT |
2854 | $users[$uid]{'BytesReceived'} = &sizeformat($match[3]); |
2855 | $users[$uid]{'BytesSent'} = &sizeformat($match[4]); | |
6e13d0a5 MT |
2856 | $users[$uid]{'Since'} = $match[5]; |
2857 | $users[$uid]{'Proto'} = $proto; | |
2858 | $uid++; | |
2859 | } | |
2860 | } | |
2861 | if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { | |
2862 | @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); | |
2863 | if ($match[1] ne "Virtual Address") { | |
2864 | $address = $match[3]; | |
2865 | #find the uid in the lookup table | |
2866 | $uid = $userlookup{$address}; | |
2867 | $users[$uid]{'VirtualAddress'} = $match[1]; | |
2868 | $users[$uid]{'LastRef'} = $match[4]; | |
2869 | } | |
2870 | } | |
2871 | } | |
2872 | my $user2 = @users; | |
2873 | if ($user2 >= 1){ | |
99bfa85c | 2874 | for (my $idx = 1; $idx <= $user2; $idx++){ |
6e13d0a5 | 2875 | if ($idx % 2) { |
99bfa85c AM |
2876 | print "<tr>"; |
2877 | $col="bgcolor='$color{'color22'}'"; | |
2878 | } else { | |
2879 | print "<tr>"; | |
2880 | $col="bgcolor='$color{'color20'}'"; | |
6e13d0a5 | 2881 | } |
99bfa85c AM |
2882 | print "<td align='left' $col>$users[$idx-1]{'CommonName'}</td>"; |
2883 | print "<td align='left' $col>$users[$idx-1]{'RealAddress'}</td>"; | |
2884 | print "<td align='left' $col>$users[$idx-1]{'VirtualAddress'}</td>"; | |
2885 | print "<td align='left' $col>$users[$idx-1]{'Since'}</td>"; | |
2886 | print "<td align='left' $col>$users[$idx-1]{'BytesSent'}</td>"; | |
2887 | print "<td align='left' $col>$users[$idx-1]{'BytesReceived'}</td>"; | |
2888 | print "<td align='left' $col>$users[$idx-1]{'LastRef'}</td>"; | |
2889 | } | |
2890 | } | |
6e13d0a5 MT |
2891 | |
2892 | print "</table>"; | |
49abe7af | 2893 | print <<END; |
6e13d0a5 MT |
2894 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> |
2895 | <tr><td></td></tr> | |
2896 | <tr><td></td></tr> | |
2897 | <tr><td></td></tr> | |
2898 | <tr><td></td></tr> | |
2899 | <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr> | |
2900 | </table> | |
2901 | END | |
2902 | ; | |
2903 | &Header::closebox(); | |
2904 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2905 | &Header::closebigbox(); | |
2906 | &Header::closepage(); | |
2907 | exit(0); | |
2908 | ||
2909 | ### | |
2910 | ### Download Certificate | |
2911 | ### | |
2912 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
2913 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 2914 | |
6e13d0a5 | 2915 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { |
c6c9630e MT |
2916 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n"; |
2917 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2918 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
2919 | exit (0); | |
2920 | } | |
2921 | ||
2922 | ### | |
2923 | ### Enable/Disable connection | |
2924 | ### | |
ce9abb66 | 2925 | |
c6c9630e MT |
2926 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
2927 | ||
2928 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2929 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2930 | ||
2931 | if ($confighash{$cgiparams{'KEY'}}) { | |
ce9abb66 | 2932 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
c6c9630e MT |
2933 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
2934 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2935 | #&writeserverconf(); | |
2936 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2937 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2938 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
2939 | # } | |
2940 | } else { | |
2941 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
2942 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2943 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2944 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2945 | # } | |
2946 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2947 | #&writeserverconf(); | |
2948 | } | |
2949 | } else { | |
2950 | $errormessage = $Lang::tr{'invalid key'}; | |
6e13d0a5 MT |
2951 | } |
2952 | ||
2953 | ### | |
2954 | ### Restart connection | |
2955 | ### | |
2956 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
2957 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2958 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2959 | ||
2960 | if ($confighash{$cgiparams{'KEY'}}) { | |
c6c9630e MT |
2961 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
2962 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2963 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
2964 | # } | |
6e13d0a5 | 2965 | } else { |
c6c9630e | 2966 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 MT |
2967 | } |
2968 | ||
2969 | ### | |
c6c9630e | 2970 | ### Remove connection |
6e13d0a5 | 2971 | ### |
c6c9630e MT |
2972 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
2973 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2974 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2975 | ||
2976 | if ($confighash{$cgiparams{'KEY'}}) { | |
2977 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2978 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2979 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2980 | # } | |
2981 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
2982 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2983 | delete $confighash{$cgiparams{'KEY'}}; | |
2984 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2985 | #&writeserverconf(); | |
2986 | } else { | |
2987 | $errormessage = $Lang::tr{'invalid key'}; | |
2988 | } | |
ce9abb66 AH |
2989 | #test33 |
2990 | ||
2991 | ### | |
2992 | ### Choose between adding a host-net or net-net connection | |
2993 | ### | |
2994 | ||
2995 | ### | |
7c1d9faf | 2996 | # m.a.d net2net |
ce9abb66 AH |
2997 | ### |
2998 | ||
2999 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
3000 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3001 | &Header::showhttpheaders(); | |
4c962356 | 3002 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
ce9abb66 AH |
3003 | &Header::openbigbox('100%', 'LEFT', '', ''); |
3004 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'}); | |
b278daf3 AH |
3005 | |
3006 | if ( -s "${General::swroot}/ovpn/settings") { | |
3007 | ||
49abe7af | 3008 | print <<END; |
ce9abb66 | 3009 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3010 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
ce9abb66 AH |
3011 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> |
3012 | <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
3013 | <tr><td><input type='radio' name='TYPE' value='net' /></td> | |
3014 | <td class='base'>$Lang::tr{'net to net vpn'}</td></tr> | |
3015 | <tr><td><input type='radio' name='TYPE' value='net2net' /></td> | |
3016 | <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr> | |
3017 | <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr> | |
54fd0535 | 3018 | <tr><td> </td><td>Import Connection Name <img src='/blob.gif' /></td></tr> |
040b8b0c | 3019 | <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>$Lang::tr{'openvpn default'}: Client Packagename</td></tr> |
54fd0535 | 3020 | <tr><td colspan='3'><hr /></td></tr> |
8c877a82 | 3021 | <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
54fd0535 | 3022 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> |
ce9abb66 AH |
3023 | </form></table> |
3024 | END | |
3025 | ; | |
8c877a82 | 3026 | |
ce9abb66 | 3027 | |
b278daf3 | 3028 | } else { |
49abe7af | 3029 | print <<END; |
b278daf3 | 3030 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3031 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
b278daf3 | 3032 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> |
8c877a82 | 3033 | <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
b278daf3 AH |
3034 | </form></table> |
3035 | END | |
3036 | ; | |
3037 | ||
3038 | } | |
3039 | ||
ce9abb66 | 3040 | &Header::closebox(); |
4c962356 | 3041 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
ce9abb66 AH |
3042 | &Header::closebigbox(); |
3043 | &Header::closepage(); | |
3044 | exit (0); | |
3045 | ||
3046 | ### | |
7c1d9faf | 3047 | # m.a.d net2net |
ce9abb66 AH |
3048 | ### |
3049 | ||
3050 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){ | |
3051 | ||
3052 | my @firen2nconf; | |
3053 | my @confdetails; | |
3054 | my $uplconffilename =''; | |
54fd0535 | 3055 | my $uplconffilename2 =''; |
ce9abb66 | 3056 | my $uplp12name = ''; |
54fd0535 | 3057 | my $uplp12name2 = ''; |
ce9abb66 AH |
3058 | my @rem_subnet; |
3059 | my @rem_subnet2; | |
3060 | my @tmposupnet3; | |
3061 | my $key; | |
54fd0535 | 3062 | my @n2nname; |
ce9abb66 AH |
3063 | |
3064 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3065 | ||
3066 | # Check if a file is uploaded | |
3067 | ||
3068 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
3069 | $errormessage = $Lang::tr{'there was no file upload'}; | |
3070 | goto N2N_ERROR; | |
3071 | } | |
3072 | ||
3073 | # Move uploaded IPfire n2n package to temporary file | |
3074 | ||
3075 | (my $fh, my $filename) = tempfile( ); | |
3076 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3077 | $errormessage = $!; | |
3078 | goto N2N_ERROR; | |
3079 | } | |
3080 | ||
3081 | my $zip = Archive::Zip->new(); | |
3082 | my $zipName = $filename; | |
3083 | my $status = $zip->read( $zipName ); | |
3084 | if ($status != AZ_OK) { | |
3085 | $errormessage = "Read of $zipName failed\n"; | |
3086 | goto N2N_ERROR; | |
3087 | } | |
3088 | ||
3089 | my $tempdir = tempdir( CLEANUP => 1 ); | |
3090 | my @files = $zip->memberNames(); | |
3091 | for(@files) { | |
3092 | $zip->extractMemberWithoutPaths($_,"$tempdir/$_"); | |
3093 | } | |
3094 | my $countfiles = @files; | |
3095 | ||
3096 | # Check if we have not more then 2 files | |
3097 | ||
3098 | if ( $countfiles == 2){ | |
3099 | foreach (@files){ | |
3100 | if ( $_ =~ /.conf$/){ | |
3101 | $uplconffilename = $_; | |
3102 | } | |
3103 | if ( $_ =~ /.p12$/){ | |
3104 | $uplp12name = $_; | |
3105 | } | |
3106 | } | |
3107 | if (($uplconffilename eq '') || ($uplp12name eq '')){ | |
3108 | $errormessage = "Either no *.conf or no *.p12 file found\n"; | |
3109 | goto N2N_ERROR; | |
3110 | } | |
3111 | ||
3112 | open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file'; | |
3113 | @firen2nconf = <FILE>; | |
3114 | close (FILE); | |
3115 | chomp(@firen2nconf); | |
3116 | ||
3117 | } else { | |
3118 | ||
3119 | $errormessage = "Filecount does not match only 2 files are allowed\n"; | |
3120 | goto N2N_ERROR; | |
3121 | } | |
3122 | ||
7c1d9faf AH |
3123 | ### |
3124 | # m.a.d net2net | |
ce9abb66 | 3125 | ### |
54fd0535 MT |
3126 | |
3127 | if ($cgiparams{'n2nname'} ne ''){ | |
3128 | ||
3129 | $uplconffilename2 = "$cgiparams{'n2nname'}.conf"; | |
3130 | $uplp12name2 = "$cgiparams{'n2nname'}.p12"; | |
3131 | $n2nname[0] = $cgiparams{'n2nname'}; | |
3132 | my @n2nname2 = split(/\./,$uplconffilename); | |
3133 | $n2nname2[0] =~ s/\n|\r//g; | |
3134 | my $input1 = "${General::swroot}/ovpn/certs/$uplp12name"; | |
3135 | my $output1 = "${General::swroot}/ovpn/certs/$uplp12name2"; | |
3136 | my $input2 = "$n2nname2[0]n2n"; | |
3137 | my $output2 = "$n2nname[0]n2n"; | |
3138 | my $filename = "$tempdir/$uplconffilename"; | |
3139 | open(FILE, "< $filename") or die 'Unable to open config file.'; | |
3140 | my @current = <FILE>; | |
3141 | close(FILE); | |
3142 | foreach (@current) {s/$input1/$output1/g;} | |
3143 | foreach (@current) {s/$input2/$output2/g;} | |
3144 | open (OUT, "> $filename") || die 'Unable to open config file.'; | |
3145 | print OUT @current; | |
3146 | close OUT; | |
ce9abb66 | 3147 | |
54fd0535 MT |
3148 | }else{ |
3149 | $uplconffilename2 = $uplconffilename; | |
3150 | $uplp12name2 = $uplp12name; | |
3151 | @n2nname = split(/\./,$uplconffilename); | |
ce9abb66 | 3152 | $n2nname[0] =~ s/\n|\r//g; |
54fd0535 | 3153 | } |
7c1d9faf AH |
3154 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
3155 | unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";} | |
ce9abb66 | 3156 | |
54fd0535 | 3157 | move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2"); |
ce9abb66 AH |
3158 | |
3159 | if ($? ne 0) { | |
3160 | $errormessage = "*.conf move failed: $!"; | |
3161 | unlink ($filename); | |
3162 | goto N2N_ERROR; | |
3163 | } | |
3164 | ||
54fd0535 | 3165 | move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2"); |
b278daf3 AH |
3166 | chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; |
3167 | ||
ce9abb66 AH |
3168 | if ($? ne 0) { |
3169 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
3170 | unlink ($filename); | |
3171 | goto N2N_ERROR; | |
3172 | } | |
3173 | ||
3174 | my $complzoactive; | |
d96c89eb | 3175 | my $mssfixactive; |
4c962356 | 3176 | my $authactive; |
d96c89eb | 3177 | my $n2nfragment; |
4c962356 | 3178 | my @n2nmtudisc = split(/ /, (grep { /^mtu-disc/ } @firen2nconf)[0]); |
60f396d7 | 3179 | my @n2nproto2 = split(/ /, (grep { /^proto/ } @firen2nconf)[0]); |
54fd0535 | 3180 | my @n2nproto = split(/-/, $n2nproto2[1]); |
ce9abb66 AH |
3181 | my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]); |
3182 | my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]); | |
3183 | my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf; | |
3184 | if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";} | |
d96c89eb AH |
3185 | my @n2nmssfix = grep { /^mssfix/ } @firen2nconf; |
3186 | if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";} | |
54fd0535 | 3187 | #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]); |
d96c89eb | 3188 | my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]); |
ce9abb66 AH |
3189 | my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]); |
3190 | my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]); | |
3191 | my @n2novpnsub = split(/\./,$n2novpnsuball[1]); | |
3192 | my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]); | |
54fd0535 | 3193 | my @n2nmgmt = split(/ /, (grep { /^management/ } @firen2nconf)[0]); |
ce9abb66 | 3194 | my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]); |
4c962356 | 3195 | my @n2ncipher = split(/ /, (grep { /^cipher/ } @firen2nconf)[0]); |
f527e53f | 3196 | my @n2nauth = split(/ /, (grep { /^auth/ } @firen2nconf)[0]);; |
60f396d7 | 3197 | |
ce9abb66 AH |
3198 | ### |
3199 | # m.a.d delete CR and LF from arrays for this chomp doesnt work | |
3200 | ### | |
3201 | ||
ce9abb66 | 3202 | $n2nremote[1] =~ s/\n|\r//g; |
ce9abb66 AH |
3203 | $n2novpnsub[0] =~ s/\n|\r//g; |
3204 | $n2novpnsub[1] =~ s/\n|\r//g; | |
3205 | $n2novpnsub[2] =~ s/\n|\r//g; | |
60f396d7 | 3206 | $n2nproto[0] =~ s/\n|\r//g; |
ce9abb66 AH |
3207 | $n2nport[1] =~ s/\n|\r//g; |
3208 | $n2ntunmtu[1] =~ s/\n|\r//g; | |
3209 | $n2nremsub[1] =~ s/\n|\r//g; | |
b278daf3 | 3210 | $n2nremsub[2] =~ s/\n|\r//g; |
ce9abb66 | 3211 | $n2nlocalsub[2] =~ s/\n|\r//g; |
d96c89eb | 3212 | $n2nfragment[1] =~ s/\n|\r//g; |
54fd0535 | 3213 | $n2nmgmt[2] =~ s/\n|\r//g; |
2ee746be | 3214 | $n2nmtudisc[1] =~ s/\n|\r//g; |
4c962356 EK |
3215 | $n2ncipher[1] =~ s/\n|\r//g; |
3216 | $n2nauth[1] =~ s/\n|\r//g; | |
ce9abb66 | 3217 | chomp ($complzoactive); |
d96c89eb | 3218 | chomp ($mssfixactive); |
ce9abb66 AH |
3219 | |
3220 | ### | |
7c1d9faf | 3221 | # m.a.d net2net |
ce9abb66 AH |
3222 | ### |
3223 | ||
3224 | ### | |
3225 | # Check if there is no other entry with this name | |
3226 | ### | |
3227 | ||
3228 | foreach my $dkey (keys %confighash) { | |
3229 | if ($confighash{$dkey}[1] eq $n2nname[0]) { | |
3230 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3231 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3232 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3233 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
ce9abb66 AH |
3234 | goto N2N_ERROR; |
3235 | } | |
3236 | } | |
3237 | ||
d96c89eb AH |
3238 | ### |
3239 | # Check if OpenVPN Subnet is valid | |
3240 | ### | |
3241 | ||
3242 | foreach my $dkey (keys %confighash) { | |
3243 | if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") { | |
3244 | $errormessage = 'The OpenVPN Subnet is already in use'; | |
b278daf3 AH |
3245 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3246 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3247 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3248 | goto N2N_ERROR; |
3249 | } | |
3250 | } | |
3251 | ||
3252 | ### | |
4c962356 | 3253 | # Check if Dest Port is vaild |
d96c89eb AH |
3254 | ### |
3255 | ||
3256 | foreach my $dkey (keys %confighash) { | |
3257 | if ($confighash{$dkey}[29] eq $n2nport[1] ) { | |
3258 | $errormessage = 'The OpenVPN Port is already in use'; | |
b278daf3 AH |
3259 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3260 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3261 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3262 | goto N2N_ERROR; |
3263 | } | |
3264 | } | |
3265 | ||
3266 | ||
3267 | ||
ce9abb66 AH |
3268 | $key = &General::findhasharraykey (\%confighash); |
3269 | ||
49abe7af | 3270 | foreach my $i (0 .. 42) { $confighash{$key}[$i] = "";} |
350f2980 | 3271 | |
ce9abb66 AH |
3272 | $confighash{$key}[0] = 'off'; |
3273 | $confighash{$key}[1] = $n2nname[0]; | |
350f2980 | 3274 | $confighash{$key}[2] = $n2nname[0]; |
ce9abb66 AH |
3275 | $confighash{$key}[3] = 'net'; |
3276 | $confighash{$key}[4] = 'cert'; | |
3277 | $confighash{$key}[6] = 'client'; | |
3278 | $confighash{$key}[8] = $n2nlocalsub[2]; | |
350f2980 SS |
3279 | $confighash{$key}[10] = $n2nremote[1]; |
3280 | $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]"; | |
54fd0535 | 3281 | $confighash{$key}[22] = $n2nmgmt[2]; |
350f2980 | 3282 | $confighash{$key}[23] = $mssfixactive; |
d96c89eb | 3283 | $confighash{$key}[24] = $n2nfragment[1]; |
350f2980 | 3284 | $confighash{$key}[25] = 'IPFire n2n Client'; |
ce9abb66 | 3285 | $confighash{$key}[26] = 'red'; |
350f2980 SS |
3286 | $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0"; |
3287 | $confighash{$key}[28] = $n2nproto[0]; | |
3288 | $confighash{$key}[29] = $n2nport[1]; | |
3289 | $confighash{$key}[30] = $complzoactive; | |
3290 | $confighash{$key}[31] = $n2ntunmtu[1]; | |
49abe7af | 3291 | $confighash{$key}[38] = $n2nmtudisc[1]; |
4c962356 EK |
3292 | $confighash{$key}[39] = $n2nauth[1]; |
3293 | $confighash{$key}[40] = $n2ncipher[1]; | |
49abe7af | 3294 | $confighash{$key}[41] = 'disabled'; |
ce9abb66 AH |
3295 | |
3296 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
d96c89eb | 3297 | |
ce9abb66 AH |
3298 | N2N_ERROR: |
3299 | ||
3300 | &Header::showhttpheaders(); | |
3301 | &Header::openpage('Validate imported configuration', 1, ''); | |
3302 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
3303 | if ($errormessage) { | |
3304 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
3305 | print "<class name='base'>$errormessage"; | |
3306 | print " </class>"; | |
3307 | &Header::closebox(); | |
3308 | ||
3309 | } else | |
3310 | { | |
3311 | &Header::openbox('100%', 'LEFT', 'import ipfire net2net config'); | |
3312 | } | |
3313 | if ($errormessage eq ''){ | |
49abe7af | 3314 | print <<END; |
ce9abb66 AH |
3315 | <!-- ipfire net2net config gui --> |
3316 | <table width='100%'> | |
3317 | <tr><td width='25%'> </td><td width='25%'> </td></tr> | |
3318 | <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr> | |
3319 | <tr><td> </td><td> </td></tr> | |
3320 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr> | |
3321 | <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr> | |
3322 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr> | |
4c962356 | 3323 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}:</td><td><b>$confighash{$key}[11]</b></td></tr> |
ce9abb66 AH |
3324 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr> |
3325 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr> | |
3326 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr> | |
3327 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr> | |
4c962356 EK |
3328 | <tr><td class='boldbase' nowrap='nowrap'>MSSFIX:</td><td><b>$confighash{$key}[23]</b></td></tr> |
3329 | <tr><td class='boldbase' nowrap='nowrap'>Fragment:</td><td><b>$confighash{$key}[24]</b></td></tr> | |
ce9abb66 | 3330 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr> |
350f2980 | 3331 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td><td><b>$confighash{$key}[38]</b></td></tr> |
54fd0535 | 3332 | <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b>$confighash{$key}[22]</b></td></tr> |
4c962356 EK |
3333 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn hmac'}:</td><td><b>$confighash{$key}[39]</b></td></tr> |
3334 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td><td><b>$confighash{$key}[40]</b></td></tr> | |
ce9abb66 AH |
3335 | <tr><td> </td><td> </td></tr> |
3336 | </table> | |
3337 | END | |
3338 | ; | |
3339 | &Header::closebox(); | |
3340 | } | |
3341 | ||
3342 | if ($errormessage) { | |
3343 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3344 | } else { | |
3345 | print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />"; | |
3346 | print "<input type='hidden' name='TYPE' value='net2netakn' />"; | |
3347 | print "<input type='hidden' name='KEY' value='$key' />"; | |
3348 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
3349 | } | |
3350 | &Header::closebigbox(); | |
3351 | &Header::closepage(); | |
4c962356 | 3352 | exit(0); |
ce9abb66 AH |
3353 | |
3354 | ||
3355 | ## | |
3356 | ### Accept IPFire n2n Package Settings | |
3357 | ### | |
3358 | ||
3359 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3360 | ||
3361 | ### | |
3362 | ### Discard and Rollback IPFire n2n Package Settings | |
3363 | ### | |
3364 | ||
3365 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3366 | ||
3367 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3368 | ||
3369 | if ($confighash{$cgiparams{'KEY'}}) { | |
3370 | ||
3371 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
3372 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
3373 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
3374 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
3375 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
3376 | delete $confighash{$cgiparams{'KEY'}}; | |
3377 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3378 | ||
3379 | } else { | |
3380 | $errormessage = $Lang::tr{'invalid key'}; | |
3381 | } | |
3382 | ||
3383 | ||
3384 | ### | |
7c1d9faf | 3385 | # m.a.d net2net |
ce9abb66 AH |
3386 | ### |
3387 | ||
3388 | ||
3389 | ### | |
3390 | ### Adding a new connection | |
3391 | ### | |
6e13d0a5 MT |
3392 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || |
3393 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || | |
3394 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
8c877a82 | 3395 | |
6e13d0a5 MT |
3396 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
3397 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
3398 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3399 | ||
3400 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { | |
8c877a82 AM |
3401 | if (! $confighash{$cgiparams{'KEY'}}[0]) { |
3402 | $errormessage = $Lang::tr{'invalid key'}; | |
3403 | goto VPNCONF_END; | |
3404 | } | |
4c962356 EK |
3405 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; |
3406 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
3407 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; | |
3408 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; | |
3409 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
3410 | $cgiparams{'SIDE'} = $confighash{$cgiparams{'KEY'}}[6]; | |
3411 | $cgiparams{'LOCAL_SUBNET'} = $confighash{$cgiparams{'KEY'}}[8]; | |
3412 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; | |
8c877a82 | 3413 | $cgiparams{'REMOTE_SUBNET'} = $confighash{$cgiparams{'KEY'}}[11]; |
4c962356 EK |
3414 | $cgiparams{'OVPN_MGMT'} = $confighash{$cgiparams{'KEY'}}[22]; |
3415 | $cgiparams{'MSSFIX'} = $confighash{$cgiparams{'KEY'}}[23]; | |
3416 | $cgiparams{'FRAGMENT'} = $confighash{$cgiparams{'KEY'}}[24]; | |
3417 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; | |
3418 | $cgiparams{'INTERFACE'} = $confighash{$cgiparams{'KEY'}}[26]; | |
3419 | $cgiparams{'OVPN_SUBNET'} = $confighash{$cgiparams{'KEY'}}[27]; | |
3420 | $cgiparams{'PROTOCOL'} = $confighash{$cgiparams{'KEY'}}[28]; | |
3421 | $cgiparams{'DEST_PORT'} = $confighash{$cgiparams{'KEY'}}[29]; | |
3422 | $cgiparams{'COMPLZO'} = $confighash{$cgiparams{'KEY'}}[30]; | |
3423 | $cgiparams{'MTU'} = $confighash{$cgiparams{'KEY'}}[31]; | |
3424 | $cgiparams{'CHECK1'} = $confighash{$cgiparams{'KEY'}}[32]; | |
df9b48b7 | 3425 | $name=$cgiparams{'CHECK1'} ; |
4c962356 EK |
3426 | $cgiparams{$name} = $confighash{$cgiparams{'KEY'}}[33]; |
3427 | $cgiparams{'RG'} = $confighash{$cgiparams{'KEY'}}[34]; | |
3428 | $cgiparams{'CCD_DNS1'} = $confighash{$cgiparams{'KEY'}}[35]; | |
3429 | $cgiparams{'CCD_DNS2'} = $confighash{$cgiparams{'KEY'}}[36]; | |
3430 | $cgiparams{'CCD_WINS'} = $confighash{$cgiparams{'KEY'}}[37]; | |
52d08bcb | 3431 | $cgiparams{'PMTU_DISCOVERY'} = $confighash{$cgiparams{'KEY'}}[38]; |
4c962356 EK |
3432 | $cgiparams{'DAUTH'} = $confighash{$cgiparams{'KEY'}}[39]; |
3433 | $cgiparams{'DCIPHER'} = $confighash{$cgiparams{'KEY'}}[40]; | |
49abe7af | 3434 | $cgiparams{'TLSAUTH'} = $confighash{$cgiparams{'KEY'}}[41]; |
8c877a82 | 3435 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
c6c9630e | 3436 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); |
18837a6a | 3437 | |
8c877a82 | 3438 | #A.Marx CCD check iroute field and convert it to decimal |
52d08bcb | 3439 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
3440 | my @temp=(); |
3441 | my %ccdroutehash=(); | |
3442 | my $keypoint=0; | |
5068ac38 AM |
3443 | my $ip; |
3444 | my $cidr; | |
8c877a82 AM |
3445 | if ($cgiparams{'IR'} ne ''){ |
3446 | @temp = split("\n",$cgiparams{'IR'}); | |
3447 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3448 | #find key to use | |
3449 | foreach my $key (keys %ccdroutehash) { | |
3450 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3451 | $keypoint=$key; | |
3452 | delete $ccdroutehash{$key}; | |
3453 | }else{ | |
3454 | $keypoint = &General::findhasharraykey (\%ccdroutehash); | |
3455 | } | |
3456 | } | |
3457 | $ccdroutehash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3458 | my $i=1; | |
3459 | my $val=0; | |
3460 | foreach $val (@temp){ | |
3461 | chomp($val); | |
3462 | $val=~s/\s*$//g; | |
5068ac38 | 3463 | #check if iroute exists in ccdroute or if new iroute is part of an existing one |
8c877a82 AM |
3464 | foreach my $key (keys %ccdroutehash) { |
3465 | foreach my $oldiroute ( 1 .. $#{$ccdroutehash{$key}}){ | |
5068ac38 AM |
3466 | if ($ccdroutehash{$key}[$oldiroute] eq "$val") { |
3467 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3468 | goto VPNCONF_ERROR; | |
3469 | } | |
3470 | my ($ip1,$cidr1) = split (/\//, $val); | |
82c809c7 | 3471 | $ip1 = &General::getnetworkip($ip1,&General::iporsubtocidr($cidr1)); |
5068ac38 AM |
3472 | my ($ip2,$cidr2) = split (/\//, $ccdroutehash{$key}[$oldiroute]); |
3473 | if (&General::IpInSubnet ($ip1,$ip2,$cidr2)){ | |
3474 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3475 | goto VPNCONF_ERROR; | |
3476 | } | |
3477 | ||
8c877a82 AM |
3478 | } |
3479 | } | |
5068ac38 AM |
3480 | if (!&General::validipandmask($val)){ |
3481 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3482 | goto VPNCONF_ERROR; | |
3483 | }else{ | |
3484 | ($ip,$cidr) = split(/\//,$val); | |
3485 | $ip=&General::getnetworkip($ip,&General::iporsubtocidr($cidr)); | |
3486 | $cidr=&General::iporsubtodec($cidr); | |
3487 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3488 | ||
3489 | } | |
8c877a82 AM |
3490 | |
3491 | #check for existing network IP's | |
52d08bcb AM |
3492 | if (&General::IpInSubnet ($ip,$netsettings{GREEN_NETADDRESS},$netsettings{GREEN_NETMASK}) && $netsettings{GREEN_NETADDRESS} ne '0.0.0.0') |
3493 | { | |
3494 | $errormessage=$Lang::tr{'ccd err green'}; | |
3495 | goto VPNCONF_ERROR; | |
3496 | }elsif(&General::IpInSubnet ($ip,$netsettings{RED_NETADDRESS},$netsettings{RED_NETMASK}) && $netsettings{RED_NETADDRESS} ne '0.0.0.0') | |
3497 | { | |
3498 | $errormessage=$Lang::tr{'ccd err red'}; | |
3499 | goto VPNCONF_ERROR; | |
3500 | }elsif(&General::IpInSubnet ($ip,$netsettings{BLUE_NETADDRESS},$netsettings{BLUE_NETMASK}) && $netsettings{BLUE_NETADDRESS} ne '0.0.0.0' && $netsettings{BLUE_NETADDRESS} gt '') | |
3501 | { | |
3502 | $errormessage=$Lang::tr{'ccd err blue'}; | |
3503 | goto VPNCONF_ERROR; | |
3504 | }elsif(&General::IpInSubnet ($ip,$netsettings{ORANGE_NETADDRESS},$netsettings{ORANGE_NETMASK}) && $netsettings{ORANGE_NETADDRESS} ne '0.0.0.0' && $netsettings{ORANGE_NETADDRESS} gt '' ) | |
3505 | { | |
3506 | $errormessage=$Lang::tr{'ccd err orange'}; | |
8c877a82 AM |
3507 | goto VPNCONF_ERROR; |
3508 | } | |
52d08bcb | 3509 | |
8c877a82 AM |
3510 | if (&General::validipandmask($val)){ |
3511 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3512 | }else{ | |
3513 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($ip/$cidr)"; | |
3514 | goto VPNCONF_ERROR; | |
3515 | } | |
3516 | $i++; | |
3517 | } | |
3518 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3519 | &writeserverconf; | |
3520 | }else{ | |
3521 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3522 | foreach my $key (keys %ccdroutehash) { | |
3523 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3524 | delete $ccdroutehash{$key}; | |
3525 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3526 | &writeserverconf; | |
3527 | } | |
3528 | } | |
3529 | } | |
3530 | undef @temp; | |
3531 | #check route field and convert it to decimal | |
8c877a82 AM |
3532 | my $val=0; |
3533 | my $i=1; | |
8c877a82 | 3534 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
52d08bcb AM |
3535 | #find key to use |
3536 | foreach my $key (keys %ccdroute2hash) { | |
3537 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
3538 | $keypoint=$key; | |
3539 | delete $ccdroute2hash{$key}; | |
3540 | }else{ | |
3541 | $keypoint = &General::findhasharraykey (\%ccdroute2hash); | |
3542 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3543 | &writeserverconf; | |
8c877a82 | 3544 | } |
52d08bcb AM |
3545 | } |
3546 | $ccdroute2hash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3547 | if ($cgiparams{'IFROUTE'} eq ''){$cgiparams{'IFROUTE'} = $Lang::tr{'ccd none'};} | |
3548 | @temp = split(/\|/,$cgiparams{'IFROUTE'}); | |
3549 | my %ownnet=(); | |
3550 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); | |
3551 | foreach $val (@temp){ | |
3552 | chomp($val); | |
3553 | $val=~s/\s*$//g; | |
3554 | if ($val eq $Lang::tr{'green'}) | |
3555 | { | |
3556 | $val=$ownnet{GREEN_NETADDRESS}."/".$ownnet{GREEN_NETMASK}; | |
3557 | } | |
3558 | if ($val eq $Lang::tr{'blue'}) | |
3559 | { | |
3560 | $val=$ownnet{BLUE_NETADDRESS}."/".$ownnet{BLUE_NETMASK}; | |
3561 | } | |
3562 | if ($val eq $Lang::tr{'orange'}) | |
3563 | { | |
3564 | $val=$ownnet{ORANGE_NETADDRESS}."/".$ownnet{ORANGE_NETMASK}; | |
3565 | } | |
3566 | my ($ip,$cidr) = split (/\//, $val); | |
3567 | ||
3568 | if ($val ne $Lang::tr{'ccd none'}) | |
3569 | { | |
8c877a82 AM |
3570 | if (! &check_routes_push($val)){$errormessage=$errormessage."Route $val ".$Lang::tr{'ccd err routeovpn2'}." ($val)";goto VPNCONF_ERROR;} |
3571 | if (! &check_ccdroute($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err inuse'}." ($val)" ;goto VPNCONF_ERROR;} | |
3572 | if (! &check_ccdconf($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err routeovpn'}." ($val)";goto VPNCONF_ERROR;} | |
3573 | if (&General::validipandmask($val)){ | |
3574 | $val=$ip."/".&General::iporsubtodec($cidr); | |
3575 | $ccdroute2hash{$keypoint}[$i] = $val; | |
3576 | }else{ | |
3577 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3578 | goto VPNCONF_ERROR; | |
3579 | } | |
52d08bcb AM |
3580 | }else{ |
3581 | $ccdroute2hash{$keypoint}[$i]=''; | |
3582 | } | |
3583 | $i++; | |
3584 | } | |
3585 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
3586 | ||
8c877a82 AM |
3587 | #check dns1 ip |
3588 | if ($cgiparams{'CCD_DNS1'} ne '' && ! &General::validip($cgiparams{'CCD_DNS1'})) { | |
3589 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 1"; | |
3590 | goto VPNCONF_ERROR; | |
3591 | } | |
3592 | #check dns2 ip | |
3593 | if ($cgiparams{'CCD_DNS2'} ne '' && ! &General::validip($cgiparams{'CCD_DNS2'})) { | |
3594 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 2"; | |
3595 | goto VPNCONF_ERROR; | |
3596 | } | |
3597 | #check wins ip | |
3598 | if ($cgiparams{'CCD_WINS'} ne '' && ! &General::validip($cgiparams{'CCD_WINS'})) { | |
3599 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp wins'}; | |
3600 | goto VPNCONF_ERROR; | |
3601 | } | |
52d08bcb | 3602 | } |
8c877a82 AM |
3603 | |
3604 | #CCD End | |
52d08bcb | 3605 | |
8c877a82 AM |
3606 | |
3607 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { | |
c6c9630e | 3608 | $errormessage = $Lang::tr{'connection type is invalid'}; |
b278daf3 AH |
3609 | if ($cgiparams{'TYPE'} eq 'net') { |
3610 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3611 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3612 | } | |
c6c9630e MT |
3613 | goto VPNCONF_ERROR; |
3614 | } | |
3615 | ||
3616 | ||
3617 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
3618 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
b278daf3 AH |
3619 | if ($cgiparams{'TYPE'} eq 'net') { |
3620 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3621 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3622 | } | |
3623 | goto VPNCONF_ERROR; | |
3624 | } | |
c6c9630e MT |
3625 | |
3626 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { | |
3627 | $errormessage = $Lang::tr{'name is invalid'}; | |
b278daf3 AH |
3628 | if ($cgiparams{'TYPE'} eq 'net') { |
3629 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3630 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3631 | } | |
c6c9630e MT |
3632 | goto VPNCONF_ERROR; |
3633 | } | |
3634 | ||
3635 | if (length($cgiparams{'NAME'}) >60) { | |
3636 | $errormessage = $Lang::tr{'name too long'}; | |
b278daf3 AH |
3637 | if ($cgiparams{'TYPE'} eq 'net') { |
3638 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3639 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3640 | } | |
c6c9630e MT |
3641 | goto VPNCONF_ERROR; |
3642 | } | |
3643 | ||
d96c89eb | 3644 | ### |
7c1d9faf | 3645 | # m.a.d net2net |
d96c89eb AH |
3646 | ### |
3647 | ||
7c1d9faf | 3648 | if ($cgiparams{'TYPE'} eq 'net') { |
ab4cf06c | 3649 | if ($cgiparams{'DEST_PORT'} eq $vpnsettings{'DDEST_PORT'}) { |
cd0c0a0d | 3650 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
b278daf3 AH |
3651 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3652 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3653 | goto VPNCONF_ERROR; | |
d96c89eb | 3654 | } |
ab4cf06c AM |
3655 | #Bugfix 10357 |
3656 | foreach my $key (sort keys %confighash){ | |
3657 | if ( ($confighash{$key}[22] eq $cgiparams{'DEST_PORT'} && $cgiparams{'NAME'} ne $confighash{$key}[1]) || ($confighash{$key}[29] eq $cgiparams{'DEST_PORT'} && $cgiparams{'NAME'} ne $confighash{$key}[1])){ | |
54fd0535 MT |
3658 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
3659 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3660 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
ab4cf06c AM |
3661 | goto VPNCONF_ERROR; |
3662 | } | |
3663 | } | |
3664 | if ($cgiparams{'DEST_PORT'} eq '') { | |
3665 | $errormessage = $Lang::tr{'invalid port'}; | |
3666 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3667 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
54fd0535 MT |
3668 | goto VPNCONF_ERROR; |
3669 | } | |
d96c89eb | 3670 | |
f48074ba SS |
3671 | # Check if the input for the transfer net is valid. |
3672 | if (!&General::validipandmask($cgiparams{'OVPN_SUBNET'})){ | |
3673 | $errormessage = $Lang::tr{'ccd err invalidnet'}; | |
3674 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3675 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3676 | goto VPNCONF_ERROR; | |
3677 | } | |
3678 | ||
d96c89eb | 3679 | if ($cgiparams{'OVPN_SUBNET'} eq $vpnsettings{'DOVPN_SUBNET'}) { |
cd0c0a0d | 3680 | $errormessage = $Lang::tr{'openvpn subnet is used'}; |
b278daf3 AH |
3681 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3682 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3683 | goto VPNCONF_ERROR; |
3684 | } | |
3685 | ||
3686 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'MSSFIX'} eq 'on')) { | |
cd0c0a0d | 3687 | $errormessage = $Lang::tr{'openvpn mssfix allowed with udp'}; |
b278daf3 AH |
3688 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3689 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3690 | goto VPNCONF_ERROR; |
3691 | } | |
3692 | ||
3693 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'FRAGMENT'} ne '')) { | |
cd0c0a0d | 3694 | $errormessage = $Lang::tr{'openvpn fragment allowed with udp'}; |
b278daf3 AH |
3695 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3696 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3697 | goto VPNCONF_ERROR; |
3698 | } | |
d96c89eb | 3699 | |
2ee746be SS |
3700 | if ($cgiparams{'PMTU_DISCOVERY'} ne 'off') { |
3701 | if (($cgiparams{'FRAGMENT'} ne '') || ($cgiparams{'MSSFIX'} eq 'on')) { | |
3702 | $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'}; | |
3703 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3704 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3705 | goto VPNCONF_ERROR; | |
3706 | } | |
3707 | } | |
3708 | ||
4cdf8b92 SS |
3709 | if (($cgiparams{'PMTU_DISCOVERY'} ne 'off') && ($cgiparams{'MTU'} ne '1500')) { |
3710 | $errormessage = $Lang::tr{'ovpn mtu-disc and mtu not 1500'}; | |
3711 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3712 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3713 | goto VPNCONF_ERROR; | |
3714 | } | |
3715 | ||
7c1d9faf | 3716 | if ( &validdotmask ($cgiparams{'LOCAL_SUBNET'})) { |
cd0c0a0d | 3717 | $errormessage = $Lang::tr{'openvpn prefix local subnet'}; |
b278daf3 AH |
3718 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3719 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3720 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3721 | } |
3722 | ||
3723 | if ( &validdotmask ($cgiparams{'OVPN_SUBNET'})) { | |
cd0c0a0d | 3724 | $errormessage = $Lang::tr{'openvpn prefix openvpn subnet'}; |
b278daf3 AH |
3725 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3726 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3727 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3728 | } |
3729 | ||
3730 | if ( &validdotmask ($cgiparams{'REMOTE_SUBNET'})) { | |
cd0c0a0d | 3731 | $errormessage = $Lang::tr{'openvpn prefix remote subnet'}; |
b278daf3 AH |
3732 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3733 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3734 | goto VPNCONF_ERROR; | |
8c252e6a EK |
3735 | } |
3736 | ||
3737 | if ($cgiparams{'DEST_PORT'} <= 1023) { | |
3738 | $errormessage = $Lang::tr{'ovpn port in root range'}; | |
3739 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3740 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3741 | goto VPNCONF_ERROR; | |
3742 | } | |
54fd0535 | 3743 | |
4c962356 | 3744 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c252e6a EK |
3745 | $cgiparams{'OVPN_MGMT'} = $cgiparams{'DEST_PORT'}; |
3746 | } | |
3747 | ||
3748 | if ($cgiparams{'OVPN_MGMT'} <= 1023) { | |
3749 | $errormessage = $Lang::tr{'ovpn mgmt in root range'}; | |
3750 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3751 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3752 | goto VPNCONF_ERROR; | |
b2e75449 MT |
3753 | } |
3754 | #Check if remote subnet is used elsewhere | |
3755 | my ($n2nip,$n2nsub)=split("/",$cgiparams{'REMOTE_SUBNET'}); | |
3756 | $warnmessage=&General::checksubnets('',$n2nip,'ovpn'); | |
3757 | if ($warnmessage){ | |
3758 | $warnmessage=$Lang::tr{'remote subnet'}." ($cgiparams{'REMOTE_SUBNET'}) <br>".$warnmessage; | |
3759 | } | |
7c1d9faf | 3760 | } |
d96c89eb | 3761 | |
ce9abb66 AH |
3762 | # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) { |
3763 | # $errormessage = $Lang::tr{'ipfire side is invalid'}; | |
3764 | # goto VPNCONF_ERROR; | |
3765 | # } | |
3766 | ||
c6c9630e MT |
3767 | # Check if there is no other entry with this name |
3768 | if (! $cgiparams{'KEY'}) { | |
3769 | foreach my $key (keys %confighash) { | |
3770 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
3771 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3772 | if ($cgiparams{'TYPE'} eq 'net') { |
3773 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3774 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3775 | } | |
c6c9630e | 3776 | goto VPNCONF_ERROR; |
6e13d0a5 | 3777 | } |
c6c9630e MT |
3778 | } |
3779 | } | |
3780 | ||
c125d8a2 | 3781 | # Check if a remote host/IP has been set for the client. |
86228a56 MT |
3782 | if ($cgiparams{'TYPE'} eq 'net') { |
3783 | if ($cgiparams{'SIDE'} ne 'server' && $cgiparams{'REMOTE'} eq '') { | |
3784 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 3785 | |
86228a56 MT |
3786 | # Check if this is a N2N connection and drop temporary config. |
3787 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3788 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
ce9abb66 | 3789 | |
86228a56 MT |
3790 | goto VPNCONF_ERROR; |
3791 | } | |
c125d8a2 | 3792 | |
86228a56 MT |
3793 | # Check if a remote host/IP has been configured - the field can be empty on the server side. |
3794 | if ($cgiparams{'REMOTE'} ne '') { | |
3795 | # Check if the given IP is valid - otherwise check if it is a valid domain. | |
3796 | if (! &General::validip($cgiparams{'REMOTE'})) { | |
3797 | # Check for a valid domain. | |
3798 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
3799 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 3800 | |
86228a56 MT |
3801 | # Check if this is a N2N connection and drop temporary config. |
3802 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3803 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
c125d8a2 | 3804 | |
86228a56 MT |
3805 | goto VPNCONF_ERROR; |
3806 | } | |
3807 | } | |
6e13d0a5 | 3808 | } |
c6c9630e | 3809 | } |
c125d8a2 | 3810 | |
c6c9630e MT |
3811 | if ($cgiparams{'TYPE'} ne 'host') { |
3812 | unless (&General::validipandmask($cgiparams{'LOCAL_SUBNET'})) { | |
3813 | $errormessage = $Lang::tr{'local subnet is invalid'}; | |
b278daf3 AH |
3814 | if ($cgiparams{'TYPE'} eq 'net') { |
3815 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3816 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3817 | } | |
c6c9630e MT |
3818 | goto VPNCONF_ERROR;} |
3819 | } | |
3820 | # Check if there is no other entry without IP-address and PSK | |
3821 | if ($cgiparams{'REMOTE'} eq '') { | |
3822 | foreach my $key (keys %confighash) { | |
3823 | if(($cgiparams{'KEY'} ne $key) && | |
3824 | ($confighash{$key}[4] eq 'psk' || $cgiparams{'AUTH'} eq 'psk') && | |
3825 | $confighash{$key}[10] eq '') { | |
3826 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
3827 | goto VPNCONF_ERROR; | |
6e13d0a5 | 3828 | } |
c6c9630e MT |
3829 | } |
3830 | } | |
ce9abb66 AH |
3831 | if (($cgiparams{'TYPE'} eq 'net') && (! &General::validipandmask($cgiparams{'REMOTE_SUBNET'}))) { |
3832 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
b278daf3 AH |
3833 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3834 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3835 | goto VPNCONF_ERROR; | |
ce9abb66 | 3836 | } |
c6c9630e MT |
3837 | |
3838 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
3839 | $errormessage = $Lang::tr{'invalid input'}; | |
3840 | goto VPNCONF_ERROR; | |
3841 | } | |
3842 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
3843 | $errormessage = $Lang::tr{'invalid input'}; | |
3844 | goto VPNCONF_ERROR; | |
3845 | } | |
3846 | ||
3847 | #fixplausi | |
3848 | if ($cgiparams{'AUTH'} eq 'psk') { | |
3849 | # if (! length($cgiparams{'PSK'}) ) { | |
3850 | # $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
3851 | # goto VPNCONF_ERROR; | |
3852 | # } | |
3853 | # if ($cgiparams{'PSK'} =~ /['",&]/) { | |
3854 | # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
3855 | # goto VPNCONF_ERROR; | |
3856 | # } | |
3857 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { | |
3858 | if ($cgiparams{'KEY'}) { | |
3859 | $errormessage = $Lang::tr{'cant change certificates'}; | |
3860 | goto VPNCONF_ERROR; | |
3861 | } | |
3862 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
3863 | $errormessage = $Lang::tr{'there was no file upload'}; | |
3864 | goto VPNCONF_ERROR; | |
3865 | } | |
3866 | ||
3867 | # Move uploaded certificate request to a temporary file | |
3868 | (my $fh, my $filename) = tempfile( ); | |
3869 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3870 | $errormessage = $!; | |
3871 | goto VPNCONF_ERROR; | |
3872 | } | |
6e13d0a5 | 3873 | |
c6c9630e MT |
3874 | # Sign the certificate request and move it |
3875 | # Sign the host certificate request | |
f6e12093 | 3876 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
3877 | '-batch', '-notext', |
3878 | '-in', $filename, | |
3879 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
3880 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
3881 | if ($?) { | |
3882 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
3883 | unlink ($filename); | |
3884 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
3885 | &newcleanssldatabase(); | |
3886 | goto VPNCONF_ERROR; | |
3887 | } else { | |
3888 | unlink ($filename); | |
3889 | &deletebackupcert(); | |
3890 | } | |
3891 | ||
3892 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
3893 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
3894 | $temp = $1; | |
3895 | $temp =~ s+/Email+, E+; | |
3896 | $temp =~ s/ ST=/ S=/; | |
3897 | $cgiparams{'CERT_NAME'} = $temp; | |
3898 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
3899 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
3900 | if ($cgiparams{'CERT_NAME'} eq '') { | |
3901 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
3902 | goto VPNCONF_ERROR; | |
3903 | } | |
3904 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { | |
3905 | if ($cgiparams{'KEY'}) { | |
3906 | $errormessage = $Lang::tr{'cant change certificates'}; | |
3907 | goto VPNCONF_ERROR; | |
3908 | } | |
3909 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
3910 | $errormessage = $Lang::tr{'there was no file upload'}; | |
3911 | goto VPNCONF_ERROR; | |
3912 | } | |
3913 | # Move uploaded certificate to a temporary file | |
3914 | (my $fh, my $filename) = tempfile( ); | |
3915 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3916 | $errormessage = $!; | |
3917 | goto VPNCONF_ERROR; | |
3918 | } | |
3919 | ||
3920 | # Verify the certificate has a valid CA and move it | |
3921 | my $validca = 0; | |
3922 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename`; | |
3923 | if ($test =~ /: OK/) { | |
3924 | $validca = 1; | |
3925 | } else { | |
3926 | foreach my $key (keys %cahash) { | |
3927 | $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$key}[0]cert.pem $filename`; | |
3928 | if ($test =~ /: OK/) { | |
3929 | $validca = 1; | |
3930 | } | |
6e13d0a5 | 3931 | } |
c6c9630e MT |
3932 | } |
3933 | if (! $validca) { | |
3934 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
3935 | unlink ($filename); | |
3936 | goto VPNCONF_ERROR; | |
3937 | } else { | |
3938 | move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
3939 | if ($? ne 0) { | |
3940 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
3941 | unlink ($filename); | |
3942 | goto VPNCONF_ERROR; | |
6e13d0a5 | 3943 | } |
c6c9630e MT |
3944 | } |
3945 | ||
3946 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
3947 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
3948 | $temp = $1; | |
3949 | $temp =~ s+/Email+, E+; | |
3950 | $temp =~ s/ ST=/ S=/; | |
3951 | $cgiparams{'CERT_NAME'} = $temp; | |
3952 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
3953 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
3954 | if ($cgiparams{'CERT_NAME'} eq '') { | |
3955 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
3956 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
3957 | goto VPNCONF_ERROR; | |
3958 | } | |
3959 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { | |
3960 | if ($cgiparams{'KEY'}) { | |
3961 | $errormessage = $Lang::tr{'cant change certificates'}; | |
3962 | goto VPNCONF_ERROR; | |
3963 | } | |
3964 | # Validate input since the form was submitted | |
3965 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
3966 | $errormessage = $Lang::tr{'name too long'}; | |
3967 | goto VPNCONF_ERROR; | |
3968 | } | |
194314b2 | 3969 | if ($cgiparams{'CERT_NAME'} eq '' || $cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { |
c6c9630e MT |
3970 | $errormessage = $Lang::tr{'invalid input for name'}; |
3971 | goto VPNCONF_ERROR; | |
3972 | } | |
3973 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
3974 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
3975 | goto VPNCONF_ERROR; | |
3976 | } | |
3977 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
3978 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
3979 | goto VPNCONF_ERROR; | |
3980 | } | |
3981 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
3982 | $errormessage = $Lang::tr{'invalid input for department'}; | |
3983 | goto VPNCONF_ERROR; | |
3984 | } | |
3985 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
3986 | $errormessage = $Lang::tr{'organization too long'}; | |
3987 | goto VPNCONF_ERROR; | |
3988 | } | |
3989 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
3990 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
3991 | goto VPNCONF_ERROR; | |
3992 | } | |
3993 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
3994 | $errormessage = $Lang::tr{'invalid input for city'}; | |
3995 | goto VPNCONF_ERROR; | |
3996 | } | |
3997 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
3998 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
3999 | goto VPNCONF_ERROR; | |
4000 | } | |
4001 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
4002 | $errormessage = $Lang::tr{'invalid input for country'}; | |
4003 | goto VPNCONF_ERROR; | |
4004 | } | |
4005 | if ($cgiparams{'CERT_PASS1'} ne '' && $cgiparams{'CERT_PASS2'} ne ''){ | |
4006 | if (length($cgiparams{'CERT_PASS1'}) < 5) { | |
4007 | $errormessage = $Lang::tr{'password too short'}; | |
4008 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4009 | } |
c6c9630e MT |
4010 | } |
4011 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { | |
4012 | $errormessage = $Lang::tr{'passwords do not match'}; | |
4013 | goto VPNCONF_ERROR; | |
4014 | } | |
4015 | ||
4016 | # Replace empty strings with a . | |
4017 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
4018 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
4019 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
4020 | ||
4021 | # Create the Host certificate request client | |
4022 | my $pid = open(OPENSSL, "|-"); | |
4023 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto VPNCONF_ERROR;}; | |
4024 | if ($pid) { # parent | |
4025 | print OPENSSL "$cgiparams{'CERT_COUNTRY'}\n"; | |
4026 | print OPENSSL "$state\n"; | |
4027 | print OPENSSL "$city\n"; | |
4028 | print OPENSSL "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
4029 | print OPENSSL "$ou\n"; | |
4030 | print OPENSSL "$cgiparams{'CERT_NAME'}\n"; | |
4031 | print OPENSSL "$cgiparams{'CERT_EMAIL'}\n"; | |
4032 | print OPENSSL ".\n"; | |
4033 | print OPENSSL ".\n"; | |
4034 | close (OPENSSL); | |
4035 | if ($?) { | |
4036 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4037 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4038 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4039 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4040 | } |
c6c9630e | 4041 | } else { # child |
badd8c1c | 4042 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
4c962356 | 4043 | '-newkey', 'rsa:2048', |
c6c9630e MT |
4044 | '-keyout', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", |
4045 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4046 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
4047 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
4048 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4049 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4050 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4051 | } |
c6c9630e MT |
4052 | } |
4053 | ||
4054 | # Sign the host certificate request | |
f6e12093 | 4055 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4056 | '-batch', '-notext', |
4057 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4058 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4059 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4060 | if ($?) { | |
4061 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4062 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4063 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4064 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4065 | &newcleanssldatabase(); | |
4066 | goto VPNCONF_ERROR; | |
4067 | } else { | |
4068 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4069 | &deletebackupcert(); | |
4070 | } | |
4071 | ||
4072 | # Create the pkcs12 file | |
4073 | system('/usr/bin/openssl', 'pkcs12', '-export', | |
4074 | '-inkey', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
4075 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4076 | '-name', $cgiparams{'NAME'}, | |
4077 | '-passout', "pass:$cgiparams{'CERT_PASS1'}", | |
4078 | '-certfile', "${General::swroot}/ovpn/ca/cacert.pem", | |
4079 | '-caname', "$vpnsettings{'ROOTCERT_ORGANIZATION'} CA", | |
4080 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4081 | if ($?) { | |
4082 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4083 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4084 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4085 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4086 | goto VPNCONF_ERROR; | |
4087 | } else { | |
4088 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4089 | } | |
4090 | } elsif ($cgiparams{'AUTH'} eq 'cert') { | |
4091 | ;# Nothing, just editing | |
4092 | } else { | |
4093 | $errormessage = $Lang::tr{'invalid input for authentication method'}; | |
4094 | goto VPNCONF_ERROR; | |
4095 | } | |
4096 | ||
4097 | # Check if there is no other entry with this common name | |
4098 | if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk')) { | |
4099 | foreach my $key (keys %confighash) { | |
4100 | if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { | |
4101 | $errormessage = $Lang::tr{'a connection with this common name already exists'}; | |
4102 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4103 | } |
c6c9630e MT |
4104 | } |
4105 | } | |
4106 | ||
ab4cf06c | 4107 | # Save the config |
c6c9630e | 4108 | my $key = $cgiparams{'KEY'}; |
8c877a82 | 4109 | |
c6c9630e MT |
4110 | if (! $key) { |
4111 | $key = &General::findhasharraykey (\%confighash); | |
49abe7af | 4112 | foreach my $i (0 .. 43) { $confighash{$key}[$i] = "";} |
c6c9630e | 4113 | } |
8c877a82 AM |
4114 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; |
4115 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
c6c9630e | 4116 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { |
8c877a82 | 4117 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; |
c6c9630e | 4118 | } |
8c877a82 AM |
4119 | |
4120 | $confighash{$key}[3] = $cgiparams{'TYPE'}; | |
c6c9630e | 4121 | if ($cgiparams{'AUTH'} eq 'psk') { |
8c877a82 AM |
4122 | $confighash{$key}[4] = 'psk'; |
4123 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
c6c9630e | 4124 | } else { |
8c877a82 | 4125 | $confighash{$key}[4] = 'cert'; |
c6c9630e | 4126 | } |
ce9abb66 | 4127 | if ($cgiparams{'TYPE'} eq 'net') { |
8c877a82 AM |
4128 | $confighash{$key}[6] = $cgiparams{'SIDE'}; |
4129 | $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'}; | |
ce9abb66 | 4130 | } |
4c962356 | 4131 | $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'}; |
8c877a82 | 4132 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; |
4c962356 | 4133 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c877a82 | 4134 | $confighash{$key}[22] = $confighash{$key}[29]; |
4c962356 | 4135 | } else { |
8c877a82 | 4136 | $confighash{$key}[22] = $cgiparams{'OVPN_MGMT'}; |
4c962356 | 4137 | } |
8c877a82 AM |
4138 | $confighash{$key}[23] = $cgiparams{'MSSFIX'}; |
4139 | $confighash{$key}[24] = $cgiparams{'FRAGMENT'}; | |
4140 | $confighash{$key}[25] = $cgiparams{'REMARK'}; | |
4141 | $confighash{$key}[26] = $cgiparams{'INTERFACE'}; | |
c6c9630e | 4142 | # new fields |
8c877a82 AM |
4143 | $confighash{$key}[27] = $cgiparams{'OVPN_SUBNET'}; |
4144 | $confighash{$key}[28] = $cgiparams{'PROTOCOL'}; | |
4145 | $confighash{$key}[29] = $cgiparams{'DEST_PORT'}; | |
4146 | $confighash{$key}[30] = $cgiparams{'COMPLZO'}; | |
4147 | $confighash{$key}[31] = $cgiparams{'MTU'}; | |
4148 | $confighash{$key}[32] = $cgiparams{'CHECK1'}; | |
df9b48b7 | 4149 | $name=$cgiparams{'CHECK1'}; |
8c877a82 AM |
4150 | $confighash{$key}[33] = $cgiparams{$name}; |
4151 | $confighash{$key}[34] = $cgiparams{'RG'}; | |
4152 | $confighash{$key}[35] = $cgiparams{'CCD_DNS1'}; | |
4153 | $confighash{$key}[36] = $cgiparams{'CCD_DNS2'}; | |
4154 | $confighash{$key}[37] = $cgiparams{'CCD_WINS'}; | |
4c962356 EK |
4155 | $confighash{$key}[38] = $cgiparams{'PMTU_DISCOVERY'}; |
4156 | $confighash{$key}[39] = $cgiparams{'DAUTH'}; | |
4157 | $confighash{$key}[40] = $cgiparams{'DCIPHER'}; | |
350f2980 | 4158 | |
c6c9630e | 4159 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
8c877a82 AM |
4160 | |
4161 | if ($cgiparams{'CHECK1'} ){ | |
4162 | ||
4163 | my ($ccdip,$ccdsub)=split "/",$cgiparams{$name}; | |
4164 | my ($a,$b,$c,$d) = split (/\./,$ccdip); | |
df9b48b7 AM |
4165 | if ( -e "${General::swroot}/ovpn/ccd/$confighash{$key}[2]"){ |
4166 | unlink "${General::swroot}/ovpn/ccd/$cgiparams{'CERT_NAME'}"; | |
4167 | } | |
8c877a82 | 4168 | open ( CCDRWCONF,'>',"${General::swroot}/ovpn/ccd/$confighash{$key}[2]") or die "Unable to create clientconfigfile $!"; |
82c809c7 | 4169 | print CCDRWCONF "# OpenVPN clientconfig from ccd extension by Copymaster#\n\n"; |
8c877a82 AM |
4170 | if($cgiparams{'CHECK1'} eq 'dynamic'){ |
4171 | print CCDRWCONF "#This client uses the dynamic pool\n"; | |
4172 | }else{ | |
82c809c7 | 4173 | print CCDRWCONF "#Ip address client and server\n"; |
8c877a82 AM |
4174 | print CCDRWCONF "ifconfig-push $ccdip ".&General::getlastip($ccdip,1)."\n"; |
4175 | } | |
4176 | if ($confighash{$key}[34] eq 'on'){ | |
4177 | print CCDRWCONF "\n#Redirect Gateway: \n#All IP traffic is redirected through the vpn \n"; | |
4178 | print CCDRWCONF "push redirect-gateway\n"; | |
4179 | } | |
52d08bcb | 4180 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
8c877a82 | 4181 | if ($cgiparams{'IR'} ne ''){ |
82c809c7 | 4182 | print CCDRWCONF "\n#Client routes these networks (behind Client)\n"; |
8c877a82 AM |
4183 | foreach my $key (keys %ccdroutehash){ |
4184 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}){ | |
4185 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
4186 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
4187 | print CCDRWCONF "iroute $a $b\n"; | |
4188 | } | |
4189 | } | |
4190 | } | |
4191 | } | |
52d08bcb | 4192 | if ($cgiparams{'IFROUTE'} eq $Lang::tr{'ccd none'} ){$cgiparams{'IFROUTE'}='';} |
8c877a82 | 4193 | if ($cgiparams{'IFROUTE'} ne ''){ |
82c809c7 | 4194 | print CCDRWCONF "\n#Client gets routes to these networks (behind IPFire)\n"; |
8c877a82 AM |
4195 | foreach my $key (keys %ccdroute2hash){ |
4196 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4197 | foreach my $i ( 1 .. $#{$ccdroute2hash{$key}}){ | |
4198 | if($ccdroute2hash{$key}[$i] eq $Lang::tr{'blue'}){ | |
4199 | my %blue=(); | |
4200 | &General::readhash("${General::swroot}/ethernet/settings", \%blue); | |
52d08bcb | 4201 | print CCDRWCONF "push \"route $blue{BLUE_ADDRESS} $blue{BLUE_NETMASK}\n"; |
8c877a82 AM |
4202 | }elsif($ccdroute2hash{$key}[$i] eq $Lang::tr{'orange'}){ |
4203 | my %orange=(); | |
4204 | &General::readhash("${General::swroot}/ethernet/settings", \%orange); | |
4205 | print CCDRWCONF "push \"route $orange{ORANGE_ADDRESS} $orange{ORANGE_NETMASK}\n"; | |
4206 | }else{ | |
4207 | my ($a,$b)=split (/\//,$ccdroute2hash{$key}[$i]); | |
4208 | print CCDRWCONF "push \"route $a $b\"\n"; | |
4209 | } | |
4210 | } | |
4211 | } | |
4212 | } | |
4213 | } | |
4214 | if(($cgiparams{'CCD_DNS1'} eq '') && ($cgiparams{'CCD_DNS1'} ne '')){ $cgiparams{'CCD_DNS1'} = $cgiparams{'CCD_DNS2'};$cgiparams{'CCD_DNS2'}='';} | |
4215 | if($cgiparams{'CCD_DNS1'} ne ''){ | |
82c809c7 | 4216 | print CCDRWCONF "\n#Client gets these nameservers\n"; |
8c877a82 AM |
4217 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS1'}\" \n"; |
4218 | } | |
4219 | if($cgiparams{'CCD_DNS2'} ne ''){ | |
4220 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS2'}\" \n"; | |
4221 | } | |
4222 | if($cgiparams{'CCD_WINS'} ne ''){ | |
4223 | print CCDRWCONF "\n#Client gets this WINS server\n"; | |
4224 | print CCDRWCONF "push \"dhcp-option WINS $cgiparams{'CCD_WINS'}\" \n"; | |
4225 | } | |
4226 | close CCDRWCONF; | |
4227 | } | |
18837a6a AH |
4228 | |
4229 | ### | |
4230 | # m.a.d n2n begin | |
4231 | ### | |
4232 | ||
4233 | if ($cgiparams{'TYPE'} eq 'net') { | |
4234 | ||
4235 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
4236 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4237 | ||
4238 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4239 | my $key = $cgiparams{'KEY'}; | |
4240 | if (! $key) { | |
4241 | $key = &General::findhasharraykey (\%confighash); | |
4242 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
4243 | } | |
4244 | $confighash{$key}[0] = 'on'; | |
4245 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4246 | ||
4247 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4248 | } | |
4249 | } | |
4250 | ||
4251 | ### | |
4252 | # m.a.d n2n end | |
4253 | ### | |
4254 | ||
c6c9630e MT |
4255 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { |
4256 | $cgiparams{'KEY'} = $key; | |
4257 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
4258 | } | |
4259 | goto VPNCONF_END; | |
6e13d0a5 | 4260 | } else { |
c6c9630e | 4261 | $cgiparams{'ENABLED'} = 'on'; |
54fd0535 MT |
4262 | ### |
4263 | # m.a.d n2n begin | |
4264 | ### | |
4265 | $cgiparams{'MSSFIX'} = 'on'; | |
4266 | $cgiparams{'FRAGMENT'} = '1300'; | |
b228aaf0 | 4267 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; |
49abe7af | 4268 | $cgiparams{'DAUTH'} = 'SHA1'; |
54fd0535 MT |
4269 | ### |
4270 | # m.a.d n2n end | |
4271 | ### | |
4c962356 | 4272 | $cgiparams{'SIDE'} = 'left'; |
c6c9630e MT |
4273 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { |
4274 | $cgiparams{'AUTH'} = 'psk'; | |
4275 | } elsif ( ! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4276 | $cgiparams{'AUTH'} = 'certfile'; | |
4277 | } else { | |
6e13d0a5 | 4278 | $cgiparams{'AUTH'} = 'certgen'; |
c6c9630e MT |
4279 | } |
4280 | $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}"; | |
4281 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
4282 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
4283 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
4284 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
6e13d0a5 | 4285 | } |
c6c9630e | 4286 | |
6e13d0a5 | 4287 | VPNCONF_ERROR: |
6e13d0a5 MT |
4288 | $checked{'ENABLED'}{'off'} = ''; |
4289 | $checked{'ENABLED'}{'on'} = ''; | |
4290 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4291 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4292 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4293 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4294 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4295 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4296 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
4297 | |
4298 | ||
6e13d0a5 MT |
4299 | $checked{'EDIT_ADVANCED'}{'off'} = ''; |
4300 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
4301 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = 'CHECKED'; | |
c6c9630e | 4302 | |
6e13d0a5 MT |
4303 | $selected{'SIDE'}{'server'} = ''; |
4304 | $selected{'SIDE'}{'client'} = ''; | |
4305 | $selected{'SIDE'}{$cgiparams{'SIDE'}} = 'SELECTED'; | |
d96c89eb AH |
4306 | |
4307 | $selected{'PROTOCOL'}{'udp'} = ''; | |
4308 | $selected{'PROTOCOL'}{'tcp'} = ''; | |
4309 | $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED'; | |
4310 | ||
c6c9630e | 4311 | |
6e13d0a5 MT |
4312 | $checked{'AUTH'}{'psk'} = ''; |
4313 | $checked{'AUTH'}{'certreq'} = ''; | |
4314 | $checked{'AUTH'}{'certgen'} = ''; | |
4315 | $checked{'AUTH'}{'certfile'} = ''; | |
4316 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = 'CHECKED'; | |
c6c9630e | 4317 | |
6e13d0a5 | 4318 | $selected{'INTERFACE'}{$cgiparams{'INTERFACE'}} = 'SELECTED'; |
c6c9630e | 4319 | |
6e13d0a5 MT |
4320 | $checked{'COMPLZO'}{'off'} = ''; |
4321 | $checked{'COMPLZO'}{'on'} = ''; | |
4322 | $checked{'COMPLZO'}{$cgiparams{'COMPLZO'}} = 'CHECKED'; | |
c6c9630e | 4323 | |
d96c89eb AH |
4324 | $checked{'MSSFIX'}{'off'} = ''; |
4325 | $checked{'MSSFIX'}{'on'} = ''; | |
4326 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
4327 | ||
92b87e17 SS |
4328 | if ($cgiparams{'PMTU_DISCOVERY'} eq '') { |
4329 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; | |
4330 | } | |
2ee746be SS |
4331 | $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\''; |
4332 | ||
4c962356 EK |
4333 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; |
4334 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
4335 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
4336 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
4337 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
4338 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
4339 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4340 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; | |
4341 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; | |
4342 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
4343 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
4344 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 4345 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
49abe7af EK |
4346 | # If no cipher has been chossen yet, select |
4347 | # the old default (AES-256-CBC) for compatiblity reasons. | |
4348 | if ($cgiparams{'DCIPHER'} eq '') { | |
4349 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; | |
4350 | } | |
4c962356 | 4351 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
49abe7af EK |
4352 | $selected{'DAUTH'}{'whirlpool'} = ''; |
4353 | $selected{'DAUTH'}{'SHA512'} = ''; | |
4354 | $selected{'DAUTH'}{'SHA384'} = ''; | |
4355 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4356 | $selected{'DAUTH'}{'SHA1'} = ''; | |
4357 | # If no hash algorythm has been choosen yet, select | |
4358 | # the old default value (SHA1) for compatiblity reasons. | |
4359 | if ($cgiparams{'DAUTH'} eq '') { | |
4360 | $cgiparams{'DAUTH'} = 'SHA1'; | |
4361 | } | |
4362 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
4363 | ||
6e13d0a5 MT |
4364 | if (1) { |
4365 | &Header::showhttpheaders(); | |
4c962356 | 4366 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
4367 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
4368 | if ($errormessage) { | |
4369 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
4370 | print "<class name='base'>$errormessage"; | |
4371 | print " </class>"; | |
4372 | &Header::closebox(); | |
4373 | } | |
c6c9630e | 4374 | |
6e13d0a5 MT |
4375 | if ($warnmessage) { |
4376 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:"); | |
4377 | print "<class name='base'>$warnmessage"; | |
4378 | print " </class>"; | |
4379 | &Header::closebox(); | |
4380 | } | |
c6c9630e | 4381 | |
6e13d0a5 | 4382 | print "<form method='post' enctype='multipart/form-data'>"; |
ce9abb66 | 4383 | print "<input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />"; |
c6c9630e | 4384 | |
6e13d0a5 MT |
4385 | if ($cgiparams{'KEY'}) { |
4386 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
4387 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
6e13d0a5 | 4388 | } |
c6c9630e | 4389 | |
6e13d0a5 | 4390 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'connection'}:"); |
8c877a82 | 4391 | print "<table width='100%' border='0'>\n"; |
4c962356 | 4392 | |
8c877a82 AM |
4393 | print "<tr><td width='14%' class='boldbase'>$Lang::tr{'name'}: </td>"; |
4394 | ||
ce9abb66 | 4395 | if ($cgiparams{'TYPE'} eq 'host') { |
6e13d0a5 | 4396 | if ($cgiparams{'KEY'}) { |
8c877a82 | 4397 | print "<td width='35%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; |
6e13d0a5 MT |
4398 | } else { |
4399 | print "<td width='35%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' size='30' /></td>"; | |
4400 | } | |
c6c9630e MT |
4401 | # print "<tr><td>$Lang::tr{'interface'}</td>"; |
4402 | # print "<td><select name='INTERFACE'>"; | |
4403 | # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>"; | |
4c962356 EK |
4404 | # if ($netsettings{'BLUE_DEV'} ne '') { |
4405 | # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>"; | |
4406 | # } | |
4407 | # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>"; | |
4408 | # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>"; | |
4409 | # print "</select></td></tr>"; | |
4410 | # print <<END; | |
ce9abb66 AH |
4411 | } else { |
4412 | print "<input type='hidden' name='INTERFACE' value='red' />"; | |
4413 | if ($cgiparams{'KEY'}) { | |
4414 | print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
4415 | } else { | |
4416 | print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' /></td>"; | |
4417 | } | |
4c962356 | 4418 | print <<END; |
ce9abb66 | 4419 | <td width='25%'> </td> |
f527e53f EK |
4420 | <td width='25%'> </td></tr> |
4421 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td> | |
4422 | <td><select name='SIDE'> | |
4423 | <option value='server' $selected{'SIDE'}{'server'}>$Lang::tr{'openvpn server'}</option> | |
4424 | <option value='client' $selected{'SIDE'}{'client'}>$Lang::tr{'openvpn client'}</option> | |
4425 | </select> | |
4426 | </td> | |
4c962356 | 4427 | |
f527e53f EK |
4428 | <td class='boldbase'>$Lang::tr{'remote host/ip'}:</td> |
4429 | <td><input type='TEXT' name='REMOTE' value='$cgiparams{'REMOTE'}' /></td> | |
4430 | </tr> | |
4c962356 | 4431 | |
f527e53f EK |
4432 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td> |
4433 | <td><input type='TEXT' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' /></td> | |
4c962356 | 4434 | |
f527e53f EK |
4435 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td> |
4436 | <td><input type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' /></td> | |
4437 | </tr> | |
4c962356 | 4438 | |
f527e53f EK |
4439 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td> |
4440 | <td><input type='TEXT' name='OVPN_SUBNET' value='$cgiparams{'OVPN_SUBNET'}' /></td> | |
49abe7af | 4441 | |
f527e53f EK |
4442 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
4443 | <td><select name='PROTOCOL'> | |
4444 | <option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option> | |
4445 | <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option></select></td> | |
4446 | </tr> | |
4447 | ||
4448 | <tr> | |
4449 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
4450 | <td><input type='TEXT' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td> | |
4c962356 | 4451 | |
f527e53f EK |
4452 | <td class='boldbase' nowrap='nowrap'>Management Port ($Lang::tr{'openvpn default'}: <span class="base">$Lang::tr{'destination port'}): <img src='/blob.gif' /></td> |
4453 | <td> <input type='TEXT' name='OVPN_MGMT' VALUE='$cgiparams{'OVPN_MGMT'}'size='5' /></td> | |
4454 | </tr> | |
49abe7af | 4455 | |
f527e53f EK |
4456 | <tr><td colspan=4><hr /></td></tr><tr> |
4457 | ||
4458 | <tr> | |
4459 | <td class'base'><b>$Lang::tr{'MTU settings'}</b></td> | |
4460 | </tr> | |
49abe7af | 4461 | |
f527e53f EK |
4462 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} <img src='/blob.gif' /></td> |
4463 | <td><input type='TEXT' name='MTU' VALUE='$cgiparams{'MTU'}'size='5' /></td> | |
4464 | <td colspan='2'>$Lang::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td> | |
4465 | </tr> | |
4c962356 | 4466 | |
f527e53f EK |
4467 | <tr><td class='boldbase' nowrap='nowrap'>fragment <img src='/blob.gif' /></td> |
4468 | <td><input type='TEXT' name='FRAGMENT' VALUE='$cgiparams{'FRAGMENT'}'size='5' /></td> | |
4469 | <td>$Lang::tr{'openvpn default'}: <span class="base">1300</span></td> | |
4470 | </tr> | |
4c962356 | 4471 | |
f527e53f EK |
4472 | <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td> |
4473 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
4474 | <td>$Lang::tr{'openvpn default'}: <span class="base">on</span></td> | |
4475 | </tr> | |
4c962356 | 4476 | |
f527e53f EK |
4477 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'} <img src='/blob.gif'</td> |
4478 | <td><input type='checkbox' name='COMPLZO' $checked{'COMPLZO'}{'on'} /></td> | |
4479 | </tr> | |
2ee746be | 4480 | |
49abe7af | 4481 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td> |
4cdf8b92 | 4482 | <td colspan='3'> |
2ee746be SS |
4483 | <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'} |
4484 | <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'} | |
4485 | <input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'} | |
4486 | <input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'} | |
4487 | </td> | |
4488 | </tr> | |
f527e53f EK |
4489 | |
4490 | <tr><td colspan=4><hr /></td></tr><tr> | |
4491 | <tr> | |
4492 | <td class'base'><b>$Lang::tr{'ovpn crypt options'}:</b></td> | |
4493 | </tr> | |
4494 | ||
4495 | <tr><td class='boldbase'>$Lang::tr{'cipher'}</td> | |
4496 | <td><select name='DCIPHER'> | |
4497 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> | |
4498 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> | |
4499 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> | |
f7fb5bc5 | 4500 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'}, $Lang::tr{'default'})</option> |
f527e53f EK |
4501 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> |
4502 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
4503 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'})</option> | |
4504 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'})</option> | |
4505 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> | |
4506 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'})</option> | |
4507 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'})</option> | |
4508 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'})</option> | |
f527e53f EK |
4509 | </select> |
4510 | </td> | |
4511 | ||
4512 | <td class='boldbase'>$Lang::tr{'ovpn ha'}:</td> | |
4513 | <td><select name='DAUTH'> | |
4514 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> | |
4515 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
4516 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
4517 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
4518 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'} Default)</option> | |
4519 | </select> | |
4520 | </td> | |
4521 | </tr> | |
4522 | <tr><td colspan=4><hr /></td></tr><tr> | |
4523 | ||
ce9abb66 | 4524 | END |
8c877a82 | 4525 | ; |
ce9abb66 | 4526 | } |
2ee746be | 4527 | #jumper |
6e13d0a5 | 4528 | print "<tr><td class='boldbase'>$Lang::tr{'remark title'} <img src='/blob.gif' /></td>"; |
8c877a82 | 4529 | print "<td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td></tr></table>"; |
c6c9630e | 4530 | |
ce9abb66 | 4531 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
4532 | print "<tr><td>$Lang::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>"; |
4533 | } | |
ce9abb66 | 4534 | |
8c877a82 AM |
4535 | print"</tr></table><br><br>"; |
4536 | #A.Marx CCD new client | |
e81be1e1 | 4537 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 | 4538 | print "<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td colspan='3'><hr><br><b>$Lang::tr{'ccd choose net'}</td></tr><tr><td height='20' colspan='3'></td></tr>"; |
8c877a82 AM |
4539 | my %vpnnet=(); |
4540 | my $vpnip; | |
4541 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnnet); | |
4542 | $vpnip=$vpnnet{'DOVPN_SUBNET'}; | |
4543 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
4544 | my @ccdconf=(); | |
4545 | my $count=0; | |
4546 | my $checked; | |
4547 | $checked{'check1'}{'off'} = ''; | |
4548 | $checked{'check1'}{'on'} = ''; | |
4549 | $checked{'check1'}{$cgiparams{'CHECK1'}} = 'CHECKED'; | |
4550 | print"<tr><td align='center' width='1%' valign='top'><input type='radio' name='CHECK1' value='dynamic' checked /></td><td align='left' valign='top' width='35%'>$Lang::tr{'ccd dynrange'} ($vpnip)</td><td width='30%'>"; | |
4551 | print"</td></tr></table><br><br>"; | |
4552 | my $name=$cgiparams{'CHECK1'}; | |
4553 | $checked{'RG'}{$cgiparams{'RG'}} = 'CHECKED'; | |
4554 | ||
4555 | if (! -z "${General::swroot}/ovpn/ccd.conf"){ | |
4556 | print"<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td width='1%'></td><td width='30%' class='boldbase' align='center'><b>$Lang::tr{'ccd name'}</td><td width='15%' class='boldbase' align='center'><b>$Lang::tr{'network'}</td><td class='boldbase' align='center' width='18%'><b>$Lang::tr{'ccd clientip'}</td></tr>"; | |
df9b48b7 | 4557 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
4558 | $count++; |
4559 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); | |
4560 | if ($count % 2){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";} | |
4561 | print"<td align='center' width='1%'><input type='radio' name='CHECK1' value='$ccdconf[0]' $checked{'check1'}{$ccdconf[0]}/></td><td>$ccdconf[0]</td><td width='40%' align='center'>$ccdconf[1]</td><td align='left' width='10%'>"; | |
4562 | &fillselectbox($ccdconf[1],$ccdconf[0],$cgiparams{$name}); | |
4563 | print"</td></tr>"; | |
4564 | } | |
4565 | print "</table><br><br><hr><br><br>"; | |
4566 | } | |
e81be1e1 | 4567 | } |
8c877a82 | 4568 | # ccd end |
6e13d0a5 MT |
4569 | &Header::closebox(); |
4570 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { | |
8c877a82 AM |
4571 | |
4572 | } elsif (! $cgiparams{'KEY'}) { | |
4573 | ||
4574 | ||
6e13d0a5 MT |
4575 | my $disabled=''; |
4576 | my $cakeydisabled=''; | |
4577 | my $cacrtdisabled=''; | |
4578 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" }; | |
4579 | if ( ! -f "${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" }; | |
8c877a82 | 4580 | |
6e13d0a5 | 4581 | &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); |
ce9abb66 AH |
4582 | |
4583 | ||
4584 | if ($cgiparams{'TYPE'} eq 'host') { | |
4585 | ||
49abe7af | 4586 | print <<END; |
6e13d0a5 | 4587 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
54fd0535 | 4588 | |
ce9abb66 AH |
4589 | <tr><td><input type='radio' name='AUTH' value='certreq' $checked{'AUTH'}{'certreq'} $cakeydisabled /></td><td class='base'>$Lang::tr{'upload a certificate request'}</td><td class='base' rowspan='2'><input type='file' name='FH' size='30' $cacrtdisabled></td></tr> |
4590 | <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'>$Lang::tr{'upload a certificate'}</td></tr> | |
54fd0535 MT |
4591 | <tr><td colspan='3'> </td></tr> |
4592 | <tr><td colspan='3'><hr /></td></tr> | |
4593 | <tr><td colspan='3'> </td></tr> | |
ce9abb66 AH |
4594 | <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'>$Lang::tr{'generate a certificate'}</td><td> </td></tr> |
4595 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> | |
4596 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
4597 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
4598 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
4599 | <tr><td> </td><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
4600 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
4601 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
6e13d0a5 | 4602 | END |
ce9abb66 AH |
4603 | ; |
4604 | ||
4605 | ### | |
7c1d9faf | 4606 | # m.a.d net2net |
ce9abb66 AH |
4607 | ### |
4608 | ||
4609 | } else { | |
4610 | ||
49abe7af | 4611 | print <<END; |
ce9abb66 AH |
4612 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
4613 | ||
4614 | <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'>$Lang::tr{'generate a certificate'}</td><td> </td></tr> | |
4615 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> | |
4616 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
4617 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
4618 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
4619 | <tr><td> </td><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
4620 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
4621 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
54fd0535 MT |
4622 | |
4623 | ||
ce9abb66 AH |
4624 | END |
4625 | ; | |
4626 | ||
4627 | } | |
4628 | ||
4629 | ### | |
7c1d9faf | 4630 | # m.a.d net2net |
ce9abb66 | 4631 | ### |
c6c9630e | 4632 | |
6e13d0a5 MT |
4633 | foreach my $country (sort keys %{Countries::countries}) { |
4634 | print "<option value='$Countries::countries{$country}'"; | |
4635 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
4636 | print " selected='selected'"; | |
4637 | } | |
4638 | print ">$country</option>"; | |
4639 | } | |
ce9abb66 | 4640 | ### |
7c1d9faf | 4641 | # m.a.d net2net |
ce9abb66 AH |
4642 | ### |
4643 | ||
4644 | if ($cgiparams{'TYPE'} eq 'host') { | |
49abe7af | 4645 | print <<END; |
6e13d0a5 | 4646 | </select></td></tr> |
ce9abb66 | 4647 | |
54fd0535 | 4648 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days):</td> |
ce9abb66 AH |
4649 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> |
4650 | <tr><td> </td> | |
6e13d0a5 MT |
4651 | <td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
4652 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
bc2b3e94 | 4653 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'}:<br>($Lang::tr{'confirmation'})</td> |
6e13d0a5 | 4654 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> |
54fd0535 MT |
4655 | <tr><td colspan='3'> </td></tr> |
4656 | <tr><td colspan='3'><hr /></td></tr> | |
4657 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
ce9abb66 AH |
4658 | </table> |
4659 | END | |
4660 | }else{ | |
49abe7af | 4661 | print <<END; |
ce9abb66 AH |
4662 | </select></td></tr> |
4663 | <tr><td> </td><td> </td><td> </td></tr> | |
4664 | <tr><td> </td><td> </td><td> </td></tr> | |
54fd0535 MT |
4665 | <tr><td colspan='3'><hr /></td></tr> |
4666 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
ce9abb66 AH |
4667 | </table> |
4668 | ||
c6c9630e | 4669 | END |
ce9abb66 AH |
4670 | } |
4671 | ||
4672 | ### | |
7c1d9faf | 4673 | # m.a.d net2net |
ce9abb66 | 4674 | ### |
c6c9630e MT |
4675 | ; |
4676 | &Header::closebox(); | |
8c877a82 AM |
4677 | |
4678 | } | |
e81be1e1 AM |
4679 | |
4680 | #A.Marx CCD new client | |
4681 | if ($cgiparams{'TYPE'} eq 'host') { | |
8c877a82 AM |
4682 | print"<br><br>"; |
4683 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ccd client options'}:"); | |
4684 | ||
8c877a82 AM |
4685 | |
4686 | print <<END; | |
4687 | <table border='0' width='100%'> | |
4688 | <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked{'RG'}{'on'} /></td></tr> | |
4689 | <tr><td colspan='4'><b><br>$Lang::tr{'ccd routes'}</b></td></tr> | |
4690 | <tr><td colspan='4'> </td></tr> | |
4691 | <tr><td valign='top'>$Lang::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'> | |
4692 | END | |
4693 | ||
4694 | if ($cgiparams{'IR'} ne ''){ | |
4695 | print $cgiparams{'IR'}; | |
4696 | }else{ | |
4697 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
4698 | foreach my $key (keys %ccdroutehash) { | |
4699 | if( $cgiparams{'NAME'} eq $ccdroutehash{$key}[0]){ | |
4700 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
4701 | if ($ccdroutehash{$key}[$i] ne ''){ | |
4702 | print $ccdroutehash{$key}[$i]."\n"; | |
4703 | } | |
4704 | $cgiparams{'IR'} .= $ccdroutehash{$key}[$i]; | |
4705 | } | |
4706 | } | |
4707 | } | |
c6c9630e | 4708 | } |
8c877a82 AM |
4709 | |
4710 | print <<END; | |
4711 | </textarea></td><td valign='top' colspan='2'>$Lang::tr{'ccd iroutehint'}</td></tr> | |
4712 | <tr><td colspan='4'><br></td></tr> | |
4713 | <tr><td valign='top' rowspan='3'>$Lang::tr{'ccd iroute2'}</td><td align='left' valign='top' rowspan='3'><select name='IFROUTE' style="width: 205px"; size='6' multiple> | |
4714 | END | |
52d08bcb AM |
4715 | |
4716 | my $set=0; | |
4717 | my $selorange=0; | |
4718 | my $selblue=0; | |
4719 | my $selgreen=0; | |
4720 | my $helpblue=0; | |
4721 | my $helporange=0; | |
4722 | my $other=0; | |
df9b48b7 | 4723 | my $none=0; |
52d08bcb AM |
4724 | my @temp=(); |
4725 | ||
8c877a82 | 4726 | our @current = (); |
52d08bcb AM |
4727 | open(FILE, "${General::swroot}/main/routing") ; |
4728 | @current = <FILE>; | |
4729 | close (FILE); | |
4730 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
df9b48b7 AM |
4731 | #check for "none" |
4732 | foreach my $key (keys %ccdroute2hash) { | |
4733 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4734 | if ($ccdroute2hash{$key}[1] eq ''){ | |
4735 | $none=1; | |
4736 | last; | |
4737 | } | |
4738 | } | |
4739 | } | |
4740 | if ($none ne '1'){ | |
4741 | print"<option>$Lang::tr{'ccd none'}</option>"; | |
4742 | }else{ | |
4743 | print"<option selected>$Lang::tr{'ccd none'}</option>"; | |
4744 | } | |
52d08bcb AM |
4745 | #check if static routes are defined for client |
4746 | foreach my $line (@current) { | |
4747 | chomp($line); | |
4748 | $line=~s/\s*$//g; # remove newline | |
4749 | @temp=split(/\,/,$line); | |
4750 | $temp[1] = '' unless defined $temp[1]; # not always populated | |
4751 | my ($a,$b) = split(/\//,$temp[1]); | |
4752 | $temp[1] = $a."/".&General::iporsubtocidr($b); | |
4753 | foreach my $key (keys %ccdroute2hash) { | |
4754 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4755 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4756 | if($ccdroute2hash{$key}[$i] eq $a."/".&General::iporsubtodec($b)){ | |
4757 | $set=1; | |
8c877a82 AM |
4758 | } |
4759 | } | |
8c877a82 | 4760 | } |
52d08bcb AM |
4761 | } |
4762 | if ($set == '1' && $#temp != -1){ print"<option selected>$temp[1]</option>";$set=0;}elsif($set == '0' && $#temp != -1){print"<option>$temp[1]</option>";} | |
4763 | } | |
4764 | #check if green,blue,orange are defined for client | |
4765 | foreach my $key (keys %ccdroute2hash) { | |
4766 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4767 | $other=1; | |
4768 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4769 | if ($ccdroute2hash{$key}[$i] eq $netsettings{'GREEN_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'GREEN_NETMASK'})){ | |
4770 | $selgreen=1; | |
4771 | } | |
4772 | if (&haveBlueNet()){ | |
4773 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'BLUE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'BLUE_NETMASK'})) { | |
4774 | $selblue=1; | |
4775 | } | |
4776 | } | |
4777 | if (&haveOrangeNet()){ | |
4778 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'ORANGE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'ORANGE_NETMASK'}) ) { | |
4779 | $selorange=1; | |
4780 | } | |
4781 | } | |
4782 | } | |
4783 | } | |
4784 | } | |
4785 | if (&haveBlueNet() && $selblue == '1'){ print"<option selected>$Lang::tr{'blue'}</option>";$selblue=0;}elsif(&haveBlueNet() && $selblue == '0'){print"<option>$Lang::tr{'blue'}</option>";} | |
4786 | if (&haveOrangeNet() && $selorange == '1'){ print"<option selected>$Lang::tr{'orange'}</option>";$selorange=0;}elsif(&haveOrangeNet() && $selorange == '0'){print"<option>$Lang::tr{'orange'}</option>";} | |
4787 | if ($selgreen == '1' || $other == '0'){ print"<option selected>$Lang::tr{'green'}</option>";$set=0;}else{print"<option>$Lang::tr{'green'}</option>";}; | |
4788 | ||
49abe7af | 4789 | print<<END; |
8c877a82 AM |
4790 | </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value='$cgiparams{'CCD_DNS1'}' size='30' /></td></tr> |
4791 | <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value='$cgiparams{'CCD_DNS2'}' size='30' /></td></tr> | |
4792 | <tr valign='top'><td valign='top'>WINS:</td><td><input type='TEXT' name='CCD_WINS' value='$cgiparams{'CCD_WINS'}' size='30' /></td></tr></table><br><hr> | |
4793 | ||
4794 | END | |
4795 | ; | |
4796 | &Header::closebox(); | |
e81be1e1 | 4797 | } |
c6c9630e MT |
4798 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
4799 | if ($cgiparams{'KEY'}) { | |
4800 | # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
4801 | } | |
4802 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
4803 | &Header::closebigbox(); | |
4804 | &Header::closepage(); | |
4805 | exit (0); | |
6e13d0a5 | 4806 | } |
c6c9630e | 4807 | VPNCONF_END: |
6e13d0a5 | 4808 | } |
c6c9630e MT |
4809 | |
4810 | # SETTINGS_ERROR: | |
6e13d0a5 MT |
4811 | ### |
4812 | ### Default status page | |
4813 | ### | |
c6c9630e MT |
4814 | %cgiparams = (); |
4815 | %cahash = (); | |
4816 | %confighash = (); | |
4817 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
4818 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
4819 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4820 | ||
4e17adad | 4821 | my @status = `/bin/cat /var/log/ovpnserver.log`; |
c6c9630e MT |
4822 | |
4823 | if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") { | |
8c877a82 AM |
4824 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { |
4825 | my $ipaddr = <IPADDR>; | |
4826 | close IPADDR; | |
4827 | chomp ($ipaddr); | |
4828 | $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
4829 | if ($cgiparams{'VPN_IP'} eq '') { | |
4830 | $cgiparams{'VPN_IP'} = $ipaddr; | |
4831 | } | |
4832 | } | |
c6c9630e MT |
4833 | } |
4834 | ||
6e13d0a5 | 4835 | #default setzen |
c6c9630e | 4836 | if ($cgiparams{'DCIPHER'} eq '') { |
4c962356 | 4837 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; |
c6c9630e | 4838 | } |
c6c9630e | 4839 | if ($cgiparams{'DDEST_PORT'} eq '') { |
4c962356 | 4840 | $cgiparams{'DDEST_PORT'} = '1194'; |
c6c9630e MT |
4841 | } |
4842 | if ($cgiparams{'DMTU'} eq '') { | |
4c962356 EK |
4843 | $cgiparams{'DMTU'} = '1400'; |
4844 | } | |
4845 | if ($cgiparams{'MSSFIX'} eq '') { | |
4846 | $cgiparams{'MSSFIX'} = 'off'; | |
4847 | } | |
4848 | if ($cgiparams{'DAUTH'} eq '') { | |
4849 | $cgiparams{'DAUTH'} = 'SHA1'; | |
c6c9630e MT |
4850 | } |
4851 | if ($cgiparams{'DOVPN_SUBNET'} eq '') { | |
4c962356 | 4852 | $cgiparams{'DOVPN_SUBNET'} = '10.' . int(rand(256)) . '.' . int(rand(256)) . '.0/255.255.255.0'; |
c6c9630e | 4853 | } |
4c962356 | 4854 | $checked{'ENABLED'}{'off'} = ''; |
c6c9630e MT |
4855 | $checked{'ENABLED'}{'on'} = ''; |
4856 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4857 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4858 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4859 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4860 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4861 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4862 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
4863 | $selected{'DDEVICE'}{'tun'} = ''; |
4864 | $selected{'DDEVICE'}{'tap'} = ''; | |
4865 | $selected{'DDEVICE'}{$cgiparams{'DDEVICE'}} = 'SELECTED'; | |
4866 | ||
4867 | $selected{'DPROTOCOL'}{'udp'} = ''; | |
4868 | $selected{'DPROTOCOL'}{'tcp'} = ''; | |
4869 | $selected{'DPROTOCOL'}{$cgiparams{'DPROTOCOL'}} = 'SELECTED'; | |
4c962356 EK |
4870 | |
4871 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; | |
4872 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
4873 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
4874 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
4875 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
4876 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
c6c9630e MT |
4877 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; |
4878 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4c962356 EK |
4879 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; |
4880 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
4881 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
4882 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 4883 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
c6c9630e | 4884 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
4c962356 EK |
4885 | |
4886 | $selected{'DAUTH'}{'whirlpool'} = ''; | |
4887 | $selected{'DAUTH'}{'SHA512'} = ''; | |
4888 | $selected{'DAUTH'}{'SHA384'} = ''; | |
4889 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
4890 | $selected{'DAUTH'}{'SHA1'} = ''; |
4891 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
4892 | ||
c6c9630e MT |
4893 | $checked{'DCOMPLZO'}{'off'} = ''; |
4894 | $checked{'DCOMPLZO'}{'on'} = ''; | |
4895 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
4c962356 | 4896 | |
d96c89eb AH |
4897 | # m.a.d |
4898 | $checked{'MSSFIX'}{'off'} = ''; | |
4899 | $checked{'MSSFIX'}{'on'} = ''; | |
4900 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 | 4901 | #new settings |
c6c9630e MT |
4902 | &Header::showhttpheaders(); |
4903 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
4904 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
6e13d0a5 | 4905 | |
c6c9630e | 4906 | if ($errormessage) { |
6e13d0a5 MT |
4907 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
4908 | print "<class name='base'>$errormessage\n"; | |
4909 | print " </class>\n"; | |
4910 | &Header::closebox(); | |
c6c9630e | 4911 | } |
6e13d0a5 | 4912 | |
b2e75449 MT |
4913 | if ($warnmessage) { |
4914 | &Header::openbox('100%', 'LEFT', $Lang::tr{'warning messages'}); | |
4915 | print "$warnmessage<br>"; | |
4916 | print "$Lang::tr{'fwdfw warn1'}<br>"; | |
4917 | &Header::closebox(); | |
4918 | print"<center><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'ok'}' style='width: 5em;'></form>"; | |
4919 | &Header::closepage(); | |
4920 | exit 0; | |
4921 | } | |
4d81e0f3 | 4922 | |
c6c9630e MT |
4923 | my $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'stopped'}</font></b></td></tr></table>"; |
4924 | my $srunning = "no"; | |
4925 | my $activeonrun = ""; | |
4926 | if ( -e "/var/run/openvpn.pid"){ | |
6e13d0a5 MT |
4927 | $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'running'}</font></b></td></tr></table>"; |
4928 | $srunning ="yes"; | |
4929 | $activeonrun = ""; | |
c6c9630e | 4930 | } else { |
6e13d0a5 | 4931 | $activeonrun = "disabled='disabled'"; |
c6c9630e | 4932 | } |
afabe9f7 | 4933 | &Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'}); |
4c962356 | 4934 | print <<END; |
631b67b7 | 4935 | <table width='100%' border='0'> |
c6c9630e MT |
4936 | <form method='post'> |
4937 | <td width='25%'> </td> | |
4938 | <td width='25%'> </td> | |
4939 | <td width='25%'> </td></tr> | |
4940 | <tr><td class='boldbase'>$Lang::tr{'ovpn server status'}</td> | |
4941 | <td align='left'>$sactive</td> | |
4942 | <tr><td class='boldbase'>$Lang::tr{'ovpn on red'}</td> | |
8c877a82 | 4943 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> |
c6c9630e MT |
4944 | END |
4945 | ; | |
4946 | if (&haveBlueNet()) { | |
4947 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on blue'}</td>"; | |
4948 | print "<td><input type='checkbox' name='ENABLED_BLUE' $checked{'ENABLED_BLUE'}{'on'} /></td>"; | |
4949 | } | |
4950 | if (&haveOrangeNet()) { | |
4951 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on orange'}</td>"; | |
4952 | print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked{'ENABLED_ORANGE'}{'on'} /></td>"; | |
4953 | } | |
4c962356 | 4954 | print <<END; |
4e17adad CS |
4955 | <tr><td class='base' nowrap='nowrap' colspan='2'>$Lang::tr{'local vpn hostname/ip'}:<br /><input type='text' name='VPN_IP' value='$cgiparams{'VPN_IP'}' size='30' /></td> |
4956 | <td class='boldbase' nowrap='nowrap' colspan='2'>$Lang::tr{'ovpn subnet'}<br /><input type='TEXT' name='DOVPN_SUBNET' value='$cgiparams{'DOVPN_SUBNET'}' size='30' /></td></tr> | |
c6c9630e MT |
4957 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn device'}</td> |
4958 | <td><select name='DDEVICE' ><option value='tun' $selected{'DDEVICE'}{'tun'}>TUN</option> | |
ee79343e JPT |
4959 | <!-- this is still not working |
4960 | <option value='tap' $selected{'DDEVICE'}{'tap'}>TAP</option></select>--> </td> | |
c6c9630e MT |
4961 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
4962 | <td><select name='DPROTOCOL'><option value='udp' $selected{'DPROTOCOL'}{'udp'}>UDP</option> | |
4963 | <option value='tcp' $selected{'DPROTOCOL'}{'tcp'}>TCP</option></select></td> | |
4964 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
4965 | <td><input type='TEXT' name='DDEST_PORT' value='$cgiparams{'DDEST_PORT'}' size='5' /></td></tr> | |
4966 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} </td> | |
bc2b3e94 | 4967 | <td> <input type='TEXT' name='DMTU' VALUE='$cgiparams{'DMTU'}' size='5' /></td> |
f527e53f | 4968 | |
4c962356 EK |
4969 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td> |
4970 | <td><select name='DCIPHER'> | |
4971 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> | |
f527e53f | 4972 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> |
4c962356 EK |
4973 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> |
4974 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'})</option> | |
4975 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> | |
4976 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
4977 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'})</option> | |
4978 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'})</option> | |
4979 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> | |
4980 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'})</option> | |
4981 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'})</option> | |
4982 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'})</option> | |
4c962356 EK |
4983 | </select> |
4984 | </td> | |
c6c9630e MT |
4985 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
4986 | <td><input type='checkbox' name='DCOMPLZO' $checked{'DCOMPLZO'}{'on'} /></td> | |
4c962356 | 4987 | </tr> |
f7edf97a | 4988 | <tr><td colspan='4'><br><br></td></tr> |
c6c9630e MT |
4989 | END |
4990 | ; | |
4991 | ||
4992 | if ( $srunning eq "yes" ) { | |
8c877a82 AM |
4993 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' disabled='disabled' />"; |
4994 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
4995 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
4996 | print "<input type='submit' name='ACTION' value='$Lang::tr{'stop ovpn server'}' /></td></tr>"; | |
c6c9630e | 4997 | } else{ |
8c877a82 AM |
4998 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
4999 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5000 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
c6c9630e MT |
5001 | if (( -e "${General::swroot}/ovpn/ca/cacert.pem" && |
5002 | -e "${General::swroot}/ovpn/ca/dh1024.pem" && | |
5003 | -e "${General::swroot}/ovpn/certs/servercert.pem" && | |
5004 | -e "${General::swroot}/ovpn/certs/serverkey.pem") && | |
5005 | (( $cgiparams{'ENABLED'} eq 'on') || | |
5006 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
5007 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on'))){ | |
8c877a82 | 5008 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' /></td></tr>"; |
c6c9630e | 5009 | } else { |
8c877a82 | 5010 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' disabled='disabled' /></td></tr>"; |
c6c9630e MT |
5011 | } |
5012 | } | |
5013 | print "</form></table>"; | |
5014 | &Header::closebox(); | |
6e13d0a5 | 5015 | |
c6c9630e | 5016 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { |
ce9abb66 | 5017 | ### |
7c1d9faf | 5018 | # m.a.d net2net |
54fd0535 | 5019 | #<td width='25%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b><br /><img src='/images/null.gif' width='125' height='1' border='0' alt='L2089' /></td> |
ce9abb66 AH |
5020 | ### |
5021 | ||
4c962356 | 5022 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection status and controlc' }); |
c6c9630e | 5023 | ; |
99bfa85c AM |
5024 | my $id = 0; |
5025 | my $gif; | |
f7edf97a | 5026 | my $col1=""; |
5b942f7f | 5027 | my $lastnet; |
c8b51e28 | 5028 | foreach my $key (sort { ncmp ($confighash{$a}[32],$confighash{$b}[32]) } sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) { |
5b942f7f AM |
5029 | if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'net' ){$confighash{$key}[32]=$Lang::tr{'fwhost OpenVPN N-2-N'};} |
5030 | if ($confighash{$key}[32] eq "dynamic"){$confighash{$key}[32]=$Lang::tr{'ccd dynrange'};} | |
5031 | if($id == 0){ | |
5032 | print"<b>$confighash{$key}[32]</b>"; | |
5033 | print <<END; | |
5034 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5035 | <tr> | |
5036 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5037 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5038 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5039 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
5040 | <th width='5%' class='boldbase' colspan='6' align='center'><b>$Lang::tr{'action'}</b></th> | |
5041 | </tr> | |
5042 | END | |
5043 | } | |
5044 | if ($id > 0 && $lastnet ne $confighash{$key}[32]){ | |
5045 | print "</table><br>"; | |
5046 | print"<b>$confighash{$key}[32]</b>"; | |
5047 | print <<END; | |
5048 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5049 | <tr> | |
5050 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5051 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5052 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5053 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
5054 | <th width='5%' class='boldbase' colspan='6' align='center'><b>$Lang::tr{'action'}</b></th> | |
5055 | </tr> | |
5056 | END | |
5057 | } | |
eff2dbf8 | 5058 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } |
c6c9630e | 5059 | if ($id % 2) { |
99bfa85c AM |
5060 | print "<tr>"; |
5061 | $col="bgcolor='$color{'color20'}'"; | |
bb89e92a | 5062 | } else { |
99bfa85c AM |
5063 | print "<tr>"; |
5064 | $col="bgcolor='$color{'color22'}'"; | |
c6c9630e | 5065 | } |
99bfa85c AM |
5066 | print "<td align='center' nowrap='nowrap' $col>$confighash{$key}[1]</td>"; |
5067 | print "<td align='center' nowrap='nowrap' $col>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>"; | |
8c877a82 AM |
5068 | #if ($confighash{$key}[4] eq 'cert') { |
5069 | #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>"; | |
5070 | #} else { | |
5071 | #print "<td align='left'> </td>"; | |
5072 | #} | |
c6c9630e MT |
5073 | my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; |
5074 | $cavalid =~ /Not After : (.*)[\n]/; | |
5075 | $cavalid = $1; | |
99bfa85c | 5076 | print "<td align='center' $col>$confighash{$key}[25]</td>"; |
f7edf97a AM |
5077 | $col1="bgcolor='${Header::colourred}'"; |
5078 | my $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
ce9abb66 | 5079 | |
c6c9630e | 5080 | if ($confighash{$key}[0] eq 'off') { |
f7edf97a AM |
5081 | $col1="bgcolor='${Header::colourblue}'"; |
5082 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
c6c9630e | 5083 | } else { |
ce9abb66 AH |
5084 | |
5085 | ### | |
7c1d9faf | 5086 | # m.a.d net2net |
f7edf97a AM |
5087 | ### |
5088 | ||
b278daf3 | 5089 | if ($confighash{$key}[3] eq 'net') { |
54fd0535 MT |
5090 | |
5091 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
5092 | my @output = ""; | |
5093 | my @tustate = ""; | |
5094 | my $tport = $confighash{$key}[22]; | |
5095 | my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); | |
5096 | if ($tport ne '') { | |
5097 | $tnet->open('127.0.0.1'); | |
5098 | @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); | |
5099 | @tustate = split(/\,/, $output[1]); | |
5100 | ### | |
5101 | #CONNECTING -- OpenVPN's initial state. | |
5102 | #WAIT -- (Client only) Waiting for initial response from server. | |
5103 | #AUTH -- (Client only) Authenticating with server. | |
5104 | #GET_CONFIG -- (Client only) Downloading configuration options from server. | |
5105 | #ASSIGN_IP -- Assigning IP address to virtual network interface. | |
5106 | #ADD_ROUTES -- Adding routes to system. | |
5107 | #CONNECTED -- Initialization Sequence Completed. | |
5108 | #RECONNECTING -- A restart has occurred. | |
5109 | #EXITING -- A graceful exit is in progress. | |
5110 | #### | |
5111 | ||
ed4b4c19 | 5112 | if (($tustate[1] eq 'CONNECTED') || ($tustate[1] eq 'WAIT')) { |
f7edf97a AM |
5113 | $col1="bgcolor='${Header::colourgreen}'"; |
5114 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5115 | }else { | |
5116 | $col1="bgcolor='${Header::colourred}'"; | |
5117 | $active = "<b><font color='#FFFFFF'>$tustate[1]</font></b>"; | |
5118 | } | |
54fd0535 | 5119 | } |
54fd0535 | 5120 | } |
f7edf97a AM |
5121 | }else { |
5122 | ||
5123 | my $cn; | |
5124 | my @match = (); | |
5125 | foreach my $line (@status) { | |
5126 | chomp($line); | |
5127 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
5128 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
5129 | if ($match[1] ne "Common Name") { | |
5130 | $cn = $match[1]; | |
5131 | } | |
5132 | $cn =~ s/[_]/ /g; | |
5133 | if ($cn eq "$confighash{$key}[2]") { | |
5134 | $col1="bgcolor='${Header::colourgreen}'"; | |
5135 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5136 | } | |
5137 | } | |
5138 | } | |
c6c9630e | 5139 | } |
7c1d9faf | 5140 | } |
ce9abb66 AH |
5141 | |
5142 | ||
4c962356 | 5143 | print <<END; |
f7edf97a | 5144 | <td align='center' $col1>$active</td> |
c6c9630e | 5145 | |
99bfa85c | 5146 | <form method='post' name='frm${key}a'><td align='center' $col> |
96096995 AM |
5147 | <input type='image' name='$Lang::tr{'dl client arch'}' src='/images/openvpn.png' alt='$Lang::tr{'dl client arch'}' title='$Lang::tr{'dl client arch'}' border='0' /> |
5148 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5149 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
5150 | </td></form> |
5151 | END | |
5152 | ; | |
5153 | if ($confighash{$key}[4] eq 'cert') { | |
4c962356 | 5154 | print <<END; |
99bfa85c | 5155 | <form method='post' name='frm${key}b'><td align='center' $col> |
c6c9630e MT |
5156 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' border='0' /> |
5157 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> | |
5158 | <input type='hidden' name='KEY' value='$key' /> | |
5159 | </td></form> | |
5160 | END | |
5161 | ; } else { | |
5162 | print "<td> </td>"; | |
5163 | } | |
5164 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$key}[1].p12") { | |
4c962356 | 5165 | print <<END; |
99bfa85c | 5166 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5167 | <input type='image' name='$Lang::tr{'download pkcs12 file'}' src='/images/media-floppy.png' alt='$Lang::tr{'download pkcs12 file'}' title='$Lang::tr{'download pkcs12 file'}' border='0' /> |
c6c9630e MT |
5168 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> |
5169 | <input type='hidden' name='KEY' value='$key' /> | |
5170 | </td></form> | |
5171 | END | |
5172 | ; } elsif ($confighash{$key}[4] eq 'cert') { | |
4c962356 | 5173 | print <<END; |
99bfa85c | 5174 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5175 | <input type='image' name='$Lang::tr{'download certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' title='$Lang::tr{'download certificate'}' border='0' /> |
c6c9630e MT |
5176 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> |
5177 | <input type='hidden' name='KEY' value='$key' /> | |
5178 | </td></form> | |
5179 | END | |
5180 | ; } else { | |
5181 | print "<td> </td>"; | |
5182 | } | |
5183 | print <<END | |
99bfa85c | 5184 | <form method='post' name='frm${key}d'><td align='center' $col> |
c6c9630e MT |
5185 | <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' border='0' /> |
5186 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
5187 | <input type='hidden' name='KEY' value='$key' /> | |
5188 | </td></form> | |
5189 | ||
99bfa85c | 5190 | <form method='post' name='frm${key}e'><td align='center' $col> |
c6c9630e MT |
5191 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> |
5192 | <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' width='20' height='20' border='0'/> | |
5193 | <input type='hidden' name='KEY' value='$key' /> | |
5194 | </td></form> | |
99bfa85c | 5195 | <form method='post' name='frm${key}f'><td align='center' $col> |
c6c9630e MT |
5196 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> |
5197 | <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' width='20' height='20' border='0' /> | |
5198 | <input type='hidden' name='KEY' value='$key' /> | |
5199 | </td></form> | |
5200 | </tr> | |
5201 | END | |
5202 | ; | |
5203 | $id++; | |
5b942f7f | 5204 | $lastnet = $confighash{$key}[32]; |
c6c9630e | 5205 | } |
5b942f7f | 5206 | print"</table>"; |
c6c9630e MT |
5207 | ; |
5208 | ||
5209 | # If the config file contains entries, print Key to action icons | |
5210 | if ( $id ) { | |
4c962356 | 5211 | print <<END; |
8c877a82 | 5212 | <table border='0'> |
c6c9630e | 5213 | <tr> |
4c962356 EK |
5214 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> |
5215 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
5216 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
5217 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5218 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5219 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
5220 | <td class='base'>$Lang::tr{'edit'}</td> | |
5221 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
5222 | <td class='base'>$Lang::tr{'remove'}</td> | |
c6c9630e MT |
5223 | </tr> |
5224 | <tr> | |
4c962356 EK |
5225 | <td> </td> |
5226 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
5227 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
5228 | <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td> | |
5229 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5230 | <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td> | |
5231 | <td class='base'>$Lang::tr{'dl client arch'}</td> | |
5232 | </tr> | |
f7edf97a | 5233 | </table><br> |
c6c9630e MT |
5234 | END |
5235 | ; | |
5236 | } | |
5237 | ||
4c962356 | 5238 | print <<END; |
c6c9630e MT |
5239 | <table width='100%'> |
5240 | <form method='post'> | |
4c962356 EK |
5241 | <tr><td align='right'> |
5242 | <input type='submit' name='ACTION' value='$Lang::tr{'add'}' /> | |
5243 | <input type='submit' name='ACTION' value='$Lang::tr{'ovpn con stat'}' $activeonrun /></td> | |
5244 | </tr> | |
c6c9630e MT |
5245 | </form> |
5246 | </table> | |
5247 | END | |
4c962356 EK |
5248 | ; |
5249 | &Header::closebox(); | |
5250 | } | |
fd5ccb2d EK |
5251 | |
5252 | # CA/key listing | |
4c962356 EK |
5253 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate authorities'}"); |
5254 | print <<END; | |
5255 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5256 | <tr> | |
5257 | <th width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5258 | <th width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></th> | |
5259 | <th width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th> | |
5260 | </tr> | |
5261 | END | |
5262 | ; | |
5263 | my $col1="bgcolor='$color{'color22'}'"; | |
f7fb5bc5 | 5264 | my $col2="bgcolor='$color{'color20'}'"; |
c8f50356 | 5265 | # DH parameter line |
f7fb5bc5 | 5266 | my $col3="bgcolor='$color{'color22'}'"; |
fd5ccb2d EK |
5267 | # ta.key line |
5268 | my $col4="bgcolor='$color{'color20'}'"; | |
f7fb5bc5 | 5269 | |
4c962356 EK |
5270 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { |
5271 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
5272 | $casubject =~ /Subject: (.*)[\n]/; | |
5273 | $casubject = $1; | |
5274 | $casubject =~ s+/Email+, E+; | |
5275 | $casubject =~ s/ ST=/ S=/; | |
5276 | print <<END; | |
5277 | <tr> | |
5278 | <td class='base' $col1>$Lang::tr{'root certificate'}</td> | |
5279 | <td class='base' $col1>$casubject</td> | |
c8f50356 | 5280 | <form method='post' name='frmrootcrta'><td width='3%' align='center' $col1> |
4c962356 EK |
5281 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> |
5282 | <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show root certificate'}' title='$Lang::tr{'show root certificate'}' width='20' height='20' border='0' /> | |
c8f50356 EK |
5283 | </form> |
5284 | <form method='post' name='frmrootcrtb'><td width='3%' align='center' $col1> | |
4c962356 EK |
5285 | <input type='image' name='$Lang::tr{'download root certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download root certificate'}' title='$Lang::tr{'download root certificate'}' border='0' /> |
5286 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> | |
c8f50356 EK |
5287 | </form> |
5288 | <td width='4%' $col1> </td> | |
5289 | </tr> | |
4c962356 EK |
5290 | END |
5291 | ; | |
5292 | } else { | |
5293 | # display rootcert generation buttons | |
5294 | print <<END; | |
5295 | <tr> | |
5296 | <td class='base' $col1>$Lang::tr{'root certificate'}:</td> | |
5297 | <td class='base' $col1>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5298 | <td colspan='3' $col1> </td> |
5299 | </tr> | |
4c962356 EK |
5300 | END |
5301 | ; | |
5302 | } | |
5303 | ||
5304 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
5305 | my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
5306 | $hostsubject =~ /Subject: (.*)[\n]/; | |
5307 | $hostsubject = $1; | |
5308 | $hostsubject =~ s+/Email+, E+; | |
5309 | $hostsubject =~ s/ ST=/ S=/; | |
5310 | ||
5311 | print <<END; | |
5312 | <tr> | |
5313 | <td class='base' $col2>$Lang::tr{'host certificate'}</td> | |
5314 | <td class='base' $col2>$hostsubject</td> | |
c8f50356 | 5315 | <form method='post' name='frmhostcrta'><td width='3%' align='center' $col2> |
4c962356 EK |
5316 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> |
5317 | <input type='image' name='$Lang::tr{'show host certificate'}' src='/images/info.gif' alt='$Lang::tr{'show host certificate'}' title='$Lang::tr{'show host certificate'}' width='20' height='20' border='0' /> | |
c8f50356 EK |
5318 | </form> |
5319 | <form method='post' name='frmhostcrtb'><td width='3%' align='center' $col2> | |
4c962356 EK |
5320 | <input type='image' name="$Lang::tr{'download host certificate'}" src='/images/media-floppy.png' alt="$Lang::tr{'download host certificate'}" title="$Lang::tr{'download host certificate'}" border='0' /> |
5321 | <input type='hidden' name='ACTION' value="$Lang::tr{'download host certificate'}" /> | |
c8f50356 EK |
5322 | </td></form> |
5323 | <td width='4%' $col2> </td> | |
5324 | </tr> | |
4c962356 EK |
5325 | END |
5326 | ; | |
5327 | } else { | |
5328 | # Nothing | |
5329 | print <<END; | |
5330 | <tr> | |
5331 | <td width='25%' class='base' $col2>$Lang::tr{'host certificate'}:</td> | |
5332 | <td class='base' $col2>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5333 | </td><td colspan='3' $col2> </td> |
5334 | </tr> | |
4c962356 EK |
5335 | END |
5336 | ; | |
5337 | } | |
ce9abb66 | 5338 | |
f7fb5bc5 EK |
5339 | # Adding DH parameter to chart |
5340 | if (-f "${General::swroot}/ovpn/ca/dh1024.pem") { | |
5341 | my $dhsubject = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem`; | |
c8f50356 | 5342 | $dhsubject =~ / (.*)[\n]/; |
f7fb5bc5 EK |
5343 | $dhsubject = $1; |
5344 | ||
5345 | ||
5346 | print <<END; | |
5347 | <tr> | |
5348 | <td class='base' $col3>$Lang::tr{'dh parameter'}</td> | |
5349 | <td class='base' $col3>$dhsubject</td> | |
c8f50356 | 5350 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> |
f7fb5bc5 EK |
5351 | <input type='hidden' name='ACTION' value='$Lang::tr{'show dh'}' /> |
5352 | <input type='image' name='$Lang::tr{'show dh'}' src='/images/info.gif' alt='$Lang::tr{'show dh'}' title='$Lang::tr{'show dh'}' width='20' height='20' border='0' /> | |
c8f50356 EK |
5353 | </form> |
5354 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> | |
c8f50356 EK |
5355 | </form> |
5356 | <td width='4%' $col3> </td> | |
5357 | </tr> | |
f7fb5bc5 EK |
5358 | END |
5359 | ; | |
5360 | } else { | |
5361 | # Nothing | |
5362 | print <<END; | |
5363 | <tr> | |
5364 | <td width='25%' class='base' $col3>$Lang::tr{'dh parameter'}:</td> | |
5365 | <td class='base' $col3>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5366 | </td><td colspan='3' $col3> </td> |
5367 | </tr> | |
f7fb5bc5 EK |
5368 | END |
5369 | ; | |
5370 | } | |
5371 | ||
fd5ccb2d EK |
5372 | # Adding ta.key to chart |
5373 | if (-f "${General::swroot}/ovpn/certs/ta.key") { | |
5374 | my $tasubject = `/bin/cat ${General::swroot}/ovpn/certs/ta.key`; | |
5375 | $tasubject =~ /# (.*)[\n]/; | |
5376 | $tasubject = $1; | |
5377 | print <<END; | |
5378 | ||
5379 | <tr> | |
5380 | <td class='base' $col4>$Lang::tr{'ta key'}</td> | |
5381 | <td class='base' $col4>$tasubject</td> | |
5382 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5383 | <input type='hidden' name='ACTION' value='$Lang::tr{'show tls-auth key'}' /> | |
5384 | <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show tls-auth key'}' title='$Lang::tr{'show tls-auth key'}' width='20' height='20' border='0' /> | |
5385 | </form> | |
5386 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5387 | <input type='image' name='$Lang::tr{'download tls-auth key'}' src='/images/media-floppy.png' alt='$Lang::tr{'download tls-auth key'}' title='$Lang::tr{'download tls-auth key'}' border='0' /> | |
5388 | <input type='hidden' name='ACTION' value='$Lang::tr{'download tls-auth key'}' /> | |
5389 | </form> | |
5390 | <td width='4%' $col4> </td> | |
5391 | </tr> | |
5392 | END | |
5393 | ; | |
5394 | } else { | |
5395 | # Nothing | |
5396 | print <<END; | |
5397 | <tr> | |
5398 | <td width='25%' class='base' $col4>$Lang::tr{'ta key'}:</td> | |
5399 | <td class='base' $col4>$Lang::tr{'not present'}</td> | |
5400 | <td colspan='3' $col4> </td> | |
5401 | </tr> | |
5402 | END | |
5403 | ; | |
5404 | } | |
5405 | ||
4c962356 EK |
5406 | if (! -f "${General::swroot}/ovpn/ca/cacert.pem") { |
5407 | print "<tr><td colspan='5' align='center'><form method='post'>"; | |
5408 | print "<input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' />"; | |
5409 | print "</form></td></tr>\n"; | |
5410 | } | |
5411 | ||
5412 | if (keys %cahash > 0) { | |
5413 | foreach my $key (keys %cahash) { | |
5414 | if (($key + 1) % 2) { | |
5415 | print "<tr bgcolor='$color{'color20'}'>\n"; | |
5416 | } else { | |
5417 | print "<tr bgcolor='$color{'color22'}'>\n"; | |
5418 | } | |
5419 | print "<td class='base'>$cahash{$key}[0]</td>\n"; | |
5420 | print "<td class='base'>$cahash{$key}[1]</td>\n"; | |
5421 | print <<END; | |
5422 | <form method='post' name='cafrm${key}a'><td align='center'> | |
5423 | <input type='image' name='$Lang::tr{'show ca certificate'}' src='/images/info.gif' alt='$Lang::tr{'show ca certificate'}' title='$Lang::tr{'show ca certificate'}' border='0' /> | |
5424 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
5425 | <input type='hidden' name='KEY' value='$key' /> | |
5426 | </td></form> | |
5427 | <form method='post' name='cafrm${key}b'><td align='center'> | |
5428 | <input type='image' name='$Lang::tr{'download ca certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download ca certificate'}' title='$Lang::tr{'download ca certificate'}' border='0' /> | |
5429 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> | |
5430 | <input type='hidden' name='KEY' value='$key' /> | |
5431 | </td></form> | |
5432 | <form method='post' name='cafrm${key}c'><td align='center'> | |
5433 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
5434 | <input type='image' name='$Lang::tr{'remove ca certificate'}' src='/images/delete.gif' alt='$Lang::tr{'remove ca certificate'}' title='$Lang::tr{'remove ca certificate'}' width='20' height='20' border='0' /> | |
5435 | <input type='hidden' name='KEY' value='$key' /> | |
5436 | </td></form></tr> | |
5437 | END | |
5438 | ; | |
5439 | } | |
5440 | } | |
5441 | ||
5442 | print "</table>"; | |
5443 | ||
5444 | # If the file contains entries, print Key to action icons | |
5445 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
5446 | print <<END; | |
5447 | <table> | |
5448 | <tr> | |
5449 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
5450 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5451 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5452 | <td> <img src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' /></td> | |
5453 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5454 | </tr> | |
5455 | </table> | |
5456 | END | |
5457 | ; | |
5458 | } | |
ce9abb66 | 5459 | |
4c962356 EK |
5460 | print <<END |
5461 | <hr size='1'> | |
5462 | <form method='post' enctype='multipart/form-data'> | |
5463 | <table width='100%' border='0'cellspacing='1' cellpadding='0'> | |
fd5ccb2d | 5464 | <tr> |
ad09461a | 5465 | <td class'base'><b>$Lang::tr{'upload ca certificate'}</b></td> |
fd5ccb2d | 5466 | </tr> |
4c962356 EK |
5467 | <tr> |
5468 | <td class='base' nowrap='nowrap'>$Lang::tr{'ca name'}:</td> | |
5469 | <td nowrap='nowrap'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' align='left'/></td> | |
5470 | <td nowrap='nowrap'><input type='file' name='FH' size='25' /> | |
5471 | <td nowrap='nowrap' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}' /></td> | |
5472 | </tr> | |
5473 | ||
f527e53f EK |
5474 | <tr align='right'> |
5475 | <td colspan='4' align='right' width='80%'><input type='submit' name='ACTION' value='$Lang::tr{'show crl'}' /></td> | |
5476 | </tr> | |
5477 | ||
5478 | <tr><td colspan=4><hr /></td></tr><tr> | |
5479 | <tr> | |
92bed250 | 5480 | <td class'base'><b>$Lang::tr{'ovpn dh parameters'}</b></td> |
f527e53f EK |
5481 | </tr> |
5482 | ||
4c962356 | 5483 | <tr> |
49abe7af EK |
5484 | <td class='base' nowrap='nowrap'>$Lang::tr{'ovpn dh upload'}:</td> |
5485 | <td nowrap='nowrap'><size='15' align='left'/></td> | |
4c962356 | 5486 | <td nowrap='nowrap'><input type='file' name='FH' size='25' /> |
49abe7af | 5487 | <td colspan='4' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload dh key'}' /></td> |
4c962356 | 5488 | </tr> |
4c962356 | 5489 | <tr> |
f527e53f EK |
5490 | <td class='base' nowrap='nowrap'>$Lang::tr{'ovpn dh new key'}:</td> |
5491 | <td nowrap='nowrap'><size='15' align='left'/></td> | |
4c962356 | 5492 | <td nowrap='nowrap'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> |
4c962356 | 5493 | </tr> |
4c962356 | 5494 | </table> |
f527e53f EK |
5495 | |
5496 | <tr><td colspan=4><hr /></td></tr><tr> | |
4c962356 EK |
5497 | END |
5498 | ; | |
5499 | ||
5500 | if ( $srunning eq "yes" ) { | |
5501 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' disabled='disabled' /></div></form>\n"; | |
5502 | } else { | |
5503 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></div></form>\n"; | |
5504 | } | |
5505 | &Header::closebox(); | |
5506 | END | |
5507 | ; | |
5508 | ||
5509 | &Header::closepage(); | |
ce9abb66 | 5510 |