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