+#test33
+
+###
+### Choose between adding a host-net or net-net connection
+###
+
+###
+# m.a.d Anpassung wegen upload n2n Package
+###
+
+} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') {
+ &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings);
+ &Header::showhttpheaders();
+ &Header::openpage($Lang::tr{'vpn configuration main'}, 1, '');
+ &Header::openbigbox('100%', 'LEFT', '', '');
+ &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'});
+ print <<END
+ <b>$Lang::tr{'connection type'}:</b><br />
+ <table><form method='post' ENCTYPE="multipart/form-data">
+ <tr><td><input type='radio' name='TYPE' value='host' checked /></td>
+ <td class='base'>$Lang::tr{'host to net vpn'}</td></tr>
+ <tr><td><input type='radio' name='TYPE' value='net' /></td>
+ <td class='base'>$Lang::tr{'net to net vpn'}</td></tr>
+ <tr><td><input type='radio' name='TYPE' value='net2net' /></td>
+ <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr>
+ <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr>
+ <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr>
+ </form></table>
+END
+ ;
+
+ &Header::closebox();
+ &Header::closebigbox();
+ &Header::closepage();
+ exit (0);
+
+###
+# m.a.d uploading a IPFire n2n Client package
+###
+
+} elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){
+
+ my @firen2nconf;
+ my @confdetails;
+ my $uplconffilename ='';
+ my $uplp12name = '';
+ my $complzoactive ='';
+ my @rem_subnet;
+ my @rem_subnet2;
+ my @tmposupnet3;
+ my $key;
+
+ &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
+
+# Check if a file is uploaded
+
+ if (ref ($cgiparams{'FH'}) ne 'Fh') {
+ $errormessage = $Lang::tr{'there was no file upload'};
+ goto N2N_ERROR;
+ }
+
+# Move uploaded IPfire n2n package to temporary file
+
+ (my $fh, my $filename) = tempfile( );
+ if (copy ($cgiparams{'FH'}, $fh) != 1) {
+ $errormessage = $!;
+ goto N2N_ERROR;
+ }
+
+ my $zip = Archive::Zip->new();
+ my $zipName = $filename;
+ my $status = $zip->read( $zipName );
+ if ($status != AZ_OK) {
+ $errormessage = "Read of $zipName failed\n";
+ goto N2N_ERROR;
+ }
+
+ my $tempdir = tempdir( CLEANUP => 1 );
+ my @files = $zip->memberNames();
+ for(@files) {
+ $zip->extractMemberWithoutPaths($_,"$tempdir/$_");
+ }
+ my $countfiles = @files;
+
+# Check if we have not more then 2 files
+
+ if ( $countfiles == 2){
+ foreach (@files){
+ if ( $_ =~ /.conf$/){
+ $uplconffilename = $_;
+ }
+ if ( $_ =~ /.p12$/){
+ $uplp12name = $_;
+ }
+ }
+ if (($uplconffilename eq '') || ($uplp12name eq '')){
+ $errormessage = "Either no *.conf or no *.p12 file found\n";
+ goto N2N_ERROR;
+ }
+
+ open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file';
+ @firen2nconf = <FILE>;
+ close (FILE);
+ chomp(@firen2nconf);
+
+ } else {
+
+ $errormessage = "Filecount does not match only 2 files are allowed\n";
+ goto N2N_ERROR;
+ }
+
+###
+# m.a.d prepare imported ipfire net2net data
+###
+
+ my @n2nname = split(/\./,$uplconffilename);
+ $n2nname[0] =~ s/\n|\r//g;
+
+ if ( !-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]") {
+ mkdir("${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770); }
+
+ move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename");
+
+ if ($? ne 0) {
+ $errormessage = "*.conf move failed: $!";
+ unlink ($filename);
+ goto N2N_ERROR;
+ }
+
+ move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name");
+ if ($? ne 0) {
+ $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
+ unlink ($filename);
+ goto N2N_ERROR;
+ }
+
+my $complzoactive;
+#my @n2nroute = split(/ /, (grep { /^route/ } @firen2nconf)[0]);
+my @n2nproto = split(/ /, (grep { /^proto/ } @firen2nconf)[0]);
+my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]);
+my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]);
+my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf;
+if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";}
+my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]);
+my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]);
+my @n2novpnsub = split(/\./,$n2novpnsuball[1]);
+my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]);
+my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]);
+
+# $errormessage = &Ovpnfunc::ovelapplausi("$tmposupnet3[0].$tmposupnet3[1].$tmposupnet3[2].0","255.255.255.0");
+# if ($errormessage ne ''){
+# goto N2N_ERROR;
+# }
+
+###
+# m.a.d delete CR and LF from arrays for this chomp doesnt work
+###
+
+#$n2nroute[1] =~ s/\n|\r//g;
+$n2nremote[1] =~ s/\n|\r//g;
+#$n2nroute[1] =~ s/\n|\r//g;
+#$n2nroute[2] =~ s/\n|\r//g;
+$n2novpnsub[0] =~ s/\n|\r//g;
+$n2novpnsub[1] =~ s/\n|\r//g;
+$n2novpnsub[2] =~ s/\n|\r//g;
+$n2nproto[1] =~ s/\n|\r//g;
+$n2nport[1] =~ s/\n|\r//g;
+$n2ntunmtu[1] =~ s/\n|\r//g;
+$n2nremsub[1] =~ s/\n|\r//g;
+$n2nlocalsub[2] =~ s/\n|\r//g;
+chomp ($complzoactive);
+
+###
+# m.a.d Write n2n config
+###
+
+###
+# Check if there is no other entry with this name
+###
+
+ foreach my $dkey (keys %confighash) {
+ if ($confighash{$dkey}[1] eq $n2nname[0]) {
+ $errormessage = $Lang::tr{'a connection with this name already exists'};
+ goto N2N_ERROR;
+ }
+ }
+
+ $key = &General::findhasharraykey (\%confighash);
+
+ foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";}
+ $confighash{$key}[0] = 'off';
+ $confighash{$key}[1] = $n2nname[0];
+ $confighash{$key}[2] = $n2nname[0];
+ $confighash{$key}[3] = 'net';
+ $confighash{$key}[4] = 'cert';
+ $confighash{$key}[6] = 'client';
+ $confighash{$key}[8] = $n2nlocalsub[2];
+ $confighash{$key}[10] = $n2nremote[1];
+ $confighash{$key}[11] = $n2nremsub[1];
+ $confighash{$key}[25] = 'IPFire n2n Client';
+ $confighash{$key}[26] = 'red';
+ $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0";
+ $confighash{$key}[28] = $n2nproto[1];
+ $confighash{$key}[29] = $n2nport[1];
+ $confighash{$key}[30] = $complzoactive;
+ $confighash{$key}[31] = $n2ntunmtu[1];
+
+
+ &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
+ N2N_ERROR:
+
+ &Header::showhttpheaders();
+ &Header::openpage('Validate imported configuration', 1, '');
+ &Header::openbigbox('100%', 'LEFT', '', $errormessage);
+ if ($errormessage) {
+ &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
+ print "<class name='base'>$errormessage";
+ print " </class>";
+ &Header::closebox();
+
+ } else
+ {
+ &Header::openbox('100%', 'LEFT', 'import ipfire net2net config');
+ }
+ if ($errormessage eq ''){
+ print <<END
+ <!-- ipfire net2net config gui -->
+ <table width='100%'>
+ <tr><td width='25%'> </td><td width='25%'> </td></tr>
+ <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr>
+ <tr><td> </td><td> </td></tr>
+ <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr>
+ <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr>
+ <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr>
+ <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td><td><b>$confighash{$key}[11]</b></td></tr>
+ <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr>
+ <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr>
+ <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr>
+ <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr>
+ <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr>
+ <tr><td> </td><td> </td></tr>
+ </table>
+END
+;
+ &Header::closebox();
+ }
+
+ if ($errormessage) {
+ print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>";
+ } else {
+ print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />";
+ print "<input type='hidden' name='TYPE' value='net2netakn' />";
+ print "<input type='hidden' name='KEY' value='$key' />";
+ print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>";
+ }
+ &Header::closebigbox();
+ &Header::closepage();
+ exit(0);
+
+
+##
+### Accept IPFire n2n Package Settings
+###
+
+ } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){
+
+###
+### Discard and Rollback IPFire n2n Package Settings
+###
+
+ } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){
+
+ &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
+
+if ($confighash{$cgiparams{'KEY'}}) {
+
+ my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf");
+ my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12");
+ unlink ($certfile) or die "Removing $certfile fail: $!";
+ unlink ($conffile) or die "Removing $conffile fail: $!";
+ rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!";
+ delete $confighash{$cgiparams{'KEY'}};
+ &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash);
+
+ } else {
+ $errormessage = $Lang::tr{'invalid key'};
+ }
+
+
+###
+# m.a.d end uploading a IPFire n2n Client package
+###
+
+
+###
+### Adding a new connection
+###