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