]>
Commit | Line | Data |
---|---|---|
ac1cfefa | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
46803376 | 5 | # Copyright (C) 2007-2022 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 | ############################################################################### | |
ac1cfefa | 21 | |
205c3c17 | 22 | use Data::UUID; |
26a0befd | 23 | use MIME::Base64; |
ac1cfefa MT |
24 | use Net::DNS; |
25 | use File::Copy; | |
26 | use File::Temp qw/ tempfile tempdir /; | |
27 | use strict; | |
eff2dbf8 | 28 | use Sort::Naturally; |
c7fe09c6 | 29 | use Sys::Hostname; |
ac1cfefa | 30 | # enable only the following on debugging purpose |
cb5e9c6c CS |
31 | #use warnings; |
32 | #use CGI::Carp 'fatalsToBrowser'; | |
ac1cfefa | 33 | |
986e08d9 | 34 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
35 | require "${General::swroot}/lang.pl"; |
36 | require "${General::swroot}/header.pl"; | |
ac1cfefa MT |
37 | require "${General::swroot}/countries.pl"; |
38 | ||
39 | #workaround to suppress a warning when a variable is used only once | |
ed84e8b8 | 40 | my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} ); |
ac1cfefa MT |
41 | undef (@dummy); |
42 | ||
43 | ### | |
44 | ### Initialize variables | |
45 | ### | |
624615ee | 46 | my $sleepDelay = 4; # after a call to ipsecctrl S or R, wait this delay (seconds) before reading status (let the ipsec do its job) |
ac1cfefa | 47 | my %netsettings=(); |
ed84e8b8 MT |
48 | our %cgiparams=(); |
49 | our %vpnsettings=(); | |
ac1cfefa MT |
50 | my %checked=(); |
51 | my %confighash=(); | |
52 | my %cahash=(); | |
53 | my %selected=(); | |
54 | my $warnmessage = ''; | |
55 | my $errormessage = ''; | |
ed84e8b8 | 56 | |
f2fdd0c1 CS |
57 | my %color = (); |
58 | my %mainsettings = (); | |
59 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 60 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
f2fdd0c1 | 61 | |
ac1cfefa | 62 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
e897bfeb | 63 | |
af183eeb MT |
64 | my %INACTIVITY_TIMEOUTS = ( |
65 | 300 => $Lang::tr{'five minutes'}, | |
66 | 600 => $Lang::tr{'ten minutes'}, | |
67 | 900 => $Lang::tr{'fifteen minutes'}, | |
68 | 1800 => $Lang::tr{'thirty minutes'}, | |
69 | 3600 => $Lang::tr{'one hour'}, | |
70 | 43200 => $Lang::tr{'twelve hours'}, | |
71 | 86400 => $Lang::tr{'24 hours'}, | |
72 | 0 => "- $Lang::tr{'unlimited'} -", | |
73 | ); | |
74 | ||
ae0d0698 MT |
75 | # Load aliases |
76 | my %aliases; | |
77 | &General::get_aliases(\%aliases); | |
78 | ||
e9850821 AM |
79 | my $col=""; |
80 | ||
ac1cfefa | 81 | $cgiparams{'ENABLED'} = 'off'; |
ac1cfefa | 82 | $cgiparams{'EDIT_ADVANCED'} = 'off'; |
ac1cfefa MT |
83 | $cgiparams{'ACTION'} = ''; |
84 | $cgiparams{'CA_NAME'} = ''; | |
ed84e8b8 MT |
85 | $cgiparams{'KEY'} = ''; |
86 | $cgiparams{'TYPE'} = ''; | |
87 | $cgiparams{'ADVANCED'} = ''; | |
ed84e8b8 MT |
88 | $cgiparams{'NAME'} = ''; |
89 | $cgiparams{'LOCAL_SUBNET'} = ''; | |
90 | $cgiparams{'REMOTE_SUBNET'} = ''; | |
ae0d0698 | 91 | $cgiparams{'LOCAL'} = ''; |
ed84e8b8 MT |
92 | $cgiparams{'REMOTE'} = ''; |
93 | $cgiparams{'LOCAL_ID'} = ''; | |
94 | $cgiparams{'REMOTE_ID'} = ''; | |
95 | $cgiparams{'REMARK'} = ''; | |
96 | $cgiparams{'PSK'} = ''; | |
97 | $cgiparams{'CERT_NAME'} = ''; | |
98 | $cgiparams{'CERT_EMAIL'} = ''; | |
99 | $cgiparams{'CERT_OU'} = ''; | |
100 | $cgiparams{'CERT_ORGANIZATION'} = ''; | |
101 | $cgiparams{'CERT_CITY'} = ''; | |
102 | $cgiparams{'CERT_STATE'} = ''; | |
103 | $cgiparams{'CERT_COUNTRY'} = ''; | |
104 | $cgiparams{'SUBJECTALTNAME'} = ''; | |
105 | $cgiparams{'CERT_PASS1'} = ''; | |
106 | $cgiparams{'CERT_PASS2'} = ''; | |
107 | $cgiparams{'ROOTCERT_HOSTNAME'} = ''; | |
108 | $cgiparams{'ROOTCERT_COUNTRY'} = ''; | |
109 | $cgiparams{'P12_PASS'} = ''; | |
110 | $cgiparams{'ROOTCERT_ORGANIZATION'} = ''; | |
111 | $cgiparams{'ROOTCERT_HOSTNAME'} = ''; | |
112 | $cgiparams{'ROOTCERT_EMAIL'} = ''; | |
113 | $cgiparams{'ROOTCERT_OU'} = ''; | |
114 | $cgiparams{'ROOTCERT_CITY'} = ''; | |
115 | $cgiparams{'ROOTCERT_STATE'} = ''; | |
c7fe09c6 | 116 | $cgiparams{'RW_ENDPOINT'} = ''; |
9d85ac3b | 117 | $cgiparams{'RW_NET'} = ''; |
4e156911 AM |
118 | $cgiparams{'DPD_DELAY'} = '30'; |
119 | $cgiparams{'DPD_TIMEOUT'} = '120'; | |
f6529a04 | 120 | $cgiparams{'FORCE_MOBIKE'} = 'off'; |
1e9457ac | 121 | $cgiparams{'START_ACTION'} = 'route'; |
8ebe7254 | 122 | $cgiparams{'INACTIVITY_TIMEOUT'} = 1800; |
29f5e0e2 | 123 | $cgiparams{'MODE'} = "tunnel"; |
cae1f4a7 | 124 | $cgiparams{'INTERFACE_MODE'} = ""; |
74641317 | 125 | $cgiparams{'INTERFACE_ADDRESS'} = ""; |
55842dda | 126 | $cgiparams{'INTERFACE_MTU'} = 1500; |
dccd7e87 | 127 | $cgiparams{'DNS_SERVERS'} = ""; |
ac1cfefa MT |
128 | &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'}); |
129 | ||
2d7b3347 MT |
130 | my %APPLE_CIPHERS = ( |
131 | "aes256gcm128" => "AES-256-GCM", | |
132 | "aes128gcm128" => "AES-128-GCM", | |
133 | "aes256" => "AES-256", | |
134 | "aes128" => "AES-128", | |
135 | "3des" => "3DES", | |
136 | ); | |
137 | ||
138 | my %APPLE_INTEGRITIES = ( | |
139 | "sha2_512" => "SHA2-512", | |
140 | "sha2_384" => "SHA2-384", | |
141 | "sha2_256" => "SHA2-256", | |
142 | "sha1" => "SHA1-160", | |
143 | ); | |
144 | ||
145 | my %APPLE_DH_GROUPS = ( | |
146 | "768" => 1, | |
147 | "1024" => 2, | |
148 | "1536" => 5, | |
149 | "2048" => 14, | |
150 | "3072" => 15, | |
151 | "4096" => 16, | |
152 | "6144" => 17, | |
153 | "8192" => 18, | |
154 | "e256" => 19, | |
155 | "e384" => 20, | |
156 | "e521" => 21, | |
157 | ); | |
158 | ||
ac1cfefa MT |
159 | ### |
160 | ### Useful functions | |
161 | ### | |
162 | sub valid_dns_host { | |
163 | my $hostname = $_[0]; | |
164 | unless ($hostname) { return "No hostname"}; | |
165 | my $res = new Net::DNS::Resolver; | |
166 | my $query = $res->search("$hostname"); | |
167 | if ($query) { | |
168 | foreach my $rr ($query->answer) { | |
169 | ## Potential bug - we are only looking at A records: | |
170 | return 0 if $rr->type eq "A"; | |
171 | } | |
172 | } else { | |
173 | return $res->errorstring; | |
174 | } | |
175 | } | |
ed84e8b8 MT |
176 | ### |
177 | ### Just return true is one interface is vpn enabled | |
178 | ### | |
179 | sub vpnenabled { | |
624615ee | 180 | return ($vpnsettings{'ENABLED'} eq 'on'); |
ed84e8b8 MT |
181 | } |
182 | ### | |
624615ee LS |
183 | ### old version: maintain serial number to one, without explication. |
184 | ### this: let the counter go, so that each cert is numbered. | |
ed84e8b8 | 185 | ### |
624615ee LS |
186 | sub cleanssldatabase { |
187 | if (open(FILE, ">${General::swroot}/certs/serial")) { | |
188 | print FILE "01"; | |
189 | close FILE; | |
190 | } | |
191 | if (open(FILE, ">${General::swroot}/certs/index.txt")) { | |
192 | print FILE ""; | |
193 | close FILE; | |
194 | } | |
e6f7f8e7 | 195 | if (open(FILE, ">${General::swroot}/certs/index.txt.attr")) { |
94aa82fa | 196 | print FILE "unique_subject = yes"; |
e6f7f8e7 EK |
197 | close FILE; |
198 | } | |
624615ee | 199 | unlink ("${General::swroot}/certs/index.txt.old"); |
e6f7f8e7 | 200 | unlink ("${General::swroot}/certs/index.txt.attr.old"); |
624615ee LS |
201 | unlink ("${General::swroot}/certs/serial.old"); |
202 | unlink ("${General::swroot}/certs/01.pem"); | |
ac1cfefa | 203 | } |
624615ee LS |
204 | sub newcleanssldatabase { |
205 | if (! -s "${General::swroot}/certs/serial" ) { | |
206 | open(FILE, ">${General::swroot}/certs/serial"); | |
207 | print FILE "01"; | |
208 | close FILE; | |
209 | } | |
210 | if (! -s ">${General::swroot}/certs/index.txt") { | |
a81cbf61 SS |
211 | open(FILE, ">${General::swroot}/certs/index.txt"); |
212 | close(FILE); | |
624615ee | 213 | } |
e6f7f8e7 | 214 | if (! -s ">${General::swroot}/certs/index.txt.attr") { |
a81cbf61 | 215 | open(FILE, ">${General::swroot}/certs/index.txt.attr"); |
94aa82fa | 216 | print FILE "unique_subject = yes"; |
a81cbf61 | 217 | close(FILE); |
e6f7f8e7 | 218 | } |
624615ee | 219 | unlink ("${General::swroot}/certs/index.txt.old"); |
e6f7f8e7 | 220 | unlink ("${General::swroot}/certs/index.txt.attr.old"); |
624615ee LS |
221 | unlink ("${General::swroot}/certs/serial.old"); |
222 | # unlink ("${General::swroot}/certs/01.pem"); numbering evolves. Wrong place to delete | |
ac1cfefa | 223 | } |
ed84e8b8 MT |
224 | |
225 | ### | |
226 | ### Call openssl and return errormessage if any | |
227 | ### | |
228 | sub callssl ($) { | |
624615ee | 229 | my $opt = shift; |
b71a7fb9 | 230 | my $retssl = `/usr/bin/openssl $opt 2>&1`; #redirect stderr |
624615ee | 231 | my $ret = ''; |
aa07e1bb MT |
232 | |
233 | if ($?) { | |
234 | foreach my $line (split (/\n/, $retssl)) { | |
235 | &General::log("ipsec", "$line") if (0); # 1 for verbose logging | |
236 | $ret .= '<br>' . &Header::escape($line); | |
237 | } | |
624615ee | 238 | } |
aa07e1bb | 239 | |
624615ee | 240 | return $ret ? "$Lang::tr{'openssl produced an error'}: $ret" : '' ; |
ed84e8b8 MT |
241 | } |
242 | ### | |
243 | ### Obtain a CN from given cert | |
244 | ### | |
245 | sub getCNfromcert ($) { | |
624615ee | 246 | #&General::log("ipsec", "Extracting name from $_[0]..."); |
b71a7fb9 | 247 | my $temp = `/usr/bin/openssl x509 -text -in $_[0]`; |
fc4b02df | 248 | $temp =~ /Subject:.*CN\s*=\s*(.*)[\n]/; |
b71a7fb9 MT |
249 | $temp = $1; |
250 | $temp =~ s+/Email+, E+; | |
251 | $temp =~ s/ ST = / S = /; | |
252 | $temp =~ s/,//g; | |
253 | $temp =~ s/\'//g; | |
624615ee | 254 | return $temp; |
ed84e8b8 MT |
255 | } |
256 | ### | |
257 | ### Obtain Subject from given cert | |
258 | ### | |
259 | sub getsubjectfromcert ($) { | |
624615ee | 260 | #&General::log("ipsec", "Extracting subject from $_[0]..."); |
b71a7fb9 MT |
261 | my $temp = `/usr/bin/openssl x509 -text -in $_[0]`; |
262 | $temp =~ /Subject: (.*)[\n]/; | |
263 | $temp = $1; | |
264 | $temp =~ s+/Email+, E+; | |
265 | $temp =~ s/ ST = / S = /; | |
624615ee | 266 | return $temp; |
ed84e8b8 MT |
267 | } |
268 | ### | |
624615ee | 269 | ### Combine local subnet and connection name to make a unique name for each connection section |
ed84e8b8 MT |
270 | ### (this sub is not used now) |
271 | ### | |
272 | sub makeconnname ($) { | |
624615ee LS |
273 | my $conn = shift; |
274 | my $subnet = shift; | |
275 | ||
276 | $subnet =~ /^(.*?)\/(.*?)$/; # $1=IP $2=mask | |
277 | my $ip = unpack('N', &Socket::inet_aton($1)); | |
278 | if (length ($2) > 2) { | |
279 | my $mm = unpack('N', &Socket::inet_aton($2)); | |
280 | while ( ($mm & 1)==0 ) { | |
281 | $ip >>= 1; | |
282 | $mm >>= 1; | |
283 | }; | |
284 | } else { | |
285 | $ip >>= (32 - $2); | |
286 | } | |
287 | return sprintf ("%s-%X", $conn, $ip); | |
ed84e8b8 MT |
288 | } |
289 | ### | |
290 | ### Write a config file. | |
291 | ### | |
292 | ###Type=Host : GUI can choose the interface used (RED,GREEN,BLUE) and | |
293 | ### the side is always defined as 'left'. | |
ed84e8b8 | 294 | ### |
ed84e8b8 | 295 | |
ac1cfefa | 296 | sub writeipsecfiles { |
624615ee LS |
297 | my %lconfighash = (); |
298 | my %lvpnsettings = (); | |
299 | &General::readhasharray("${General::swroot}/vpn/config", \%lconfighash); | |
300 | &General::readhash("${General::swroot}/vpn/settings", \%lvpnsettings); | |
301 | ||
302 | open(CONF, ">${General::swroot}/vpn/ipsec.conf") or die "Unable to open ${General::swroot}/vpn/ipsec.conf: $!"; | |
303 | open(SECRETS, ">${General::swroot}/vpn/ipsec.secrets") or die "Unable to open ${General::swroot}/vpn/ipsec.secrets: $!"; | |
304 | flock CONF, 2; | |
305 | flock SECRETS, 2; | |
306 | print CONF "version 2\n\n"; | |
307 | print CONF "conn %default\n"; | |
308 | print CONF "\tkeyingtries=%forever\n"; | |
309 | print CONF "\n"; | |
310 | ||
311 | # Add user includes to config file | |
312 | if (-e "/etc/ipsec.user.conf") { | |
313 | print CONF "include /etc/ipsec.user.conf\n"; | |
314 | print CONF "\n"; | |
ed84e8b8 | 315 | } |
e8b3bb0e | 316 | |
624615ee | 317 | print SECRETS "include /etc/ipsec.user.secrets\n"; |
4b02b404 | 318 | |
624615ee LS |
319 | if (-f "${General::swroot}/certs/hostkey.pem") { |
320 | print SECRETS ": RSA ${General::swroot}/certs/hostkey.pem\n" | |
321 | } | |
322 | my $last_secrets = ''; # old the less specifics connections | |
323 | ||
324 | foreach my $key (keys %lconfighash) { | |
325 | next if ($lconfighash{$key}[0] ne 'on'); | |
326 | ||
327 | #remote peer is not set? => use '%any' | |
328 | $lconfighash{$key}[10] = '%any' if ($lconfighash{$key}[10] eq ''); | |
329 | ||
ae0d0698 MT |
330 | # Field 6 might be "off" on old installations |
331 | if ($lconfighash{$key}[6] eq "off") { | |
517683ee | 332 | $lconfighash{$key}[6] = $lvpnsettings{"VPN_IP"}; |
ae0d0698 MT |
333 | } |
334 | ||
624615ee | 335 | my $localside; |
ae0d0698 MT |
336 | if ($lconfighash{$key}[6]) { |
337 | $localside = $lconfighash{$key}[6]; | |
ae0d0698 MT |
338 | } else { |
339 | $localside = "%defaultroute"; | |
4b02b404 | 340 | } |
e8b3bb0e | 341 | |
b01c17e9 MT |
342 | my $interface_mode = $lconfighash{$key}[36]; |
343 | ||
624615ee LS |
344 | print CONF "conn $lconfighash{$key}[1]\n"; |
345 | print CONF "\tleft=$localside\n"; | |
b01c17e9 MT |
346 | |
347 | if ($interface_mode eq "gre") { | |
90aa4f10 | 348 | print CONF "\tleftprotoport=gre\n"; |
b01c17e9 MT |
349 | } elsif ($interface_mode eq "vti") { |
350 | print CONF "\tleftsubnet=0.0.0.0/0\n"; | |
351 | } else { | |
f2d45a45 | 352 | print CONF "\tleftsubnet=" . &make_subnets("left", $lconfighash{$key}[8]) . "\n"; |
b01c17e9 MT |
353 | } |
354 | ||
624615ee LS |
355 | print CONF "\tleftfirewall=yes\n"; |
356 | print CONF "\tlefthostaccess=yes\n"; | |
9f374222 MT |
357 | |
358 | # Always send the host certificate | |
359 | if ($lconfighash{$key}[3] eq 'host') { | |
360 | print CONF "\tleftsendcert=always\n"; | |
361 | } | |
362 | ||
624615ee LS |
363 | print CONF "\tright=$lconfighash{$key}[10]\n"; |
364 | ||
365 | if ($lconfighash{$key}[3] eq 'net') { | |
b01c17e9 | 366 | if ($interface_mode eq "gre") { |
90aa4f10 | 367 | print CONF "\trightprotoport=gre\n"; |
b01c17e9 MT |
368 | } elsif ($interface_mode eq "vti") { |
369 | print CONF "\trightsubnet=0.0.0.0/0\n"; | |
370 | } else { | |
f2d45a45 | 371 | print CONF "\trightsubnet=" . &make_subnets("right", $lconfighash{$key}[11]) . "\n"; |
b01c17e9 | 372 | } |
624615ee | 373 | } |
e8b3bb0e | 374 | |
624615ee LS |
375 | # Local Cert and Remote Cert (unless auth is DN dn-auth) |
376 | if ($lconfighash{$key}[4] eq 'cert') { | |
377 | print CONF "\tleftcert=${General::swroot}/certs/hostcert.pem\n"; | |
378 | print CONF "\trightcert=${General::swroot}/certs/$lconfighash{$key}[1]cert.pem\n" if ($lconfighash{$key}[2] ne '%auth-dn'); | |
ed84e8b8 | 379 | } |
ed84e8b8 | 380 | |
624615ee LS |
381 | # Local and Remote IDs |
382 | print CONF "\tleftid=\"$lconfighash{$key}[7]\"\n" if ($lconfighash{$key}[7]); | |
383 | print CONF "\trightid=\"$lconfighash{$key}[9]\"\n" if ($lconfighash{$key}[9]); | |
126246a8 | 384 | |
326728d5 MT |
385 | # Set mode |
386 | if ($lconfighash{$key}[35] eq "transport") { | |
387 | print CONF "\ttype=transport\n"; | |
388 | } else { | |
389 | print CONF "\ttype=tunnel\n"; | |
390 | } | |
391 | ||
b01c17e9 MT |
392 | # Add mark for VTI |
393 | if ($interface_mode eq "vti") { | |
394 | print CONF "\tmark=$key\n"; | |
395 | } | |
396 | ||
624615ee LS |
397 | # Is PFS enabled? |
398 | my $pfs = $lconfighash{$key}[28] eq 'on' ? 'on' : 'off'; | |
ed84e8b8 | 399 | |
624615ee LS |
400 | # Algorithms |
401 | if ($lconfighash{$key}[18] && $lconfighash{$key}[19] && $lconfighash{$key}[20]) { | |
402 | my @encs = split('\|', $lconfighash{$key}[18]); | |
403 | my @ints = split('\|', $lconfighash{$key}[19]); | |
404 | my @groups = split('\|', $lconfighash{$key}[20]); | |
ed84e8b8 | 405 | |
624615ee LS |
406 | my @algos = &make_algos("ike", \@encs, \@ints, \@groups, 1); |
407 | print CONF "\tike=" . join(",", @algos); | |
408 | ||
409 | if ($lconfighash{$key}[24] eq 'on') { #only proposed algorythms? | |
410 | print CONF "!\n"; | |
411 | } else { | |
412 | print CONF "\n"; | |
413 | } | |
414 | } | |
415 | ||
416 | if ($lconfighash{$key}[21] && $lconfighash{$key}[22]) { | |
417 | my @encs = split('\|', $lconfighash{$key}[21]); | |
418 | my @ints = split('\|', $lconfighash{$key}[22]); | |
419 | my @groups = split('\|', $lconfighash{$key}[23]); | |
420 | ||
421 | # Use IKE grouptype if no ESP group type has been selected | |
422 | # (for backwards compatibility) | |
423 | if ($lconfighash{$key}[23] eq "") { | |
424 | @groups = split('\|', $lconfighash{$key}[20]); | |
425 | } | |
f6529a04 | 426 | |
624615ee LS |
427 | my @algos = &make_algos("esp", \@encs, \@ints, \@groups, ($pfs eq "on")); |
428 | print CONF "\tesp=" . join(",", @algos); | |
afd5d8f7 | 429 | |
624615ee LS |
430 | if ($lconfighash{$key}[24] eq 'on') { #only proposed algorythms? |
431 | print CONF "!\n"; | |
432 | } else { | |
433 | print CONF "\n"; | |
434 | } | |
afd5d8f7 | 435 | } |
ac1cfefa | 436 | |
624615ee LS |
437 | # IKE V1 or V2 |
438 | if (! $lconfighash{$key}[29]) { | |
439 | $lconfighash{$key}[29] = "ikev1"; | |
440 | } | |
a4737620 | 441 | |
624615ee | 442 | print CONF "\tkeyexchange=$lconfighash{$key}[29]\n"; |
a4737620 | 443 | |
624615ee LS |
444 | # Lifetimes |
445 | print CONF "\tikelifetime=$lconfighash{$key}[16]h\n" if ($lconfighash{$key}[16]); | |
446 | print CONF "\tkeylife=$lconfighash{$key}[17]h\n" if ($lconfighash{$key}[17]); | |
447 | ||
448 | # Compression | |
449 | print CONF "\tcompress=yes\n" if ($lconfighash{$key}[13] eq 'on'); | |
450 | ||
451 | # Force MOBIKE? | |
452 | if (($lconfighash{$key}[29] eq "ikev2") && ($lconfighash{$key}[32] eq 'on')) { | |
453 | print CONF "\tmobike=yes\n"; | |
454 | } | |
455 | ||
456 | # Dead Peer Detection | |
457 | my $dpdaction = $lconfighash{$key}[27]; | |
458 | print CONF "\tdpdaction=$dpdaction\n"; | |
459 | ||
460 | # If the dead peer detection is disabled and IKEv2 is used, | |
461 | # dpddelay must be set to zero, too. | |
462 | if ($dpdaction eq "none") { | |
463 | if ($lconfighash{$key}[29] eq "ikev2") { | |
464 | print CONF "\tdpddelay=0\n"; | |
465 | } | |
466 | } else { | |
467 | my $dpddelay = $lconfighash{$key}[31]; | |
468 | if (!$dpddelay) { | |
469 | $dpddelay = 30; | |
470 | } | |
471 | print CONF "\tdpddelay=$dpddelay\n"; | |
472 | my $dpdtimeout = $lconfighash{$key}[30]; | |
473 | if (!$dpdtimeout) { | |
474 | $dpdtimeout = 120; | |
475 | } | |
476 | print CONF "\tdpdtimeout=$dpdtimeout\n"; | |
477 | } | |
478 | ||
479 | # Build Authentication details: LEFTid RIGHTid : PSK psk | |
480 | my $psk_line; | |
481 | if ($lconfighash{$key}[4] eq 'psk') { | |
482 | $psk_line = ($lconfighash{$key}[7] ? $lconfighash{$key}[7] : $localside) . " " ; | |
483 | $psk_line .= $lconfighash{$key}[9] ? $lconfighash{$key}[9] : $lconfighash{$key}[10]; #remoteid or remote address? | |
484 | $psk_line .= " : PSK '$lconfighash{$key}[5]'\n"; | |
485 | # if the line contains %any, it is less specific than two IP or ID, so move it at end of file. | |
486 | if ($psk_line =~ /%any/) { | |
487 | $last_secrets .= $psk_line; | |
488 | } else { | |
489 | print SECRETS $psk_line; | |
490 | } | |
491 | print CONF "\tauthby=secret\n"; | |
492 | } else { | |
493 | print CONF "\tauthby=rsasig\n"; | |
494 | print CONF "\tleftrsasigkey=%cert\n"; | |
495 | print CONF "\trightrsasigkey=%cert\n"; | |
496 | } | |
497 | ||
dcb406cc MT |
498 | my $start_action = $lconfighash{$key}[33]; |
499 | if (!$start_action) { | |
500 | $start_action = "start"; | |
501 | } | |
502 | ||
af183eeb MT |
503 | my $inactivity_timeout = $lconfighash{$key}[34]; |
504 | if ($inactivity_timeout eq "") { | |
505 | $inactivity_timeout = 900; | |
506 | } | |
507 | ||
624615ee LS |
508 | # Automatically start only if a net-to-net connection |
509 | if ($lconfighash{$key}[3] eq 'host') { | |
510 | print CONF "\tauto=add\n"; | |
511 | print CONF "\trightsourceip=$lvpnsettings{'RW_NET'}\n"; | |
512 | } else { | |
dcb406cc | 513 | print CONF "\tauto=$start_action\n"; |
1ee1666e MT |
514 | |
515 | # If in on-demand mode, we terminate the tunnel | |
516 | # after 15 min of no traffic | |
af183eeb MT |
517 | if ($start_action eq 'route' && $inactivity_timeout > 0) { |
518 | print CONF "\tinactivity=$inactivity_timeout\n"; | |
1ee1666e | 519 | } |
624615ee LS |
520 | } |
521 | ||
522 | # Fragmentation | |
523 | print CONF "\tfragmentation=yes\n"; | |
524 | ||
dccd7e87 MT |
525 | # DNS Servers for RW |
526 | if ($lconfighash{$key}[3] eq 'host') { | |
527 | my @servers = split(/\|/, $lconfighash{$key}[39]); | |
528 | ||
529 | print CONF "\trightdns=" . join(",", @servers) . "\n"; | |
530 | } | |
531 | ||
624615ee LS |
532 | print CONF "\n"; |
533 | } #foreach key | |
534 | ||
535 | # Add post user includes to config file | |
536 | # After the GUI-connections allows to patch connections. | |
537 | if (-e "/etc/ipsec.user-post.conf") { | |
538 | print CONF "include /etc/ipsec.user-post.conf\n"; | |
539 | print CONF "\n"; | |
540 | } | |
541 | ||
542 | print SECRETS $last_secrets if ($last_secrets); | |
543 | close(CONF); | |
544 | close(SECRETS); | |
ac1cfefa MT |
545 | } |
546 | ||
ae2782ba MT |
547 | # Hook to regenerate the configuration files. |
548 | if ($ENV{"REMOTE_ADDR"} eq "") { | |
26dfc86a | 549 | writeipsecfiles(); |
ae2782ba MT |
550 | exit(0); |
551 | } | |
552 | ||
ac1cfefa MT |
553 | ### |
554 | ### Save main settings | |
555 | ### | |
556 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { | |
624615ee LS |
557 | &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings); |
558 | ||
c7fe09c6 MT |
559 | if ($cgiparams{'RW_ENDPOINT'} ne '' && !&General::validip($cgiparams{'RW_ENDPOINT'}) && !&General::validfqdn($cgiparams{'RW_ENDPOINT'})) { |
560 | $errormessage = $Lang::tr{'ipsec invalid ip address or fqdn for rw endpoint'}; | |
561 | goto SAVE_ERROR; | |
562 | } | |
563 | ||
624615ee LS |
564 | if ( $cgiparams{'RW_NET'} ne '' and !&General::validipandmask($cgiparams{'RW_NET'}) ) { |
565 | $errormessage = $Lang::tr{'urlfilter invalid ip or mask error'}; | |
566 | goto SAVE_ERROR; | |
567 | } | |
568 | ||
569 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
c7fe09c6 | 570 | $vpnsettings{'RW_ENDPOINT'} = $cgiparams{'RW_ENDPOINT'}; |
624615ee LS |
571 | $vpnsettings{'RW_NET'} = $cgiparams{'RW_NET'}; |
572 | &General::writehash("${General::swroot}/vpn/settings", \%vpnsettings); | |
573 | &writeipsecfiles(); | |
574 | if (&vpnenabled) { | |
d22c7c10 | 575 | &General::system('/usr/local/bin/ipsecctrl', 'S'); |
624615ee | 576 | } else { |
d22c7c10 | 577 | &General::system('/usr/local/bin/ipsecctrl', 'D'); |
624615ee LS |
578 | } |
579 | sleep $sleepDelay; | |
580 | SAVE_ERROR: | |
ac1cfefa MT |
581 | ### |
582 | ### Reset all step 2 | |
583 | ### | |
ed84e8b8 | 584 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'} && $cgiparams{'AREUSURE'} eq 'yes') { |
624615ee LS |
585 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); |
586 | ||
587 | foreach my $key (keys %confighash) { | |
588 | if ($confighash{$key}[4] eq 'cert') { | |
589 | delete $confighash{$key}; | |
590 | } | |
591 | } | |
592 | while (my $file = glob("${General::swroot}/{ca,certs,crls,private}/*")) { | |
593 | unlink $file | |
594 | } | |
595 | &cleanssldatabase(); | |
596 | if (open(FILE, ">${General::swroot}/vpn/caconfig")) { | |
597 | print FILE ""; | |
598 | close FILE; | |
599 | } | |
600 | &General::writehasharray("${General::swroot}/vpn/config", \%confighash); | |
601 | &writeipsecfiles(); | |
a81cbf61 | 602 | &General::system('/usr/local/bin/ipsecctrl', 'R'); |
624615ee | 603 | sleep $sleepDelay; |
ac1cfefa MT |
604 | |
605 | ### | |
606 | ### Reset all step 1 | |
607 | ### | |
ed84e8b8 | 608 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'}) { |
624615ee LS |
609 | &Header::showhttpheaders(); |
610 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); | |
611 | &Header::openbigbox('100%', 'left', '', ''); | |
612 | &Header::openbox('100%', 'left', $Lang::tr{'are you sure'}); | |
613 | print <<END | |
ed84e8b8 | 614 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
624615ee LS |
615 | <table width='100%'> |
616 | <tr> | |
617 | <td align='center'> | |
618 | <input type='hidden' name='AREUSURE' value='yes' /> | |
619 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'} | |
620 | </td> | |
621 | </tr><tr> | |
622 | <td align='center'> | |
623 | <input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /> | |
ed84e8b8 | 624 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td> |
624615ee LS |
625 | </tr> |
626 | </table> | |
ed84e8b8 | 627 | </form> |
ac1cfefa | 628 | END |
624615ee LS |
629 | ; |
630 | &Header::closebox(); | |
631 | &Header::closebigbox(); | |
632 | &Header::closepage(); | |
633 | exit (0); | |
ac1cfefa MT |
634 | |
635 | ### | |
636 | ### Upload CA Certificate | |
637 | ### | |
638 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
624615ee LS |
639 | &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash); |
640 | ||
641 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
642 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
643 | goto UPLOADCA_ERROR; | |
644 | } | |
645 | ||
646 | if (length($cgiparams{'CA_NAME'}) >60) { | |
647 | $errormessage = $Lang::tr{'name too long'}; | |
648 | goto VPNCONF_ERROR; | |
649 | } | |
650 | ||
651 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
652 | $errormessage = $Lang::tr{'name is invalid'}; | |
653 | goto UPLOAD_CA_ERROR; | |
654 | } | |
655 | ||
656 | # Check if there is no other entry with this name | |
657 | foreach my $key (keys %cahash) { | |
658 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { | |
659 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
660 | goto UPLOADCA_ERROR; | |
661 | } | |
662 | } | |
663 | ||
2ad1b18b | 664 | unless (ref ($cgiparams{'FH'})) { |
624615ee LS |
665 | $errormessage = $Lang::tr{'there was no file upload'}; |
666 | goto UPLOADCA_ERROR; | |
667 | } | |
668 | # Move uploaded ca to a temporary file | |
669 | (my $fh, my $filename) = tempfile( ); | |
670 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
671 | $errormessage = $!; | |
672 | goto UPLOADCA_ERROR; | |
673 | } | |
b71a7fb9 MT |
674 | my $temp = `/usr/bin/openssl x509 -text -in $filename`; |
675 | if ($temp !~ /CA:TRUE/i) { | |
624615ee LS |
676 | $errormessage = $Lang::tr{'not a valid ca certificate'}; |
677 | unlink ($filename); | |
678 | goto UPLOADCA_ERROR; | |
679 | } else { | |
b5b19f37 | 680 | unless(move($filename, "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem")) { |
624615ee LS |
681 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; |
682 | unlink ($filename); | |
683 | goto UPLOADCA_ERROR; | |
684 | } | |
685 | } | |
686 | ||
687 | my $key = &General::findhasharraykey (\%cahash); | |
688 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
689 | $cahash{$key}[1] = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem")); | |
690 | &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash); | |
691 | ||
a81cbf61 | 692 | &General::system('/usr/local/bin/ipsecctrl', 'R'); |
624615ee LS |
693 | sleep $sleepDelay; |
694 | ||
695 | UPLOADCA_ERROR: | |
ac1cfefa MT |
696 | |
697 | ### | |
698 | ### Display ca certificate | |
699 | ### | |
700 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
624615ee LS |
701 | &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash); |
702 | ||
703 | if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
704 | &Header::showhttpheaders(); | |
705 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); | |
706 | &Header::openbigbox('100%', 'left', '', ''); | |
707 | &Header::openbox('100%', 'left', "$Lang::tr{'ca certificate'}:"); | |
a81cbf61 | 708 | my @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); |
c64dc3be MT |
709 | my $output = &Header::cleanhtml(join("", @output) ,"y"); |
710 | print "<pre>$output</pre>\n"; | |
624615ee LS |
711 | &Header::closebox(); |
712 | print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
713 | &Header::closebigbox(); | |
714 | &Header::closepage(); | |
715 | exit(0); | |
716 | } else { | |
717 | $errormessage = $Lang::tr{'invalid key'}; | |
718 | } | |
ac1cfefa MT |
719 | |
720 | ### | |
ed84e8b8 | 721 | ### Export ca certificate to browser |
ac1cfefa MT |
722 | ### |
723 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
624615ee LS |
724 | &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash); |
725 | ||
726 | if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
727 | print "Content-Type: application/force-download\n"; | |
728 | print "Content-Type: application/octet-stream\r\n"; | |
729 | print "Content-Disposition: attachment; filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
a81cbf61 SS |
730 | |
731 | my @cert = &General::system_output("/usr/bin/openssl", "x509", "-in", "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
732 | print "@cert"; | |
624615ee LS |
733 | exit(0); |
734 | } else { | |
735 | $errormessage = $Lang::tr{'invalid key'}; | |
736 | } | |
ac1cfefa MT |
737 | |
738 | ### | |
739 | ### Remove ca certificate (step 2) | |
740 | ### | |
741 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
624615ee LS |
742 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); |
743 | &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash); | |
744 | ||
745 | if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
746 | foreach my $key (keys %confighash) { | |
a81cbf61 SS |
747 | my @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem", "${General::swroot}/certs/$confighash{$key}[1]cert.pem"); |
748 | if (grep(/: OK/, @test)) { | |
624615ee | 749 | # Delete connection |
624615ee LS |
750 | unlink ("${General::swroot}/certs/$confighash{$key}[1]cert.pem"); |
751 | unlink ("${General::swroot}/certs/$confighash{$key}[1].p12"); | |
752 | delete $confighash{$key}; | |
753 | &General::writehasharray("${General::swroot}/vpn/config", \%confighash); | |
754 | &writeipsecfiles(); | |
a81cbf61 | 755 | &General::system('/usr/local/bin/ipsecctrl', 'D', $key) if (&vpnenabled); |
624615ee LS |
756 | } |
757 | } | |
758 | unlink ("${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
759 | delete $cahash{$cgiparams{'KEY'}}; | |
760 | &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash); | |
a81cbf61 | 761 | &General::system('/usr/local/bin/ipsecctrl', 'R'); |
624615ee LS |
762 | sleep $sleepDelay; |
763 | } else { | |
764 | $errormessage = $Lang::tr{'invalid key'}; | |
ac1cfefa | 765 | } |
ac1cfefa MT |
766 | ### |
767 | ### Remove ca certificate (step 1) | |
768 | ### | |
769 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
624615ee LS |
770 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); |
771 | &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash); | |
772 | ||
773 | my $assignedcerts = 0; | |
774 | if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
775 | foreach my $key (keys %confighash) { | |
a81cbf61 SS |
776 | my @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem", "${General::swroot}/certs/$confighash{$key}[1]cert.pem"); |
777 | if (grep(/: OK/, @test)) { | |
624615ee LS |
778 | $assignedcerts++; |
779 | } | |
780 | } | |
781 | if ($assignedcerts) { | |
782 | &Header::showhttpheaders(); | |
783 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); | |
784 | &Header::openbigbox('100%', 'left', '', ''); | |
785 | &Header::openbox('100%', 'left', $Lang::tr{'are you sure'}); | |
786 | print <<END | |
787 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
788 | <table width='100%'> | |
789 | <tr> | |
790 | <td align='center'> | |
791 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
792 | <input type='hidden' name='AREUSURE' value='yes' /></td> | |
793 | </tr><tr> | |
794 | <td align='center'> | |
795 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b> $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}</td> | |
796 | </tr><tr> | |
797 | <td align='center'> | |
798 | <input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
799 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td> | |
800 | </tr> | |
801 | </table> | |
802 | </form> | |
ac1cfefa | 803 | END |
624615ee LS |
804 | ; |
805 | &Header::closebox(); | |
806 | &Header::closebigbox(); | |
807 | &Header::closepage(); | |
808 | exit (0); | |
809 | } else { | |
810 | unlink ("${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
811 | delete $cahash{$cgiparams{'KEY'}}; | |
812 | &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash); | |
a81cbf61 | 813 | &General::system('/usr/local/bin/ipsecctrl', 'R'); |
624615ee LS |
814 | sleep $sleepDelay; |
815 | } | |
ac1cfefa | 816 | } else { |
624615ee | 817 | $errormessage = $Lang::tr{'invalid key'}; |
ac1cfefa | 818 | } |
ac1cfefa MT |
819 | |
820 | ### | |
821 | ### Display root certificate | |
822 | ### | |
823 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || | |
824 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
a81cbf61 | 825 | my @output; |
624615ee LS |
826 | &Header::showhttpheaders(); |
827 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); | |
828 | &Header::openbigbox('100%', 'left', '', ''); | |
829 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
830 | &Header::openbox('100%', 'left', "$Lang::tr{'root certificate'}:"); | |
a81cbf61 | 831 | @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ca/cacert.pem"); |
624615ee LS |
832 | } else { |
833 | &Header::openbox('100%', 'left', "$Lang::tr{'host certificate'}:"); | |
a81cbf61 | 834 | @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/certs/hostcert.pem"); |
624615ee | 835 | } |
c64dc3be MT |
836 | my $output = &Header::cleanhtml(join("", @output) ,"y"); |
837 | print "<pre>$output</pre>\n"; | |
624615ee LS |
838 | &Header::closebox(); |
839 | print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
840 | &Header::closebigbox(); | |
841 | &Header::closepage(); | |
842 | exit(0); | |
ac1cfefa MT |
843 | |
844 | ### | |
ed84e8b8 | 845 | ### Export root certificate to browser |
ac1cfefa MT |
846 | ### |
847 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
624615ee LS |
848 | if ( -f "${General::swroot}/ca/cacert.pem" ) { |
849 | print "Content-Type: application/force-download\n"; | |
850 | print "Content-Disposition: attachment; filename=cacert.pem\r\n\r\n"; | |
a81cbf61 SS |
851 | |
852 | my @cert = &General::system_output("/usr/bin/openssl", "x509", "-in", "${General::swroot}/ca/cacert.pem"); | |
6688e0bc | 853 | print join("", @cert); |
624615ee LS |
854 | exit(0); |
855 | } | |
ac1cfefa | 856 | ### |
ed84e8b8 | 857 | ### Export host certificate to browser |
ac1cfefa MT |
858 | ### |
859 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
624615ee LS |
860 | if ( -f "${General::swroot}/certs/hostcert.pem" ) { |
861 | print "Content-Type: application/force-download\n"; | |
862 | print "Content-Disposition: attachment; filename=hostcert.pem\r\n\r\n"; | |
a81cbf61 SS |
863 | |
864 | my @cert = &General::system_output("/usr/bin/openssl", "x509", "-in", "${General::swroot}/certs/hostcert.pem"); | |
6688e0bc | 865 | print join("", @cert); |
624615ee LS |
866 | exit(0); |
867 | } | |
ac1cfefa | 868 | ### |
9f010115 MT |
869 | ### Regenerate the host certificate |
870 | ### | |
871 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'regenerate host certificate'}) { | |
872 | $errormessage = ®enerate_host_certificate(); | |
873 | ||
874 | ### | |
ed84e8b8 | 875 | ### Form for generating/importing the caroot+host certificate |
ac1cfefa MT |
876 | ### |
877 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
624615ee LS |
878 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { |
879 | ||
0746122a AB |
880 | &newcleanssldatabase(); |
881 | ||
624615ee LS |
882 | if (-f "${General::swroot}/ca/cacert.pem") { |
883 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
884 | goto ROOTCERT_SKIP; | |
885 | } | |
886 | ||
887 | &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings); | |
888 | # fill in initial values | |
889 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
890 | if (-e "${General::swroot}/red/active" && open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
891 | my $ipaddr = <IPADDR>; | |
892 | close IPADDR; | |
893 | chomp ($ipaddr); | |
894 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
993724b4 | 895 | $cgiparams{'SUBJECTALTNAME'} = "DNS:" . $cgiparams{'ROOTCERT_HOSTNAME'}; |
624615ee LS |
896 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { |
897 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
993724b4 | 898 | $cgiparams{'SUBJECTALTNAME'} = "IP:" . $cgiparams{'ROOTCERT_HOSTNAME'}; |
624615ee LS |
899 | } |
900 | } | |
901 | $cgiparams{'ROOTCERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'} if (!$cgiparams{'ROOTCERT_COUNTRY'}); | |
902 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
903 | &General::log("ipsec", "Importing from p12..."); | |
ac1cfefa | 904 | |
2ad1b18b | 905 | unless (ref ($cgiparams{'FH'})) { |
624615ee LS |
906 | $errormessage = $Lang::tr{'there was no file upload'}; |
907 | goto ROOTCERT_ERROR; | |
908 | } | |
ac1cfefa | 909 | |
624615ee LS |
910 | # Move uploaded certificate request to a temporary file |
911 | (my $fh, my $filename) = tempfile( ); | |
912 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
913 | $errormessage = $!; | |
914 | goto ROOTCERT_ERROR; | |
915 | } | |
ac1cfefa | 916 | |
624615ee LS |
917 | # Extract the CA certificate from the file |
918 | &General::log("ipsec", "Extracting caroot from p12..."); | |
919 | if (open(STDIN, "-|")) { | |
94aa82fa | 920 | my $opt = " pkcs12 -legacy -cacerts -nokeys"; |
624615ee LS |
921 | $opt .= " -in $filename"; |
922 | $opt .= " -out /tmp/newcacert"; | |
923 | $errormessage = &callssl ($opt); | |
924 | } else { #child | |
925 | print "$cgiparams{'P12_PASS'}\n"; | |
926 | exit (0); | |
927 | } | |
ac1cfefa | 928 | |
624615ee LS |
929 | # Extract the Host certificate from the file |
930 | if (!$errormessage) { | |
931 | &General::log("ipsec", "Extracting host cert from p12..."); | |
932 | if (open(STDIN, "-|")) { | |
94aa82fa | 933 | my $opt = " pkcs12 -legacy -clcerts -nokeys"; |
624615ee LS |
934 | $opt .= " -in $filename"; |
935 | $opt .= " -out /tmp/newhostcert"; | |
936 | $errormessage = &callssl ($opt); | |
937 | } else { #child | |
938 | print "$cgiparams{'P12_PASS'}\n"; | |
939 | exit (0); | |
940 | } | |
941 | } | |
ed84e8b8 | 942 | |
624615ee LS |
943 | # Extract the Host key from the file |
944 | if (!$errormessage) { | |
945 | &General::log("ipsec", "Extracting private key from p12..."); | |
946 | if (open(STDIN, "-|")) { | |
94aa82fa | 947 | my $opt = " pkcs12 -legacy -nocerts -nodes"; |
624615ee LS |
948 | $opt .= " -in $filename"; |
949 | $opt .= " -out /tmp/newhostkey"; | |
950 | $errormessage = &callssl ($opt); | |
951 | } else { #child | |
952 | print "$cgiparams{'P12_PASS'}\n"; | |
953 | exit (0); | |
954 | } | |
955 | } | |
ac1cfefa | 956 | |
624615ee LS |
957 | if (!$errormessage) { |
958 | &General::log("ipsec", "Moving cacert..."); | |
b5b19f37 SS |
959 | unless(move("/tmp/newcacert", "${General::swroot}/ca/cacert.pem")) { |
960 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
961 | } | |
624615ee | 962 | } |
ed84e8b8 | 963 | |
624615ee LS |
964 | if (!$errormessage) { |
965 | &General::log("ipsec", "Moving host cert..."); | |
b5b19f37 SS |
966 | unless(move("/tmp/newhostcert", "${General::swroot}/certs/hostcert.pem")) { |
967 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
968 | } | |
624615ee | 969 | } |
ed84e8b8 | 970 | |
624615ee LS |
971 | if (!$errormessage) { |
972 | &General::log("ipsec", "Moving private key..."); | |
b5b19f37 SS |
973 | unless(move("/tmp/newhostkey", "${General::swroot}/certs/hostkey.pem")) { |
974 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
975 | } | |
624615ee LS |
976 | } |
977 | ||
978 | #cleanup temp files | |
979 | unlink ($filename); | |
980 | unlink ('/tmp/newcacert'); | |
981 | unlink ('/tmp/newhostcert'); | |
982 | unlink ('/tmp/newhostkey'); | |
983 | if ($errormessage) { | |
984 | unlink ("${General::swroot}/ca/cacert.pem"); | |
985 | unlink ("${General::swroot}/certs/hostcert.pem"); | |
986 | unlink ("${General::swroot}/certs/hostkey.pem"); | |
987 | goto ROOTCERT_ERROR; | |
988 | } | |
989 | ||
990 | # Create empty CRL cannot be done because we don't have | |
991 | # the private key for this CAROOT | |
992 | # IPFire can only import certificates | |
993 | ||
994 | &General::log("ipsec", "p12 import completed!"); | |
995 | &cleanssldatabase(); | |
996 | goto ROOTCERT_SUCCESS; | |
997 | ||
998 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
999 | ||
1000 | # Validate input since the form was submitted | |
1001 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1002 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1003 | goto ROOTCERT_ERROR; | |
1004 | } | |
1005 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1006 | $errormessage = $Lang::tr{'organization too long'}; | |
1007 | goto ROOTCERT_ERROR; | |
1008 | } | |
1009 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1010 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1011 | goto ROOTCERT_ERROR; | |
1012 | } | |
1013 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1014 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1015 | goto ROOTCERT_ERROR; | |
1016 | } | |
1017 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1018 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1019 | goto ROOTCERT_ERROR; | |
1020 | } | |
1021 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1022 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1023 | goto ROOTCERT_ERROR; | |
1024 | } | |
1025 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1026 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1027 | goto ROOTCERT_ERROR; | |
1028 | } | |
1029 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1030 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1031 | goto ROOTCERT_ERROR; | |
1032 | } | |
1033 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1034 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1035 | goto ROOTCERT_ERROR; | |
1036 | } | |
1037 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1038 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1039 | goto ROOTCERT_ERROR; | |
1040 | } | |
1041 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1042 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1043 | goto ROOTCERT_ERROR; | |
1044 | } | |
1045 | #the exact syntax is a list comma separated of | |
1046 | # email:any-validemail | |
1047 | # URI: a uniform resource indicator | |
1048 | # DNS: a DNS domain name | |
1049 | # RID: a registered OBJECT IDENTIFIER | |
1050 | # IP: an IP address | |
1051 | # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com | |
1052 | ||
993724b4 PM |
1053 | if ($cgiparams{'SUBJECTALTNAME'} eq '') { |
1054 | $errormessage = $Lang::tr{'vpn subjectaltname missing'}; | |
1055 | goto ROOTCERT_ERROR; | |
1056 | } | |
1057 | ||
624615ee LS |
1058 | if ($cgiparams{'SUBJECTALTNAME'} ne '' && $cgiparams{'SUBJECTALTNAME'} !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/,\.\-_@]*$/) { |
1059 | $errormessage = $Lang::tr{'vpn altname syntax'}; | |
1060 | goto VPNCONF_ERROR; | |
1061 | } | |
1062 | ||
1063 | # Copy the cgisettings to vpnsettings and save the configfile | |
1064 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1065 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1066 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1067 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1068 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1069 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1070 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1071 | &General::writehash("${General::swroot}/vpn/settings", \%vpnsettings); | |
1072 | ||
1073 | # Replace empty strings with a . | |
1074 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1075 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1076 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1077 | ||
1078 | # Create the CA certificate | |
1079 | if (!$errormessage) { | |
1080 | &General::log("ipsec", "Creating cacert..."); | |
1081 | if (open(STDIN, "-|")) { | |
1082 | my $opt = " req -x509 -sha256 -nodes"; | |
926e5519 | 1083 | $opt .= " -days 3650"; |
624615ee LS |
1084 | $opt .= " -newkey rsa:4096"; |
1085 | $opt .= " -keyout ${General::swroot}/private/cakey.pem"; | |
1086 | $opt .= " -out ${General::swroot}/ca/cacert.pem"; | |
1087 | ||
1088 | $errormessage = &callssl ($opt); | |
1089 | } else { #child | |
1090 | print "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1091 | print "$state\n"; | |
1092 | print "$city\n"; | |
1093 | print "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1094 | print "$ou\n"; | |
1095 | print "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1096 | print "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1097 | exit (0); | |
1098 | } | |
1099 | } | |
1100 | ||
1101 | # Create the Host certificate request | |
1102 | if (!$errormessage) { | |
1103 | &General::log("ipsec", "Creating host cert..."); | |
1104 | if (open(STDIN, "-|")) { | |
1105 | my $opt = " req -sha256 -nodes"; | |
818dde8e | 1106 | $opt .= " -newkey rsa:4096"; |
624615ee LS |
1107 | $opt .= " -keyout ${General::swroot}/certs/hostkey.pem"; |
1108 | $opt .= " -out ${General::swroot}/certs/hostreq.pem"; | |
1109 | $errormessage = &callssl ($opt); | |
1110 | } else { #child | |
1111 | print "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1112 | print "$state\n"; | |
1113 | print "$city\n"; | |
1114 | print "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1115 | print "$ou\n"; | |
1116 | print "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1117 | print "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1118 | print ".\n"; | |
1119 | print ".\n"; | |
1120 | exit (0); | |
1121 | } | |
1122 | } | |
1123 | ||
1124 | # Sign the host certificate request | |
1125 | if (!$errormessage) { | |
1126 | &General::log("ipsec", "Self signing host cert..."); | |
1127 | ||
1128 | #No easy way for specifying the contain of subjectAltName without writing a config file... | |
1129 | my ($fh, $v3extname) = tempfile ('/tmp/XXXXXXXX'); | |
1130 | print $fh <<END | |
1131 | basicConstraints=CA:FALSE | |
1132 | nsComment="OpenSSL Generated Certificate" | |
1133 | subjectKeyIdentifier=hash | |
1134 | authorityKeyIdentifier=keyid,issuer:always | |
1135 | extendedKeyUsage = serverAuth | |
ed84e8b8 MT |
1136 | END |
1137 | ; | |
624615ee LS |
1138 | print $fh "subjectAltName=$cgiparams{'SUBJECTALTNAME'}" if ($cgiparams{'SUBJECTALTNAME'}); |
1139 | close ($fh); | |
1140 | ||
926e5519 | 1141 | my $opt = " ca -md sha256 -days 825"; |
624615ee LS |
1142 | $opt .= " -batch -notext"; |
1143 | $opt .= " -in ${General::swroot}/certs/hostreq.pem"; | |
1144 | $opt .= " -out ${General::swroot}/certs/hostcert.pem"; | |
1145 | $opt .= " -extfile $v3extname"; | |
1146 | $errormessage = &callssl ($opt); | |
1147 | unlink ("${General::swroot}/certs/hostreq.pem"); #no more needed | |
1148 | unlink ($v3extname); | |
1149 | } | |
1150 | ||
1151 | # Create an empty CRL | |
1152 | if (!$errormessage) { | |
1153 | &General::log("ipsec", "Creating emptycrl..."); | |
1154 | my $opt = " ca -gencrl"; | |
1155 | $opt .= " -out ${General::swroot}/crls/cacrl.pem"; | |
1156 | $errormessage = &callssl ($opt); | |
1157 | } | |
1158 | ||
1159 | # Successfully build CA / CERT! | |
1160 | if (!$errormessage) { | |
1161 | &cleanssldatabase(); | |
1162 | goto ROOTCERT_SUCCESS; | |
1163 | } | |
1164 | ||
1165 | #Cleanup | |
1166 | unlink ("${General::swroot}/ca/cacert.pem"); | |
1167 | unlink ("${General::swroot}/certs/hostkey.pem"); | |
1168 | unlink ("${General::swroot}/certs/hostcert.pem"); | |
1169 | unlink ("${General::swroot}/crls/cacrl.pem"); | |
1170 | &cleanssldatabase(); | |
1171 | } | |
1172 | ||
1173 | ROOTCERT_ERROR: | |
1174 | &Header::showhttpheaders(); | |
1175 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); | |
1176 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
1177 | if ($errormessage) { | |
1178 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
1179 | print "<class name='base'>$errormessage"; | |
1180 | print " </class>"; | |
1181 | &Header::closebox(); | |
1182 | } | |
1183 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
1184 | print <<END | |
1185 | <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'> | |
1186 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
1187 | <tr><td width='40%' class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td> | |
1188 | <td width='60%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td></tr> | |
1189 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td> | |
1190 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td></tr> | |
1191 | <tr><td class='base'>$Lang::tr{'your e-mail'}:</td> | |
1192 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td></tr> | |
1193 | <tr><td class='base'>$Lang::tr{'your department'}:</td> | |
1194 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td></tr> | |
1195 | <tr><td class='base'>$Lang::tr{'city'}:</td> | |
1196 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td></tr> | |
1197 | <tr><td class='base'>$Lang::tr{'state or province'}:</td> | |
1198 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td></tr> | |
1199 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
1200 | <td class='base'><select name='ROOTCERT_COUNTRY'> | |
ac1cfefa | 1201 | END |
624615ee LS |
1202 | ; |
1203 | foreach my $country (sort keys %{Countries::countries}) { | |
1204 | print "<option value='$Countries::countries{$country}'"; | |
1205 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
1206 | print " selected='selected'"; | |
1207 | } | |
1208 | print ">$country</option>"; | |
1209 | } | |
1210 | print <<END | |
1211 | </select></td></tr> | |
993724b4 | 1212 | <tr><td class='base'>$Lang::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*) <img src='/blob.gif' alt='*' /></td> |
ed84e8b8 | 1213 | <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value='$cgiparams{'SUBJECTALTNAME'}' size='32' /></td></tr> |
624615ee LS |
1214 | <tr><td> </td> |
1215 | <td><br /><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /><br /><br /></td></tr> | |
1216 | <tr><td class='base' colspan='2' align='left'> | |
1217 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: | |
1218 | $Lang::tr{'generating the root and host certificates may take a long time. it can take up to several minutes on older hardware. please be patient'} | |
1219 | </td></tr> | |
1220 | <tr><td colspan='2'><hr></td></tr> | |
1221 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td> | |
1222 | <td nowrap='nowrap'><input type='file' name='FH' size='32' /></td></tr> | |
1223 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:</td> | |
1224 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td></tr> | |
1225 | <tr><td> </td> | |
1226 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td></tr> | |
1227 | <tr><td class='base' colspan='2' align='left'> | |
1228 | <img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td></tr> | |
1229 | </table></form> | |
ed84e8b8 | 1230 | END |
624615ee LS |
1231 | ; |
1232 | &Header::closebox(); | |
1233 | &Header::closebigbox(); | |
1234 | &Header::closepage(); | |
1235 | exit(0); | |
1236 | ||
1237 | ROOTCERT_SUCCESS: | |
1238 | if (&vpnenabled) { | |
a81cbf61 | 1239 | &General::system('/usr/local/bin/ipsecctrl', 'S'); |
624615ee LS |
1240 | sleep $sleepDelay; |
1241 | } | |
1242 | ROOTCERT_SKIP: | |
ac1cfefa | 1243 | ### |
ed84e8b8 | 1244 | ### Export PKCS12 file to browser |
ac1cfefa MT |
1245 | ### |
1246 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
624615ee LS |
1247 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); |
1248 | print "Content-Type: application/force-download\n"; | |
1249 | print "Content-Disposition: attachment; filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
1250 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
a81cbf61 SS |
1251 | |
1252 | open(FILE, "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
1253 | my @p12 = <FILE>; | |
1254 | close(FILE); | |
f8384fbf | 1255 | print join("", @p12); |
a81cbf61 | 1256 | |
624615ee | 1257 | exit (0); |
ac1cfefa | 1258 | |
26a0befd MT |
1259 | # Export Apple profile to browser |
1260 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download apple profile'}) { | |
c7fe09c6 MT |
1261 | # Read global configuration |
1262 | &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings); | |
1263 | ||
1264 | # Read connections | |
26a0befd MT |
1265 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); |
1266 | my $key = $cgiparams{'KEY'}; | |
1267 | ||
205c3c17 MT |
1268 | # Create a UUID generator |
1269 | my $uuid = Data::UUID->new(); | |
1270 | ||
1271 | my $uuid1 = $uuid->create_str(); | |
1272 | my $uuid2 = $uuid->create_str(); | |
26a0befd | 1273 | |
db33a122 MT |
1274 | my $ca = ""; |
1275 | my $ca_uuid = $uuid->create_str(); | |
1276 | ||
26a0befd | 1277 | my $cert = ""; |
205c3c17 | 1278 | my $cert_uuid = $uuid->create_str(); |
26a0befd | 1279 | |
db33a122 | 1280 | # Read and encode the CA & certificate |
26a0befd | 1281 | if ($confighash{$key}[4] eq "cert") { |
db33a122 | 1282 | my $ca_path = "${General::swroot}/ca/cacert.pem"; |
26a0befd MT |
1283 | my $cert_path = "${General::swroot}/certs/$confighash{$key}[1].p12"; |
1284 | ||
db33a122 MT |
1285 | # Read the CA and encode it into Base64 |
1286 | open(CA, "<${ca_path}"); | |
1287 | local($/) = undef; # slurp | |
1288 | $ca = MIME::Base64::encode_base64(<CA>); | |
1289 | close(CA); | |
1290 | ||
26a0befd MT |
1291 | # Read certificate and encode it into Base64 |
1292 | open(CERT, "<${cert_path}"); | |
1293 | local($/) = undef; # slurp | |
1294 | $cert = MIME::Base64::encode_base64(<CERT>); | |
1295 | close(CERT); | |
1296 | } | |
1297 | ||
1298 | print "Content-Type: application/octet-stream\n"; | |
1299 | print "Content-Disposition: attachment; filename=" . $confighash{$key}[1] . ".mobileconfig\n"; | |
1300 | print "\n"; # end headers | |
1301 | ||
c7fe09c6 MT |
1302 | # Use our own FQDN if nothing else is configured |
1303 | my $endpoint = ($vpnsettings{'RW_ENDPOINT'} ne "") ? $vpnsettings{'RW_ENDPOINT'} : &hostname(); | |
1304 | ||
26a0befd MT |
1305 | print "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"; |
1306 | print "<plist version=\"1.0\">\n"; | |
1307 | print " <dict>\n"; | |
1308 | print " <key>PayloadDisplayName</key>\n"; | |
1309 | print " <string>$confighash{$key}[1]</string>\n"; | |
1310 | print " <key>PayloadIdentifier</key>\n"; | |
1311 | print " <string>$confighash{$key}[1]</string>\n"; | |
1312 | print " <key>PayloadUUID</key>\n"; | |
1313 | print " <string>${uuid1}</string>\n"; | |
1314 | print " <key>PayloadType</key>\n"; | |
1315 | print " <string>Configuration</string>\n"; | |
1316 | print " <key>PayloadVersion</key>\n"; | |
1317 | print " <integer>1</integer>\n"; | |
1318 | print " <key>PayloadContent</key>\n"; | |
1319 | print " <array>\n"; | |
1320 | print " <dict>\n"; | |
1321 | print " <key>PayloadIdentifier</key>\n"; | |
1322 | print " <string>org.example.vpn1.conf1</string>\n"; | |
1323 | print " <key>PayloadUUID</key>\n"; | |
1324 | print " <string>${uuid2}</string>\n"; | |
1325 | print " <key>PayloadType</key>\n"; | |
1326 | print " <string>com.apple.vpn.managed</string>\n"; | |
1327 | print " <key>PayloadVersion</key>\n"; | |
1328 | print " <integer>1</integer>\n"; | |
1329 | print " <key>UserDefinedName</key>\n"; | |
1330 | print " <string>$confighash{$key}[1]</string>\n"; | |
1331 | print " <key>VPNType</key>\n"; | |
1332 | print " <string>IKEv2</string>\n"; | |
1333 | print " <key>IKEv2</key>\n"; | |
1334 | print " <dict>\n"; | |
1335 | print " <key>RemoteAddress</key>\n"; | |
c7fe09c6 | 1336 | print " <string>$endpoint</string>\n"; |
26a0befd | 1337 | |
b75d9210 MT |
1338 | # PFS |
1339 | my $pfs = $confighash{$key}[28]; | |
1340 | if ($pfs eq "on") { | |
1341 | print " <key>EnablePFS</key>\n"; | |
1342 | print " <true/>\n"; | |
1343 | } | |
1344 | ||
2d7b3347 MT |
1345 | # IKE Cipher Suite |
1346 | print " <key>IKESecurityAssociationParameters</key>\n"; | |
1347 | print " <dict>\n"; | |
1348 | ||
1349 | # Encryption | |
1350 | foreach my $cipher (split(/\|/,$confighash{$key}[18])) { | |
1351 | # Skip all unsupported ciphers | |
1352 | next unless (exists $APPLE_CIPHERS{$cipher}); | |
1353 | ||
1354 | print " <key>EncryptionAlgorithm</key>\n"; | |
1355 | print " <string>$APPLE_CIPHERS{$cipher}</string>\n"; | |
1356 | last; | |
1357 | } | |
1358 | ||
1359 | # Integrity | |
1360 | foreach my $integrity (split(/\|/,$confighash{$key}[19])) { | |
1361 | # Skip all unsupported algorithms | |
1362 | next unless (exists $APPLE_INTEGRITIES{$integrity}); | |
1363 | ||
1364 | print " <key>IntegrityAlgorithm</key>\n"; | |
1365 | print " <string>$APPLE_INTEGRITIES{$integrity}</string>\n"; | |
1366 | last; | |
1367 | } | |
1368 | ||
1369 | # Diffie Hellman Groups | |
1370 | foreach my $group (split(/\|/,$confighash{$key}[20])) { | |
1371 | # Skip all unsupported algorithms | |
1372 | next unless (exists $APPLE_DH_GROUPS{$group}); | |
1373 | ||
1374 | print " <key>DiffieHellmanGroup</key>\n"; | |
1375 | print " <string>$APPLE_DH_GROUPS{$group}</string>\n"; | |
1376 | last; | |
1377 | } | |
1378 | ||
1379 | # Lifetime | |
1380 | my $lifetime = $confighash{$key}[16] * 60; | |
1381 | print " <key>LifeTimeInMinutes</key>\n"; | |
1382 | print " <integer>$lifetime</integer>\n"; | |
1383 | print " </dict>\n"; | |
1384 | ||
1385 | # ESP Cipher Suite | |
1386 | print " <key>ChildSecurityAssociationParameters</key>\n"; | |
1387 | print " <dict>\n"; | |
1388 | ||
1389 | # Encryption | |
1390 | foreach my $cipher (split(/\|/,$confighash{$key}[21])) { | |
1391 | # Skip all unsupported ciphers | |
1392 | next unless (exists $APPLE_CIPHERS{$cipher}); | |
1393 | ||
1394 | print " <key>EncryptionAlgorithm</key>\n"; | |
1395 | print " <string>$APPLE_CIPHERS{$cipher}</string>\n"; | |
1396 | last; | |
1397 | } | |
1398 | ||
1399 | # Integrity | |
1400 | foreach my $integrity (split(/\|/,$confighash{$key}[22])) { | |
1401 | # Skip all unsupported algorithms | |
1402 | next unless (exists $APPLE_INTEGRITIES{$integrity}); | |
1403 | ||
1404 | print " <key>IntegrityAlgorithm</key>\n"; | |
1405 | print " <string>$APPLE_INTEGRITIES{$integrity}</string>\n"; | |
1406 | last; | |
1407 | } | |
1408 | ||
1409 | # Diffie Hellman Groups | |
1410 | foreach my $group (split(/\|/,$confighash{$key}[23])) { | |
1411 | # Skip all unsupported algorithms | |
1412 | next unless (exists $APPLE_DH_GROUPS{$group}); | |
1413 | ||
1414 | print " <key>DiffieHellmanGroup</key>\n"; | |
1415 | print " <string>$APPLE_DH_GROUPS{$group}</string>\n"; | |
1416 | last; | |
1417 | } | |
1418 | ||
1419 | # Lifetime | |
1420 | my $lifetime = $confighash{$key}[17] * 60; | |
1421 | print " <key>LifeTimeInMinutes</key>\n"; | |
1422 | print " <integer>$lifetime</integer>\n"; | |
1423 | print " </dict>\n"; | |
1424 | ||
1425 | ||
26a0befd MT |
1426 | # Left ID |
1427 | if ($confighash{$key}[9]) { | |
1108156c MT |
1428 | my $leftid = $confighash{$key}[9]; |
1429 | ||
1430 | # Strip leading @ from FQDNs | |
1431 | if ($leftid =~ m/^@(.*)$/) { | |
1432 | $leftid = $1; | |
1433 | } | |
1434 | ||
f3567364 | 1435 | print " <key>LocalIdentifier</key>\n"; |
1108156c | 1436 | print " <string>$leftid</string>\n"; |
26a0befd MT |
1437 | } |
1438 | ||
1439 | # Right ID | |
1440 | if ($confighash{$key}[7]) { | |
1108156c MT |
1441 | my $rightid = $confighash{$key}[7]; |
1442 | ||
1443 | # Strip leading @ from FQDNs | |
1444 | if ($rightid =~ m/^@(.*)$/) { | |
1445 | $rightid = $1; | |
1446 | } | |
1447 | ||
f3567364 | 1448 | print " <key>RemoteIdentifier</key>\n"; |
1108156c | 1449 | print " <string>$rightid</string>\n"; |
26a0befd MT |
1450 | } |
1451 | ||
1452 | if ($confighash{$key}[4] eq "cert") { | |
f3567364 MT |
1453 | print " <key>AuthenticationMethod</key>\n"; |
1454 | print " <string>Certificate</string>\n"; | |
26a0befd | 1455 | |
f3567364 MT |
1456 | print " <key>PayloadCertificateUUID</key>\n"; |
1457 | print " <string>${cert_uuid}</string>\n"; | |
26a0befd | 1458 | } else { |
f3567364 MT |
1459 | print " <key>AuthenticationMethod</key>\n"; |
1460 | print " <string>SharedSecret</string>\n"; | |
1461 | print " <key>SharedSecret</key>\n"; | |
1462 | print " <string>$confighash{$key}[5]</string>\n"; | |
26a0befd MT |
1463 | } |
1464 | ||
1465 | print " <key>ExtendedAuthEnabled</key>\n"; | |
1466 | print " <integer>0</integer>\n"; | |
5b2e16dd | 1467 | |
08fa1272 MT |
1468 | # These are not needed, but we provide some default to stop iPhone asking for credentials |
1469 | print " <key>AuthName</key>\n"; | |
1470 | print " <string>$confighash{$key}[1]</string>\n"; | |
1471 | print " <key>AuthPassword</key>\n"; | |
1472 | print " <string></string>\n"; | |
26a0befd MT |
1473 | print " </dict>\n"; |
1474 | print " </dict>\n"; | |
1475 | ||
1476 | if ($confighash{$key}[4] eq "cert") { | |
1477 | print " <dict>\n"; | |
1478 | print " <key>PayloadIdentifier</key>\n"; | |
1479 | print " <string>org.example.vpn1.client</string>\n"; | |
839183d8 MT |
1480 | print " <key>PayloadDisplayName</key>\n"; |
1481 | print " <string>$confighash{$key}[1]</string>\n"; | |
26a0befd MT |
1482 | print " <key>PayloadUUID</key>\n"; |
1483 | print " <string>${cert_uuid}</string>\n"; | |
1484 | print " <key>PayloadType</key>\n"; | |
1485 | print " <string>com.apple.security.pkcs12</string>\n"; | |
1486 | print " <key>PayloadVersion</key>\n"; | |
1487 | print " <integer>1</integer>\n"; | |
1488 | print " <key>PayloadContent</key>\n"; | |
1489 | print " <data>\n"; | |
1490 | ||
1491 | foreach (split /\n/,${cert}) { | |
1492 | print " $_\n"; | |
1493 | } | |
1494 | ||
1495 | print " </data>\n"; | |
1496 | print " </dict>\n"; | |
db33a122 MT |
1497 | |
1498 | print " <dict>\n"; | |
1499 | print " <key>PayloadIdentifier</key>\n"; | |
1500 | print " <string>org.example.ca</string>\n"; | |
1501 | print " <key>PayloadUUID</key>\n"; | |
1502 | print " <string>${ca_uuid}</string>\n"; | |
1503 | print " <key>PayloadType</key>\n"; | |
1504 | print " <string>com.apple.security.root</string>\n"; | |
1505 | print " <key>PayloadVersion</key>\n"; | |
1506 | print " <integer>1</integer>\n"; | |
1507 | print " <key>PayloadContent</key>\n"; | |
1508 | print " <data>\n"; | |
1509 | ||
1510 | foreach (split /\n/,${ca}) { | |
1511 | print " $_\n"; | |
1512 | } | |
1513 | ||
1514 | print " </data>\n"; | |
1515 | print " </dict>\n"; | |
26a0befd MT |
1516 | } |
1517 | ||
1518 | print " </array>\n"; | |
1519 | print " </dict>\n"; | |
1520 | print "</plist>\n"; | |
1521 | ||
1522 | # Done | |
1523 | exit(0); | |
ac1cfefa MT |
1524 | ### |
1525 | ### Display certificate | |
1526 | ### | |
1527 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
624615ee LS |
1528 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); |
1529 | ||
1530 | if ( -f "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
1531 | &Header::showhttpheaders(); | |
1532 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); | |
1533 | &Header::openbigbox('100%', 'left', '', ''); | |
1534 | &Header::openbox('100%', 'left', "$Lang::tr{'cert'}:"); | |
a81cbf61 | 1535 | my @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); |
c64dc3be MT |
1536 | my $output = &Header::cleanhtml(join("", @output) ,"y"); |
1537 | print "<pre>$output</pre>\n"; | |
624615ee LS |
1538 | &Header::closebox(); |
1539 | print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1540 | &Header::closebigbox(); | |
1541 | &Header::closepage(); | |
1542 | exit(0); | |
1543 | } | |
ac1cfefa MT |
1544 | |
1545 | ### | |
ed84e8b8 | 1546 | ### Export Certificate to browser |
ac1cfefa MT |
1547 | ### |
1548 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
624615ee | 1549 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); |
ac1cfefa | 1550 | |
624615ee LS |
1551 | if ( -f "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { |
1552 | print "Content-Type: application/force-download\n"; | |
1553 | print "Content-Disposition: attachment; filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\n\n"; | |
a81cbf61 SS |
1554 | |
1555 | open(FILE, "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
1556 | my @pem = <FILE>; | |
1557 | close(FILE); | |
1558 | print "@pem"; | |
1559 | ||
624615ee LS |
1560 | exit (0); |
1561 | } | |
ac1cfefa MT |
1562 | |
1563 | ### | |
1564 | ### Enable/Disable connection | |
1565 | ### | |
1566 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { | |
624615ee LS |
1567 | |
1568 | &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings); | |
1569 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); | |
1570 | ||
1571 | if ($confighash{$cgiparams{'KEY'}}) { | |
1572 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { | |
1573 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; | |
1574 | &General::writehasharray("${General::swroot}/vpn/config", \%confighash); | |
1575 | &writeipsecfiles(); | |
a81cbf61 | 1576 | &General::system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}) if (&vpnenabled); |
624615ee | 1577 | } else { |
624615ee LS |
1578 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; |
1579 | &General::writehasharray("${General::swroot}/vpn/config", \%confighash); | |
1580 | &writeipsecfiles(); | |
a81cbf61 | 1581 | &General::system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}) if (&vpnenabled); |
624615ee LS |
1582 | } |
1583 | sleep $sleepDelay; | |
ac1cfefa | 1584 | } else { |
624615ee | 1585 | $errormessage = $Lang::tr{'invalid key'}; |
ac1cfefa | 1586 | } |
ac1cfefa MT |
1587 | |
1588 | ### | |
1589 | ### Restart connection | |
1590 | ### | |
1591 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
624615ee LS |
1592 | &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings); |
1593 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); | |
ac1cfefa | 1594 | |
624615ee LS |
1595 | if ($confighash{$cgiparams{'KEY'}}) { |
1596 | if (&vpnenabled) { | |
a81cbf61 | 1597 | &General::system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); |
624615ee LS |
1598 | sleep $sleepDelay; |
1599 | } | |
1600 | } else { | |
1601 | $errormessage = $Lang::tr{'invalid key'}; | |
ac1cfefa | 1602 | } |
ac1cfefa MT |
1603 | |
1604 | ### | |
1605 | ### Remove connection | |
1606 | ### | |
1607 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { | |
624615ee LS |
1608 | &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings); |
1609 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); | |
1610 | ||
1611 | if ($confighash{$cgiparams{'KEY'}}) { | |
624615ee LS |
1612 | unlink ("${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); |
1613 | unlink ("${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
1614 | delete $confighash{$cgiparams{'KEY'}}; | |
1615 | &General::writehasharray("${General::swroot}/vpn/config", \%confighash); | |
1616 | &writeipsecfiles(); | |
a81cbf61 | 1617 | &General::system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}) if (&vpnenabled); |
624615ee LS |
1618 | } else { |
1619 | $errormessage = $Lang::tr{'invalid key'}; | |
1620 | } | |
c6df357f | 1621 | &General::firewall_reload(); |
ac1cfefa MT |
1622 | ### |
1623 | ### Choose between adding a host-net or net-net connection | |
1624 | ### | |
1625 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
ac1cfefa | 1626 | &Header::showhttpheaders(); |
7d44bfee | 1627 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); |
ed84e8b8 MT |
1628 | &Header::openbigbox('100%', 'left', '', ''); |
1629 | &Header::openbox('100%', 'left', $Lang::tr{'connection type'}); | |
ac1cfefa | 1630 | print <<END |
624615ee LS |
1631 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
1632 | <b>$Lang::tr{'connection type'}:</b><br /> | |
1633 | <table> | |
1634 | <tr><td><input type='radio' name='TYPE' value='host' checked='checked' /></td> | |
ed84e8b8 | 1635 | <td class='base'>$Lang::tr{'host to net vpn'}</td> |
624615ee | 1636 | </tr><tr> |
ed84e8b8 MT |
1637 | <td><input type='radio' name='TYPE' value='net' /></td> |
1638 | <td class='base'>$Lang::tr{'net to net vpn'}</td> | |
624615ee | 1639 | </tr><tr> |
ed84e8b8 | 1640 | <td align='center' colspan='2'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td> |
624615ee LS |
1641 | </tr> |
1642 | </table></form> | |
ac1cfefa | 1643 | END |
624615ee | 1644 | ; |
ac1cfefa MT |
1645 | &Header::closebox(); |
1646 | &Header::closebigbox(); | |
1647 | &Header::closepage(); | |
1648 | exit (0); | |
1649 | ### | |
ed1d0fbd | 1650 | ### Adding/Editing/Saving a connection |
ac1cfefa MT |
1651 | ### |
1652 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || | |
624615ee LS |
1653 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || |
1654 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
ac1cfefa | 1655 | |
624615ee LS |
1656 | &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings); |
1657 | &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash); | |
1658 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); | |
cbb3a8f9 | 1659 | |
624615ee LS |
1660 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { |
1661 | if (! $confighash{$cgiparams{'KEY'}}[0]) { | |
1662 | $errormessage = $Lang::tr{'invalid key'}; | |
1663 | goto VPNCONF_END; | |
1664 | } | |
1665 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; | |
1666 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
1667 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; | |
1668 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; | |
1669 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
ae0d0698 | 1670 | $cgiparams{'LOCAL'} = $confighash{$cgiparams{'KEY'}}[6]; |
624615ee | 1671 | $cgiparams{'LOCAL_ID'} = $confighash{$cgiparams{'KEY'}}[7]; |
b1881251 MT |
1672 | my @local_subnets = split(",", $confighash{$cgiparams{'KEY'}}[8]); |
1673 | $cgiparams{'LOCAL_SUBNET'} = join(/\|/, @local_subnets); | |
624615ee LS |
1674 | $cgiparams{'REMOTE_ID'} = $confighash{$cgiparams{'KEY'}}[9]; |
1675 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; | |
b1881251 MT |
1676 | my @remote_subnets = split(",", $confighash{$cgiparams{'KEY'}}[11]); |
1677 | $cgiparams{'REMOTE_SUBNET'} = join(/\|/, @remote_subnets); | |
624615ee LS |
1678 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; |
1679 | $cgiparams{'DPD_ACTION'} = $confighash{$cgiparams{'KEY'}}[27]; | |
1680 | $cgiparams{'IKE_VERSION'} = $confighash{$cgiparams{'KEY'}}[29]; | |
1681 | $cgiparams{'IKE_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[18]; | |
1682 | $cgiparams{'IKE_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[19]; | |
1683 | $cgiparams{'IKE_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[20]; | |
1684 | $cgiparams{'IKE_LIFETIME'} = $confighash{$cgiparams{'KEY'}}[16]; | |
1685 | $cgiparams{'ESP_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[21]; | |
1686 | $cgiparams{'ESP_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[22]; | |
1687 | $cgiparams{'ESP_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[23]; | |
1688 | if ($cgiparams{'ESP_GROUPTYPE'} eq "") { | |
1689 | $cgiparams{'ESP_GROUPTYPE'} = $cgiparams{'IKE_GROUPTYPE'}; | |
1690 | } | |
1691 | $cgiparams{'ESP_KEYLIFE'} = $confighash{$cgiparams{'KEY'}}[17]; | |
1692 | $cgiparams{'COMPRESSION'} = $confighash{$cgiparams{'KEY'}}[13]; | |
1693 | $cgiparams{'ONLY_PROPOSED'} = $confighash{$cgiparams{'KEY'}}[24]; | |
1694 | $cgiparams{'PFS'} = $confighash{$cgiparams{'KEY'}}[28]; | |
1695 | $cgiparams{'DPD_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[30]; | |
1696 | $cgiparams{'DPD_DELAY'} = $confighash{$cgiparams{'KEY'}}[31]; | |
1697 | $cgiparams{'FORCE_MOBIKE'} = $confighash{$cgiparams{'KEY'}}[32]; | |
eb09c90e | 1698 | $cgiparams{'START_ACTION'} = $confighash{$cgiparams{'KEY'}}[33]; |
af183eeb | 1699 | $cgiparams{'INACTIVITY_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[34]; |
29f5e0e2 | 1700 | $cgiparams{'MODE'} = $confighash{$cgiparams{'KEY'}}[35]; |
cae1f4a7 | 1701 | $cgiparams{'INTERFACE_MODE'} = $confighash{$cgiparams{'KEY'}}[36]; |
74641317 | 1702 | $cgiparams{'INTERFACE_ADDRESS'} = $confighash{$cgiparams{'KEY'}}[37]; |
55842dda | 1703 | $cgiparams{'INTERFACE_MTU'} = $confighash{$cgiparams{'KEY'}}[38]; |
dccd7e87 | 1704 | $cgiparams{'DNS_SERVERS'} = $confighash{$cgiparams{'KEY'}}[39]; |
624615ee LS |
1705 | |
1706 | if (!$cgiparams{'DPD_DELAY'}) { | |
1707 | $cgiparams{'DPD_DELAY'} = 30; | |
1708 | } | |
cbb3a8f9 | 1709 | |
624615ee LS |
1710 | if (!$cgiparams{'DPD_TIMEOUT'}) { |
1711 | $cgiparams{'DPD_TIMEOUT'} = 120; | |
1712 | } | |
ac1cfefa | 1713 | |
af183eeb MT |
1714 | if ($cgiparams{'INACTIVITY_TIMEOUT'} eq "") { |
1715 | $cgiparams{'INACTIVITY_TIMEOUT'} = 900; | |
1716 | } | |
1717 | ||
29f5e0e2 MT |
1718 | if ($cgiparams{'MODE'} eq "") { |
1719 | $cgiparams{'MODE'} = "tunnel"; | |
1720 | } | |
1721 | ||
ab79dc43 MT |
1722 | if ($cgiparams{'INTERFACE_MTU'} eq "") { |
1723 | $cgiparams{'INTERFACE_MTU'} = 1500; | |
1724 | } | |
1725 | ||
624615ee LS |
1726 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
1727 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); | |
1728 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { | |
1729 | $errormessage = $Lang::tr{'connection type is invalid'}; | |
1730 | goto VPNCONF_ERROR; | |
1731 | } | |
ac1cfefa | 1732 | |
624615ee LS |
1733 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { |
1734 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
1735 | goto VPNCONF_ERROR; | |
1736 | } | |
ac1cfefa | 1737 | |
624615ee LS |
1738 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { |
1739 | $errormessage = $Lang::tr{'name is invalid'}; | |
1740 | goto VPNCONF_ERROR; | |
1741 | } | |
ac1cfefa | 1742 | |
624615ee LS |
1743 | if (length($cgiparams{'NAME'}) >60) { |
1744 | $errormessage = $Lang::tr{'name too long'}; | |
1745 | goto VPNCONF_ERROR; | |
ac1cfefa | 1746 | } |
ac1cfefa | 1747 | |
624615ee LS |
1748 | # Check if there is no other entry with this name |
1749 | if (! $cgiparams{'KEY'}) { #only for add | |
1750 | foreach my $key (keys %confighash) { | |
1751 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
1752 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
1753 | goto VPNCONF_ERROR; | |
1754 | } | |
1755 | } | |
1756 | } | |
ac1cfefa | 1757 | |
624615ee LS |
1758 | if (($cgiparams{'TYPE'} eq 'net') && (! $cgiparams{'REMOTE'})) { |
1759 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
1760 | goto VPNCONF_ERROR; | |
ac1cfefa | 1761 | } |
ac1cfefa | 1762 | |
ae0d0698 MT |
1763 | if ($cgiparams{'LOCAL'}) { |
1764 | if (($cgiparams{'LOCAL'} ne "") && (!&General::validip($cgiparams{'LOCAL'}))) { | |
1765 | $errormessage = $Lang::tr{'invalid input for local ip address'}; | |
1766 | goto VPNCONF_ERROR; | |
1767 | } | |
1768 | } | |
1769 | ||
624615ee LS |
1770 | if ($cgiparams{'REMOTE'}) { |
1771 | if (($cgiparams{'REMOTE'} ne '%any') && (! &General::validip($cgiparams{'REMOTE'}))) { | |
1772 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
1773 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
1774 | goto VPNCONF_ERROR; | |
1775 | } else { | |
1776 | if (&valid_dns_host($cgiparams{'REMOTE'})) { | |
1777 | $warnmessage = "$Lang::tr{'check vpn lr'} $cgiparams{'REMOTE'}. $Lang::tr{'dns check failed'}"; | |
1778 | } | |
1779 | } | |
1780 | } | |
1781 | } | |
ac1cfefa | 1782 | |
b1881251 MT |
1783 | my @local_subnets = split(",", $cgiparams{'LOCAL_SUBNET'}); |
1784 | foreach my $subnet (@local_subnets) { | |
8792caad | 1785 | unless (&Network::check_subnet($subnet)) { |
b1881251 | 1786 | $errormessage = $Lang::tr{'local subnet is invalid'}; |
8792caad MT |
1787 | goto VPNCONF_ERROR; |
1788 | } | |
ac1cfefa | 1789 | } |
ac1cfefa | 1790 | |
624615ee LS |
1791 | # Allow only one roadwarrior/psk without remote IP-address |
1792 | if ($cgiparams{'REMOTE'} eq '' && $cgiparams{'AUTH'} eq 'psk') { | |
1793 | foreach my $key (keys %confighash) { | |
1794 | if ( ($cgiparams{'KEY'} ne $key) && | |
1795 | ($confighash{$key}[4] eq 'psk') && | |
1796 | ($confighash{$key}[10] eq '') ) { | |
1797 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
1798 | goto VPNCONF_ERROR; | |
1799 | } | |
1800 | } | |
1801 | } | |
ac1cfefa | 1802 | |
b1881251 MT |
1803 | if ($cgiparams{'TYPE'} eq 'net') { |
1804 | my @remote_subnets = split(",", $cgiparams{'REMOTE_SUBNET'}); | |
1805 | foreach my $subnet (@remote_subnets) { | |
1806 | unless (&Network::check_subnet($subnet)) { | |
1807 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
1808 | goto VPNCONF_ERROR; | |
1809 | } | |
1810 | } | |
216bd9b3 MT |
1811 | |
1812 | if ($cgiparams{'MODE'} !~ /^(tunnel|transport)$/) { | |
1813 | $errormessage = $Lang::tr{'invalid input for mode'}; | |
1814 | goto VPNCONF_ERROR; | |
1815 | } | |
1816 | ||
1817 | if ($cgiparams{'INTERFACE_MODE'} !~ /^(|gre|vti)$/) { | |
1818 | $errormessage = $Lang::tr{'invalid input for interface mode'}; | |
1819 | goto VPNCONF_ERROR; | |
1820 | } | |
1821 | ||
7e25093d MT |
1822 | if (($cgiparams{'INTERFACE_MODE'} eq "vti") && ($cgiparams{'MODE'} eq "transport")) { |
1823 | $errormessage = $Lang::tr{'transport mode does not support vti'}; | |
1824 | goto VPNCONF_ERROR; | |
1825 | } | |
1826 | ||
216bd9b3 MT |
1827 | if (($cgiparams{'INTERFACE_MODE'} ne "") && !&Network::check_subnet($cgiparams{'INTERFACE_ADDRESS'})) { |
1828 | $errormessage = $Lang::tr{'invalid input for interface address'}; | |
1829 | goto VPNCONF_ERROR; | |
1830 | } | |
1831 | ||
1832 | if ($cgiparams{'INTERFACE_MTU'} !~ /^\d+$/) { | |
1833 | $errormessage = $Lang::tr{'invalid input for interface mtu'}; | |
1834 | goto VPNCONF_ERROR; | |
1835 | } | |
624615ee | 1836 | } |
ac1cfefa | 1837 | |
dccd7e87 MT |
1838 | if ($cgiparams{'TYPE'} eq 'host') { |
1839 | my @servers = split(",", $cgiparams{'DNS_SERVERS'}); | |
1840 | foreach my $server (@servers) { | |
1841 | unless (&Network::check_ip_address($server)) { | |
1842 | $errormessage = $Lang::tr{'ipsec dns server address is invalid'}; | |
1843 | goto VPNCONF_ERROR; | |
1844 | } | |
1845 | } | |
1846 | } | |
1847 | ||
624615ee LS |
1848 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { |
1849 | $errormessage = $Lang::tr{'invalid input'}; | |
1850 | goto VPNCONF_ERROR; | |
1851 | } | |
1852 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
1853 | $errormessage = $Lang::tr{'invalid input'}; | |
1854 | goto VPNCONF_ERROR; | |
1855 | } | |
ed84e8b8 | 1856 | |
624615ee LS |
1857 | # Allow nothing or a string (DN,FDQN,) beginning with @ |
1858 | # with no comma but slashes between RID eg @O=FR/C=Paris/OU=myhome/CN=franck | |
40d45a30 MT |
1859 | if ( ($cgiparams{'LOCAL_ID'} !~ /^(|[\w.-]*@[@#]?[\w. =*\/-]+|\d+\.\d+\.\d+\.\d+)$/) || |
1860 | ($cgiparams{'REMOTE_ID'} !~ /^(|[\w.-]*@[@#]?[\w. =*\/-]+|\d+\.\d+\.\d+\.\d+)$/) || | |
624615ee LS |
1861 | (($cgiparams{'REMOTE_ID'} eq $cgiparams{'LOCAL_ID'}) && ($cgiparams{'LOCAL_ID'} ne '')) |
1862 | ) { | |
1863 | $errormessage = $Lang::tr{'invalid local-remote id'} . '<br />' . | |
1864 | 'DER_ASN1_DN: @c=FR/ou=Paris/ou=Home/cn=*<br />' . | |
1865 | 'FQDN: @ipfire.org<br />' . | |
1866 | 'USER_FQDN: info@ipfire.org<br />' . | |
1867 | 'IPV4_ADDR: 123.123.123.123'; | |
1868 | goto VPNCONF_ERROR; | |
1869 | } | |
1870 | # If Auth is DN, verify existance of Remote ID. | |
1871 | if ( $cgiparams{'REMOTE_ID'} eq '' && ( | |
1872 | $cgiparams{'AUTH'} eq 'auth-dn'|| # while creation | |
1873 | $confighash{$cgiparams{'KEY'}}[2] eq '%auth-dn')){ # while editing | |
1874 | $errormessage = $Lang::tr{'vpn missing remote id'}; | |
1875 | goto VPNCONF_ERROR; | |
4d81e0f3 | 1876 | } |
4d81e0f3 | 1877 | |
624615ee LS |
1878 | if ($cgiparams{'TYPE'} eq 'net'){ |
1879 | $warnmessage=&General::checksubnets('',$cgiparams{'REMOTE_SUBNET'},'ipsec'); | |
1880 | if ($warnmessage ne ''){ | |
1881 | $warnmessage=$Lang::tr{'remote subnet'}." ($cgiparams{'REMOTE_SUBNET'}) <br>".$warnmessage; | |
1882 | } | |
1883 | } | |
1884 | ||
1885 | if ($cgiparams{'AUTH'} eq 'psk') { | |
1886 | if (! length($cgiparams{'PSK'}) ) { | |
1887 | $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
1888 | goto VPNCONF_ERROR; | |
1889 | } | |
1890 | if ($cgiparams{'PSK'} =~ /'/) { | |
1891 | $cgiparams{'PSK'} =~ tr/'/ /; | |
1892 | $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
1893 | goto VPNCONF_ERROR; | |
1894 | } | |
ac1cfefa | 1895 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { |
624615ee LS |
1896 | if ($cgiparams{'KEY'}) { |
1897 | $errormessage = $Lang::tr{'cant change certificates'}; | |
1898 | goto VPNCONF_ERROR; | |
1899 | } | |
2ad1b18b | 1900 | unless (ref ($cgiparams{'FH'})) { |
624615ee LS |
1901 | $errormessage = $Lang::tr{'there was no file upload'}; |
1902 | goto VPNCONF_ERROR; | |
1903 | } | |
ac1cfefa | 1904 | |
624615ee LS |
1905 | # Move uploaded certificate request to a temporary file |
1906 | (my $fh, my $filename) = tempfile( ); | |
1907 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1908 | $errormessage = $!; | |
1909 | goto VPNCONF_ERROR; | |
1910 | } | |
ac1cfefa | 1911 | |
624615ee LS |
1912 | # Sign the certificate request |
1913 | &General::log("ipsec", "Signing your cert $cgiparams{'NAME'}..."); | |
926e5519 | 1914 | my $opt = " ca -md sha256 -days 825"; |
ed84e8b8 MT |
1915 | $opt .= " -batch -notext"; |
1916 | $opt .= " -in $filename"; | |
1917 | $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"; | |
1918 | ||
624615ee LS |
1919 | if ( $errormessage = &callssl ($opt) ) { |
1920 | unlink ($filename); | |
1921 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"); | |
1922 | &cleanssldatabase(); | |
1923 | goto VPNCONF_ERROR; | |
1924 | } else { | |
1925 | unlink ($filename); | |
1926 | &cleanssldatabase(); | |
1927 | } | |
1928 | ||
1929 | $cgiparams{'CERT_NAME'} = getCNfromcert ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"); | |
1930 | if ($cgiparams{'CERT_NAME'} eq '') { | |
1931 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
1932 | goto VPNCONF_ERROR; | |
1933 | } | |
ed84e8b8 MT |
1934 | } elsif ($cgiparams{'AUTH'} eq 'pkcs12') { |
1935 | &General::log("ipsec", "Importing from p12..."); | |
1936 | ||
2ad1b18b | 1937 | unless (ref ($cgiparams{'FH'})) { |
624615ee LS |
1938 | $errormessage = $Lang::tr{'there was no file upload'}; |
1939 | goto ROOTCERT_ERROR; | |
ed84e8b8 MT |
1940 | } |
1941 | ||
1942 | # Move uploaded certificate request to a temporary file | |
1943 | (my $fh, my $filename) = tempfile( ); | |
1944 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
624615ee LS |
1945 | $errormessage = $!; |
1946 | goto ROOTCERT_ERROR; | |
ed84e8b8 MT |
1947 | } |
1948 | ||
1949 | # Extract the CA certificate from the file | |
1950 | &General::log("ipsec", "Extracting caroot from p12..."); | |
1951 | if (open(STDIN, "-|")) { | |
94aa82fa | 1952 | my $opt = " pkcs12 -legacy -cacerts -nokeys"; |
ed84e8b8 MT |
1953 | $opt .= " -in $filename"; |
1954 | $opt .= " -out /tmp/newcacert"; | |
ed84e8b8 | 1955 | $errormessage = &callssl ($opt); |
624615ee | 1956 | } else { #child |
ed84e8b8 MT |
1957 | print "$cgiparams{'P12_PASS'}\n"; |
1958 | exit (0); | |
624615ee LS |
1959 | } |
1960 | ||
1961 | # Extract the Host certificate from the file | |
1962 | if (!$errormessage) { | |
1963 | &General::log("ipsec", "Extracting host cert from p12..."); | |
1964 | if (open(STDIN, "-|")) { | |
94aa82fa | 1965 | my $opt = " pkcs12 -legacy -clcerts -nokeys"; |
624615ee LS |
1966 | $opt .= " -in $filename"; |
1967 | $opt .= " -out /tmp/newhostcert"; | |
1968 | $errormessage = &callssl ($opt); | |
1969 | } else { #child | |
1970 | print "$cgiparams{'P12_PASS'}\n"; | |
1971 | exit (0); | |
1972 | } | |
1973 | } | |
1974 | ||
1975 | if (!$errormessage) { | |
1976 | &General::log("ipsec", "Moving cacert..."); | |
1977 | #If CA have new subject, add it to our list of CA | |
1978 | my $casubject = &Header::cleanhtml(getsubjectfromcert ('/tmp/newcacert')); | |
1979 | my @names; | |
1980 | foreach my $x (keys %cahash) { | |
1981 | $casubject='' if ($cahash{$x}[1] eq $casubject); | |
1982 | unshift (@names,$cahash{$x}[0]); | |
1983 | } | |
1984 | if ($casubject) { # a new one! | |
a81cbf61 SS |
1985 | my @temp = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "/tmp/newcacert"); |
1986 | if (! grep(/CA:TRUE/, @temp)) { | |
624615ee LS |
1987 | $errormessage = $Lang::tr{'not a valid ca certificate'}; |
1988 | } else { | |
1989 | #compute a name for it | |
1990 | my $idx=0; | |
1991 | while (grep(/Imported-$idx/, @names) ) {$idx++}; | |
1992 | $cgiparams{'CA_NAME'}="Imported-$idx"; | |
1993 | $cgiparams{'CERT_NAME'}=&Header::cleanhtml(getCNfromcert ('/tmp/newhostcert')); | |
b5b19f37 SS |
1994 | |
1995 | unless(move("/tmp/newcacert", "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem")) { | |
1996 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1997 | } | |
1998 | ||
624615ee LS |
1999 | if (!$errormessage) { |
2000 | my $key = &General::findhasharraykey (\%cahash); | |
2001 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
2002 | $cahash{$key}[1] = $casubject; | |
2003 | &General::writehasharray("${General::swroot}/vpn/caconfig", \%cahash); | |
a81cbf61 | 2004 | &General::system('/usr/local/bin/ipsecctrl', 'R'); |
624615ee LS |
2005 | } |
2006 | } | |
2007 | } | |
ed84e8b8 MT |
2008 | } |
2009 | if (!$errormessage) { | |
624615ee | 2010 | &General::log("ipsec", "Moving host cert..."); |
b5b19f37 SS |
2011 | unless(move("/tmp/newhostcert", "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem")) { |
2012 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
2013 | } | |
624615ee | 2014 | } |
ed84e8b8 MT |
2015 | |
2016 | #cleanup temp files | |
2017 | unlink ($filename); | |
2018 | unlink ('/tmp/newcacert'); | |
2019 | unlink ('/tmp/newhostcert'); | |
2020 | if ($errormessage) { | |
624615ee LS |
2021 | unlink ("${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem"); |
2022 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"); | |
2023 | goto VPNCONF_ERROR; | |
ed84e8b8 MT |
2024 | } |
2025 | &General::log("ipsec", "p12 import completed!"); | |
ac1cfefa | 2026 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { |
624615ee LS |
2027 | if ($cgiparams{'KEY'}) { |
2028 | $errormessage = $Lang::tr{'cant change certificates'}; | |
2029 | goto VPNCONF_ERROR; | |
2030 | } | |
2ad1b18b | 2031 | unless (ref ($cgiparams{'FH'})) { |
624615ee LS |
2032 | $errormessage = $Lang::tr{'there was no file upload'}; |
2033 | goto VPNCONF_ERROR; | |
2034 | } | |
2035 | # Move uploaded certificate to a temporary file | |
2036 | (my $fh, my $filename) = tempfile( ); | |
2037 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
2038 | $errormessage = $!; | |
2039 | goto VPNCONF_ERROR; | |
ac1cfefa | 2040 | } |
ac1cfefa | 2041 | |
624615ee LS |
2042 | # Verify the certificate has a valid CA and move it |
2043 | &General::log("ipsec", "Validating imported cert against our known CA..."); | |
2044 | my $validca = 1; #assume ok | |
a81cbf61 SS |
2045 | my @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ca/cacert.pem", "$filename"); |
2046 | if (! grep(/: OK/, @test)) { | |
624615ee LS |
2047 | my $validca = 0; |
2048 | foreach my $key (keys %cahash) { | |
a81cbf61 SS |
2049 | @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ca/$cahash{$key}[0]cert.pem", "$filename"); |
2050 | if (grep(/: OK/, @test)) { | |
624615ee LS |
2051 | $validca = 1; |
2052 | last; | |
2053 | } | |
2054 | } | |
2055 | } | |
2056 | if (! $validca) { | |
2057 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
2058 | unlink ($filename); | |
2059 | goto VPNCONF_ERROR; | |
2060 | } else { | |
aec1c53c MT |
2061 | unless (move($filename, "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem")) { |
2062 | $errormessage = "$Lang::tr{'certificate file move failed'} ($filename): $!"; | |
624615ee LS |
2063 | unlink ($filename); |
2064 | goto VPNCONF_ERROR; | |
2065 | } | |
2066 | } | |
2067 | ||
2068 | $cgiparams{'CERT_NAME'} = getCNfromcert ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"); | |
2069 | if ($cgiparams{'CERT_NAME'} eq '') { | |
2070 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"); | |
2071 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
2072 | goto VPNCONF_ERROR; | |
2073 | } | |
ac1cfefa | 2074 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { |
624615ee LS |
2075 | if ($cgiparams{'KEY'}) { |
2076 | $errormessage = $Lang::tr{'cant change certificates'}; | |
2077 | goto VPNCONF_ERROR; | |
2078 | } | |
2079 | # Validate input since the form was submitted | |
2080 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
2081 | $errormessage = $Lang::tr{'name too long'}; | |
2082 | goto VPNCONF_ERROR; | |
2083 | } | |
2084 | if ($cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
2085 | $errormessage = $Lang::tr{'invalid input for name'}; | |
2086 | goto VPNCONF_ERROR; | |
2087 | } | |
2088 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
2089 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
2090 | goto VPNCONF_ERROR; | |
2091 | } | |
2092 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
2093 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
2094 | goto VPNCONF_ERROR; | |
2095 | } | |
2096 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
2097 | $errormessage = $Lang::tr{'invalid input for department'}; | |
2098 | goto VPNCONF_ERROR; | |
2099 | } | |
2100 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
2101 | $errormessage = $Lang::tr{'organization too long'}; | |
2102 | goto VPNCONF_ERROR; | |
2103 | } | |
2104 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
2105 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
2106 | goto VPNCONF_ERROR; | |
2107 | } | |
2108 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
2109 | $errormessage = $Lang::tr{'invalid input for city'}; | |
2110 | goto VPNCONF_ERROR; | |
2111 | } | |
2112 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
2113 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
2114 | goto VPNCONF_ERROR; | |
2115 | } | |
2116 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
2117 | $errormessage = $Lang::tr{'invalid input for country'}; | |
2118 | goto VPNCONF_ERROR; | |
2119 | } | |
2120 | #the exact syntax is a list comma separated of | |
2121 | # email:any-validemail | |
2122 | # URI: a uniform resource indicator | |
2123 | # DNS: a DNS domain name | |
2124 | # RID: a registered OBJECT IDENTIFIER | |
2125 | # IP: an IP address | |
2126 | # example: email:franck@foo.com,IP:10.0.0.10,DNS:franck.foo.com | |
2127 | ||
2128 | if ($cgiparams{'SUBJECTALTNAME'} ne '' && $cgiparams{'SUBJECTALTNAME'} !~ /^(email|URI|DNS|RID|IP):[a-zA-Z0-9 :\/,\.\-_@]*$/) { | |
2129 | $errormessage = $Lang::tr{'vpn altname syntax'}; | |
2130 | goto VPNCONF_ERROR; | |
2131 | } | |
ed84e8b8 | 2132 | |
624615ee LS |
2133 | if (length($cgiparams{'CERT_PASS1'}) < 5) { |
2134 | $errormessage = $Lang::tr{'password too short'}; | |
2135 | goto VPNCONF_ERROR; | |
2136 | } | |
2137 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { | |
2138 | $errormessage = $Lang::tr{'passwords do not match'}; | |
2139 | goto VPNCONF_ERROR; | |
2140 | } | |
ac1cfefa | 2141 | |
624615ee LS |
2142 | # Replace empty strings with a . |
2143 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
2144 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
2145 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
ac1cfefa | 2146 | |
624615ee LS |
2147 | # Create the Client certificate request |
2148 | &General::log("ipsec", "Creating a cert..."); | |
ed84e8b8 | 2149 | |
624615ee | 2150 | if (open(STDIN, "-|")) { |
18274331 | 2151 | my $opt = " req -nodes"; |
818dde8e | 2152 | $opt .= " -newkey rsa:4096"; |
624615ee LS |
2153 | $opt .= " -keyout ${General::swroot}/certs/$cgiparams{'NAME'}key.pem"; |
2154 | $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}req.pem"; | |
2155 | ||
2156 | if ( $errormessage = &callssl ($opt) ) { | |
2157 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem"); | |
2158 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem"); | |
2159 | goto VPNCONF_ERROR; | |
2160 | } | |
2161 | } else { #child | |
2162 | print "$cgiparams{'CERT_COUNTRY'}\n"; | |
2163 | print "$state\n"; | |
2164 | print "$city\n"; | |
2165 | print "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
2166 | print "$ou\n"; | |
2167 | print "$cgiparams{'CERT_NAME'}\n"; | |
2168 | print "$cgiparams{'CERT_EMAIL'}\n"; | |
2169 | print ".\n"; | |
2170 | print ".\n"; | |
2171 | exit (0); | |
2172 | } | |
ed84e8b8 | 2173 | |
624615ee LS |
2174 | # Sign the client certificate request |
2175 | &General::log("ipsec", "Signing the cert $cgiparams{'NAME'}..."); | |
2176 | ||
2177 | #No easy way for specifying the contain of subjectAltName without writing a config file... | |
2178 | my ($fh, $v3extname) = tempfile ('/tmp/XXXXXXXX'); | |
2179 | print $fh <<END | |
2180 | basicConstraints=CA:FALSE | |
2181 | nsComment="OpenSSL Generated Certificate" | |
2182 | subjectKeyIdentifier=hash | |
2183 | extendedKeyUsage=clientAuth | |
2184 | authorityKeyIdentifier=keyid,issuer:always | |
ed84e8b8 MT |
2185 | END |
2186 | ; | |
624615ee LS |
2187 | print $fh "subjectAltName=$cgiparams{'SUBJECTALTNAME'}" if ($cgiparams{'SUBJECTALTNAME'}); |
2188 | close ($fh); | |
2189 | ||
926e5519 | 2190 | my $opt = " ca -md sha256 -days 825 -batch -notext"; |
624615ee LS |
2191 | $opt .= " -in ${General::swroot}/certs/$cgiparams{'NAME'}req.pem"; |
2192 | $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"; | |
2193 | $opt .= " -extfile $v3extname"; | |
2194 | ||
2195 | if ( $errormessage = &callssl ($opt) ) { | |
2196 | unlink ($v3extname); | |
2197 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem"); | |
2198 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem"); | |
2199 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"); | |
2200 | &cleanssldatabase(); | |
2201 | goto VPNCONF_ERROR; | |
2202 | } else { | |
2203 | unlink ($v3extname); | |
2204 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}req.pem"); | |
2205 | &cleanssldatabase(); | |
2206 | } | |
2207 | ||
2208 | # Create the pkcs12 file | |
2209 | &General::log("ipsec", "Packing a pkcs12 file..."); | |
94aa82fa | 2210 | $opt = " pkcs12 -legacy -export"; |
624615ee LS |
2211 | $opt .= " -inkey ${General::swroot}/certs/$cgiparams{'NAME'}key.pem"; |
2212 | $opt .= " -in ${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"; | |
2213 | $opt .= " -name \"$cgiparams{'NAME'}\""; | |
2214 | $opt .= " -passout pass:$cgiparams{'CERT_PASS1'}"; | |
2215 | $opt .= " -certfile ${General::swroot}/ca/cacert.pem"; | |
2216 | $opt .= " -caname \"$vpnsettings{'ROOTCERT_ORGANIZATION'} CA\""; | |
2217 | $opt .= " -out ${General::swroot}/certs/$cgiparams{'NAME'}.p12"; | |
2218 | ||
2219 | if ( $errormessage = &callssl ($opt) ) { | |
2220 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem"); | |
2221 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}cert.pem"); | |
2222 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}.p12"); | |
2223 | goto VPNCONF_ERROR; | |
2224 | } else { | |
2225 | unlink ("${General::swroot}/certs/$cgiparams{'NAME'}key.pem"); | |
2226 | } | |
ac1cfefa | 2227 | } elsif ($cgiparams{'AUTH'} eq 'cert') { |
624615ee | 2228 | ;# Nothing, just editing |
ed84e8b8 | 2229 | } elsif ($cgiparams{'AUTH'} eq 'auth-dn') { |
624615ee | 2230 | $cgiparams{'CERT_NAME'} = '%auth-dn'; # a special value saying 'no cert file' |
ac1cfefa | 2231 | } else { |
624615ee LS |
2232 | $errormessage = $Lang::tr{'invalid input for authentication method'}; |
2233 | goto VPNCONF_ERROR; | |
ac1cfefa MT |
2234 | } |
2235 | ||
ed84e8b8 MT |
2236 | # 1)Error message here is not accurate. |
2237 | # 2)Test is superfluous, openswan can reference same cert multiple times | |
2238 | # 3)Present since initial version (1.3.2.11), it isn't a bug correction | |
2239 | # Check if there is no other entry with this certificate name | |
2240 | #if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk') && ($cgiparams{'AUTH'} ne 'auth-dn')) { | |
624615ee | 2241 | # foreach my $key (keys %confighash) { |
ed84e8b8 | 2242 | # if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { |
624615ee LS |
2243 | # $errormessage = $Lang::tr{'a connection with this common name already exists'}; |
2244 | # goto VPNCONF_ERROR; | |
2245 | # } | |
ed84e8b8 | 2246 | # } |
ed84e8b8 | 2247 | #} |
624615ee | 2248 | # Save the config |
ed84e8b8 | 2249 | |
ac1cfefa MT |
2250 | my $key = $cgiparams{'KEY'}; |
2251 | if (! $key) { | |
624615ee | 2252 | $key = &General::findhasharraykey (\%confighash); |
dccd7e87 | 2253 | foreach my $i (0 .. 39) { $confighash{$key}[$i] = "";} |
ac1cfefa MT |
2254 | } |
2255 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; | |
2256 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
2257 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { | |
624615ee | 2258 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; |
ac1cfefa MT |
2259 | } |
2260 | $confighash{$key}[3] = $cgiparams{'TYPE'}; | |
2261 | if ($cgiparams{'AUTH'} eq 'psk') { | |
624615ee LS |
2262 | $confighash{$key}[4] = 'psk'; |
2263 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
ac1cfefa | 2264 | } else { |
624615ee | 2265 | $confighash{$key}[4] = 'cert'; |
ac1cfefa MT |
2266 | } |
2267 | if ($cgiparams{'TYPE'} eq 'net') { | |
b1881251 MT |
2268 | my @remote_subnets = split(",", $cgiparams{'REMOTE_SUBNET'}); |
2269 | $confighash{$key}[11] = join('|', @remote_subnets); | |
ac1cfefa | 2270 | } |
ae0d0698 | 2271 | $confighash{$key}[6] = $cgiparams{'LOCAL'}; |
ac1cfefa | 2272 | $confighash{$key}[7] = $cgiparams{'LOCAL_ID'}; |
8792caad MT |
2273 | my @local_subnets = split(",", $cgiparams{'LOCAL_SUBNET'}); |
2274 | $confighash{$key}[8] = join('|', @local_subnets); | |
ac1cfefa MT |
2275 | $confighash{$key}[9] = $cgiparams{'REMOTE_ID'}; |
2276 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; | |
2277 | $confighash{$key}[25] = $cgiparams{'REMARK'}; | |
ae2782ba | 2278 | $confighash{$key}[26] = ""; # Formerly INTERFACE |
ac1cfefa | 2279 | $confighash{$key}[27] = $cgiparams{'DPD_ACTION'}; |
e2e4ed01 | 2280 | $confighash{$key}[29] = $cgiparams{'IKE_VERSION'}; |
ac1cfefa | 2281 | |
624615ee | 2282 | # don't forget advanced value |
ed84e8b8 MT |
2283 | $confighash{$key}[18] = $cgiparams{'IKE_ENCRYPTION'}; |
2284 | $confighash{$key}[19] = $cgiparams{'IKE_INTEGRITY'}; | |
2285 | $confighash{$key}[20] = $cgiparams{'IKE_GROUPTYPE'}; | |
2286 | $confighash{$key}[16] = $cgiparams{'IKE_LIFETIME'}; | |
2287 | $confighash{$key}[21] = $cgiparams{'ESP_ENCRYPTION'}; | |
2288 | $confighash{$key}[22] = $cgiparams{'ESP_INTEGRITY'}; | |
2289 | $confighash{$key}[23] = $cgiparams{'ESP_GROUPTYPE'}; | |
2290 | $confighash{$key}[17] = $cgiparams{'ESP_KEYLIFE'}; | |
451a2f68 | 2291 | $confighash{$key}[12] = 'off'; # $cgiparams{'AGGRMODE'}; |
ed84e8b8 MT |
2292 | $confighash{$key}[13] = $cgiparams{'COMPRESSION'}; |
2293 | $confighash{$key}[24] = $cgiparams{'ONLY_PROPOSED'}; | |
2294 | $confighash{$key}[28] = $cgiparams{'PFS'}; | |
4e156911 AM |
2295 | $confighash{$key}[30] = $cgiparams{'DPD_TIMEOUT'}; |
2296 | $confighash{$key}[31] = $cgiparams{'DPD_DELAY'}; | |
f6529a04 | 2297 | $confighash{$key}[32] = $cgiparams{'FORCE_MOBIKE'}; |
eb09c90e | 2298 | $confighash{$key}[33] = $cgiparams{'START_ACTION'}; |
af183eeb | 2299 | $confighash{$key}[34] = $cgiparams{'INACTIVITY_TIMEOUT'}; |
29f5e0e2 | 2300 | $confighash{$key}[35] = $cgiparams{'MODE'}; |
cae1f4a7 | 2301 | $confighash{$key}[36] = $cgiparams{'INTERFACE_MODE'}; |
74641317 | 2302 | $confighash{$key}[37] = $cgiparams{'INTERFACE_ADDRESS'}; |
55842dda | 2303 | $confighash{$key}[38] = $cgiparams{'INTERFACE_MTU'}; |
dccd7e87 | 2304 | $confighash{$key}[39] = join("|", split(",", $cgiparams{'DNS_SERVERS'})); |
ac1cfefa | 2305 | |
624615ee | 2306 | # free unused fields! |
ed84e8b8 | 2307 | $confighash{$key}[15] = 'off'; |
ac1cfefa MT |
2308 | |
2309 | &General::writehasharray("${General::swroot}/vpn/config", \%confighash); | |
2310 | &writeipsecfiles(); | |
ed84e8b8 | 2311 | if (&vpnenabled) { |
a81cbf61 | 2312 | &General::system('/usr/local/bin/ipsecctrl', 'S', $key); |
624615ee | 2313 | sleep $sleepDelay; |
ac1cfefa MT |
2314 | } |
2315 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { | |
624615ee LS |
2316 | $cgiparams{'KEY'} = $key; |
2317 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
ac1cfefa MT |
2318 | } |
2319 | goto VPNCONF_END; | |
624615ee LS |
2320 | } else { # add new connection |
2321 | $cgiparams{'ENABLED'} = 'on'; | |
ac1cfefa | 2322 | if ( ! -f "${General::swroot}/private/cakey.pem" ) { |
624615ee | 2323 | $cgiparams{'AUTH'} = 'psk'; |
ac1cfefa | 2324 | } elsif ( ! -f "${General::swroot}/ca/cacert.pem") { |
624615ee | 2325 | $cgiparams{'AUTH'} = 'certfile'; |
ac1cfefa | 2326 | } else { |
624615ee | 2327 | $cgiparams{'AUTH'} = 'certgen'; |
ac1cfefa | 2328 | } |
605c391a MT |
2329 | |
2330 | if ($netsettings{"GREEN_NETADDRESS"} && $netsettings{"GREEN_NETMASK"}) { | |
2331 | $cgiparams{"LOCAL_SUBNET"} = $netsettings{'GREEN_NETADDRESS'} . "/" . $netsettings{'GREEN_NETMASK'}; | |
2332 | } else { | |
2333 | $cgiparams{"LOCAL_SUBNET"} = ""; | |
2334 | } | |
624615ee LS |
2335 | $cgiparams{'CERT_EMAIL'} = $vpnsettings{'ROOTCERT_EMAIL'}; |
2336 | $cgiparams{'CERT_OU'} = $vpnsettings{'ROOTCERT_OU'}; | |
2337 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
2338 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
2339 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
2340 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
ac1cfefa | 2341 | |
624615ee | 2342 | # choose appropriate dpd action |
ac1cfefa | 2343 | if ($cgiparams{'TYPE'} eq 'host') { |
afd5d8f7 | 2344 | $cgiparams{'DPD_ACTION'} = 'clear'; |
ac1cfefa | 2345 | } else { |
afd5d8f7 | 2346 | $cgiparams{'DPD_ACTION'} = 'restart'; |
ac1cfefa MT |
2347 | } |
2348 | ||
cbb3a8f9 MT |
2349 | if (!$cgiparams{'DPD_DELAY'}) { |
2350 | $cgiparams{'DPD_DELAY'} = 30; | |
2351 | } | |
2352 | ||
2353 | if (!$cgiparams{'DPD_TIMEOUT'}) { | |
2354 | $cgiparams{'DPD_TIMEOUT'} = 120; | |
2355 | } | |
2356 | ||
f6529a04 MT |
2357 | if (!$cgiparams{'FORCE_MOBIKE'}) { |
2358 | $cgiparams{'FORCE_MOBIKE'} = 'no'; | |
2359 | } | |
2360 | ||
ae2782ba MT |
2361 | # Default IKE Version to v2 |
2362 | if (!$cgiparams{'IKE_VERSION'}) { | |
624615ee | 2363 | $cgiparams{'IKE_VERSION'} = 'ikev2'; |
e2e4ed01 AF |
2364 | } |
2365 | ||
ac1cfefa | 2366 | # ID are empty |
624615ee | 2367 | $cgiparams{'LOCAL_ID'} = ''; |
ac1cfefa | 2368 | $cgiparams{'REMOTE_ID'} = ''; |
ed84e8b8 MT |
2369 | |
2370 | #use default advanced value | |
05375f12 | 2371 | $cgiparams{'IKE_ENCRYPTION'} = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128'; #[18]; |
570d54fd | 2372 | $cgiparams{'IKE_INTEGRITY'} = 'sha2_512|sha2_256'; #[19]; |
69d4453e | 2373 | $cgiparams{'IKE_GROUPTYPE'} = 'curve448|curve25519|e521|e384|4096|3072'; #[20]; |
624615ee | 2374 | $cgiparams{'IKE_LIFETIME'} = '3'; #[16]; |
05375f12 | 2375 | $cgiparams{'ESP_ENCRYPTION'} = 'chacha20poly1305|aes256gcm128|aes256gcm96|aes256gcm64|aes256|aes192gcm128|aes192gcm96|aes192gcm64|aes192|aes128gcm128|aes128gcm96|aes128gcm64|aes128'; #[21]; |
570d54fd | 2376 | $cgiparams{'ESP_INTEGRITY'} = 'sha2_512|sha2_256'; #[22]; |
69d4453e | 2377 | $cgiparams{'ESP_GROUPTYPE'} = 'curve448|curve25519|e521|e384|4096|3072'; #[23]; |
624615ee | 2378 | $cgiparams{'ESP_KEYLIFE'} = '1'; #[17]; |
120d77b3 | 2379 | $cgiparams{'COMPRESSION'} = 'off'; #[13]; |
570d54fd | 2380 | $cgiparams{'ONLY_PROPOSED'} = 'on'; #[24]; |
624615ee | 2381 | $cgiparams{'PFS'} = 'on'; #[28]; |
af183eeb | 2382 | $cgiparams{'INACTIVITY_TIMEOUT'} = 900; |
29f5e0e2 | 2383 | $cgiparams{'MODE'} = "tunnel"; |
cae1f4a7 | 2384 | $cgiparams{'INTERFACE_MODE'} = ""; |
74641317 | 2385 | $cgiparams{'INTERFACE_ADDRESS'} = ""; |
55842dda | 2386 | $cgiparams{'INTERFACE_MTU'} = 1500; |
dccd7e87 | 2387 | $cgiparams{'DNS_SERVERS'} = ""; |
624615ee | 2388 | } |
ac1cfefa | 2389 | |
624615ee LS |
2390 | VPNCONF_ERROR: |
2391 | $checked{'ENABLED'}{'off'} = ''; | |
2392 | $checked{'ENABLED'}{'on'} = ''; | |
2393 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'"; | |
2394 | ||
2395 | $checked{'EDIT_ADVANCED'}{'off'} = ''; | |
2396 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
2397 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = "checked='checked'"; | |
2398 | ||
2399 | $checked{'AUTH'}{'psk'} = ''; | |
2400 | $checked{'AUTH'}{'certreq'} = ''; | |
2401 | $checked{'AUTH'}{'certgen'} = ''; | |
2402 | $checked{'AUTH'}{'certfile'} = ''; | |
2403 | $checked{'AUTH'}{'pkcs12'} = ''; | |
2404 | $checked{'AUTH'}{'auth-dn'} = ''; | |
2405 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = "checked='checked'"; | |
2406 | ||
216bd9b3 MT |
2407 | $selected{'MODE'}{'tunnel'} = ''; |
2408 | $selected{'MODE'}{'transport'} = ''; | |
2409 | $selected{'MODE'}{$cgiparams{'MODE'}} = "selected='selected'"; | |
2410 | ||
2411 | $selected{'INTERFACE_MODE'}{''} = ''; | |
2412 | $selected{'INTERFACE_MODE'}{'gre'} = ''; | |
2413 | $selected{'INTERFACE_MODE'}{'vti'} = ''; | |
2414 | $selected{'INTERFACE_MODE'}{$cgiparams{'INTERFACE_MODE'}} = "selected='selected'"; | |
2415 | ||
ae0d0698 MT |
2416 | $selected{'LOCAL'}{''} = ''; |
2417 | foreach my $alias (sort keys %aliases) { | |
2418 | my $address = $aliases{$alias}{'IPT'}; | |
2419 | ||
2420 | $selected{'LOCAL'}{$address} = ''; | |
2421 | } | |
2422 | $selected{'LOCAL'}{$cgiparams{'LOCAL'}} = "selected='selected'"; | |
2423 | ||
624615ee LS |
2424 | &Header::showhttpheaders(); |
2425 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); | |
2426 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
2427 | if ($errormessage) { | |
2428 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
2429 | print "<class name='base'>$errormessage"; | |
2430 | print " </class>"; | |
2431 | &Header::closebox(); | |
2432 | } | |
2433 | ||
2434 | if ($warnmessage) { | |
2435 | &Header::openbox('100%', 'left', "$Lang::tr{'warning messages'}:"); | |
2436 | print "<class name='base'>$warnmessage"; | |
2437 | print " </class>"; | |
2438 | &Header::closebox(); | |
2439 | } | |
ac1cfefa | 2440 | |
624615ee LS |
2441 | print "<form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>"; |
2442 | print<<END | |
ed84e8b8 | 2443 | <input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' /> |
4ad0b5b6 | 2444 | <input type='hidden' name='IKE_VERSION' value='$cgiparams{'IKE_VERSION'}' /> |
ed84e8b8 MT |
2445 | <input type='hidden' name='IKE_ENCRYPTION' value='$cgiparams{'IKE_ENCRYPTION'}' /> |
2446 | <input type='hidden' name='IKE_INTEGRITY' value='$cgiparams{'IKE_INTEGRITY'}' /> | |
2447 | <input type='hidden' name='IKE_GROUPTYPE' value='$cgiparams{'IKE_GROUPTYPE'}' /> | |
2448 | <input type='hidden' name='IKE_LIFETIME' value='$cgiparams{'IKE_LIFETIME'}' /> | |
2449 | <input type='hidden' name='ESP_ENCRYPTION' value='$cgiparams{'ESP_ENCRYPTION'}' /> | |
2450 | <input type='hidden' name='ESP_INTEGRITY' value='$cgiparams{'ESP_INTEGRITY'}' /> | |
2451 | <input type='hidden' name='ESP_GROUPTYPE' value='$cgiparams{'ESP_GROUPTYPE'}' /> | |
2452 | <input type='hidden' name='ESP_KEYLIFE' value='$cgiparams{'ESP_KEYLIFE'}' /> | |
ed84e8b8 MT |
2453 | <input type='hidden' name='COMPRESSION' value='$cgiparams{'COMPRESSION'}' /> |
2454 | <input type='hidden' name='ONLY_PROPOSED' value='$cgiparams{'ONLY_PROPOSED'}' /> | |
2455 | <input type='hidden' name='PFS' value='$cgiparams{'PFS'}' /> | |
cbb3a8f9 MT |
2456 | <input type='hidden' name='DPD_ACTION' value='$cgiparams{'DPD_ACTION'}' /> |
2457 | <input type='hidden' name='DPD_DELAY' value='$cgiparams{'DPD_DELAY'}' /> | |
2458 | <input type='hidden' name='DPD_TIMEOUT' value='$cgiparams{'DPD_TIMEOUT'}' /> | |
f6529a04 | 2459 | <input type='hidden' name='FORCE_MOBIKE' value='$cgiparams{'FORCE_MOBIKE'}' /> |
eb09c90e | 2460 | <input type='hidden' name='START_ACTION' value='$cgiparams{'START_ACTION'}' /> |
5e6fa03e | 2461 | <input type='hidden' name='INACTIVITY_TIMEOUT' value='$cgiparams{'INACTIVITY_TIMEOUT'}' /> |
ed84e8b8 | 2462 | END |
624615ee LS |
2463 | ; |
2464 | if ($cgiparams{'KEY'}) { | |
2465 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
2466 | print "<input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />"; | |
2467 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
2468 | } | |
2469 | ||
2470 | &Header::openbox('100%', 'left', "$Lang::tr{'connection'}: $cgiparams{'NAME'}"); | |
2471 | print "<table width='100%'>"; | |
2472 | if (!$cgiparams{'KEY'}) { | |
2473 | print <<EOF; | |
2474 | <tr> | |
2475 | <td width='20%'>$Lang::tr{'name'}: <img src='/blob.gif' alt='*' /></td> | |
2476 | <td width='30%'> | |
2477 | <input type='text' name='NAME' value='$cgiparams{'NAME'}' size='25' /> | |
2478 | </td> | |
2479 | <td colspan="2"></td> | |
2480 | </tr> | |
d2d87f2c | 2481 | EOF |
624615ee | 2482 | } |
ac1cfefa | 2483 | |
dccd7e87 MT |
2484 | my $blob = ""; |
2485 | if ($cgiparams{'TYPE'} eq 'net') { | |
e3edceeb | 2486 | $blob = "<img src='/blob.gif' alt='*' />"; |
624615ee | 2487 | }; |
5fd30232 | 2488 | |
b1881251 MT |
2489 | my @local_subnets = split(/\|/, $cgiparams{'LOCAL_SUBNET'}); |
2490 | my $local_subnets = join(",", @local_subnets); | |
8792caad | 2491 | |
b1881251 MT |
2492 | my @remote_subnets = split(/\|/, $cgiparams{'REMOTE_SUBNET'}); |
2493 | my $remote_subnets = join(",", @remote_subnets); | |
8792caad | 2494 | |
dccd7e87 MT |
2495 | my @dns_servers = split(/\|/, $cgiparams{'DNS_SERVERS'}); |
2496 | my $dns_servers = join(",", @dns_servers); | |
2497 | ||
ae0d0698 | 2498 | print <<END; |
ae2782ba | 2499 | <tr> |
d2d87f2c MT |
2500 | <td width='20%'>$Lang::tr{'enabled'}</td> |
2501 | <td width='30%'> | |
2502 | <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /> | |
2503 | </td> | |
455fdcb1 | 2504 | <td colspan="2"></td> |
d2d87f2c MT |
2505 | </tr> |
2506 | <tr> | |
ae0d0698 MT |
2507 | <td class='boldbase' width='20%'>$Lang::tr{'local ip address'}:</td> |
2508 | <td width='30%'> | |
2509 | <select name="LOCAL"> | |
2510 | <option value="" $selected{'LOCAL'}{''}>- $Lang::tr{'default IP address'} -</option> | |
2511 | END | |
2512 | ||
2513 | foreach my $alias (sort keys %aliases) { | |
2514 | my $address = $aliases{$alias}{'IPT'}; | |
2515 | print <<END; | |
2516 | <option value="$address" $selected{'LOCAL'}{$address}>$alias ($address)</option> | |
2517 | END | |
2518 | } | |
2519 | ||
2520 | print <<END; | |
2521 | </select> | |
2522 | </td> | |
624615ee LS |
2523 | <td class='boldbase' width='20%'>$Lang::tr{'remote host/ip'}: $blob</td> |
2524 | <td width='30%'> | |
2525 | <input type='text' name='REMOTE' value='$cgiparams{'REMOTE'}' size="25" /> | |
2526 | </td> | |
455fdcb1 MT |
2527 | </tr> |
2528 | <tr> | |
2529 | <td class='boldbase' nowrap='nowrap' width='20%'>$Lang::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td> | |
2530 | <td width='30%'> | |
2531 | <input type='text' name='LOCAL_SUBNET' value='$local_subnets' size="25" /> | |
2532 | </td> | |
dccd7e87 MT |
2533 | END |
2534 | ||
2535 | if ($cgiparams{'TYPE'} eq "net") { | |
2536 | print <<END; | |
2537 | <td class='boldbase' nowrap='nowrap' width='20%'>$Lang::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td> | |
624615ee | 2538 | <td width='30%'> |
dccd7e87 | 2539 | <input type='text' name='REMOTE_SUBNET' value='$remote_subnets' size="25" /> |
624615ee | 2540 | </td> |
dccd7e87 MT |
2541 | END |
2542 | ||
2543 | } elsif ($cgiparams{'TYPE'} eq "host") { | |
2544 | print <<END; | |
2545 | <td class='boldbase' nowrap='nowrap' width='20%'>$Lang::tr{'dns servers'}:</td> | |
2546 | <td width='30%'> | |
2547 | <input type='text' name='DNS_SERVERS' value='$dns_servers' size="25" /> | |
2548 | </td> | |
2549 | END | |
2550 | } | |
2551 | ||
2552 | print <<END; | |
ae2782ba MT |
2553 | </tr> |
2554 | <tr> | |
624615ee LS |
2555 | <td class='boldbase' width='20%'>$Lang::tr{'vpn local id'}:</td> |
2556 | <td width='30%'> | |
2557 | <input type='text' name='LOCAL_ID' value='$cgiparams{'LOCAL_ID'}' size="25" /> | |
2558 | </td> | |
2559 | <td class='boldbase' width='20%'>$Lang::tr{'vpn remote id'}:</td> | |
2560 | <td width='30%'> | |
2561 | <input type='text' name='REMOTE_ID' value='$cgiparams{'REMOTE_ID'}' size="25" /> | |
2562 | </td> | |
ae2782ba | 2563 | </tr> |
d2d87f2c | 2564 | <tr><td colspan="4"><br /></td></tr> |
ae2782ba | 2565 | <tr> |
624615ee LS |
2566 | <td class='boldbase' width='20%'>$Lang::tr{'remark title'}</td> |
2567 | <td colspan='3'> | |
2568 | <input type='text' name='REMARK' value='$cgiparams{'REMARK'}' maxlength='50' size="73" /> | |
2569 | </td> | |
ed84e8b8 | 2570 | </tr> |
ac1cfefa | 2571 | END |
624615ee LS |
2572 | ; |
2573 | if (!$cgiparams{'KEY'}) { | |
2574 | print "<tr><td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked{'EDIT_ADVANCED'}{'on'} /> $Lang::tr{'edit advanced settings when done'}</td></tr>"; | |
2575 | } | |
2576 | print "</table>"; | |
ed84e8b8 | 2577 | &Header::closebox(); |
ed84e8b8 | 2578 | |
216bd9b3 MT |
2579 | if ($cgiparams{'TYPE'} eq 'net') { |
2580 | &Header::openbox('100%', 'left', $Lang::tr{'ipsec settings'}); | |
2581 | print <<EOF; | |
2582 | <table width='100%'> | |
2583 | <tbody> | |
2584 | <tr> | |
2585 | <td class='boldbase' width='20%'>$Lang::tr{'mode'}:</td> | |
2586 | <td width='30%'> | |
2587 | <select name='MODE'> | |
2588 | <option value='tunnel' $selected{'MODE'}{'tunnel'}>$Lang::tr{'ipsec mode tunnel'}</option> | |
2589 | <option value='transport' $selected{'MODE'}{'transport'}>$Lang::tr{'ipsec mode transport'}</option> | |
2590 | </select> | |
2591 | </td> | |
2592 | <td colspan='2'></td> | |
2593 | </tr> | |
2594 | ||
2595 | <tr> | |
2596 | <td class='boldbase' width='20%'>$Lang::tr{'interface mode'}:</td> | |
2597 | <td width='30%'> | |
2598 | <select name='INTERFACE_MODE'> | |
2599 | <option value='' $selected{'INTERFACE_MODE'}{''}>$Lang::tr{'ipsec interface mode none'}</option> | |
2600 | <option value='gre' $selected{'INTERFACE_MODE'}{'gre'}>$Lang::tr{'ipsec interface mode gre'}</option> | |
2601 | <option value='vti' $selected{'INTERFACE_MODE'}{'vti'}>$Lang::tr{'ipsec interface mode vti'}</option> | |
2602 | </select> | |
2603 | </td> | |
2604 | ||
2605 | <td class='boldbase' width='20%'>$Lang::tr{'ip address'}/$Lang::tr{'subnet mask'}:</td> | |
2606 | <td width='30%'> | |
2607 | <input type="text" name="INTERFACE_ADDRESS" value="$cgiparams{'INTERFACE_ADDRESS'}"> | |
2608 | </td> | |
2609 | </tr> | |
2610 | ||
2611 | <tr> | |
2612 | <td class='boldbase' width='20%'>$Lang::tr{'mtu'}:</td> | |
2613 | <td width='30%'> | |
2614 | <input type="number" name="INTERFACE_MTU" value="$cgiparams{'INTERFACE_MTU'}" min="576" max="9000"> | |
2615 | </td> | |
2616 | <td colspan='2'></td> | |
2617 | </tr> | |
2618 | </tbody> | |
2619 | </table> | |
2620 | EOF | |
2621 | &Header::closebox(); | |
2622 | } | |
2623 | ||
624615ee LS |
2624 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { |
2625 | &Header::openbox('100%', 'left', $Lang::tr{'authentication'}); | |
2626 | print <<END | |
2627 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> | |
2628 | <tr><td class='base' width='50%'>$Lang::tr{'use a pre-shared key'}</td> | |
2629 | <td class='base' width='50%'><input type='password' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td> | |
2630 | </tr> | |
2631 | </table> | |
ac1cfefa | 2632 | END |
624615ee LS |
2633 | ; |
2634 | &Header::closebox(); | |
2635 | } elsif (! $cgiparams{'KEY'}) { | |
2636 | my $cakeydisabled = ( ! -f "${General::swroot}/private/cakey.pem" ) ? "disabled='disabled'" : ''; | |
2637 | $cgiparams{'CERT_NAME'} = $Lang::tr{'vpn no full pki'} if ($cakeydisabled); | |
2638 | my $cacrtdisabled = ( ! -f "${General::swroot}/ca/cacert.pem" ) ? "disabled='disabled'" : ''; | |
2639 | ||
2640 | &Header::openbox('100%', 'left', $Lang::tr{'authentication'}); | |
2641 | print <<END | |
2642 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> | |
2643 | <tr><td width='5%'><input type='radio' name='AUTH' value='psk' $checked{'AUTH'}{'psk'} /></td> | |
2644 | <td class='base' width='55%'>$Lang::tr{'use a pre-shared key'}</td> | |
2645 | <td class='base' width='40%'><input type='password' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td></tr> | |
2646 | <tr><td colspan='3' bgcolor='#000000'></td></tr> | |
2647 | <tr><td><input type='radio' name='AUTH' value='certreq' $checked{'AUTH'}{'certreq'} $cakeydisabled /></td> | |
2648 | <td class='base'><hr />$Lang::tr{'upload a certificate request'}</td> | |
2649 | <td class='base' rowspan='3' valign='middle'><input type='file' name='FH' size='30' $cacrtdisabled /></td></tr> | |
2650 | <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td> | |
2651 | <td class='base'>$Lang::tr{'upload a certificate'}</td></tr> | |
2652 | <tr><td><input type='radio' name='AUTH' value='pkcs12' $cacrtdisabled /></td> | |
2653 | <td class='base'>$Lang::tr{'upload p12 file'} $Lang::tr{'pkcs12 file password'}:<input type='password' name='P12_PASS'/></td></tr> | |
2654 | <tr><td><input type='radio' name='AUTH' value='auth-dn' $checked{'AUTH'}{'auth-dn'} $cacrtdisabled /></td> | |
2655 | <td class='base'><hr />$Lang::tr{'vpn auth-dn'}</td></tr> | |
2656 | <tr><td colspan='3' bgcolor='#000000'></td></tr> | |
2657 | <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td> | |
2658 | <td class='base'><hr />$Lang::tr{'generate a certificate'}</td><td> </td></tr> | |
2659 | <tr><td> </td> | |
2660 | <td class='base'>$Lang::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td> | |
2661 | <td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' size='32' $cakeydisabled /></td></tr> | |
2662 | <tr><td> </td> | |
2663 | <td class='base'>$Lang::tr{'users email'}:</td> | |
2664 | <td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' size='32' $cakeydisabled /></td></tr> | |
2665 | <tr><td> </td> | |
2666 | <td class='base'>$Lang::tr{'users department'}:</td> | |
2667 | <td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' size='32' $cakeydisabled /></td></tr> | |
2668 | <tr><td> </td> | |
2158e11b | 2669 | <td class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td> |
624615ee LS |
2670 | <td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' size='32' $cakeydisabled /></td></tr> |
2671 | <tr><td> </td> | |
2672 | <td class='base'>$Lang::tr{'city'}:</td> | |
2673 | <td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' size='32' $cakeydisabled /></td></tr> | |
2674 | <tr><td> </td> | |
2675 | <td class='base'>$Lang::tr{'state or province'}:</td> | |
2676 | <td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' size='32' $cakeydisabled /></td></tr> | |
2677 | <tr><td> </td> | |
2678 | <td class='base'>$Lang::tr{'country'}:</td> | |
2679 | <td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
2680 | END | |
2681 | ; | |
2682 | foreach my $country (sort keys %{Countries::countries}) { | |
2683 | print "\t\t\t<option value='$Countries::countries{$country}'"; | |
2684 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
2685 | print " selected='selected'"; | |
2686 | } | |
2687 | print ">$country</option>\n"; | |
2688 | } | |
2689 | print <<END | |
2690 | </select></td></tr> | |
2691 | ||
2692 | <tr><td> </td><td class='base'>$Lang::tr{'vpn subjectaltname'} (subjectAltName=email:*,URI:*,DNS:*,RID:*)</td> | |
2693 | <td class='base' nowrap='nowrap'><input type='text' name='SUBJECTALTNAME' value='$cgiparams{'SUBJECTALTNAME'}' size='32' $cakeydisabled /></td></tr> | |
2694 | <tr><td> </td> | |
2695 | <td class='base'>$Lang::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' /></td> | |
2696 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
2697 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'} ($Lang::tr{'confirmation'}): <img src='/blob.gif' alt='*' /></td> | |
2698 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> | |
2699 | </table> | |
2700 | END | |
2701 | ; | |
2702 | &Header::closebox(); | |
ac1cfefa MT |
2703 | } |
2704 | ||
624615ee LS |
2705 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
2706 | if ($cgiparams{'KEY'}) { | |
2707 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
2708 | } | |
2709 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
2710 | &Header::closebigbox(); | |
2711 | &Header::closepage(); | |
2712 | exit (0); | |
2713 | ||
2714 | VPNCONF_END: | |
ac1cfefa MT |
2715 | } |
2716 | ||
2717 | ### | |
2718 | ### Advanced settings | |
2719 | ### | |
2720 | if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) || | |
2721 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq 'yes')) { | |
624615ee LS |
2722 | &General::readhash("${General::swroot}/vpn/settings", \%vpnsettings); |
2723 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); | |
2724 | if (! $confighash{$cgiparams{'KEY'}}) { | |
2725 | $errormessage = $Lang::tr{'invalid key'}; | |
2726 | goto ADVANCED_END; | |
2727 | } | |
2728 | ||
2729 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { | |
2730 | my @temp = split('\|', $cgiparams{'IKE_ENCRYPTION'}); | |
2731 | if ($#temp < 0) { | |
2732 | $errormessage = $Lang::tr{'invalid input'}; | |
2733 | goto ADVANCED_ERROR; | |
2734 | } | |
2735 | foreach my $val (@temp) { | |
05375f12 | 2736 | if ($val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/) { |
624615ee LS |
2737 | $errormessage = $Lang::tr{'invalid input'}; |
2738 | goto ADVANCED_ERROR; | |
2739 | } | |
2740 | } | |
2741 | @temp = split('\|', $cgiparams{'IKE_INTEGRITY'}); | |
2742 | if ($#temp < 0) { | |
2743 | $errormessage = $Lang::tr{'invalid input'}; | |
2744 | goto ADVANCED_ERROR; | |
2745 | } | |
2746 | foreach my $val (@temp) { | |
2747 | if ($val !~ /^(sha2_(512|384|256)|sha|md5|aesxcbc)$/) { | |
2748 | $errormessage = $Lang::tr{'invalid input'}; | |
2749 | goto ADVANCED_ERROR; | |
2750 | } | |
2751 | } | |
2752 | @temp = split('\|', $cgiparams{'IKE_GROUPTYPE'}); | |
2753 | if ($#temp < 0) { | |
2754 | $errormessage = $Lang::tr{'invalid input'}; | |
2755 | goto ADVANCED_ERROR; | |
2756 | } | |
2757 | foreach my $val (@temp) { | |
7f662098 | 2758 | if ($val !~ /^(curve448|curve25519|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192)$/) { |
624615ee LS |
2759 | $errormessage = $Lang::tr{'invalid input'}; |
2760 | goto ADVANCED_ERROR; | |
2761 | } | |
2762 | } | |
2763 | if ($cgiparams{'IKE_LIFETIME'} !~ /^\d+$/) { | |
2764 | $errormessage = $Lang::tr{'invalid input for ike lifetime'}; | |
2765 | goto ADVANCED_ERROR; | |
2766 | } | |
610108ff | 2767 | if ($cgiparams{'IKE_LIFETIME'} < 1 || $cgiparams{'IKE_LIFETIME'} > 24) { |
81ebfac7 | 2768 | $errormessage = $Lang::tr{'ike lifetime should be between 1 and 24 hours'}; |
624615ee LS |
2769 | goto ADVANCED_ERROR; |
2770 | } | |
2771 | @temp = split('\|', $cgiparams{'ESP_ENCRYPTION'}); | |
2772 | if ($#temp < 0) { | |
2773 | $errormessage = $Lang::tr{'invalid input'}; | |
2774 | goto ADVANCED_ERROR; | |
2775 | } | |
2776 | foreach my $val (@temp) { | |
05375f12 | 2777 | if ($val !~ /^(aes(256|192|128)(gcm(128|96|64))?|3des|chacha20poly1305|camellia(256|192|128))$/) { |
624615ee LS |
2778 | $errormessage = $Lang::tr{'invalid input'}; |
2779 | goto ADVANCED_ERROR; | |
2780 | } | |
2781 | } | |
2782 | @temp = split('\|', $cgiparams{'ESP_INTEGRITY'}); | |
2783 | if ($#temp < 0) { | |
2784 | $errormessage = $Lang::tr{'invalid input'}; | |
2785 | goto ADVANCED_ERROR; | |
2786 | } | |
2787 | foreach my $val (@temp) { | |
2788 | if ($val !~ /^(sha2_(512|384|256)|sha1|md5|aesxcbc)$/) { | |
2789 | $errormessage = $Lang::tr{'invalid input'}; | |
2790 | goto ADVANCED_ERROR; | |
2791 | } | |
2792 | } | |
2793 | @temp = split('\|', $cgiparams{'ESP_GROUPTYPE'}); | |
2794 | if ($#temp < 0) { | |
2795 | $errormessage = $Lang::tr{'invalid input'}; | |
2796 | goto ADVANCED_ERROR; | |
2797 | } | |
2798 | foreach my $val (@temp) { | |
7f662098 | 2799 | if ($val !~ /^(curve448|curve25519|e521|e384|e256|e224|e192|e512bp|e384bp|e256bp|e224bp|768|1024|1536|2048|3072|4096|6144|8192|none)$/) { |
624615ee LS |
2800 | $errormessage = $Lang::tr{'invalid input'}; |
2801 | goto ADVANCED_ERROR; | |
2802 | } | |
2803 | } | |
2804 | if ($cgiparams{'ESP_KEYLIFE'} !~ /^\d+$/) { | |
2805 | $errormessage = $Lang::tr{'invalid input for esp keylife'}; | |
2806 | goto ADVANCED_ERROR; | |
2807 | } | |
2808 | if ($cgiparams{'ESP_KEYLIFE'} < 1 || $cgiparams{'ESP_KEYLIFE'} > 24) { | |
2809 | $errormessage = $Lang::tr{'esp keylife should be between 1 and 24 hours'}; | |
2810 | goto ADVANCED_ERROR; | |
2811 | } | |
2812 | ||
2813 | if (($cgiparams{'COMPRESSION'} !~ /^(|on|off)$/) || | |
2814 | ($cgiparams{'FORCE_MOBIKE'} !~ /^(|on|off)$/) || | |
2815 | ($cgiparams{'ONLY_PROPOSED'} !~ /^(|on|off)$/) || | |
2816 | ($cgiparams{'PFS'} !~ /^(|on|off)$/)) { | |
2817 | $errormessage = $Lang::tr{'invalid input'}; | |
2818 | goto ADVANCED_ERROR; | |
2819 | } | |
2820 | ||
2821 | if ($cgiparams{'DPD_DELAY'} !~ /^\d+$/) { | |
2822 | $errormessage = $Lang::tr{'invalid input for dpd delay'}; | |
2823 | goto ADVANCED_ERROR; | |
2824 | } | |
2825 | ||
2826 | if ($cgiparams{'DPD_TIMEOUT'} !~ /^\d+$/) { | |
2827 | $errormessage = $Lang::tr{'invalid input for dpd timeout'}; | |
2828 | goto ADVANCED_ERROR; | |
2829 | } | |
2830 | ||
af183eeb MT |
2831 | if ($cgiparams{'INACTIVITY_TIMEOUT'} !~ /^\d+$/) { |
2832 | $errormessage = $Lang::tr{'invalid input for inactivity timeout'}; | |
2833 | goto ADVANCED_ERROR; | |
2834 | } | |
2835 | ||
624615ee LS |
2836 | $confighash{$cgiparams{'KEY'}}[29] = $cgiparams{'IKE_VERSION'}; |
2837 | $confighash{$cgiparams{'KEY'}}[18] = $cgiparams{'IKE_ENCRYPTION'}; | |
2838 | $confighash{$cgiparams{'KEY'}}[19] = $cgiparams{'IKE_INTEGRITY'}; | |
2839 | $confighash{$cgiparams{'KEY'}}[20] = $cgiparams{'IKE_GROUPTYPE'}; | |
2840 | $confighash{$cgiparams{'KEY'}}[16] = $cgiparams{'IKE_LIFETIME'}; | |
2841 | $confighash{$cgiparams{'KEY'}}[21] = $cgiparams{'ESP_ENCRYPTION'}; | |
2842 | $confighash{$cgiparams{'KEY'}}[22] = $cgiparams{'ESP_INTEGRITY'}; | |
2843 | $confighash{$cgiparams{'KEY'}}[23] = $cgiparams{'ESP_GROUPTYPE'}; | |
2844 | $confighash{$cgiparams{'KEY'}}[17] = $cgiparams{'ESP_KEYLIFE'}; | |
2845 | $confighash{$cgiparams{'KEY'}}[12] = 'off'; #$cgiparams{'AGGRMODE'}; | |
2846 | $confighash{$cgiparams{'KEY'}}[13] = $cgiparams{'COMPRESSION'}; | |
2847 | $confighash{$cgiparams{'KEY'}}[24] = $cgiparams{'ONLY_PROPOSED'}; | |
2848 | $confighash{$cgiparams{'KEY'}}[28] = $cgiparams{'PFS'}; | |
2849 | $confighash{$cgiparams{'KEY'}}[27] = $cgiparams{'DPD_ACTION'}; | |
2850 | $confighash{$cgiparams{'KEY'}}[30] = $cgiparams{'DPD_TIMEOUT'}; | |
2851 | $confighash{$cgiparams{'KEY'}}[31] = $cgiparams{'DPD_DELAY'}; | |
2852 | $confighash{$cgiparams{'KEY'}}[32] = $cgiparams{'FORCE_MOBIKE'}; | |
dcb406cc | 2853 | $confighash{$cgiparams{'KEY'}}[33] = $cgiparams{'START_ACTION'}; |
af183eeb | 2854 | $confighash{$cgiparams{'KEY'}}[34] = $cgiparams{'INACTIVITY_TIMEOUT'}; |
624615ee LS |
2855 | &General::writehasharray("${General::swroot}/vpn/config", \%confighash); |
2856 | &writeipsecfiles(); | |
2857 | if (&vpnenabled) { | |
a81cbf61 | 2858 | &General::system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); |
624615ee LS |
2859 | sleep $sleepDelay; |
2860 | } | |
2861 | goto ADVANCED_END; | |
2862 | } else { | |
2863 | $cgiparams{'IKE_VERSION'} = $confighash{$cgiparams{'KEY'}}[29]; | |
2864 | $cgiparams{'IKE_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[18]; | |
2865 | $cgiparams{'IKE_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[19]; | |
2866 | $cgiparams{'IKE_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[20]; | |
2867 | $cgiparams{'IKE_LIFETIME'} = $confighash{$cgiparams{'KEY'}}[16]; | |
2868 | $cgiparams{'ESP_ENCRYPTION'} = $confighash{$cgiparams{'KEY'}}[21]; | |
2869 | $cgiparams{'ESP_INTEGRITY'} = $confighash{$cgiparams{'KEY'}}[22]; | |
2870 | $cgiparams{'ESP_GROUPTYPE'} = $confighash{$cgiparams{'KEY'}}[23]; | |
2871 | if ($cgiparams{'ESP_GROUPTYPE'} eq "") { | |
2872 | $cgiparams{'ESP_GROUPTYPE'} = $cgiparams{'IKE_GROUPTYPE'}; | |
2873 | } | |
2874 | $cgiparams{'ESP_KEYLIFE'} = $confighash{$cgiparams{'KEY'}}[17]; | |
2875 | $cgiparams{'COMPRESSION'} = $confighash{$cgiparams{'KEY'}}[13]; | |
2876 | $cgiparams{'ONLY_PROPOSED'} = $confighash{$cgiparams{'KEY'}}[24]; | |
2877 | $cgiparams{'PFS'} = $confighash{$cgiparams{'KEY'}}[28]; | |
2878 | $cgiparams{'DPD_ACTION'} = $confighash{$cgiparams{'KEY'}}[27]; | |
2879 | $cgiparams{'DPD_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[30]; | |
2880 | $cgiparams{'DPD_DELAY'} = $confighash{$cgiparams{'KEY'}}[31]; | |
2881 | $cgiparams{'FORCE_MOBIKE'} = $confighash{$cgiparams{'KEY'}}[32]; | |
dcb406cc | 2882 | $cgiparams{'START_ACTION'} = $confighash{$cgiparams{'KEY'}}[33]; |
af183eeb | 2883 | $cgiparams{'INACTIVITY_TIMEOUT'} = $confighash{$cgiparams{'KEY'}}[34]; |
29f5e0e2 | 2884 | $cgiparams{'MODE'} = $confighash{$cgiparams{'KEY'}}[35]; |
cae1f4a7 | 2885 | $cgiparams{'INTERFACE_MODE'} = $confighash{$cgiparams{'KEY'}}[36]; |
74641317 | 2886 | $cgiparams{'INTERFACE_ADDRESS'} = $confighash{$cgiparams{'KEY'}}[37]; |
55842dda | 2887 | $cgiparams{'INTERFACE_MTU'} = $confighash{$cgiparams{'KEY'}}[38]; |
dccd7e87 | 2888 | $cgiparams{'DNS_SERVERS'} = $confighash{$cgiparams{'KEY'}}[39]; |
624615ee LS |
2889 | |
2890 | if (!$cgiparams{'DPD_DELAY'}) { | |
2891 | $cgiparams{'DPD_DELAY'} = 30; | |
2892 | } | |
2893 | ||
2894 | if (!$cgiparams{'DPD_TIMEOUT'}) { | |
2895 | $cgiparams{'DPD_TIMEOUT'} = 120; | |
2896 | } | |
dcb406cc MT |
2897 | |
2898 | if (!$cgiparams{'START_ACTION'}) { | |
2899 | $cgiparams{'START_ACTION'} = "start"; | |
2900 | } | |
af183eeb MT |
2901 | |
2902 | if ($cgiparams{'INACTIVITY_TIMEOUT'} eq "") { | |
2903 | $cgiparams{'INACTIVITY_TIMEOUT'} = 900; # 15 min | |
2904 | } | |
29f5e0e2 MT |
2905 | |
2906 | if ($cgiparams{'MODE'} eq "") { | |
2907 | $cgiparams{'MODE'} = "tunnel"; | |
2908 | } | |
ac1cfefa | 2909 | } |
624615ee LS |
2910 | |
2911 | ADVANCED_ERROR: | |
05375f12 | 2912 | $checked{'IKE_ENCRYPTION'}{'chacha20poly1305'} = ''; |
624615ee LS |
2913 | $checked{'IKE_ENCRYPTION'}{'aes256'} = ''; |
2914 | $checked{'IKE_ENCRYPTION'}{'aes192'} = ''; | |
2915 | $checked{'IKE_ENCRYPTION'}{'aes128'} = ''; | |
2916 | $checked{'IKE_ENCRYPTION'}{'aes256gcm128'} = ''; | |
2917 | $checked{'IKE_ENCRYPTION'}{'aes192gcm128'} = ''; | |
2918 | $checked{'IKE_ENCRYPTION'}{'aes128gcm128'} = ''; | |
2919 | $checked{'IKE_ENCRYPTION'}{'aes256gcm96'} = ''; | |
2920 | $checked{'IKE_ENCRYPTION'}{'aes192gcm96'} = ''; | |
2921 | $checked{'IKE_ENCRYPTION'}{'aes128gcm96'} = ''; | |
2922 | $checked{'IKE_ENCRYPTION'}{'aes256gcm64'} = ''; | |
2923 | $checked{'IKE_ENCRYPTION'}{'aes192gcm64'} = ''; | |
2924 | $checked{'IKE_ENCRYPTION'}{'aes128gcm64'} = ''; | |
2925 | $checked{'IKE_ENCRYPTION'}{'3des'} = ''; | |
2926 | $checked{'IKE_ENCRYPTION'}{'camellia256'} = ''; | |
2927 | $checked{'IKE_ENCRYPTION'}{'camellia192'} = ''; | |
2928 | $checked{'IKE_ENCRYPTION'}{'camellia128'} = ''; | |
2929 | my @temp = split('\|', $cgiparams{'IKE_ENCRYPTION'}); | |
2930 | foreach my $key (@temp) {$checked{'IKE_ENCRYPTION'}{$key} = "selected='selected'"; } | |
2931 | $checked{'IKE_INTEGRITY'}{'sha2_512'} = ''; | |
2932 | $checked{'IKE_INTEGRITY'}{'sha2_384'} = ''; | |
2933 | $checked{'IKE_INTEGRITY'}{'sha2_256'} = ''; | |
2934 | $checked{'IKE_INTEGRITY'}{'sha'} = ''; | |
2935 | $checked{'IKE_INTEGRITY'}{'md5'} = ''; | |
2936 | $checked{'IKE_INTEGRITY'}{'aesxcbc'} = ''; | |
ac1cfefa | 2937 | @temp = split('\|', $cgiparams{'IKE_INTEGRITY'}); |
624615ee | 2938 | foreach my $key (@temp) {$checked{'IKE_INTEGRITY'}{$key} = "selected='selected'"; } |
d47b2cc2 | 2939 | $checked{'IKE_GROUPTYPE'}{'curve448'} = ''; |
7f662098 | 2940 | $checked{'IKE_GROUPTYPE'}{'curve25519'} = ''; |
624615ee LS |
2941 | $checked{'IKE_GROUPTYPE'}{'768'} = ''; |
2942 | $checked{'IKE_GROUPTYPE'}{'1024'} = ''; | |
2943 | $checked{'IKE_GROUPTYPE'}{'1536'} = ''; | |
2944 | $checked{'IKE_GROUPTYPE'}{'2048'} = ''; | |
2945 | $checked{'IKE_GROUPTYPE'}{'3072'} = ''; | |
2946 | $checked{'IKE_GROUPTYPE'}{'4096'} = ''; | |
2947 | $checked{'IKE_GROUPTYPE'}{'6144'} = ''; | |
2948 | $checked{'IKE_GROUPTYPE'}{'8192'} = ''; | |
ac1cfefa | 2949 | @temp = split('\|', $cgiparams{'IKE_GROUPTYPE'}); |
624615ee LS |
2950 | foreach my $key (@temp) {$checked{'IKE_GROUPTYPE'}{$key} = "selected='selected'"; } |
2951 | ||
05375f12 | 2952 | $checked{'ESP_ENCRYPTION'}{'chacha20poly1305'} = ''; |
624615ee LS |
2953 | $checked{'ESP_ENCRYPTION'}{'aes256'} = ''; |
2954 | $checked{'ESP_ENCRYPTION'}{'aes192'} = ''; | |
2955 | $checked{'ESP_ENCRYPTION'}{'aes128'} = ''; | |
2956 | $checked{'ESP_ENCRYPTION'}{'aes256gcm128'} = ''; | |
2957 | $checked{'ESP_ENCRYPTION'}{'aes192gcm128'} = ''; | |
2958 | $checked{'ESP_ENCRYPTION'}{'aes128gcm128'} = ''; | |
2959 | $checked{'ESP_ENCRYPTION'}{'aes256gcm96'} = ''; | |
2960 | $checked{'ESP_ENCRYPTION'}{'aes192gcm96'} = ''; | |
2961 | $checked{'ESP_ENCRYPTION'}{'aes128gcm96'} = ''; | |
2962 | $checked{'ESP_ENCRYPTION'}{'aes256gcm64'} = ''; | |
2963 | $checked{'ESP_ENCRYPTION'}{'aes192gcm64'} = ''; | |
2964 | $checked{'ESP_ENCRYPTION'}{'aes128gcm64'} = ''; | |
2965 | $checked{'ESP_ENCRYPTION'}{'3des'} = ''; | |
2966 | $checked{'ESP_ENCRYPTION'}{'camellia256'} = ''; | |
2967 | $checked{'ESP_ENCRYPTION'}{'camellia192'} = ''; | |
2968 | $checked{'ESP_ENCRYPTION'}{'camellia128'} = ''; | |
ac1cfefa | 2969 | @temp = split('\|', $cgiparams{'ESP_ENCRYPTION'}); |
624615ee LS |
2970 | foreach my $key (@temp) {$checked{'ESP_ENCRYPTION'}{$key} = "selected='selected'"; } |
2971 | $checked{'ESP_INTEGRITY'}{'sha2_512'} = ''; | |
2972 | $checked{'ESP_INTEGRITY'}{'sha2_384'} = ''; | |
2973 | $checked{'ESP_INTEGRITY'}{'sha2_256'} = ''; | |
2974 | $checked{'ESP_INTEGRITY'}{'sha1'} = ''; | |
2975 | $checked{'ESP_INTEGRITY'}{'md5'} = ''; | |
2976 | $checked{'ESP_INTEGRITY'}{'aesxcbc'} = ''; | |
ac1cfefa | 2977 | @temp = split('\|', $cgiparams{'ESP_INTEGRITY'}); |
624615ee | 2978 | foreach my $key (@temp) {$checked{'ESP_INTEGRITY'}{$key} = "selected='selected'"; } |
d47b2cc2 | 2979 | $checked{'ESP_GROUPTYPE'}{'curve448'} = ''; |
7f662098 | 2980 | $checked{'ESP_GROUPTYPE'}{'curve25519'} = ''; |
624615ee LS |
2981 | $checked{'ESP_GROUPTYPE'}{'768'} = ''; |
2982 | $checked{'ESP_GROUPTYPE'}{'1024'} = ''; | |
2983 | $checked{'ESP_GROUPTYPE'}{'1536'} = ''; | |
2984 | $checked{'ESP_GROUPTYPE'}{'2048'} = ''; | |
2985 | $checked{'ESP_GROUPTYPE'}{'3072'} = ''; | |
2986 | $checked{'ESP_GROUPTYPE'}{'4096'} = ''; | |
2987 | $checked{'ESP_GROUPTYPE'}{'6144'} = ''; | |
2988 | $checked{'ESP_GROUPTYPE'}{'8192'} = ''; | |
2989 | $checked{'ESP_GROUPTYPE'}{'none'} = ''; | |
4b02b404 | 2990 | @temp = split('\|', $cgiparams{'ESP_GROUPTYPE'}); |
624615ee | 2991 | foreach my $key (@temp) {$checked{'ESP_GROUPTYPE'}{$key} = "selected='selected'"; } |
ed84e8b8 | 2992 | |
624615ee LS |
2993 | $checked{'COMPRESSION'} = $cgiparams{'COMPRESSION'} eq 'on' ? "checked='checked'" : '' ; |
2994 | $checked{'FORCE_MOBIKE'} = $cgiparams{'FORCE_MOBIKE'} eq 'on' ? "checked='checked'" : '' ; | |
2995 | $checked{'ONLY_PROPOSED'} = $cgiparams{'ONLY_PROPOSED'} eq 'on' ? "checked='checked'" : '' ; | |
2996 | $checked{'PFS'} = $cgiparams{'PFS'} eq 'on' ? "checked='checked'" : '' ; | |
cbb3a8f9 | 2997 | |
624615ee LS |
2998 | $selected{'IKE_VERSION'}{'ikev1'} = ''; |
2999 | $selected{'IKE_VERSION'}{'ikev2'} = ''; | |
3000 | $selected{'IKE_VERSION'}{$cgiparams{'IKE_VERSION'}} = "selected='selected'"; | |
cbb3a8f9 | 3001 | |
624615ee LS |
3002 | $selected{'DPD_ACTION'}{'clear'} = ''; |
3003 | $selected{'DPD_ACTION'}{'hold'} = ''; | |
3004 | $selected{'DPD_ACTION'}{'restart'} = ''; | |
3005 | $selected{'DPD_ACTION'}{'none'} = ''; | |
3006 | $selected{'DPD_ACTION'}{$cgiparams{'DPD_ACTION'}} = "selected='selected'"; | |
ac1cfefa | 3007 | |
237f3ab7 | 3008 | $selected{'START_ACTION'}{'add'} = ''; |
dcb406cc MT |
3009 | $selected{'START_ACTION'}{'route'} = ''; |
3010 | $selected{'START_ACTION'}{'start'} = ''; | |
3011 | $selected{'START_ACTION'}{$cgiparams{'START_ACTION'}} = "selected='selected'"; | |
3012 | ||
af183eeb MT |
3013 | $selected{'INACTIVITY_TIMEOUT'} = (); |
3014 | foreach my $timeout (keys %INACTIVITY_TIMEOUTS) { | |
3015 | $selected{'INACTIVITY_TIMEOUT'}{$timeout} = ""; | |
3016 | } | |
3017 | $selected{'INACTIVITY_TIMEOUT'}{$cgiparams{'INACTIVITY_TIMEOUT'}} = "selected"; | |
3018 | ||
624615ee LS |
3019 | &Header::showhttpheaders(); |
3020 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); | |
3021 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
3022 | ||
3023 | if ($errormessage) { | |
3024 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
3025 | print "<class name='base'>$errormessage"; | |
3026 | print " </class>"; | |
3027 | &Header::closebox(); | |
3028 | } | |
3029 | ||
3030 | if ($warnmessage) { | |
3031 | &Header::openbox('100%', 'left', $Lang::tr{'warning messages'}); | |
3032 | print "<class name='base'>$warnmessage"; | |
3033 | print " </class>"; | |
3034 | &Header::closebox(); | |
3035 | } | |
ac1cfefa | 3036 | |
624615ee | 3037 | &Header::openbox('100%', 'left', "$Lang::tr{'advanced'}:"); |
dcb406cc | 3038 | print <<EOF; |
624615ee LS |
3039 | <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'> |
3040 | <input type='hidden' name='ADVANCED' value='yes' /> | |
3041 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
ac1cfefa | 3042 | |
624615ee | 3043 | <table width='100%'> |
63e3da59 MT |
3044 | <thead> |
3045 | <tr> | |
cbb3a8f9 | 3046 | <th width="15%"></th> |
63e3da59 MT |
3047 | <th>IKE</th> |
3048 | <th>ESP</th> | |
3049 | </tr> | |
3050 | </thead> | |
3051 | <tbody> | |
4ad0b5b6 MT |
3052 | <tr> |
3053 | <td>$Lang::tr{'vpn keyexchange'}:</td> | |
3054 | <td> | |
3055 | <select name='IKE_VERSION'> | |
3056 | <option value='ikev2' $selected{'IKE_VERSION'}{'ikev2'}>IKEv2</option> | |
3057 | <option value='ikev1' $selected{'IKE_VERSION'}{'ikev1'}>IKEv1</option> | |
3058 | </select> | |
3059 | </td> | |
3060 | <td></td> | |
3061 | </tr> | |
63e3da59 | 3062 | <tr> |
cbb3a8f9 | 3063 | <td class='boldbase' width="15%">$Lang::tr{'encryption'}</td> |
63e3da59 MT |
3064 | <td class='boldbase'> |
3065 | <select name='IKE_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'> | |
05375f12 | 3066 | <option value='chacha20poly1305' $checked{'IKE_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option> |
dfea4f86 | 3067 | <option value='aes256gcm128' $checked{'IKE_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option> |
dfea4f86 | 3068 | <option value='aes256gcm96' $checked{'IKE_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option> |
dfea4f86 | 3069 | <option value='aes256gcm64' $checked{'IKE_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option> |
a4d24f90 | 3070 | <option value='aes256' $checked{'IKE_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option> |
dfea4f86 | 3071 | <option value='camellia256' $checked{'IKE_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option> |
a4d24f90 MT |
3072 | <option value='aes192gcm128' $checked{'IKE_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option> |
3073 | <option value='aes192gcm96' $checked{'IKE_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option> | |
3074 | <option value='aes192gcm64' $checked{'IKE_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option> | |
3075 | <option value='aes192' $checked{'IKE_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option> | |
dfea4f86 | 3076 | <option value='camellia192' $checked{'IKE_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option> |
a4d24f90 MT |
3077 | <option value='aes128gcm128' $checked{'IKE_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option> |
3078 | <option value='aes128gcm96' $checked{'IKE_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option> | |
3079 | <option value='aes128gcm64' $checked{'IKE_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option> | |
3080 | <option value='aes128' $checked{'IKE_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option> | |
dfea4f86 | 3081 | <option value='camellia128' $checked{'IKE_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option> |
6fc0f5eb | 3082 | <option value='3des' $checked{'IKE_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ($Lang::tr{'vpn weak'})</option> |
63e3da59 MT |
3083 | </select> |
3084 | </td> | |
3085 | <td class='boldbase'> | |
3086 | <select name='ESP_ENCRYPTION' multiple='multiple' size='6' style='width: 100%'> | |
05375f12 | 3087 | <option value='chacha20poly1305' $checked{'ESP_ENCRYPTION'}{'chacha20poly1305'}>256 bit ChaCha20-Poly1305/128 bit ICV</option> |
dfea4f86 | 3088 | <option value='aes256gcm128' $checked{'ESP_ENCRYPTION'}{'aes256gcm128'}>256 bit AES-GCM/128 bit ICV</option> |
dfea4f86 | 3089 | <option value='aes256gcm96' $checked{'ESP_ENCRYPTION'}{'aes256gcm96'}>256 bit AES-GCM/96 bit ICV</option> |
dfea4f86 | 3090 | <option value='aes256gcm64' $checked{'ESP_ENCRYPTION'}{'aes256gcm64'}>256 bit AES-GCM/64 bit ICV</option> |
a4d24f90 | 3091 | <option value='aes256' $checked{'ESP_ENCRYPTION'}{'aes256'}>256 bit AES-CBC</option> |
dfea4f86 | 3092 | <option value='camellia256' $checked{'ESP_ENCRYPTION'}{'camellia256'}>256 bit Camellia-CBC</option> |
a4d24f90 MT |
3093 | <option value='aes192gcm128' $checked{'ESP_ENCRYPTION'}{'aes192gcm128'}>192 bit AES-GCM/128 bit ICV</option> |
3094 | <option value='aes192gcm96' $checked{'ESP_ENCRYPTION'}{'aes192gcm96'}>192 bit AES-GCM/96 bit ICV</option> | |
3095 | <option value='aes192gcm64' $checked{'ESP_ENCRYPTION'}{'aes192gcm64'}>192 bit AES-GCM/64 bit ICV</option> | |
3096 | <option value='aes192' $checked{'ESP_ENCRYPTION'}{'aes192'}>192 bit AES-CBC</option> | |
dfea4f86 | 3097 | <option value='camellia192' $checked{'ESP_ENCRYPTION'}{'camellia192'}>192 bit Camellia-CBC</option> |
a4d24f90 MT |
3098 | <option value='aes128gcm128' $checked{'ESP_ENCRYPTION'}{'aes128gcm128'}>128 bit AES-GCM/128 bit ICV</option> |
3099 | <option value='aes128gcm96' $checked{'ESP_ENCRYPTION'}{'aes128gcm96'}>128 bit AES-GCM/96 bit ICV</option> | |
3100 | <option value='aes128gcm64' $checked{'ESP_ENCRYPTION'}{'aes128gcm64'}>128 bit AES-GCM/64 bit ICV</option> | |
3101 | <option value='aes128' $checked{'ESP_ENCRYPTION'}{'aes128'}>128 bit AES-CBC</option> | |
dfea4f86 | 3102 | <option value='camellia128' $checked{'ESP_ENCRYPTION'}{'camellia128'}>128 bit Camellia-CBC</option> |
6fc0f5eb | 3103 | <option value='3des' $checked{'ESP_ENCRYPTION'}{'3des'}>168 bit 3DES-EDE-CBC ($Lang::tr{'vpn weak'})</option> |
63e3da59 MT |
3104 | </select> |
3105 | </td> | |
3106 | </tr> | |
ed84e8b8 | 3107 | |
63e3da59 | 3108 | <tr> |
cbb3a8f9 | 3109 | <td class='boldbase' width="15%">$Lang::tr{'integrity'}</td> |
63e3da59 MT |
3110 | <td class='boldbase'> |
3111 | <select name='IKE_INTEGRITY' multiple='multiple' size='6' style='width: 100%'> | |
3112 | <option value='sha2_512' $checked{'IKE_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option> | |
3113 | <option value='sha2_384' $checked{'IKE_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option> | |
3114 | <option value='sha2_256' $checked{'IKE_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option> | |
a4d24f90 | 3115 | <option value='aesxcbc' $checked{'IKE_INTEGRITY'}{'aesxcbc'}>AES XCBC</option> |
c94d1976 | 3116 | <option value='sha' $checked{'IKE_INTEGRITY'}{'sha'}>SHA1 ($Lang::tr{'vpn weak'})</option> |
86282bdc | 3117 | <option value='md5' $checked{'IKE_INTEGRITY'}{'md5'}>MD5 ($Lang::tr{'vpn broken'})</option> |
63e3da59 MT |
3118 | </select> |
3119 | </td> | |
3120 | <td class='boldbase'> | |
3121 | <select name='ESP_INTEGRITY' multiple='multiple' size='6' style='width: 100%'> | |
3122 | <option value='sha2_512' $checked{'ESP_INTEGRITY'}{'sha2_512'}>SHA2 512 bit</option> | |
3123 | <option value='sha2_384' $checked{'ESP_INTEGRITY'}{'sha2_384'}>SHA2 384 bit</option> | |
3124 | <option value='sha2_256' $checked{'ESP_INTEGRITY'}{'sha2_256'}>SHA2 256 bit</option> | |
a4d24f90 | 3125 | <option value='aesxcbc' $checked{'ESP_INTEGRITY'}{'aesxcbc'}>AES XCBC</option> |
c94d1976 MT |
3126 | <option value='sha1' $checked{'ESP_INTEGRITY'}{'sha1'}>SHA1 ($Lang::tr{'vpn weak'})</option> |
3127 | <option value='md5' $checked{'ESP_INTEGRITY'}{'md5'}>MD5 ($Lang::tr{'vpn broken'})</option> | |
63e3da59 MT |
3128 | </select> |
3129 | </td> | |
3130 | </tr> | |
3131 | <tr> | |
e3edceeb | 3132 | <td class='boldbase' width="15%">$Lang::tr{'lifetime'} <img src='/blob.gif' alt='*' /></td> |
63e3da59 MT |
3133 | <td class='boldbase'> |
3134 | <input type='text' name='IKE_LIFETIME' value='$cgiparams{'IKE_LIFETIME'}' size='5' /> $Lang::tr{'hours'} | |
3135 | </td> | |
3136 | <td class='boldbase'> | |
3137 | <input type='text' name='ESP_KEYLIFE' value='$cgiparams{'ESP_KEYLIFE'}' size='5' /> $Lang::tr{'hours'} | |
3138 | </td> | |
3139 | </tr> | |
3140 | <tr> | |
cbb3a8f9 | 3141 | <td class='boldbase' width="15%">$Lang::tr{'grouptype'}</td> |
63e3da59 MT |
3142 | <td class='boldbase'> |
3143 | <select name='IKE_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'> | |
d47b2cc2 | 3144 | <option value='curve448' $checked{'IKE_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option> |
7f662098 | 3145 | <option value='curve25519' $checked{'IKE_GROUPTYPE'}{'curve25519'}>Curve 25519 (128 bit)</option> |
63e3da59 | 3146 | <option value='e521' $checked{'IKE_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option> |
63e3da59 | 3147 | <option value='e512bp' $checked{'IKE_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option> |
a4d24f90 | 3148 | <option value='e384' $checked{'IKE_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option> |
63e3da59 | 3149 | <option value='e384bp' $checked{'IKE_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option> |
a4d24f90 | 3150 | <option value='e256' $checked{'IKE_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option> |
63e3da59 | 3151 | <option value='e256bp' $checked{'IKE_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option> |
a4d24f90 | 3152 | <option value='e224' $checked{'IKE_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option> |
63e3da59 | 3153 | <option value='e224bp' $checked{'IKE_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option> |
a4d24f90 | 3154 | <option value='e192' $checked{'IKE_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option> |
63e3da59 MT |
3155 | <option value='8192' $checked{'IKE_GROUPTYPE'}{'8192'}>MODP-8192</option> |
3156 | <option value='6144' $checked{'IKE_GROUPTYPE'}{'6144'}>MODP-6144</option> | |
3157 | <option value='4096' $checked{'IKE_GROUPTYPE'}{'4096'}>MODP-4096</option> | |
3158 | <option value='3072' $checked{'IKE_GROUPTYPE'}{'3072'}>MODP-3072</option> | |
46803376 PM |
3159 | <option value='2048' $checked{'IKE_GROUPTYPE'}{'2048'}>MODP-2048 ($Lang::tr{'vpn weak'})</option> |
3160 | <option value='1536' $checked{'IKE_GROUPTYPE'}{'1536'}>MODP-1536 ($Lang::tr{'vpn broken'})</option> | |
c94d1976 MT |
3161 | <option value='1024' $checked{'IKE_GROUPTYPE'}{'1024'}>MODP-1024 ($Lang::tr{'vpn broken'})</option> |
3162 | <option value='768' $checked{'IKE_GROUPTYPE'}{'768'}>MODP-768 ($Lang::tr{'vpn broken'})</option> | |
63e3da59 MT |
3163 | </select> |
3164 | </td> | |
4b02b404 MT |
3165 | <td class='boldbase'> |
3166 | <select name='ESP_GROUPTYPE' multiple='multiple' size='6' style='width: 100%'> | |
d47b2cc2 | 3167 | <option value='curve448' $checked{'ESP_GROUPTYPE'}{'curve448'}>Curve 448 (224 bit)</option> |
7f662098 | 3168 | <option value='curve25519' $checked{'ESP_GROUPTYPE'}{'curve25519'}>Curve 25519 (128 bit)</option> |
4b02b404 MT |
3169 | <option value='e521' $checked{'ESP_GROUPTYPE'}{'e521'}>ECP-521 (NIST)</option> |
3170 | <option value='e512bp' $checked{'ESP_GROUPTYPE'}{'e512bp'}>ECP-512 (Brainpool)</option> | |
3171 | <option value='e384' $checked{'ESP_GROUPTYPE'}{'e384'}>ECP-384 (NIST)</option> | |
3172 | <option value='e384bp' $checked{'ESP_GROUPTYPE'}{'e384bp'}>ECP-384 (Brainpool)</option> | |
3173 | <option value='e256' $checked{'ESP_GROUPTYPE'}{'e256'}>ECP-256 (NIST)</option> | |
3174 | <option value='e256bp' $checked{'ESP_GROUPTYPE'}{'e256bp'}>ECP-256 (Brainpool)</option> | |
3175 | <option value='e224' $checked{'ESP_GROUPTYPE'}{'e224'}>ECP-224 (NIST)</option> | |
3176 | <option value='e224bp' $checked{'ESP_GROUPTYPE'}{'e224bp'}>ECP-224 (Brainpool)</option> | |
3177 | <option value='e192' $checked{'ESP_GROUPTYPE'}{'e192'}>ECP-192 (NIST)</option> | |
3178 | <option value='8192' $checked{'ESP_GROUPTYPE'}{'8192'}>MODP-8192</option> | |
3179 | <option value='6144' $checked{'ESP_GROUPTYPE'}{'6144'}>MODP-6144</option> | |
3180 | <option value='4096' $checked{'ESP_GROUPTYPE'}{'4096'}>MODP-4096</option> | |
3181 | <option value='3072' $checked{'ESP_GROUPTYPE'}{'3072'}>MODP-3072</option> | |
46803376 PM |
3182 | <option value='2048' $checked{'ESP_GROUPTYPE'}{'2048'}>MODP-2048 ($Lang::tr{'vpn weak'})</option> |
3183 | <option value='1536' $checked{'ESP_GROUPTYPE'}{'1536'}>MODP-1536 ($Lang::tr{'vpn broken'})</option> | |
c94d1976 MT |
3184 | <option value='1024' $checked{'ESP_GROUPTYPE'}{'1024'}>MODP-1024 ($Lang::tr{'vpn broken'})</option> |
3185 | <option value='768' $checked{'ESP_GROUPTYPE'}{'768'}>MODP-768 ($Lang::tr{'vpn broken'})</option> | |
4b02b404 MT |
3186 | <option value='none' $checked{'ESP_GROUPTYPE'}{'none'}>- $Lang::tr{'none'} -</option> |
3187 | </select> | |
3188 | </td> | |
63e3da59 MT |
3189 | </tr> |
3190 | </tbody> | |
624615ee | 3191 | </table> |
63e3da59 | 3192 | |
cbb3a8f9 MT |
3193 | <br><br> |
3194 | ||
3195 | <h2>$Lang::tr{'dead peer detection'}</h2> | |
3196 | ||
624615ee LS |
3197 | <table width="100%"> |
3198 | <tr> | |
cbb3a8f9 MT |
3199 | <td width="15%">$Lang::tr{'dpd action'}:</td> |
3200 | <td> | |
3201 | <select name='DPD_ACTION'> | |
afd5d8f7 | 3202 | <option value='none' $selected{'DPD_ACTION'}{'none'}>- $Lang::tr{'disabled'} -</option> |
cbb3a8f9 MT |
3203 | <option value='clear' $selected{'DPD_ACTION'}{'clear'}>clear</option> |
3204 | <option value='hold' $selected{'DPD_ACTION'}{'hold'}>hold</option> | |
3205 | <option value='restart' $selected{'DPD_ACTION'}{'restart'}>restart</option> | |
3206 | </select> | |
3207 | </td> | |
3208 | </tr> | |
3209 | <tr> | |
e3edceeb | 3210 | <td width="15%">$Lang::tr{'dpd timeout'}: <img src='/blob.gif' alt='*' /></td> |
cbb3a8f9 MT |
3211 | <td> |
3212 | <input type='text' name='DPD_TIMEOUT' size='5' value='$cgiparams{'DPD_TIMEOUT'}' /> | |
3213 | </td> | |
3214 | </tr> | |
3215 | <tr> | |
e3edceeb | 3216 | <td width="15%">$Lang::tr{'dpd delay'}: <img src='/blob.gif' alt='*' /></td> |
cbb3a8f9 MT |
3217 | <td> |
3218 | <input type='text' name='DPD_DELAY' size='5' value='$cgiparams{'DPD_DELAY'}' /> | |
3219 | </td> | |
3220 | </tr> | |
624615ee | 3221 | </table> |
cbb3a8f9 | 3222 | |
624615ee | 3223 | <hr> |
63e3da59 | 3224 | |
624615ee | 3225 | <table width="100%"> |
63e3da59 | 3226 | <tr> |
cbb3a8f9 | 3227 | <td> |
63e3da59 MT |
3228 | <label> |
3229 | <input type='checkbox' name='ONLY_PROPOSED' $checked{'ONLY_PROPOSED'} /> | |
cbb88df1 | 3230 | IKE+ESP: $Lang::tr{'use only proposed settings'} |
63e3da59 MT |
3231 | </label> |
3232 | </td> | |
dcb406cc MT |
3233 | <td> |
3234 | <label>$Lang::tr{'vpn start action'}</label> | |
3235 | <select name="START_ACTION"> | |
3236 | <option value="route" $selected{'START_ACTION'}{'route'}>$Lang::tr{'vpn start action route'}</option> | |
3237 | <option value="start" $selected{'START_ACTION'}{'start'}>$Lang::tr{'vpn start action start'}</option> | |
237f3ab7 | 3238 | <option value="add" $selected{'START_ACTION'}{'add'} >$Lang::tr{'vpn start action add'}</option> |
dcb406cc MT |
3239 | </select> |
3240 | </td> | |
63e3da59 MT |
3241 | </tr> |
3242 | <tr> | |
af183eeb | 3243 | <td> |
63e3da59 MT |
3244 | <label> |
3245 | <input type='checkbox' name='PFS' $checked{'PFS'} /> | |
3246 | $Lang::tr{'pfs yes no'} | |
3247 | </label> | |
3248 | </td> | |
af183eeb MT |
3249 | <td> |
3250 | <label>$Lang::tr{'vpn inactivity timeout'}</label> | |
3251 | <select name="INACTIVITY_TIMEOUT"> | |
3252 | EOF | |
3253 | foreach my $t (sort { $a <=> $b } keys %INACTIVITY_TIMEOUTS) { | |
3254 | print "<option value=\"$t\" $selected{'INACTIVITY_TIMEOUT'}{$t}>$INACTIVITY_TIMEOUTS{$t}</option>\n"; | |
3255 | } | |
3256 | ||
3257 | print <<EOF; | |
3258 | ||
3259 | </select> | |
3260 | </td> | |
63e3da59 MT |
3261 | </tr> |
3262 | <tr> | |
dcb406cc | 3263 | <td colspan="2"> |
63e3da59 MT |
3264 | <label> |
3265 | <input type='checkbox' name='COMPRESSION' $checked{'COMPRESSION'} /> | |
3266 | $Lang::tr{'vpn payload compression'} | |
3267 | </label> | |
3268 | </td> | |
ed84e8b8 | 3269 | </tr> |
f6529a04 | 3270 | <tr> |
dcb406cc | 3271 | <td colspan="2"> |
f6529a04 MT |
3272 | <label> |
3273 | <input type='checkbox' name='FORCE_MOBIKE' $checked{'FORCE_MOBIKE'} /> | |
3274 | $Lang::tr{'vpn force mobike'} | |
3275 | </label> | |
3276 | </td> | |
3277 | </tr> | |
63e3da59 | 3278 | <tr> |
dcb406cc MT |
3279 | <td align='left'><img src='/blob.gif' align='top' alt='*' /> $Lang::tr{'required field'}</td> |
3280 | <td align='right'> | |
63e3da59 MT |
3281 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /> |
3282 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /> | |
3283 | </td> | |
3284 | </tr> | |
624615ee | 3285 | </table></form> |
63e3da59 MT |
3286 | EOF |
3287 | ||
624615ee LS |
3288 | &Header::closebox(); |
3289 | &Header::closebigbox(); | |
3290 | &Header::closepage(); | |
3291 | exit(0); | |
ac1cfefa | 3292 | |
624615ee | 3293 | ADVANCED_END: |
ac1cfefa MT |
3294 | } |
3295 | ||
3296 | ### | |
3297 | ### Default status page | |
3298 | ### | |
624615ee LS |
3299 | %cgiparams = (); |
3300 | %cahash = (); | |
3301 | %confighash = (); | |
3302 | &General::readhash("${General::swroot}/vpn/settings", \%cgiparams); | |
3303 | &General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash); | |
3304 | &General::readhasharray("${General::swroot}/vpn/config", \%confighash); | |
3305 | $cgiparams{'CA_NAME'} = ''; | |
3306 | ||
a81cbf61 | 3307 | my @status = &General::system_output("/usr/local/bin/ipsecctrl", "I"); |
624615ee | 3308 | |
624615ee LS |
3309 | $checked{'ENABLED'} = $cgiparams{'ENABLED'} eq 'on' ? "checked='checked'" : ''; |
3310 | ||
3311 | &Header::showhttpheaders(); | |
3312 | &Header::openpage($Lang::tr{'ipsec'}, 1, ''); | |
3313 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
3314 | ||
3315 | if ($errormessage) { | |
3316 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
3317 | print "<class name='base'>$errormessage\n"; | |
3318 | print " </class>\n"; | |
3319 | &Header::closebox(); | |
3320 | } | |
ac1cfefa | 3321 | |
4d81e0f3 AM |
3322 | if ($warnmessage) { |
3323 | &Header::openbox('100%', 'left', $Lang::tr{'warning messages'}); | |
3324 | print "$warnmessage<br>"; | |
3325 | print "$Lang::tr{'fwdfw warn1'}<br>"; | |
3326 | &Header::closebox(); | |
03b08c08 | 3327 | print"<center><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'ok'}' style='width: 5em;'></form>"; |
4d81e0f3 AM |
3328 | &Header::closepage(); |
3329 | exit 0; | |
3330 | } | |
3331 | ||
624615ee LS |
3332 | &Header::openbox('100%', 'left', $Lang::tr{'global settings'}); |
3333 | print <<END | |
3334 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
3335 | <table width='100%'> | |
38f6bdb7 MT |
3336 | <tr> |
3337 | <td width='60%' class='base'> | |
3338 | $Lang::tr{'enabled'} | |
3339 | </td> | |
3340 | <td width="40%"> | |
3341 | <input type='checkbox' name='ENABLED' $checked{'ENABLED'} /> | |
3342 | </td> | |
3343 | </tr> | |
c7fe09c6 MT |
3344 | <tr> |
3345 | <td class='base' nowrap='nowrap' width="60%">$Lang::tr{'ipsec roadwarrior endpoint'}:</td> | |
3346 | <td width="40%"><input type='text' name='RW_ENDPOINT' value='$cgiparams{'RW_ENDPOINT'}' /></td> | |
3347 | </tr> | |
38f6bdb7 MT |
3348 | <tr> |
3349 | <td class='base' nowrap='nowrap' width="60%">$Lang::tr{'host to net vpn'}:</td> | |
3350 | <td width="40%"><input type='text' name='RW_NET' value='$cgiparams{'RW_NET'}' /></td> | |
3351 | </tr> | |
3352 | <tr> | |
3353 | <td width='100%' colspan="2" align='right' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td> | |
3354 | </tr> | |
ac1cfefa MT |
3355 | </table> |
3356 | END | |
624615ee LS |
3357 | ; |
3358 | print "</form>"; | |
3359 | &Header::closebox(); | |
3360 | ||
3361 | &Header::openbox('100%', 'left', $Lang::tr{'connection status and controlc'}); | |
3362 | print <<END | |
3363 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
3364 | <tr> | |
e9850821 AM |
3365 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> |
3366 | <th width='22%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
3367 | <th width='23%' class='boldbase' align='center'><b>$Lang::tr{'common name'}</b></th> | |
3368 | <th width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
3369 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
26a0befd | 3370 | <th class='boldbase' align='center' colspan='7'><b>$Lang::tr{'action'}</b></th> |
624615ee | 3371 | </tr> |
ac1cfefa | 3372 | END |
624615ee LS |
3373 | ; |
3374 | my $id = 0; | |
3375 | my $gif; | |
3376 | foreach my $key (sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) { | |
ac1cfefa MT |
3377 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } |
3378 | ||
3379 | if ($id % 2) { | |
e9850821 AM |
3380 | print "<tr>"; |
3381 | $col="bgcolor='$color{'color20'}'"; | |
ac1cfefa | 3382 | } else { |
e9850821 AM |
3383 | print "<tr>"; |
3384 | $col="bgcolor='$color{'color22'}'"; | |
ac1cfefa | 3385 | } |
e9850821 AM |
3386 | print "<td align='center' nowrap='nowrap' $col>$confighash{$key}[1]</td>"; |
3387 | print "<td align='center' nowrap='nowrap' $col>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ") $confighash{$key}[29]</td>"; | |
ed84e8b8 | 3388 | if ($confighash{$key}[2] eq '%auth-dn') { |
624615ee | 3389 | print "<td align='left' nowrap='nowrap' $col>$confighash{$key}[9]</td>"; |
ed84e8b8 | 3390 | } elsif ($confighash{$key}[4] eq 'cert') { |
624615ee | 3391 | print "<td align='left' nowrap='nowrap' $col>$confighash{$key}[2]</td>"; |
ac1cfefa | 3392 | } else { |
624615ee | 3393 | print "<td align='left' $col> </td>"; |
ac1cfefa | 3394 | } |
e9850821 | 3395 | print "<td align='center' $col>$confighash{$key}[25]</td>"; |
234fd050 MT |
3396 | my $col1="class='status is-disconnected'"; |
3397 | my $active = "$Lang::tr{'capsclosed'}"; | |
aec1925b | 3398 | if ($confighash{$key}[33] eq "add") { |
234fd050 MT |
3399 | $col1="class='status is-connecting'"; |
3400 | $active = "$Lang::tr{'vpn wait'}"; | |
aec1925b | 3401 | } |
5fd30232 | 3402 | foreach my $line (@status) { |
624615ee LS |
3403 | if (($line =~ /\"$confighash{$key}[1]\".*IPsec SA established/) || |
3404 | ($line =~ /$confighash{$key}[1]\{.*INSTALLED/)) { | |
3cfe40fa MT |
3405 | $col1="class='status is-connected'"; |
3406 | $active = "$Lang::tr{'capsopen'}"; | |
1f3f2d67 | 3407 | last; |
1fab4edf | 3408 | } elsif ($line =~ /$confighash{$key}[1]\[.*CONNECTING/) { |
3cfe40fa MT |
3409 | $col1="class='status is-connecting'"; |
3410 | $active = "$Lang::tr{'vpn connecting'}"; | |
8057ab15 | 3411 | } elsif ($line =~ /$confighash{$key}[1]\{.*ROUTED/) { |
3cfe40fa MT |
3412 | $col1="class='status is-connecting'"; |
3413 | $active = "$Lang::tr{'vpn on-demand'}"; | |
624615ee LS |
3414 | } |
3415 | } | |
3416 | # move to blue if really down | |
0afd8493 | 3417 | if ($confighash{$key}[0] eq 'off' && $col1 =~ /${Header::colourred}/ ) { |
3cfe40fa MT |
3418 | $col1="class='status is-disabled'"; |
3419 | $active = "$Lang::tr{'capsclosed'}"; | |
5fd30232 | 3420 | } |
ac1cfefa | 3421 | print <<END |
0afd8493 | 3422 | <td align='center' $col1>$active</td> |
e9850821 | 3423 | <td align='center' $col> |
624615ee LS |
3424 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
3425 | <input type='image' name='$Lang::tr{'restart'}' src='/images/reload.gif' alt='$Lang::tr{'restart'}' title='$Lang::tr{'restart'}' /> | |
3426 | <input type='hidden' name='ACTION' value='$Lang::tr{'restart'}' /> | |
3427 | <input type='hidden' name='KEY' value='$key' /> | |
3428 | </form> | |
ed84e8b8 | 3429 | </td> |
ac1cfefa | 3430 | END |
624615ee | 3431 | ; |
ed84e8b8 | 3432 | if (($confighash{$key}[4] eq 'cert') && ($confighash{$key}[2] ne '%auth-dn')) { |
624615ee LS |
3433 | print <<END |
3434 | <td align='center' $col> | |
3435 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
ed84e8b8 | 3436 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' /> |
ac1cfefa MT |
3437 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> |
3438 | <input type='hidden' name='KEY' value='$key' /> | |
624615ee LS |
3439 | </form> |
3440 | </td> | |
ac1cfefa | 3441 | END |
624615ee LS |
3442 | ; |
3443 | } else { | |
3444 | print "<td width='2%' $col> </td>"; | |
ac1cfefa | 3445 | } |
624615ee LS |
3446 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/certs/$confighash{$key}[1].p12") { |
3447 | print <<END | |
3448 | <td align='center' $col> | |
3449 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
ed84e8b8 | 3450 | <input type='image' name='$Lang::tr{'download pkcs12 file'}' src='/images/floppy.gif' alt='$Lang::tr{'download pkcs12 file'}' title='$Lang::tr{'download pkcs12 file'}' /> |
ac1cfefa MT |
3451 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> |
3452 | <input type='hidden' name='KEY' value='$key' /> | |
624615ee | 3453 | </form> |
ed84e8b8 | 3454 | </td> |
ac1cfefa | 3455 | END |
624615ee LS |
3456 | ; |
3457 | } elsif (($confighash{$key}[4] eq 'cert') && ($confighash{$key}[2] ne '%auth-dn')) { | |
3458 | print <<END | |
3459 | <td align='center' $col> | |
3460 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
ed84e8b8 | 3461 | <input type='image' name='$Lang::tr{'download certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download certificate'}' title='$Lang::tr{'download certificate'}' /> |
ac1cfefa MT |
3462 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> |
3463 | <input type='hidden' name='KEY' value='$key' /> | |
624615ee | 3464 | </form> |
ed84e8b8 | 3465 | </td> |
ac1cfefa | 3466 | END |
624615ee LS |
3467 | ; |
3468 | } else { | |
3469 | print "<td width='2%' $col> </td>"; | |
ac1cfefa | 3470 | } |
26a0befd MT |
3471 | |
3472 | # Apple Profile | |
3473 | if ($confighash{$key}[3] eq 'host') { | |
3474 | print <<END; | |
3475 | <td align='center' $col> | |
3476 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
3477 | <input type='image' name='$Lang::tr{'download apple profile'}' src='/images/apple.png' alt='$Lang::tr{'download apple profile'}' title='$Lang::tr{'download apple profile'}' /> | |
3478 | <input type='hidden' name='ACTION' value='$Lang::tr{'download apple profile'}' /> | |
3479 | <input type='hidden' name='KEY' value='$key' /> | |
3480 | </form> | |
3481 | </td> | |
3482 | END | |
3483 | } else { | |
3484 | print "<td width='2%' $col> </td>"; | |
3485 | } | |
3486 | ||
ac1cfefa | 3487 | print <<END |
e9850821 | 3488 | <td align='center' $col> |
624615ee LS |
3489 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
3490 | <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' /> | |
3491 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
3492 | <input type='hidden' name='KEY' value='$key' /> | |
3493 | </form> | |
ed84e8b8 | 3494 | </td> |
ac1cfefa | 3495 | |
e9850821 | 3496 | <td align='center' $col> |
624615ee LS |
3497 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
3498 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> | |
3499 | <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /> | |
3500 | <input type='hidden' name='KEY' value='$key' /> | |
3501 | </form> | |
ed84e8b8 | 3502 | </td> |
e9850821 | 3503 | <td align='center' $col> |
624615ee LS |
3504 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
3505 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> | |
3506 | <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' /> | |
3507 | <input type='hidden' name='KEY' value='$key' /> | |
3508 | </form> | |
ed84e8b8 | 3509 | </td> |
ac1cfefa MT |
3510 | </tr> |
3511 | END | |
624615ee | 3512 | ; |
ac1cfefa | 3513 | $id++; |
624615ee LS |
3514 | } |
3515 | print "</table>"; | |
3516 | ||
3517 | # If the config file contains entries, print Key to action icons | |
3518 | if ( $id ) { | |
3519 | print <<END | |
3520 | <table> | |
3521 | <tr> | |
3522 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
3523 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
3524 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
3525 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
3526 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
3527 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
3528 | <td class='base'>$Lang::tr{'edit'}</td> | |
3529 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
3530 | <td class='base'>$Lang::tr{'remove'}</td> | |
3531 | </tr> | |
3532 | <tr> | |
3533 | <td> </td> | |
3534 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
3535 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
3536 | <td> <img src='/images/floppy.gif' alt='?FLOPPY' /></td> | |
3537 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
3538 | <td> <img src='/images/reload.gif' alt='?RELOAD'/></td> | |
3539 | <td class='base'>$Lang::tr{'restart'}</td> | |
3540 | </tr> | |
3541 | </table> | |
ac1cfefa | 3542 | END |
624615ee LS |
3543 | ; |
3544 | } | |
ac1cfefa | 3545 | |
624615ee LS |
3546 | print <<END |
3547 | <table width='100%'> | |
3548 | <tr><td align='right' colspan='9'> | |
ed84e8b8 MT |
3549 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
3550 | <input type='submit' name='ACTION' value='$Lang::tr{'add'}' /> | |
3551 | </form> | |
624615ee LS |
3552 | </td></tr> |
3553 | </table> | |
ac1cfefa | 3554 | END |
624615ee LS |
3555 | ; |
3556 | &Header::closebox(); | |
ac1cfefa | 3557 | |
624615ee LS |
3558 | &Header::openbox('100%', 'left', "$Lang::tr{'certificate authorities'}"); |
3559 | print <<EOF | |
3560 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
3561 | <tr> | |
e9850821 AM |
3562 | <th width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> |
3563 | <th width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></th> | |
3564 | <th width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th> | |
624615ee | 3565 | </tr> |
ac1cfefa | 3566 | EOF |
624615ee LS |
3567 | ; |
3568 | my $col1="bgcolor='$color{'color22'}'"; | |
e9850821 | 3569 | my $col2="bgcolor='$color{'color20'}'"; |
624615ee LS |
3570 | if (-f "${General::swroot}/ca/cacert.pem") { |
3571 | my $casubject = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/ca/cacert.pem")); | |
3572 | print <<END | |
3573 | <tr> | |
3574 | <td class='base' $col1>$Lang::tr{'root certificate'}</td> | |
3575 | <td class='base' $col1>$casubject</td> | |
3576 | <td width='3%' align='center' $col1> | |
3577 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
3578 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> | |
3579 | <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show root certificate'}' title='$Lang::tr{'show root certificate'}' /> | |
3580 | </form> | |
3581 | </td> | |
3582 | <td width='3%' align='center' $col1> | |
3583 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
3584 | <input type='image' name='$Lang::tr{'download root certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download root certificate'}' title='$Lang::tr{'download root certificate'}' /> | |
3585 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> | |
3586 | </form> | |
3587 | </td> | |
3588 | <td width='4%' $col1> </td></tr> | |
ac1cfefa | 3589 | END |
624615ee LS |
3590 | ; |
3591 | } else { | |
3592 | # display rootcert generation buttons | |
3593 | print <<END | |
3594 | <tr> | |
3595 | <td class='base' $col1>$Lang::tr{'root certificate'}:</td> | |
3596 | <td class='base' $col1>$Lang::tr{'not present'}</td> | |
3597 | <td colspan='3' $col1> </td></tr> | |
ac1cfefa | 3598 | END |
624615ee LS |
3599 | ; |
3600 | } | |
ac1cfefa | 3601 | |
624615ee LS |
3602 | if (-f "${General::swroot}/certs/hostcert.pem") { |
3603 | my $hostsubject = &Header::cleanhtml(getsubjectfromcert ("${General::swroot}/certs/hostcert.pem")); | |
ac1cfefa | 3604 | |
624615ee LS |
3605 | print <<END |
3606 | <tr> | |
3607 | <td class='base' $col2>$Lang::tr{'host certificate'}</td> | |
3608 | <td class='base' $col2>$hostsubject</td> | |
3609 | <td width='3%' align='center' $col2> | |
3610 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
3611 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> | |
3612 | <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'}' /> | |
3613 | </form> | |
3614 | </td> | |
3615 | <td width='3%' align='center' $col2> | |
3616 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
3617 | <input type='image' name="$Lang::tr{'download host certificate'}" src='/images/floppy.gif' alt="$Lang::tr{'download host certificate'}" title="$Lang::tr{'download host certificate'}" /> | |
3618 | <input type='hidden' name='ACTION' value="$Lang::tr{'download host certificate'}" /> | |
3619 | </form> | |
3620 | </td> | |
9f010115 MT |
3621 | <td width='4%' align='center' $col2> |
3622 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
3623 | <input type='image' name='$Lang::tr{'regenerate host certificate'}' src='/images/reload.gif' alt='$Lang::tr{'regenerate host certificate'}' title='$Lang::tr{'regenerate host certificate'}' /> | |
3624 | <input type='hidden' name='ACTION' value='$Lang::tr{'regenerate host certificate'}' /> | |
3625 | </form> | |
3626 | </td></tr> | |
ac1cfefa | 3627 | END |
624615ee LS |
3628 | ; |
3629 | } else { | |
3630 | # Nothing | |
3631 | print <<END | |
3632 | <tr> | |
3633 | <td width='25%' class='base' $col2>$Lang::tr{'host certificate'}:</td> | |
3634 | <td class='base' $col2>$Lang::tr{'not present'}</td> | |
3635 | <td colspan='3' $col2> </td></tr> | |
ac1cfefa | 3636 | END |
624615ee LS |
3637 | ; |
3638 | } | |
3639 | ||
e9850821 AM |
3640 | my $rowcolor = 0; |
3641 | if (keys %cahash > 0) { | |
3642 | foreach my $key (keys %cahash) { | |
624615ee LS |
3643 | if ($rowcolor++ % 2) { |
3644 | print "<tr>"; | |
3645 | $col="bgcolor='$color{'color20'}'"; | |
3646 | } else { | |
3647 | print "<tr>"; | |
3648 | $col="bgcolor='$color{'color22'}'"; | |
3649 | } | |
3650 | print "<td class='base' $col>$cahash{$key}[0]</td>\n"; | |
3651 | print "<td class='base' $col>$cahash{$key}[1]</td>\n"; | |
3652 | print <<END | |
3653 | <td align='center' $col> | |
3654 | <form method='post' name='cafrm${key}a' action='$ENV{'SCRIPT_NAME'}'> | |
3655 | <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'}' /> | |
3656 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
3657 | <input type='hidden' name='KEY' value='$key' /> | |
3658 | </form> | |
3659 | </td> | |
3660 | <td align='center' $col> | |
3661 | <form method='post' name='cafrm${key}b' action='$ENV{'SCRIPT_NAME'}'> | |
3662 | <input type='image' name='$Lang::tr{'download ca certificate'}' src='/images/floppy.gif' alt='$Lang::tr{'download ca certificate'}' title='$Lang::tr{'download ca certificate'}' /> | |
3663 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> | |
3664 | <input type='hidden' name='KEY' value='$key' /> | |
3665 | </form> | |
3666 | </td> | |
3667 | <td align='center' $col> | |
3668 | <form method='post' name='cafrm${key}c' action='$ENV{'SCRIPT_NAME'}'> | |
3669 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
3670 | <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'}' /> | |
3671 | <input type='hidden' name='KEY' value='$key' /> | |
3672 | </form> | |
3673 | </td> | |
3674 | </tr> | |
3675 | END | |
3676 | ; | |
3677 | } | |
3678 | } | |
3679 | print "</table>"; | |
3680 | ||
3681 | # If the file contains entries, print Key to action icons | |
3682 | if ( -f "${General::swroot}/ca/cacert.pem") { | |
3683 | print <<END | |
3684 | <table><tr> | |
3685 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
3686 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
3687 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
3688 | <td> <img src='/images/floppy.gif' alt='$Lang::tr{'download certificate'}' /></td> | |
3689 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
3690 | </tr></table> | |
ac1cfefa | 3691 | END |
624615ee | 3692 | ; |
ac1cfefa | 3693 | } |
624615ee | 3694 | my $createCA = -f "${General::swroot}/ca/cacert.pem" ? '' : "<tr><td colspan='3'></td><td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td></tr>"; |
ed84e8b8 | 3695 | print <<END |
624615ee LS |
3696 | <br> |
3697 | <hr /> | |
3698 | <form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'> | |
3699 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
3700 | $createCA | |
3701 | <tr> | |
e3edceeb | 3702 | <td class='base' nowrap='nowrap'>$Lang::tr{'ca name'}: <img src='/blob.gif' alt='*' /></td> |
ed84e8b8 MT |
3703 | <td nowrap='nowrap'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' /> </td> |
3704 | <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td> | |
3705 | <td nowrap='nowrap'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}' /></td> | |
624615ee LS |
3706 | </tr> |
3707 | <tr> | |
ed84e8b8 | 3708 | <td colspan='3'>$Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}:</td> |
0afd8493 | 3709 | <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></td> |
624615ee LS |
3710 | </tr> |
3711 | </table> | |
3712 | </form> | |
ac1cfefa | 3713 | END |
624615ee LS |
3714 | ; |
3715 | &Header::closebox(); | |
3716 | &Header::closebigbox(); | |
3717 | &Header::closepage(); | |
e8b3bb0e MT |
3718 | |
3719 | sub array_unique($) { | |
3720 | my $array = shift; | |
3721 | my @unique = (); | |
3722 | ||
3723 | my %seen = (); | |
3724 | foreach my $e (@$array) { | |
3725 | next if $seen{$e}++; | |
3726 | push(@unique, $e); | |
3727 | } | |
3728 | ||
3729 | return @unique; | |
3730 | } | |
3731 | ||
3732 | sub make_algos($$$$$) { | |
3733 | my ($mode, $encs, $ints, $grps, $pfs) = @_; | |
3734 | my @algos = (); | |
3735 | ||
3736 | foreach my $enc (@$encs) { | |
3737 | foreach my $int (@$ints) { | |
3738 | foreach my $grp (@$grps) { | |
3739 | my @algo = ($enc); | |
3740 | ||
78039c15 | 3741 | if ($mode eq "ike") { |
e8b3bb0e | 3742 | push(@algo, $int); |
e8b3bb0e | 3743 | |
2c531c21 | 3744 | if ($grp =~ m/^e(.*)$/) { |
e8b3bb0e | 3745 | push(@algo, "ecp$1"); |
7f662098 | 3746 | } elsif ($grp =~ m/curve(448|25519)/) { |
e34e72b6 | 3747 | push(@algo, "$grp"); |
e8b3bb0e MT |
3748 | } else { |
3749 | push(@algo, "modp$grp"); | |
3750 | } | |
e8b3bb0e | 3751 | |
745915d8 | 3752 | } elsif ($mode eq "esp") { |
78039c15 MT |
3753 | my $is_aead = ($enc =~ m/[cg]cm/); |
3754 | ||
3755 | if (!$is_aead) { | |
3756 | push(@algo, $int); | |
3757 | } | |
4b02b404 | 3758 | |
0dd16f40 | 3759 | if (!$pfs || $grp eq "none") { |
4b02b404 MT |
3760 | # noop |
3761 | } elsif ($grp =~ m/^e(.*)$/) { | |
3762 | push(@algo, "ecp$1"); | |
7f662098 | 3763 | } elsif ($grp =~ m/curve(448|25519)/) { |
e34e72b6 | 3764 | push(@algo, "$grp"); |
4b02b404 MT |
3765 | } else { |
3766 | push(@algo, "modp$grp"); | |
3767 | } | |
e8b3bb0e MT |
3768 | } |
3769 | ||
3770 | push(@algos, join("-", @algo)); | |
3771 | } | |
3772 | } | |
3773 | } | |
3774 | ||
3775 | return &array_unique(\@algos); | |
3776 | } | |
8792caad | 3777 | |
f2d45a45 MT |
3778 | sub make_subnets($$) { |
3779 | my $direction = shift; | |
8792caad MT |
3780 | my $subnets = shift; |
3781 | ||
3782 | my @nets = split(/\|/, $subnets); | |
3783 | my @cidr_nets = (); | |
3784 | foreach my $net (@nets) { | |
3785 | my $cidr_net = &General::ipcidr($net); | |
f2d45a45 MT |
3786 | |
3787 | # Skip 0.0.0.0/0 for remote because this renders the | |
3788 | # while system inaccessible | |
3789 | next if (($direction eq "right") && ($cidr_net eq "0.0.0.0/0")); | |
3790 | ||
8792caad MT |
3791 | push(@cidr_nets, $cidr_net); |
3792 | } | |
3793 | ||
3794 | return join(",", @cidr_nets); | |
3795 | } | |
9f010115 MT |
3796 | |
3797 | sub regenerate_host_certificate() { | |
3798 | my $errormessage = ""; | |
3799 | ||
3800 | &General::log("ipsec", "Regenerating host certificate..."); | |
3801 | ||
3802 | # Create a CSR based on the existing certificate | |
3803 | my $opt = " x509 -x509toreq -copy_extensions copyall"; | |
3804 | $opt .= " -signkey ${General::swroot}/certs/hostkey.pem"; | |
3805 | $opt .= " -in ${General::swroot}/certs/hostcert.pem"; | |
3806 | $opt .= " -out ${General::swroot}/certs/hostreq.pem"; | |
3807 | $errormessage = &callssl($opt); | |
3808 | ||
3809 | # Revoke the old certificate | |
3810 | if (!$errormessage) { | |
3811 | &General::log("ipsec", "Revoking the old host cert..."); | |
3812 | ||
3813 | my $opt = " ca -revoke ${General::swroot}/certs/hostcert.pem"; | |
3814 | $errormessage = &callssl($opt); | |
3815 | } | |
3816 | ||
3817 | # Sign the host certificate request | |
3818 | if (!$errormessage) { | |
3819 | &General::log("ipsec", "Self signing host cert..."); | |
3820 | ||
3821 | my $opt = " ca -md sha256 -days 825"; | |
3822 | $opt .= " -batch -notext"; | |
3823 | $opt .= " -in ${General::swroot}/certs/hostreq.pem"; | |
3824 | $opt .= " -out ${General::swroot}/certs/hostcert.pem"; | |
3825 | $errormessage = &callssl ($opt); | |
3826 | ||
3827 | unlink ("${General::swroot}/certs/hostreq.pem"); #no more needed | |
3828 | } | |
3829 | ||
3830 | # Reload the new certificate | |
3831 | if (!$errormessage) { | |
3832 | &General::system('/usr/local/bin/ipsecctrl', 'R'); | |
3833 | } | |
3834 | ||
3835 | return $errormessage; | |
3836 | } |