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