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