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