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