]>
Commit | Line | Data |
---|---|---|
6e13d0a5 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
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 | ############################################################################### | |
6e13d0a5 MT |
21 | |
22 | use CGI; | |
23 | use CGI qw/:standard/; | |
24 | use Net::DNS; | |
ce9abb66 | 25 | use Net::Ping; |
6e13d0a5 MT |
26 | use File::Copy; |
27 | use File::Temp qw/ tempfile tempdir /; | |
28 | use strict; | |
29 | use Archive::Zip qw(:ERROR_CODES :CONSTANTS); | |
6e13d0a5 | 30 | require '/var/ipfire/general-functions.pl'; |
6e13d0a5 MT |
31 | require "${General::swroot}/lang.pl"; |
32 | require "${General::swroot}/header.pl"; | |
33 | require "${General::swroot}/countries.pl"; | |
34 | ||
35 | # enable only the following on debugging purpose | |
ce9abb66 AH |
36 | use warnings; |
37 | use CGI::Carp 'fatalsToBrowser'; | |
6e13d0a5 MT |
38 | #workaround to suppress a warning when a variable is used only once |
39 | my @dummy = ( ${Header::colourgreen} ); | |
40 | undef (@dummy); | |
41 | ||
f2fdd0c1 CS |
42 | my %color = (); |
43 | my %mainsettings = (); | |
44 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
45 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
6e13d0a5 MT |
46 | |
47 | ### | |
48 | ### Initialize variables | |
49 | ### | |
50 | my %netsettings=(); | |
51 | my %cgiparams=(); | |
52 | my %vpnsettings=(); | |
53 | my %checked=(); | |
54 | my %confighash=(); | |
55 | my %cahash=(); | |
56 | my %selected=(); | |
57 | my $warnmessage = ''; | |
58 | my $errormessage = ''; | |
59 | my %settings=(); | |
6e13d0a5 MT |
60 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
61 | $cgiparams{'ENABLED'} = 'off'; | |
62 | $cgiparams{'ENABLED_BLUE'} = 'off'; | |
63 | $cgiparams{'ENABLED_ORANGE'} = 'off'; | |
64 | $cgiparams{'EDIT_ADVANCED'} = 'off'; | |
65 | $cgiparams{'NAT'} = 'off'; | |
66 | $cgiparams{'COMPRESSION'} = 'off'; | |
67 | $cgiparams{'ONLY_PROPOSED'} = 'off'; | |
68 | $cgiparams{'ACTION'} = ''; | |
69 | $cgiparams{'CA_NAME'} = ''; | |
70 | $cgiparams{'DHCP_DOMAIN'} = ''; | |
71 | $cgiparams{'DHCP_DNS'} = ''; | |
72 | $cgiparams{'DHCP_WINS'} = ''; | |
73 | $cgiparams{'DCOMPLZO'} = 'off'; | |
a79fa1d6 JPT |
74 | $cgiparams{'MSSFIX'} = ''; |
75 | ||
ce9abb66 | 76 | |
6e13d0a5 MT |
77 | &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'}); |
78 | ||
79 | # prepare openvpn config file | |
80 | ### | |
81 | ### Useful functions | |
82 | ### | |
c6c9630e MT |
83 | sub haveOrangeNet |
84 | { | |
13211b21 CS |
85 | if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;} |
86 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} | |
c6c9630e MT |
87 | return 0; |
88 | } | |
89 | ||
90 | sub haveBlueNet | |
91 | { | |
13211b21 | 92 | if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;} |
c6c9630e | 93 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} |
c6c9630e MT |
94 | return 0; |
95 | } | |
96 | ||
97 | sub sizeformat{ | |
98 | my $bytesize = shift; | |
99 | my $i = 0; | |
100 | ||
101 | while(abs($bytesize) >= 1024){ | |
102 | $bytesize=$bytesize/1024; | |
103 | $i++; | |
104 | last if($i==6); | |
105 | } | |
106 | ||
107 | my @units = ("Bytes","KB","MB","GB","TB","PB","EB"); | |
108 | my $newsize=(int($bytesize*100 +0.5))/100; | |
109 | return("$newsize $units[$i]"); | |
110 | } | |
111 | ||
112 | sub valid_dns_host { | |
113 | my $hostname = $_[0]; | |
114 | unless ($hostname) { return "No hostname"}; | |
115 | my $res = new Net::DNS::Resolver; | |
116 | my $query = $res->search("$hostname"); | |
117 | if ($query) { | |
118 | foreach my $rr ($query->answer) { | |
119 | ## Potential bug - we are only looking at A records: | |
120 | return 0 if $rr->type eq "A"; | |
121 | } | |
122 | } else { | |
123 | return $res->errorstring; | |
124 | } | |
125 | } | |
126 | ||
127 | sub cleanssldatabase | |
128 | { | |
129 | if (open(FILE, ">${General::swroot}/ovpn/certs/serial")) { | |
130 | print FILE "01"; | |
131 | close FILE; | |
132 | } | |
133 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt")) { | |
134 | print FILE ""; | |
135 | close FILE; | |
136 | } | |
137 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
138 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
139 | unlink ("${General::swroot}/ovpn/certs/01.pem"); | |
140 | } | |
141 | ||
142 | sub newcleanssldatabase | |
143 | { | |
144 | if (! -s "${General::swroot}/ovpn/certs/serial" ) { | |
145 | open(FILE, ">${General::swroot}(ovpn/certs/serial"); | |
146 | print FILE "01"; | |
147 | close FILE; | |
148 | } | |
149 | if (! -s ">${General::swroot}/ovpn/certs/index.txt") { | |
150 | system ("touch ${General::swroot}/ovpn/certs/index.txt"); | |
151 | } | |
152 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
153 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
154 | } | |
155 | ||
156 | sub deletebackupcert | |
157 | { | |
158 | if (open(FILE, "${General::swroot}/ovpn/certs/serial.old")) { | |
159 | my $hexvalue = <FILE>; | |
160 | chomp $hexvalue; | |
161 | close FILE; | |
162 | unlink ("${General::swroot}/ovpn/certs/$hexvalue.pem"); | |
163 | } | |
164 | } | |
165 | ||
166 | sub checkportfw { | |
167 | my $KEY2 = $_[0]; # key2 | |
168 | my $SRC_PORT = $_[1]; # src_port | |
169 | my $PROTOCOL = $_[2]; # protocol | |
170 | my $SRC_IP = $_[3]; # sourceip | |
171 | ||
172 | my $pfwfilename = "${General::swroot}/portfw/config"; | |
173 | open(FILE, $pfwfilename) or die 'Unable to open config file.'; | |
174 | my @pfwcurrent = <FILE>; | |
175 | close(FILE); | |
176 | my $pfwkey1 = 0; # used for finding last sequence number used | |
177 | foreach my $pfwline (@pfwcurrent) | |
178 | { | |
179 | my @pfwtemp = split(/\,/,$pfwline); | |
180 | ||
181 | chomp ($pfwtemp[8]); | |
182 | if ($KEY2 eq "0"){ # if key2 is 0 then it is a portfw addition | |
183 | if ( $SRC_PORT eq $pfwtemp[3] && | |
184 | $PROTOCOL eq $pfwtemp[2] && | |
185 | $SRC_IP eq $pfwtemp[7]) | |
186 | { | |
187 | $errormessage = "$Lang::tr{'source port in use'} $SRC_PORT"; | |
188 | } | |
189 | # Check if key2 = 0, if it is then it is a port forward entry and we want the sequence number | |
190 | if ( $pfwtemp[1] eq "0") { | |
191 | $pfwkey1=$pfwtemp[0]; | |
192 | } | |
193 | # Darren Critchley - Duplicate or overlapping Port range check | |
194 | if ($pfwtemp[1] eq "0" && | |
195 | $PROTOCOL eq $pfwtemp[2] && | |
196 | $SRC_IP eq $pfwtemp[7] && | |
197 | $errormessage eq '') | |
198 | { | |
199 | &portchecks($SRC_PORT, $pfwtemp[5]); | |
200 | # &portchecks($pfwtemp[3], $pfwtemp[5]); | |
201 | # &portchecks($pfwtemp[3], $SRC_IP); | |
202 | } | |
203 | } | |
204 | } | |
205 | # $errormessage="$KEY2 $SRC_PORT $PROTOCOL $SRC_IP"; | |
206 | ||
207 | return; | |
208 | } | |
209 | ||
210 | sub checkportoverlap | |
211 | { | |
212 | my $portrange1 = $_[0]; # New port range | |
213 | my $portrange2 = $_[1]; # existing port range | |
214 | my @tempr1 = split(/\:/,$portrange1); | |
215 | my @tempr2 = split(/\:/,$portrange2); | |
216 | ||
217 | unless (&checkportinc($tempr1[0], $portrange2)){ return 0;} | |
218 | unless (&checkportinc($tempr1[1], $portrange2)){ return 0;} | |
219 | ||
220 | unless (&checkportinc($tempr2[0], $portrange1)){ return 0;} | |
221 | unless (&checkportinc($tempr2[1], $portrange1)){ return 0;} | |
222 | ||
223 | return 1; # Everything checks out! | |
224 | } | |
225 | ||
226 | # Darren Critchley - we want to make sure that a port entry is not within an already existing range | |
227 | sub checkportinc | |
228 | { | |
229 | my $port1 = $_[0]; # Port | |
230 | my $portrange2 = $_[1]; # Port range | |
231 | my @tempr1 = split(/\:/,$portrange2); | |
232 | ||
233 | if ($port1 < $tempr1[0] || $port1 > $tempr1[1]) { | |
234 | return 1; | |
235 | } else { | |
236 | return 0; | |
237 | } | |
238 | } | |
239 | # Darren Critchley - Duplicate or overlapping Port range check | |
240 | sub portchecks | |
241 | { | |
242 | my $p1 = $_[0]; # New port range | |
243 | my $p2 = $_[1]; # existing port range | |
244 | # $_ = $_[0]; | |
245 | our ($prtrange1, $prtrange2); | |
246 | $prtrange1 = 0; | |
247 | # if (m/:/ && $prtrange1 == 1) { # comparing two port ranges | |
248 | # unless (&checkportoverlap($p1,$p2)) { | |
249 | # $errormessage = "$Lang::tr{'source port overlaps'} $p1"; | |
250 | # } | |
251 | # } | |
252 | if (m/:/ && $prtrange1 == 0 && $errormessage eq '') { # compare one port to a range | |
253 | unless (&checkportinc($p2,$p1)) { | |
254 | $errormessage = "$Lang::tr{'srcprt within existing'} $p1"; | |
255 | } | |
256 | } | |
257 | $prtrange1 = 1; | |
258 | if (! m/:/ && $prtrange1 == 1 && $errormessage eq '') { # compare one port to a range | |
259 | unless (&checkportinc($p1,$p2)) { | |
260 | $errormessage = "$Lang::tr{'srcprt range overlaps'} $p2"; | |
261 | } | |
262 | } | |
263 | return; | |
264 | } | |
265 | ||
266 | # Darren Critchley - certain ports are reserved for IPFire | |
267 | # TCP 67,68,81,222,445 | |
268 | # UDP 67,68 | |
269 | # Params passed in -> port, rangeyn, protocol | |
270 | sub disallowreserved | |
271 | { | |
272 | # port 67 and 68 same for tcp and udp, don't bother putting in an array | |
273 | my $msg = ""; | |
274 | my @tcp_reserved = (81,222,445); | |
275 | my $prt = $_[0]; # the port or range | |
276 | my $ryn = $_[1]; # tells us whether or not it is a port range | |
277 | my $prot = $_[2]; # protocol | |
278 | my $srcdst = $_[3]; # source or destination | |
279 | if ($ryn) { # disect port range | |
280 | if ($srcdst eq "src") { | |
281 | $msg = "$Lang::tr{'rsvd src port overlap'}"; | |
282 | } else { | |
283 | $msg = "$Lang::tr{'rsvd dst port overlap'}"; | |
284 | } | |
285 | my @tmprng = split(/\:/,$prt); | |
286 | unless (67 < $tmprng[0] || 67 > $tmprng[1]) { $errormessage="$msg 67"; return; } | |
287 | unless (68 < $tmprng[0] || 68 > $tmprng[1]) { $errormessage="$msg 68"; return; } | |
288 | if ($prot eq "tcp") { | |
289 | foreach my $prange (@tcp_reserved) { | |
290 | unless ($prange < $tmprng[0] || $prange > $tmprng[1]) { $errormessage="$msg $prange"; return; } | |
291 | } | |
292 | } | |
293 | } else { | |
294 | if ($srcdst eq "src") { | |
295 | $msg = "$Lang::tr{'reserved src port'}"; | |
296 | } else { | |
297 | $msg = "$Lang::tr{'reserved dst port'}"; | |
298 | } | |
299 | if ($prt == 67) { $errormessage="$msg 67"; return; } | |
300 | if ($prt == 68) { $errormessage="$msg 68"; return; } | |
301 | if ($prot eq "tcp") { | |
302 | foreach my $prange (@tcp_reserved) { | |
303 | if ($prange == $prt) { $errormessage="$msg $prange"; return; } | |
304 | } | |
305 | } | |
306 | } | |
307 | return; | |
308 | } | |
309 | ||
310 | sub writeserverconf { | |
311 | my %sovpnsettings = (); | |
312 | &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings); | |
313 | ||
314 | open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!"; | |
315 | flock CONF, 2; | |
316 | print CONF "#OpenVPN Server conf\n"; | |
317 | print CONF "\n"; | |
318 | print CONF "daemon openvpnserver\n"; | |
319 | print CONF "writepid /var/run/openvpn.pid\n"; | |
afabe9f7 | 320 | print CONF "#DAN prepare OpenVPN for listening on blue and orange\n"; |
c6c9630e MT |
321 | print CONF ";local $sovpnsettings{'VPN_IP'}\n"; |
322 | print CONF "dev $sovpnsettings{'DDEVICE'}\n"; | |
323 | print CONF "$sovpnsettings{'DDEVICE'}-mtu $sovpnsettings{'DMTU'}\n"; | |
324 | print CONF "proto $sovpnsettings{'DPROTOCOL'}\n"; | |
325 | print CONF "port $sovpnsettings{'DDEST_PORT'}\n"; | |
2b29c22e | 326 | print CONF "script-security 3 system\n"; |
07675dc3 | 327 | print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n"; |
c6c9630e MT |
328 | print CONF "tls-server\n"; |
329 | print CONF "ca /var/ipfire/ovpn/ca/cacert.pem\n"; | |
330 | print CONF "cert /var/ipfire/ovpn/certs/servercert.pem\n"; | |
331 | print CONF "key /var/ipfire/ovpn/certs/serverkey.pem\n"; | |
332 | print CONF "dh /var/ipfire/ovpn/ca/dh1024.pem\n"; | |
333 | my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'}); | |
334 | print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n"; | |
335 | print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n"; | |
336 | if ($sovpnsettings{CLIENT2CLIENT} eq 'on') { | |
337 | print CONF "client-to-client\n"; | |
338 | } | |
a79fa1d6 JPT |
339 | if ($sovpnsettings{MSSFIX} eq 'on') { |
340 | print CONF "mssfix\n"; | |
341 | } | |
74225cce | 342 | if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') { |
a79fa1d6 JPT |
343 | print CONF "fragment $sovpnsettings{'FRAGMENT'}\n"; |
344 | } | |
c6c9630e MT |
345 | if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) { |
346 | print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n"; | |
347 | } | |
348 | print CONF "status-version 1\n"; | |
4e17adad | 349 | print CONF "status /var/log/ovpnserver.log 30\n"; |
c6c9630e MT |
350 | print CONF "cipher $sovpnsettings{DCIPHER}\n"; |
351 | if ($sovpnsettings{DCOMPLZO} eq 'on') { | |
352 | print CONF "comp-lzo\n"; | |
353 | } | |
354 | if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') { | |
355 | print CONF "push \"redirect-gateway def1\"\n"; | |
356 | } | |
357 | if ($sovpnsettings{DHCP_DOMAIN} ne '') { | |
358 | print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n"; | |
359 | } | |
360 | ||
361 | if ($sovpnsettings{DHCP_DNS} ne '') { | |
362 | print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n"; | |
363 | } | |
364 | ||
365 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
366 | print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n"; | |
367 | } | |
368 | ||
369 | if ($sovpnsettings{DHCP_WINS} eq '') { | |
370 | print CONF "max-clients 100\n"; | |
a79fa1d6 | 371 | } |
c6c9630e MT |
372 | if ($sovpnsettings{DHCP_WINS} ne '') { |
373 | print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n"; | |
374 | } | |
375 | print CONF "tls-verify /var/ipfire/ovpn/verify\n"; | |
376 | print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n"; | |
377 | print CONF "user nobody\n"; | |
378 | print CONF "group nobody\n"; | |
379 | print CONF "persist-key\n"; | |
380 | print CONF "persist-tun\n"; | |
381 | if ($sovpnsettings{LOG_VERB} ne '') { | |
382 | print CONF "verb $sovpnsettings{LOG_VERB}\n"; | |
383 | } else { | |
384 | print CONF "verb 3\n"; | |
385 | } | |
386 | print CONF "\n"; | |
387 | ||
388 | close(CONF); | |
389 | } | |
390 | # | |
391 | sub emptyserverlog{ | |
4e17adad | 392 | if (open(FILE, ">/var/log/ovpnserver.log")) { |
c6c9630e MT |
393 | flock FILE, 2; |
394 | print FILE ""; | |
395 | close FILE; | |
396 | } | |
397 | ||
398 | } | |
399 | ||
7c1d9faf AH |
400 | ### |
401 | # m.a.d net2net | |
402 | ### | |
403 | ||
404 | sub validdotmask | |
405 | { | |
406 | my $ipdotmask = $_[0]; | |
407 | if (&General::validip($ipdotmask)) { return 0; } | |
408 | if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { } | |
409 | my $mask = $2; | |
410 | if (($mask =~ /\./ )) { return 0; } | |
411 | return 1; | |
412 | } | |
413 | ||
414 | ||
415 | ||
c6c9630e MT |
416 | #hier die refresh page |
417 | if ( -e "${General::swroot}/ovpn/gencanow") { | |
418 | my $refresh = ''; | |
419 | $refresh = "<meta http-equiv='refresh' content='15;' />"; | |
420 | &Header::showhttpheaders(); | |
421 | &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh); | |
422 | &Header::openbigbox('100%', 'center'); | |
423 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
424 | print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n"; | |
425 | print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n"; | |
426 | &Header::closebox(); | |
427 | &Header::closebigbox(); | |
428 | &Header::closepage(); | |
429 | exit (0); | |
430 | } | |
431 | ##hier die refresh page | |
432 | ||
6e13d0a5 MT |
433 | |
434 | ### | |
435 | ### OpenVPN Server Control | |
436 | ### | |
437 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} || | |
438 | $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} || | |
439 | $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) { | |
6e13d0a5 MT |
440 | #start openvpn server |
441 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){ | |
c6c9630e | 442 | &emptyserverlog(); |
6e13d0a5 MT |
443 | system('/usr/local/bin/openvpnctrl', '-s'); |
444 | } | |
445 | #stop openvpn server | |
446 | if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){ | |
6e13d0a5 | 447 | system('/usr/local/bin/openvpnctrl', '-k'); |
c6c9630e | 448 | &emptyserverlog(); |
6e13d0a5 MT |
449 | } |
450 | # #restart openvpn server | |
451 | if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){ | |
452 | #workarund, till SIGHUP also works when running as nobody | |
c6c9630e MT |
453 | system('/usr/local/bin/openvpnctrl', '-r'); |
454 | &emptyserverlog(); | |
6e13d0a5 MT |
455 | } |
456 | } | |
457 | ||
458 | ### | |
459 | ### Save Advanced options | |
460 | ### | |
461 | ||
462 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) { | |
463 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
464 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, | |
465 | #DAN this value has to leave. | |
466 | #new settings for daemon | |
467 | $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'}; | |
468 | $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'}; | |
469 | $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'}; | |
470 | $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'}; | |
471 | $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'}; | |
472 | $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'}; | |
473 | $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'}; | |
474 | $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'}; | |
475 | $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'}; | |
6e13d0a5 | 476 | |
a79fa1d6 JPT |
477 | if ($cgiparams{'FRAGMENT'} eq '') { |
478 | delete $vpnsettings{'FRAGMENT'}; | |
479 | } else { | |
480 | if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) { | |
481 | $errormessage = "Incorrect value, please insert only numbers."; | |
482 | goto ADV_ERROR; | |
483 | } else { | |
484 | $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'}; | |
485 | } | |
486 | } | |
487 | if ($cgiparams{'MSSFIX'} ne 'on') { | |
488 | delete $vpnsettings{'MSSFIX'}; | |
489 | } else { | |
490 | $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'}; | |
491 | } | |
6e13d0a5 MT |
492 | if ($cgiparams{'DHCP_DOMAIN'} ne ''){ |
493 | unless (&General::validfqdn($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) { | |
494 | $errormessage = $Lang::tr{'invalid input for dhcp domain'}; | |
495 | goto ADV_ERROR; | |
496 | } | |
497 | } | |
498 | if ($cgiparams{'DHCP_DNS'} ne ''){ | |
499 | unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) { | |
500 | $errormessage = $Lang::tr{'invalid input for dhcp dns'}; | |
501 | goto ADV_ERROR; | |
502 | } | |
503 | } | |
504 | if ($cgiparams{'DHCP_WINS'} ne ''){ | |
505 | unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) { | |
506 | $errormessage = $Lang::tr{'invalid input for dhcp wins'}; | |
507 | goto ADV_ERROR; | |
508 | } | |
509 | } | |
6e13d0a5 MT |
510 | if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 255 )) { |
511 | $errormessage = $Lang::tr{'invalid input for max clients'}; | |
512 | goto ADV_ERROR; | |
513 | } | |
514 | if ($cgiparams{'KEEPALIVE_1'} ne '') { | |
515 | if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) { | |
516 | $errormessage = $Lang::tr{'invalid input for keepalive 1'}; | |
517 | goto ADV_ERROR; | |
518 | } | |
519 | } | |
520 | if ($cgiparams{'KEEPALIVE_2'} ne ''){ | |
521 | if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) { | |
522 | $errormessage = $Lang::tr{'invalid input for keepalive 2'}; | |
523 | goto ADV_ERROR; | |
524 | } | |
525 | } | |
526 | if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){ | |
527 | $errormessage = $Lang::tr{'invalid input for keepalive 1:2'}; | |
528 | goto ADV_ERROR; | |
529 | } | |
530 | ||
531 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 532 | &writeserverconf();#hier ok |
6e13d0a5 MT |
533 | } |
534 | ||
ce9abb66 | 535 | ### |
7c1d9faf | 536 | # m.a.d net2net |
ce9abb66 AH |
537 | ### |
538 | ||
539 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server') | |
540 | { | |
c6c9630e | 541 | |
ce9abb66 AH |
542 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
543 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
544 | my $ovsubnet = "@ovsubnettemp[0].@ovsubnettemp[1].@ovsubnettemp[2]"; | |
d96c89eb | 545 | my $tunmtu = ''; |
531f0835 AH |
546 | |
547 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
548 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
549 | |
550 | open(SERVERCONF, ">${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Unable to open ${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf: $!"; | |
551 | ||
552 | flock SERVERCONF, 2; | |
7c1d9faf | 553 | print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n"; |
ce9abb66 | 554 | print SERVERCONF "\n"; |
b278daf3 | 555 | print SERVERCONF "# User Security\n"; |
ce9abb66 AH |
556 | print SERVERCONF "user nobody\n"; |
557 | print SERVERCONF "group nobody\n"; | |
558 | print SERVERCONF "persist-tun\n"; | |
559 | print SERVERCONF "persist-key\n"; | |
7c1d9faf | 560 | print SERVERCONF "script-security 2\n"; |
b278daf3 | 561 | print SERVERCONF "# IP/DNS for the Server Gateway - g2g Mode\n"; |
ce9abb66 | 562 | print SERVERCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 AH |
563 | print SERVERCONF "float\n"; |
564 | print SERVERCONF "# IP address of the n2n VPN Subnet\n"; | |
ce9abb66 | 565 | print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n"; |
b278daf3 | 566 | print SERVERCONF "# Client gateway network\n"; |
ce9abb66 | 567 | print SERVERCONF "route @remsubnet[0] @remsubnet[1]\n"; |
b278daf3 | 568 | print SERVERCONF "# tun device\n"; |
ce9abb66 | 569 | print SERVERCONF "dev tun\n"; |
b278daf3 | 570 | print SERVERCONF "#Port and protocol\n"; |
ce9abb66 AH |
571 | print SERVERCONF "port $cgiparams{'DEST_PORT'}\n"; |
572 | print SERVERCONF "proto $cgiparams{'PROTOCOL'}\n"; | |
b278daf3 | 573 | print SERVERCONF "# Paketsize\n"; |
d96c89eb | 574 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
ce9abb66 | 575 | print SERVERCONF "tun-mtu $tunmtu\n"; |
d96c89eb AH |
576 | if ($cgiparams{'PROTOCOL'} eq 'udp') { |
577 | if ($cgiparams{'FRAGMENT'} eq '') { | |
578 | print SERVERCONF "fragment 1300\r\n"; | |
579 | } else { | |
580 | print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n" | |
581 | } | |
582 | if ($cgiparams{'MSSFIX'} eq 'on') { | |
ce9abb66 | 583 | print SERVERCONF "mssfix\n"; |
d96c89eb AH |
584 | } |
585 | } | |
ce9abb66 AH |
586 | print SERVERCONF "# Auth Server\n"; |
587 | print SERVERCONF "tls-server\n"; | |
588 | print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; | |
589 | print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
590 | print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
591 | print SERVERCONF "dh ${General::swroot}/ovpn/ca/dh1024.pem\n"; | |
b278daf3 | 592 | print SERVERCONF "# Cipher\n"; |
ce9abb66 AH |
593 | print SERVERCONF "cipher AES-256-CBC\n"; |
594 | if ($cgiparams{'COMPLZO'} eq 'on') { | |
b278daf3 | 595 | print SERVERCONF "# Enable compession\n"; |
ce9abb66 | 596 | print SERVERCONF "comp-lzo\r\n"; |
b278daf3 AH |
597 | } |
598 | print SERVERCONF "# Debug level\n"; | |
ce9abb66 | 599 | print SERVERCONF "verb 3\n"; |
b278daf3 | 600 | print SERVERCONF "# Tunnel check\n"; |
ce9abb66 | 601 | print SERVERCONF "keepalive 10 60\n"; |
b278daf3 | 602 | print SERVERCONF "# start as daemon\n"; |
ce9abb66 AH |
603 | print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n"; |
604 | print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
b278daf3 | 605 | print SERVERCONF "# Activate Management Interface on Port\n"; |
ce9abb66 AH |
606 | print SERVERCONF "#management localhost 4711\n"; |
607 | close(SERVERCONF); | |
608 | ||
609 | } | |
610 | ||
611 | ### | |
7c1d9faf | 612 | # m.a.d net2net |
ce9abb66 | 613 | ### |
7c1d9faf | 614 | |
ce9abb66 AH |
615 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client') |
616 | { | |
617 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
618 | my $ovsubnet = "@ovsubnettemp[0].@ovsubnettemp[1].@ovsubnettemp[2]"; | |
619 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); | |
d96c89eb AH |
620 | my $tunmtu = ''; |
621 | ||
531f0835 AH |
622 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
623 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
624 | |
625 | open(CLIENTCONF, ">${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Unable to open ${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf: $!"; | |
626 | ||
627 | flock CLIENTCONF, 2; | |
7c1d9faf | 628 | print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 629 | print CLIENTCONF "#\n"; |
b278daf3 | 630 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
631 | print CLIENTCONF "user nobody\n"; |
632 | print CLIENTCONF "group nobody\n"; | |
633 | print CLIENTCONF "persist-tun\n"; | |
634 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 635 | print CLIENTCONF "script-security 2\n"; |
b278daf3 | 636 | print CLIENTCONF "# IP/DNS for the Server Gateway - g2g Mode\n"; |
ce9abb66 | 637 | print CLIENTCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 AH |
638 | print CLIENTCONF "float\n"; |
639 | print CLIENTCONF "# IP address of the n2n VPN Subnet\n"; | |
ce9abb66 | 640 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
b278daf3 | 641 | print CLIENTCONF "# Server gateway network\n"; |
7c1d9faf | 642 | print CLIENTCONF "route @remsubnet[0] @remsubnet[1]\n"; |
b278daf3 | 643 | print CLIENTCONF "# tun device\n"; |
ce9abb66 | 644 | print CLIENTCONF "dev tun\n"; |
b278daf3 | 645 | print CLIENTCONF "#Port and protocol\n"; |
ce9abb66 AH |
646 | print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n"; |
647 | print CLIENTCONF "proto $cgiparams{'PROTOCOL'}\n"; | |
b278daf3 | 648 | print CLIENTCONF "# Paketsize\n"; |
d96c89eb | 649 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
ce9abb66 | 650 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb AH |
651 | if ($cgiparams{'PROTOCOL'} eq 'udp') { |
652 | if ($cgiparams{'FRAGMENT'} eq '') { | |
653 | print CLIENTCONF "fragment 1300\r\n"; | |
654 | } else { | |
655 | print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n" | |
656 | } | |
657 | if ($cgiparams{'MSSFIX'} eq 'on') { | |
ce9abb66 | 658 | print CLIENTCONF "mssfix\n"; |
d96c89eb AH |
659 | } |
660 | } | |
ce9abb66 AH |
661 | print CLIENTCONF "# Auth. Client\n"; |
662 | print CLIENTCONF "tls-client\n"; | |
b278daf3 | 663 | print CLIENTCONF "# Cipher\n"; |
ce9abb66 AH |
664 | print CLIENTCONF "cipher AES-256-CBC\n"; |
665 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n"; | |
ce9abb66 | 666 | if ($cgiparams{'COMPLZO'} eq 'on') { |
b278daf3 | 667 | print CLIENTCONF "# Enable compession\n"; |
ce9abb66 | 668 | print CLIENTCONF "comp-lzo\r\n"; |
b278daf3 | 669 | } |
ce9abb66 AH |
670 | print CLIENTCONF "# Debug Level\n"; |
671 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 672 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 673 | print CLIENTCONF "keepalive 10 60\n"; |
b278daf3 | 674 | print CLIENTCONF "# Start sa daemon\n"; |
ce9abb66 AH |
675 | print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n"; |
676 | print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
b278daf3 | 677 | print CLIENTCONF "# Activate Management Interface on Port\n"; |
ce9abb66 AH |
678 | print CLIENTCONF "# management localhost 4711\n"; |
679 | close(CLIENTCONF); | |
c6c9630e | 680 | |
ce9abb66 AH |
681 | } |
682 | ||
6e13d0a5 MT |
683 | ### |
684 | ### Save main settings | |
685 | ### | |
ce9abb66 AH |
686 | |
687 | ||
6e13d0a5 MT |
688 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { |
689 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 MT |
690 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, |
691 | #DAN this value has to leave. | |
692 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
693 | unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) { | |
694 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
c6c9630e | 695 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
696 | } |
697 | } | |
698 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
c6c9630e | 699 | &disallowreserved($cgiparams{'DDEST_PORT'},0,$cgiparams{'DPROTOCOL'},"dest"); |
6e13d0a5 MT |
700 | } |
701 | if ($errormessage) { goto SETTINGS_ERROR; } | |
702 | ||
703 | ||
704 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
c6c9630e | 705 | &checkportfw(0,$cgiparams{'DDEST_PORT'},$cgiparams{'DPROTOCOL'},'0.0.0.0'); |
6e13d0a5 MT |
706 | } |
707 | ||
708 | if ($errormessage) { goto SETTINGS_ERROR; } | |
709 | ||
710 | if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) { | |
c6c9630e MT |
711 | $errormessage = $Lang::tr{'ovpn subnet is invalid'}; |
712 | goto SETTINGS_ERROR; | |
713 | } | |
714 | my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'}); | |
715 | ||
716 | if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'}, | |
717 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
718 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}"; | |
719 | goto SETTINGS_ERROR; | |
720 | } | |
721 | ||
722 | if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'}, | |
723 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
724 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}"; | |
725 | goto SETTINGS_ERROR; | |
726 | } | |
727 | ||
728 | if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'}, | |
729 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
730 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}"; | |
731 | goto SETTINGS_ERROR; | |
732 | } | |
733 | ||
734 | if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'}, | |
735 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
736 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}"; | |
737 | goto SETTINGS_ERROR; | |
738 | } | |
739 | open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.'; | |
740 | while (<ALIASES>) | |
741 | { | |
742 | chomp($_); | |
743 | my @tempalias = split(/\,/,$_); | |
744 | if ($tempalias[1] eq 'on') { | |
745 | if (&General::IpInSubnet ($tempalias[0] , | |
746 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
747 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]"; | |
748 | } | |
749 | } | |
750 | } | |
751 | close(ALIASES); | |
6e13d0a5 | 752 | if ($errormessage ne ''){ |
c6c9630e | 753 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
754 | } |
755 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
756 | $errormessage = $Lang::tr{'invalid input'}; | |
757 | goto SETTINGS_ERROR; | |
758 | } | |
759 | if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) { | |
760 | $errormessage = $Lang::tr{'invalid mtu input'}; | |
761 | goto SETTINGS_ERROR; | |
762 | } | |
763 | ||
764 | unless (&General::validport($cgiparams{'DDEST_PORT'})) { | |
c6c9630e MT |
765 | $errormessage = $Lang::tr{'invalid port'}; |
766 | goto SETTINGS_ERROR; | |
6e13d0a5 | 767 | } |
6e13d0a5 MT |
768 | $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'}; |
769 | $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'}; | |
770 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
771 | $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'}; | |
772 | #new settings for daemon | |
773 | $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'}; | |
774 | $vpnsettings{'DDEVICE'} = $cgiparams{'DDEVICE'}; | |
775 | $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'}; | |
776 | $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'}; | |
777 | $vpnsettings{'DMTU'} = $cgiparams{'DMTU'}; | |
778 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; | |
779 | $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'}; | |
3ffee04b CS |
780 | #wrtie enable |
781 | ||
782 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable_blue 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable_blue 2>/dev/null");} | |
783 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable_orange 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable_orange 2>/dev/null");} | |
784 | if ( $vpnsettings{'ENABLED'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable 2>/dev/null");} | |
6e13d0a5 MT |
785 | #new settings for daemon |
786 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 787 | &writeserverconf();#hier ok |
6e13d0a5 MT |
788 | SETTINGS_ERROR: |
789 | ### | |
790 | ### Reset all step 2 | |
791 | ### | |
792 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
793 | my $file = ''; | |
794 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
795 | ||
796 | foreach my $key (keys %confighash) { | |
c6c9630e MT |
797 | if ($confighash{$key}[4] eq 'cert') { |
798 | delete $confighash{$cgiparams{'$key'}}; | |
799 | } | |
6e13d0a5 MT |
800 | } |
801 | while ($file = glob("${General::swroot}/ovpn/ca/*")) { | |
c6c9630e | 802 | unlink $file |
6e13d0a5 MT |
803 | } |
804 | while ($file = glob("${General::swroot}/ovpn/certs/*")) { | |
c6c9630e | 805 | unlink $file |
6e13d0a5 MT |
806 | } |
807 | while ($file = glob("${General::swroot}/ovpn/crls/*")) { | |
c6c9630e | 808 | unlink $file |
6e13d0a5 | 809 | } |
c6c9630e | 810 | &cleanssldatabase(); |
6e13d0a5 MT |
811 | if (open(FILE, ">${General::swroot}/ovpn/caconfig")) { |
812 | print FILE ""; | |
813 | close FILE; | |
814 | } | |
815 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 816 | #&writeserverconf(); |
6e13d0a5 MT |
817 | ### |
818 | ### Reset all step 1 | |
819 | ### | |
820 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'}) { | |
821 | &Header::showhttpheaders(); | |
822 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
823 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
824 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
825 | print <<END | |
826 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
827 | <tr><td align='center'> | |
828 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: | |
829 | $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'} | |
830 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /> | |
831 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
832 | </form></table> | |
833 | END | |
834 | ; | |
835 | &Header::closebox(); | |
836 | &Header::closebigbox(); | |
837 | &Header::closepage(); | |
838 | exit (0); | |
839 | ||
840 | ### | |
841 | ### Upload CA Certificate | |
842 | ### | |
843 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
844 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
845 | ||
846 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
847 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
848 | goto UPLOADCA_ERROR; | |
849 | } | |
850 | ||
851 | if (length($cgiparams{'CA_NAME'}) >60) { | |
852 | $errormessage = $Lang::tr{'name too long'}; | |
853 | goto VPNCONF_ERROR; | |
854 | } | |
855 | ||
856 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
857 | $errormessage = $Lang::tr{'name is invalid'}; | |
858 | goto UPLOAD_CA_ERROR; | |
859 | } | |
860 | ||
861 | # Check if there is no other entry with this name | |
862 | foreach my $key (keys %cahash) { | |
c6c9630e MT |
863 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { |
864 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
865 | goto UPLOADCA_ERROR; | |
866 | } | |
6e13d0a5 MT |
867 | } |
868 | ||
869 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
c6c9630e MT |
870 | $errormessage = $Lang::tr{'there was no file upload'}; |
871 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
872 | } |
873 | # Move uploaded ca to a temporary file | |
874 | (my $fh, my $filename) = tempfile( ); | |
875 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
c6c9630e MT |
876 | $errormessage = $!; |
877 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
878 | } |
879 | my $temp = `/usr/bin/openssl x509 -text -in $filename`; | |
c6c9630e MT |
880 | if ($temp !~ /CA:TRUE/i) { |
881 | $errormessage = $Lang::tr{'not a valid ca certificate'}; | |
882 | unlink ($filename); | |
883 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 884 | } else { |
c6c9630e MT |
885 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); |
886 | if ($? ne 0) { | |
887 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
888 | unlink ($filename); | |
889 | goto UPLOADCA_ERROR; | |
890 | } | |
6e13d0a5 MT |
891 | } |
892 | ||
893 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`; | |
894 | $casubject =~ /Subject: (.*)[\n]/; | |
895 | $casubject = $1; | |
896 | $casubject =~ s+/Email+, E+; | |
897 | $casubject =~ s/ ST=/ S=/; | |
898 | $casubject = &Header::cleanhtml($casubject); | |
899 | ||
900 | my $key = &General::findhasharraykey (\%cahash); | |
901 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
902 | $cahash{$key}[1] = $casubject; | |
903 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e MT |
904 | # system('/usr/local/bin/ipsecctrl', 'R'); |
905 | ||
6e13d0a5 MT |
906 | UPLOADCA_ERROR: |
907 | ||
908 | ### | |
909 | ### Display ca certificate | |
910 | ### | |
911 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
c6c9630e MT |
912 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); |
913 | ||
914 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
915 | &Header::showhttpheaders(); | |
916 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
917 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
918 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:"); | |
919 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
920 | $output = &Header::cleanhtml($output,"y"); | |
921 | print "<pre>$output</pre>\n"; | |
922 | &Header::closebox(); | |
923 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
924 | &Header::closebigbox(); | |
925 | &Header::closepage(); | |
926 | exit(0); | |
927 | } else { | |
928 | $errormessage = $Lang::tr{'invalid key'}; | |
929 | } | |
930 | ||
6e13d0a5 MT |
931 | ### |
932 | ### Download ca certificate | |
933 | ### | |
934 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
935 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
936 | ||
937 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
938 | print "Content-Type: application/octet-stream\r\n"; | |
939 | print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
940 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
941 | exit(0); | |
942 | } else { | |
943 | $errormessage = $Lang::tr{'invalid key'}; | |
944 | } | |
945 | ||
946 | ### | |
947 | ### Remove ca certificate (step 2) | |
948 | ### | |
949 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
950 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
951 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
952 | ||
953 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
954 | foreach my $key (keys %confighash) { | |
955 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
956 | if ($test =~ /: OK/) { | |
c6c9630e MT |
957 | # Delete connection |
958 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
959 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
960 | # system('/usr/local/bin/ipsecctrl', 'D', $key); | |
961 | # } | |
6e13d0a5 MT |
962 | unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem"); |
963 | unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12"); | |
964 | delete $confighash{$key}; | |
965 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 966 | # &writeipsecfiles(); |
6e13d0a5 MT |
967 | } |
968 | } | |
969 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
970 | delete $cahash{$cgiparams{'KEY'}}; | |
971 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e | 972 | # system('/usr/local/bin/ipsecctrl', 'R'); |
6e13d0a5 MT |
973 | } else { |
974 | $errormessage = $Lang::tr{'invalid key'}; | |
975 | } | |
976 | ### | |
977 | ### Remove ca certificate (step 1) | |
978 | ### | |
979 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
980 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
981 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
982 | ||
983 | my $assignedcerts = 0; | |
984 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
985 | foreach my $key (keys %confighash) { | |
986 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
987 | if ($test =~ /: OK/) { | |
988 | $assignedcerts++; | |
989 | } | |
990 | } | |
991 | if ($assignedcerts) { | |
992 | &Header::showhttpheaders(); | |
993 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
994 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
995 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
996 | print <<END | |
997 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
998 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
999 | <tr><td align='center'> | |
1000 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts | |
1001 | $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'} | |
1002 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
1003 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1004 | </form></table> | |
1005 | END | |
1006 | ; | |
1007 | &Header::closebox(); | |
1008 | &Header::closebigbox(); | |
1009 | &Header::closepage(); | |
1010 | exit (0); | |
1011 | } else { | |
1012 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1013 | delete $cahash{$cgiparams{'KEY'}}; | |
1014 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1015 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1016 | } | |
1017 | } else { | |
1018 | $errormessage = $Lang::tr{'invalid key'}; | |
1019 | } | |
1020 | ||
1021 | ### | |
1022 | ### Display root certificate | |
1023 | ### | |
c6c9630e MT |
1024 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || |
1025 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
1026 | my $output; | |
1027 | &Header::showhttpheaders(); | |
1028 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1029 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1030 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
1031 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:"); | |
1032 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1033 | } else { | |
1034 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:"); | |
1035 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1036 | } | |
1037 | $output = &Header::cleanhtml($output,"y"); | |
1038 | print "<pre>$output</pre>\n"; | |
1039 | &Header::closebox(); | |
1040 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1041 | &Header::closebigbox(); | |
1042 | &Header::closepage(); | |
1043 | exit(0); | |
1044 | ||
6e13d0a5 MT |
1045 | ### |
1046 | ### Download root certificate | |
1047 | ### | |
1048 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
1049 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
1050 | print "Content-Type: application/octet-stream\r\n"; | |
1051 | print "Content-Disposition: filename=cacert.pem\r\n\r\n"; | |
1052 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1053 | exit(0); | |
1054 | } | |
1055 | ||
1056 | ### | |
1057 | ### Download host certificate | |
1058 | ### | |
1059 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
1060 | if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) { | |
1061 | print "Content-Type: application/octet-stream\r\n"; | |
1062 | print "Content-Disposition: filename=servercert.pem\r\n\r\n"; | |
1063 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1064 | exit(0); | |
1065 | } | |
1066 | ### | |
1067 | ### Form for generating a root certificate | |
1068 | ### | |
1069 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
1070 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1071 | ||
1072 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1073 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
1074 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
1075 | $cgiparams{'ACTION'} = ''; | |
1076 | goto ROOTCERT_ERROR; | |
1077 | } | |
1078 | ||
1079 | if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") { | |
1080 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
1081 | my $ipaddr = <IPADDR>; | |
1082 | close IPADDR; | |
1083 | chomp ($ipaddr); | |
1084 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
1085 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
1086 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
1087 | } | |
1088 | } | |
1089 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1090 | ||
1091 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
1092 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1093 | goto ROOTCERT_ERROR; | |
1094 | } | |
1095 | ||
1096 | # Move uploaded certificate request to a temporary file | |
1097 | (my $fh, my $filename) = tempfile( ); | |
1098 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1099 | $errormessage = $!; | |
1100 | goto ROOTCERT_ERROR; | |
1101 | } | |
1102 | ||
1103 | # Create a temporary dirctory | |
1104 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1105 | ||
1106 | # Extract the CA certificate from the file | |
1107 | my $pid = open(OPENSSL, "|-"); | |
1108 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1109 | if ($pid) { # parent | |
1110 | if ($cgiparams{'P12_PASS'} ne '') { | |
1111 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1112 | } | |
1113 | close (OPENSSL); | |
1114 | if ($?) { | |
1115 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1116 | unlink ($filename); | |
1117 | goto ROOTCERT_ERROR; | |
1118 | } | |
1119 | } else { # child | |
1120 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys', | |
1121 | '-in', $filename, | |
1122 | '-out', "$tempdir/cacert.pem")) { | |
1123 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1124 | unlink ($filename); | |
1125 | goto ROOTCERT_ERROR; | |
1126 | } | |
1127 | } | |
1128 | ||
1129 | # Extract the Host certificate from the file | |
1130 | $pid = open(OPENSSL, "|-"); | |
1131 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1132 | if ($pid) { # parent | |
1133 | if ($cgiparams{'P12_PASS'} ne '') { | |
1134 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1135 | } | |
1136 | close (OPENSSL); | |
1137 | if ($?) { | |
1138 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1139 | unlink ($filename); | |
1140 | goto ROOTCERT_ERROR; | |
1141 | } | |
1142 | } else { # child | |
1143 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys', | |
1144 | '-in', $filename, | |
1145 | '-out', "$tempdir/hostcert.pem")) { | |
1146 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1147 | unlink ($filename); | |
1148 | goto ROOTCERT_ERROR; | |
1149 | } | |
1150 | } | |
1151 | ||
1152 | # Extract the Host key from the file | |
1153 | $pid = open(OPENSSL, "|-"); | |
1154 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1155 | if ($pid) { # parent | |
1156 | if ($cgiparams{'P12_PASS'} ne '') { | |
1157 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1158 | } | |
1159 | close (OPENSSL); | |
1160 | if ($?) { | |
1161 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1162 | unlink ($filename); | |
1163 | goto ROOTCERT_ERROR; | |
1164 | } | |
1165 | } else { # child | |
1166 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts', | |
1167 | '-nodes', | |
1168 | '-in', $filename, | |
1169 | '-out', "$tempdir/serverkey.pem")) { | |
1170 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1171 | unlink ($filename); | |
1172 | goto ROOTCERT_ERROR; | |
1173 | } | |
1174 | } | |
1175 | ||
1176 | move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem"); | |
1177 | if ($? ne 0) { | |
1178 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1179 | unlink ($filename); | |
1180 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1181 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1182 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1183 | goto ROOTCERT_ERROR; | |
1184 | } | |
1185 | ||
1186 | move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem"); | |
1187 | if ($? ne 0) { | |
1188 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1189 | unlink ($filename); | |
1190 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1191 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1192 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1193 | goto ROOTCERT_ERROR; | |
1194 | } | |
1195 | ||
1196 | move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem"); | |
1197 | if ($? ne 0) { | |
1198 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1199 | unlink ($filename); | |
1200 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1201 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1202 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1203 | goto ROOTCERT_ERROR; | |
1204 | } | |
1205 | ||
1206 | goto ROOTCERT_SUCCESS; | |
1207 | ||
1208 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
1209 | ||
1210 | # Validate input since the form was submitted | |
1211 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1212 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1213 | goto ROOTCERT_ERROR; | |
1214 | } | |
1215 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1216 | $errormessage = $Lang::tr{'organization too long'}; | |
1217 | goto ROOTCERT_ERROR; | |
1218 | } | |
1219 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1220 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1221 | goto ROOTCERT_ERROR; | |
1222 | } | |
1223 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1224 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1225 | goto ROOTCERT_ERROR; | |
1226 | } | |
1227 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1228 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1229 | goto ROOTCERT_ERROR; | |
1230 | } | |
1231 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1232 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1233 | goto ROOTCERT_ERROR; | |
1234 | } | |
1235 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1236 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1237 | goto ROOTCERT_ERROR; | |
1238 | } | |
1239 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1240 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1241 | goto ROOTCERT_ERROR; | |
1242 | } | |
1243 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1244 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1245 | goto ROOTCERT_ERROR; | |
1246 | } | |
1247 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1248 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1249 | goto ROOTCERT_ERROR; | |
1250 | } | |
1251 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1252 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1253 | goto ROOTCERT_ERROR; | |
1254 | } | |
1255 | ||
1256 | # Copy the cgisettings to vpnsettings and save the configfile | |
1257 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1258 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1259 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1260 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1261 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1262 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1263 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1264 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1265 | ||
1266 | # Replace empty strings with a . | |
1267 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1268 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1269 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1270 | ||
1271 | # refresh | |
c6c9630e | 1272 | #system ('/bin/touch', "${General::swroot}/ovpn/gencanow"); |
6e13d0a5 MT |
1273 | |
1274 | # Create the CA certificate | |
1275 | my $pid = open(OPENSSL, "|-"); | |
1276 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1277 | if ($pid) { # parent | |
1278 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1279 | print OPENSSL "$state\n"; | |
1280 | print OPENSSL "$city\n"; | |
1281 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1282 | print OPENSSL "$ou\n"; | |
1283 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1284 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1285 | close (OPENSSL); | |
1286 | if ($?) { | |
1287 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1288 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1289 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1290 | goto ROOTCERT_ERROR; | |
1291 | } | |
1292 | } else { # child | |
1293 | unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1294 | '-days', '999999', '-newkey', 'rsa:2048', | |
1295 | '-keyout', "${General::swroot}/ovpn/ca/cakey.pem", | |
1296 | '-out', "${General::swroot}/ovpn/ca/cacert.pem", | |
1297 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
1298 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1299 | goto ROOTCERT_ERROR; | |
1300 | } | |
1301 | } | |
1302 | ||
1303 | # Create the Host certificate request | |
1304 | $pid = open(OPENSSL, "|-"); | |
1305 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1306 | if ($pid) { # parent | |
1307 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1308 | print OPENSSL "$state\n"; | |
1309 | print OPENSSL "$city\n"; | |
1310 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1311 | print OPENSSL "$ou\n"; | |
1312 | print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1313 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1314 | print OPENSSL ".\n"; | |
1315 | print OPENSSL ".\n"; | |
1316 | close (OPENSSL); | |
1317 | if ($?) { | |
1318 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1319 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1320 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1321 | goto ROOTCERT_ERROR; | |
1322 | } | |
1323 | } else { # child | |
1324 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1325 | '-newkey', 'rsa:1024', | |
1326 | '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem", | |
1327 | '-out', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1328 | '-extensions', 'server', | |
1329 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) { | |
1330 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1331 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1332 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1333 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1334 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1335 | goto ROOTCERT_ERROR; | |
1336 | } | |
1337 | } | |
1338 | ||
1339 | # Sign the host certificate request | |
1340 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
1341 | '-batch', '-notext', | |
1342 | '-in', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1343 | '-out', "${General::swroot}/ovpn/certs/servercert.pem", | |
1344 | '-extensions', 'server', | |
1345 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
1346 | if ($?) { | |
1347 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1348 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1349 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1350 | unlink ("${General::swroot}/ovpn/serverkey.pem"); | |
1351 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1352 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
c6c9630e | 1353 | &newcleanssldatabase(); |
6e13d0a5 MT |
1354 | goto ROOTCERT_ERROR; |
1355 | } else { | |
1356 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
c6c9630e | 1357 | &deletebackupcert(); |
6e13d0a5 MT |
1358 | } |
1359 | ||
1360 | # Create an empty CRL | |
1361 | system('/usr/bin/openssl', 'ca', '-gencrl', | |
1362 | '-out', "${General::swroot}/ovpn/crls/cacrl.pem", | |
1363 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" ); | |
1364 | if ($?) { | |
1365 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1366 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1367 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1368 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1369 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
c6c9630e | 1370 | &cleanssldatabase(); |
6e13d0a5 | 1371 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1372 | # } else { |
1373 | # &cleanssldatabase(); | |
6e13d0a5 MT |
1374 | } |
1375 | # Create Diffie Hellmann Parameter | |
1376 | system('/usr/bin/openssl', 'dhparam', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1377 | '-out', "${General::swroot}/ovpn/ca/dh1024.pem", | |
1378 | '1024' ); | |
1379 | if ($?) { | |
1380 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1381 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1382 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1383 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1384 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
1385 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
c6c9630e | 1386 | &cleanssldatabase(); |
6e13d0a5 | 1387 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1388 | # } else { |
1389 | # &cleanssldatabase(); | |
6e13d0a5 MT |
1390 | } |
1391 | goto ROOTCERT_SUCCESS; | |
1392 | } | |
1393 | ROOTCERT_ERROR: | |
1394 | if ($cgiparams{'ACTION'} ne '') { | |
1395 | &Header::showhttpheaders(); | |
1396 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1397 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1398 | if ($errormessage) { | |
1399 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
1400 | print "<class name='base'>$errormessage"; | |
1401 | print " </class>"; | |
1402 | &Header::closebox(); | |
1403 | } | |
1404 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:"); | |
1405 | print <<END | |
1406 | <form method='post' enctype='multipart/form-data'> | |
1407 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
1408 | <tr><td width='30%' class='base'>$Lang::tr{'organization name'}:</td> | |
1409 | <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td> | |
1410 | <td width='35%' colspan='2'> </td></tr> | |
1411 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}:</td> | |
1412 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td> | |
1413 | <td colspan='2'> </td></tr> | |
1414 | <tr><td class='base'>$Lang::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td> | |
1415 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td> | |
1416 | <td colspan='2'> </td></tr> | |
1417 | <tr><td class='base'>$Lang::tr{'your department'}: <img src='/blob.gif' alt'*' /></td> | |
1418 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td> | |
1419 | <td colspan='2'> </td></tr> | |
1420 | <tr><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif' alt'*' /></td> | |
1421 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td> | |
1422 | <td colspan='2'> </td></tr> | |
1423 | <tr><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td> | |
1424 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td> | |
1425 | <td colspan='2'> </td></tr> | |
1426 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
1427 | <td class='base'><select name='ROOTCERT_COUNTRY'> | |
1428 | ||
1429 | END | |
1430 | ; | |
1431 | foreach my $country (sort keys %{Countries::countries}) { | |
1432 | print "<option value='$Countries::countries{$country}'"; | |
1433 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
1434 | print " selected='selected'"; | |
1435 | } | |
1436 | print ">$country</option>"; | |
1437 | } | |
1438 | print <<END | |
1439 | </select></td> | |
1440 | <td colspan='2'> </td></tr> | |
1441 | <tr><td> </td> | |
1442 | <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td> | |
1443 | <td> </td><td> </td></tr> | |
1444 | <tr><td class='base' colspan='4' align='left'> | |
1445 | <img src='/blob.gif' valign='top' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
1446 | <tr><td class='base' colspan='4' align='left'> | |
1447 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: | |
1448 | $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'} | |
1449 | </td></tr> | |
1450 | <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr> | |
1451 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td> | |
1452 | <td nowrap='nowrap'><input type='file' name='FH' size='32'></td> | |
1453 | <td colspan='2'> </td></tr> | |
1454 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td> | |
1455 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td> | |
1456 | <td colspan='2'> </td></tr> | |
1457 | <tr><td> </td> | |
1458 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td> | |
1459 | <td colspan='2'> </td></tr> | |
1460 | <tr><td class='base' colspan='4' align='left'> | |
1461 | <img src='/blob.gif' valign='top' al='*' > $Lang::tr{'this field may be blank'}</td></tr> | |
1462 | </form></table> | |
1463 | END | |
1464 | ; | |
1465 | &Header::closebox(); | |
1466 | ||
1467 | &Header::closebigbox(); | |
1468 | &Header::closepage(); | |
1469 | exit(0) | |
1470 | } | |
1471 | ||
1472 | ROOTCERT_SUCCESS: | |
1473 | system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem"); | |
c6c9630e MT |
1474 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
1475 | # $vpnsettings{'ENABLE_BLUE'} eq 'on') { | |
1476 | # system('/usr/local/bin/ipsecctrl', 'S'); | |
1477 | # } | |
6e13d0a5 MT |
1478 | |
1479 | ### | |
1480 | ### Enable/Disable connection | |
1481 | ### | |
ce9abb66 AH |
1482 | |
1483 | ### | |
7c1d9faf | 1484 | # m.a.d net2net |
ce9abb66 AH |
1485 | ### |
1486 | ||
6e13d0a5 | 1487 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
c6c9630e MT |
1488 | |
1489 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 | 1490 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
ce9abb66 AH |
1491 | # my $n2nactive = ''; |
1492 | my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`; | |
1493 | ||
6e13d0a5 | 1494 | if ($confighash{$cgiparams{'KEY'}}) { |
ce9abb66 AH |
1495 | |
1496 | ||
1497 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { | |
c6c9630e MT |
1498 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
1499 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 AH |
1500 | |
1501 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
1502 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
1503 | } | |
1504 | ||
1505 | } else { | |
1506 | ||
c6c9630e | 1507 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; |
ce9abb66 AH |
1508 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
1509 | ||
1510 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
1511 | if ($n2nactive ne ''){ | |
1512 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
1513 | } | |
1514 | ||
1515 | } else { | |
1516 | $errormessage = $Lang::tr{'invalid key'}; | |
1517 | } | |
1518 | } | |
1519 | } | |
6e13d0a5 MT |
1520 | |
1521 | ### | |
1522 | ### Download OpenVPN client package | |
1523 | ### | |
ce9abb66 AH |
1524 | |
1525 | ||
6e13d0a5 MT |
1526 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) { |
1527 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1528 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1529 | my $file = ''; | |
1530 | my $clientovpn = ''; | |
1531 | my @fileholder; | |
1532 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1533 | my $zippath = "$tempdir/"; | |
ce9abb66 AH |
1534 | |
1535 | ### | |
7c1d9faf AH |
1536 | # m.a.d net2net |
1537 | ### | |
ce9abb66 AH |
1538 | |
1539 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
1540 | ||
1541 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip"; | |
1542 | my $zippathname = "$zippath$zipname"; | |
1543 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf"; | |
1544 | my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]); | |
1545 | my $ovsubnet = "@ovsubnettemp[0].@ovsubnettemp[1].@ovsubnettemp[2]"; | |
1546 | my $tunmtu = ''; | |
7c1d9faf | 1547 | my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]); |
ce9abb66 AH |
1548 | |
1549 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; | |
1550 | flock CLIENTCONF, 2; | |
1551 | ||
1552 | my $zip = Archive::Zip->new(); | |
7c1d9faf | 1553 | print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 1554 | print CLIENTCONF "# \n"; |
b278daf3 | 1555 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
1556 | print CLIENTCONF "user nobody\n"; |
1557 | print CLIENTCONF "group nobody\n"; | |
1558 | print CLIENTCONF "persist-tun\n"; | |
1559 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 1560 | print CLIENTCONF "script-security 2\n"; |
b278daf3 | 1561 | print CLIENTCONF "# IP/DNS for the Server Gateway - g2g Mode\n"; |
531f0835 | 1562 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n"; |
b278daf3 AH |
1563 | print CLIENTCONF "float\n"; |
1564 | print CLIENTCONF "# IP adress of the VPN Subnet\n"; | |
ce9abb66 | 1565 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
b278daf3 | 1566 | print CLIENTCONF "# Server Gateway Network\n"; |
7c1d9faf | 1567 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
b278daf3 | 1568 | print CLIENTCONF "# tun Device\n"; |
ce9abb66 | 1569 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\n"; |
b278daf3 | 1570 | print CLIENTCONF "#Port and Protokoll\n"; |
ce9abb66 AH |
1571 | print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n"; |
1572 | print CLIENTCONF "proto $confighash{$cgiparams{'KEY'}}[28]\n"; | |
b278daf3 | 1573 | print CLIENTCONF "# Paketsize\n"; |
d96c89eb | 1574 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; |
ce9abb66 | 1575 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb AH |
1576 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') { |
1577 | if ($cgiparams{'FRAGMENT'} eq '') { | |
1578 | print CLIENTCONF "fragment 1300\r\n"; | |
1579 | } else { | |
1580 | print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n" | |
1581 | } | |
1582 | if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') { | |
ce9abb66 | 1583 | print CLIENTCONF "mssfix\n"; |
d96c89eb AH |
1584 | } |
1585 | } | |
ce9abb66 AH |
1586 | print CLIENTCONF "# Auth. Client\n"; |
1587 | print CLIENTCONF "tls-client\n"; | |
b278daf3 | 1588 | print CLIENTCONF "# Cipher\n"; |
ce9abb66 AH |
1589 | print CLIENTCONF "cipher AES-256-CBC\n"; |
1590 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { | |
1591 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
1592 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", "$confighash{$cgiparams{'KEY'}}[1].p12") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1].p12\n"; | |
1593 | } | |
ce9abb66 | 1594 | if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') { |
b278daf3 | 1595 | print CLIENTCONF "# Enable Compression\n"; |
ce9abb66 | 1596 | print CLIENTCONF "comp-lzo\r\n"; |
b278daf3 | 1597 | } |
ce9abb66 AH |
1598 | print CLIENTCONF "# Debug Level\n"; |
1599 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 1600 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 1601 | print CLIENTCONF "keepalive 10 60\n"; |
b278daf3 | 1602 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
1603 | print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n"; |
1604 | print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n"; | |
b278daf3 | 1605 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
ce9abb66 AH |
1606 | print CLIENTCONF "# management localhost 4711\n"; |
1607 | print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n"; | |
531f0835 | 1608 | |
ce9abb66 AH |
1609 | |
1610 | close(CLIENTCONF); | |
1611 | ||
1612 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; | |
1613 | my $status = $zip->writeToFileNamed($zippathname); | |
1614 | ||
1615 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
1616 | @fileholder = <DLFILE>; | |
1617 | print "Content-Type:application/x-download\n"; | |
1618 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
1619 | print @fileholder; | |
1620 | exit (0); | |
1621 | } | |
1622 | else | |
1623 | { | |
1624 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip"; | |
1625 | my $zippathname = "$zippath$zipname"; | |
1626 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn"; | |
1627 | ||
1628 | ### | |
7c1d9faf | 1629 | # m.a.d net2net |
ce9abb66 AH |
1630 | ### |
1631 | ||
c6c9630e | 1632 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; |
6e13d0a5 MT |
1633 | flock CLIENTCONF, 2; |
1634 | ||
1635 | my $zip = Archive::Zip->new(); | |
1636 | ||
c6c9630e | 1637 | print CLIENTCONF "#OpenVPN Server conf\r\n"; |
6e13d0a5 MT |
1638 | print CLIENTCONF "tls-client\r\n"; |
1639 | print CLIENTCONF "client\r\n"; | |
1640 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\r\n"; | |
c6c9630e | 1641 | print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n"; |
6e13d0a5 MT |
1642 | print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu $vpnsettings{'DMTU'}\r\n"; |
1643 | if ( $vpnsettings{'ENABLED'} eq 'on'){ | |
1644 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
c6c9630e MT |
1645 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ |
1646 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n"; | |
1647 | print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
1648 | } | |
1649 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
1650 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
1651 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
1652 | } | |
1653 | } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
1654 | print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
1655 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
1656 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
1657 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
1658 | } | |
1659 | } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
1660 | print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
6e13d0a5 MT |
1661 | } |
1662 | ||
1663 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { | |
c6c9630e MT |
1664 | print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n"; |
1665 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", "$confighash{$cgiparams{'KEY'}}[1].p12") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1].p12\n"; | |
6e13d0a5 | 1666 | } else { |
c6c9630e MT |
1667 | print CLIENTCONF "ca cacert.pem\r\n"; |
1668 | print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n"; | |
1669 | print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; | |
1670 | $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; | |
1671 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem", "$confighash{$cgiparams{'KEY'}}[1]cert.pem") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1]cert.pem\n"; | |
6e13d0a5 MT |
1672 | } |
1673 | print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n"; | |
1674 | if ($vpnsettings{DCOMPLZO} eq 'on') { | |
1675 | print CLIENTCONF "comp-lzo\r\n"; | |
1676 | } | |
1677 | print CLIENTCONF "verb 3\r\n"; | |
1678 | print CLIENTCONF "ns-cert-type server\r\n"; | |
a79fa1d6 JPT |
1679 | print CLIENTCONF "tls-remote $vpnsettings{ROOTCERT_HOSTNAME}\r\n"; |
1680 | if ($vpnsettings{MSSFIX} eq 'on') { | |
1681 | print CLIENTCONF "mssfix\r\n"; | |
1682 | } | |
74225cce | 1683 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) { |
a79fa1d6 JPT |
1684 | print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n"; |
1685 | } | |
6e13d0a5 | 1686 | close(CLIENTCONF); |
ce9abb66 | 1687 | |
6e13d0a5 MT |
1688 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; |
1689 | my $status = $zip->writeToFileNamed($zippathname); | |
1690 | ||
1691 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
1692 | @fileholder = <DLFILE>; | |
1693 | print "Content-Type:application/x-download\n"; | |
1694 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
1695 | print @fileholder; | |
1696 | exit (0); | |
ce9abb66 AH |
1697 | } |
1698 | ||
1699 | ||
1700 | ||
6e13d0a5 MT |
1701 | ### |
1702 | ### Remove connection | |
1703 | ### | |
ce9abb66 AH |
1704 | |
1705 | ||
6e13d0a5 MT |
1706 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
1707 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1708 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e MT |
1709 | |
1710 | if ($confighash{$cgiparams{'KEY'}}) { | |
1711 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1712 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
1713 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
1714 | # } | |
1715 | # | |
1716 | my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
ce9abb66 AH |
1717 | |
1718 | ### | |
7c1d9faf | 1719 | # m.a.d net2net |
ce9abb66 | 1720 | ### |
7c1d9faf | 1721 | |
ce9abb66 AH |
1722 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { |
1723 | ||
1724 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
1725 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
1726 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
1727 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
1728 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
1729 | ||
1730 | } | |
ce9abb66 AH |
1731 | |
1732 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
c6c9630e MT |
1733 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); |
1734 | delete $confighash{$cgiparams{'KEY'}}; | |
1735 | my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
1736 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1737 | #&writeserverconf(); | |
6e13d0a5 | 1738 | } else { |
c6c9630e | 1739 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 | 1740 | } |
ce9abb66 AH |
1741 | |
1742 | ||
6e13d0a5 MT |
1743 | ### |
1744 | ### Download PKCS12 file | |
1745 | ### | |
1746 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
1747 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1748 | ||
1749 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
1750 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
1751 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`; | |
1752 | exit (0); | |
1753 | ||
1754 | ### | |
1755 | ### Display certificate | |
1756 | ### | |
1757 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
1758 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1759 | ||
1760 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
c6c9630e MT |
1761 | &Header::showhttpheaders(); |
1762 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1763 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1764 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:"); | |
1765 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
1766 | $output = &Header::cleanhtml($output,"y"); | |
1767 | print "<pre>$output</pre>\n"; | |
1768 | &Header::closebox(); | |
1769 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1770 | &Header::closebigbox(); | |
1771 | &Header::closepage(); | |
1772 | exit(0); | |
6e13d0a5 MT |
1773 | } |
1774 | ### | |
1775 | ### Display Certificate Revoke List | |
1776 | ### | |
1777 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) { | |
c6c9630e MT |
1778 | # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
1779 | ||
6e13d0a5 | 1780 | if ( -f "${General::swroot}/ovpn/crls/cacrl.pem") { |
c6c9630e MT |
1781 | &Header::showhttpheaders(); |
1782 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1783 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1784 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:"); | |
1785 | my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`; | |
1786 | $output = &Header::cleanhtml($output,"y"); | |
1787 | print "<pre>$output</pre>\n"; | |
1788 | &Header::closebox(); | |
1789 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1790 | &Header::closebigbox(); | |
1791 | &Header::closepage(); | |
1792 | exit(0); | |
6e13d0a5 MT |
1793 | } |
1794 | ||
1795 | ### | |
1796 | ### Advanced Server Settings | |
1797 | ### | |
1798 | ||
1799 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) { | |
1800 | %cgiparams = (); | |
1801 | %cahash = (); | |
1802 | %confighash = (); | |
1803 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
1804 | ||
c6c9630e MT |
1805 | # if ($cgiparams{'CLIENT2CLIENT'} eq '') { |
1806 | # $cgiparams{'CLIENT2CLIENT'} = 'on'; | |
1807 | # } | |
6e13d0a5 MT |
1808 | ADV_ERROR: |
1809 | if ($cgiparams{'MAX_CLIENTS'} eq '') { | |
c6c9630e | 1810 | $cgiparams{'MAX_CLIENTS'} = '100'; |
6e13d0a5 MT |
1811 | } |
1812 | ||
1813 | if ($cgiparams{'KEEPALIVE_1'} eq '') { | |
c6c9630e | 1814 | $cgiparams{'KEEPALIVE_1'} = '10'; |
6e13d0a5 MT |
1815 | } |
1816 | if ($cgiparams{'KEEPALIVE_2'} eq '') { | |
c6c9630e | 1817 | $cgiparams{'KEEPALIVE_2'} = '60'; |
6e13d0a5 MT |
1818 | } |
1819 | if ($cgiparams{'LOG_VERB'} eq '') { | |
c6c9630e | 1820 | $cgiparams{'LOG_VERB'} = '3'; |
6e13d0a5 | 1821 | } |
6e13d0a5 MT |
1822 | $checked{'CLIENT2CLIENT'}{'off'} = ''; |
1823 | $checked{'CLIENT2CLIENT'}{'on'} = ''; | |
1824 | $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED'; | |
1825 | $checked{'REDIRECT_GW_DEF1'}{'off'} = ''; | |
1826 | $checked{'REDIRECT_GW_DEF1'}{'on'} = ''; | |
1827 | $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED'; | |
a79fa1d6 JPT |
1828 | $selected{'ENGINES'}{$cgiparams{'ENGINES'}} = 'SELECTED'; |
1829 | $checked{'MSSFIX'}{'off'} = ''; | |
1830 | $checked{'MSSFIX'}{'on'} = ''; | |
1831 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 MT |
1832 | $selected{'LOG_VERB'}{'1'} = ''; |
1833 | $selected{'LOG_VERB'}{'2'} = ''; | |
1834 | $selected{'LOG_VERB'}{'3'} = ''; | |
1835 | $selected{'LOG_VERB'}{'4'} = ''; | |
1836 | $selected{'LOG_VERB'}{'5'} = ''; | |
1837 | $selected{'LOG_VERB'}{'6'} = ''; | |
1838 | $selected{'LOG_VERB'}{'7'} = ''; | |
1839 | $selected{'LOG_VERB'}{'8'} = ''; | |
1840 | $selected{'LOG_VERB'}{'9'} = ''; | |
1841 | $selected{'LOG_VERB'}{'10'} = ''; | |
1842 | $selected{'LOG_VERB'}{'11'} = ''; | |
1843 | $selected{'LOG_VERB'}{'0'} = ''; | |
1844 | $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED'; | |
a79fa1d6 JPT |
1845 | |
1846 | ||
6e13d0a5 MT |
1847 | |
1848 | &Header::showhttpheaders(); | |
1849 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
1850 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
1851 | if ($errormessage) { | |
c6c9630e MT |
1852 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
1853 | print "<class name='base'>$errormessage\n"; | |
1854 | print " </class>\n"; | |
1855 | &Header::closebox(); | |
6e13d0a5 MT |
1856 | } |
1857 | &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'}); | |
1858 | print <<END | |
1859 | <form method='post' enctype='multipart/form-data'> | |
1860 | <table width='100%'> | |
1861 | <tr> | |
1862 | <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td> | |
1863 | </tr> | |
1864 | <tr> | |
1865 | <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td> | |
1866 | </tr> | |
1867 | <tr> | |
1868 | <td class='base'>Domain</td> | |
1869 | <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td> | |
1870 | </tr> | |
1871 | <tr> | |
1872 | <td class='base'>DNS</td> | |
1873 | <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td> | |
1874 | </tr> | |
1875 | <tr> | |
1876 | <td class='base'>WINS</td> | |
1877 | <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td> | |
1878 | </tr> | |
1879 | </table> | |
1880 | <hr size='1'> | |
6e13d0a5 MT |
1881 | <table width='100%'> |
1882 | <tr> | |
1883 | <td class'base'><b>$Lang::tr{'misc-options'}</b></td> | |
1884 | </tr> | |
1885 | <tr> | |
a79fa1d6 | 1886 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='50%'></td> |
6e13d0a5 MT |
1887 | </tr> |
1888 | <tr> | |
1889 | <td class='base'>Client-To-Client</td> | |
1890 | <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td> | |
1891 | </tr> | |
1892 | <tr> | |
1893 | <td class='base'>Redirect-Gateway def1</td> | |
1894 | <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td> | |
1895 | </tr> | |
1896 | <tr> | |
1897 | <td class='base'>Max-Clients</td> | |
a79fa1d6 | 1898 | <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td> |
6e13d0a5 | 1899 | </tr> |
a79fa1d6 JPT |
1900 | <tr> |
1901 | <td class='base'>Keppalive <br /> | |
1902 | (ping/ping-restart)</td> | |
1903 | <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td> | |
1904 | <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td> | |
1905 | </tr> | |
1906 | <tr> | |
1907 | <td class='base'>fragment <br></td> | |
1908 | <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td> | |
1909 | <td>Default: <span class="base">1300</span></td> | |
1910 | </tr> | |
1911 | <tr> | |
1912 | <td class='base'>mssfix</td> | |
1913 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
1914 | <td>Default: on</td> | |
1915 | </tr> | |
1916 | </table> | |
1917 | ||
1918 | <!-- | |
1919 | <hr size='1'> | |
1920 | <table width='100%'> | |
1921 | <tr> | |
1922 | <td class'base'><b>Crypto-Engines</b></td> | |
1923 | </tr> | |
1924 | <tr> | |
1925 | <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td> | |
6e13d0a5 | 1926 | </tr> |
a79fa1d6 JPT |
1927 | <tr><td class='base'>Engines:</td> |
1928 | <td><select name='ENGINES'><option value="none" $selected{'ENGINES'}{'none'}>none</option> | |
1929 | <option value="cryptodev" $selected{'ENGINES'}{'cryptodev'}>cryptodev</option> | |
1930 | <option value="padlock" $selected{'ENGINES'}{'padlock'}>padlock</option> | |
1931 | </select> | |
1932 | </td> | |
6e13d0a5 | 1933 | </table> |
a79fa1d6 | 1934 | --> |
6e13d0a5 MT |
1935 | <hr size='1'> |
1936 | <table width='100%'> | |
1937 | <tr> | |
1938 | <td class'base'><b>$Lang::tr{'log-options'}</b></td> | |
1939 | </tr> | |
1940 | <tr> | |
a79fa1d6 | 1941 | <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td> |
6e13d0a5 MT |
1942 | </tr> |
1943 | ||
1944 | <tr><td class='base'>VERB</td> | |
1945 | <td><select name='LOG_VERB'><option value='1' $selected{'LOG_VERB'}{'1'}>1</option> | |
1946 | <option value='2' $selected{'LOG_VERB'}{'2'}>2</option> | |
1947 | <option value='3' $selected{'LOG_VERB'}{'3'}>3</option> | |
1948 | <option value='4' $selected{'LOG_VERB'}{'4'}>4</option> | |
1949 | <option value='5' $selected{'LOG_VERB'}{'5'}>5</option> | |
1950 | <option value='6' $selected{'LOG_VERB'}{'6'}>6</option> | |
1951 | <option value='7' $selected{'LOG_VERB'}{'7'}>7</option> | |
1952 | <option value='8' $selected{'LOG_VERB'}{'8'}>8</option> | |
1953 | <option value='9' $selected{'LOG_VERB'}{'9'}>9</option> | |
1954 | <option value='10' $selected{'LOG_VERB'}{'10'}>10</option> | |
1955 | <option value='11' $selected{'LOG_VERB'}{'11'}>11</option> | |
c6c9630e | 1956 | <option value='0' $selected{'LOG_VERB'}{'0'}>0</option></select></td> |
6e13d0a5 MT |
1957 | </table> |
1958 | <hr size='1'> | |
1959 | <table width='100%'> | |
1960 | <tr> | |
1961 | <td> </td> | |
1962 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td> | |
1963 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
1964 | <td> </td> | |
1965 | </tr> | |
1966 | </table> | |
1967 | </form> | |
1968 | END | |
1969 | ; | |
1970 | ||
1971 | &Header::closebox(); | |
c6c9630e | 1972 | # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
1973 | &Header::closebigbox(); |
1974 | &Header::closepage(); | |
1975 | exit(0); | |
1976 | ||
1977 | ### | |
1978 | ### Openvpn Connections Statistics | |
1979 | ### | |
1980 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) { | |
1981 | &Header::showhttpheaders(); | |
1982 | &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); | |
1983 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1984 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); | |
1985 | ||
1986 | # | |
1987 | # <td><b>$Lang::tr{'protocol'}</b></td> | |
1988 | # protocol temp removed | |
1989 | print <<END | |
1990 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> | |
1991 | <tr> | |
1992 | <td><b>$Lang::tr{'common name'}</b></td> | |
1993 | <td><b>$Lang::tr{'real address'}</b></td> | |
1994 | <td><b>$Lang::tr{'virtual address'}</b></td> | |
1995 | <td><b>$Lang::tr{'loged in at'}</b></td> | |
1996 | <td><b>$Lang::tr{'bytes sent'}</b></td> | |
1997 | <td><b>$Lang::tr{'bytes received'}</b></td> | |
1998 | <td><b>$Lang::tr{'last activity'}</b></td> | |
1999 | </tr> | |
2000 | END | |
2001 | ; | |
4e17adad | 2002 | my $filename = "/var/log/ovpnserver.log"; |
6e13d0a5 MT |
2003 | open(FILE, $filename) or die 'Unable to open config file.'; |
2004 | my @current = <FILE>; | |
2005 | close(FILE); | |
2006 | my @users =(); | |
2007 | my $status; | |
2008 | my $uid = 0; | |
2009 | my $cn; | |
2010 | my @match = (); | |
2011 | my $proto = "udp"; | |
2012 | my $address; | |
2013 | my %userlookup = (); | |
2014 | foreach my $line (@current) | |
2015 | { | |
2016 | chomp($line); | |
2017 | if ( $line =~ /^Updated,(.+)/){ | |
2018 | @match = split( /^Updated,(.+)/, $line); | |
2019 | $status = $match[1]; | |
2020 | } | |
c6c9630e | 2021 | #gian |
6e13d0a5 MT |
2022 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { |
2023 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
2024 | if ($match[1] ne "Common Name") { | |
2025 | $cn = $match[1]; | |
2026 | $userlookup{$match[2]} = $uid; | |
2027 | $users[$uid]{'CommonName'} = $match[1]; | |
2028 | $users[$uid]{'RealAddress'} = $match[2]; | |
c6c9630e MT |
2029 | $users[$uid]{'BytesReceived'} = &sizeformat($match[3]); |
2030 | $users[$uid]{'BytesSent'} = &sizeformat($match[4]); | |
6e13d0a5 MT |
2031 | $users[$uid]{'Since'} = $match[5]; |
2032 | $users[$uid]{'Proto'} = $proto; | |
2033 | $uid++; | |
2034 | } | |
2035 | } | |
2036 | if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { | |
2037 | @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); | |
2038 | if ($match[1] ne "Virtual Address") { | |
2039 | $address = $match[3]; | |
2040 | #find the uid in the lookup table | |
2041 | $uid = $userlookup{$address}; | |
2042 | $users[$uid]{'VirtualAddress'} = $match[1]; | |
2043 | $users[$uid]{'LastRef'} = $match[4]; | |
2044 | } | |
2045 | } | |
2046 | } | |
2047 | my $user2 = @users; | |
2048 | if ($user2 >= 1){ | |
2049 | for (my $idx = 1; $idx <= $user2; $idx++){ | |
2050 | if ($idx % 2) { | |
4e17adad | 2051 | print "<tr bgcolor='$color{'color20'}'>\n"; |
6e13d0a5 | 2052 | } else { |
4e17adad | 2053 | print "<tr bgcolor='$color{'color22'}'>\n"; |
6e13d0a5 MT |
2054 | } |
2055 | print "<td align='left'>$users[$idx-1]{'CommonName'}</td>"; | |
2056 | print "<td align='left'>$users[$idx-1]{'RealAddress'}</td>"; | |
2057 | print "<td align='left'>$users[$idx-1]{'VirtualAddress'}</td>"; | |
2058 | print "<td align='left'>$users[$idx-1]{'Since'}</td>"; | |
2059 | print "<td align='left'>$users[$idx-1]{'BytesSent'}</td>"; | |
2060 | print "<td align='left'>$users[$idx-1]{'BytesReceived'}</td>"; | |
2061 | print "<td align='left'>$users[$idx-1]{'LastRef'}</td>"; | |
2062 | # print "<td align='left'>$users[$idx-1]{'Proto'}</td>"; | |
2063 | } | |
2064 | } | |
2065 | ||
2066 | print "</table>"; | |
2067 | print <<END | |
2068 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> | |
2069 | <tr><td></td></tr> | |
2070 | <tr><td></td></tr> | |
2071 | <tr><td></td></tr> | |
2072 | <tr><td></td></tr> | |
2073 | <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr> | |
2074 | </table> | |
2075 | END | |
2076 | ; | |
2077 | &Header::closebox(); | |
2078 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2079 | &Header::closebigbox(); | |
2080 | &Header::closepage(); | |
2081 | exit(0); | |
2082 | ||
2083 | ### | |
2084 | ### Download Certificate | |
2085 | ### | |
2086 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
2087 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 2088 | |
6e13d0a5 | 2089 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { |
c6c9630e MT |
2090 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n"; |
2091 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2092 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
2093 | exit (0); | |
2094 | } | |
2095 | ||
2096 | ### | |
2097 | ### Enable/Disable connection | |
2098 | ### | |
ce9abb66 | 2099 | |
c6c9630e MT |
2100 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
2101 | ||
2102 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2103 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2104 | ||
2105 | if ($confighash{$cgiparams{'KEY'}}) { | |
ce9abb66 | 2106 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
c6c9630e MT |
2107 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
2108 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2109 | #&writeserverconf(); | |
2110 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2111 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2112 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
2113 | # } | |
2114 | } else { | |
2115 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
2116 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2117 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2118 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2119 | # } | |
2120 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2121 | #&writeserverconf(); | |
2122 | } | |
2123 | } else { | |
2124 | $errormessage = $Lang::tr{'invalid key'}; | |
6e13d0a5 MT |
2125 | } |
2126 | ||
2127 | ### | |
2128 | ### Restart connection | |
2129 | ### | |
2130 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
2131 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2132 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2133 | ||
2134 | if ($confighash{$cgiparams{'KEY'}}) { | |
c6c9630e MT |
2135 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
2136 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2137 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
2138 | # } | |
6e13d0a5 | 2139 | } else { |
c6c9630e | 2140 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 MT |
2141 | } |
2142 | ||
2143 | ### | |
c6c9630e | 2144 | ### Remove connection |
6e13d0a5 | 2145 | ### |
c6c9630e MT |
2146 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
2147 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2148 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2149 | ||
2150 | if ($confighash{$cgiparams{'KEY'}}) { | |
2151 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2152 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2153 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2154 | # } | |
2155 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
2156 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2157 | delete $confighash{$cgiparams{'KEY'}}; | |
2158 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2159 | #&writeserverconf(); | |
2160 | } else { | |
2161 | $errormessage = $Lang::tr{'invalid key'}; | |
2162 | } | |
ce9abb66 AH |
2163 | #test33 |
2164 | ||
2165 | ### | |
2166 | ### Choose between adding a host-net or net-net connection | |
2167 | ### | |
2168 | ||
2169 | ### | |
7c1d9faf | 2170 | # m.a.d net2net |
ce9abb66 AH |
2171 | ### |
2172 | ||
2173 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
2174 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2175 | &Header::showhttpheaders(); | |
2176 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
2177 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2178 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'}); | |
b278daf3 AH |
2179 | |
2180 | if ( -s "${General::swroot}/ovpn/settings") { | |
2181 | ||
ce9abb66 AH |
2182 | print <<END |
2183 | <b>$Lang::tr{'connection type'}:</b><br /> | |
2184 | <table><form method='post' ENCTYPE="multipart/form-data"> | |
2185 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> | |
2186 | <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
2187 | <tr><td><input type='radio' name='TYPE' value='net' /></td> | |
2188 | <td class='base'>$Lang::tr{'net to net vpn'}</td></tr> | |
2189 | <tr><td><input type='radio' name='TYPE' value='net2net' /></td> | |
2190 | <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr> | |
2191 | <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr> | |
2192 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> | |
2193 | </form></table> | |
2194 | END | |
2195 | ; | |
2196 | ||
b278daf3 AH |
2197 | } else { |
2198 | print <<END | |
2199 | <b>$Lang::tr{'connection type'}:</b><br /> | |
2200 | <table><form method='post' ENCTYPE="multipart/form-data"> | |
2201 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
2202 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> | |
2203 | </form></table> | |
2204 | END | |
2205 | ; | |
2206 | ||
2207 | } | |
2208 | ||
ce9abb66 AH |
2209 | &Header::closebox(); |
2210 | &Header::closebigbox(); | |
2211 | &Header::closepage(); | |
2212 | exit (0); | |
2213 | ||
2214 | ### | |
7c1d9faf | 2215 | # m.a.d net2net |
ce9abb66 AH |
2216 | ### |
2217 | ||
2218 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){ | |
2219 | ||
2220 | my @firen2nconf; | |
2221 | my @confdetails; | |
2222 | my $uplconffilename =''; | |
2223 | my $uplp12name = ''; | |
ce9abb66 AH |
2224 | my @rem_subnet; |
2225 | my @rem_subnet2; | |
2226 | my @tmposupnet3; | |
2227 | my $key; | |
2228 | ||
2229 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2230 | ||
2231 | # Check if a file is uploaded | |
2232 | ||
2233 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
2234 | $errormessage = $Lang::tr{'there was no file upload'}; | |
2235 | goto N2N_ERROR; | |
2236 | } | |
2237 | ||
2238 | # Move uploaded IPfire n2n package to temporary file | |
2239 | ||
2240 | (my $fh, my $filename) = tempfile( ); | |
2241 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
2242 | $errormessage = $!; | |
2243 | goto N2N_ERROR; | |
2244 | } | |
2245 | ||
2246 | my $zip = Archive::Zip->new(); | |
2247 | my $zipName = $filename; | |
2248 | my $status = $zip->read( $zipName ); | |
2249 | if ($status != AZ_OK) { | |
2250 | $errormessage = "Read of $zipName failed\n"; | |
2251 | goto N2N_ERROR; | |
2252 | } | |
2253 | ||
2254 | my $tempdir = tempdir( CLEANUP => 1 ); | |
2255 | my @files = $zip->memberNames(); | |
2256 | for(@files) { | |
2257 | $zip->extractMemberWithoutPaths($_,"$tempdir/$_"); | |
2258 | } | |
2259 | my $countfiles = @files; | |
2260 | ||
2261 | # Check if we have not more then 2 files | |
2262 | ||
2263 | if ( $countfiles == 2){ | |
2264 | foreach (@files){ | |
2265 | if ( $_ =~ /.conf$/){ | |
2266 | $uplconffilename = $_; | |
2267 | } | |
2268 | if ( $_ =~ /.p12$/){ | |
2269 | $uplp12name = $_; | |
2270 | } | |
2271 | } | |
2272 | if (($uplconffilename eq '') || ($uplp12name eq '')){ | |
2273 | $errormessage = "Either no *.conf or no *.p12 file found\n"; | |
2274 | goto N2N_ERROR; | |
2275 | } | |
2276 | ||
2277 | open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file'; | |
2278 | @firen2nconf = <FILE>; | |
2279 | close (FILE); | |
2280 | chomp(@firen2nconf); | |
2281 | ||
2282 | } else { | |
2283 | ||
2284 | $errormessage = "Filecount does not match only 2 files are allowed\n"; | |
2285 | goto N2N_ERROR; | |
2286 | } | |
2287 | ||
7c1d9faf AH |
2288 | ### |
2289 | # m.a.d net2net | |
ce9abb66 AH |
2290 | ### |
2291 | ||
2292 | my @n2nname = split(/\./,$uplconffilename); | |
2293 | $n2nname[0] =~ s/\n|\r//g; | |
2294 | ||
7c1d9faf AH |
2295 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
2296 | unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
2297 | |
2298 | move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename"); | |
2299 | ||
2300 | if ($? ne 0) { | |
2301 | $errormessage = "*.conf move failed: $!"; | |
2302 | unlink ($filename); | |
2303 | goto N2N_ERROR; | |
2304 | } | |
2305 | ||
2306 | move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name"); | |
b278daf3 AH |
2307 | chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; |
2308 | ||
ce9abb66 AH |
2309 | if ($? ne 0) { |
2310 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
2311 | unlink ($filename); | |
2312 | goto N2N_ERROR; | |
2313 | } | |
2314 | ||
2315 | my $complzoactive; | |
d96c89eb AH |
2316 | my $mssfixactive; |
2317 | my $n2nfragment; | |
ce9abb66 AH |
2318 | my @n2nproto = split(/ /, (grep { /^proto/ } @firen2nconf)[0]); |
2319 | my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]); | |
2320 | my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]); | |
2321 | my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf; | |
2322 | if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";} | |
d96c89eb AH |
2323 | my @n2nmssfix = grep { /^mssfix/ } @firen2nconf; |
2324 | if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";} | |
2325 | my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]); | |
ce9abb66 AH |
2326 | my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]); |
2327 | my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]); | |
2328 | my @n2novpnsub = split(/\./,$n2novpnsuball[1]); | |
2329 | my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]); | |
2330 | my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]); | |
2331 | ||
ce9abb66 AH |
2332 | ### |
2333 | # m.a.d delete CR and LF from arrays for this chomp doesnt work | |
2334 | ### | |
2335 | ||
ce9abb66 | 2336 | $n2nremote[1] =~ s/\n|\r//g; |
ce9abb66 AH |
2337 | $n2novpnsub[0] =~ s/\n|\r//g; |
2338 | $n2novpnsub[1] =~ s/\n|\r//g; | |
2339 | $n2novpnsub[2] =~ s/\n|\r//g; | |
2340 | $n2nproto[1] =~ s/\n|\r//g; | |
2341 | $n2nport[1] =~ s/\n|\r//g; | |
2342 | $n2ntunmtu[1] =~ s/\n|\r//g; | |
2343 | $n2nremsub[1] =~ s/\n|\r//g; | |
b278daf3 | 2344 | $n2nremsub[2] =~ s/\n|\r//g; |
ce9abb66 | 2345 | $n2nlocalsub[2] =~ s/\n|\r//g; |
d96c89eb | 2346 | $n2nfragment[1] =~ s/\n|\r//g; |
ce9abb66 | 2347 | chomp ($complzoactive); |
d96c89eb | 2348 | chomp ($mssfixactive); |
ce9abb66 AH |
2349 | |
2350 | ### | |
7c1d9faf | 2351 | # m.a.d net2net |
ce9abb66 AH |
2352 | ### |
2353 | ||
2354 | ### | |
2355 | # Check if there is no other entry with this name | |
2356 | ### | |
2357 | ||
2358 | foreach my $dkey (keys %confighash) { | |
2359 | if ($confighash{$dkey}[1] eq $n2nname[0]) { | |
2360 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
2361 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
2362 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
2363 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
ce9abb66 AH |
2364 | goto N2N_ERROR; |
2365 | } | |
2366 | } | |
2367 | ||
d96c89eb AH |
2368 | ### |
2369 | # Check if OpenVPN Subnet is valid | |
2370 | ### | |
2371 | ||
2372 | foreach my $dkey (keys %confighash) { | |
2373 | if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") { | |
2374 | $errormessage = 'The OpenVPN Subnet is already in use'; | |
b278daf3 AH |
2375 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
2376 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
2377 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2378 | goto N2N_ERROR; |
2379 | } | |
2380 | } | |
2381 | ||
2382 | ### | |
2383 | # Check im Dest Port is vaild | |
2384 | ### | |
2385 | ||
2386 | foreach my $dkey (keys %confighash) { | |
2387 | if ($confighash{$dkey}[29] eq $n2nport[1] ) { | |
2388 | $errormessage = 'The OpenVPN Port is already in use'; | |
b278daf3 AH |
2389 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
2390 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
2391 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2392 | goto N2N_ERROR; |
2393 | } | |
2394 | } | |
2395 | ||
2396 | ||
2397 | ||
ce9abb66 AH |
2398 | $key = &General::findhasharraykey (\%confighash); |
2399 | ||
2400 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
2401 | $confighash{$key}[0] = 'off'; | |
2402 | $confighash{$key}[1] = $n2nname[0]; | |
2403 | $confighash{$key}[2] = $n2nname[0]; | |
2404 | $confighash{$key}[3] = 'net'; | |
2405 | $confighash{$key}[4] = 'cert'; | |
2406 | $confighash{$key}[6] = 'client'; | |
2407 | $confighash{$key}[8] = $n2nlocalsub[2]; | |
2408 | $confighash{$key}[10] = $n2nremote[1]; | |
b278daf3 | 2409 | $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]"; |
d96c89eb AH |
2410 | $confighash{$key}[23] = $mssfixactive; |
2411 | $confighash{$key}[24] = $n2nfragment[1]; | |
2412 | $confighash{$key}[25] = 'IPFire n2n Client'; | |
ce9abb66 AH |
2413 | $confighash{$key}[26] = 'red'; |
2414 | $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0"; | |
2415 | $confighash{$key}[28] = $n2nproto[1]; | |
2416 | $confighash{$key}[29] = $n2nport[1]; | |
2417 | $confighash{$key}[30] = $complzoactive; | |
2418 | $confighash{$key}[31] = $n2ntunmtu[1]; | |
2419 | ||
2420 | ||
2421 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
d96c89eb | 2422 | |
ce9abb66 AH |
2423 | N2N_ERROR: |
2424 | ||
2425 | &Header::showhttpheaders(); | |
2426 | &Header::openpage('Validate imported configuration', 1, ''); | |
2427 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
2428 | if ($errormessage) { | |
2429 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2430 | print "<class name='base'>$errormessage"; | |
2431 | print " </class>"; | |
2432 | &Header::closebox(); | |
2433 | ||
2434 | } else | |
2435 | { | |
2436 | &Header::openbox('100%', 'LEFT', 'import ipfire net2net config'); | |
2437 | } | |
2438 | if ($errormessage eq ''){ | |
2439 | print <<END | |
2440 | <!-- ipfire net2net config gui --> | |
2441 | <table width='100%'> | |
2442 | <tr><td width='25%'> </td><td width='25%'> </td></tr> | |
2443 | <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr> | |
2444 | <tr><td> </td><td> </td></tr> | |
2445 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr> | |
2446 | <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr> | |
2447 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr> | |
2448 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td><td><b>$confighash{$key}[11]</b></td></tr> | |
2449 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr> | |
2450 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr> | |
2451 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr> | |
2452 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr> | |
7c1d9faf AH |
2453 | <tr><td class='boldbase' nowrap='nowrap'>MSSFIX </td><td><b>$confighash{$key}[23]</b></td></tr> |
2454 | <tr><td class='boldbase' nowrap='nowrap'>Fragment </td><td><b>$confighash{$key}[24]</b></td></tr> | |
ce9abb66 AH |
2455 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr> |
2456 | <tr><td> </td><td> </td></tr> | |
2457 | </table> | |
2458 | END | |
2459 | ; | |
2460 | &Header::closebox(); | |
2461 | } | |
2462 | ||
2463 | if ($errormessage) { | |
2464 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2465 | } else { | |
2466 | print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />"; | |
2467 | print "<input type='hidden' name='TYPE' value='net2netakn' />"; | |
2468 | print "<input type='hidden' name='KEY' value='$key' />"; | |
2469 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
2470 | } | |
2471 | &Header::closebigbox(); | |
2472 | &Header::closepage(); | |
2473 | exit(0); | |
2474 | ||
2475 | ||
2476 | ## | |
2477 | ### Accept IPFire n2n Package Settings | |
2478 | ### | |
2479 | ||
2480 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
2481 | ||
2482 | ### | |
2483 | ### Discard and Rollback IPFire n2n Package Settings | |
2484 | ### | |
2485 | ||
2486 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
2487 | ||
2488 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2489 | ||
2490 | if ($confighash{$cgiparams{'KEY'}}) { | |
2491 | ||
2492 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
2493 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2494 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
2495 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
2496 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
2497 | delete $confighash{$cgiparams{'KEY'}}; | |
2498 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2499 | ||
2500 | } else { | |
2501 | $errormessage = $Lang::tr{'invalid key'}; | |
2502 | } | |
2503 | ||
2504 | ||
2505 | ### | |
7c1d9faf | 2506 | # m.a.d net2net |
ce9abb66 AH |
2507 | ### |
2508 | ||
2509 | ||
2510 | ### | |
2511 | ### Adding a new connection | |
2512 | ### | |
6e13d0a5 MT |
2513 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || |
2514 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || | |
2515 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
2516 | ||
2517 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2518 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
2519 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2520 | ||
2521 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { | |
c6c9630e MT |
2522 | if (! $confighash{$cgiparams{'KEY'}}[0]) { |
2523 | $errormessage = $Lang::tr{'invalid key'}; | |
2524 | goto VPNCONF_END; | |
2525 | } | |
2526 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; | |
2527 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
ce9abb66 | 2528 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; |
c6c9630e MT |
2529 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; |
2530 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
2531 | $cgiparams{'SIDE'} = $confighash{$cgiparams{'KEY'}}[6]; | |
2532 | $cgiparams{'LOCAL_SUBNET'} = $confighash{$cgiparams{'KEY'}}[8]; | |
531f0835 AH |
2533 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; |
2534 | $cgiparams{'REMOTE_SUBNET'} = $confighash{$cgiparams{'KEY'}}[11]; | |
d96c89eb AH |
2535 | # n2n m.a.d new fields |
2536 | $cgiparams{'MSSFIX'} = $confighash{$cgiparams{'KEY'}}[23]; | |
2537 | $cgiparams{'FRAGMENT'} = $confighash{$cgiparams{'KEY'}}[24]; | |
c6c9630e MT |
2538 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; |
2539 | $cgiparams{'INTERFACE'} = $confighash{$cgiparams{'KEY'}}[26]; | |
2540 | #new fields | |
2541 | $cgiparams{'OVPN_SUBNET'} = $confighash{$cgiparams{'KEY'}}[27]; | |
2542 | $cgiparams{'PROTOCOL'} = $confighash{$cgiparams{'KEY'}}[28]; | |
2543 | $cgiparams{'DEST_PORT'} = $confighash{$cgiparams{'KEY'}}[29]; | |
2544 | $cgiparams{'COMPLZO'} = $confighash{$cgiparams{'KEY'}}[30]; | |
2545 | $cgiparams{'MTU'} = $confighash{$cgiparams{'KEY'}}[31]; | |
d96c89eb | 2546 | |
c6c9630e MT |
2547 | #new fields |
2548 | #ab hiere error uebernehmen | |
d96c89eb | 2549 | |
c6c9630e MT |
2550 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
2551 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); | |
18837a6a AH |
2552 | |
2553 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { | |
c6c9630e | 2554 | $errormessage = $Lang::tr{'connection type is invalid'}; |
b278daf3 AH |
2555 | if ($cgiparams{'TYPE'} eq 'net') { |
2556 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2557 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2558 | } | |
c6c9630e MT |
2559 | goto VPNCONF_ERROR; |
2560 | } | |
2561 | ||
2562 | ||
2563 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
2564 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
b278daf3 AH |
2565 | if ($cgiparams{'TYPE'} eq 'net') { |
2566 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2567 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2568 | } | |
2569 | goto VPNCONF_ERROR; | |
2570 | } | |
c6c9630e MT |
2571 | |
2572 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { | |
2573 | $errormessage = $Lang::tr{'name is invalid'}; | |
b278daf3 AH |
2574 | if ($cgiparams{'TYPE'} eq 'net') { |
2575 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2576 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2577 | } | |
c6c9630e MT |
2578 | goto VPNCONF_ERROR; |
2579 | } | |
2580 | ||
2581 | if (length($cgiparams{'NAME'}) >60) { | |
2582 | $errormessage = $Lang::tr{'name too long'}; | |
b278daf3 AH |
2583 | if ($cgiparams{'TYPE'} eq 'net') { |
2584 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2585 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2586 | } | |
c6c9630e MT |
2587 | goto VPNCONF_ERROR; |
2588 | } | |
2589 | ||
d96c89eb | 2590 | ### |
7c1d9faf | 2591 | # m.a.d net2net |
d96c89eb AH |
2592 | ### |
2593 | ||
7c1d9faf AH |
2594 | if ($cgiparams{'TYPE'} eq 'net') { |
2595 | ||
2596 | if ($cgiparams{'DEST_PORT'} eq $vpnsettings{'DDEST_PORT'}) { | |
d96c89eb | 2597 | $errormessage = 'The Destination Port is used by the OpenVPN Server please change'; |
b278daf3 AH |
2598 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2599 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2600 | goto VPNCONF_ERROR; | |
d96c89eb AH |
2601 | } |
2602 | ||
2603 | if ($cgiparams{'OVPN_SUBNET'} eq $vpnsettings{'DOVPN_SUBNET'}) { | |
2604 | $errormessage = 'The OpenVPN Subnet is used by the OpenVPN Server please change'; | |
b278daf3 AH |
2605 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2606 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2607 | goto VPNCONF_ERROR; |
2608 | } | |
2609 | ||
2610 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'MSSFIX'} eq 'on')) { | |
2611 | $errormessage = 'mssfix only allowed with udp'; | |
b278daf3 AH |
2612 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2613 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2614 | goto VPNCONF_ERROR; |
2615 | } | |
2616 | ||
2617 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'FRAGMENT'} ne '')) { | |
2618 | $errormessage = 'fragment only allowed with udp'; | |
b278daf3 AH |
2619 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2620 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2621 | goto VPNCONF_ERROR; |
2622 | } | |
d96c89eb | 2623 | |
7c1d9faf | 2624 | if ( &validdotmask ($cgiparams{'LOCAL_SUBNET'})) { |
b278daf3 AH |
2625 | $errormessage = 'Prefix not allowed for Local Subnet. Please enter Subnet Mask e.g. 255.255.255.0'; |
2626 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2627 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2628 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
2629 | } |
2630 | ||
2631 | if ( &validdotmask ($cgiparams{'OVPN_SUBNET'})) { | |
b278daf3 AH |
2632 | $errormessage = 'Prefix not allowed for OpenVPN Subnet. Please enter Subnet Mask e.g. 255.255.255.0'; |
2633 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2634 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2635 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
2636 | } |
2637 | ||
2638 | if ( &validdotmask ($cgiparams{'REMOTE_SUBNET'})) { | |
b278daf3 AH |
2639 | $errormessage = 'Prefix not allowed for Remote Subnet. Please enter Subnet Mask e.g. 255.255.255.0'; |
2640 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2641 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2642 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
2643 | } |
2644 | } | |
d96c89eb | 2645 | |
ce9abb66 AH |
2646 | # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) { |
2647 | # $errormessage = $Lang::tr{'ipfire side is invalid'}; | |
2648 | # goto VPNCONF_ERROR; | |
2649 | # } | |
2650 | ||
c6c9630e MT |
2651 | # Check if there is no other entry with this name |
2652 | if (! $cgiparams{'KEY'}) { | |
2653 | foreach my $key (keys %confighash) { | |
2654 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
2655 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
2656 | if ($cgiparams{'TYPE'} eq 'net') { |
2657 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2658 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2659 | } | |
c6c9630e | 2660 | goto VPNCONF_ERROR; |
6e13d0a5 | 2661 | } |
c6c9630e MT |
2662 | } |
2663 | } | |
2664 | ||
ce9abb66 AH |
2665 | if (($cgiparams{'TYPE'} eq 'net') && (! $cgiparams{'REMOTE'})) { |
2666 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
b278daf3 AH |
2667 | if ($cgiparams{'TYPE'} eq 'net') { |
2668 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2669 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2670 | } | |
ce9abb66 AH |
2671 | goto VPNCONF_ERROR; |
2672 | } | |
2673 | ||
c6c9630e MT |
2674 | if ($cgiparams{'REMOTE'}) { |
2675 | if (! &General::validip($cgiparams{'REMOTE'})) { | |
2676 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
2677 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
b278daf3 AH |
2678 | if ($cgiparams{'TYPE'} eq 'net') { |
2679 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2680 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2681 | } | |
c6c9630e | 2682 | goto VPNCONF_ERROR; |
6e13d0a5 | 2683 | } else { |
c6c9630e MT |
2684 | if (&valid_dns_host($cgiparams{'REMOTE'})) { |
2685 | $warnmessage = "$Lang::tr{'check vpn lr'} $cgiparams{'REMOTE'}. $Lang::tr{'dns check failed'}"; | |
b278daf3 AH |
2686 | if ($cgiparams{'TYPE'} eq 'net') { |
2687 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2688 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2689 | } | |
c6c9630e | 2690 | } |
6e13d0a5 | 2691 | } |
c6c9630e MT |
2692 | } |
2693 | } | |
2694 | if ($cgiparams{'TYPE'} ne 'host') { | |
2695 | unless (&General::validipandmask($cgiparams{'LOCAL_SUBNET'})) { | |
2696 | $errormessage = $Lang::tr{'local subnet is invalid'}; | |
b278daf3 AH |
2697 | if ($cgiparams{'TYPE'} eq 'net') { |
2698 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2699 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2700 | } | |
c6c9630e MT |
2701 | goto VPNCONF_ERROR;} |
2702 | } | |
2703 | # Check if there is no other entry without IP-address and PSK | |
2704 | if ($cgiparams{'REMOTE'} eq '') { | |
2705 | foreach my $key (keys %confighash) { | |
2706 | if(($cgiparams{'KEY'} ne $key) && | |
2707 | ($confighash{$key}[4] eq 'psk' || $cgiparams{'AUTH'} eq 'psk') && | |
2708 | $confighash{$key}[10] eq '') { | |
2709 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
2710 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2711 | } |
c6c9630e MT |
2712 | } |
2713 | } | |
ce9abb66 AH |
2714 | if (($cgiparams{'TYPE'} eq 'net') && (! &General::validipandmask($cgiparams{'REMOTE_SUBNET'}))) { |
2715 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
b278daf3 AH |
2716 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2717 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2718 | goto VPNCONF_ERROR; | |
ce9abb66 | 2719 | } |
c6c9630e MT |
2720 | |
2721 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
2722 | $errormessage = $Lang::tr{'invalid input'}; | |
2723 | goto VPNCONF_ERROR; | |
2724 | } | |
2725 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
2726 | $errormessage = $Lang::tr{'invalid input'}; | |
2727 | goto VPNCONF_ERROR; | |
2728 | } | |
2729 | ||
2730 | #fixplausi | |
2731 | if ($cgiparams{'AUTH'} eq 'psk') { | |
2732 | # if (! length($cgiparams{'PSK'}) ) { | |
2733 | # $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
2734 | # goto VPNCONF_ERROR; | |
2735 | # } | |
2736 | # if ($cgiparams{'PSK'} =~ /['",&]/) { | |
2737 | # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
2738 | # goto VPNCONF_ERROR; | |
2739 | # } | |
2740 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { | |
2741 | if ($cgiparams{'KEY'}) { | |
2742 | $errormessage = $Lang::tr{'cant change certificates'}; | |
2743 | goto VPNCONF_ERROR; | |
2744 | } | |
2745 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
2746 | $errormessage = $Lang::tr{'there was no file upload'}; | |
2747 | goto VPNCONF_ERROR; | |
2748 | } | |
2749 | ||
2750 | # Move uploaded certificate request to a temporary file | |
2751 | (my $fh, my $filename) = tempfile( ); | |
2752 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
2753 | $errormessage = $!; | |
2754 | goto VPNCONF_ERROR; | |
2755 | } | |
6e13d0a5 | 2756 | |
c6c9630e MT |
2757 | # Sign the certificate request and move it |
2758 | # Sign the host certificate request | |
2759 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
2760 | '-batch', '-notext', | |
2761 | '-in', $filename, | |
2762 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
2763 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
2764 | if ($?) { | |
2765 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2766 | unlink ($filename); | |
2767 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2768 | &newcleanssldatabase(); | |
2769 | goto VPNCONF_ERROR; | |
2770 | } else { | |
2771 | unlink ($filename); | |
2772 | &deletebackupcert(); | |
2773 | } | |
2774 | ||
2775 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
2776 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
2777 | $temp = $1; | |
2778 | $temp =~ s+/Email+, E+; | |
2779 | $temp =~ s/ ST=/ S=/; | |
2780 | $cgiparams{'CERT_NAME'} = $temp; | |
2781 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
2782 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
2783 | if ($cgiparams{'CERT_NAME'} eq '') { | |
2784 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
2785 | goto VPNCONF_ERROR; | |
2786 | } | |
2787 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { | |
2788 | if ($cgiparams{'KEY'}) { | |
2789 | $errormessage = $Lang::tr{'cant change certificates'}; | |
2790 | goto VPNCONF_ERROR; | |
2791 | } | |
2792 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
2793 | $errormessage = $Lang::tr{'there was no file upload'}; | |
2794 | goto VPNCONF_ERROR; | |
2795 | } | |
2796 | # Move uploaded certificate to a temporary file | |
2797 | (my $fh, my $filename) = tempfile( ); | |
2798 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
2799 | $errormessage = $!; | |
2800 | goto VPNCONF_ERROR; | |
2801 | } | |
2802 | ||
2803 | # Verify the certificate has a valid CA and move it | |
2804 | my $validca = 0; | |
2805 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename`; | |
2806 | if ($test =~ /: OK/) { | |
2807 | $validca = 1; | |
2808 | } else { | |
2809 | foreach my $key (keys %cahash) { | |
2810 | $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$key}[0]cert.pem $filename`; | |
2811 | if ($test =~ /: OK/) { | |
2812 | $validca = 1; | |
2813 | } | |
6e13d0a5 | 2814 | } |
c6c9630e MT |
2815 | } |
2816 | if (! $validca) { | |
2817 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
2818 | unlink ($filename); | |
2819 | goto VPNCONF_ERROR; | |
2820 | } else { | |
2821 | move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2822 | if ($? ne 0) { | |
2823 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
2824 | unlink ($filename); | |
2825 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2826 | } |
c6c9630e MT |
2827 | } |
2828 | ||
2829 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
2830 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
2831 | $temp = $1; | |
2832 | $temp =~ s+/Email+, E+; | |
2833 | $temp =~ s/ ST=/ S=/; | |
2834 | $cgiparams{'CERT_NAME'} = $temp; | |
2835 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
2836 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
2837 | if ($cgiparams{'CERT_NAME'} eq '') { | |
2838 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2839 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
2840 | goto VPNCONF_ERROR; | |
2841 | } | |
2842 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { | |
2843 | if ($cgiparams{'KEY'}) { | |
2844 | $errormessage = $Lang::tr{'cant change certificates'}; | |
2845 | goto VPNCONF_ERROR; | |
2846 | } | |
2847 | # Validate input since the form was submitted | |
2848 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
2849 | $errormessage = $Lang::tr{'name too long'}; | |
2850 | goto VPNCONF_ERROR; | |
2851 | } | |
2852 | if ($cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
2853 | $errormessage = $Lang::tr{'invalid input for name'}; | |
2854 | goto VPNCONF_ERROR; | |
2855 | } | |
2856 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
2857 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
2858 | goto VPNCONF_ERROR; | |
2859 | } | |
2860 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
2861 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
2862 | goto VPNCONF_ERROR; | |
2863 | } | |
2864 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
2865 | $errormessage = $Lang::tr{'invalid input for department'}; | |
2866 | goto VPNCONF_ERROR; | |
2867 | } | |
2868 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
2869 | $errormessage = $Lang::tr{'organization too long'}; | |
2870 | goto VPNCONF_ERROR; | |
2871 | } | |
2872 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
2873 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
2874 | goto VPNCONF_ERROR; | |
2875 | } | |
2876 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
2877 | $errormessage = $Lang::tr{'invalid input for city'}; | |
2878 | goto VPNCONF_ERROR; | |
2879 | } | |
2880 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
2881 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
2882 | goto VPNCONF_ERROR; | |
2883 | } | |
2884 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
2885 | $errormessage = $Lang::tr{'invalid input for country'}; | |
2886 | goto VPNCONF_ERROR; | |
2887 | } | |
2888 | if ($cgiparams{'CERT_PASS1'} ne '' && $cgiparams{'CERT_PASS2'} ne ''){ | |
2889 | if (length($cgiparams{'CERT_PASS1'}) < 5) { | |
2890 | $errormessage = $Lang::tr{'password too short'}; | |
2891 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2892 | } |
c6c9630e MT |
2893 | } |
2894 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { | |
2895 | $errormessage = $Lang::tr{'passwords do not match'}; | |
2896 | goto VPNCONF_ERROR; | |
2897 | } | |
2898 | ||
2899 | # Replace empty strings with a . | |
2900 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
2901 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
2902 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
2903 | ||
2904 | # Create the Host certificate request client | |
2905 | my $pid = open(OPENSSL, "|-"); | |
2906 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto VPNCONF_ERROR;}; | |
2907 | if ($pid) { # parent | |
2908 | print OPENSSL "$cgiparams{'CERT_COUNTRY'}\n"; | |
2909 | print OPENSSL "$state\n"; | |
2910 | print OPENSSL "$city\n"; | |
2911 | print OPENSSL "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
2912 | print OPENSSL "$ou\n"; | |
2913 | print OPENSSL "$cgiparams{'CERT_NAME'}\n"; | |
2914 | print OPENSSL "$cgiparams{'CERT_EMAIL'}\n"; | |
2915 | print OPENSSL ".\n"; | |
2916 | print OPENSSL ".\n"; | |
2917 | close (OPENSSL); | |
2918 | if ($?) { | |
2919 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2920 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2921 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
2922 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2923 | } |
c6c9630e MT |
2924 | } else { # child |
2925 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
2926 | '-newkey', 'rsa:1024', | |
2927 | '-keyout', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
2928 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
2929 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
2930 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
2931 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2932 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
2933 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2934 | } |
c6c9630e MT |
2935 | } |
2936 | ||
2937 | # Sign the host certificate request | |
2938 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
2939 | '-batch', '-notext', | |
2940 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
2941 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
2942 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
2943 | if ($?) { | |
2944 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2945 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2946 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
2947 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2948 | &newcleanssldatabase(); | |
2949 | goto VPNCONF_ERROR; | |
2950 | } else { | |
2951 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
2952 | &deletebackupcert(); | |
2953 | } | |
2954 | ||
2955 | # Create the pkcs12 file | |
2956 | system('/usr/bin/openssl', 'pkcs12', '-export', | |
2957 | '-inkey', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
2958 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
2959 | '-name', $cgiparams{'NAME'}, | |
2960 | '-passout', "pass:$cgiparams{'CERT_PASS1'}", | |
2961 | '-certfile', "${General::swroot}/ovpn/ca/cacert.pem", | |
2962 | '-caname', "$vpnsettings{'ROOTCERT_ORGANIZATION'} CA", | |
2963 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
2964 | if ($?) { | |
2965 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2966 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2967 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2968 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
2969 | goto VPNCONF_ERROR; | |
2970 | } else { | |
2971 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2972 | } | |
2973 | } elsif ($cgiparams{'AUTH'} eq 'cert') { | |
2974 | ;# Nothing, just editing | |
2975 | } else { | |
2976 | $errormessage = $Lang::tr{'invalid input for authentication method'}; | |
2977 | goto VPNCONF_ERROR; | |
2978 | } | |
2979 | ||
2980 | # Check if there is no other entry with this common name | |
2981 | if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk')) { | |
2982 | foreach my $key (keys %confighash) { | |
2983 | if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { | |
2984 | $errormessage = $Lang::tr{'a connection with this common name already exists'}; | |
2985 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2986 | } |
c6c9630e MT |
2987 | } |
2988 | } | |
2989 | ||
2990 | # Save the config | |
2991 | my $key = $cgiparams{'KEY'}; | |
2992 | if (! $key) { | |
2993 | $key = &General::findhasharraykey (\%confighash); | |
2994 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
2995 | } | |
2996 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; | |
2997 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
2998 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { | |
2999 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; | |
3000 | } | |
ce9abb66 | 3001 | $confighash{$key}[3] = $cgiparams{'TYPE'}; |
c6c9630e MT |
3002 | if ($cgiparams{'AUTH'} eq 'psk') { |
3003 | $confighash{$key}[4] = 'psk'; | |
3004 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
3005 | } else { | |
3006 | $confighash{$key}[4] = 'cert'; | |
3007 | } | |
ce9abb66 AH |
3008 | if ($cgiparams{'TYPE'} eq 'net') { |
3009 | $confighash{$key}[6] = $cgiparams{'SIDE'}; | |
3010 | $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'}; | |
3011 | } | |
c6c9630e MT |
3012 | $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'}; |
3013 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; | |
d96c89eb AH |
3014 | $confighash{$key}[23] = $cgiparams{'MSSFIX'}; |
3015 | if ($cgiparams{'FRAGMENT'} eq '') { | |
3016 | $confighash{$key}[24] = '1300'; | |
3017 | } else { | |
3018 | $confighash{$key}[24] = $cgiparams{'FRAGMENT'}; | |
3019 | } | |
c6c9630e MT |
3020 | $confighash{$key}[25] = $cgiparams{'REMARK'}; |
3021 | $confighash{$key}[26] = $cgiparams{'INTERFACE'}; | |
3022 | # new fields | |
3023 | $confighash{$key}[27] = $cgiparams{'OVPN_SUBNET'}; | |
3024 | $confighash{$key}[28] = $cgiparams{'PROTOCOL'}; | |
3025 | $confighash{$key}[29] = $cgiparams{'DEST_PORT'}; | |
3026 | $confighash{$key}[30] = $cgiparams{'COMPLZO'}; | |
3027 | $confighash{$key}[31] = $cgiparams{'MTU'}; | |
3028 | # new fileds | |
3029 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
18837a6a AH |
3030 | |
3031 | ### | |
3032 | # m.a.d n2n begin | |
3033 | ### | |
3034 | ||
3035 | if ($cgiparams{'TYPE'} eq 'net') { | |
3036 | ||
3037 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
3038 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
3039 | ||
3040 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3041 | my $key = $cgiparams{'KEY'}; | |
3042 | if (! $key) { | |
3043 | $key = &General::findhasharraykey (\%confighash); | |
3044 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
3045 | } | |
3046 | $confighash{$key}[0] = 'on'; | |
3047 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3048 | ||
3049 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
3050 | } | |
3051 | } | |
3052 | ||
3053 | ### | |
3054 | # m.a.d n2n end | |
3055 | ### | |
3056 | ||
c6c9630e MT |
3057 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { |
3058 | $cgiparams{'KEY'} = $key; | |
3059 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
3060 | } | |
3061 | goto VPNCONF_END; | |
6e13d0a5 | 3062 | } else { |
c6c9630e MT |
3063 | $cgiparams{'ENABLED'} = 'on'; |
3064 | $cgiparams{'SIDE'} = 'left'; | |
3065 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { | |
3066 | $cgiparams{'AUTH'} = 'psk'; | |
3067 | } elsif ( ! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
3068 | $cgiparams{'AUTH'} = 'certfile'; | |
3069 | } else { | |
6e13d0a5 | 3070 | $cgiparams{'AUTH'} = 'certgen'; |
c6c9630e MT |
3071 | } |
3072 | $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}"; | |
3073 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
3074 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
3075 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
3076 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
6e13d0a5 | 3077 | } |
c6c9630e | 3078 | |
6e13d0a5 | 3079 | VPNCONF_ERROR: |
6e13d0a5 MT |
3080 | $checked{'ENABLED'}{'off'} = ''; |
3081 | $checked{'ENABLED'}{'on'} = ''; | |
3082 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
3083 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
3084 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
3085 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
3086 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
3087 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
3088 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
3089 | |
3090 | ||
6e13d0a5 MT |
3091 | $checked{'EDIT_ADVANCED'}{'off'} = ''; |
3092 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
3093 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = 'CHECKED'; | |
c6c9630e | 3094 | |
6e13d0a5 MT |
3095 | $selected{'SIDE'}{'server'} = ''; |
3096 | $selected{'SIDE'}{'client'} = ''; | |
3097 | $selected{'SIDE'}{$cgiparams{'SIDE'}} = 'SELECTED'; | |
d96c89eb AH |
3098 | |
3099 | $selected{'PROTOCOL'}{'udp'} = ''; | |
3100 | $selected{'PROTOCOL'}{'tcp'} = ''; | |
3101 | $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED'; | |
3102 | ||
c6c9630e | 3103 | |
6e13d0a5 MT |
3104 | $checked{'AUTH'}{'psk'} = ''; |
3105 | $checked{'AUTH'}{'certreq'} = ''; | |
3106 | $checked{'AUTH'}{'certgen'} = ''; | |
3107 | $checked{'AUTH'}{'certfile'} = ''; | |
3108 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = 'CHECKED'; | |
c6c9630e | 3109 | |
6e13d0a5 | 3110 | $selected{'INTERFACE'}{$cgiparams{'INTERFACE'}} = 'SELECTED'; |
c6c9630e | 3111 | |
6e13d0a5 MT |
3112 | $checked{'COMPLZO'}{'off'} = ''; |
3113 | $checked{'COMPLZO'}{'on'} = ''; | |
3114 | $checked{'COMPLZO'}{$cgiparams{'COMPLZO'}} = 'CHECKED'; | |
c6c9630e | 3115 | |
d96c89eb AH |
3116 | $checked{'MSSFIX'}{'off'} = ''; |
3117 | $checked{'MSSFIX'}{'on'} = ''; | |
3118 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
3119 | ||
6e13d0a5 MT |
3120 | |
3121 | if (1) { | |
3122 | &Header::showhttpheaders(); | |
3123 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
3124 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
3125 | if ($errormessage) { | |
3126 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
3127 | print "<class name='base'>$errormessage"; | |
3128 | print " </class>"; | |
3129 | &Header::closebox(); | |
3130 | } | |
c6c9630e | 3131 | |
6e13d0a5 MT |
3132 | if ($warnmessage) { |
3133 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:"); | |
3134 | print "<class name='base'>$warnmessage"; | |
3135 | print " </class>"; | |
3136 | &Header::closebox(); | |
3137 | } | |
c6c9630e | 3138 | |
6e13d0a5 | 3139 | print "<form method='post' enctype='multipart/form-data'>"; |
ce9abb66 | 3140 | print "<input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />"; |
c6c9630e | 3141 | |
6e13d0a5 MT |
3142 | if ($cgiparams{'KEY'}) { |
3143 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
3144 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
6e13d0a5 | 3145 | } |
c6c9630e | 3146 | |
6e13d0a5 MT |
3147 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'connection'}:"); |
3148 | print "<table width='100%'>\n"; | |
3149 | print "<tr><td width='25%' class='boldbase'>$Lang::tr{'name'}:</td>"; | |
ce9abb66 | 3150 | if ($cgiparams{'TYPE'} eq 'host') { |
6e13d0a5 MT |
3151 | if ($cgiparams{'KEY'}) { |
3152 | print "<td width='35%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>\n"; | |
3153 | } else { | |
3154 | print "<td width='35%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' size='30' /></td>"; | |
3155 | } | |
c6c9630e MT |
3156 | # print "<tr><td>$Lang::tr{'interface'}</td>"; |
3157 | # print "<td><select name='INTERFACE'>"; | |
3158 | # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>"; | |
3159 | # if ($netsettings{'BLUE_DEV'} ne '') { | |
3160 | # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>"; | |
3161 | # } | |
3162 | # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>"; | |
3163 | # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>"; | |
3164 | # print "</select></td></tr>"; | |
3165 | # print <<END | |
ce9abb66 AH |
3166 | } else { |
3167 | print "<input type='hidden' name='INTERFACE' value='red' />"; | |
3168 | if ($cgiparams{'KEY'}) { | |
3169 | print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
3170 | } else { | |
3171 | print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' /></td>"; | |
3172 | } | |
3173 | print <<END | |
3174 | <td width='25%'> </td> | |
3175 | <td width='25%'> </td></tr> | |
3176 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td> | |
3177 | <td><select name='SIDE'><option value='server' $selected{'SIDE'}{'server'}>OpenVPN Server</option> | |
3178 | <option value='client' $selected{'SIDE'}{'client'}>OpenVPN Client</option></select></td> | |
3179 | <td class='boldbase'>$Lang::tr{'remote host/ip'}:</td> | |
3180 | <td><input type='TEXT' name='REMOTE' value='$cgiparams{'REMOTE'}' /></td></tr> | |
3181 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td> | |
3182 | <td><input type='TEXT' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' /></td> | |
3183 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td> | |
3184 | <td><input type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' /></td></tr> | |
3185 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td> | |
3186 | <td><input type='TEXT' name='OVPN_SUBNET' value='$cgiparams{'OVPN_SUBNET'}' /></td></tr> | |
3187 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> | |
d96c89eb AH |
3188 | |
3189 | <td><select name='PROTOCOL'><option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option> | |
3190 | <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option></select></td> | |
3191 | ||
3192 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
ce9abb66 | 3193 | <td><input type='TEXT' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td></tr> |
d96c89eb | 3194 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'} <img src='/blob.gif'</td> |
ce9abb66 | 3195 | <td><input type='checkbox' name='COMPLZO' $checked{'COMPLZO'}{'on'} /></td> |
d96c89eb AH |
3196 | |
3197 | <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td> | |
3198 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
3199 | ||
3200 | <tr><td class='boldbase' nowrap='nowrap'>Fragment <img src='/blob.gif' /></td> | |
3201 | <td><input type='TEXT' name='FRAGMENT' VALUE='$cgiparams{'FRAGMENT'}'size='5' /></td> | |
3202 | <td>Default: <span class="base">1300</span></td> | |
3203 | ||
ce9abb66 AH |
3204 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} <img src='/blob.gif' /></td> |
3205 | <td> <input type='TEXT' name='MTU' VALUE='$cgiparams{'MTU'}'size='5' /></TD> | |
ce9abb66 AH |
3206 | |
3207 | END | |
3208 | ; | |
3209 | } | |
d96c89eb | 3210 | |
6e13d0a5 MT |
3211 | print "<tr><td class='boldbase'>$Lang::tr{'remark title'} <img src='/blob.gif' /></td>"; |
3212 | print "<td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td></tr>"; | |
c6c9630e | 3213 | |
ce9abb66 AH |
3214 | if ($cgiparams{'TYPE'} eq 'host') { |
3215 | ||
3216 | print "<tr><td>$Lang::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>\n"; | |
3217 | } | |
3218 | ||
c6c9630e MT |
3219 | # if ($cgiparams{'KEY'}) { |
3220 | # print "<td colspan='3'> </td></tr></table>"; | |
3221 | # } else { | |
3222 | # print "<td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked{'EDIT_ADVANCED'}{'on'} /> $Lang::tr{'edit advanced settings when done'}</tr></table>"; | |
3223 | # } | |
3224 | # }else{ | |
6e13d0a5 | 3225 | print "<td colspan='3'> </td></tr></table>"; |
c6c9630e MT |
3226 | # } |
3227 | ||
6e13d0a5 MT |
3228 | |
3229 | ||
3230 | &Header::closebox(); | |
c6c9630e | 3231 | |
6e13d0a5 | 3232 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { |
c6c9630e MT |
3233 | # &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); |
3234 | # print <<END | |
3235 | # <table width='100%' cellpadding='0' cellspacing='5' border='0'> | |
3236 | # <tr><td class='base' width='50%'>$Lang::tr{'use a pre-shared key'}</td> | |
3237 | # <td class='base' width='50%'><input type='text' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td></tr> | |
3238 | # </table> | |
3239 | END | |
3240 | # ; | |
3241 | # &Header::closebox(); | |
6e13d0a5 MT |
3242 | } elsif (! $cgiparams{'KEY'}) { |
3243 | my $disabled=''; | |
3244 | my $cakeydisabled=''; | |
3245 | my $cacrtdisabled=''; | |
3246 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" }; | |
3247 | if ( ! -f "${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" }; | |
3248 | &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); | |
ce9abb66 AH |
3249 | |
3250 | ||
3251 | if ($cgiparams{'TYPE'} eq 'host') { | |
3252 | ||
3253 | print <<END | |
6e13d0a5 MT |
3254 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
3255 | <tr><td colspan='3' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr> | |
ce9abb66 AH |
3256 | <tr><td><input type='radio' name='AUTH' value='certreq' $checked{'AUTH'}{'certreq'} $cakeydisabled /></td><td class='base'>$Lang::tr{'upload a certificate request'}</td><td class='base' rowspan='2'><input type='file' name='FH' size='30' $cacrtdisabled></td></tr> |
3257 | <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'>$Lang::tr{'upload a certificate'}</td></tr> | |
6e13d0a5 | 3258 | <tr><td colspan='3' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' BORDER='0' /></td></tr> |
ce9abb66 AH |
3259 | <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'>$Lang::tr{'generate a certificate'}</td><td> </td></tr> |
3260 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> | |
3261 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
3262 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
3263 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
3264 | <tr><td> </td><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
3265 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
3266 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
6e13d0a5 | 3267 | END |
ce9abb66 AH |
3268 | ; |
3269 | ||
3270 | ### | |
7c1d9faf | 3271 | # m.a.d net2net |
ce9abb66 AH |
3272 | ### |
3273 | ||
3274 | } else { | |
3275 | ||
3276 | print <<END | |
3277 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> | |
3278 | ||
3279 | <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'>$Lang::tr{'generate a certificate'}</td><td> </td></tr> | |
3280 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> | |
3281 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
3282 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
3283 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
3284 | <tr><td> </td><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif'></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
3285 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
3286 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
3287 | ||
3288 | END | |
3289 | ; | |
3290 | ||
3291 | } | |
3292 | ||
3293 | ### | |
7c1d9faf | 3294 | # m.a.d net2net |
ce9abb66 | 3295 | ### |
c6c9630e | 3296 | |
6e13d0a5 MT |
3297 | foreach my $country (sort keys %{Countries::countries}) { |
3298 | print "<option value='$Countries::countries{$country}'"; | |
3299 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
3300 | print " selected='selected'"; | |
3301 | } | |
3302 | print ">$country</option>"; | |
3303 | } | |
ce9abb66 | 3304 | ### |
7c1d9faf | 3305 | # m.a.d net2net |
ce9abb66 AH |
3306 | ### |
3307 | ||
3308 | if ($cgiparams{'TYPE'} eq 'host') { | |
6e13d0a5 MT |
3309 | print <<END |
3310 | </select></td></tr> | |
ce9abb66 AH |
3311 | |
3312 | <td class='base'>$Lang::tr{'valid till'} (days):</td> | |
3313 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> | |
3314 | <tr><td> </td> | |
6e13d0a5 MT |
3315 | <td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
3316 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
3317 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'}:<BR>($Lang::tr{'confirmation'})</td> | |
3318 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> | |
ce9abb66 AH |
3319 | </table> |
3320 | END | |
3321 | }else{ | |
3322 | print <<END | |
3323 | </select></td></tr> | |
3324 | <tr><td> </td><td> </td><td> </td></tr> | |
3325 | <tr><td> </td><td> </td><td> </td></tr> | |
3326 | </table> | |
3327 | ||
c6c9630e | 3328 | END |
ce9abb66 AH |
3329 | } |
3330 | ||
3331 | ### | |
7c1d9faf | 3332 | # m.a.d net2net |
ce9abb66 | 3333 | ### |
c6c9630e MT |
3334 | ; |
3335 | &Header::closebox(); | |
3336 | } | |
6e13d0a5 | 3337 | |
c6c9630e MT |
3338 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
3339 | if ($cgiparams{'KEY'}) { | |
3340 | # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
3341 | } | |
3342 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
3343 | &Header::closebigbox(); | |
3344 | &Header::closepage(); | |
3345 | exit (0); | |
6e13d0a5 | 3346 | } |
c6c9630e | 3347 | VPNCONF_END: |
6e13d0a5 | 3348 | } |
c6c9630e MT |
3349 | |
3350 | # SETTINGS_ERROR: | |
6e13d0a5 MT |
3351 | ### |
3352 | ### Default status page | |
3353 | ### | |
c6c9630e MT |
3354 | %cgiparams = (); |
3355 | %cahash = (); | |
3356 | %confighash = (); | |
3357 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
3358 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
3359 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3360 | ||
4e17adad | 3361 | my @status = `/bin/cat /var/log/ovpnserver.log`; |
c6c9630e MT |
3362 | |
3363 | if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") { | |
6e13d0a5 MT |
3364 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { |
3365 | my $ipaddr = <IPADDR>; | |
3366 | close IPADDR; | |
3367 | chomp ($ipaddr); | |
3368 | $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
3369 | if ($cgiparams{'VPN_IP'} eq '') { | |
c6c9630e | 3370 | $cgiparams{'VPN_IP'} = $ipaddr; |
6e13d0a5 MT |
3371 | } |
3372 | } | |
c6c9630e MT |
3373 | } |
3374 | ||
6e13d0a5 | 3375 | #default setzen |
c6c9630e | 3376 | if ($cgiparams{'DCIPHER'} eq '') { |
6e13d0a5 | 3377 | $cgiparams{'DCIPHER'} = 'BF-CBC'; |
c6c9630e | 3378 | } |
6e13d0a5 MT |
3379 | # if ($cgiparams{'DCOMPLZO'} eq '') { |
3380 | # $cgiparams{'DCOMPLZO'} = 'on'; | |
3381 | # } | |
c6c9630e | 3382 | if ($cgiparams{'DDEST_PORT'} eq '') { |
6e13d0a5 | 3383 | $cgiparams{'DDEST_PORT'} = '1194'; |
c6c9630e MT |
3384 | } |
3385 | if ($cgiparams{'DMTU'} eq '') { | |
6e13d0a5 | 3386 | $cgiparams{'DMTU'} = '1400'; |
c6c9630e MT |
3387 | } |
3388 | if ($cgiparams{'DOVPN_SUBNET'} eq '') { | |
6e13d0a5 | 3389 | $cgiparams{'DOVPN_SUBNET'} = '10.' . int(rand(256)) . '.' . int(rand(256)) . '.0/255.255.255.0'; |
c6c9630e MT |
3390 | } |
3391 | ||
3392 | $checked{'ENABLED'}{'off'} = ''; | |
3393 | $checked{'ENABLED'}{'on'} = ''; | |
3394 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
3395 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
3396 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
3397 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
3398 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
3399 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
3400 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
3401 | $selected{'DDEVICE'}{'tun'} = ''; |
3402 | $selected{'DDEVICE'}{'tap'} = ''; | |
3403 | $selected{'DDEVICE'}{$cgiparams{'DDEVICE'}} = 'SELECTED'; | |
3404 | ||
3405 | $selected{'DPROTOCOL'}{'udp'} = ''; | |
3406 | $selected{'DPROTOCOL'}{'tcp'} = ''; | |
3407 | $selected{'DPROTOCOL'}{$cgiparams{'DPROTOCOL'}} = 'SELECTED'; | |
3408 | ||
3409 | $selected{'DCIPHER'}{'DES-CBC'} = ''; | |
3410 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
3411 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; | |
3412 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
3413 | $selected{'DCIPHER'}{'RC2-CBC'} = ''; | |
3414 | $selected{'DCIPHER'}{'RC2-40-CBC'} = ''; | |
3415 | $selected{'DCIPHER'}{'RC2-64-CBC'} = ''; | |
3416 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
3417 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
3418 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
3419 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
3420 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
3421 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; | |
3422 | $checked{'DCOMPLZO'}{'off'} = ''; | |
3423 | $checked{'DCOMPLZO'}{'on'} = ''; | |
3424 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
d96c89eb AH |
3425 | # m.a.d |
3426 | $checked{'MSSFIX'}{'off'} = ''; | |
3427 | $checked{'MSSFIX'}{'on'} = ''; | |
3428 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 | 3429 | #new settings |
c6c9630e MT |
3430 | &Header::showhttpheaders(); |
3431 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
3432 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
6e13d0a5 | 3433 | |
c6c9630e | 3434 | if ($errormessage) { |
6e13d0a5 MT |
3435 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
3436 | print "<class name='base'>$errormessage\n"; | |
3437 | print " </class>\n"; | |
3438 | &Header::closebox(); | |
c6c9630e | 3439 | } |
6e13d0a5 | 3440 | |
c6c9630e MT |
3441 | my $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'stopped'}</font></b></td></tr></table>"; |
3442 | my $srunning = "no"; | |
3443 | my $activeonrun = ""; | |
3444 | if ( -e "/var/run/openvpn.pid"){ | |
6e13d0a5 MT |
3445 | $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'running'}</font></b></td></tr></table>"; |
3446 | $srunning ="yes"; | |
3447 | $activeonrun = ""; | |
c6c9630e | 3448 | } else { |
6e13d0a5 | 3449 | $activeonrun = "disabled='disabled'"; |
c6c9630e | 3450 | } |
afabe9f7 | 3451 | &Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'}); |
c6c9630e MT |
3452 | print <<END |
3453 | <table width='100%'> | |
3454 | <form method='post'> | |
3455 | <td width='25%'> </td> | |
3456 | <td width='25%'> </td> | |
3457 | <td width='25%'> </td></tr> | |
3458 | <tr><td class='boldbase'>$Lang::tr{'ovpn server status'}</td> | |
3459 | <td align='left'>$sactive</td> | |
3460 | <tr><td class='boldbase'>$Lang::tr{'ovpn on red'}</td> | |
3461 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> | |
3462 | END | |
3463 | ; | |
3464 | if (&haveBlueNet()) { | |
3465 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on blue'}</td>"; | |
3466 | print "<td><input type='checkbox' name='ENABLED_BLUE' $checked{'ENABLED_BLUE'}{'on'} /></td>"; | |
3467 | } | |
3468 | if (&haveOrangeNet()) { | |
3469 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on orange'}</td>"; | |
3470 | print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked{'ENABLED_ORANGE'}{'on'} /></td>"; | |
3471 | } | |
3472 | print <<END | |
4e17adad CS |
3473 | <tr><td class='base' nowrap='nowrap' colspan='2'>$Lang::tr{'local vpn hostname/ip'}:<br /><input type='text' name='VPN_IP' value='$cgiparams{'VPN_IP'}' size='30' /></td> |
3474 | <td class='boldbase' nowrap='nowrap' colspan='2'>$Lang::tr{'ovpn subnet'}<br /><input type='TEXT' name='DOVPN_SUBNET' value='$cgiparams{'DOVPN_SUBNET'}' size='30' /></td></tr> | |
c6c9630e MT |
3475 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn device'}</td> |
3476 | <td><select name='DDEVICE' ><option value='tun' $selected{'DDEVICE'}{'tun'}>TUN</option> | |
ee79343e JPT |
3477 | <!-- this is still not working |
3478 | <option value='tap' $selected{'DDEVICE'}{'tap'}>TAP</option></select>--> </td> | |
c6c9630e MT |
3479 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
3480 | <td><select name='DPROTOCOL'><option value='udp' $selected{'DPROTOCOL'}{'udp'}>UDP</option> | |
3481 | <option value='tcp' $selected{'DPROTOCOL'}{'tcp'}>TCP</option></select></td> | |
3482 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
3483 | <td><input type='TEXT' name='DDEST_PORT' value='$cgiparams{'DDEST_PORT'}' size='5' /></td></tr> | |
3484 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} </td> | |
3485 | <td> <input type='TEXT' name='DMTU' VALUE='$cgiparams{'DMTU'}'size='5' /></TD> | |
3486 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> | |
3487 | <td><input type='checkbox' name='DCOMPLZO' $checked{'DCOMPLZO'}{'on'} /></td> | |
3488 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td> | |
3489 | <td><select name='DCIPHER'><option value='DES-CBC' $selected{'DCIPHER'}{'DES-CBC'}>DES-CBC</option> | |
3490 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC</option> | |
3491 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC</option> | |
3492 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC</option> | |
3493 | <option value='RC2-CBC' $selected{'DCIPHER'}{'RC2-CBC'}>RC2-CBC</option> | |
3494 | <option value='RC2-40-CBC' $selected{'DCIPHER'}{'RC2-40-CBC'}>RC2-40-CBC</option> | |
3495 | <option value='RC2-64-CBC' $selected{'DCIPHER'}{'RC2-64-CBC'}>RC2-64-CBC</option> | |
3496 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC</option> | |
3497 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC</option> | |
3498 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-128-CBC</option> | |
3499 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-192-CBC</option> | |
3500 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-256-CBC</option></select></td> | |
3501 | END | |
3502 | ; | |
3503 | ||
3504 | if ( $srunning eq "yes" ) { | |
3505 | print "<tr><td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' disabled='disabled' /></td>"; | |
3506 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' disabled='disabled'/></td>"; | |
3507 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'stop ovpn server'}' /></td>"; | |
3508 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'restart ovpn server'}' /></td></tr>"; | |
3509 | } else{ | |
3510 | print "<tr><td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>"; | |
3511 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' /></td>"; | |
3512 | if (( -e "${General::swroot}/ovpn/ca/cacert.pem" && | |
3513 | -e "${General::swroot}/ovpn/ca/dh1024.pem" && | |
3514 | -e "${General::swroot}/ovpn/certs/servercert.pem" && | |
3515 | -e "${General::swroot}/ovpn/certs/serverkey.pem") && | |
3516 | (( $cgiparams{'ENABLED'} eq 'on') || | |
3517 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
3518 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on'))){ | |
3519 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' /></td>"; | |
3520 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'restart ovpn server'}' /></td></tr>"; | |
3521 | } else { | |
3522 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' disabled='disabled' /></td>"; | |
3523 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'restart ovpn server'}' disabled='disabled' /></td></tr>"; | |
3524 | } | |
3525 | } | |
3526 | print "</form></table>"; | |
3527 | &Header::closebox(); | |
3528 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate authorities'}:"); | |
3529 | print <<EOF#' | |
3530 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
3531 | <tr> | |
3532 | <td width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></td> | |
6e13d0a5 MT |
3533 | <td width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></td> |
3534 | <td width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td> | |
c6c9630e | 3535 | </tr> |
6e13d0a5 MT |
3536 | EOF |
3537 | ; | |
c6c9630e | 3538 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { |
6e13d0a5 MT |
3539 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; |
3540 | $casubject =~ /Subject: (.*)[\n]/; | |
3541 | $casubject = $1; | |
3542 | $casubject =~ s+/Email+, E+; | |
3543 | $casubject =~ s/ ST=/ S=/; | |
c6c9630e | 3544 | |
6e13d0a5 | 3545 | print <<END |
4e17adad | 3546 | <tr bgcolor='$color{'color22'}'> |
c6c9630e MT |
3547 | <td class='base'>$Lang::tr{'root certificate'}</td> |
3548 | <td class='base'>$casubject</td> | |
3549 | <form method='post' name='frmrootcrta'><td width='3%' align='center'> | |
3550 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> | |
3551 | <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show root certificate'}' title='$Lang::tr{'show root certificate'}' width='20' height='20' border='0' /> | |
3552 | </td></form> | |
3553 | <form method='post' name='frmrootcrtb'><td width='3%' align='center'> | |
438dd0cc | 3554 | <input type='image' name='$Lang::tr{'download root certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download root certificate'}' title='$Lang::tr{'download root certificate'}' border='0' /> |
6e13d0a5 | 3555 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> |
c6c9630e MT |
3556 | </td></form> |
3557 | <td width='4%'> </td></tr> | |
6e13d0a5 MT |
3558 | END |
3559 | ; | |
c6c9630e | 3560 | } else { |
6e13d0a5 MT |
3561 | # display rootcert generation buttons |
3562 | print <<END | |
4e17adad | 3563 | <tr bgcolor='$color{'color22'}'> |
6e13d0a5 MT |
3564 | <td class='base'>$Lang::tr{'root certificate'}:</td> |
3565 | <td class='base'>$Lang::tr{'not present'}</td> | |
3566 | <td colspan='3'> </td></tr> | |
3567 | END | |
3568 | ; | |
c6c9630e | 3569 | } |
6e13d0a5 | 3570 | |
c6c9630e | 3571 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { |
6e13d0a5 MT |
3572 | my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; |
3573 | $hostsubject =~ /Subject: (.*)[\n]/; | |
3574 | $hostsubject = $1; | |
3575 | $hostsubject =~ s+/Email+, E+; | |
3576 | $hostsubject =~ s/ ST=/ S=/; | |
c6c9630e | 3577 | |
6e13d0a5 | 3578 | print <<END |
4e17adad | 3579 | <tr bgcolor='$color{'color20'}'> |
6e13d0a5 MT |
3580 | <td class='base'>$Lang::tr{'host certificate'}</td> |
3581 | <td class='base'>$hostsubject</td> | |
3582 | <form method='post' name='frmhostcrta'><td width='3%' align='center'> | |
c6c9630e MT |
3583 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> |
3584 | <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'}' width='20' height='20' border='0' /> | |
6e13d0a5 MT |
3585 | </td></form> |
3586 | <form method='post' name='frmhostcrtb'><td width='3%' align='center'> | |
438dd0cc | 3587 | <input type='image' name='$Lang::tr{'download host certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download host certificate'}' title='$Lang::tr{'download host certificate'}' border='0' /> |
c6c9630e | 3588 | <input type='hidden' name='ACTION' value='$Lang::tr{'download host certificate'}' /> |
6e13d0a5 MT |
3589 | </td></form> |
3590 | <td width='4%'> </td></tr> | |
3591 | END | |
3592 | ; | |
c6c9630e | 3593 | } else { |
6e13d0a5 MT |
3594 | # Nothing |
3595 | print <<END | |
4e17adad | 3596 | <tr bgcolor='$color{'color20'}'> |
6e13d0a5 MT |
3597 | <td width='25%' class='base'>$Lang::tr{'host certificate'}:</td> |
3598 | <td class='base'>$Lang::tr{'not present'}</td> | |
3599 | </td><td colspan='3'> </td></tr> | |
3600 | END | |
3601 | ; | |
c6c9630e | 3602 | } |
6e13d0a5 | 3603 | |
c6c9630e MT |
3604 | if (! -f "${General::swroot}/ovpn/ca/cacert.pem") { |
3605 | print "<tr><td colspan='5' align='center'><form method='post'>"; | |
6e13d0a5 | 3606 | print "<input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' />"; |
c6c9630e MT |
3607 | print "</form></td></tr>\n"; |
3608 | } | |
6e13d0a5 | 3609 | |
c6c9630e | 3610 | if (keys %cahash > 0) { |
6e13d0a5 | 3611 | foreach my $key (keys %cahash) { |
c6c9630e | 3612 | if (($key + 1) % 2) { |
4e17adad | 3613 | print "<tr bgcolor='$color{'color20'}'>\n"; |
c6c9630e | 3614 | } else { |
4e17adad | 3615 | print "<tr bgcolor='$color{'color22'}'>\n"; |
c6c9630e MT |
3616 | } |
3617 | print "<td class='base'>$cahash{$key}[0]</td>\n"; | |
3618 | print "<td class='base'>$cahash{$key}[1]</td>\n"; | |
3619 | print <<END | |
3620 | <form method='post' name='cafrm${key}a'><td align='center'> | |
6e13d0a5 MT |
3621 | <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'}' border='0' /> |
3622 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
3623 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
3624 | </td></form> |
3625 | <form method='post' name='cafrm${key}b'><td align='center'> | |
438dd0cc | 3626 | <input type='image' name='$Lang::tr{'download ca certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download ca certificate'}' title='$Lang::tr{'download ca certificate'}' border='0' /> |
6e13d0a5 MT |
3627 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> |
3628 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
3629 | </td></form> |
3630 | <form method='post' name='cafrm${key}c'><td align='center'> | |
6e13d0a5 MT |
3631 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> |
3632 | <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'}' width='20' height='20' border='0' /> | |
3633 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e | 3634 | </td></form></tr> |
6e13d0a5 MT |
3635 | END |
3636 | ; | |
3637 | } | |
c6c9630e MT |
3638 | } |
3639 | ||
3640 | print "</table>"; | |
3641 | ||
3642 | # If the file contains entries, print Key to action icons | |
3643 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
3644 | print <<END | |
3645 | <table> | |
3646 | <tr> | |
6e13d0a5 MT |
3647 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> |
3648 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
3649 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
438dd0cc | 3650 | <td> <img src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' /></td> |
6e13d0a5 | 3651 | <td class='base'>$Lang::tr{'download certificate'}</td> |
c6c9630e MT |
3652 | </tr> |
3653 | </table> | |
6e13d0a5 MT |
3654 | END |
3655 | ; | |
c6c9630e MT |
3656 | } |
3657 | print <<END | |
3658 | <form method='post' enctype='multipart/form-data'> | |
3659 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
3660 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'ca name'}:</td> | |
3661 | <td nowrap='nowrap'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' /> | |
3662 | <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td> | |
4e17adad | 3663 | <td nowrap='nowrap'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}' /><br /><input type='submit' name='ACTION' value='$Lang::tr{'show crl'}' /></td> |
c6c9630e | 3664 | </tr></table></form> |
6e13d0a5 MT |
3665 | END |
3666 | ; | |
c6c9630e MT |
3667 | |
3668 | &Header::closebox(); | |
3669 | if ( $srunning eq "yes" ) { | |
6e13d0a5 | 3670 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' disabled='disabled' /></div></form>\n"; |
c6c9630e MT |
3671 | }else{ |
3672 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /></div></form>\n"; | |
3673 | } | |
3674 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
ce9abb66 AH |
3675 | |
3676 | ### | |
7c1d9faf | 3677 | # m.a.d net2net |
ce9abb66 AH |
3678 | ### |
3679 | ||
c6c9630e MT |
3680 | &Header::openbox('100%', 'LEFT', $Lang::tr{'Client status and controlc' }); |
3681 | print <<END | |
ce9abb66 AH |
3682 | |
3683 | ||
c6c9630e MT |
3684 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> |
3685 | <tr> | |
3686 | <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></td> | |
3687 | <td width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></td> | |
3688 | <td width='18%' class='boldbase' align='center'><b>$Lang::tr{'common name'}</b></td> | |
3689 | <td width='17%' class='boldbase' align='center'><b>$Lang::tr{'valid till'}</b></td> | |
3690 | <td width='25%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b><br /><img src='/images/null.gif' width='125' height='1' border='0' alt='L2089' /></td> | |
3691 | <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></td> | |
3692 | <td width='5%' class='boldbase' colspan='6' align='center'><b>$Lang::tr{'action'}</b></td> | |
3693 | </tr> | |
6e13d0a5 | 3694 | END |
c6c9630e MT |
3695 | ; |
3696 | my $id = 0; | |
3697 | my $gif; | |
3698 | foreach my $key (keys %confighash) { | |
3699 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } | |
3700 | ||
3701 | if ($id % 2) { | |
4e17adad | 3702 | print "<tr bgcolor='$color{'color20'}'>\n"; |
bb89e92a | 3703 | } else { |
4e17adad | 3704 | print "<tr bgcolor='$color{'color22'}'>\n"; |
c6c9630e MT |
3705 | } |
3706 | print "<td align='center' nowrap='nowrap'>$confighash{$key}[1]</td>"; | |
3707 | print "<td align='center' nowrap='nowrap'>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>"; | |
3708 | if ($confighash{$key}[4] eq 'cert') { | |
3709 | print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>"; | |
3710 | } else { | |
3711 | print "<td align='left'> </td>"; | |
3712 | } | |
3713 | my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
3714 | $cavalid =~ /Not After : (.*)[\n]/; | |
3715 | $cavalid = $1; | |
3716 | print "<td align='center'>$cavalid</td>"; | |
3717 | print "<td align='center'>$confighash{$key}[25]</td>"; | |
ce9abb66 | 3718 | |
c6c9630e | 3719 | 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>"; |
ce9abb66 | 3720 | |
c6c9630e MT |
3721 | if ($confighash{$key}[0] eq 'off') { |
3722 | $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>"; | |
3723 | } else { | |
ce9abb66 AH |
3724 | |
3725 | ### | |
7c1d9faf | 3726 | # m.a.d net2net |
b278daf3 AH |
3727 | ### |
3728 | ||
3729 | if ($confighash{$key}[3] eq 'net') { | |
18837a6a AH |
3730 | # my @tempovpnsubnet = split("\/",$confighash{$key}[27]); |
3731 | # my @ovpnip = split /\./,$tempovpnsubnet[0]; | |
3732 | # my $pingip = ""; | |
3733 | # if ($confighash{$key}[6] eq 'server') { | |
3734 | # $pingip = "$ovpnip[0].$ovpnip[1].$ovpnip[2].2"; | |
3735 | # } else { | |
3736 | # $pingip = "$ovpnip[0].$ovpnip[1].$ovpnip[2].1"; | |
3737 | # } | |
3738 | # my $p = Net::Ping->new("udp",1); | |
3739 | # if ($p->ping($pingip)) { | |
3740 | # $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>"; | |
3741 | # } | |
3742 | # $p->close(); | |
3743 | ||
3744 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
3745 | $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>"; | |
3746 | } | |
3747 | } | |
b278daf3 AH |
3748 | |
3749 | my $cn; | |
3750 | my @match = (); | |
3751 | foreach my $line (@status) { | |
3752 | chomp($line); | |
3753 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
3754 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
3755 | if ($match[1] ne "Common Name") { | |
3756 | $cn = $match[1]; | |
3757 | } | |
3758 | $cn =~ s/[_]/ /g; | |
3759 | if ($cn eq "$confighash{$key}[2]") { | |
3760 | $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>"; | |
3761 | } | |
3762 | ||
3763 | ||
c6c9630e | 3764 | } |
7c1d9faf AH |
3765 | } |
3766 | } | |
ce9abb66 AH |
3767 | |
3768 | ||
c6c9630e MT |
3769 | my $disable_clientdl = "disabled='disabled'"; |
3770 | if (( $cgiparams{'ENABLED'} eq 'on') || | |
3771 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
3772 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on')){ | |
3773 | $disable_clientdl = ""; | |
3774 | } | |
3775 | print <<END | |
3776 | <td align='center'>$active</td> | |
3777 | ||
3778 | <form method='post' name='frm${key}a'><td align='center'> | |
3779 | <input type='image' name='$Lang::tr{'dl client arch'}' $disable_clientdl src='/images/openvpn.png' alt='$Lang::tr{'dl client arch'}' title='$Lang::tr{'dl client arch'}' border='0' /> | |
3780 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' $disable_clientdl /> | |
3781 | <input type='hidden' name='KEY' value='$key' $disable_clientdl /> | |
3782 | </td></form> | |
3783 | END | |
3784 | ; | |
3785 | if ($confighash{$key}[4] eq 'cert') { | |
3786 | print <<END | |
3787 | <form method='post' name='frm${key}b'><td align='center'> | |
3788 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' border='0' /> | |
3789 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> | |
3790 | <input type='hidden' name='KEY' value='$key' /> | |
3791 | </td></form> | |
3792 | END | |
3793 | ; } else { | |
3794 | print "<td> </td>"; | |
3795 | } | |
3796 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$key}[1].p12") { | |
3797 | print <<END | |
3798 | <form method='post' name='frm${key}c'><td align='center'> | |
438dd0cc | 3799 | <input type='image' name='$Lang::tr{'download pkcs12 file'}' src='/images/media-floppy.png' alt='$Lang::tr{'download pkcs12 file'}' title='$Lang::tr{'download pkcs12 file'}' border='0' /> |
c6c9630e MT |
3800 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> |
3801 | <input type='hidden' name='KEY' value='$key' /> | |
3802 | </td></form> | |
3803 | END | |
3804 | ; } elsif ($confighash{$key}[4] eq 'cert') { | |
3805 | print <<END | |
3806 | <form method='post' name='frm${key}c'><td align='center'> | |
438dd0cc | 3807 | <input type='image' name='$Lang::tr{'download certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' title='$Lang::tr{'download certificate'}' border='0' /> |
c6c9630e MT |
3808 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> |
3809 | <input type='hidden' name='KEY' value='$key' /> | |
3810 | </td></form> | |
3811 | END | |
3812 | ; } else { | |
3813 | print "<td> </td>"; | |
3814 | } | |
3815 | print <<END | |
3816 | <form method='post' name='frm${key}d'><td align='center'> | |
3817 | <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' border='0' /> | |
3818 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
3819 | <input type='hidden' name='KEY' value='$key' /> | |
3820 | </td></form> | |
3821 | ||
3822 | <form method='post' name='frm${key}e'><td align='center'> | |
3823 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> | |
3824 | <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' width='20' height='20' border='0'/> | |
3825 | <input type='hidden' name='KEY' value='$key' /> | |
3826 | </td></form> | |
3827 | <form method='post' name='frm${key}f'><td align='center'> | |
3828 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> | |
3829 | <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' width='20' height='20' border='0' /> | |
3830 | <input type='hidden' name='KEY' value='$key' /> | |
3831 | </td></form> | |
3832 | </tr> | |
3833 | END | |
3834 | ; | |
3835 | $id++; | |
3836 | } | |
3837 | ; | |
3838 | ||
3839 | # If the config file contains entries, print Key to action icons | |
3840 | if ( $id ) { | |
3841 | print <<END | |
3842 | <table> | |
3843 | <tr> | |
3844 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
3845 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
3846 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
3847 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
3848 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
3849 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
3850 | <td class='base'>$Lang::tr{'edit'}</td> | |
3851 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
3852 | <td class='base'>$Lang::tr{'remove'}</td> | |
3853 | </tr> | |
3854 | <tr> | |
3855 | <td> </td> | |
3856 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
3857 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
aa7eb426 | 3858 | <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td> |
c6c9630e | 3859 | <td class='base'>$Lang::tr{'download certificate'}</td> |
aa7eb426 | 3860 | <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td> |
c6c9630e MT |
3861 | <td class='base'>$Lang::tr{'dl client arch'}</td> |
3862 | </tr> | |
3863 | </table> | |
3864 | END | |
3865 | ; | |
3866 | } | |
3867 | ||
3868 | print <<END | |
3869 | <table width='100%'> | |
3870 | <form method='post'> | |
3871 | <tr><td width='50%' ><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td> | |
3872 | <td width='50%' ><input type='submit' name='ACTION' value='$Lang::tr{'ovpn con stat'}' $activeonrun /></td></tr> | |
3873 | </form> | |
3874 | </table> | |
3875 | END | |
3876 | ; | |
3877 | &Header::closebox(); | |
bb89e92a | 3878 | } |
115340d2 | 3879 | &Header::closepage(); |
ce9abb66 AH |
3880 | |
3881 | ||
3882 |