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