Merge branch 'fifteen' of ssh://git.ipfire.org/pub/git/ipfire-2.x into fifteen-layout
[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 $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'};
1167 $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'};
1168 $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'};
1169 $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'};
1170 #new settings for daemon
1171 $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'};
1172 $vpnsettings{'DDEVICE'} = $cgiparams{'DDEVICE'};
1173 $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'};
1174 $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'};
1175 $vpnsettings{'DMTU'} = $cgiparams{'DMTU'};
1176 $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'};
1177 $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'};
1178 #wrtie enable
1179
1180 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");}
1181 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");}
1182 if ( $vpnsettings{'ENABLED'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable 2>/dev/null");}
1183 #new settings for daemon
1184 &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings);
1185 &writeserverconf();#hier ok
1186 SETTINGS_ERROR:
1187 ###
1188 ### Reset all step 2
1189 ###
1190 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'} && $cgiparams{'AREUSURE'} eq 'yes') {
1191 my $file = '';
1192 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1193
1194 foreach my $key (keys %confighash) {
1195 if ($confighash{$key}[4] eq 'cert') {
1196 delete $confighash{$cgiparams{'$key'}};
1197 }
1198 }
1199 while ($file = glob("${General::swroot}/ovpn/ca/*")) {
1200 unlink $file
1201 }
1202 while ($file = glob("${General::swroot}/ovpn/certs/*")) {
1203 unlink $file
1204 }
1205 while ($file = glob("${General::swroot}/ovpn/crls/*")) {
1206 unlink $file
1207 }
1208 &cleanssldatabase();
1209 if (open(FILE, ">${General::swroot}/ovpn/caconfig")) {
1210 print FILE "";
1211 close FILE;
1212 }
1213 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1214 #&writeserverconf();
1215 ###
1216 ### Reset all step 1
1217 ###
1218 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'}) {
1219 &Header::showhttpheaders();
1220 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1221 &Header::openbigbox('100%', 'LEFT', '', '');
1222 &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'});
1223 print <<END
1224 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1225 <tr><td align='center'>
1226 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:
1227 $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
1228 <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' />
1229 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr>
1230 </form></table>
1231 END
1232 ;
1233 &Header::closebox();
1234 &Header::closebigbox();
1235 &Header::closepage();
1236 exit (0);
1237
1238 ###
1239 ### Upload CA Certificate
1240 ###
1241 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) {
1242 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1243
1244 if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) {
1245 $errormessage = $Lang::tr{'name must only contain characters'};
1246 goto UPLOADCA_ERROR;
1247 }
1248
1249 if (length($cgiparams{'CA_NAME'}) >60) {
1250 $errormessage = $Lang::tr{'name too long'};
1251 goto VPNCONF_ERROR;
1252 }
1253
1254 if ($cgiparams{'CA_NAME'} eq 'ca') {
1255 $errormessage = $Lang::tr{'name is invalid'};
1256 goto UPLOAD_CA_ERROR;
1257 }
1258
1259 # Check if there is no other entry with this name
1260 foreach my $key (keys %cahash) {
1261 if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) {
1262 $errormessage = $Lang::tr{'a ca certificate with this name already exists'};
1263 goto UPLOADCA_ERROR;
1264 }
1265 }
1266
1267 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1268 $errormessage = $Lang::tr{'there was no file upload'};
1269 goto UPLOADCA_ERROR;
1270 }
1271 # Move uploaded ca to a temporary file
1272 (my $fh, my $filename) = tempfile( );
1273 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1274 $errormessage = $!;
1275 goto UPLOADCA_ERROR;
1276 }
1277 my $temp = `/usr/bin/openssl x509 -text -in $filename`;
1278 if ($temp !~ /CA:TRUE/i) {
1279 $errormessage = $Lang::tr{'not a valid ca certificate'};
1280 unlink ($filename);
1281 goto UPLOADCA_ERROR;
1282 } else {
1283 move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem");
1284 if ($? ne 0) {
1285 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1286 unlink ($filename);
1287 goto UPLOADCA_ERROR;
1288 }
1289 }
1290
1291 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`;
1292 $casubject =~ /Subject: (.*)[\n]/;
1293 $casubject = $1;
1294 $casubject =~ s+/Email+, E+;
1295 $casubject =~ s/ ST=/ S=/;
1296 $casubject = &Header::cleanhtml($casubject);
1297
1298 my $key = &General::findhasharraykey (\%cahash);
1299 $cahash{$key}[0] = $cgiparams{'CA_NAME'};
1300 $cahash{$key}[1] = $casubject;
1301 &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1302 # system('/usr/local/bin/ipsecctrl', 'R');
1303
1304 UPLOADCA_ERROR:
1305
1306 ###
1307 ### Display ca certificate
1308 ###
1309 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) {
1310 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1311
1312 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") {
1313 &Header::showhttpheaders();
1314 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1315 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
1316 &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:");
1317 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
1318 $output = &Header::cleanhtml($output,"y");
1319 print "<pre>$output</pre>\n";
1320 &Header::closebox();
1321 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
1322 &Header::closebigbox();
1323 &Header::closepage();
1324 exit(0);
1325 } else {
1326 $errormessage = $Lang::tr{'invalid key'};
1327 }
1328
1329 ###
1330 ### Download ca certificate
1331 ###
1332 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) {
1333 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1334
1335 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
1336 print "Content-Type: application/octet-stream\r\n";
1337 print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n";
1338 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
1339 exit(0);
1340 } else {
1341 $errormessage = $Lang::tr{'invalid key'};
1342 }
1343
1344 ###
1345 ### Remove ca certificate (step 2)
1346 ###
1347 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') {
1348 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1349 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1350
1351 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
1352 foreach my $key (keys %confighash) {
1353 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`;
1354 if ($test =~ /: OK/) {
1355 # Delete connection
1356 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1357 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1358 # system('/usr/local/bin/ipsecctrl', 'D', $key);
1359 # }
1360 unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem");
1361 unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12");
1362 delete $confighash{$key};
1363 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1364 # &writeipsecfiles();
1365 }
1366 }
1367 unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem");
1368 delete $cahash{$cgiparams{'KEY'}};
1369 &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1370 # system('/usr/local/bin/ipsecctrl', 'R');
1371 } else {
1372 $errormessage = $Lang::tr{'invalid key'};
1373 }
1374 ###
1375 ### Remove ca certificate (step 1)
1376 ###
1377 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) {
1378 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1379 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1380
1381 my $assignedcerts = 0;
1382 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
1383 foreach my $key (keys %confighash) {
1384 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`;
1385 if ($test =~ /: OK/) {
1386 $assignedcerts++;
1387 }
1388 }
1389 if ($assignedcerts) {
1390 &Header::showhttpheaders();
1391 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1392 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
1393 &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'});
1394 print <<END
1395 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1396 <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />
1397 <tr><td align='center'>
1398 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts
1399 $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1400 <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' />
1401 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr>
1402 </form></table>
1403 END
1404 ;
1405 &Header::closebox();
1406 &Header::closebigbox();
1407 &Header::closepage();
1408 exit (0);
1409 } else {
1410 unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem");
1411 delete $cahash{$cgiparams{'KEY'}};
1412 &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1413 # system('/usr/local/bin/ipsecctrl', 'R');
1414 }
1415 } else {
1416 $errormessage = $Lang::tr{'invalid key'};
1417 }
1418
1419 ###
1420 ### Display root certificate
1421 ###
1422 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} ||
1423 $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) {
1424 my $output;
1425 &Header::showhttpheaders();
1426 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1427 &Header::openbigbox('100%', 'LEFT', '', '');
1428 if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) {
1429 &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:");
1430 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`;
1431 } else {
1432 &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:");
1433 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`;
1434 }
1435 $output = &Header::cleanhtml($output,"y");
1436 print "<pre>$output</pre>\n";
1437 &Header::closebox();
1438 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
1439 &Header::closebigbox();
1440 &Header::closepage();
1441 exit(0);
1442
1443 ###
1444 ### Download root certificate
1445 ###
1446 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) {
1447 if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) {
1448 print "Content-Type: application/octet-stream\r\n";
1449 print "Content-Disposition: filename=cacert.pem\r\n\r\n";
1450 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`;
1451 exit(0);
1452 }
1453
1454 ###
1455 ### Download host certificate
1456 ###
1457 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) {
1458 if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) {
1459 print "Content-Type: application/octet-stream\r\n";
1460 print "Content-Disposition: filename=servercert.pem\r\n\r\n";
1461 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`;
1462 exit(0);
1463 }
1464 ###
1465 ### Form for generating a root certificate
1466 ###
1467 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} ||
1468 $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
1469
1470 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
1471 if (-f "${General::swroot}/ovpn/ca/cacert.pem") {
1472 $errormessage = $Lang::tr{'valid root certificate already exists'};
1473 $cgiparams{'ACTION'} = '';
1474 goto ROOTCERT_ERROR;
1475 }
1476
1477 if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") {
1478 if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) {
1479 my $ipaddr = <IPADDR>;
1480 close IPADDR;
1481 chomp ($ipaddr);
1482 $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
1483 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') {
1484 $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr;
1485 }
1486 }
1487 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
1488
1489 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1490 $errormessage = $Lang::tr{'there was no file upload'};
1491 goto ROOTCERT_ERROR;
1492 }
1493
1494 # Move uploaded certificate request to a temporary file
1495 (my $fh, my $filename) = tempfile( );
1496 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1497 $errormessage = $!;
1498 goto ROOTCERT_ERROR;
1499 }
1500
1501 # Create a temporary dirctory
1502 my $tempdir = tempdir( CLEANUP => 1 );
1503
1504 # Extract the CA certificate from the file
1505 my $pid = open(OPENSSL, "|-");
1506 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1507 if ($pid) { # parent
1508 if ($cgiparams{'P12_PASS'} ne '') {
1509 print OPENSSL "$cgiparams{'P12_PASS'}\n";
1510 }
1511 close (OPENSSL);
1512 if ($?) {
1513 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1514 unlink ($filename);
1515 goto ROOTCERT_ERROR;
1516 }
1517 } else { # child
1518 unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys',
1519 '-in', $filename,
1520 '-out', "$tempdir/cacert.pem")) {
1521 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1522 unlink ($filename);
1523 goto ROOTCERT_ERROR;
1524 }
1525 }
1526
1527 # Extract the Host certificate from the file
1528 $pid = open(OPENSSL, "|-");
1529 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1530 if ($pid) { # parent
1531 if ($cgiparams{'P12_PASS'} ne '') {
1532 print OPENSSL "$cgiparams{'P12_PASS'}\n";
1533 }
1534 close (OPENSSL);
1535 if ($?) {
1536 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1537 unlink ($filename);
1538 goto ROOTCERT_ERROR;
1539 }
1540 } else { # child
1541 unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys',
1542 '-in', $filename,
1543 '-out', "$tempdir/hostcert.pem")) {
1544 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1545 unlink ($filename);
1546 goto ROOTCERT_ERROR;
1547 }
1548 }
1549
1550 # Extract the Host key from the file
1551 $pid = open(OPENSSL, "|-");
1552 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1553 if ($pid) { # parent
1554 if ($cgiparams{'P12_PASS'} ne '') {
1555 print OPENSSL "$cgiparams{'P12_PASS'}\n";
1556 }
1557 close (OPENSSL);
1558 if ($?) {
1559 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1560 unlink ($filename);
1561 goto ROOTCERT_ERROR;
1562 }
1563 } else { # child
1564 unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts',
1565 '-nodes',
1566 '-in', $filename,
1567 '-out', "$tempdir/serverkey.pem")) {
1568 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1569 unlink ($filename);
1570 goto ROOTCERT_ERROR;
1571 }
1572 }
1573
1574 move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem");
1575 if ($? ne 0) {
1576 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1577 unlink ($filename);
1578 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1579 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1580 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1581 goto ROOTCERT_ERROR;
1582 }
1583
1584 move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem");
1585 if ($? ne 0) {
1586 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1587 unlink ($filename);
1588 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1589 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1590 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1591 goto ROOTCERT_ERROR;
1592 }
1593
1594 move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem");
1595 if ($? ne 0) {
1596 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1597 unlink ($filename);
1598 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1599 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1600 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1601 goto ROOTCERT_ERROR;
1602 }
1603
1604 goto ROOTCERT_SUCCESS;
1605
1606 } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') {
1607
1608 # Validate input since the form was submitted
1609 if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){
1610 $errormessage = $Lang::tr{'organization cant be empty'};
1611 goto ROOTCERT_ERROR;
1612 }
1613 if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) {
1614 $errormessage = $Lang::tr{'organization too long'};
1615 goto ROOTCERT_ERROR;
1616 }
1617 if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1618 $errormessage = $Lang::tr{'invalid input for organization'};
1619 goto ROOTCERT_ERROR;
1620 }
1621 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){
1622 $errormessage = $Lang::tr{'hostname cant be empty'};
1623 goto ROOTCERT_ERROR;
1624 }
1625 unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) {
1626 $errormessage = $Lang::tr{'invalid input for hostname'};
1627 goto ROOTCERT_ERROR;
1628 }
1629 if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) {
1630 $errormessage = $Lang::tr{'invalid input for e-mail address'};
1631 goto ROOTCERT_ERROR;
1632 }
1633 if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) {
1634 $errormessage = $Lang::tr{'e-mail address too long'};
1635 goto ROOTCERT_ERROR;
1636 }
1637 if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1638 $errormessage = $Lang::tr{'invalid input for department'};
1639 goto ROOTCERT_ERROR;
1640 }
1641 if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1642 $errormessage = $Lang::tr{'invalid input for city'};
1643 goto ROOTCERT_ERROR;
1644 }
1645 if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1646 $errormessage = $Lang::tr{'invalid input for state or province'};
1647 goto ROOTCERT_ERROR;
1648 }
1649 if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) {
1650 $errormessage = $Lang::tr{'invalid input for country'};
1651 goto ROOTCERT_ERROR;
1652 }
1653
1654 # Copy the cgisettings to vpnsettings and save the configfile
1655 $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'};
1656 $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'};
1657 $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'};
1658 $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'};
1659 $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'};
1660 $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'};
1661 $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'};
1662 &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings);
1663
1664 # Replace empty strings with a .
1665 (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./;
1666 (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./;
1667 (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./;
1668
1669 # refresh
1670 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
1671
1672 # Create the CA certificate
1673 my $pid = open(OPENSSL, "|-");
1674 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1675 if ($pid) { # parent
1676 print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n";
1677 print OPENSSL "$state\n";
1678 print OPENSSL "$city\n";
1679 print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
1680 print OPENSSL "$ou\n";
1681 print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n";
1682 print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n";
1683 close (OPENSSL);
1684 if ($?) {
1685 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1686 unlink ("${General::swroot}/ovpn/ca/cakey.pem");
1687 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1688 goto ROOTCERT_ERROR;
1689 }
1690 } else { # child
1691 unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache',
1692 '-days', '999999', '-newkey', 'rsa:2048',
1693 '-keyout', "${General::swroot}/ovpn/ca/cakey.pem",
1694 '-out', "${General::swroot}/ovpn/ca/cacert.pem",
1695 '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) {
1696 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1697 goto ROOTCERT_ERROR;
1698 }
1699 }
1700
1701 # Create the Host certificate request
1702 $pid = open(OPENSSL, "|-");
1703 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1704 if ($pid) { # parent
1705 print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n";
1706 print OPENSSL "$state\n";
1707 print OPENSSL "$city\n";
1708 print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
1709 print OPENSSL "$ou\n";
1710 print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n";
1711 print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n";
1712 print OPENSSL ".\n";
1713 print OPENSSL ".\n";
1714 close (OPENSSL);
1715 if ($?) {
1716 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1717 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1718 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1719 goto ROOTCERT_ERROR;
1720 }
1721 } else { # child
1722 unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache',
1723 '-newkey', 'rsa:1024',
1724 '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem",
1725 '-out', "${General::swroot}/ovpn/certs/serverreq.pem",
1726 '-extensions', 'server',
1727 '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1728 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1729 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1730 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1731 unlink ("${General::swroot}/ovpn/ca/cakey.pem");
1732 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1733 goto ROOTCERT_ERROR;
1734 }
1735 }
1736
1737 # Sign the host certificate request
1738 system('/usr/bin/openssl', 'ca', '-days', '999999',
1739 '-batch', '-notext',
1740 '-in', "${General::swroot}/ovpn/certs/serverreq.pem",
1741 '-out', "${General::swroot}/ovpn/certs/servercert.pem",
1742 '-extensions', 'server',
1743 '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf");
1744 if ($?) {
1745 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1746 unlink ("${General::swroot}/ovpn/ca/cakey.pem");
1747 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1748 unlink ("${General::swroot}/ovpn/serverkey.pem");
1749 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1750 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1751 &newcleanssldatabase();
1752 goto ROOTCERT_ERROR;
1753 } else {
1754 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1755 &deletebackupcert();
1756 }
1757
1758 # Create an empty CRL
1759 system('/usr/bin/openssl', 'ca', '-gencrl',
1760 '-out', "${General::swroot}/ovpn/crls/cacrl.pem",
1761 '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1762 if ($?) {
1763 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1764 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1765 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1766 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1767 unlink ("${General::swroot}/ovpn/crls/cacrl.pem");
1768 &cleanssldatabase();
1769 goto ROOTCERT_ERROR;
1770 # } else {
1771 # &cleanssldatabase();
1772 }
1773 # Create Diffie Hellmann Parameter
1774 system('/usr/bin/openssl', 'dhparam', '-rand', '/proc/interrupts:/proc/net/rt_cache',
1775 '-out', "${General::swroot}/ovpn/ca/dh1024.pem",
1776 '1024' );
1777 if ($?) {
1778 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1779 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1780 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1781 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1782 unlink ("${General::swroot}/ovpn/crls/cacrl.pem");
1783 unlink ("${General::swroot}/ovpn/ca/dh1024.pem");
1784 &cleanssldatabase();
1785 goto ROOTCERT_ERROR;
1786 # } else {
1787 # &cleanssldatabase();
1788 }
1789 goto ROOTCERT_SUCCESS;
1790 }
1791 ROOTCERT_ERROR:
1792 if ($cgiparams{'ACTION'} ne '') {
1793 &Header::showhttpheaders();
1794 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1795 &Header::openbigbox('100%', 'LEFT', '', '');
1796 if ($errormessage) {
1797 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
1798 print "<class name='base'>$errormessage";
1799 print "&nbsp;</class>";
1800 &Header::closebox();
1801 }
1802 &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:");
1803 print <<END
1804 <form method='post' enctype='multipart/form-data'>
1805 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1806 <tr><td width='30%' class='base'>$Lang::tr{'organization name'}:</td>
1807 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1808 <td width='35%' colspan='2'>&nbsp;</td></tr>
1809 <tr><td class='base'>$Lang::tr{'ipfires hostname'}:</td>
1810 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td>
1811 <td colspan='2'>&nbsp;</td></tr>
1812 <tr><td class='base'>$Lang::tr{'your e-mail'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1813 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td>
1814 <td colspan='2'>&nbsp;</td></tr>
1815 <tr><td class='base'>$Lang::tr{'your department'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1816 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td>
1817 <td colspan='2'>&nbsp;</td></tr>
1818 <tr><td class='base'>$Lang::tr{'city'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1819 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td>
1820 <td colspan='2'>&nbsp;</td></tr>
1821 <tr><td class='base'>$Lang::tr{'state or province'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1822 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td>
1823 <td colspan='2'>&nbsp;</td></tr>
1824 <tr><td class='base'>$Lang::tr{'country'}:</td>
1825 <td class='base'><select name='ROOTCERT_COUNTRY'>
1826
1827 END
1828 ;
1829 foreach my $country (sort keys %{Countries::countries}) {
1830 print "<option value='$Countries::countries{$country}'";
1831 if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) {
1832 print " selected='selected'";
1833 }
1834 print ">$country</option>";
1835 }
1836 print <<END
1837 </select></td>
1838 <td colspan='2'>&nbsp;</td></tr>
1839 <tr><td>&nbsp;</td>
1840 <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td>
1841 <td>&nbsp;</td><td>&nbsp;</td></tr>
1842 <tr><td class='base' colspan='4' align='left'>
1843 <img src='/blob.gif' valign='top' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td></tr>
1844 <tr><td class='base' colspan='4' align='left'>
1845 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:
1846 $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'}
1847 </td></tr>
1848 <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr>
1849 <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td>
1850 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1851 <td colspan='2'>&nbsp;</td></tr>
1852 <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:&nbsp;<img src='/blob.gif' alt='*' ></td>
1853 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td>
1854 <td colspan='2'>&nbsp;</td></tr>
1855 <tr><td>&nbsp;</td>
1856 <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td>
1857 <td colspan='2'>&nbsp;</td></tr>
1858 <tr><td class='base' colspan='4' align='left'>
1859 <img src='/blob.gif' valign='top' al='*' >&nbsp;$Lang::tr{'this field may be blank'}</td></tr>
1860 </form></table>
1861 END
1862 ;
1863 &Header::closebox();
1864
1865 &Header::closebigbox();
1866 &Header::closepage();
1867 exit(0)
1868 }
1869
1870 ROOTCERT_SUCCESS:
1871 system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem");
1872 # if ($vpnsettings{'ENABLED'} eq 'on' ||
1873 # $vpnsettings{'ENABLE_BLUE'} eq 'on') {
1874 # system('/usr/local/bin/ipsecctrl', 'S');
1875 # }
1876
1877 ###
1878 ### Enable/Disable connection
1879 ###
1880
1881 ###
1882 # m.a.d net2net
1883 ###
1884
1885 }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
1886
1887 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
1888 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1889 # my $n2nactive = '';
1890 my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`;
1891
1892 if ($confighash{$cgiparams{'KEY'}}) {
1893 if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') {
1894 $confighash{$cgiparams{'KEY'}}[0] = 'on';
1895 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1896
1897 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
1898 system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]);
1899 }
1900 } else {
1901
1902 $confighash{$cgiparams{'KEY'}}[0] = 'off';
1903 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1904
1905 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
1906 if ($n2nactive ne ''){
1907 system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]);
1908 }
1909
1910 } else {
1911 $errormessage = $Lang::tr{'invalid key'};
1912 }
1913 }
1914 }
1915
1916 ###
1917 ### Download OpenVPN client package
1918 ###
1919
1920
1921 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) {
1922 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
1923 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1924 my $file = '';
1925 my $clientovpn = '';
1926 my @fileholder;
1927 my $tempdir = tempdir( CLEANUP => 1 );
1928 my $zippath = "$tempdir/";
1929
1930 ###
1931 # m.a.d net2net
1932 ###
1933
1934 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
1935
1936 my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip";
1937 my $zippathname = "$zippath$zipname";
1938 $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf";
1939 my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]);
1940 my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]";
1941 my $tunmtu = '';
1942 my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]);
1943 my $n2nfragment = '';
1944
1945 open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!";
1946 flock CLIENTCONF, 2;
1947
1948 my $zip = Archive::Zip->new();
1949 print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n";
1950 print CLIENTCONF "# \n";
1951 print CLIENTCONF "# User Security\n";
1952 print CLIENTCONF "user nobody\n";
1953 print CLIENTCONF "group nobody\n";
1954 print CLIENTCONF "persist-tun\n";
1955 print CLIENTCONF "persist-key\n";
1956 print CLIENTCONF "script-security 2\n";
1957 print CLIENTCONF "# IP/DNS for remote Server Gateway\n";
1958 print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n";
1959 print CLIENTCONF "float\n";
1960 print CLIENTCONF "# IP adresses of the VPN Subnet\n";
1961 print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n";
1962 print CLIENTCONF "# Server Gateway Network\n";
1963 print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n";
1964 print CLIENTCONF "# tun Device\n";
1965 print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\n";
1966 print CLIENTCONF "# Port and Protokoll\n";
1967 print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n";
1968
1969 if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') {
1970 print CLIENTCONF "proto tcp-client\n";
1971 print CLIENTCONF "# Packet size\n";
1972 if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]};
1973 print CLIENTCONF "tun-mtu $tunmtu\n";
1974 }
1975
1976 if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') {
1977 print CLIENTCONF "proto udp\n";
1978 print CLIENTCONF "# Paketsize\n";
1979 if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]};
1980 print CLIENTCONF "tun-mtu $tunmtu\n";
1981 if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";}
1982 if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";}
1983 }
1984 if (($confighash{$cgiparams{'KEY'}}[38] eq 'yes') ||
1985 ($confighash{$cgiparams{'KEY'}}[38] eq 'maybe') ||
1986 ($confighash{$cgiparams{'KEY'}}[38] eq 'no' )) {
1987 if (($confighash{$cgiparams{'KEY'}}[23] ne 'on') || ($confighash{$cgiparams{'KEY'}}[24] eq '')) {
1988 if ($tunmtu eq '1500' ) {
1989 print CLIENTCONF "mtu-disc $confighash{$cgiparams{'KEY'}}[38]\n";
1990 }
1991 }
1992 }
1993 print CLIENTCONF "ns-cert-type server\n";
1994 print CLIENTCONF "# Auth. Client\n";
1995 print CLIENTCONF "tls-client\n";
1996 print CLIENTCONF "# Cipher\n";
1997 print CLIENTCONF "cipher AES-256-CBC\n";
1998 if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") {
1999 print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n";
2000 $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";
2001 }
2002 if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') {
2003 print CLIENTCONF "# Enable Compression\n";
2004 print CLIENTCONF "comp-lzo\r\n";
2005 }
2006 print CLIENTCONF "# Debug Level\n";
2007 print CLIENTCONF "verb 3\n";
2008 print CLIENTCONF "# Tunnel check\n";
2009 print CLIENTCONF "keepalive 10 60\n";
2010 print CLIENTCONF "# Start as daemon\n";
2011 print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n";
2012 print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n";
2013 print CLIENTCONF "# Activate Management Interface and Port\n";
2014 if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"}
2015 else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"};
2016 print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n";
2017
2018
2019 close(CLIENTCONF);
2020
2021 $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n";
2022 my $status = $zip->writeToFileNamed($zippathname);
2023
2024 open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!";
2025 @fileholder = <DLFILE>;
2026 print "Content-Type:application/x-download\n";
2027 print "Content-Disposition:attachment;filename=$zipname\n\n";
2028 print @fileholder;
2029 exit (0);
2030 }
2031 else
2032 {
2033 my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip";
2034 my $zippathname = "$zippath$zipname";
2035 $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn";
2036
2037 ###
2038 # m.a.d net2net
2039 ###
2040
2041 open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!";
2042 flock CLIENTCONF, 2;
2043
2044 my $zip = Archive::Zip->new();
2045
2046 print CLIENTCONF "#OpenVPN Client conf\r\n";
2047 print CLIENTCONF "tls-client\r\n";
2048 print CLIENTCONF "client\r\n";
2049 print CLIENTCONF "nobind\r\n";
2050 print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\r\n";
2051 print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n";
2052
2053 # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500
2054 # or use configured value.
2055 if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' )
2056 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; }
2057 elsif ($vpnsettings{MSSFIX} eq 'on')
2058 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; }
2059 elsif (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
2060 ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
2061 ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' ))
2062 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; }
2063 else
2064 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu $vpnsettings{'DMTU'}\r\n"; }
2065
2066 if ( $vpnsettings{'ENABLED'} eq 'on'){
2067 print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n";
2068 if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){
2069 print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n";
2070 print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2071 }
2072 if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){
2073 print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n";
2074 print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2075 }
2076 } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){
2077 print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
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_ORANGE'} eq 'on' && (&haveOrangeNet())){
2083 print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2084 }
2085
2086 if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") {
2087 print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n";
2088 $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";
2089 } else {
2090 print CLIENTCONF "ca cacert.pem\r\n";
2091 print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n";
2092 print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n";
2093 $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n";
2094 $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";
2095 }
2096 print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n";
2097 if ($vpnsettings{DCOMPLZO} eq 'on') {
2098 print CLIENTCONF "comp-lzo\r\n";
2099 }
2100 print CLIENTCONF "verb 3\r\n";
2101 print CLIENTCONF "ns-cert-type server\r\n";
2102 print CLIENTCONF "tls-remote $vpnsettings{ROOTCERT_HOSTNAME}\r\n";
2103 if ($vpnsettings{MSSFIX} eq 'on') {
2104 print CLIENTCONF "mssfix\r\n";
2105 }
2106 if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) {
2107 print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n";
2108 }
2109
2110 # Check if a valid operating mode has been choosen and use it.
2111 if (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
2112 ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
2113 ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) {
2114 if(($vpnsettings{MSSFIX} ne 'on') || ($vpnsettings{FRAGMENT} eq '')) {
2115 print CLIENTCONF "mtu-disc $vpnsettings{'PMTU_DISCOVERY'}\r\n";
2116 }
2117 }
2118 close(CLIENTCONF);
2119
2120 $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n";
2121 my $status = $zip->writeToFileNamed($zippathname);
2122
2123 open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!";
2124 @fileholder = <DLFILE>;
2125 print "Content-Type:application/x-download\n";
2126 print "Content-Disposition:attachment;filename=$zipname\n\n";
2127 print @fileholder;
2128 exit (0);
2129 }
2130
2131
2132
2133 ###
2134 ### Remove connection
2135 ###
2136
2137
2138 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) {
2139 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
2140 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2141
2142 if ($confighash{$cgiparams{'KEY'}}) {
2143 # if ($vpnsettings{'ENABLED'} eq 'on' ||
2144 # $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2145 # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2146 # }
2147 #
2148 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`;
2149
2150 ###
2151 # m.a.d net2net
2152 ###
2153
2154 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') {
2155 my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf");
2156 my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
2157 unlink ($certfile);
2158 unlink ($conffile);
2159
2160 if (-e "${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") {
2161 rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!";
2162 }
2163 }
2164
2165 unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem");
2166 unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
2167
2168 # A.Marx CCD delete ccd files and routes
2169
2170
2171 if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]")
2172 {
2173 unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]";
2174 }
2175
2176 &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
2177 foreach my $key (keys %ccdroutehash) {
2178 if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){
2179 delete $ccdroutehash{$key};
2180 }
2181 }
2182 &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
2183
2184 &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash);
2185 foreach my $key (keys %ccdroute2hash) {
2186 if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){
2187 delete $ccdroute2hash{$key};
2188 }
2189 }
2190 &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash);
2191 &writeserverconf;
2192
2193
2194 # CCD end
2195
2196
2197 delete $confighash{$cgiparams{'KEY'}};
2198 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`;
2199 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2200
2201 #&writeserverconf();
2202 } else {
2203 $errormessage = $Lang::tr{'invalid key'};
2204 }
2205
2206
2207 ###
2208 ### Download PKCS12 file
2209 ###
2210 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) {
2211 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2212
2213 print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n";
2214 print "Content-Type: application/octet-stream\r\n\r\n";
2215 print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`;
2216 exit (0);
2217
2218 ###
2219 ### Display certificate
2220 ###
2221 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) {
2222 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2223
2224 if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") {
2225 &Header::showhttpheaders();
2226 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
2227 &Header::openbigbox('100%', 'LEFT', '', '');
2228 &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:");
2229 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`;
2230 $output = &Header::cleanhtml($output,"y");
2231 print "<pre>$output</pre>\n";
2232 &Header::closebox();
2233 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2234 &Header::closebigbox();
2235 &Header::closepage();
2236 exit(0);
2237 }
2238 ###
2239 ### Display Certificate Revoke List
2240 ###
2241 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) {
2242 # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2243
2244 if ( -f "${General::swroot}/ovpn/crls/cacrl.pem") {
2245 &Header::showhttpheaders();
2246 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
2247 &Header::openbigbox('100%', 'LEFT', '', '');
2248 &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:");
2249 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`;
2250 $output = &Header::cleanhtml($output,"y");
2251 print "<pre>$output</pre>\n";
2252 &Header::closebox();
2253 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2254 &Header::closebigbox();
2255 &Header::closepage();
2256 exit(0);
2257 }
2258
2259 ###
2260 ### Advanced Server Settings
2261 ###
2262
2263 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) {
2264 %cgiparams = ();
2265 %cahash = ();
2266 %confighash = ();
2267 my $disabled;
2268 &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams);
2269 read_routepushfile;
2270
2271
2272 # if ($cgiparams{'CLIENT2CLIENT'} eq '') {
2273 # $cgiparams{'CLIENT2CLIENT'} = 'on';
2274 # }
2275 ADV_ERROR:
2276 if ($cgiparams{'MAX_CLIENTS'} eq '') {
2277 $cgiparams{'MAX_CLIENTS'} = '100';
2278 }
2279 if ($cgiparams{'KEEPALIVE_1'} eq '') {
2280 $cgiparams{'KEEPALIVE_1'} = '10';
2281 }
2282 if ($cgiparams{'KEEPALIVE_2'} eq '') {
2283 $cgiparams{'KEEPALIVE_2'} = '60';
2284 }
2285 if ($cgiparams{'LOG_VERB'} eq '') {
2286 $cgiparams{'LOG_VERB'} = '3';
2287 }
2288 if ($cgiparams{'PMTU_DISCOVERY'} eq '') {
2289 $cgiparams{'PMTU_DISCOVERY'} = 'off';
2290 }
2291 $checked{'CLIENT2CLIENT'}{'off'} = '';
2292 $checked{'CLIENT2CLIENT'}{'on'} = '';
2293 $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED';
2294 $checked{'REDIRECT_GW_DEF1'}{'off'} = '';
2295 $checked{'REDIRECT_GW_DEF1'}{'on'} = '';
2296 $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED';
2297 $selected{'ENGINES'}{$cgiparams{'ENGINES'}} = 'SELECTED';
2298 $checked{'MSSFIX'}{'off'} = '';
2299 $checked{'MSSFIX'}{'on'} = '';
2300 $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED';
2301 $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\'';
2302 $selected{'LOG_VERB'}{'1'} = '';
2303 $selected{'LOG_VERB'}{'2'} = '';
2304 $selected{'LOG_VERB'}{'3'} = '';
2305 $selected{'LOG_VERB'}{'4'} = '';
2306 $selected{'LOG_VERB'}{'5'} = '';
2307 $selected{'LOG_VERB'}{'6'} = '';
2308 $selected{'LOG_VERB'}{'7'} = '';
2309 $selected{'LOG_VERB'}{'8'} = '';
2310 $selected{'LOG_VERB'}{'9'} = '';
2311 $selected{'LOG_VERB'}{'10'} = '';
2312 $selected{'LOG_VERB'}{'11'} = '';
2313 $selected{'LOG_VERB'}{'0'} = '';
2314 $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED';
2315
2316 &Header::showhttpheaders();
2317 &Header::openpage($Lang::tr{'status ovpn'}, 1, '');
2318 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
2319 if ($errormessage) {
2320 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
2321 print "<class name='base'>$errormessage\n";
2322 print "&nbsp;</class>\n";
2323 &Header::closebox();
2324 }
2325 &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'});
2326 print <<END
2327 <form method='post' enctype='multipart/form-data'>
2328 <table width='100%' border=0>
2329 <tr>
2330 <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td>
2331 </tr>
2332 <tr>
2333 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2334 </tr>
2335 <tr>
2336 <td class='base'>Domain</td>
2337 <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td>
2338 </tr>
2339 <tr>
2340 <td class='base'>DNS</td>
2341 <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td>
2342 </tr>
2343 <tr>
2344 <td class='base'>WINS</td>
2345 <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td>
2346 </tr>
2347 <tr>
2348 <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td>
2349 </tr>
2350 <tr>
2351 <td class='base'>$Lang::tr{'ovpn routes push'}</td>
2352 <td colspan='2'>
2353 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
2354 END
2355 ;
2356
2357 if ($cgiparams{'ROUTES_PUSH'} ne '')
2358 {
2359 print $cgiparams{'ROUTES_PUSH'};
2360 }
2361
2362 print <<END;
2363 </textarea></td>
2364 </tr>
2365 </tr>
2366 </table>
2367 <hr size='1'>
2368 <table width='100%'>
2369 <tr>
2370 <td class'base'><b>$Lang::tr{'misc-options'}</b></td>
2371 </tr>
2372 <tr>
2373 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
2374 </tr>
2375 <tr>
2376 <td class='base'>Client-To-Client</td>
2377 <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td>
2378 </tr>
2379 <tr>
2380 <td class='base'>Redirect-Gateway def1</td>
2381 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td>
2382 </tr>
2383 <tr>
2384 <td class='base'>Max-Clients</td>
2385 <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td>
2386 </tr>
2387 <tr>
2388 <td class='base'>Keepalive <br />
2389 (ping/ping-restart)</td>
2390 <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td>
2391 <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td>
2392 </tr>
2393 <tr>
2394 <td class='base'>fragment <br></td>
2395 <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td>
2396 <td>Default: <span class="base">1300</span></td>
2397 </tr>
2398 <tr>
2399 <td class='base'>mssfix</td>
2400 <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td>
2401 <td>Default: on</td>
2402 </tr>
2403
2404 <tr>
2405 <td class='base'>$Lang::tr{'ovpn mtu-disc'}</td>
2406 <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'}</td>
2407 <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'}</td>
2408 <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'}</td>
2409 <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'}</td>
2410 </tr>
2411 </table>
2412
2413 <!--
2414 <hr size='1'>
2415 <table width='100%'>
2416 <tr>
2417 <td class'base'><b>Crypto-Engines</b></td>
2418 </tr>
2419 <tr>
2420 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2421 </tr>
2422 <tr><td class='base'>Engines:</td>
2423 <td><select name='ENGINES'><option value="none" $selected{'ENGINES'}{'none'}>none</option>
2424 <option value="cryptodev" $selected{'ENGINES'}{'cryptodev'}>cryptodev</option>
2425 <option value="padlock" $selected{'ENGINES'}{'padlock'}>padlock</option>
2426 </select>
2427 </td>
2428 </table>
2429 -->
2430 <hr size='1'>
2431 <table width='100%'>
2432 <tr>
2433 <td class'base'><b>$Lang::tr{'log-options'}</b></td>
2434 </tr>
2435 <tr>
2436 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
2437 </tr>
2438
2439 <tr><td class='base'>VERB</td>
2440 <td><select name='LOG_VERB'><option value='1' $selected{'LOG_VERB'}{'1'}>1</option>
2441 <option value='2' $selected{'LOG_VERB'}{'2'}>2</option>
2442 <option value='3' $selected{'LOG_VERB'}{'3'}>3</option>
2443 <option value='4' $selected{'LOG_VERB'}{'4'}>4</option>
2444 <option value='5' $selected{'LOG_VERB'}{'5'}>5</option>
2445 <option value='6' $selected{'LOG_VERB'}{'6'}>6</option>
2446 <option value='7' $selected{'LOG_VERB'}{'7'}>7</option>
2447 <option value='8' $selected{'LOG_VERB'}{'8'}>8</option>
2448 <option value='9' $selected{'LOG_VERB'}{'9'}>9</option>
2449 <option value='10' $selected{'LOG_VERB'}{'10'}>10</option>
2450 <option value='11' $selected{'LOG_VERB'}{'11'}>11</option>
2451 <option value='0' $selected{'LOG_VERB'}{'0'}>0</option></select></td>
2452 </table><hr>
2453 END
2454
2455 if ( -e "/var/run/openvpn.pid"){
2456 print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br>
2457 $Lang::tr{'server restart'}<br><br>
2458 <hr>";
2459 print<<END
2460 <table width='100%'>
2461 <tr>
2462 <td>&nbsp;</td>
2463 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td>
2464 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td>
2465 <td>&nbsp;</td>
2466 </tr>
2467 </table>
2468 </form>
2469 END
2470 ;
2471
2472
2473 }else{
2474
2475 print<<END
2476 <table width='100%'>
2477 <tr>
2478 <td>&nbsp;</td>
2479 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td>
2480 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td>
2481 <td>&nbsp;</td>
2482 </tr>
2483 </table>
2484 </form>
2485 END
2486 ;
2487 }
2488 &Header::closebox();
2489 # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2490 &Header::closebigbox();
2491 &Header::closepage();
2492 exit(0);
2493
2494
2495 # A.Marx CCD Add,delete or edit CCD net
2496
2497 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} ||
2498 $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} ||
2499 $cgiparams{'ACTION'} eq "kill" ||
2500 $cgiparams{'ACTION'} eq "edit" ||
2501 $cgiparams{'ACTION'} eq 'editsave'){
2502 &Header::showhttpheaders();
2503 &Header::openpage($Lang::tr{'ccd net'}, 1, '');
2504 &Header::openbigbox('100%', 'LEFT', '', '');
2505
2506 if ($cgiparams{'ACTION'} eq "kill"){
2507 &delccdnet($cgiparams{'net'});
2508 }
2509
2510 if ($cgiparams{'ACTION'} eq 'editsave'){
2511 my ($a,$b) =split (/\|/,$cgiparams{'ccdname'});
2512 if ( $a ne $b){ &modccdnet($a,$b);}
2513 $cgiparams{'ccdname'}='';
2514 $cgiparams{'ccdsubnet'}='';
2515 }
2516
2517 if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) {
2518 &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'});
2519 }
2520 if ($errormessage) {
2521 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
2522 print "<class name='base'>$errormessage";
2523 print "&nbsp;</class>";
2524 &Header::closebox();
2525 }
2526 if ($cgiparams{'ACTION'} eq "edit"){
2527
2528 &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'});
2529
2530 print <<END
2531 <table width='100%' border=0>
2532 <tr><form method='post'>
2533 <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td>
2534 <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly /></td></tr>
2535 <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/>
2536 <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' />
2537 </td></tr>
2538 </table></form>
2539 END
2540 ;
2541 &Header::closebox();
2542
2543 &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} );
2544 print <<END