Merge branch 'fifteen' of ssh://git.ipfire.org/pub/git/ipfire-2.x into fifteen
[people/teissler/ipfire-2.x.git] / html / cgi-bin / ovpnmain.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2013 IPFire Team <info@ipfire.org> #
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 ###############################################################################
21 ###
22 # Based on IPFireCore 55
23 ###
24 use CGI;
25 use CGI qw/:standard/;
26 use Net::DNS;
27 use Net::Ping;
28 use Net::Telnet;
29 use File::Copy;
30 use File::Temp qw/ tempfile tempdir /;
31 use strict;
32 use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
33 use Sort::Naturally;
34 require '/var/ipfire/general-functions.pl';
35 require "${General::swroot}/lang.pl";
36 require "${General::swroot}/header.pl";
37 require "${General::swroot}/countries.pl";
38
39 # enable only the following on debugging purpose
40 #use warnings;
41 #use CGI::Carp 'fatalsToBrowser';
42 #workaround to suppress a warning when a variable is used only once
43 my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} );
44 undef (@dummy);
45
46 my %color = ();
47 my %mainsettings = ();
48 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
49 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
50
51 ###
52 ### Initialize variables
53 ###
54 my %ccdconfhash=();
55 my %ccdroutehash=();
56 my %ccdroute2hash=();
57 my %netsettings=();
58 my %cgiparams=();
59 my %vpnsettings=();
60 my %checked=();
61 my %confighash=();
62 my %cahash=();
63 my %selected=();
64 my $warnmessage = '';
65 my $errormessage = '';
66 my %settings=();
67 my $routes_push_file = '';
68 my $confighost="${General::swroot}/fwhosts/customhosts";
69 my $configgrp="${General::swroot}/fwhosts/customgroups";
70 my $customnet="${General::swroot}/fwhosts/customnetworks";
71 my $name;
72 my $col="";
73 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
74 $cgiparams{'ENABLED'} = 'off';
75 $cgiparams{'ENABLED_BLUE'} = 'off';
76 $cgiparams{'ENABLED_ORANGE'} = 'off';
77 $cgiparams{'EDIT_ADVANCED'} = 'off';
78 $cgiparams{'NAT'} = 'off';
79 $cgiparams{'COMPRESSION'} = 'off';
80 $cgiparams{'ONLY_PROPOSED'} = 'off';
81 $cgiparams{'ACTION'} = '';
82 $cgiparams{'CA_NAME'} = '';
83 $cgiparams{'DHCP_DOMAIN'} = '';
84 $cgiparams{'DHCP_DNS'} = '';
85 $cgiparams{'DHCP_WINS'} = '';
86 $cgiparams{'ROUTES_PUSH'} = '';
87 $cgiparams{'DCOMPLZO'} = 'off';
88 $cgiparams{'MSSFIX'} = '';
89 $cgiparams{'number'} = '';
90 $cgiparams{'PMTU_DISCOVERY'} = '';
91 $routes_push_file = "${General::swroot}/ovpn/routes_push";
92 unless (-e $routes_push_file) { system("touch $routes_push_file"); }
93 unless (-e "${General::swroot}/ovpn/ccd.conf") { system("touch ${General::swroot}/ovpn/ccd.conf"); }
94 unless (-e "${General::swroot}/ovpn/ccdroute") { system("touch ${General::swroot}/ovpn/ccdroute"); }
95 unless (-e "${General::swroot}/ovpn/ccdroute2") { system("touch ${General::swroot}/ovpn/ccdroute2"); }
96
97 &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'});
98
99 # prepare openvpn config file
100 ###
101 ### Useful functions
102 ###
103 sub haveOrangeNet
104 {
105 if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;}
106 if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}
107 return 0;
108 }
109
110 sub haveBlueNet
111 {
112 if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;}
113 if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}
114 return 0;
115 }
116
117 sub sizeformat{
118 my $bytesize = shift;
119 my $i = 0;
120
121 while(abs($bytesize) >= 1024){
122 $bytesize=$bytesize/1024;
123 $i++;
124 last if($i==6);
125 }
126
127 my @units = ("Bytes","KB","MB","GB","TB","PB","EB");
128 my $newsize=(int($bytesize*100 +0.5))/100;
129 return("$newsize $units[$i]");
130 }
131
132 sub cleanssldatabase
133 {
134 if (open(FILE, ">${General::swroot}/ovpn/certs/serial")) {
135 print FILE "01";
136 close FILE;
137 }
138 if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt")) {
139 print FILE "";
140 close FILE;
141 }
142 unlink ("${General::swroot}/ovpn/certs/index.txt.old");
143 unlink ("${General::swroot}/ovpn/certs/serial.old");
144 unlink ("${General::swroot}/ovpn/certs/01.pem");
145 }
146
147 sub newcleanssldatabase
148 {
149 if (! -s "${General::swroot}/ovpn/certs/serial" ) {
150 open(FILE, ">${General::swroot}(ovpn/certs/serial");
151 print FILE "01";
152 close FILE;
153 }
154 if (! -s ">${General::swroot}/ovpn/certs/index.txt") {
155 system ("touch ${General::swroot}/ovpn/certs/index.txt");
156 }
157 unlink ("${General::swroot}/ovpn/certs/index.txt.old");
158 unlink ("${General::swroot}/ovpn/certs/serial.old");
159 }
160
161 sub deletebackupcert
162 {
163 if (open(FILE, "${General::swroot}/ovpn/certs/serial.old")) {
164 my $hexvalue = <FILE>;
165 chomp $hexvalue;
166 close FILE;
167 unlink ("${General::swroot}/ovpn/certs/$hexvalue.pem");
168 }
169 }
170 sub checkportfw {
171 my $DPORT = shift;
172 my $DPROT = shift;
173 my %natconfig =();
174 my $confignat = "${General::swroot}/firewall/config";
175 $DPROT= uc ($DPROT);
176 &General::readhasharray($confignat, \%natconfig);
177 foreach my $key (sort keys %natconfig){
178 my @portarray = split (/\|/,$natconfig{$key}[30]);
179 foreach my $value (@portarray){
180 if ($value =~ /:/i){
181 my ($a,$b) = split (":",$value);
182 if ($DPROT eq $natconfig{$key}[12] && $DPORT gt $a && $DPORT lt $b){
183 $errormessage= "$Lang::tr{'source port in use'} $DPORT";
184 }
185 }else{
186 if ($DPROT eq $natconfig{$key}[12] && $DPORT eq $value){
187 $errormessage= "$Lang::tr{'source port in use'} $DPORT";
188 }
189 }
190 }
191 }
192 return;
193 }
194
195 sub checkportoverlap
196 {
197 my $portrange1 = $_[0]; # New port range
198 my $portrange2 = $_[1]; # existing port range
199 my @tempr1 = split(/\:/,$portrange1);
200 my @tempr2 = split(/\:/,$portrange2);
201
202 unless (&checkportinc($tempr1[0], $portrange2)){ return 0;}
203 unless (&checkportinc($tempr1[1], $portrange2)){ return 0;}
204
205 unless (&checkportinc($tempr2[0], $portrange1)){ return 0;}
206 unless (&checkportinc($tempr2[1], $portrange1)){ return 0;}
207
208 return 1; # Everything checks out!
209 }
210
211 # Darren Critchley - we want to make sure that a port entry is not within an already existing range
212 sub checkportinc
213 {
214 my $port1 = $_[0]; # Port
215 my $portrange2 = $_[1]; # Port range
216 my @tempr1 = split(/\:/,$portrange2);
217
218 if ($port1 < $tempr1[0] || $port1 > $tempr1[1]) {
219 return 1;
220 } else {
221 return 0;
222 }
223 }
224
225 # Darren Critchley - certain ports are reserved for IPFire
226 # TCP 67,68,81,222,445
227 # UDP 67,68
228 # Params passed in -> port, rangeyn, protocol
229 sub disallowreserved
230 {
231 # port 67 and 68 same for tcp and udp, don't bother putting in an array
232 my $msg = "";
233 my @tcp_reserved = (81,222,445);
234 my $prt = $_[0]; # the port or range
235 my $ryn = $_[1]; # tells us whether or not it is a port range
236 my $prot = $_[2]; # protocol
237 my $srcdst = $_[3]; # source or destination
238 if ($ryn) { # disect port range
239 if ($srcdst eq "src") {
240 $msg = "$Lang::tr{'rsvd src port overlap'}";
241 } else {
242 $msg = "$Lang::tr{'rsvd dst port overlap'}";
243 }
244 my @tmprng = split(/\:/,$prt);
245 unless (67 < $tmprng[0] || 67 > $tmprng[1]) { $errormessage="$msg 67"; return; }
246 unless (68 < $tmprng[0] || 68 > $tmprng[1]) { $errormessage="$msg 68"; return; }
247 if ($prot eq "tcp") {
248 foreach my $prange (@tcp_reserved) {
249 unless ($prange < $tmprng[0] || $prange > $tmprng[1]) { $errormessage="$msg $prange"; return; }
250 }
251 }
252 } else {
253 if ($srcdst eq "src") {
254 $msg = "$Lang::tr{'reserved src port'}";
255 } else {
256 $msg = "$Lang::tr{'reserved dst port'}";
257 }
258 if ($prt == 67) { $errormessage="$msg 67"; return; }
259 if ($prt == 68) { $errormessage="$msg 68"; return; }
260 if ($prot eq "tcp") {
261 foreach my $prange (@tcp_reserved) {
262 if ($prange == $prt) { $errormessage="$msg $prange"; return; }
263 }
264 }
265 }
266 return;
267 }
268
269 sub writeserverconf {
270 my %sovpnsettings = ();
271 my @temp = ();
272 &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings);
273 &read_routepushfile;
274
275 open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!";
276 flock CONF, 2;
277 print CONF "#OpenVPN Server conf\n";
278 print CONF "\n";
279 print CONF "daemon openvpnserver\n";
280 print CONF "writepid /var/run/openvpn.pid\n";
281 print CONF "#DAN prepare OpenVPN for listening on blue and orange\n";
282 print CONF ";local $sovpnsettings{'VPN_IP'}\n";
283 print CONF "dev $sovpnsettings{'DDEVICE'}\n";
284 print CONF "proto $sovpnsettings{'DPROTOCOL'}\n";
285 print CONF "port $sovpnsettings{'DDEST_PORT'}\n";
286 print CONF "script-security 3 system\n";
287 print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n";
288 print CONF "client-config-dir /var/ipfire/ovpn/ccd\n";
289 print CONF "tls-server\n";
290 print CONF "ca /var/ipfire/ovpn/ca/cacert.pem\n";
291 print CONF "cert /var/ipfire/ovpn/certs/servercert.pem\n";
292 print CONF "key /var/ipfire/ovpn/certs/serverkey.pem\n";
293 print CONF "dh /var/ipfire/ovpn/ca/dh1024.pem\n";
294 my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'});
295 print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n";
296 #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n";
297
298 # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500.
299 # If we doesn't use one of them, we can use the configured mtu value.
300 if ($sovpnsettings{'MSSFIX'} eq 'on')
301 { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; }
302 elsif ($sovpnsettings{'FRAGMENT'} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp')
303 { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; }
304 elsif (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
305 ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
306 ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' ))
307 { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; }
308 else
309 { print CONF "$sovpnsettings{'DDEVICE'}-mtu $sovpnsettings{'DMTU'}\n"; }
310
311 if ($vpnsettings{'ROUTES_PUSH'} ne '') {
312 @temp = split(/\n/,$vpnsettings{'ROUTES_PUSH'});
313 foreach (@temp)
314 {
315 @tempovpnsubnet = split("\/",&General::ipcidr2msk($_));
316 print CONF "push \"route " . $tempovpnsubnet[0]. " " . $tempovpnsubnet[1] . "\"\n";
317 }
318 }
319 # a.marx ccd
320 my %ccdconfhash=();
321 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
322 foreach my $key (keys %ccdconfhash) {
323 my $a=$ccdconfhash{$key}[1];
324 my ($b,$c) = split (/\//, $a);
325 print CONF "route $b ".&General::cidrtosub($c)."\n";
326 }
327 my %ccdroutehash=();
328 &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
329 foreach my $key (keys %ccdroutehash) {
330 foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){
331 my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]);
332 print CONF "route $a $b\n";
333 }
334 }
335 # ccd end
336
337 if ($sovpnsettings{CLIENT2CLIENT} eq 'on') {
338 print CONF "client-to-client\n";
339 }
340 if ($sovpnsettings{MSSFIX} eq 'on') {
341 print CONF "mssfix\n";
342 }
343 if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') {
344 print CONF "fragment $sovpnsettings{'FRAGMENT'}\n";
345 }
346
347 # Check if a valid operating mode has been choosen and use it.
348 if (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
349 ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
350 ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) {
351 print CONF "mtu-disc $sovpnsettings{'PMTU_DISCOVERY'}\n";
352 }
353
354 if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) {
355 print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n";
356 }
357 print CONF "status-version 1\n";
358 print CONF "status /var/log/ovpnserver.log 30\n";
359 print CONF "cipher $sovpnsettings{DCIPHER}\n";
360 if ($sovpnsettings{DCOMPLZO} eq 'on') {
361 print CONF "comp-lzo\n";
362 }
363 if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') {
364 print CONF "push \"redirect-gateway def1\"\n";
365 }
366 if ($sovpnsettings{DHCP_DOMAIN} ne '') {
367 print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n";
368 }
369
370 if ($sovpnsettings{DHCP_DNS} ne '') {
371 print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n";
372 }
373
374 if ($sovpnsettings{DHCP_WINS} ne '') {
375 print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n";
376 }
377
378 if ($sovpnsettings{DHCP_WINS} eq '') {
379 print CONF "max-clients 100\n";
380 }
381 if ($sovpnsettings{DHCP_WINS} ne '') {
382 print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n";
383 }
384 print CONF "tls-verify /usr/lib/openvpn/verify\n";
385 print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n";
386 print CONF "user nobody\n";
387 print CONF "group nobody\n";
388 print CONF "persist-key\n";
389 print CONF "persist-tun\n";
390 if ($sovpnsettings{LOG_VERB} ne '') {
391 print CONF "verb $sovpnsettings{LOG_VERB}\n";
392 } else {
393 print CONF "verb 3\n";
394 }
395 print CONF "\n";
396
397 close(CONF);
398 }
399
400 sub emptyserverlog{
401 if (open(FILE, ">/var/log/ovpnserver.log")) {
402 flock FILE, 2;
403 print FILE "";
404 close FILE;
405 }
406
407 }
408
409 sub delccdnet
410 {
411 my %ccdconfhash = ();
412 my %ccdhash = ();
413 my $ccdnetname=$_[0];
414 if (-f "${General::swroot}/ovpn/ovpnconfig"){
415 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
416 foreach my $key (keys %ccdhash) {
417 if ($ccdhash{$key}[32] eq $ccdnetname) {
418 $errormessage=$Lang::tr{'ccd err hostinnet'};
419 return;
420 }
421 }
422 }
423 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
424 foreach my $key (keys %ccdconfhash) {
425 if ($ccdconfhash{$key}[0] eq $ccdnetname){
426 delete $ccdconfhash{$key};
427 }
428 }
429 &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
430
431 &writeserverconf;
432 return 0;
433 }
434
435 sub addccdnet
436 {
437 my %ccdconfhash=();
438 my @ccdconf=();
439 my $ccdname=$_[0];
440 my $ccdnet=$_[1];
441 my $subcidr;
442 my @ip2=();
443 my $checkup;
444 my $ccdip;
445 my $baseaddress;
446
447
448 #check name
449 if ($ccdname eq '')
450 {
451 $errormessage=$errormessage.$Lang::tr{'ccd err name'}."<br>";
452 return
453 }
454
455 if(!&General::validhostname($ccdname))
456 {
457 $errormessage=$Lang::tr{'ccd err invalidname'};
458 return;
459 }
460
461 ($ccdip,$subcidr) = split (/\//,$ccdnet);
462 $subcidr=&General::iporsubtocidr($subcidr);
463 #check subnet
464 if ($subcidr > 30)
465 {
466 $errormessage=$Lang::tr{'ccd err invalidnet'};
467 return;
468 }
469 #check ip
470 if (!&General::validipandmask($ccdnet)){
471 $errormessage=$Lang::tr{'ccd err invalidnet'};
472 return;
473 }
474
475 $errormessage=&General::checksubnets($ccdname,$ccdnet);
476
477
478 if (!$errormessage) {
479 my %ccdconfhash=();
480 $baseaddress=&General::getnetworkip($ccdip,$subcidr);
481 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
482 my $key = &General::findhasharraykey (\%ccdconfhash);
483 foreach my $i (0 .. 1) { $ccdconfhash{$key}[$i] = "";}
484 $ccdconfhash{$key}[0] = $ccdname;
485 $ccdconfhash{$key}[1] = $baseaddress."/".$subcidr;
486 &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
487 &writeserverconf;
488 $cgiparams{'ccdname'}='';
489 $cgiparams{'ccdsubnet'}='';
490 return 1;
491 }
492 }
493
494 sub modccdnet
495 {
496
497 my $newname=$_[0];
498 my $oldname=$_[1];
499 my %ccdconfhash=();
500 my %ccdhash=();
501 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
502 foreach my $key (keys %ccdconfhash) {
503 if ($ccdconfhash{$key}[0] eq $oldname) {
504 foreach my $key1 (keys %ccdconfhash) {
505 if ($ccdconfhash{$key1}[0] eq $newname){
506 $errormessage=$errormessage.$Lang::tr{'ccd err netadrexist'};
507 return;
508 }else{
509 $ccdconfhash{$key}[0]= $newname;
510 &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
511 last;
512 }
513 }
514 }
515 }
516
517 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
518 foreach my $key (keys %ccdhash) {
519 if ($ccdhash{$key}[32] eq $oldname) {
520 $ccdhash{$key}[32]=$newname;
521 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
522 last;
523 }
524 }
525
526 return 0;
527 }
528 sub ccdmaxclients
529 {
530 my $ccdnetwork=$_[0];
531 my @octets=();
532 my @subnet=();
533 @octets=split("\/",$ccdnetwork);
534 @subnet= split /\./, &General::cidrtosub($octets[1]);
535 my ($a,$b,$c,$d,$e);
536 $a=256-$subnet[0];
537 $b=256-$subnet[1];
538 $c=256-$subnet[2];
539 $d=256-$subnet[3];
540 $e=($a*$b*$c*$d)/4;
541 return $e-1;
542 }
543
544 sub getccdadresses
545 {
546 my $ipin=$_[0];
547 my ($ip1,$ip2,$ip3,$ip4)=split /\./, $ipin;
548 my $cidr=$_[1];
549 chomp($cidr);
550 my $count=$_[2];
551 my $hasip=$_[3];
552 chomp($hasip);
553 my @iprange=();
554 my %ccdhash=();
555 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
556 $iprange[0]=$ip1.".".$ip2.".".$ip3.".".2;
557 for (my $i=1;$i<=$count;$i++) {
558 my $tmpip=$iprange[$i-1];
559 my $stepper=$i*4;
560 $iprange[$i]= &General::getnextip($tmpip,4);
561 }
562 my $r=0;
563 foreach my $key (keys %ccdhash) {
564 $r=0;
565 foreach my $tmp (@iprange){
566 my ($net,$sub) = split (/\//,$ccdhash{$key}[33]);
567 if ($net eq $tmp) {
568 if ( $hasip ne $ccdhash{$key}[33] ){
569 splice (@iprange,$r,1);
570 }
571 }
572 $r++;
573 }
574 }
575 return @iprange;
576 }
577
578 sub fillselectbox
579 {
580 my $boxname=$_[1];
581 my ($ccdip,$subcidr) = split("/",$_[0]);
582 my $tz=$_[2];
583 my @allccdips=&getccdadresses($ccdip,$subcidr,&ccdmaxclients($ccdip."/".$subcidr),$tz);
584 print"<select name='$boxname' STYLE='font-family : arial; font-size : 9pt; width:130px;' >";
585 foreach (@allccdips) {
586 my $ip=$_."/30";
587 chomp($ip);
588 print "<option value='$ip' ";
589 if ( $ip eq $cgiparams{$boxname} ){
590 print"selected";
591 }
592 print ">$ip</option>";
593 }
594 print "</select>";
595 }
596
597 sub hostsinnet
598 {
599 my $name=$_[0];
600 my %ccdhash=();
601 my $i=0;
602 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
603 foreach my $key (keys %ccdhash) {
604 if ($ccdhash{$key}[32] eq $name){ $i++;}
605 }
606 return $i;
607 }
608
609 sub check_routes_push
610 {
611 my $val=$_[0];
612 my ($ip,$cidr) = split (/\//, $val);
613 ##check for existing routes in routes_push
614 if (-e "${General::swroot}/ovpn/routes_push") {
615 open(FILE,"${General::swroot}/ovpn/routes_push");
616 while (<FILE>) {
617 $_=~s/\s*$//g;
618
619 my ($ip2,$cidr2) = split (/\//,"$_");
620 my $val2=$ip2."/".&General::iporsubtodec($cidr2);
621
622 if($val eq $val2){
623 return 0;
624 }
625 #subnetcheck
626 if (&General::IpInSubnet ($ip,$ip2,&General::iporsubtodec($cidr2))){
627 return 0;
628 }
629 };
630 close(FILE);
631 }
632 return 1;
633 }
634
635 sub check_ccdroute
636 {
637 my %ccdroutehash=();
638 my $val=$_[0];
639 my ($ip,$cidr) = split (/\//, $val);
640 #check for existing routes in ccdroute
641 &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
642 foreach my $key (keys %ccdroutehash) {
643 foreach my $i (1 .. $#{$ccdroutehash{$key}}) {
644 if (&General::iporsubtodec($val) eq $ccdroutehash{$key}[$i] && $ccdroutehash{$key}[0] ne $cgiparams{'NAME'}){
645 return 0;
646 }
647 my ($ip2,$cidr2) = split (/\//,$ccdroutehash{$key}[$i]);
648 #subnetcheck
649 if (&General::IpInSubnet ($ip,$ip2,$cidr2)&& $ccdroutehash{$key}[0] ne $cgiparams{'NAME'} ){
650 return 0;
651 }
652 }
653 }
654 return 1;
655 }
656 sub check_ccdconf
657 {
658 my %ccdconfhash=();
659 my $val=$_[0];
660 my ($ip,$cidr) = split (/\//, $val);
661 #check for existing routes in ccdroute
662 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
663 foreach my $key (keys %ccdconfhash) {
664 if (&General::iporsubtocidr($val) eq $ccdconfhash{$key}[1]){
665 return 0;
666 }
667 my ($ip2,$cidr2) = split (/\//,$ccdconfhash{$key}[1]);
668 #subnetcheck
669 if (&General::IpInSubnet ($ip,$ip2,&General::cidrtosub($cidr2))){
670 return 0;
671 }
672
673 }
674 return 1;
675 }
676
677 ###
678 # m.a.d net2net
679 ###
680
681 sub validdotmask
682 {
683 my $ipdotmask = $_[0];
684 if (&General::validip($ipdotmask)) { return 0; }
685 if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { }
686 my $mask = $2;
687 if (($mask =~ /\./ )) { return 0; }
688 return 1;
689 }
690
691 # -------------------------------------------------------------------
692
693 sub write_routepushfile
694 {
695 open(FILE, ">$routes_push_file");
696 flock(FILE, 2);
697 if ($vpnsettings{'ROUTES_PUSH'} ne '') {
698 print FILE $vpnsettings{'ROUTES_PUSH'};
699 }
700 close(FILE);
701 }
702
703 sub read_routepushfile
704 {
705 if (-e "$routes_push_file") {
706 open(FILE,"$routes_push_file");
707 delete $vpnsettings{'ROUTES_PUSH'};
708 while (<FILE>) { $vpnsettings{'ROUTES_PUSH'} .= $_ };
709 close(FILE);
710 $cgiparams{'ROUTES_PUSH'} = $vpnsettings{'ROUTES_PUSH'};
711
712 }
713 }
714
715
716 #hier die refresh page
717 if ( -e "${General::swroot}/ovpn/gencanow") {
718 my $refresh = '';
719 $refresh = "<meta http-equiv='refresh' content='15;' />";
720 &Header::showhttpheaders();
721 &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh);
722 &Header::openbigbox('100%', 'center');
723 &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:");
724 print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n";
725 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n";
726 &Header::closebox();
727 &Header::closebigbox();
728 &Header::closepage();
729 exit (0);
730 }
731 ##hier die refresh page
732
733
734 ###
735 ### OpenVPN Server Control
736 ###
737 if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} ||
738 $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} ||
739 $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) {
740 #start openvpn server
741 if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){
742 &emptyserverlog();
743 system('/usr/local/bin/openvpnctrl', '-s');
744 }
745 #stop openvpn server
746 if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){
747 system('/usr/local/bin/openvpnctrl', '-k');
748 &emptyserverlog();
749 }
750 # #restart openvpn server
751 # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){
752 #workarund, till SIGHUP also works when running as nobody
753 # system('/usr/local/bin/openvpnctrl', '-r');
754 # &emptyserverlog();
755 # }
756 }
757
758 ###
759 ### Save Advanced options
760 ###
761
762 if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) {
763 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
764 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
765 #DAN this value has to leave.
766 #new settings for daemon
767 $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'};
768 $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'};
769 $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'};
770 $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'};
771 $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'};
772 $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'};
773 $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'};
774 $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'};
775 $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'};
776 $vpnsettings{'ROUTES_PUSH'} = $cgiparams{'ROUTES_PUSH'};
777 $vpnsettings{'PMTU_DISCOVERY'} = $cgiparams{'PMTU_DISCOVERY'};
778 my @temp=();
779
780 if ($cgiparams{'FRAGMENT'} eq '') {
781 delete $vpnsettings{'FRAGMENT'};
782 } else {
783 if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) {
784 $errormessage = "Incorrect value, please insert only numbers.";
785 goto ADV_ERROR;
786 } else {
787 $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'};
788 }
789 }
790 if ($cgiparams{'MSSFIX'} ne 'on') {
791 delete $vpnsettings{'MSSFIX'};
792 } else {
793 $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'};
794 }
795
796 if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') ||
797 ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') ||
798 ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) {
799
800 if (($cgiparams{'MSSFIX'} eq 'on') || ($cgiparams{'FRAGMENT'} ne '')) {
801 $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'};
802 goto ADV_ERROR;
803 }
804 }
805
806 if ($cgiparams{'DHCP_DOMAIN'} ne ''){
807 unless (&General::validdomainname($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) {
808 $errormessage = $Lang::tr{'invalid input for dhcp domain'};
809 goto ADV_ERROR;
810 }
811 }
812 if ($cgiparams{'DHCP_DNS'} ne ''){
813 unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) {
814 $errormessage = $Lang::tr{'invalid input for dhcp dns'};
815 goto ADV_ERROR;
816 }
817 }
818 if ($cgiparams{'DHCP_WINS'} ne ''){
819 unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) {
820 $errormessage = $Lang::tr{'invalid input for dhcp wins'};
821 goto ADV_ERROR;
822 }
823 }
824 if ($cgiparams{'ROUTES_PUSH'} ne ''){
825 @temp = split(/\n/,$cgiparams{'ROUTES_PUSH'});
826 undef $vpnsettings{'ROUTES_PUSH'};
827
828 foreach my $tmpip (@temp)
829 {
830 s/^\s+//g; s/\s+$//g;
831
832 if ($tmpip)
833 {
834 $tmpip=~s/\s*$//g;
835 unless (&General::validipandmask($tmpip)) {
836 $errormessage = "$tmpip ".$Lang::tr{'ovpn errmsg invalid ip or mask'};
837 goto ADV_ERROR;
838 }
839 my ($ip, $cidr) = split("\/",&General::ipcidr2msk($tmpip));
840
841 if ($ip eq $netsettings{'GREEN_NETADDRESS'} && $cidr eq $netsettings{'GREEN_NETMASK'}) {
842 $errormessage = $Lang::tr{'ovpn errmsg green already pushed'};
843 goto ADV_ERROR;
844 }
845 # a.marx ccd
846 my %ccdroutehash=();
847 &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
848 foreach my $key (keys %ccdroutehash) {
849 foreach my $i (1 .. $#{$ccdroutehash{$key}}) {
850 if ( $ip."/".$cidr eq $ccdroutehash{$key}[$i] ){
851 $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ;
852 goto ADV_ERROR;
853 }
854 my ($ip2,$cidr2) = split(/\//,$ccdroutehash{$key}[$i]);
855 if (&General::IpInSubnet ($ip,$ip2,$cidr2)){
856 $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ;
857 goto ADV_ERROR;
858 }
859 }
860 }
861
862 # ccd end
863
864 $vpnsettings{'ROUTES_PUSH'} .= $tmpip."\n";
865 }
866 }
867 &write_routepushfile;
868 undef $vpnsettings{'ROUTES_PUSH'};
869 }
870 else {
871 undef $vpnsettings{'ROUTES_PUSH'};
872 &write_routepushfile;
873 }
874 if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 255 )) {
875 $errormessage = $Lang::tr{'invalid input for max clients'};
876 goto ADV_ERROR;
877 }
878 if ($cgiparams{'KEEPALIVE_1'} ne '') {
879 if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) {
880 $errormessage = $Lang::tr{'invalid input for keepalive 1'};
881 goto ADV_ERROR;
882 }
883 }
884 if ($cgiparams{'KEEPALIVE_2'} ne ''){
885 if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) {
886 $errormessage = $Lang::tr{'invalid input for keepalive 2'};
887 goto ADV_ERROR;
888 }
889 }
890 if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){
891 $errormessage = $Lang::tr{'invalid input for keepalive 1:2'};
892 goto ADV_ERROR;
893 }
894
895 &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings);
896 &writeserverconf();#hier ok
897 }
898
899 ###
900 # m.a.d net2net
901 ###
902
903 if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server')
904 {
905
906 my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'});
907 my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'});
908 my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]";
909 my $tunmtu = '';
910
911 unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";}
912 unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";}
913
914 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: $!";
915
916 flock SERVERCONF, 2;
917 print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n";
918 print SERVERCONF "\n";
919 print SERVERCONF "# User Security\n";
920 print SERVERCONF "user nobody\n";
921 print SERVERCONF "group nobody\n";
922 print SERVERCONF "persist-tun\n";
923 print SERVERCONF "persist-key\n";
924 print SERVERCONF "script-security 2\n";
925 print SERVERCONF "# IP/DNS for remote Server Gateway\n";
926
927 if ($cgiparams{'REMOTE'} ne '') {
928 print SERVERCONF "remote $cgiparams{'REMOTE'}\n";
929 }
930
931 print SERVERCONF "float\n";
932 print SERVERCONF "# IP adresses of the VPN Subnet\n";
933 print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n";
934 print SERVERCONF "# Client Gateway Network\n";
935 print SERVERCONF "route $remsubnet[0] $remsubnet[1]\n";
936 print SERVERCONF "# tun Device\n";
937 print SERVERCONF "dev tun\n";
938 print SERVERCONF "# Port and Protokol\n";
939 print SERVERCONF "port $cgiparams{'DEST_PORT'}\n";
940
941 if ($cgiparams{'PROTOCOL'} eq 'tcp') {
942 print SERVERCONF "proto tcp-server\n";
943 print SERVERCONF "# Packet size\n";
944 if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}};
945 print SERVERCONF "tun-mtu $tunmtu\n";
946 }
947
948 if ($cgiparams{'PROTOCOL'} eq 'udp') {
949 print SERVERCONF "proto udp\n";
950 print SERVERCONF "# Paketsize\n";
951 if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}};
952 print SERVERCONF "tun-mtu $tunmtu\n";
953 if ($cgiparams{'FRAGMENT'} ne '') {print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n";}
954 if ($cgiparams{'MSSFIX'} eq 'on') {print SERVERCONF "mssfix\n"; };
955 }
956
957 # Check if a valid operating mode has been choosen and use it.
958 if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') ||
959 ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') ||
960 ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) {
961 if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) {
962 if($cgiparams{'MTU'} eq '1500') {
963 print SERVERCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n";
964 }
965 }
966 }
967 print SERVERCONF "# Auth. Server\n";
968 print SERVERCONF "tls-server\n";
969 print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n";
970 print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n";
971 print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n";
972 print SERVERCONF "dh ${General::swroot}/ovpn/ca/dh1024.pem\n";
973 print SERVERCONF "# Cipher\n";
974 print SERVERCONF "cipher AES-256-CBC\n";
975 if ($cgiparams{'COMPLZO'} eq 'on') {
976 print SERVERCONF "# Enable Compression\n";
977 print SERVERCONF "comp-lzo\r\n";
978 }
979 print SERVERCONF "# Debug Level\n";
980 print SERVERCONF "verb 3\n";
981 print SERVERCONF "# Tunnel check\n";
982 print SERVERCONF "keepalive 10 60\n";
983 print SERVERCONF "# Start as daemon\n";
984 print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n";
985 print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n";
986 print SERVERCONF "# Activate Management Interface and Port\n";
987 if ($cgiparams{'OVPN_MGMT'} eq '') {print SERVERCONF "management localhost $cgiparams{'DEST_PORT'}\n"}
988 else {print SERVERCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"};
989 close(SERVERCONF);
990
991 }
992
993 ###
994 # m.a.d net2net
995 ###
996
997 if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client')
998 {
999 my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'});
1000 my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]";
1001 my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'});
1002 my $tunmtu = '';
1003
1004 unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";}
1005 unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";}
1006
1007 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: $!";
1008
1009 flock CLIENTCONF, 2;
1010 print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n";
1011 print CLIENTCONF "#\n";
1012 print CLIENTCONF "# User Security\n";
1013 print CLIENTCONF "user nobody\n";
1014 print CLIENTCONF "group nobody\n";
1015 print CLIENTCONF "persist-tun\n";
1016 print CLIENTCONF "persist-key\n";
1017 print CLIENTCONF "script-security 2\n";
1018 print CLIENTCONF "# IP/DNS for remote Server Gateway\n";
1019 print CLIENTCONF "remote $cgiparams{'REMOTE'}\n";
1020 print CLIENTCONF "float\n";
1021 print CLIENTCONF "# IP adresses of the VPN Subnet\n";
1022 print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n";
1023 print CLIENTCONF "# Server Gateway Network\n";
1024 print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n";
1025 print CLIENTCONF "# tun Device\n";
1026 print CLIENTCONF "dev tun\n";
1027 print CLIENTCONF "# Port and Protokol\n";
1028 print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n";
1029
1030 if ($cgiparams{'PROTOCOL'} eq 'tcp') {
1031 print CLIENTCONF "proto tcp-client\n";
1032 print CLIENTCONF "# Packet size\n";
1033 if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}};
1034 print CLIENTCONF "tun-mtu $tunmtu\n";
1035 }
1036
1037 if ($cgiparams{'PROTOCOL'} eq 'udp') {
1038 print CLIENTCONF "proto udp\n";
1039 print CLIENTCONF "# Paketsize\n";
1040 if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}};
1041 print CLIENTCONF "tun-mtu $tunmtu\n";
1042 if ($cgiparams{'FRAGMENT'} ne '') {print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n";}
1043 if ($cgiparams{'MSSFIX'} eq 'on') {print CLIENTCONF "mssfix\n"; };
1044 }
1045
1046 # Check if a valid operating mode has been choosen and use it.
1047 if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') ||
1048 ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') ||
1049 ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) {
1050 if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) {
1051 if ($cgiparams{'MTU'} eq '1500') {
1052 print CLIENTCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n";
1053 }
1054 }
1055 }
1056
1057 print CLIENTCONF "ns-cert-type server\n";
1058 print CLIENTCONF "# Auth. Client\n";
1059 print CLIENTCONF "tls-client\n";
1060 print CLIENTCONF "# Cipher\n";
1061 print CLIENTCONF "cipher AES-256-CBC\n";
1062 print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n";
1063 if ($cgiparams{'COMPLZO'} eq 'on') {
1064 print CLIENTCONF "# Enable Compression\n";
1065 print CLIENTCONF "comp-lzo\r\n";
1066 }
1067 print CLIENTCONF "# Debug Level\n";
1068 print CLIENTCONF "verb 3\n";
1069 print CLIENTCONF "# Tunnel check\n";
1070 print CLIENTCONF "keepalive 10 60\n";
1071 print CLIENTCONF "# Start as daemon\n";
1072 print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n";
1073 print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n";
1074 print CLIENTCONF "# Activate Management Interface and Port\n";
1075 if ($cgiparams{'OVPN_MGMT'} eq '') {print CLIENTCONF "management localhost $cgiparams{'DEST_PORT'}\n"}
1076 else {print CLIENTCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"};
1077 close(CLIENTCONF);
1078
1079 }
1080
1081 ###
1082 ### Save main settings
1083 ###
1084
1085
1086 if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') {
1087 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
1088 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
1089 #DAN this value has to leave.
1090 if ($cgiparams{'ENABLED'} eq 'on'){
1091 unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) {
1092 $errormessage = $Lang::tr{'invalid input for hostname'};
1093 goto SETTINGS_ERROR;
1094 }
1095 }
1096 if ($cgiparams{'ENABLED'} eq 'on'){
1097 &disallowreserved($cgiparams{'DDEST_PORT'},0,$cgiparams{'DPROTOCOL'},"dest");
1098 }
1099 if ($errormessage) { goto SETTINGS_ERROR; }
1100
1101
1102 if ($cgiparams{'ENABLED'} eq 'on'){
1103 &checkportfw($cgiparams{'DDEST_PORT'},$cgiparams{'DPROTOCOL'});
1104 }
1105
1106 if ($errormessage) { goto SETTINGS_ERROR; }
1107
1108 if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) {
1109 $errormessage = $Lang::tr{'ovpn subnet is invalid'};
1110 goto SETTINGS_ERROR;
1111 }
1112 my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'});
1113
1114 if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'},
1115 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1116 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}";
1117 goto SETTINGS_ERROR;
1118 }
1119
1120 if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'},
1121 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1122 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}";
1123 goto SETTINGS_ERROR;
1124 }
1125
1126 if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'},
1127 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1128 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}";
1129 goto SETTINGS_ERROR;
1130 }
1131
1132 if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'},
1133 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1134 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}";
1135 goto SETTINGS_ERROR;
1136 }
1137 open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.';
1138 while (<ALIASES>)
1139 {
1140 chomp($_);
1141 my @tempalias = split(/\,/,$_);
1142 if ($tempalias[1] eq 'on') {
1143 if (&General::IpInSubnet ($tempalias[0] ,
1144 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1145 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]";
1146 }
1147 }
1148 }
1149 close(ALIASES);
1150 if ($errormessage ne ''){
1151 goto SETTINGS_ERROR;
1152 }
1153 if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) {
1154 $errormessage = $Lang::tr{'invalid input'};
1155 goto SETTINGS_ERROR;
1156 }
1157 if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) {
1158 $errormessage = $Lang::tr{'invalid mtu input'};
1159 goto SETTINGS_ERROR;
1160 }
1161
1162 unless (&General::validport($cgiparams{'DDEST_PORT'})) {
1163 $errormessage = $Lang::tr{'invalid port'};
1164 goto SETTINGS_ERROR;
1165 }
1166
1167 if ($cgiparams{'DDEST_PORT'} <= 1023) {
1168 $errormessage = $Lang::tr{'ovpn port in root range'};
1169 goto SETTINGS_ERROR;
1170 }
1171
1172 $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'};
1173 $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'};
1174 $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'};
1175 $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'};
1176 #new settings for daemon
1177 $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'};
1178 $vpnsettings{'DDEVICE'} = $cgiparams{'DDEVICE'};
1179 $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'};
1180 $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'};
1181 $vpnsettings{'DMTU'} = $cgiparams{'DMTU'};
1182 $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'};
1183 $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'};
1184 #wrtie enable
1185
1186 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");}
1187 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");}
1188 if ( $vpnsettings{'ENABLED'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable 2>/dev/null");}
1189 #new settings for daemon
1190 &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings);
1191 &writeserverconf();#hier ok
1192 SETTINGS_ERROR:
1193 ###
1194 ### Reset all step 2
1195 ###
1196 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'} && $cgiparams{'AREUSURE'} eq 'yes') {
1197 my $file = '';
1198 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1199
1200 foreach my $key (keys %confighash) {
1201 if ($confighash{$key}[4] eq 'cert') {
1202 delete $confighash{$cgiparams{'$key'}};
1203 }
1204 }
1205 while ($file = glob("${General::swroot}/ovpn/ca/*")) {
1206 unlink $file
1207 }
1208 while ($file = glob("${General::swroot}/ovpn/certs/*")) {
1209 unlink $file
1210 }
1211 while ($file = glob("${General::swroot}/ovpn/crls/*")) {
1212 unlink $file
1213 }
1214 &cleanssldatabase();
1215 if (open(FILE, ">${General::swroot}/ovpn/caconfig")) {
1216 print FILE "";
1217 close FILE;
1218 }
1219 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1220 #&writeserverconf();
1221 ###
1222 ### Reset all step 1
1223 ###
1224 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'}) {
1225 &Header::showhttpheaders();
1226 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1227 &Header::openbigbox('100%', 'LEFT', '', '');
1228 &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'});
1229 print <<END
1230 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1231 <tr><td align='center'>
1232 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:
1233 $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
1234 <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' />
1235 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr>
1236 </form></table>
1237 END
1238 ;
1239 &Header::closebox();
1240 &Header::closebigbox();
1241 &Header::closepage();
1242 exit (0);
1243
1244 ###
1245 ### Upload CA Certificate
1246 ###
1247 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) {
1248 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1249
1250 if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) {
1251 $errormessage = $Lang::tr{'name must only contain characters'};
1252 goto UPLOADCA_ERROR;
1253 }
1254
1255 if (length($cgiparams{'CA_NAME'}) >60) {
1256 $errormessage = $Lang::tr{'name too long'};
1257 goto VPNCONF_ERROR;
1258 }
1259
1260 if ($cgiparams{'CA_NAME'} eq 'ca') {
1261 $errormessage = $Lang::tr{'name is invalid'};
1262 goto UPLOAD_CA_ERROR;
1263 }
1264
1265 # Check if there is no other entry with this name
1266 foreach my $key (keys %cahash) {
1267 if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) {
1268 $errormessage = $Lang::tr{'a ca certificate with this name already exists'};
1269 goto UPLOADCA_ERROR;
1270 }
1271 }
1272
1273 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1274 $errormessage = $Lang::tr{'there was no file upload'};
1275 goto UPLOADCA_ERROR;
1276 }
1277 # Move uploaded ca to a temporary file
1278 (my $fh, my $filename) = tempfile( );
1279 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1280 $errormessage = $!;
1281 goto UPLOADCA_ERROR;
1282 }
1283 my $temp = `/usr/bin/openssl x509 -text -in $filename`;
1284 if ($temp !~ /CA:TRUE/i) {
1285 $errormessage = $Lang::tr{'not a valid ca certificate'};
1286 unlink ($filename);
1287 goto UPLOADCA_ERROR;
1288 } else {
1289 move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem");
1290 if ($? ne 0) {
1291 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1292 unlink ($filename);
1293 goto UPLOADCA_ERROR;
1294 }
1295 }
1296
1297 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`;
1298 $casubject =~ /Subject: (.*)[\n]/;
1299 $casubject = $1;
1300 $casubject =~ s+/Email+, E+;
1301 $casubject =~ s/ ST=/ S=/;
1302 $casubject = &Header::cleanhtml($casubject);
1303
1304 my $key = &General::findhasharraykey (\%cahash);
1305 $cahash{$key}[0] = $cgiparams{'CA_NAME'};
1306 $cahash{$key}[1] = $casubject;
1307 &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1308 # system('/usr/local/bin/ipsecctrl', 'R');
1309
1310 UPLOADCA_ERROR:
1311
1312 ###
1313 ### Display ca certificate
1314 ###
1315 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) {
1316 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1317
1318 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") {
1319 &Header::showhttpheaders();
1320 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1321 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
1322 &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:");
1323 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
1324 $output = &Header::cleanhtml($output,"y");
1325 print "<pre>$output</pre>\n";
1326 &Header::closebox();
1327 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
1328 &Header::closebigbox();
1329 &Header::closepage();
1330 exit(0);
1331 } else {
1332 $errormessage = $Lang::tr{'invalid key'};
1333 }
1334
1335 ###
1336 ### Download ca certificate
1337 ###
1338 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) {
1339 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1340
1341 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
1342 print "Content-Type: application/octet-stream\r\n";
1343 print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n";
1344 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
1345 exit(0);
1346 } else {
1347 $errormessage = $Lang::tr{'invalid key'};
1348 }
1349
1350 ###
1351 ### Remove ca certificate (step 2)
1352 ###
1353 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') {
1354 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1355 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1356
1357 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
1358 foreach my $key (keys %confighash) {
1359 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`;
1360 if ($test =~ /: OK/) {
1361 # Delete connection
1362 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1363 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1364 # system('/usr/local/bin/ipsecctrl', 'D', $key);
1365 # }
1366 unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem");
1367 unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12");
1368 delete $confighash{$key};
1369 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1370 # &writeipsecfiles();
1371 }
1372 }
1373 unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem");
1374 delete $cahash{$cgiparams{'KEY'}};
1375 &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1376 # system('/usr/local/bin/ipsecctrl', 'R');
1377 } else {
1378 $errormessage = $Lang::tr{'invalid key'};
1379 }
1380 ###
1381 ### Remove ca certificate (step 1)
1382 ###
1383 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) {
1384 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1385 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1386
1387 my $assignedcerts = 0;
1388 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
1389 foreach my $key (keys %confighash) {
1390 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`;
1391 if ($test =~ /: OK/) {
1392 $assignedcerts++;
1393 }
1394 }
1395 if ($assignedcerts) {
1396 &Header::showhttpheaders();
1397 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1398 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
1399 &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'});
1400 print <<END
1401 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1402 <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />
1403 <tr><td align='center'>
1404 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts
1405 $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1406 <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' />
1407 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr>
1408 </form></table>
1409 END
1410 ;
1411 &Header::closebox();
1412 &Header::closebigbox();
1413 &Header::closepage();
1414 exit (0);
1415 } else {
1416 unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem");
1417 delete $cahash{$cgiparams{'KEY'}};
1418 &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1419 # system('/usr/local/bin/ipsecctrl', 'R');
1420 }
1421 } else {
1422 $errormessage = $Lang::tr{'invalid key'};
1423 }
1424
1425 ###
1426 ### Display root certificate
1427 ###
1428 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} ||
1429 $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) {
1430 my $output;
1431 &Header::showhttpheaders();
1432 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1433 &Header::openbigbox('100%', 'LEFT', '', '');
1434 if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) {
1435 &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:");
1436 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`;
1437 } else {
1438 &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:");
1439 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`;
1440 }
1441 $output = &Header::cleanhtml($output,"y");
1442 print "<pre>$output</pre>\n";
1443 &Header::closebox();
1444 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
1445 &Header::closebigbox();
1446 &Header::closepage();
1447 exit(0);
1448
1449 ###
1450 ### Download root certificate
1451 ###
1452 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) {
1453 if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) {
1454 print "Content-Type: application/octet-stream\r\n";
1455 print "Content-Disposition: filename=cacert.pem\r\n\r\n";
1456 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`;
1457 exit(0);
1458 }
1459
1460 ###
1461 ### Download host certificate
1462 ###
1463 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) {
1464 if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) {
1465 print "Content-Type: application/octet-stream\r\n";
1466 print "Content-Disposition: filename=servercert.pem\r\n\r\n";
1467 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`;
1468 exit(0);
1469 }
1470 ###
1471 ### Form for generating a root certificate
1472 ###
1473 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} ||
1474 $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
1475
1476 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
1477 if (-f "${General::swroot}/ovpn/ca/cacert.pem") {
1478 $errormessage = $Lang::tr{'valid root certificate already exists'};
1479 $cgiparams{'ACTION'} = '';
1480 goto ROOTCERT_ERROR;
1481 }
1482
1483 if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") {
1484 if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) {
1485 my $ipaddr = <IPADDR>;
1486 close IPADDR;
1487 chomp ($ipaddr);
1488 $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
1489 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') {
1490 $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr;
1491 }
1492 }
1493 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
1494
1495 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1496 $errormessage = $Lang::tr{'there was no file upload'};
1497 goto ROOTCERT_ERROR;
1498 }
1499
1500 # Move uploaded certificate request to a temporary file
1501 (my $fh, my $filename) = tempfile( );
1502 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1503 $errormessage = $!;
1504 goto ROOTCERT_ERROR;
1505 }
1506
1507 # Create a temporary dirctory
1508 my $tempdir = tempdir( CLEANUP => 1 );
1509
1510 # Extract the CA certificate from the file
1511 my $pid = open(OPENSSL, "|-");
1512 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1513 if ($pid) { # parent
1514 if ($cgiparams{'P12_PASS'} ne '') {
1515 print OPENSSL "$cgiparams{'P12_PASS'}\n";
1516 }
1517 close (OPENSSL);
1518 if ($?) {
1519 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1520 unlink ($filename);
1521 goto ROOTCERT_ERROR;
1522 }
1523 } else { # child
1524 unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys',
1525 '-in', $filename,
1526 '-out', "$tempdir/cacert.pem")) {
1527 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1528 unlink ($filename);
1529 goto ROOTCERT_ERROR;
1530 }
1531 }
1532
1533 # Extract the Host certificate from the file
1534 $pid = open(OPENSSL, "|-");
1535 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1536 if ($pid) { # parent
1537 if ($cgiparams{'P12_PASS'} ne '') {
1538 print OPENSSL "$cgiparams{'P12_PASS'}\n";
1539 }
1540 close (OPENSSL);
1541 if ($?) {
1542 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1543 unlink ($filename);
1544 goto ROOTCERT_ERROR;
1545 }
1546 } else { # child
1547 unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys',
1548 '-in', $filename,
1549 '-out', "$tempdir/hostcert.pem")) {
1550 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1551 unlink ($filename);
1552 goto ROOTCERT_ERROR;
1553 }
1554 }
1555
1556 # Extract the Host key from the file
1557 $pid = open(OPENSSL, "|-");
1558 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1559 if ($pid) { # parent
1560 if ($cgiparams{'P12_PASS'} ne '') {
1561 print OPENSSL "$cgiparams{'P12_PASS'}\n";
1562 }
1563 close (OPENSSL);
1564 if ($?) {
1565 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1566 unlink ($filename);
1567 goto ROOTCERT_ERROR;
1568 }
1569 } else { # child
1570 unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts',
1571 '-nodes',
1572 '-in', $filename,
1573 '-out', "$tempdir/serverkey.pem")) {
1574 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1575 unlink ($filename);
1576 goto ROOTCERT_ERROR;
1577 }
1578 }
1579
1580 move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem");
1581 if ($? ne 0) {
1582 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1583 unlink ($filename);
1584 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1585 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1586 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1587 goto ROOTCERT_ERROR;
1588 }
1589
1590 move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem");
1591 if ($? ne 0) {
1592 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1593 unlink ($filename);
1594 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1595 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1596 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1597 goto ROOTCERT_ERROR;
1598 }
1599
1600 move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem");
1601 if ($? ne 0) {
1602 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1603 unlink ($filename);
1604 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1605 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1606 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1607 goto ROOTCERT_ERROR;
1608 }
1609
1610 goto ROOTCERT_SUCCESS;
1611
1612 } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') {
1613
1614 # Validate input since the form was submitted
1615 if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){
1616 $errormessage = $Lang::tr{'organization cant be empty'};
1617 goto ROOTCERT_ERROR;
1618 }
1619 if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) {
1620 $errormessage = $Lang::tr{'organization too long'};
1621 goto ROOTCERT_ERROR;
1622 }
1623 if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1624 $errormessage = $Lang::tr{'invalid input for organization'};
1625 goto ROOTCERT_ERROR;
1626 }
1627 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){
1628 $errormessage = $Lang::tr{'hostname cant be empty'};
1629 goto ROOTCERT_ERROR;
1630 }
1631 unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) {
1632 $errormessage = $Lang::tr{'invalid input for hostname'};
1633 goto ROOTCERT_ERROR;
1634 }
1635 if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) {
1636 $errormessage = $Lang::tr{'invalid input for e-mail address'};
1637 goto ROOTCERT_ERROR;
1638 }
1639 if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) {
1640 $errormessage = $Lang::tr{'e-mail address too long'};
1641 goto ROOTCERT_ERROR;
1642 }
1643 if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1644 $errormessage = $Lang::tr{'invalid input for department'};
1645 goto ROOTCERT_ERROR;
1646 }
1647 if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1648 $errormessage = $Lang::tr{'invalid input for city'};
1649 goto ROOTCERT_ERROR;
1650 }
1651 if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1652 $errormessage = $Lang::tr{'invalid input for state or province'};
1653 goto ROOTCERT_ERROR;
1654 }
1655 if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) {
1656 $errormessage = $Lang::tr{'invalid input for country'};
1657 goto ROOTCERT_ERROR;
1658 }
1659
1660 # Copy the cgisettings to vpnsettings and save the configfile
1661 $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'};
1662 $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'};
1663 $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'};
1664 $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'};
1665 $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'};
1666 $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'};
1667 $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'};
1668 &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings);
1669
1670 # Replace empty strings with a .
1671 (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./;
1672 (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./;
1673 (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./;
1674
1675 # refresh
1676 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1677
1678 # Create the CA certificate
1679 my $pid = open(OPENSSL, "|-");
1680 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1681 if ($pid) { # parent
1682 print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n";
1683 print OPENSSL "$state\n";
1684 print OPENSSL "$city\n";
1685 print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
1686 print OPENSSL "$ou\n";
1687 print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n";
1688 print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n";
1689 close (OPENSSL);
1690 if ($?) {
1691 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1692 unlink ("${General::swroot}/ovpn/ca/cakey.pem");
1693 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1694 goto ROOTCERT_ERROR;
1695 }
1696 } else { # child
1697 unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache',
1698 '-days', '999999', '-newkey', 'rsa:2048',
1699 '-keyout', "${General::swroot}/ovpn/ca/cakey.pem",
1700 '-out', "${General::swroot}/ovpn/ca/cacert.pem",
1701 '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) {
1702 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1703 goto ROOTCERT_ERROR;
1704 }
1705 }
1706
1707 # Create the Host certificate request
1708 $pid = open(OPENSSL, "|-");
1709 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1710 if ($pid) { # parent
1711 print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n";
1712 print OPENSSL "$state\n";
1713 print OPENSSL "$city\n";
1714 print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
1715 print OPENSSL "$ou\n";
1716 print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n";
1717 print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n";
1718 print OPENSSL ".\n";
1719 print OPENSSL ".\n";
1720 close (OPENSSL);
1721 if ($?) {
1722 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1723 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1724 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1725 goto ROOTCERT_ERROR;
1726 }
1727 } else { # child
1728 unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache',
1729 '-newkey', 'rsa:1024',
1730 '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem",
1731 '-out', "${General::swroot}/ovpn/certs/serverreq.pem",
1732 '-extensions', 'server',
1733 '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1734 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1735 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1736 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1737 unlink ("${General::swroot}/ovpn/ca/cakey.pem");
1738 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1739 goto ROOTCERT_ERROR;
1740 }
1741 }
1742
1743 # Sign the host certificate request
1744 system('/usr/bin/openssl', 'ca', '-days', '999999',
1745 '-batch', '-notext',
1746 '-in', "${General::swroot}/ovpn/certs/serverreq.pem",
1747 '-out', "${General::swroot}/ovpn/certs/servercert.pem",
1748 '-extensions', 'server',
1749 '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf");
1750 if ($?) {
1751 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1752 unlink ("${General::swroot}/ovpn/ca/cakey.pem");
1753 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1754 unlink ("${General::swroot}/ovpn/serverkey.pem");
1755 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1756 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1757 &newcleanssldatabase();
1758 goto ROOTCERT_ERROR;
1759 } else {
1760 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1761 &deletebackupcert();
1762 }
1763
1764 # Create an empty CRL
1765 system('/usr/bin/openssl', 'ca', '-gencrl',
1766 '-out', "${General::swroot}/ovpn/crls/cacrl.pem",
1767 '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1768 if ($?) {
1769 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1770 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1771 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1772 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1773 unlink ("${General::swroot}/ovpn/crls/cacrl.pem");
1774 &cleanssldatabase();
1775 goto ROOTCERT_ERROR;
1776 # } else {
1777 # &cleanssldatabase();
1778 }
1779 # Create Diffie Hellmann Parameter
1780 system('/usr/bin/openssl', 'dhparam', '-rand', '/proc/interrupts:/proc/net/rt_cache',
1781 '-out', "${General::swroot}/ovpn/ca/dh1024.pem",
1782 '1024' );
1783 if ($?) {
1784 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1785 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1786 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1787 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1788 unlink ("${General::swroot}/ovpn/crls/cacrl.pem");
1789 unlink ("${General::swroot}/ovpn/ca/dh1024.pem");
1790 &cleanssldatabase();
1791 goto ROOTCERT_ERROR;
1792 # } else {
1793 # &cleanssldatabase();
1794 }
1795 goto ROOTCERT_SUCCESS;
1796 }
1797 ROOTCERT_ERROR:
1798 if ($cgiparams{'ACTION'} ne '') {
1799 &Header::showhttpheaders();
1800 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1801 &Header::openbigbox('100%', 'LEFT', '', '');
1802 if ($errormessage) {
1803 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
1804 print "<class name='base'>$errormessage";
1805 print "&nbsp;</class>";
1806 &Header::closebox();
1807 }
1808 &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:");
1809 print <<END
1810 <form method='post' enctype='multipart/form-data'>
1811 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1812 <tr><td width='30%' class='base'>$Lang::tr{'organization name'}:</td>
1813 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1814 <td width='35%' colspan='2'>&nbsp;</td></tr>
1815 <tr><td class='base'>$Lang::tr{'ipfires hostname'}:</td>
1816 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td>
1817 <td colspan='2'>&nbsp;</td></tr>
1818 <tr><td class='base'>$Lang::tr{'your e-mail'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1819 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td>
1820 <td colspan='2'>&nbsp;</td></tr>
1821 <tr><td class='base'>$Lang::tr{'your department'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1822 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td>
1823 <td colspan='2'>&nbsp;</td></tr>
1824 <tr><td class='base'>$Lang::tr{'city'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1825 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td>
1826 <td colspan='2'>&nbsp;</td></tr>
1827 <tr><td class='base'>$Lang::tr{'state or province'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1828 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td>
1829 <td colspan='2'>&nbsp;</td></tr>
1830 <tr><td class='base'>$Lang::tr{'country'}:</td>
1831 <td class='base'><select name='ROOTCERT_COUNTRY'>
1832
1833 END
1834 ;
1835 foreach my $country (sort keys %{Countries::countries}) {
1836 print "<option value='$Countries::countries{$country}'";
1837 if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) {
1838 print " selected='selected'";
1839 }
1840 print ">$country</option>";
1841 }
1842 print <<END
1843 </select></td>
1844 <td colspan='2'>&nbsp;</td></tr>
1845 <tr><td>&nbsp;</td>
1846 <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td>
1847 <td>&nbsp;</td><td>&nbsp;</td></tr>
1848 <tr><td class='base' colspan='4' align='left'>
1849 <img src='/blob.gif' valign='top' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td></tr>
1850 <tr><td class='base' colspan='4' align='left'>
1851 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:
1852 $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'}
1853 </td></tr>
1854 <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr>
1855 <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td>
1856 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1857 <td colspan='2'>&nbsp;</td></tr>
1858 <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:&nbsp;<img src='/blob.gif' alt='*' ></td>
1859 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td>
1860 <td colspan='2'>&nbsp;</td></tr>
1861 <tr><td>&nbsp;</td>
1862 <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td>
1863 <td colspan='2'>&nbsp;</td></tr>
1864 <tr><td class='base' colspan='4' align='left'>
1865 <img src='/blob.gif' valign='top' al='*' >&nbsp;$Lang::tr{'this field may be blank'}</td></tr>
1866 </form></table>
1867 END
1868 ;
1869 &Header::closebox();
1870
1871 &Header::closebigbox();
1872 &Header::closepage();
1873 exit(0)
1874 }
1875
1876 ROOTCERT_SUCCESS:
1877 system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem");
1878 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1879 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
1880 # system('/usr/local/bin/ipsecctrl', 'S');
1881 # }
1882
1883 ###
1884 ### Enable/Disable connection
1885 ###
1886
1887 ###
1888 # m.a.d net2net
1889 ###
1890
1891 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
1892
1893 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
1894 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1895 # my $n2nactive = '';
1896 my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`;
1897
1898 if ($confighash{$cgiparams{'KEY'}}) {
1899 if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') {
1900 $confighash{$cgiparams{'KEY'}}[0] = 'on';
1901 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1902
1903 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
1904 system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]);
1905 }
1906 } else {
1907
1908 $confighash{$cgiparams{'KEY'}}[0] = 'off';
1909 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1910
1911 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
1912 if ($n2nactive ne ''){
1913 system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]);
1914 }
1915
1916 } else {
1917 $errormessage = $Lang::tr{'invalid key'};
1918 }
1919 }
1920 }
1921
1922 ###
1923 ### Download OpenVPN client package
1924 ###
1925
1926
1927 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) {
1928 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
1929 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1930 my $file = '';
1931 my $clientovpn = '';
1932 my @fileholder;
1933 my $tempdir = tempdir( CLEANUP => 1 );
1934 my $zippath = "$tempdir/";
1935
1936 ###
1937 # m.a.d net2net
1938 ###
1939
1940 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
1941
1942 my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip";
1943 my $zippathname = "$zippath$zipname";
1944 $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf";
1945 my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]);
1946 my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]";
1947 my $tunmtu = '';
1948 my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]);
1949 my $n2nfragment = '';
1950
1951 open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!";
1952 flock CLIENTCONF, 2;
1953
1954 my $zip = Archive::Zip->new();
1955 print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n";
1956 print CLIENTCONF "# \n";
1957 print CLIENTCONF "# User Security\n";
1958 print CLIENTCONF "user nobody\n";
1959 print CLIENTCONF "group nobody\n";
1960 print CLIENTCONF "persist-tun\n";
1961 print CLIENTCONF "persist-key\n";
1962 print CLIENTCONF "script-security 2\n";
1963 print CLIENTCONF "# IP/DNS for remote Server Gateway\n";
1964 print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n";
1965 print CLIENTCONF "float\n";
1966 print CLIENTCONF "# IP adresses of the VPN Subnet\n";
1967 print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n";
1968 print CLIENTCONF "# Server Gateway Network\n";
1969 print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n";
1970 print CLIENTCONF "# tun Device\n";
1971 print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\n";
1972 print CLIENTCONF "# Port and Protokoll\n";
1973 print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n";
1974
1975 if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') {
1976 print CLIENTCONF "proto tcp-client\n";
1977 print CLIENTCONF "# Packet size\n";
1978 if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]};
1979 print CLIENTCONF "tun-mtu $tunmtu\n";
1980 }
1981
1982 if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') {
1983 print CLIENTCONF "proto udp\n";
1984 print CLIENTCONF "# Paketsize\n";
1985 if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]};
1986 print CLIENTCONF "tun-mtu $tunmtu\n";
1987 if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";}
1988 if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";}
1989 }
1990 if (($confighash{$cgiparams{'KEY'}}[38] eq 'yes') ||
1991 ($confighash{$cgiparams{'KEY'}}[38] eq 'maybe') ||
1992 ($confighash{$cgiparams{'KEY'}}[38] eq 'no' )) {
1993 if (($confighash{$cgiparams{'KEY'}}[23] ne 'on') || ($confighash{$cgiparams{'KEY'}}[24] eq '')) {
1994 if ($tunmtu eq '1500' ) {
1995 print CLIENTCONF "mtu-disc $confighash{$cgiparams{'KEY'}}[38]\n";
1996 }
1997 }
1998 }
1999 print CLIENTCONF "ns-cert-type server\n";
2000 print CLIENTCONF "# Auth. Client\n";
2001 print CLIENTCONF "tls-client\n";
2002 print CLIENTCONF "# Cipher\n";
2003 print CLIENTCONF "cipher AES-256-CBC\n";
2004 if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") {
2005 print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n";
2006 $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";
2007 }
2008 if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') {
2009 print CLIENTCONF "# Enable Compression\n";
2010 print CLIENTCONF "comp-lzo\r\n";
2011 }
2012 print CLIENTCONF "# Debug Level\n";
2013 print CLIENTCONF "verb 3\n";
2014 print CLIENTCONF "# Tunnel check\n";
2015 print CLIENTCONF "keepalive 10 60\n";
2016 print CLIENTCONF "# Start as daemon\n";
2017 print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n";
2018 print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n";
2019 print CLIENTCONF "# Activate Management Interface and Port\n";
2020 if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"}
2021 else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"};
2022 print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n";
2023
2024
2025 close(CLIENTCONF);
2026
2027 $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n";
2028 my $status = $zip->writeToFileNamed($zippathname);
2029
2030 open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!";
2031 @fileholder = <DLFILE>;
2032 print "Content-Type:application/x-download\n";
2033 print "Content-Disposition:attachment;filename=$zipname\n\n";
2034 print @fileholder;
2035 exit (0);
2036 }
2037 else
2038 {
2039 my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip";
2040 my $zippathname = "$zippath$zipname";
2041 $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn";
2042
2043 ###
2044 # m.a.d net2net
2045 ###
2046
2047 open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!";
2048 flock CLIENTCONF, 2;
2049
2050 my $zip = Archive::Zip->new();
2051
2052 print CLIENTCONF "#OpenVPN Client conf\r\n";
2053 print CLIENTCONF "tls-client\r\n";
2054 print CLIENTCONF "client\r\n";
2055 print CLIENTCONF "nobind\r\n";
2056 print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\r\n";
2057 print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n";
2058
2059 # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500
2060 # or use configured value.
2061 if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' )
2062 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; }
2063 elsif ($vpnsettings{MSSFIX} eq 'on')
2064 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; }
2065 elsif (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
2066 ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
2067 ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' ))
2068 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; }
2069 else
2070 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu $vpnsettings{'DMTU'}\r\n"; }
2071
2072 if ( $vpnsettings{'ENABLED'} eq 'on'){
2073 print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n";
2074 if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){
2075 print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n";
2076 print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2077 }
2078 if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){
2079 print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n";
2080 print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2081 }
2082 } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){
2083 print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2084 if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){
2085 print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n";
2086 print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2087 }
2088 } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){
2089 print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2090 }
2091
2092 if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") {
2093 print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n";
2094 $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";
2095 } else {
2096 print CLIENTCONF "ca cacert.pem\r\n";
2097 print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n";
2098 print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n";
2099 $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n";
2100 $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";
2101 }
2102 print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n";
2103 if ($vpnsettings{DCOMPLZO} eq 'on') {
2104 print CLIENTCONF "comp-lzo\r\n";
2105 }
2106 print CLIENTCONF "verb 3\r\n";
2107 print CLIENTCONF "ns-cert-type server\r\n";
2108 print CLIENTCONF "tls-remote $vpnsettings{ROOTCERT_HOSTNAME}\r\n";
2109 if ($vpnsettings{MSSFIX} eq 'on') {
2110 print CLIENTCONF "mssfix\r\n";
2111 }
2112 if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) {
2113 print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n";
2114 }
2115
2116 # Check if a valid operating mode has been choosen and use it.
2117 if (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
2118 ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
2119 ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) {
2120 if(($vpnsettings{MSSFIX} ne 'on') || ($vpnsettings{FRAGMENT} eq '')) {
2121 print CLIENTCONF "mtu-disc $vpnsettings{'PMTU_DISCOVERY'}\r\n";
2122 }
2123 }
2124 close(CLIENTCONF);
2125
2126 $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n";
2127 my $status = $zip->writeToFileNamed($zippathname);
2128
2129 open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!";
2130 @fileholder = <DLFILE>;
2131 print "Content-Type:application/x-download\n";
2132 print "Content-Disposition:attachment;filename=$zipname\n\n";
2133 print @fileholder;
2134 exit (0);
2135 }
2136
2137
2138
2139 ###
2140 ### Remove connection
2141 ###
2142
2143
2144 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) {
2145 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
2146 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2147
2148 if ($confighash{$cgiparams{'KEY'}}) {
2149 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2150 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2151 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2152 # }
2153 #
2154 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`;
2155
2156 ###
2157 # m.a.d net2net
2158 ###
2159
2160 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') {
2161 my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf");
2162 my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
2163 unlink ($certfile);
2164 unlink ($conffile);
2165
2166 if (-e "${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") {
2167 rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!";
2168 }
2169 }
2170
2171 unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem");
2172 unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
2173
2174 # A.Marx CCD delete ccd files and routes
2175
2176
2177 if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]")
2178 {
2179 unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]";
2180 }
2181
2182 &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
2183 foreach my $key (keys %ccdroutehash) {
2184 if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){
2185 delete $ccdroutehash{$key};
2186 }
2187 }
2188 &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
2189
2190 &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash);
2191 foreach my $key (keys %ccdroute2hash) {
2192 if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){
2193 delete $ccdroute2hash{$key};
2194 }
2195 }
2196 &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash);
2197 &writeserverconf;
2198
2199
2200 # CCD end
2201
2202
2203 delete $confighash{$cgiparams{'KEY'}};
2204 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`;
2205 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2206
2207 #&writeserverconf();
2208 } else {
2209 $errormessage = $Lang::tr{'invalid key'};
2210 }
2211
2212
2213 ###
2214 ### Download PKCS12 file
2215 ###
2216 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) {
2217 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2218
2219 print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n";
2220 print "Content-Type: application/octet-stream\r\n\r\n";
2221 print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`;
2222 exit (0);
2223
2224 ###
2225 ### Display certificate
2226 ###
2227 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) {
2228 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2229
2230 if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") {
2231 &Header::showhttpheaders();
2232 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
2233 &Header::openbigbox('100%', 'LEFT', '', '');
2234 &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:");
2235 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`;
2236 $output = &Header::cleanhtml($output,"y");
2237 print "<pre>$output</pre>\n";
2238 &Header::closebox();
2239 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2240 &Header::closebigbox();
2241 &Header::closepage();
2242 exit(0);
2243 }
2244 ###
2245 ### Display Certificate Revoke List
2246 ###
2247 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) {
2248 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2249
2250 if ( -f "${General::swroot}/ovpn/crls/cacrl.pem") {
2251 &Header::showhttpheaders();
2252 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
2253 &Header::openbigbox('100%', 'LEFT', '', '');
2254 &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:");
2255 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`;
2256 $output = &Header::cleanhtml($output,"y");
2257 print "<pre>$output</pre>\n";
2258 &Header::closebox();
2259 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2260 &Header::closebigbox();
2261 &Header::closepage();
2262 exit(0);
2263 }
2264
2265 ###
2266 ### Advanced Server Settings
2267 ###
2268
2269 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) {
2270 %cgiparams = ();
2271 %cahash = ();
2272 %confighash = ();
2273 my $disabled;
2274 &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams);
2275 read_routepushfile;
2276
2277
2278 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
2279 # $cgiparams{'CLIENT2CLIENT'} = 'on';
2280 # }
2281 ADV_ERROR:
2282 if ($cgiparams{'MAX_CLIENTS'} eq '') {
2283 $cgiparams{'MAX_CLIENTS'} = '100';
2284 }
2285 if ($cgiparams{'KEEPALIVE_1'} eq '') {
2286 $cgiparams{'KEEPALIVE_1'} = '10';
2287 }
2288 if ($cgiparams{'KEEPALIVE_2'} eq '') {
2289 $cgiparams{'KEEPALIVE_2'} = '60';
2290 }
2291 if ($cgiparams{'LOG_VERB'} eq '') {
2292 $cgiparams{'LOG_VERB'} = '3';
2293 }
2294 if ($cgiparams{'PMTU_DISCOVERY'} eq '') {
2295 $cgiparams{'PMTU_DISCOVERY'} = 'off';
2296 }
2297 $checked{'CLIENT2CLIENT'}{'off'} = '';
2298 $checked{'CLIENT2CLIENT'}{'on'} = '';
2299 $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED';
2300 $checked{'REDIRECT_GW_DEF1'}{'off'} = '';
2301 $checked{'REDIRECT_GW_DEF1'}{'on'} = '';
2302 $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED';
2303 $selected{'ENGINES'}{$cgiparams{'ENGINES'}} = 'SELECTED';
2304 $checked{'MSSFIX'}{'off'} = '';
2305 $checked{'MSSFIX'}{'on'} = '';
2306 $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED';
2307 $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\'';
2308 $selected{'LOG_VERB'}{'1'} = '';
2309 $selected{'LOG_VERB'}{'2'} = '';
2310 $selected{'LOG_VERB'}{'3'} = '';
2311 $selected{'LOG_VERB'}{'4'} = '';
2312 $selected{'LOG_VERB'}{'5'} = '';
2313 $selected{'LOG_VERB'}{'6'} = '';
2314 $selected{'LOG_VERB'}{'7'} = '';
2315 $selected{'LOG_VERB'}{'8'} = '';
2316 $selected{'LOG_VERB'}{'9'} = '';
2317 $selected{'LOG_VERB'}{'10'} = '';
2318 $selected{'LOG_VERB'}{'11'} = '';
2319 $selected{'LOG_VERB'}{'0'} = '';
2320 $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED';
2321
2322 &Header::showhttpheaders();
2323 &Header::openpage($Lang::tr{'status ovpn'}, 1, '');
2324 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
2325 if ($errormessage) {
2326 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
2327 print "<class name='base'>$errormessage\n";
2328 print "&nbsp;</class>\n";
2329 &Header::closebox();
2330 }
2331 &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'});
2332 print <<END
2333 <form method='post' enctype='multipart/form-data'>
2334 <table width='100%' border=0>
2335 <tr>
2336 <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td>
2337 </tr>
2338 <tr>
2339 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2340 </tr>
2341 <tr>
2342 <td class='base'>Domain</td>
2343 <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td>
2344 </tr>
2345 <tr>
2346 <td class='base'>DNS</td>
2347 <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td>
2348 </tr>
2349 <tr>
2350 <td class='base'>WINS</td>
2351 <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td>
2352 </tr>
2353 <tr>
2354 <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td>
2355 </tr>
2356 <tr>
2357 <td class='base'>$Lang::tr{'ovpn routes push'}</td>
2358 <td colspan='2'>
2359 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
2360 END
2361 ;
2362
2363 if ($cgiparams{'ROUTES_PUSH'} ne '')
2364 {
2365 print $cgiparams{'ROUTES_PUSH'};
2366 }
2367
2368 print <<END;
2369 </textarea></td>
2370 </tr>
2371 </tr>
2372 </table>
2373 <hr size='1'>
2374 <table width='100%'>
2375 <tr>
2376 <td class'base'><b>$Lang::tr{'misc-options'}</b></td>
2377 </tr>
2378 <tr>
2379 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
2380 </tr>
2381 <tr>
2382 <td class='base'>Client-To-Client</td>
2383 <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td>
2384 </tr>
2385 <tr>
2386 <td class='base'>Redirect-Gateway def1</td>
2387 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td>
2388 </tr>
2389 <tr>
2390 <td class='base'>Max-Clients</td>
2391 <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td>
2392 </tr>
2393 <tr>
2394 <td class='base'>Keepalive <br />
2395 (ping/ping-restart)</td>
2396 <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td>
2397 <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td>
2398 </tr>
2399 <tr>
2400 <td class='base'>fragment <br></td>
2401 <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td>
2402 <td>Default: <span class="base">1300</span></td>
2403 </tr>
2404 <tr>
2405 <td class='base'>mssfix</td>
2406 <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td>
2407 <td>Default: on</td>
2408 </tr>
2409
2410 <tr>
2411 <td class='base'>$Lang::tr{'ovpn mtu-disc'}</td>
2412 <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'}</td>
2413 <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'}</td>
2414 <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'}</td>
2415 <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'}</td>
2416 </tr>
2417 </table>
2418
2419 <!--
2420 <hr size='1'>
2421 <table width='100%'>
2422 <tr>
2423 <td class'base'><b>Crypto-Engines</b></td>
2424 </tr>
2425 <tr>
2426 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2427 </tr>
2428 <tr><td class='base'>Engines:</td>
2429 <td><select name='ENGINES'><option value="none" $selected{'ENGINES'}{'none'}>none</option>
2430 <option value="cryptodev" $selected{'ENGINES'}{'cryptodev'}>cryptodev</option>
2431 <option value="padlock" $selected{'ENGINES'}{'padlock'}>padlock</option>
2432 </select>
2433 </td>
2434 </table>
2435 -->
2436 <hr size='1'>
2437 <table width='100%'>
2438 <tr>
2439 <td class'base'><b>$Lang::tr{'log-options'}</b></td>
2440 </tr>
2441 <tr>
2442 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2443 </tr>
2444
2445 <tr><td class='base'>VERB</td>
2446 <td><select name='LOG_VERB'><option value='1' $selected{'LOG_VERB'}{'1'}>1</option>
2447 <option value='2' $selected{'LOG_VERB'}{'2'}>2</option>
2448 <option value='3' $selected{'LOG_VERB'}{'3'}>3</option>
2449 <option value='4' $selected{'LOG_VERB'}{'4'}>4</option>
2450 <option value='5' $selected{'LOG_VERB'}{'5'}>5</option>
2451 <option value='6' $selected{'LOG_VERB'}{'6'}>6</option>
2452 <option value='7' $selected{'LOG_VERB'}{'7'}>7</option>
2453 <option value='8' $selected{'LOG_VERB'}{'8'}>8</option>
2454 <option value='9' $selected{'LOG_VERB'}{'9'}>9</option>
2455 <option value='10' $selected{'LOG_VERB'}{'10'}>10</option>
2456 <option value='11' $selected{'LOG_VERB'}{'11'}>11</option>
2457 <option value='0' $selected{'LOG_VERB'}{'0'}>0</option></select></td>
2458 </table><hr>
2459 END
2460
2461 if ( -e "/var/run/openvpn.pid"){
2462 print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br>
2463 $Lang::tr{'server restart'}<br><br>
2464 <hr>";
2465 print<<END
2466 <table width='100%'>
2467 <tr>
2468 <td>&nbsp;</td>
2469 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td>
2470 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td>
2471 <td>&nbsp;</td>
2472 </tr>
2473 </table>
2474 </form>
2475 END
2476 ;
2477
2478
2479 }else{
2480
2481 print<<END
2482 <table width='100%'>
2483 <tr>
2484 <td>&nbsp;</td>
2485 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td>
2486 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td>
2487 <td>&nbsp;</td>
2488 </tr>
2489 </table>
2490 </form>
2491 END
2492 ;
2493 }
2494 &Header::closebox();
2495 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2496 &Header::closebigbox();
2497 &Header::closepage();
2498 exit(0);
2499
2500
2501 # A.Marx CCD Add,delete or edit CCD net
2502
2503 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} ||
2504 $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} ||
2505 $cgiparams{'ACTION'} eq "kill" ||
2506 $cgiparams{'ACTION'} eq "edit" ||
2507 $cgiparams{'ACTION'} eq 'editsave'){
2508 &Header::showhttpheaders();
2509 &Header::openpage($Lang::tr{'ccd net'}, 1, '');
2510 &Header::openbigbox('100%', 'LEFT', '', '');
2511
2512 if ($cgiparams{'ACTION'} eq "kill"){
2513 &delccdnet($cgiparams{'net'});
2514 }
2515
2516 if ($cgiparams{'ACTION'} eq 'editsave'){
2517 my ($a,$b) =split (/\|/,$cgiparams{'ccdname'});
2518 if ( $a ne $b){ &modccdnet($a,$b);}
2519 $cgiparams{'ccdname'}='';
2520 $cgiparams{'ccdsubnet'}='';
2521 }
2522
2523 if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) {
2524 &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'});
2525 }
2526 if ($errormessage) {
2527 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
2528 print "<class name='base'>$errormessage";
2529 print "&nbsp;</class>";
2530 &Header::closebox();
2531 }
2532 if ($cgiparams{'ACTION'} eq "edit"){
2533
2534 &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'});
2535
2536 print <<END
2537 <table width='100%' border=0>
2538 <tr><form method='post'>
2539 <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td>
2540 <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly /></td></tr>
2541 <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/>
2542 <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' />
2543 </td></tr>
2544 </table></form>