VPN Checksubnets: Now the remote subnets (OpenVPN/IPSec) are checked. If they are...
[people/teissler/ipfire-2.x.git] / html / cgi-bin / ovpnmain.cgi
CommitLineData
6e13d0a5 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
ab4cf06c 5# Copyright (C) 2007-2013 IPFire Team <info@ipfire.org> #
70df8302
MT
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
54fd0535
MT
21###
22# Based on IPFireCore 55
23###
6e13d0a5
MT
24use CGI;
25use CGI qw/:standard/;
26use Net::DNS;
ce9abb66 27use Net::Ping;
54fd0535 28use Net::Telnet;
6e13d0a5
MT
29use File::Copy;
30use File::Temp qw/ tempfile tempdir /;
31use strict;
32use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
eff2dbf8 33use Sort::Naturally;
6e13d0a5 34require '/var/ipfire/general-functions.pl';
6e13d0a5
MT
35require "${General::swroot}/lang.pl";
36require "${General::swroot}/header.pl";
37require "${General::swroot}/countries.pl";
38
39# enable only the following on debugging purpose
8c877a82
AM
40#use warnings;
41#use CGI::Carp 'fatalsToBrowser';
6e13d0a5 42#workaround to suppress a warning when a variable is used only once
8c877a82 43my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} );
6e13d0a5
MT
44undef (@dummy);
45
f2fdd0c1
CS
46my %color = ();
47my %mainsettings = ();
48&General::readhash("${General::swroot}/main/settings", \%mainsettings);
49&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
6e13d0a5
MT
50
51###
52### Initialize variables
53###
e81be1e1
AM
54my %ccdconfhash=();
55my %ccdroutehash=();
56my %ccdroute2hash=();
6e13d0a5
MT
57my %netsettings=();
58my %cgiparams=();
59my %vpnsettings=();
60my %checked=();
61my %confighash=();
62my %cahash=();
63my %selected=();
64my $warnmessage = '';
65my $errormessage = '';
66my %settings=();
54fd0535 67my $routes_push_file = '';
df9b48b7
AM
68my $confighost="${General::swroot}/fwhosts/customhosts";
69my $configgrp="${General::swroot}/fwhosts/customgroups";
70my $customnet="${General::swroot}/fwhosts/customnetworks";
71my $name;
99bfa85c 72my $col="";
6e13d0a5
MT
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'} = '';
54fd0535 86$cgiparams{'ROUTES_PUSH'} = '';
6e13d0a5 87$cgiparams{'DCOMPLZO'} = 'off';
a79fa1d6 88$cgiparams{'MSSFIX'} = '';
8c877a82 89$cgiparams{'number'} = '';
2ee746be 90$cgiparams{'PMTU_DISCOVERY'} = '';
54fd0535
MT
91$routes_push_file = "${General::swroot}/ovpn/routes_push";
92unless (-e $routes_push_file) { system("touch $routes_push_file"); }
8c877a82
AM
93unless (-e "${General::swroot}/ovpn/ccd.conf") { system("touch ${General::swroot}/ovpn/ccd.conf"); }
94unless (-e "${General::swroot}/ovpn/ccdroute") { system("touch ${General::swroot}/ovpn/ccdroute"); }
95unless (-e "${General::swroot}/ovpn/ccdroute2") { system("touch ${General::swroot}/ovpn/ccdroute2"); }
ce9abb66 96
6e13d0a5
MT
97&Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'});
98
99# prepare openvpn config file
100###
101### Useful functions
102###
c6c9630e
MT
103sub haveOrangeNet
104{
13211b21
CS
105 if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;}
106 if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}
c6c9630e
MT
107 return 0;
108}
109
110sub haveBlueNet
111{
13211b21 112 if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;}
c6c9630e 113 if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}
c6c9630e
MT
114 return 0;
115}
116
117sub 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
c6c9630e
MT
132sub 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
147sub 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
161sub 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}
c6c9630e 170sub checkportfw {
6945e463
AM
171 my $DPORT = shift;
172 my $DPROT = shift;
173 my %natconfig =();
6d8eb5de 174 my $confignat = "${General::swroot}/firewall/config";
6945e463
AM
175 $DPROT= uc ($DPROT);
176 &General::readhasharray($confignat, \%natconfig);
177 foreach my $key (sort keys %natconfig){
6945e463
AM
178 my @portarray = split (/\|/,$natconfig{$key}[30]);
179 foreach my $value (@portarray){
6945e463
AM
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 }
c6c9630e
MT
190 }
191 }
6945e463 192 return;
c6c9630e
MT
193}
194
195sub 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
212sub 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}
c6c9630e 224
c6c9630e 225sub writeserverconf {
54fd0535
MT
226 my %sovpnsettings = ();
227 my @temp = ();
c6c9630e 228 &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings);
54fd0535
MT
229 &read_routepushfile;
230
c6c9630e
MT
231 open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!";
232 flock CONF, 2;
233 print CONF "#OpenVPN Server conf\n";
234 print CONF "\n";
235 print CONF "daemon openvpnserver\n";
236 print CONF "writepid /var/run/openvpn.pid\n";
afabe9f7 237 print CONF "#DAN prepare OpenVPN for listening on blue and orange\n";
c6c9630e
MT
238 print CONF ";local $sovpnsettings{'VPN_IP'}\n";
239 print CONF "dev $sovpnsettings{'DDEVICE'}\n";
c6c9630e
MT
240 print CONF "proto $sovpnsettings{'DPROTOCOL'}\n";
241 print CONF "port $sovpnsettings{'DDEST_PORT'}\n";
2b29c22e 242 print CONF "script-security 3 system\n";
07675dc3 243 print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n";
6140e7e0 244 print CONF "client-config-dir /var/ipfire/ovpn/ccd\n";
c6c9630e
MT
245 print CONF "tls-server\n";
246 print CONF "ca /var/ipfire/ovpn/ca/cacert.pem\n";
247 print CONF "cert /var/ipfire/ovpn/certs/servercert.pem\n";
248 print CONF "key /var/ipfire/ovpn/certs/serverkey.pem\n";
249 print CONF "dh /var/ipfire/ovpn/ca/dh1024.pem\n";
250 my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'});
251 print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n";
8c877a82 252 #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n";
2ee746be
SS
253
254 # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500.
255 # If we doesn't use one of them, we can use the configured mtu value.
256 if ($sovpnsettings{'MSSFIX'} eq 'on')
257 { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; }
258 elsif ($sovpnsettings{'FRAGMENT'} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp')
259 { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; }
1647059d
SS
260 elsif (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
261 ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
262 ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' ))
2ee746be
SS
263 { print CONF "$sovpnsettings{'DDEVICE'}-mtu 1500\n"; }
264 else
265 { print CONF "$sovpnsettings{'DDEVICE'}-mtu $sovpnsettings{'DMTU'}\n"; }
266
54fd0535 267 if ($vpnsettings{'ROUTES_PUSH'} ne '') {
8c877a82
AM
268 @temp = split(/\n/,$vpnsettings{'ROUTES_PUSH'});
269 foreach (@temp)
270 {
271 @tempovpnsubnet = split("\/",&General::ipcidr2msk($_));
272 print CONF "push \"route " . $tempovpnsubnet[0]. " " . $tempovpnsubnet[1] . "\"\n";
273 }
54fd0535 274 }
8c877a82
AM
275# a.marx ccd
276 my %ccdconfhash=();
277 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
278 foreach my $key (keys %ccdconfhash) {
279 my $a=$ccdconfhash{$key}[1];
280 my ($b,$c) = split (/\//, $a);
281 print CONF "route $b ".&General::cidrtosub($c)."\n";
282 }
283 my %ccdroutehash=();
284 &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
285 foreach my $key (keys %ccdroutehash) {
286 foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){
287 my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]);
288 print CONF "route $a $b\n";
289 }
290 }
291# ccd end
54fd0535 292
8c877a82 293 if ($sovpnsettings{CLIENT2CLIENT} eq 'on') {
c6c9630e
MT
294 print CONF "client-to-client\n";
295 }
1de5c945
EK
296 if ($sovpnsettings{MSSFIX} eq 'on') {
297 print CONF "mssfix\n";
298 }
299 if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') {
300 print CONF "fragment $sovpnsettings{'FRAGMENT'}\n";
a79fa1d6 301 }
2ee746be 302
1647059d
SS
303 # Check if a valid operating mode has been choosen and use it.
304 if (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
305 ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
306 ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) {
307 print CONF "mtu-disc $sovpnsettings{'PMTU_DISCOVERY'}\n";
2ee746be
SS
308 }
309
c6c9630e
MT
310 if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) {
311 print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n";
312 }
313 print CONF "status-version 1\n";
4e17adad 314 print CONF "status /var/log/ovpnserver.log 30\n";
c6c9630e
MT
315 print CONF "cipher $sovpnsettings{DCIPHER}\n";
316 if ($sovpnsettings{DCOMPLZO} eq 'on') {
317 print CONF "comp-lzo\n";
318 }
319 if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') {
320 print CONF "push \"redirect-gateway def1\"\n";
321 }
322 if ($sovpnsettings{DHCP_DOMAIN} ne '') {
323 print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n";
324 }
325
326 if ($sovpnsettings{DHCP_DNS} ne '') {
327 print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n";
328 }
329
330 if ($sovpnsettings{DHCP_WINS} ne '') {
331 print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n";
332 }
333
334 if ($sovpnsettings{DHCP_WINS} eq '') {
335 print CONF "max-clients 100\n";
a79fa1d6 336 }
c6c9630e
MT
337 if ($sovpnsettings{DHCP_WINS} ne '') {
338 print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n";
339 }
1d0a260a 340 print CONF "tls-verify /usr/lib/openvpn/verify\n";
c6c9630e
MT
341 print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n";
342 print CONF "user nobody\n";
343 print CONF "group nobody\n";
344 print CONF "persist-key\n";
345 print CONF "persist-tun\n";
346 if ($sovpnsettings{LOG_VERB} ne '') {
347 print CONF "verb $sovpnsettings{LOG_VERB}\n";
348 } else {
349 print CONF "verb 3\n";
350 }
351 print CONF "\n";
352
353 close(CONF);
354}
8c877a82 355
c6c9630e 356sub emptyserverlog{
4e17adad 357 if (open(FILE, ">/var/log/ovpnserver.log")) {
c6c9630e
MT
358 flock FILE, 2;
359 print FILE "";
360 close FILE;
361 }
362
363}
364
8c877a82
AM
365sub delccdnet
366{
367 my %ccdconfhash = ();
368 my %ccdhash = ();
369 my $ccdnetname=$_[0];
370 if (-f "${General::swroot}/ovpn/ovpnconfig"){
371 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
372 foreach my $key (keys %ccdhash) {
373 if ($ccdhash{$key}[32] eq $ccdnetname) {
374 $errormessage=$Lang::tr{'ccd err hostinnet'};
375 return;
376 }
377 }
378 }
379 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
380 foreach my $key (keys %ccdconfhash) {
381 if ($ccdconfhash{$key}[0] eq $ccdnetname){
382 delete $ccdconfhash{$key};
383 }
384 }
385 &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
386
387 &writeserverconf;
388 return 0;
389}
390
391sub addccdnet
392{
393 my %ccdconfhash=();
394 my @ccdconf=();
395 my $ccdname=$_[0];
396 my $ccdnet=$_[1];
8c877a82
AM
397 my $subcidr;
398 my @ip2=();
399 my $checkup;
400 my $ccdip;
401 my $baseaddress;
290007b3
AM
402
403
404 #check name
405 if ($ccdname eq '')
406 {
407 $errormessage=$errormessage.$Lang::tr{'ccd err name'}."<br>";
408 return
409 }
410
411 if(!&General::validhostname($ccdname))
412 {
8c877a82
AM
413 $errormessage=$Lang::tr{'ccd err invalidname'};
414 return;
415 }
290007b3
AM
416
417 ($ccdip,$subcidr) = split (/\//,$ccdnet);
418 $subcidr=&General::iporsubtocidr($subcidr);
419 #check subnet
420 if ($subcidr > 30)
421 {
8c877a82
AM
422 $errormessage=$Lang::tr{'ccd err invalidnet'};
423 return;
424 }
290007b3
AM
425 #check ip
426 if (!&General::validipandmask($ccdnet)){
427 $errormessage=$Lang::tr{'ccd err invalidnet'};
428 return;
8c877a82 429 }
290007b3 430
e2429e8d 431 $errormessage=&General::checksubnets($ccdname,$ccdnet);
290007b3 432
8c877a82
AM
433
434 if (!$errormessage) {
435 my %ccdconfhash=();
436 $baseaddress=&General::getnetworkip($ccdip,$subcidr);
437 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
438 my $key = &General::findhasharraykey (\%ccdconfhash);
439 foreach my $i (0 .. 1) { $ccdconfhash{$key}[$i] = "";}
440 $ccdconfhash{$key}[0] = $ccdname;
441 $ccdconfhash{$key}[1] = $baseaddress."/".$subcidr;
442 &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
443 &writeserverconf;
444 $cgiparams{'ccdname'}='';
445 $cgiparams{'ccdsubnet'}='';
446 return 1;
447 }
448}
449
450sub modccdnet
451{
452
453 my $newname=$_[0];
454 my $oldname=$_[1];
455 my %ccdconfhash=();
456 my %ccdhash=();
457 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
458 foreach my $key (keys %ccdconfhash) {
459 if ($ccdconfhash{$key}[0] eq $oldname) {
460 foreach my $key1 (keys %ccdconfhash) {
461 if ($ccdconfhash{$key1}[0] eq $newname){
462 $errormessage=$errormessage.$Lang::tr{'ccd err netadrexist'};
463 return;
464 }else{
465 $ccdconfhash{$key}[0]= $newname;
466 &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
467 last;
468 }
469 }
470 }
471 }
472
473 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
474 foreach my $key (keys %ccdhash) {
475 if ($ccdhash{$key}[32] eq $oldname) {
476 $ccdhash{$key}[32]=$newname;
477 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
478 last;
479 }
480 }
481
482 return 0;
483}
484sub ccdmaxclients
485{
486 my $ccdnetwork=$_[0];
487 my @octets=();
488 my @subnet=();
489 @octets=split("\/",$ccdnetwork);
490 @subnet= split /\./, &General::cidrtosub($octets[1]);
491 my ($a,$b,$c,$d,$e);
492 $a=256-$subnet[0];
493 $b=256-$subnet[1];
494 $c=256-$subnet[2];
495 $d=256-$subnet[3];
496 $e=($a*$b*$c*$d)/4;
497 return $e-1;
498}
499
500sub getccdadresses
501{
502 my $ipin=$_[0];
503 my ($ip1,$ip2,$ip3,$ip4)=split /\./, $ipin;
504 my $cidr=$_[1];
505 chomp($cidr);
506 my $count=$_[2];
507 my $hasip=$_[3];
508 chomp($hasip);
509 my @iprange=();
510 my %ccdhash=();
511 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
80846568 512 $iprange[0]=$ip1.".".$ip2.".".$ip3.".".($ip4+2);
ac87f371 513 for (my $i=1;$i<=$count;$i++) {
8c877a82
AM
514 my $tmpip=$iprange[$i-1];
515 my $stepper=$i*4;
516 $iprange[$i]= &General::getnextip($tmpip,4);
517 }
518 my $r=0;
519 foreach my $key (keys %ccdhash) {
520 $r=0;
521 foreach my $tmp (@iprange){
522 my ($net,$sub) = split (/\//,$ccdhash{$key}[33]);
523 if ($net eq $tmp) {
524 if ( $hasip ne $ccdhash{$key}[33] ){
525 splice (@iprange,$r,1);
526 }
527 }
528 $r++;
529 }
530 }
531 return @iprange;
532}
533
534sub fillselectbox
535{
536 my $boxname=$_[1];
537 my ($ccdip,$subcidr) = split("/",$_[0]);
538 my $tz=$_[2];
539 my @allccdips=&getccdadresses($ccdip,$subcidr,&ccdmaxclients($ccdip."/".$subcidr),$tz);
540 print"<select name='$boxname' STYLE='font-family : arial; font-size : 9pt; width:130px;' >";
541 foreach (@allccdips) {
542 my $ip=$_."/30";
543 chomp($ip);
544 print "<option value='$ip' ";
545 if ( $ip eq $cgiparams{$boxname} ){
546 print"selected";
547 }
548 print ">$ip</option>";
549 }
550 print "</select>";
551}
552
553sub hostsinnet
554{
555 my $name=$_[0];
556 my %ccdhash=();
557 my $i=0;
558 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
559 foreach my $key (keys %ccdhash) {
560 if ($ccdhash{$key}[32] eq $name){ $i++;}
561 }
562 return $i;
563}
564
565sub check_routes_push
566{
567 my $val=$_[0];
568 my ($ip,$cidr) = split (/\//, $val);
569 ##check for existing routes in routes_push
570 if (-e "${General::swroot}/ovpn/routes_push") {
571 open(FILE,"${General::swroot}/ovpn/routes_push");
572 while (<FILE>) {
573 $_=~s/\s*$//g;
574
575 my ($ip2,$cidr2) = split (/\//,"$_");
576 my $val2=$ip2."/".&General::iporsubtodec($cidr2);
577
578 if($val eq $val2){
579 return 0;
580 }
581 #subnetcheck
582 if (&General::IpInSubnet ($ip,$ip2,&General::iporsubtodec($cidr2))){
583 return 0;
584 }
585 };
586 close(FILE);
587 }
588 return 1;
589}
590
591sub check_ccdroute
592{
593 my %ccdroutehash=();
594 my $val=$_[0];
595 my ($ip,$cidr) = split (/\//, $val);
596 #check for existing routes in ccdroute
597 &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
598 foreach my $key (keys %ccdroutehash) {
599 foreach my $i (1 .. $#{$ccdroutehash{$key}}) {
600 if (&General::iporsubtodec($val) eq $ccdroutehash{$key}[$i] && $ccdroutehash{$key}[0] ne $cgiparams{'NAME'}){
601 return 0;
602 }
603 my ($ip2,$cidr2) = split (/\//,$ccdroutehash{$key}[$i]);
604 #subnetcheck
605 if (&General::IpInSubnet ($ip,$ip2,$cidr2)&& $ccdroutehash{$key}[0] ne $cgiparams{'NAME'} ){
606 return 0;
607 }
608 }
609 }
610 return 1;
611}
612sub check_ccdconf
613{
614 my %ccdconfhash=();
615 my $val=$_[0];
616 my ($ip,$cidr) = split (/\//, $val);
617 #check for existing routes in ccdroute
618 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
619 foreach my $key (keys %ccdconfhash) {
620 if (&General::iporsubtocidr($val) eq $ccdconfhash{$key}[1]){
621 return 0;
622 }
623 my ($ip2,$cidr2) = split (/\//,$ccdconfhash{$key}[1]);
624 #subnetcheck
625 if (&General::IpInSubnet ($ip,$ip2,&General::cidrtosub($cidr2))){
626 return 0;
627 }
628
629 }
630 return 1;
631}
632
7c1d9faf
AH
633###
634# m.a.d net2net
635###
636
637sub validdotmask
638{
639 my $ipdotmask = $_[0];
640 if (&General::validip($ipdotmask)) { return 0; }
641 if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { }
642 my $mask = $2;
643 if (($mask =~ /\./ )) { return 0; }
644 return 1;
645}
54fd0535
MT
646
647# -------------------------------------------------------------------
648
649sub write_routepushfile
650{
651 open(FILE, ">$routes_push_file");
652 flock(FILE, 2);
653 if ($vpnsettings{'ROUTES_PUSH'} ne '') {
654 print FILE $vpnsettings{'ROUTES_PUSH'};
655 }
656 close(FILE);
657}
658
659sub read_routepushfile
660{
661 if (-e "$routes_push_file") {
662 open(FILE,"$routes_push_file");
663 delete $vpnsettings{'ROUTES_PUSH'};
664 while (<FILE>) { $vpnsettings{'ROUTES_PUSH'} .= $_ };
665 close(FILE);
666 $cgiparams{'ROUTES_PUSH'} = $vpnsettings{'ROUTES_PUSH'};
8c877a82 667
54fd0535
MT
668 }
669}
7c1d9faf
AH
670
671
c6c9630e
MT
672#hier die refresh page
673if ( -e "${General::swroot}/ovpn/gencanow") {
674 my $refresh = '';
675 $refresh = "<meta http-equiv='refresh' content='15;' />";
676 &Header::showhttpheaders();
677 &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh);
678 &Header::openbigbox('100%', 'center');
679 &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:");
680 print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n";
681 print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n";
682 &Header::closebox();
683 &Header::closebigbox();
684 &Header::closepage();
685 exit (0);
686}
687##hier die refresh page
688
6e13d0a5
MT
689
690###
691### OpenVPN Server Control
692###
693if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} ||
694 $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} ||
695 $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) {
6e13d0a5
MT
696 #start openvpn server
697 if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){
c6c9630e 698 &emptyserverlog();
6e13d0a5
MT
699 system('/usr/local/bin/openvpnctrl', '-s');
700 }
701 #stop openvpn server
702 if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){
6e13d0a5 703 system('/usr/local/bin/openvpnctrl', '-k');
c6c9630e 704 &emptyserverlog();
6e13d0a5
MT
705 }
706# #restart openvpn server
8c877a82 707# if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){
6e13d0a5 708#workarund, till SIGHUP also works when running as nobody
8c877a82
AM
709# system('/usr/local/bin/openvpnctrl', '-r');
710# &emptyserverlog();
711# }
6e13d0a5
MT
712}
713
714###
715### Save Advanced options
716###
717
718if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) {
719 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
720 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
721 #DAN this value has to leave.
722#new settings for daemon
723 $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'};
724 $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'};
725 $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'};
726 $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'};
727 $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'};
728 $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'};
729 $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'};
730 $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'};
731 $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'};
54fd0535 732 $vpnsettings{'ROUTES_PUSH'} = $cgiparams{'ROUTES_PUSH'};
2ee746be 733 $vpnsettings{'PMTU_DISCOVERY'} = $cgiparams{'PMTU_DISCOVERY'};
54fd0535 734 my @temp=();
6e13d0a5 735
a79fa1d6
JPT
736 if ($cgiparams{'FRAGMENT'} eq '') {
737 delete $vpnsettings{'FRAGMENT'};
738 } else {
739 if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) {
740 $errormessage = "Incorrect value, please insert only numbers.";
741 goto ADV_ERROR;
742 } else {
743 $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'};
744 }
745 }
746 if ($cgiparams{'MSSFIX'} ne 'on') {
1de5c945 747 delete $vpnsettings{'MSSFIX'};
a79fa1d6
JPT
748 } else {
749 $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'};
750 }
2ee746be 751
1647059d
SS
752 if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') ||
753 ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') ||
754 ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) {
755
2ee746be
SS
756 if (($cgiparams{'MSSFIX'} eq 'on') || ($cgiparams{'FRAGMENT'} ne '')) {
757 $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'};
758 goto ADV_ERROR;
759 }
760 }
761
6e13d0a5 762 if ($cgiparams{'DHCP_DOMAIN'} ne ''){
81da1b01 763 unless (&General::validdomainname($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) {
6e13d0a5
MT
764 $errormessage = $Lang::tr{'invalid input for dhcp domain'};
765 goto ADV_ERROR;
766 }
767 }
768 if ($cgiparams{'DHCP_DNS'} ne ''){
769 unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) {
770 $errormessage = $Lang::tr{'invalid input for dhcp dns'};
771 goto ADV_ERROR;
772 }
773 }
774 if ($cgiparams{'DHCP_WINS'} ne ''){
775 unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) {
776 $errormessage = $Lang::tr{'invalid input for dhcp wins'};
54fd0535
MT
777 goto ADV_ERROR;
778 }
779 }
780 if ($cgiparams{'ROUTES_PUSH'} ne ''){
781 @temp = split(/\n/,$cgiparams{'ROUTES_PUSH'});
782 undef $vpnsettings{'ROUTES_PUSH'};
8c877a82
AM
783
784 foreach my $tmpip (@temp)
54fd0535
MT
785 {
786 s/^\s+//g; s/\s+$//g;
8c877a82
AM
787
788 if ($tmpip)
54fd0535 789 {
8c877a82
AM
790 $tmpip=~s/\s*$//g;
791 unless (&General::validipandmask($tmpip)) {
792 $errormessage = "$tmpip ".$Lang::tr{'ovpn errmsg invalid ip or mask'};
793 goto ADV_ERROR;
54fd0535 794 }
8c877a82
AM
795 my ($ip, $cidr) = split("\/",&General::ipcidr2msk($tmpip));
796
54fd0535
MT
797 if ($ip eq $netsettings{'GREEN_NETADDRESS'} && $cidr eq $netsettings{'GREEN_NETMASK'}) {
798 $errormessage = $Lang::tr{'ovpn errmsg green already pushed'};
8c877a82
AM
799 goto ADV_ERROR;
800 }
801# a.marx ccd
802 my %ccdroutehash=();
803 &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
804 foreach my $key (keys %ccdroutehash) {
805 foreach my $i (1 .. $#{$ccdroutehash{$key}}) {
806 if ( $ip."/".$cidr eq $ccdroutehash{$key}[$i] ){
807 $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ;
808 goto ADV_ERROR;
809 }
810 my ($ip2,$cidr2) = split(/\//,$ccdroutehash{$key}[$i]);
811 if (&General::IpInSubnet ($ip,$ip2,$cidr2)){
812 $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ;
813 goto ADV_ERROR;
814 }
815 }
54fd0535 816 }
8c877a82
AM
817
818# ccd end
819
820 $vpnsettings{'ROUTES_PUSH'} .= $tmpip."\n";
54fd0535 821 }
8c877a82
AM
822 }
823 &write_routepushfile;
54fd0535 824 undef $vpnsettings{'ROUTES_PUSH'};
8e148dc3
NP
825 }
826 else {
827 undef $vpnsettings{'ROUTES_PUSH'};
828 &write_routepushfile;
6e13d0a5 829 }
6e13d0a5
MT
830 if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 255 )) {
831 $errormessage = $Lang::tr{'invalid input for max clients'};
832 goto ADV_ERROR;
833 }
834 if ($cgiparams{'KEEPALIVE_1'} ne '') {
835 if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) {
836 $errormessage = $Lang::tr{'invalid input for keepalive 1'};
837 goto ADV_ERROR;
838 }
839 }
840 if ($cgiparams{'KEEPALIVE_2'} ne ''){
841 if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) {
842 $errormessage = $Lang::tr{'invalid input for keepalive 2'};
843 goto ADV_ERROR;
844 }
845 }
846 if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){
847 $errormessage = $Lang::tr{'invalid input for keepalive 1:2'};
848 goto ADV_ERROR;
849 }
850
851 &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings);
c6c9630e 852 &writeserverconf();#hier ok
6e13d0a5
MT
853}
854
ce9abb66 855###
7c1d9faf 856# m.a.d net2net
ce9abb66
AH
857###
858
859if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server')
860{
c6c9630e 861
ce9abb66
AH
862my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'});
863my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'});
54fd0535 864my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]";
d96c89eb 865my $tunmtu = '';
531f0835
AH
866
867unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";}
868unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";}
ce9abb66
AH
869
870 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: $!";
871
872 flock SERVERCONF, 2;
7c1d9faf 873 print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n";
ce9abb66 874 print SERVERCONF "\n";
b278daf3 875 print SERVERCONF "# User Security\n";
ce9abb66
AH
876 print SERVERCONF "user nobody\n";
877 print SERVERCONF "group nobody\n";
878 print SERVERCONF "persist-tun\n";
879 print SERVERCONF "persist-key\n";
7c1d9faf 880 print SERVERCONF "script-security 2\n";
60f396d7 881 print SERVERCONF "# IP/DNS for remote Server Gateway\n";
c125d8a2
SS
882
883 if ($cgiparams{'REMOTE'} ne '') {
ce9abb66 884 print SERVERCONF "remote $cgiparams{'REMOTE'}\n";
c125d8a2
SS
885 }
886
b278daf3 887 print SERVERCONF "float\n";
60f396d7 888 print SERVERCONF "# IP adresses of the VPN Subnet\n";
ce9abb66 889 print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n";
60f396d7 890 print SERVERCONF "# Client Gateway Network\n";
54fd0535 891 print SERVERCONF "route $remsubnet[0] $remsubnet[1]\n";
60f396d7 892 print SERVERCONF "# tun Device\n";
ce9abb66 893 print SERVERCONF "dev tun\n";
60f396d7 894 print SERVERCONF "# Port and Protokol\n";
ce9abb66 895 print SERVERCONF "port $cgiparams{'DEST_PORT'}\n";
60f396d7
AH
896
897 if ($cgiparams{'PROTOCOL'} eq 'tcp') {
898 print SERVERCONF "proto tcp-server\n";
899 print SERVERCONF "# Packet size\n";
d96c89eb 900 if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}};
60f396d7 901 print SERVERCONF "tun-mtu $tunmtu\n";
d96c89eb 902 }
60f396d7
AH
903
904 if ($cgiparams{'PROTOCOL'} eq 'udp') {
905 print SERVERCONF "proto udp\n";
906 print SERVERCONF "# Paketsize\n";
907 if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}};
908 print SERVERCONF "tun-mtu $tunmtu\n";
54fd0535
MT
909 if ($cgiparams{'FRAGMENT'} ne '') {print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n";}
910 if ($cgiparams{'MSSFIX'} eq 'on') {print SERVERCONF "mssfix\n"; };
d96c89eb 911 }
1647059d
SS
912
913 # Check if a valid operating mode has been choosen and use it.
914 if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') ||
915 ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') ||
916 ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) {
2ee746be
SS
917 if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) {
918 if($cgiparams{'MTU'} eq '1500') {
919 print SERVERCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n";
920 }
921 }
922 }
60f396d7 923 print SERVERCONF "# Auth. Server\n";
ce9abb66
AH
924 print SERVERCONF "tls-server\n";
925 print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n";
926 print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n";
927 print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n";
928 print SERVERCONF "dh ${General::swroot}/ovpn/ca/dh1024.pem\n";
b278daf3 929 print SERVERCONF "# Cipher\n";
ce9abb66
AH
930 print SERVERCONF "cipher AES-256-CBC\n";
931 if ($cgiparams{'COMPLZO'} eq 'on') {
60f396d7 932 print SERVERCONF "# Enable Compression\n";
ce9abb66 933 print SERVERCONF "comp-lzo\r\n";
b278daf3 934 }
60f396d7 935 print SERVERCONF "# Debug Level\n";
ce9abb66 936 print SERVERCONF "verb 3\n";
b278daf3 937 print SERVERCONF "# Tunnel check\n";
ce9abb66 938 print SERVERCONF "keepalive 10 60\n";
60f396d7 939 print SERVERCONF "# Start as daemon\n";
ce9abb66
AH
940 print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n";
941 print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n";
60f396d7 942 print SERVERCONF "# Activate Management Interface and Port\n";
54fd0535
MT
943 if ($cgiparams{'OVPN_MGMT'} eq '') {print SERVERCONF "management localhost $cgiparams{'DEST_PORT'}\n"}
944 else {print SERVERCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"};
ce9abb66
AH
945 close(SERVERCONF);
946
947}
948
949###
7c1d9faf 950# m.a.d net2net
ce9abb66 951###
7c1d9faf 952
ce9abb66
AH
953if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client')
954{
955 my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'});
54fd0535 956 my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]";
ce9abb66 957 my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'});
d96c89eb 958 my $tunmtu = '';
54fd0535 959
531f0835
AH
960unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";}
961unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";}
ce9abb66
AH
962
963 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: $!";
964
965 flock CLIENTCONF, 2;
7c1d9faf 966 print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n";
ce9abb66 967 print CLIENTCONF "#\n";
b278daf3 968 print CLIENTCONF "# User Security\n";
ce9abb66
AH
969 print CLIENTCONF "user nobody\n";
970 print CLIENTCONF "group nobody\n";
971 print CLIENTCONF "persist-tun\n";
972 print CLIENTCONF "persist-key\n";
7c1d9faf 973 print CLIENTCONF "script-security 2\n";
60f396d7 974 print CLIENTCONF "# IP/DNS for remote Server Gateway\n";
ce9abb66 975 print CLIENTCONF "remote $cgiparams{'REMOTE'}\n";
b278daf3 976 print CLIENTCONF "float\n";
60f396d7 977 print CLIENTCONF "# IP adresses of the VPN Subnet\n";
ce9abb66 978 print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n";
60f396d7 979 print CLIENTCONF "# Server Gateway Network\n";
54fd0535 980 print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n";
60f396d7 981 print CLIENTCONF "# tun Device\n";
ce9abb66 982 print CLIENTCONF "dev tun\n";
60f396d7 983 print CLIENTCONF "# Port and Protokol\n";
ce9abb66 984 print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n";
60f396d7
AH
985
986 if ($cgiparams{'PROTOCOL'} eq 'tcp') {
987 print CLIENTCONF "proto tcp-client\n";
988 print CLIENTCONF "# Packet size\n";
d96c89eb 989 if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}};
60f396d7 990 print CLIENTCONF "tun-mtu $tunmtu\n";
d96c89eb 991 }
60f396d7
AH
992
993 if ($cgiparams{'PROTOCOL'} eq 'udp') {
994 print CLIENTCONF "proto udp\n";
995 print CLIENTCONF "# Paketsize\n";
996 if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}};
997 print CLIENTCONF "tun-mtu $tunmtu\n";
54fd0535
MT
998 if ($cgiparams{'FRAGMENT'} ne '') {print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n";}
999 if ($cgiparams{'MSSFIX'} eq 'on') {print CLIENTCONF "mssfix\n"; };
d96c89eb 1000 }
1647059d
SS
1001
1002 # Check if a valid operating mode has been choosen and use it.
1003 if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') ||
1004 ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') ||
1005 ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) {
2ee746be
SS
1006 if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) {
1007 if ($cgiparams{'MTU'} eq '1500') {
1008 print CLIENTCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n";
1009 }
1010 }
1647059d
SS
1011 }
1012
54fd0535 1013 print CLIENTCONF "ns-cert-type server\n";
ce9abb66
AH
1014 print CLIENTCONF "# Auth. Client\n";
1015 print CLIENTCONF "tls-client\n";
b278daf3 1016 print CLIENTCONF "# Cipher\n";
ce9abb66
AH
1017 print CLIENTCONF "cipher AES-256-CBC\n";
1018 print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n";
ce9abb66 1019 if ($cgiparams{'COMPLZO'} eq 'on') {
60f396d7 1020 print CLIENTCONF "# Enable Compression\n";
ce9abb66 1021 print CLIENTCONF "comp-lzo\r\n";
b278daf3 1022 }
ce9abb66
AH
1023 print CLIENTCONF "# Debug Level\n";
1024 print CLIENTCONF "verb 3\n";
b278daf3 1025 print CLIENTCONF "# Tunnel check\n";
ce9abb66 1026 print CLIENTCONF "keepalive 10 60\n";
60f396d7 1027 print CLIENTCONF "# Start as daemon\n";
ce9abb66
AH
1028 print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n";
1029 print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n";
60f396d7 1030 print CLIENTCONF "# Activate Management Interface and Port\n";
54fd0535
MT
1031 if ($cgiparams{'OVPN_MGMT'} eq '') {print CLIENTCONF "management localhost $cgiparams{'DEST_PORT'}\n"}
1032 else {print CLIENTCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"};
ce9abb66 1033 close(CLIENTCONF);
c6c9630e 1034
ce9abb66
AH
1035}
1036
6e13d0a5
MT
1037###
1038### Save main settings
1039###
ce9abb66
AH
1040
1041
6e13d0a5
MT
1042if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') {
1043 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
6e13d0a5
MT
1044 #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too,
1045 #DAN this value has to leave.
1046 if ($cgiparams{'ENABLED'} eq 'on'){
1047 unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) {
1048 $errormessage = $Lang::tr{'invalid input for hostname'};
c6c9630e 1049 goto SETTINGS_ERROR;
6e13d0a5
MT
1050 }
1051 }
6e13d0a5 1052 if ($errormessage) { goto SETTINGS_ERROR; }
48cc0e12 1053
6e13d0a5 1054 if ($cgiparams{'ENABLED'} eq 'on'){
6945e463 1055 &checkportfw($cgiparams{'DDEST_PORT'},$cgiparams{'DPROTOCOL'});
6e13d0a5 1056 }
6e13d0a5
MT
1057 if ($errormessage) { goto SETTINGS_ERROR; }
1058
1059 if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) {
c6c9630e
MT
1060 $errormessage = $Lang::tr{'ovpn subnet is invalid'};
1061 goto SETTINGS_ERROR;
1062 }
1063 my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'});
1064
1065 if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'},
1066 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1067 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}";
1068 goto SETTINGS_ERROR;
1069 }
1070
1071 if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'},
1072 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1073 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}";
1074 goto SETTINGS_ERROR;
1075 }
1076
1077 if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'},
1078 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1079 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}";
1080 goto SETTINGS_ERROR;
1081 }
1082
1083 if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'},
1084 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1085 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}";
1086 goto SETTINGS_ERROR;
1087 }
1088 open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.';
1089 while (<ALIASES>)
1090 {
1091 chomp($_);
1092 my @tempalias = split(/\,/,$_);
1093 if ($tempalias[1] eq 'on') {
1094 if (&General::IpInSubnet ($tempalias[0] ,
1095 $tmpovpnsubnet[0], $tmpovpnsubnet[1])) {
1096 $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]";
1097 }
1098 }
1099 }
1100 close(ALIASES);
6e13d0a5 1101 if ($errormessage ne ''){
c6c9630e 1102 goto SETTINGS_ERROR;
6e13d0a5
MT
1103 }
1104 if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) {
1105 $errormessage = $Lang::tr{'invalid input'};
1106 goto SETTINGS_ERROR;
1107 }
1108 if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) {
1109 $errormessage = $Lang::tr{'invalid mtu input'};
1110 goto SETTINGS_ERROR;
1111 }
1112
1113 unless (&General::validport($cgiparams{'DDEST_PORT'})) {
c6c9630e
MT
1114 $errormessage = $Lang::tr{'invalid port'};
1115 goto SETTINGS_ERROR;
6e13d0a5 1116 }
8c252e6a
EK
1117
1118 if ($cgiparams{'DDEST_PORT'} <= 1023) {
1119 $errormessage = $Lang::tr{'ovpn port in root range'};
1120 goto SETTINGS_ERROR;
1121 }
1122
6e13d0a5
MT
1123 $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'};
1124 $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'};
1125 $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'};
1126 $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'};
1127#new settings for daemon
1128 $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'};
1129 $vpnsettings{'DDEVICE'} = $cgiparams{'DDEVICE'};
1130 $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'};
1131 $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'};
1132 $vpnsettings{'DMTU'} = $cgiparams{'DMTU'};
1133 $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'};
1134 $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'};
3ffee04b
CS
1135#wrtie enable
1136
1137 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");}
1138 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");}
1139 if ( $vpnsettings{'ENABLED'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable 2>/dev/null");}
6e13d0a5
MT
1140#new settings for daemon
1141 &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings);
c6c9630e 1142 &writeserverconf();#hier ok
6e13d0a5
MT
1143SETTINGS_ERROR:
1144###
1145### Reset all step 2
1146###
1147}elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'} && $cgiparams{'AREUSURE'} eq 'yes') {
1148 my $file = '';
1149 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1150
1151 foreach my $key (keys %confighash) {
c6c9630e
MT
1152 if ($confighash{$key}[4] eq 'cert') {
1153 delete $confighash{$cgiparams{'$key'}};
1154 }
6e13d0a5
MT
1155 }
1156 while ($file = glob("${General::swroot}/ovpn/ca/*")) {
c6c9630e 1157 unlink $file
6e13d0a5
MT
1158 }
1159 while ($file = glob("${General::swroot}/ovpn/certs/*")) {
c6c9630e 1160 unlink $file
6e13d0a5
MT
1161 }
1162 while ($file = glob("${General::swroot}/ovpn/crls/*")) {
c6c9630e 1163 unlink $file
6e13d0a5 1164 }
c6c9630e 1165 &cleanssldatabase();
6e13d0a5
MT
1166 if (open(FILE, ">${General::swroot}/ovpn/caconfig")) {
1167 print FILE "";
1168 close FILE;
1169 }
1170 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
c6c9630e 1171 #&writeserverconf();
6e13d0a5
MT
1172###
1173### Reset all step 1
1174###
1175}elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'}) {
1176 &Header::showhttpheaders();
1177 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1178 &Header::openbigbox('100%', 'LEFT', '', '');
1179 &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'});
1180 print <<END
1181 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1182 <tr><td align='center'>
1183 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:
1184 $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}
1185 <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' />
1186 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr>
1187 </form></table>
1188END
1189 ;
1190 &Header::closebox();
1191 &Header::closebigbox();
1192 &Header::closepage();
1193 exit (0);
1194
1195###
1196### Upload CA Certificate
1197###
1198} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) {
1199 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1200
1201 if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) {
1202 $errormessage = $Lang::tr{'name must only contain characters'};
1203 goto UPLOADCA_ERROR;
1204 }
1205
1206 if (length($cgiparams{'CA_NAME'}) >60) {
1207 $errormessage = $Lang::tr{'name too long'};
1208 goto VPNCONF_ERROR;
1209 }
1210
1211 if ($cgiparams{'CA_NAME'} eq 'ca') {
1212 $errormessage = $Lang::tr{'name is invalid'};
1213 goto UPLOAD_CA_ERROR;
1214 }
1215
1216 # Check if there is no other entry with this name
1217 foreach my $key (keys %cahash) {
c6c9630e
MT
1218 if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) {
1219 $errormessage = $Lang::tr{'a ca certificate with this name already exists'};
1220 goto UPLOADCA_ERROR;
1221 }
6e13d0a5
MT
1222 }
1223
1224 if (ref ($cgiparams{'FH'}) ne 'Fh') {
c6c9630e
MT
1225 $errormessage = $Lang::tr{'there was no file upload'};
1226 goto UPLOADCA_ERROR;
6e13d0a5
MT
1227 }
1228 # Move uploaded ca to a temporary file
1229 (my $fh, my $filename) = tempfile( );
1230 if (copy ($cgiparams{'FH'}, $fh) != 1) {
c6c9630e
MT
1231 $errormessage = $!;
1232 goto UPLOADCA_ERROR;
6e13d0a5
MT
1233 }
1234 my $temp = `/usr/bin/openssl x509 -text -in $filename`;
c6c9630e
MT
1235 if ($temp !~ /CA:TRUE/i) {
1236 $errormessage = $Lang::tr{'not a valid ca certificate'};
1237 unlink ($filename);
1238 goto UPLOADCA_ERROR;
6e13d0a5 1239 } else {
c6c9630e
MT
1240 move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem");
1241 if ($? ne 0) {
1242 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1243 unlink ($filename);
1244 goto UPLOADCA_ERROR;
1245 }
6e13d0a5
MT
1246 }
1247
1248 my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`;
1249 $casubject =~ /Subject: (.*)[\n]/;
1250 $casubject = $1;
1251 $casubject =~ s+/Email+, E+;
1252 $casubject =~ s/ ST=/ S=/;
1253 $casubject = &Header::cleanhtml($casubject);
1254
1255 my $key = &General::findhasharraykey (\%cahash);
1256 $cahash{$key}[0] = $cgiparams{'CA_NAME'};
1257 $cahash{$key}[1] = $casubject;
1258 &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash);
c6c9630e
MT
1259# system('/usr/local/bin/ipsecctrl', 'R');
1260
6e13d0a5
MT
1261 UPLOADCA_ERROR:
1262
1263###
1264### Display ca certificate
1265###
1266} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) {
c6c9630e
MT
1267 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1268
1269 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") {
1270 &Header::showhttpheaders();
1271 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1272 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
1273 &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:");
1274 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
1275 $output = &Header::cleanhtml($output,"y");
1276 print "<pre>$output</pre>\n";
1277 &Header::closebox();
1278 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
1279 &Header::closebigbox();
1280 &Header::closepage();
1281 exit(0);
1282 } else {
1283 $errormessage = $Lang::tr{'invalid key'};
1284 }
1285
6e13d0a5
MT
1286###
1287### Download ca certificate
1288###
1289} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) {
1290 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1291
1292 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
1293 print "Content-Type: application/octet-stream\r\n";
1294 print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n";
1295 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
1296 exit(0);
1297 } else {
1298 $errormessage = $Lang::tr{'invalid key'};
1299 }
1300
1301###
1302### Remove ca certificate (step 2)
1303###
1304} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') {
1305 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1306 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1307
1308 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
1309 foreach my $key (keys %confighash) {
1310 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`;
1311 if ($test =~ /: OK/) {
c6c9630e
MT
1312 # Delete connection
1313# if ($vpnsettings{'ENABLED'} eq 'on' ||
1314# $vpnsettings{'ENABLED_BLUE'} eq 'on') {
1315# system('/usr/local/bin/ipsecctrl', 'D', $key);
1316# }
6e13d0a5
MT
1317 unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem");
1318 unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12");
1319 delete $confighash{$key};
1320 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
c6c9630e 1321# &writeipsecfiles();
6e13d0a5
MT
1322 }
1323 }
1324 unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem");
1325 delete $cahash{$cgiparams{'KEY'}};
1326 &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash);
c6c9630e 1327# system('/usr/local/bin/ipsecctrl', 'R');
6e13d0a5
MT
1328 } else {
1329 $errormessage = $Lang::tr{'invalid key'};
1330 }
1331###
1332### Remove ca certificate (step 1)
1333###
1334} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) {
1335 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1336 &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash);
1337
1338 my $assignedcerts = 0;
1339 if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) {
1340 foreach my $key (keys %confighash) {
1341 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`;
1342 if ($test =~ /: OK/) {
1343 $assignedcerts++;
1344 }
1345 }
1346 if ($assignedcerts) {
1347 &Header::showhttpheaders();
1348 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1349 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
1350 &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'});
1351 print <<END
1352 <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' />
1353 <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />
1354 <tr><td align='center'>
1355 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts
1356 $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'}
1357 <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' />
1358 <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr>
1359 </form></table>
1360END
1361 ;
1362 &Header::closebox();
1363 &Header::closebigbox();
1364 &Header::closepage();
1365 exit (0);
1366 } else {
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 }
1372 } else {
1373 $errormessage = $Lang::tr{'invalid key'};
1374 }
1375
1376###
1377### Display root certificate
1378###
c6c9630e
MT
1379}elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} ||
1380 $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) {
1381 my $output;
1382 &Header::showhttpheaders();
1383 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1384 &Header::openbigbox('100%', 'LEFT', '', '');
1385 if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) {
1386 &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:");
1387 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`;
1388 } else {
1389 &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:");
1390 $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`;
1391 }
1392 $output = &Header::cleanhtml($output,"y");
1393 print "<pre>$output</pre>\n";
1394 &Header::closebox();
1395 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
1396 &Header::closebigbox();
1397 &Header::closepage();
1398 exit(0);
1399
6e13d0a5
MT
1400###
1401### Download root certificate
1402###
1403}elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) {
1404 if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) {
1405 print "Content-Type: application/octet-stream\r\n";
1406 print "Content-Disposition: filename=cacert.pem\r\n\r\n";
1407 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`;
1408 exit(0);
1409 }
1410
1411###
1412### Download host certificate
1413###
1414}elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) {
1415 if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) {
1416 print "Content-Type: application/octet-stream\r\n";
1417 print "Content-Disposition: filename=servercert.pem\r\n\r\n";
1418 print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`;
1419 exit(0);
1420 }
1421###
1422### Form for generating a root certificate
1423###
1424}elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} ||
1425 $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
1426
1427 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
1428 if (-f "${General::swroot}/ovpn/ca/cacert.pem") {
1429 $errormessage = $Lang::tr{'valid root certificate already exists'};
1430 $cgiparams{'ACTION'} = '';
1431 goto ROOTCERT_ERROR;
1432 }
1433
1434 if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") {
1435 if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) {
1436 my $ipaddr = <IPADDR>;
1437 close IPADDR;
1438 chomp ($ipaddr);
1439 $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0];
1440 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') {
1441 $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr;
1442 }
1443 }
1444 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) {
1445
1446 if (ref ($cgiparams{'FH'}) ne 'Fh') {
1447 $errormessage = $Lang::tr{'there was no file upload'};
1448 goto ROOTCERT_ERROR;
1449 }
1450
1451 # Move uploaded certificate request to a temporary file
1452 (my $fh, my $filename) = tempfile( );
1453 if (copy ($cgiparams{'FH'}, $fh) != 1) {
1454 $errormessage = $!;
1455 goto ROOTCERT_ERROR;
1456 }
1457
1458 # Create a temporary dirctory
1459 my $tempdir = tempdir( CLEANUP => 1 );
1460
1461 # Extract the CA certificate from the file
1462 my $pid = open(OPENSSL, "|-");
1463 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1464 if ($pid) { # parent
1465 if ($cgiparams{'P12_PASS'} ne '') {
1466 print OPENSSL "$cgiparams{'P12_PASS'}\n";
1467 }
1468 close (OPENSSL);
1469 if ($?) {
1470 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1471 unlink ($filename);
1472 goto ROOTCERT_ERROR;
1473 }
1474 } else { # child
1475 unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys',
1476 '-in', $filename,
1477 '-out', "$tempdir/cacert.pem")) {
1478 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1479 unlink ($filename);
1480 goto ROOTCERT_ERROR;
1481 }
1482 }
1483
1484 # Extract the Host certificate from the file
1485 $pid = open(OPENSSL, "|-");
1486 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1487 if ($pid) { # parent
1488 if ($cgiparams{'P12_PASS'} ne '') {
1489 print OPENSSL "$cgiparams{'P12_PASS'}\n";
1490 }
1491 close (OPENSSL);
1492 if ($?) {
1493 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1494 unlink ($filename);
1495 goto ROOTCERT_ERROR;
1496 }
1497 } else { # child
1498 unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys',
1499 '-in', $filename,
1500 '-out', "$tempdir/hostcert.pem")) {
1501 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1502 unlink ($filename);
1503 goto ROOTCERT_ERROR;
1504 }
1505 }
1506
1507 # Extract the Host key from the file
1508 $pid = open(OPENSSL, "|-");
1509 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1510 if ($pid) { # parent
1511 if ($cgiparams{'P12_PASS'} ne '') {
1512 print OPENSSL "$cgiparams{'P12_PASS'}\n";
1513 }
1514 close (OPENSSL);
1515 if ($?) {
1516 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1517 unlink ($filename);
1518 goto ROOTCERT_ERROR;
1519 }
1520 } else { # child
1521 unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts',
1522 '-nodes',
1523 '-in', $filename,
1524 '-out', "$tempdir/serverkey.pem")) {
1525 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1526 unlink ($filename);
1527 goto ROOTCERT_ERROR;
1528 }
1529 }
1530
1531 move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem");
1532 if ($? ne 0) {
1533 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1534 unlink ($filename);
1535 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1536 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1537 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1538 goto ROOTCERT_ERROR;
1539 }
1540
1541 move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem");
1542 if ($? ne 0) {
1543 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1544 unlink ($filename);
1545 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1546 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1547 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1548 goto ROOTCERT_ERROR;
1549 }
1550
1551 move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem");
1552 if ($? ne 0) {
1553 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
1554 unlink ($filename);
1555 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1556 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1557 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1558 goto ROOTCERT_ERROR;
1559 }
1560
1561 goto ROOTCERT_SUCCESS;
1562
1563 } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') {
1564
1565 # Validate input since the form was submitted
1566 if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){
1567 $errormessage = $Lang::tr{'organization cant be empty'};
1568 goto ROOTCERT_ERROR;
1569 }
1570 if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) {
1571 $errormessage = $Lang::tr{'organization too long'};
1572 goto ROOTCERT_ERROR;
1573 }
1574 if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1575 $errormessage = $Lang::tr{'invalid input for organization'};
1576 goto ROOTCERT_ERROR;
1577 }
1578 if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){
1579 $errormessage = $Lang::tr{'hostname cant be empty'};
1580 goto ROOTCERT_ERROR;
1581 }
1582 unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) {
1583 $errormessage = $Lang::tr{'invalid input for hostname'};
1584 goto ROOTCERT_ERROR;
1585 }
1586 if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) {
1587 $errormessage = $Lang::tr{'invalid input for e-mail address'};
1588 goto ROOTCERT_ERROR;
1589 }
1590 if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) {
1591 $errormessage = $Lang::tr{'e-mail address too long'};
1592 goto ROOTCERT_ERROR;
1593 }
1594 if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1595 $errormessage = $Lang::tr{'invalid input for department'};
1596 goto ROOTCERT_ERROR;
1597 }
1598 if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1599 $errormessage = $Lang::tr{'invalid input for city'};
1600 goto ROOTCERT_ERROR;
1601 }
1602 if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) {
1603 $errormessage = $Lang::tr{'invalid input for state or province'};
1604 goto ROOTCERT_ERROR;
1605 }
1606 if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) {
1607 $errormessage = $Lang::tr{'invalid input for country'};
1608 goto ROOTCERT_ERROR;
1609 }
1610
1611 # Copy the cgisettings to vpnsettings and save the configfile
1612 $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'};
1613 $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'};
1614 $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'};
1615 $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'};
1616 $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'};
1617 $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'};
1618 $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'};
1619 &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings);
1620
1621 # Replace empty strings with a .
1622 (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./;
1623 (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./;
1624 (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./;
1625
1626 # refresh
c6c9630e 1627 #system ('/bin/touch', "${General::swroot}/ovpn/gencanow");
6e13d0a5
MT
1628
1629 # Create the CA certificate
1630 my $pid = open(OPENSSL, "|-");
1631 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1632 if ($pid) { # parent
1633 print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n";
1634 print OPENSSL "$state\n";
1635 print OPENSSL "$city\n";
1636 print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
1637 print OPENSSL "$ou\n";
1638 print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n";
1639 print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n";
1640 close (OPENSSL);
1641 if ($?) {
1642 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1643 unlink ("${General::swroot}/ovpn/ca/cakey.pem");
1644 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1645 goto ROOTCERT_ERROR;
1646 }
1647 } else { # child
1648 unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache',
1649 '-days', '999999', '-newkey', 'rsa:2048',
1650 '-keyout', "${General::swroot}/ovpn/ca/cakey.pem",
1651 '-out', "${General::swroot}/ovpn/ca/cacert.pem",
1652 '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) {
1653 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1654 goto ROOTCERT_ERROR;
1655 }
1656 }
1657
1658 # Create the Host certificate request
1659 $pid = open(OPENSSL, "|-");
1660 $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;};
1661 if ($pid) { # parent
1662 print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n";
1663 print OPENSSL "$state\n";
1664 print OPENSSL "$city\n";
1665 print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n";
1666 print OPENSSL "$ou\n";
1667 print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n";
1668 print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n";
1669 print OPENSSL ".\n";
1670 print OPENSSL ".\n";
1671 close (OPENSSL);
1672 if ($?) {
1673 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1674 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1675 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1676 goto ROOTCERT_ERROR;
1677 }
1678 } else { # child
1679 unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache',
1680 '-newkey', 'rsa:1024',
1681 '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem",
1682 '-out', "${General::swroot}/ovpn/certs/serverreq.pem",
1683 '-extensions', 'server',
1684 '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) {
1685 $errormessage = "$Lang::tr{'cant start openssl'}: $!";
1686 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1687 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1688 unlink ("${General::swroot}/ovpn/ca/cakey.pem");
1689 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1690 goto ROOTCERT_ERROR;
1691 }
1692 }
1693
1694 # Sign the host certificate request
1695 system('/usr/bin/openssl', 'ca', '-days', '999999',
1696 '-batch', '-notext',
1697 '-in', "${General::swroot}/ovpn/certs/serverreq.pem",
1698 '-out', "${General::swroot}/ovpn/certs/servercert.pem",
1699 '-extensions', 'server',
1700 '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf");
1701 if ($?) {
1702 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1703 unlink ("${General::swroot}/ovpn/ca/cakey.pem");
1704 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1705 unlink ("${General::swroot}/ovpn/serverkey.pem");
1706 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
1707 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
c6c9630e 1708 &newcleanssldatabase();
6e13d0a5
MT
1709 goto ROOTCERT_ERROR;
1710 } else {
1711 unlink ("${General::swroot}/ovpn/certs/serverreq.pem");
c6c9630e 1712 &deletebackupcert();
6e13d0a5
MT
1713 }
1714
1715 # Create an empty CRL
1716 system('/usr/bin/openssl', 'ca', '-gencrl',
1717 '-out', "${General::swroot}/ovpn/crls/cacrl.pem",
1718 '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" );
1719 if ($?) {
1720 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1721 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1722 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1723 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1724 unlink ("${General::swroot}/ovpn/crls/cacrl.pem");
c6c9630e 1725 &cleanssldatabase();
6e13d0a5 1726 goto ROOTCERT_ERROR;
c6c9630e
MT
1727# } else {
1728# &cleanssldatabase();
6e13d0a5
MT
1729 }
1730 # Create Diffie Hellmann Parameter
1731 system('/usr/bin/openssl', 'dhparam', '-rand', '/proc/interrupts:/proc/net/rt_cache',
1732 '-out', "${General::swroot}/ovpn/ca/dh1024.pem",
1733 '1024' );
1734 if ($?) {
1735 $errormessage = "$Lang::tr{'openssl produced an error'}: $?";
1736 unlink ("${General::swroot}/ovpn/certs/serverkey.pem");
1737 unlink ("${General::swroot}/ovpn/certs/servercert.pem");
1738 unlink ("${General::swroot}/ovpn/ca/cacert.pem");
1739 unlink ("${General::swroot}/ovpn/crls/cacrl.pem");
1740 unlink ("${General::swroot}/ovpn/ca/dh1024.pem");
c6c9630e 1741 &cleanssldatabase();
6e13d0a5 1742 goto ROOTCERT_ERROR;
c6c9630e
MT
1743# } else {
1744# &cleanssldatabase();
6e13d0a5
MT
1745 }
1746 goto ROOTCERT_SUCCESS;
1747 }
1748 ROOTCERT_ERROR:
1749 if ($cgiparams{'ACTION'} ne '') {
1750 &Header::showhttpheaders();
1751 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
1752 &Header::openbigbox('100%', 'LEFT', '', '');
1753 if ($errormessage) {
1754 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
1755 print "<class name='base'>$errormessage";
1756 print "&nbsp;</class>";
1757 &Header::closebox();
1758 }
1759 &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:");
1760 print <<END
1761 <form method='post' enctype='multipart/form-data'>
1762 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
1763 <tr><td width='30%' class='base'>$Lang::tr{'organization name'}:</td>
1764 <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td>
1765 <td width='35%' colspan='2'>&nbsp;</td></tr>
1766 <tr><td class='base'>$Lang::tr{'ipfires hostname'}:</td>
1767 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td>
1768 <td colspan='2'>&nbsp;</td></tr>
1769 <tr><td class='base'>$Lang::tr{'your e-mail'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1770 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td>
1771 <td colspan='2'>&nbsp;</td></tr>
1772 <tr><td class='base'>$Lang::tr{'your department'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1773 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td>
1774 <td colspan='2'>&nbsp;</td></tr>
1775 <tr><td class='base'>$Lang::tr{'city'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1776 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td>
1777 <td colspan='2'>&nbsp;</td></tr>
1778 <tr><td class='base'>$Lang::tr{'state or province'}:&nbsp;<img src='/blob.gif' alt'*' /></td>
1779 <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td>
1780 <td colspan='2'>&nbsp;</td></tr>
1781 <tr><td class='base'>$Lang::tr{'country'}:</td>
1782 <td class='base'><select name='ROOTCERT_COUNTRY'>
1783
1784END
1785 ;
1786 foreach my $country (sort keys %{Countries::countries}) {
1787 print "<option value='$Countries::countries{$country}'";
1788 if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) {
1789 print " selected='selected'";
1790 }
1791 print ">$country</option>";
1792 }
1793 print <<END
1794 </select></td>
1795 <td colspan='2'>&nbsp;</td></tr>
1796 <tr><td>&nbsp;</td>
1797 <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td>
1798 <td>&nbsp;</td><td>&nbsp;</td></tr>
1799 <tr><td class='base' colspan='4' align='left'>
1800 <img src='/blob.gif' valign='top' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td></tr>
1801 <tr><td class='base' colspan='4' align='left'>
1802 <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>:
1803 $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'}
1804 </td></tr>
1805 <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr>
1806 <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td>
1807 <td nowrap='nowrap'><input type='file' name='FH' size='32'></td>
1808 <td colspan='2'>&nbsp;</td></tr>
1809 <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:&nbsp;<img src='/blob.gif' alt='*' ></td>
1810 <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td>
1811 <td colspan='2'>&nbsp;</td></tr>
1812 <tr><td>&nbsp;</td>
1813 <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td>
1814 <td colspan='2'>&nbsp;</td></tr>
1815 <tr><td class='base' colspan='4' align='left'>
1816 <img src='/blob.gif' valign='top' al='*' >&nbsp;$Lang::tr{'this field may be blank'}</td></tr>
1817 </form></table>
1818END
1819 ;
1820 &Header::closebox();
1821
1822 &Header::closebigbox();
1823 &Header::closepage();
1824 exit(0)
1825 }
1826
1827 ROOTCERT_SUCCESS:
1828 system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem");
c6c9630e
MT
1829# if ($vpnsettings{'ENABLED'} eq 'on' ||
1830# $vpnsettings{'ENABLE_BLUE'} eq 'on') {
1831# system('/usr/local/bin/ipsecctrl', 'S');
1832# }
6e13d0a5
MT
1833
1834###
1835### Enable/Disable connection
1836###
ce9abb66
AH
1837
1838###
7c1d9faf 1839# m.a.d net2net
ce9abb66
AH
1840###
1841
6e13d0a5 1842}elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
c6c9630e
MT
1843
1844 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
6e13d0a5 1845 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
ce9abb66
AH
1846# my $n2nactive = '';
1847 my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`;
1848
6e13d0a5 1849 if ($confighash{$cgiparams{'KEY'}}) {
8c877a82
AM
1850 if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') {
1851 $confighash{$cgiparams{'KEY'}}[0] = 'on';
1852 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
ce9abb66 1853
8c877a82 1854 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
ce9abb66 1855 system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]);
8c877a82
AM
1856 }
1857 } else {
ce9abb66 1858
8c877a82
AM
1859 $confighash{$cgiparams{'KEY'}}[0] = 'off';
1860 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
ce9abb66 1861
8c877a82 1862 if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
ce9abb66 1863 if ($n2nactive ne ''){
8c877a82
AM
1864 system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]);
1865 }
ce9abb66 1866
8c877a82 1867 } else {
ce9abb66 1868 $errormessage = $Lang::tr{'invalid key'};
8c877a82 1869 }
ce9abb66
AH
1870 }
1871 }
6e13d0a5
MT
1872
1873###
1874### Download OpenVPN client package
1875###
ce9abb66
AH
1876
1877
6e13d0a5
MT
1878} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) {
1879 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
1880 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
1881 my $file = '';
1882 my $clientovpn = '';
1883 my @fileholder;
1884 my $tempdir = tempdir( CLEANUP => 1 );
1885 my $zippath = "$tempdir/";
ce9abb66
AH
1886
1887###
7c1d9faf
AH
1888# m.a.d net2net
1889###
ce9abb66
AH
1890
1891if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
1892
1893 my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip";
1894 my $zippathname = "$zippath$zipname";
1895 $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf";
1896 my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]);
54fd0535 1897 my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]";
ce9abb66 1898 my $tunmtu = '';
7c1d9faf 1899 my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]);
54fd0535 1900 my $n2nfragment = '';
ce9abb66
AH
1901
1902 open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!";
1903 flock CLIENTCONF, 2;
1904
1905 my $zip = Archive::Zip->new();
7c1d9faf 1906 print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n";
ce9abb66 1907 print CLIENTCONF "# \n";
b278daf3 1908 print CLIENTCONF "# User Security\n";
ce9abb66
AH
1909 print CLIENTCONF "user nobody\n";
1910 print CLIENTCONF "group nobody\n";
1911 print CLIENTCONF "persist-tun\n";
1912 print CLIENTCONF "persist-key\n";
7c1d9faf 1913 print CLIENTCONF "script-security 2\n";
60f396d7 1914 print CLIENTCONF "# IP/DNS for remote Server Gateway\n";
531f0835 1915 print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n";
b278daf3 1916 print CLIENTCONF "float\n";
60f396d7 1917 print CLIENTCONF "# IP adresses of the VPN Subnet\n";
ce9abb66 1918 print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n";
b278daf3 1919 print CLIENTCONF "# Server Gateway Network\n";
7c1d9faf 1920 print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n";
b278daf3 1921 print CLIENTCONF "# tun Device\n";
ce9abb66 1922 print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\n";
60f396d7 1923 print CLIENTCONF "# Port and Protokoll\n";
ce9abb66 1924 print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n";
60f396d7
AH
1925
1926 if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') {
1927 print CLIENTCONF "proto tcp-client\n";
1928 print CLIENTCONF "# Packet size\n";
d96c89eb 1929 if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]};
60f396d7 1930 print CLIENTCONF "tun-mtu $tunmtu\n";
d96c89eb 1931 }
60f396d7
AH
1932
1933 if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') {
1934 print CLIENTCONF "proto udp\n";
1935 print CLIENTCONF "# Paketsize\n";
1936 if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]};
1937 print CLIENTCONF "tun-mtu $tunmtu\n";
54fd0535 1938 if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";}
60f396d7 1939 if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";}
d96c89eb 1940 }
1647059d
SS
1941 if (($confighash{$cgiparams{'KEY'}}[38] eq 'yes') ||
1942 ($confighash{$cgiparams{'KEY'}}[38] eq 'maybe') ||
1943 ($confighash{$cgiparams{'KEY'}}[38] eq 'no' )) {
2ee746be
SS
1944 if (($confighash{$cgiparams{'KEY'}}[23] ne 'on') || ($confighash{$cgiparams{'KEY'}}[24] eq '')) {
1945 if ($tunmtu eq '1500' ) {
350f2980 1946 print CLIENTCONF "mtu-disc $confighash{$cgiparams{'KEY'}}[38]\n";
2ee746be
SS
1947 }
1948 }
1949 }
54fd0535 1950 print CLIENTCONF "ns-cert-type server\n";
ce9abb66
AH
1951 print CLIENTCONF "# Auth. Client\n";
1952 print CLIENTCONF "tls-client\n";
b278daf3 1953 print CLIENTCONF "# Cipher\n";
ce9abb66
AH
1954 print CLIENTCONF "cipher AES-256-CBC\n";
1955 if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") {
1956 print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n";
1957 $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";
1958 }
ce9abb66 1959 if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') {
b278daf3 1960 print CLIENTCONF "# Enable Compression\n";
ce9abb66 1961 print CLIENTCONF "comp-lzo\r\n";
b278daf3 1962 }
ce9abb66
AH
1963 print CLIENTCONF "# Debug Level\n";
1964 print CLIENTCONF "verb 3\n";
b278daf3 1965 print CLIENTCONF "# Tunnel check\n";
ce9abb66 1966 print CLIENTCONF "keepalive 10 60\n";
b278daf3 1967 print CLIENTCONF "# Start as daemon\n";
ce9abb66
AH
1968 print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n";
1969 print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n";
b278daf3 1970 print CLIENTCONF "# Activate Management Interface and Port\n";
54fd0535
MT
1971 if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"}
1972 else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"};
ce9abb66 1973 print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n";
531f0835 1974
ce9abb66
AH
1975
1976 close(CLIENTCONF);
1977
1978 $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n";
1979 my $status = $zip->writeToFileNamed($zippathname);
1980
1981 open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!";
1982 @fileholder = <DLFILE>;
1983 print "Content-Type:application/x-download\n";
1984 print "Content-Disposition:attachment;filename=$zipname\n\n";
1985 print @fileholder;
1986 exit (0);
1987}
1988else
1989{
1990 my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip";
1991 my $zippathname = "$zippath$zipname";
1992 $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn";
1993
1994###
7c1d9faf 1995# m.a.d net2net
ce9abb66
AH
1996###
1997
c6c9630e 1998 open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!";
6e13d0a5
MT
1999 flock CLIENTCONF, 2;
2000
2001 my $zip = Archive::Zip->new();
2002
8c877a82 2003 print CLIENTCONF "#OpenVPN Client conf\r\n";
6e13d0a5
MT
2004 print CLIENTCONF "tls-client\r\n";
2005 print CLIENTCONF "client\r\n";
4f6e3ae3 2006 print CLIENTCONF "nobind\r\n";
6e13d0a5 2007 print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\r\n";
c6c9630e 2008 print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n";
2ee746be
SS
2009
2010 # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500
2011 # or use configured value.
2012 if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' )
4f6e3ae3 2013 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; }
2ee746be 2014 elsif ($vpnsettings{MSSFIX} eq 'on')
4f6e3ae3 2015 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; }
1647059d
SS
2016 elsif (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
2017 ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
2018 ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' ))
4f6e3ae3 2019 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu 1500\r\n"; }
2ee746be
SS
2020 else
2021 { print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu $vpnsettings{'DMTU'}\r\n"; }
2022
6e13d0a5
MT
2023 if ( $vpnsettings{'ENABLED'} eq 'on'){
2024 print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n";
c6c9630e
MT
2025 if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){
2026 print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n";
2027 print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2028 }
2029 if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){
2030 print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n";
2031 print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2032 }
2033 } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){
2034 print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2035 if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){
2036 print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n";
2037 print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
2038 }
2039 } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){
2040 print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n";
6e13d0a5
MT
2041 }
2042
2043 if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") {
c6c9630e
MT
2044 print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n";
2045 $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", "$confighash{$cgiparams{'KEY'}}[1].p12") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1].p12\n";
6e13d0a5 2046 } else {
c6c9630e
MT
2047 print CLIENTCONF "ca cacert.pem\r\n";
2048 print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n";
2049 print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n";
2050 $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n";
2051 $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem", "$confighash{$cgiparams{'KEY'}}[1]cert.pem") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1]cert.pem\n";
6e13d0a5
MT
2052 }
2053 print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n";
2054 if ($vpnsettings{DCOMPLZO} eq 'on') {
2055 print CLIENTCONF "comp-lzo\r\n";
2056 }
2057 print CLIENTCONF "verb 3\r\n";
2058 print CLIENTCONF "ns-cert-type server\r\n";
a79fa1d6
JPT
2059 print CLIENTCONF "tls-remote $vpnsettings{ROOTCERT_HOSTNAME}\r\n";
2060 if ($vpnsettings{MSSFIX} eq 'on') {
2061 print CLIENTCONF "mssfix\r\n";
2062 }
74225cce 2063 if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) {
a79fa1d6
JPT
2064 print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n";
2065 }
1647059d
SS
2066
2067 # Check if a valid operating mode has been choosen and use it.
2068 if (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') ||
2069 ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') ||
2070 ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) {
2ee746be 2071 if(($vpnsettings{MSSFIX} ne 'on') || ($vpnsettings{FRAGMENT} eq '')) {
4f6e3ae3 2072 print CLIENTCONF "mtu-disc $vpnsettings{'PMTU_DISCOVERY'}\r\n";
2ee746be
SS
2073 }
2074 }
6e13d0a5 2075 close(CLIENTCONF);
ce9abb66 2076
6e13d0a5
MT
2077 $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n";
2078 my $status = $zip->writeToFileNamed($zippathname);
2079
2080 open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!";
2081 @fileholder = <DLFILE>;
2082 print "Content-Type:application/x-download\n";
2083 print "Content-Disposition:attachment;filename=$zipname\n\n";
2084 print @fileholder;
2085 exit (0);
ce9abb66
AH
2086 }
2087
2088
2089
6e13d0a5
MT
2090###
2091### Remove connection
2092###
ce9abb66
AH
2093
2094
6e13d0a5
MT
2095} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) {
2096 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
2097 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
c6c9630e
MT
2098
2099 if ($confighash{$cgiparams{'KEY'}}) {
2100# if ($vpnsettings{'ENABLED'} eq 'on' ||
2101# $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2102# system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2103# }
2104#
2105 my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`;
ce9abb66
AH
2106
2107###
7c1d9faf 2108# m.a.d net2net
ce9abb66 2109###
7c1d9faf 2110
8e6a8fd5 2111if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') {
ce9abb66 2112 my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf");
8e6a8fd5
MT
2113 my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
2114 unlink ($certfile);
2115 unlink ($conffile);
2116
2117 if (-e "${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") {
2118 rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!";
2119 }
ce9abb66 2120}
ce9abb66
AH
2121
2122 unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem");
8c877a82
AM
2123 unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
2124
2125# A.Marx CCD delete ccd files and routes
2126
2127
2128 if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]")
2129 {
2130 unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]";
2131 }
e81be1e1 2132
8c877a82
AM
2133 &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
2134 foreach my $key (keys %ccdroutehash) {
2135 if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){
2136 delete $ccdroutehash{$key};
2137 }
2138 }
2139 &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash);
e81be1e1 2140
8c877a82
AM
2141 &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash);
2142 foreach my $key (keys %ccdroute2hash) {
2143 if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){
2144 delete $ccdroute2hash{$key};
2145 }
2146 }
2147 &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash);
52d08bcb 2148 &writeserverconf;
8c877a82
AM
2149
2150
2151# CCD end
2152
2153
c6c9630e
MT
2154 delete $confighash{$cgiparams{'KEY'}};
2155 my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`;
2156 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
8c877a82 2157
c6c9630e 2158 #&writeserverconf();
6e13d0a5 2159 } else {
c6c9630e 2160 $errormessage = $Lang::tr{'invalid key'};
6e13d0a5 2161 }
b3c53248 2162 &General::firewall_reload();
ce9abb66 2163
6e13d0a5
MT
2164###
2165### Download PKCS12 file
2166###
2167} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) {
2168 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2169
2170 print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n";
2171 print "Content-Type: application/octet-stream\r\n\r\n";
2172 print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`;
2173 exit (0);
2174
2175###
2176### Display certificate
2177###
2178} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) {
2179 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2180
2181 if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") {
c6c9630e
MT
2182 &Header::showhttpheaders();
2183 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
2184 &Header::openbigbox('100%', 'LEFT', '', '');
2185 &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:");
2186 my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`;
2187 $output = &Header::cleanhtml($output,"y");
2188 print "<pre>$output</pre>\n";
2189 &Header::closebox();
2190 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2191 &Header::closebigbox();
2192 &Header::closepage();
2193 exit(0);
6e13d0a5
MT
2194 }
2195###
2196### Display Certificate Revoke List
2197###
2198} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) {
c6c9630e
MT
2199# &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2200
6e13d0a5 2201 if ( -f "${General::swroot}/ovpn/crls/cacrl.pem") {
c6c9630e
MT
2202 &Header::showhttpheaders();
2203 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
2204 &Header::openbigbox('100%', 'LEFT', '', '');
2205 &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:");
2206 my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`;
2207 $output = &Header::cleanhtml($output,"y");
2208 print "<pre>$output</pre>\n";
2209 &Header::closebox();
2210 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2211 &Header::closebigbox();
2212 &Header::closepage();
2213 exit(0);
6e13d0a5
MT
2214 }
2215
2216###
2217### Advanced Server Settings
2218###
2219
2220} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) {
2221 %cgiparams = ();
2222 %cahash = ();
2223 %confighash = ();
8c877a82 2224 my $disabled;
6e13d0a5 2225 &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams);
54fd0535 2226 read_routepushfile;
8c877a82
AM
2227
2228
c6c9630e
MT
2229# if ($cgiparams{'CLIENT2CLIENT'} eq '') {
2230# $cgiparams{'CLIENT2CLIENT'} = 'on';
2231# }
6e13d0a5
MT
2232ADV_ERROR:
2233 if ($cgiparams{'MAX_CLIENTS'} eq '') {
c6c9630e 2234 $cgiparams{'MAX_CLIENTS'} = '100';
6e13d0a5 2235 }
6e13d0a5 2236 if ($cgiparams{'KEEPALIVE_1'} eq '') {
c6c9630e 2237 $cgiparams{'KEEPALIVE_1'} = '10';
6e13d0a5
MT
2238 }
2239 if ($cgiparams{'KEEPALIVE_2'} eq '') {
c6c9630e 2240 $cgiparams{'KEEPALIVE_2'} = '60';
6e13d0a5
MT
2241 }
2242 if ($cgiparams{'LOG_VERB'} eq '') {
ae9f6139
MT
2243 $cgiparams{'LOG_VERB'} = '3';
2244 }
92b87e17
SS
2245 if ($cgiparams{'PMTU_DISCOVERY'} eq '') {
2246 $cgiparams{'PMTU_DISCOVERY'} = 'off';
2247 }
6e13d0a5
MT
2248 $checked{'CLIENT2CLIENT'}{'off'} = '';
2249 $checked{'CLIENT2CLIENT'}{'on'} = '';
2250 $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED';
2251 $checked{'REDIRECT_GW_DEF1'}{'off'} = '';
2252 $checked{'REDIRECT_GW_DEF1'}{'on'} = '';
2253 $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED';
a79fa1d6
JPT
2254 $selected{'ENGINES'}{$cgiparams{'ENGINES'}} = 'SELECTED';
2255 $checked{'MSSFIX'}{'off'} = '';
2256 $checked{'MSSFIX'}{'on'} = '';
2257 $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED';
2ee746be 2258 $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\'';
6e13d0a5
MT
2259 $selected{'LOG_VERB'}{'1'} = '';
2260 $selected{'LOG_VERB'}{'2'} = '';
2261 $selected{'LOG_VERB'}{'3'} = '';
2262 $selected{'LOG_VERB'}{'4'} = '';
2263 $selected{'LOG_VERB'}{'5'} = '';
2264 $selected{'LOG_VERB'}{'6'} = '';
2265 $selected{'LOG_VERB'}{'7'} = '';
2266 $selected{'LOG_VERB'}{'8'} = '';
2267 $selected{'LOG_VERB'}{'9'} = '';
2268 $selected{'LOG_VERB'}{'10'} = '';
2269 $selected{'LOG_VERB'}{'11'} = '';
2270 $selected{'LOG_VERB'}{'0'} = '';
2271 $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED';
8c877a82 2272
6e13d0a5
MT
2273 &Header::showhttpheaders();
2274 &Header::openpage($Lang::tr{'status ovpn'}, 1, '');
2275 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
2276 if ($errormessage) {
c6c9630e
MT
2277 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
2278 print "<class name='base'>$errormessage\n";
2279 print "&nbsp;</class>\n";
2280 &Header::closebox();
6e13d0a5
MT
2281 }
2282 &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'});
2283 print <<END
b376fae4 2284 <form method='post' enctype='multipart/form-data'>
631b67b7 2285 <table width='100%' border='0'>
6e13d0a5
MT
2286 <tr>
2287 <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td>
2288 </tr>
2289 <tr>
2290 <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
2291 </tr>
2292 <tr>
2293 <td class='base'>Domain</td>
8c877a82 2294 <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td>
6e13d0a5
MT
2295 </tr>
2296 <tr>
2297 <td class='base'>DNS</td>
2298 <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td>
2299 </tr>
2300 <tr>
2301 <td class='base'>WINS</td>
2302 <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td>
54fd0535
MT
2303 </tr>
2304 <tr>
2305 <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td>
2306 </tr>
2307 <tr>
2308 <td class='base'>$Lang::tr{'ovpn routes push'}</td>
2309 <td colspan='2'>
2310 <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'>
2311END
2312;
2313
2314if ($cgiparams{'ROUTES_PUSH'} ne '')
2315{
2316 print $cgiparams{'ROUTES_PUSH'};
2317}
2318
8c877a82 2319print <<END;
54fd0535
MT
2320</textarea></td>
2321</tr>
6e13d0a5
MT
2322 </tr>
2323</table>
2324<hr size='1'>
6e13d0a5
MT
2325 <table width='100%'>
2326 <tr>
2327 <td class'base'><b>$Lang::tr{'misc-options'}</b></td>
2328 </tr>
2329 <tr>
2ee746be 2330 <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
6e13d0a5
MT
2331 </tr>
2332 <tr>
2333 <td class='base'>Client-To-Client</td>
2334 <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td>
2335 </tr>
2336 <tr>
2337 <td class='base'>Redirect-Gateway def1</td>
2338 <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td>
2339 </tr>
2340 <tr>
2341 <td class='base'>Max-Clients</td>
a79fa1d6 2342 <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td>
6e13d0a5 2343 </tr>
a79fa1d6 2344 <tr>
f0ccae18 2345 <td class='base'>Keepalive <br />
a79fa1d6
JPT
2346 (ping/ping-restart)</td>
2347 <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td>
2348 <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td>
2349 </tr>
2350 <tr>
2351 <td class='base'>fragment <br></td>
2352 <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td>
1560bc6e 2353 <td>$Lang::tr{'openvpn default'}: <span class="base">1300</span></td>
60f396d7 2354 </tr>
a79fa1d6
JPT
2355 <tr>
2356 <td class='base'>mssfix</td>
2357 <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td>
1560bc6e 2358 <td>$Lang::tr{'openvpn default'}: on</td>
2ee746be
SS
2359 </tr>
2360
2361 <tr>
2362 <td class='base'>$Lang::tr{'ovpn mtu-disc'}</td>
2363 <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'}</td>
2364 <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'}</td>
2365 <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'}</td>
2366 <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'}</td>
2367 </tr>
a79fa1d6
JPT
2368</table>
2369
2370<!--
2371<hr size='1'>
2372 <table width='100%'>
2373 <tr>
2374 <td class'base'><b>Crypto-Engines</b></td>
2375 </tr>
2376 <tr>
2377 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
6e13d0a5 2378 </tr>
a79fa1d6
JPT
2379 <tr><td class='base'>Engines:</td>
2380 <td><select name='ENGINES'><option value="none" $selected{'ENGINES'}{'none'}>none</option>
2381 <option value="cryptodev" $selected{'ENGINES'}{'cryptodev'}>cryptodev</option>
2382 <option value="padlock" $selected{'ENGINES'}{'padlock'}>padlock</option>
2383 </select>
2384 </td>
6e13d0a5 2385</table>
a79fa1d6 2386-->
6e13d0a5
MT
2387<hr size='1'>
2388 <table width='100%'>
2389 <tr>
2390 <td class'base'><b>$Lang::tr{'log-options'}</b></td>
2391 </tr>
2392 <tr>
a79fa1d6 2393 <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td>
6e13d0a5
MT
2394 </tr>
2395
2396 <tr><td class='base'>VERB</td>
2397 <td><select name='LOG_VERB'><option value='1' $selected{'LOG_VERB'}{'1'}>1</option>
2398 <option value='2' $selected{'LOG_VERB'}{'2'}>2</option>
2399 <option value='3' $selected{'LOG_VERB'}{'3'}>3</option>
2400 <option value='4' $selected{'LOG_VERB'}{'4'}>4</option>
2401 <option value='5' $selected{'LOG_VERB'}{'5'}>5</option>
2402 <option value='6' $selected{'LOG_VERB'}{'6'}>6</option>
2403 <option value='7' $selected{'LOG_VERB'}{'7'}>7</option>
2404 <option value='8' $selected{'LOG_VERB'}{'8'}>8</option>
2405 <option value='9' $selected{'LOG_VERB'}{'9'}>9</option>
2406 <option value='10' $selected{'LOG_VERB'}{'10'}>10</option>
2407 <option value='11' $selected{'LOG_VERB'}{'11'}>11</option>
c6c9630e 2408 <option value='0' $selected{'LOG_VERB'}{'0'}>0</option></select></td>
8c877a82
AM
2409</table><hr>
2410END
2411
2412if ( -e "/var/run/openvpn.pid"){
2413print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br>
2414 $Lang::tr{'server restart'}<br><br>
2415 <hr>";
52d08bcb
AM
2416 print<<END
2417<table width='100%'>
2418<tr>
2419 <td>&nbsp;</td>
2420 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td>
2421 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td>
2422 <td>&nbsp;</td>
2423</tr>
2424</table>
2425</form>
2426END
2427;
2428
2429
2430}else{
8c877a82
AM
2431
2432print<<END
6e13d0a5
MT
2433<table width='100%'>
2434<tr>
2435 <td>&nbsp;</td>
2436 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td>
2437 <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td>
2438 <td>&nbsp;</td>
2439</tr>
2440</table>
2441</form>
2442END
2443;
52d08bcb 2444}
6e13d0a5 2445 &Header::closebox();
c6c9630e 2446# print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
6e13d0a5
MT
2447 &Header::closebigbox();
2448 &Header::closepage();
2449 exit(0);
2450
8c877a82
AM
2451
2452# A.Marx CCD Add,delete or edit CCD net
2453
2454} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} ||
2455 $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} ||
2456 $cgiparams{'ACTION'} eq "kill" ||
2457 $cgiparams{'ACTION'} eq "edit" ||
2458 $cgiparams{'ACTION'} eq 'editsave'){
2459 &Header::showhttpheaders();
2460 &Header::openpage($Lang::tr{'ccd net'}, 1, '');
2461 &Header::openbigbox('100%', 'LEFT', '', '');
2462
2463 if ($cgiparams{'ACTION'} eq "kill"){
2464 &delccdnet($cgiparams{'net'});
2465 }
2466
2467 if ($cgiparams{'ACTION'} eq 'editsave'){
2468 my ($a,$b) =split (/\|/,$cgiparams{'ccdname'});
2469 if ( $a ne $b){ &modccdnet($a,$b);}
5068ac38
AM
2470 $cgiparams{'ccdname'}='';
2471 $cgiparams{'ccdsubnet'}='';
8c877a82
AM
2472 }
2473
2474 if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) {
e2429e8d 2475 &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'});
8c877a82
AM
2476 }
2477 if ($errormessage) {
2478 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
2479 print "<class name='base'>$errormessage";
2480 print "&nbsp;</class>";
2481 &Header::closebox();
2482 }
2483if ($cgiparams{'ACTION'} eq "edit"){
2484
2485 &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'});
2486
2487 print <<END
631b67b7 2488 <table width='100%' border='0'>
8c877a82
AM
2489 <tr><form method='post'>
2490 <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td>
153cf640 2491 <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly='readonly' /></td></tr>
8c877a82
AM
2492 <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/>
2493 <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' />
2494 </td></tr>
2495 </table></form>
2496END
2497;
2498 &Header::closebox();
2499
2500 &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} );
2501 print <<END
2502 <table width='100%' border='0' cellpadding='0' cellspacing='1'>
2503 <tr>
2504 <td class='boldbase' align='center'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center'><b>$Lang::tr{'network'}</td><td class='boldbase' width='15%' align='center'><b>$Lang::tr{'ccd used'}</td><td width='3%'></td><td width='3%'></td></tr>
2505END
2506;
2507}
2508else{
2509 if (! -e "/var/run/openvpn.pid"){
2510 &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd add'});
2511 print <<END;
2512 <table width='100%' border='0'>
2513 <tr><form method='post'>
2514 <td colspan='4'>$Lang::tr{'ccd hint'}<br><br></td></tr>
2515 <tr>
2516 <td width='10%' nowrap='nwrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td>
2517 <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' /></td></tr>
2518 <tr><td colspan=4><hr /></td></tr><tr>
2519 <td colspan='4' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'ccd add'}' /><input type='submit' value='$Lang::tr{'add'}' /><input type='hidden' name='DOVPN_SUBNET' value='$cgiparams{'DOVPN_SUBNET'}'/></td></tr>
2520 </table></form>
2521END
2522
2523 &Header::closebox();
2524}
2525 &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} );
5068ac38
AM
2526 if ( -e "/var/run/openvpn.pid"){
2527 print "<b>$Lang::tr{'attention'}:</b><br>";
2528 print "$Lang::tr{'ccd noaddnet'}<br><hr>";
2529 }
2530
8c877a82 2531 print <<END
99bfa85c 2532 <table width='100%' cellpadding='0' cellspacing='1'>
8c877a82
AM
2533 <tr>
2534 <td class='boldbase' align='center' nowrap='nowrap' width='20%'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center' width='8%'><b>$Lang::tr{'network'}</td><td class='boldbase' width='8%' align='center' nowrap='nowrap'><b>$Lang::tr{'ccd used'}</td><td width='1%' align='center'></td><td width='1%' align='center'></td></tr>
2535END
2536;
2537}
2538 my %ccdconfhash=();
2539 &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
2540 my @ccdconf=();
2541 my $count=0;
df9b48b7 2542 foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) {
8c877a82
AM
2543 @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]);
2544 $count++;
2545 my $ccdhosts = &hostsinnet($ccdconf[0]);
2546 if ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";}
2547 else{ print" <tr bgcolor='$color{'color20'}'>";}
2548 print"<td>$ccdconf[0]</td><td align='center'>$ccdconf[1]</td><td align='center'>$ccdhosts/".(&ccdmaxclients($ccdconf[1])+1)."</td><td>";
2549print <<END
2550 <form method='post' />
f8aa0679 2551 <input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
8c877a82
AM
2552 <input type='hidden' name='ACTION' value='edit'/>
2553 <input type='hidden' name='ccdname' value='$ccdconf[0]' />
2554 <input type='hidden' name='ccdsubnet' value='$ccdconf[1]' />
2555 </form></td>
2556 <form method='post' />
2557 <td><input type='hidden' name='ACTION' value='kill'/>
2558 <input type='hidden' name='number' value='$count' />
2559 <input type='hidden' name='net' value='$ccdconf[0]' />
f8aa0679 2560 <input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' /></form></td></tr>
8c877a82
AM
2561END
2562;
2563 }
2564 print "</table></form>";
2565 &Header::closebox();
2566 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2567 &Header::closebigbox();
2568 &Header::closepage();
2569 exit(0);
2570
2571#END CCD
2572
6e13d0a5
MT
2573###
2574### Openvpn Connections Statistics
2575###
2576} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) {
2577 &Header::showhttpheaders();
2578 &Header::openpage($Lang::tr{'ovpn con stat'}, 1, '');
2579 &Header::openbigbox('100%', 'LEFT', '', '');
2580 &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'});
2581
2582#
2583# <td><b>$Lang::tr{'protocol'}</b></td>
2584# protocol temp removed
2585 print <<END
99bfa85c 2586 <table width='100%' cellpadding='2' cellspacing='0' class='tbl'>
6e13d0a5 2587 <tr>
99bfa85c
AM
2588 <th><b>$Lang::tr{'common name'}</b></th>
2589 <th><b>$Lang::tr{'real address'}</b></th>
2590 <th><b>$Lang::tr{'virtual address'}</b></th>
2591 <th><b>$Lang::tr{'loged in at'}</b></th>
2592 <th><b>$Lang::tr{'bytes sent'}</b></th>
2593 <th><b>$Lang::tr{'bytes received'}</b></th>
2594 <th><b>$Lang::tr{'last activity'}</b></th>
6e13d0a5
MT
2595 </tr>
2596END
2597;
4e17adad 2598 my $filename = "/var/log/ovpnserver.log";
6e13d0a5
MT
2599 open(FILE, $filename) or die 'Unable to open config file.';
2600 my @current = <FILE>;
2601 close(FILE);
2602 my @users =();
2603 my $status;
2604 my $uid = 0;
2605 my $cn;
2606 my @match = ();
2607 my $proto = "udp";
2608 my $address;
2609 my %userlookup = ();
2610 foreach my $line (@current)
2611 {
2612 chomp($line);
2613 if ( $line =~ /^Updated,(.+)/){
2614 @match = split( /^Updated,(.+)/, $line);
2615 $status = $match[1];
2616 }
c6c9630e 2617#gian
6e13d0a5
MT
2618 if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) {
2619 @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line);
2620 if ($match[1] ne "Common Name") {
2621 $cn = $match[1];
2622 $userlookup{$match[2]} = $uid;
2623 $users[$uid]{'CommonName'} = $match[1];
2624 $users[$uid]{'RealAddress'} = $match[2];
c6c9630e
MT
2625 $users[$uid]{'BytesReceived'} = &sizeformat($match[3]);
2626 $users[$uid]{'BytesSent'} = &sizeformat($match[4]);
6e13d0a5
MT
2627 $users[$uid]{'Since'} = $match[5];
2628 $users[$uid]{'Proto'} = $proto;
2629 $uid++;
2630 }
2631 }
2632 if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) {
2633 @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line);
2634 if ($match[1] ne "Virtual Address") {
2635 $address = $match[3];
2636 #find the uid in the lookup table
2637 $uid = $userlookup{$address};
2638 $users[$uid]{'VirtualAddress'} = $match[1];
2639 $users[$uid]{'LastRef'} = $match[4];
2640 }
2641 }
2642 }
2643 my $user2 = @users;
2644 if ($user2 >= 1){
99bfa85c 2645 for (my $idx = 1; $idx <= $user2; $idx++){
6e13d0a5 2646 if ($idx % 2) {
99bfa85c
AM
2647 print "<tr>";
2648 $col="bgcolor='$color{'color22'}'";
2649 } else {
2650 print "<tr>";
2651 $col="bgcolor='$color{'color20'}'";
6e13d0a5 2652 }
99bfa85c
AM
2653 print "<td align='left' $col>$users[$idx-1]{'CommonName'}</td>";
2654 print "<td align='left' $col>$users[$idx-1]{'RealAddress'}</td>";
2655 print "<td align='left' $col>$users[$idx-1]{'VirtualAddress'}</td>";
2656 print "<td align='left' $col>$users[$idx-1]{'Since'}</td>";
2657 print "<td align='left' $col>$users[$idx-1]{'BytesSent'}</td>";
2658 print "<td align='left' $col>$users[$idx-1]{'BytesReceived'}</td>";
2659 print "<td align='left' $col>$users[$idx-1]{'LastRef'}</td>";
2660 }
2661 }
6e13d0a5
MT
2662
2663 print "</table>";
2664 print <<END
2665 <table width='100%' border='0' cellpadding='2' cellspacing='0'>
2666 <tr><td></td></tr>
2667 <tr><td></td></tr>
2668 <tr><td></td></tr>
2669 <tr><td></td></tr>
2670 <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr>
2671 </table>
2672END
2673;
2674 &Header::closebox();
2675 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
2676 &Header::closebigbox();
2677 &Header::closepage();
2678 exit(0);
2679
2680###
2681### Download Certificate
2682###
2683} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) {
2684 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
c6c9630e 2685
6e13d0a5 2686 if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") {
c6c9630e
MT
2687 print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n";
2688 print "Content-Type: application/octet-stream\r\n\r\n";
2689 print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`;
2690 exit (0);
2691 }
2692
2693###
2694### Enable/Disable connection
2695###
ce9abb66 2696
c6c9630e
MT
2697} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) {
2698
2699 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
2700 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2701
2702 if ($confighash{$cgiparams{'KEY'}}) {
ce9abb66 2703 if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') {
c6c9630e
MT
2704 $confighash{$cgiparams{'KEY'}}[0] = 'on';
2705 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2706 #&writeserverconf();
2707# if ($vpnsettings{'ENABLED'} eq 'on' ||
2708# $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2709# system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2710# }
2711 } else {
2712 $confighash{$cgiparams{'KEY'}}[0] = 'off';
2713# if ($vpnsettings{'ENABLED'} eq 'on' ||
2714# $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2715# system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2716# }
2717 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2718 #&writeserverconf();
2719 }
2720 } else {
2721 $errormessage = $Lang::tr{'invalid key'};
6e13d0a5
MT
2722 }
2723
2724###
2725### Restart connection
2726###
2727} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) {
2728 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
2729 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2730
2731 if ($confighash{$cgiparams{'KEY'}}) {
c6c9630e
MT
2732# if ($vpnsettings{'ENABLED'} eq 'on' ||
2733# $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2734# system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'});
2735# }
6e13d0a5 2736 } else {
c6c9630e 2737 $errormessage = $Lang::tr{'invalid key'};
6e13d0a5
MT
2738 }
2739
2740###
c6c9630e 2741### Remove connection
6e13d0a5 2742###
c6c9630e
MT
2743} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) {
2744 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
2745 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2746
2747 if ($confighash{$cgiparams{'KEY'}}) {
2748# if ($vpnsettings{'ENABLED'} eq 'on' ||
2749# $vpnsettings{'ENABLED_BLUE'} eq 'on') {
2750# system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'});
2751# }
2752 unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem");
2753 unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
2754 delete $confighash{$cgiparams{'KEY'}};
2755 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2756 #&writeserverconf();
2757 } else {
2758 $errormessage = $Lang::tr{'invalid key'};
2759 }
ce9abb66
AH
2760#test33
2761
2762###
2763### Choose between adding a host-net or net-net connection
2764###
2765
2766###
7c1d9faf 2767# m.a.d net2net
ce9abb66
AH
2768###
2769
2770} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') {
2771 &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
2772 &Header::showhttpheaders();
2773 &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
2774 &Header::openbigbox('100%', 'LEFT', '', '');
2775 &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'});
b278daf3
AH
2776
2777if ( -s "${General::swroot}/ovpn/settings") {
2778
ce9abb66
AH
2779 print <<END
2780 <b>$Lang::tr{'connection type'}:</b><br />
8c877a82 2781 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
ce9abb66
AH
2782 <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
2783 <td class='base'>$Lang::tr{'host to net vpn'}</td></tr>
2784 <tr><td><input type='radio' name='TYPE' value='net' /></td>
2785 <td class='base'>$Lang::tr{'net to net vpn'}</td></tr>
2786 <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
2787 <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr>
2788 <tr><td>&nbsp;</td><td class='base'><input type='file' name='FH' size='30'></td></tr>
54fd0535 2789 <tr><td>&nbsp;</td><td>Import Connection Name <img src='/blob.gif' /></td></tr>
1560bc6e 2790 <tr><td>&nbsp;</td><td class='base'><input type='text' name='n2nname' size='30'>$Lang::tr{'openvpn default'}: Client Packagename</td></tr>
54fd0535 2791 <tr><td colspan='3'><hr /></td></tr>
8c877a82 2792 <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr>
54fd0535 2793 <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td></tr>
ce9abb66
AH
2794 </form></table>
2795END
2796 ;
8c877a82 2797
ce9abb66 2798
b278daf3
AH
2799} else {
2800 print <<END
2801 <b>$Lang::tr{'connection type'}:</b><br />
8c877a82 2802 <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data">
b278daf3 2803 <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr>
8c877a82 2804 <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr>
b278daf3
AH
2805 </form></table>
2806END
2807 ;
2808
2809}
2810
ce9abb66
AH
2811 &Header::closebox();
2812 &Header::closebigbox();
2813 &Header::closepage();
2814 exit (0);
2815
2816###
7c1d9faf 2817# m.a.d net2net
ce9abb66
AH
2818###
2819
2820} elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){
2821
2822 my @firen2nconf;
2823 my @confdetails;
2824 my $uplconffilename ='';
54fd0535 2825 my $uplconffilename2 ='';
ce9abb66 2826 my $uplp12name = '';
54fd0535 2827 my $uplp12name2 = '';
ce9abb66
AH
2828 my @rem_subnet;
2829 my @rem_subnet2;
2830 my @tmposupnet3;
2831 my $key;
54fd0535 2832 my @n2nname;
ce9abb66
AH
2833
2834 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
2835
2836# Check if a file is uploaded
2837
2838 if (ref ($cgiparams{'FH'}) ne 'Fh') {
2839 $errormessage = $Lang::tr{'there was no file upload'};
2840 goto N2N_ERROR;
2841 }
2842
2843# Move uploaded IPfire n2n package to temporary file
2844
2845 (my $fh, my $filename) = tempfile( );
2846 if (copy ($cgiparams{'FH'}, $fh) != 1) {
2847 $errormessage = $!;
2848 goto N2N_ERROR;
2849 }
2850
2851 my $zip = Archive::Zip->new();
2852 my $zipName = $filename;
2853 my $status = $zip->read( $zipName );
2854 if ($status != AZ_OK) {
2855 $errormessage = "Read of $zipName failed\n";
2856 goto N2N_ERROR;
2857 }
2858
2859 my $tempdir = tempdir( CLEANUP => 1 );
2860 my @files = $zip->memberNames();
2861 for(@files) {
2862 $zip->extractMemberWithoutPaths($_,"$tempdir/$_");
2863 }
2864 my $countfiles = @files;
2865
2866# Check if we have not more then 2 files
2867
2868 if ( $countfiles == 2){
2869 foreach (@files){
2870 if ( $_ =~ /.conf$/){
2871 $uplconffilename = $_;
2872 }
2873 if ( $_ =~ /.p12$/){
2874 $uplp12name = $_;
2875 }
2876 }
2877 if (($uplconffilename eq '') || ($uplp12name eq '')){
2878 $errormessage = "Either no *.conf or no *.p12 file found\n";
2879 goto N2N_ERROR;
2880 }
2881
2882 open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file';
2883 @firen2nconf = <FILE>;
2884 close (FILE);
2885 chomp(@firen2nconf);
2886
2887 } else {
2888
2889 $errormessage = "Filecount does not match only 2 files are allowed\n";
2890 goto N2N_ERROR;
2891 }
2892
7c1d9faf
AH
2893###
2894# m.a.d net2net
ce9abb66 2895###
54fd0535
MT
2896
2897 if ($cgiparams{'n2nname'} ne ''){
2898
2899 $uplconffilename2 = "$cgiparams{'n2nname'}.conf";
2900 $uplp12name2 = "$cgiparams{'n2nname'}.p12";
2901 $n2nname[0] = $cgiparams{'n2nname'};
2902 my @n2nname2 = split(/\./,$uplconffilename);
2903 $n2nname2[0] =~ s/\n|\r//g;
2904 my $input1 = "${General::swroot}/ovpn/certs/$uplp12name";
2905 my $output1 = "${General::swroot}/ovpn/certs/$uplp12name2";
2906 my $input2 = "$n2nname2[0]n2n";
2907 my $output2 = "$n2nname[0]n2n";
2908 my $filename = "$tempdir/$uplconffilename";
2909 open(FILE, "< $filename") or die 'Unable to open config file.';
2910 my @current = <FILE>;
2911 close(FILE);
2912 foreach (@current) {s/$input1/$output1/g;}
2913 foreach (@current) {s/$input2/$output2/g;}
2914 open (OUT, "> $filename") || die 'Unable to open config file.';
2915 print OUT @current;
2916 close OUT;
ce9abb66 2917
54fd0535
MT
2918 }else{
2919 $uplconffilename2 = $uplconffilename;
2920 $uplp12name2 = $uplp12name;
2921 @n2nname = split(/\./,$uplconffilename);
ce9abb66 2922 $n2nname[0] =~ s/\n|\r//g;
54fd0535 2923 }
7c1d9faf
AH
2924 unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";}
2925 unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";}
ce9abb66 2926
54fd0535 2927 move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2");
ce9abb66
AH
2928
2929 if ($? ne 0) {
2930 $errormessage = "*.conf move failed: $!";
2931 unlink ($filename);
2932 goto N2N_ERROR;
2933 }
2934
54fd0535 2935 move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2");
b278daf3
AH
2936 chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name";
2937
ce9abb66
AH
2938 if ($? ne 0) {
2939 $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
2940 unlink ($filename);
2941 goto N2N_ERROR;
2942 }
2943
2944my $complzoactive;
d96c89eb
AH
2945my $mssfixactive;
2946my $n2nfragment;
2ee746be 2947my @n2nmtudisc = split(/ /, (grep { /^mtu-disc/ } @firen2nconf)[0]);;
60f396d7 2948my @n2nproto2 = split(/ /, (grep { /^proto/ } @firen2nconf)[0]);
54fd0535 2949my @n2nproto = split(/-/, $n2nproto2[1]);
ce9abb66
AH
2950my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]);
2951my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]);
2952my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf;
2953if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";}
d96c89eb
AH
2954my @n2nmssfix = grep { /^mssfix/ } @firen2nconf;
2955if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";}
54fd0535 2956#my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]);
d96c89eb 2957my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]);
ce9abb66
AH
2958my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]);
2959my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]);
2960my @n2novpnsub = split(/\./,$n2novpnsuball[1]);
2961my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]);
54fd0535 2962my @n2nmgmt = split(/ /, (grep { /^management/ } @firen2nconf)[0]);
ce9abb66
AH
2963my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]);
2964
60f396d7 2965
ce9abb66
AH
2966###
2967# m.a.d delete CR and LF from arrays for this chomp doesnt work
2968###
2969
ce9abb66 2970$n2nremote[1] =~ s/\n|\r//g;
ce9abb66
AH
2971$n2novpnsub[0] =~ s/\n|\r//g;
2972$n2novpnsub[1] =~ s/\n|\r//g;
2973$n2novpnsub[2] =~ s/\n|\r//g;
60f396d7 2974$n2nproto[0] =~ s/\n|\r//g;
ce9abb66
AH
2975$n2nport[1] =~ s/\n|\r//g;
2976$n2ntunmtu[1] =~ s/\n|\r//g;
2977$n2nremsub[1] =~ s/\n|\r//g;
b278daf3 2978$n2nremsub[2] =~ s/\n|\r//g;
ce9abb66 2979$n2nlocalsub[2] =~ s/\n|\r//g;
d96c89eb 2980$n2nfragment[1] =~ s/\n|\r//g;
54fd0535 2981$n2nmgmt[2] =~ s/\n|\r//g;
2ee746be 2982$n2nmtudisc[1] =~ s/\n|\r//g;
ce9abb66 2983chomp ($complzoactive);
d96c89eb 2984chomp ($mssfixactive);
ce9abb66
AH
2985
2986###
7c1d9faf 2987# m.a.d net2net
ce9abb66
AH
2988###
2989
2990###
2991# Check if there is no other entry with this name
2992###
2993
2994 foreach my $dkey (keys %confighash) {
2995 if ($confighash{$dkey}[1] eq $n2nname[0]) {
2996 $errormessage = $Lang::tr{'a connection with this name already exists'};
b278daf3
AH
2997 unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!";
2998 unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!";
2999 rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!";
ce9abb66
AH
3000 goto N2N_ERROR;
3001 }
3002 }
3003
d96c89eb
AH
3004###
3005# Check if OpenVPN Subnet is valid
3006###
3007
3008foreach my $dkey (keys %confighash) {
3009 if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") {
3010 $errormessage = 'The OpenVPN Subnet is already in use';
b278daf3
AH
3011 unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!";
3012 unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!";
3013 rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!";
d96c89eb
AH
3014 goto N2N_ERROR;
3015 }
3016 }
3017
3018###
3019# Check im Dest Port is vaild
3020###
3021
3022foreach my $dkey (keys %confighash) {
3023 if ($confighash{$dkey}[29] eq $n2nport[1] ) {
3024 $errormessage = 'The OpenVPN Port is already in use';
b278daf3
AH
3025 unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!";
3026 unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!";
3027 rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!";
d96c89eb
AH
3028 goto N2N_ERROR;
3029 }
3030 }
3031
3032
3033
ce9abb66
AH
3034 $key = &General::findhasharraykey (\%confighash);
3035
350f2980
SS
3036 foreach my $i (0 .. 39) { $confighash{$key}[$i] = "";}
3037
ce9abb66
AH
3038 $confighash{$key}[0] = 'off';
3039 $confighash{$key}[1] = $n2nname[0];
350f2980 3040 $confighash{$key}[2] = $n2nname[0];
ce9abb66
AH
3041 $confighash{$key}[3] = 'net';
3042 $confighash{$key}[4] = 'cert';
3043 $confighash{$key}[6] = 'client';
3044 $confighash{$key}[8] = $n2nlocalsub[2];
350f2980
SS
3045 $confighash{$key}[10] = $n2nremote[1];
3046 $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]";
54fd0535 3047 $confighash{$key}[22] = $n2nmgmt[2];
350f2980 3048 $confighash{$key}[23] = $mssfixactive;
d96c89eb 3049 $confighash{$key}[24] = $n2nfragment[1];
350f2980 3050 $confighash{$key}[25] = 'IPFire n2n Client';
ce9abb66 3051 $confighash{$key}[26] = 'red';
350f2980
SS
3052 $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0";
3053 $confighash{$key}[28] = $n2nproto[0];
3054 $confighash{$key}[29] = $n2nport[1];
3055 $confighash{$key}[30] = $complzoactive;
3056 $confighash{$key}[31] = $n2ntunmtu[1];
3057 $confighash{$key}[38] = $n2nmtudisc[1];
ce9abb66
AH
3058
3059
3060 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
d96c89eb 3061
ce9abb66
AH
3062 N2N_ERROR:
3063
3064 &Header::showhttpheaders();
3065 &Header::openpage('Validate imported configuration', 1, '');
3066 &Header::openbigbox('100%', 'LEFT', '', $errormessage);
3067 if ($errormessage) {
3068 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
3069 print "<class name='base'>$errormessage";
3070 print "&nbsp;</class>";
3071 &Header::closebox();
3072
3073 } else
3074 {
3075 &Header::openbox('100%', 'LEFT', 'import ipfire net2net config');
3076 }
3077 if ($errormessage eq ''){
3078 print <<END
3079 <!-- ipfire net2net config gui -->
3080 <table width='100%'>
3081 <tr><td width='25%'>&nbsp;</td><td width='25%'>&nbsp;</td></tr>
3082 <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr>
3083 <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
3084 <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr>
3085 <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr>
3086 <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr>
3087 <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td><td><b>$confighash{$key}[11]</b></td></tr>
3088 <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr>
3089 <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr>
3090 <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr>
3091 <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr>
7c1d9faf
AH
3092 <tr><td class='boldbase' nowrap='nowrap'>MSSFIX </td><td><b>$confighash{$key}[23]</b></td></tr>
3093 <tr><td class='boldbase' nowrap='nowrap'>Fragment </td><td><b>$confighash{$key}[24]</b></td></tr>
ce9abb66 3094 <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr>
350f2980 3095 <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td><td><b>$confighash{$key}[38]</b></td></tr>
54fd0535 3096 <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b>$confighash{$key}[22]</b></td></tr>
ce9abb66
AH
3097 <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
3098 </table>
3099END
3100;
3101 &Header::closebox();
3102 }
3103
3104 if ($errormessage) {
3105 print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
3106 } else {
3107 print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />";
3108 print "<input type='hidden' name='TYPE' value='net2netakn' />";
3109 print "<input type='hidden' name='KEY' value='$key' />";
3110 print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>";
3111 }
3112 &Header::closebigbox();
3113 &Header::closepage();
3114 exit(0);
3115
3116
3117##
3118### Accept IPFire n2n Package Settings
3119###
3120
3121 } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){
3122
3123###
3124### Discard and Rollback IPFire n2n Package Settings
3125###
3126
3127 } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){
3128
3129 &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
3130
3131if ($confighash{$cgiparams{'KEY'}}) {
3132
3133 my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf");
3134 my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
3135 unlink ($certfile) or die "Removing $certfile fail: $!";
3136 unlink ($conffile) or die "Removing $conffile fail: $!";
3137 rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!";
3138 delete $confighash{$cgiparams{'KEY'}};
3139 &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
3140
3141 } else {
3142 $errormessage = $Lang::tr{'invalid key'};
3143 }