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