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