]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/vpnmain.cgi
IPsec: Update ipsec.conf for GRE/VTI changes
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / vpnmain.cgi
index 21fd1f4cd6061c80ddb2067527427122c7e348d1..c29c5d53d39a2c07435c1b5ef70e387d229eedf1 100644 (file)
@@ -109,8 +109,12 @@ $cgiparams{'RW_NET'} = '';
 $cgiparams{'DPD_DELAY'} = '30';
 $cgiparams{'DPD_TIMEOUT'} = '120';
 $cgiparams{'FORCE_MOBIKE'} = 'off';
-$cgiparams{'START_ACTION'} = 'start';
-$cgiparams{'INACTIVITY_TIMEOUT'} = 900;
+$cgiparams{'START_ACTION'} = 'route';
+$cgiparams{'INACTIVITY_TIMEOUT'} = 1800;
+$cgiparams{'MODE'} = "tunnel";
+$cgiparams{'INTERFACE_MODE'} = "";
+$cgiparams{'INTERFACE_ADDRESS'} = "";
+$cgiparams{'INTERFACE_MTU'} = 1500;
 &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'});
 
 ###
@@ -149,7 +153,12 @@ sub cleanssldatabase {
                print FILE "";
                close FILE;
        }
+       if (open(FILE, ">${General::swroot}/certs/index.txt.attr")) {
+               print FILE "";
+               close FILE;
+       }
        unlink ("${General::swroot}/certs/index.txt.old");
+       unlink ("${General::swroot}/certs/index.txt.attr.old");
        unlink ("${General::swroot}/certs/serial.old");
        unlink ("${General::swroot}/certs/01.pem");
 }
@@ -162,7 +171,11 @@ sub newcleanssldatabase {
        if (! -s ">${General::swroot}/certs/index.txt") {
                system ("touch ${General::swroot}/certs/index.txt");
        }
+       if (! -s ">${General::swroot}/certs/index.txt.attr") {
+               system ("touch ${General::swroot}/certs/index.txt.attr");
+       }
        unlink ("${General::swroot}/certs/index.txt.old");
+       unlink ("${General::swroot}/certs/index.txt.attr.old");
        unlink ("${General::swroot}/certs/serial.old");
 #      unlink ("${General::swroot}/certs/01.pem");             numbering evolves. Wrong place to delete
 }
@@ -282,15 +295,31 @@ sub writeipsecfiles {
                        $localside = $lvpnsettings{'VPN_IP'};
                }
 
+               my $interface_mode = $lconfighash{$key}[36];
+
                print CONF "conn $lconfighash{$key}[1]\n";
                print CONF "\tleft=$localside\n";
-               print CONF "\tleftsubnet=" . &make_subnets($lconfighash{$key}[8]) . "\n";
+
+               if ($interface_mode eq "gre") {
+                       print CONF "\tleftsubnet=%dynamic[gre]\n";
+               } elsif ($interface_mode eq "vti") {
+                       print CONF "\tleftsubnet=0.0.0.0/0\n";
+               } else {
+                       print CONF "\tleftsubnet=" . &make_subnets($lconfighash{$key}[8]) . "\n";
+               }
+
                print CONF "\tleftfirewall=yes\n";
                print CONF "\tlefthostaccess=yes\n";
                print CONF "\tright=$lconfighash{$key}[10]\n";
 
                if ($lconfighash{$key}[3] eq 'net') {
-                       print CONF "\trightsubnet=" . &make_subnets($lconfighash{$key}[11]) . "\n";
+                       if ($interface_mode eq "gre") {
+                               print CONF "\trightsubnet=%dynamic[gre]\n";
+                       } elsif ($interface_mode eq "vti") {
+                               print CONF "\trightsubnet=0.0.0.0/0\n";
+                       } else {
+                               print CONF "\trightsubnet=" . &make_subnets($lconfighash{$key}[11]) . "\n";
+                       }
                }
 
                # Local Cert and Remote Cert (unless auth is DN dn-auth)
@@ -303,6 +332,18 @@ sub writeipsecfiles {
                print CONF "\tleftid=\"$lconfighash{$key}[7]\"\n" if ($lconfighash{$key}[7]);
                print CONF "\trightid=\"$lconfighash{$key}[9]\"\n" if ($lconfighash{$key}[9]);
 
+               # Set mode
+               if ($lconfighash{$key}[35] eq "transport") {
+                       print CONF "\ttype=transport\n";
+               } else {
+                       print CONF "\ttype=tunnel\n";
+               }
+
+               # Add mark for VTI
+               if ($interface_mode eq "vti") {
+                       print CONF "\tmark=$key\n";
+               }
+
                # Is PFS enabled?
                my $pfs = $lconfighash{$key}[28] eq 'on' ? 'on' : 'off';
 
@@ -1307,6 +1348,10 @@ END
                $cgiparams{'DPD_DELAY'}                 = $confighash{$cgiparams{'KEY'}}[31];
                $cgiparams{'FORCE_MOBIKE'}              = $confighash{$cgiparams{'KEY'}}[32];
                $cgiparams{'INACTIVITY_TIMEOUT'}        = $confighash{$cgiparams{'KEY'}}[34];
+               $cgiparams{'MODE'}                      = $confighash{$cgiparams{'KEY'}}[35];
+               $cgiparams{'INTERFACE_MODE'}            = $confighash{$cgiparams{'KEY'}}[36];
+               $cgiparams{'INTERFACE_ADDRESS'}         = $confighash{$cgiparams{'KEY'}}[37];
+               $cgiparams{'INTERFACE_MTU'}             = $confighash{$cgiparams{'KEY'}}[38];
 
                if (!$cgiparams{'DPD_DELAY'}) {
                        $cgiparams{'DPD_DELAY'} = 30;
@@ -1320,6 +1365,10 @@ END
                        $cgiparams{'INACTIVITY_TIMEOUT'} = 900;
                }
 
+               if ($cgiparams{'MODE'} eq "") {
+                       $cgiparams{'MODE'} = "tunnel";
+               }
+
        } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
                $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'});
                if ($cgiparams{'TYPE'} !~ /^(host|net)$/) {
@@ -1802,7 +1851,7 @@ END
        my $key = $cgiparams{'KEY'};
        if (! $key) {
                $key = &General::findhasharraykey (\%confighash);
-               foreach my $i (0 .. 34) { $confighash{$key}[$i] = "";}
+               foreach my $i (0 .. 38) { $confighash{$key}[$i] = "";}
        }
        $confighash{$key}[0] = $cgiparams{'ENABLED'};
        $confighash{$key}[1] = $cgiparams{'NAME'};
@@ -1847,6 +1896,10 @@ END
        $confighash{$key}[31] = $cgiparams{'DPD_DELAY'};
        $confighash{$key}[32] = $cgiparams{'FORCE_MOBIKE'};
        $confighash{$key}[34] = $cgiparams{'INACTIVITY_TIMEOUT'};
+       $confighash{$key}[35] = $cgiparams{'MODE'};
+       $confighash{$key}[36] = $cgiparams{'INTERFACE_MODE'};
+       $confighash{$key}[37] = $cgiparams{'INTERFACE_ADDRESS'};
+       $confighash{$key}[38] = $cgiparams{'INTERFACE_MTU'};
 
        # free unused fields!
        $confighash{$key}[6] = 'off';
@@ -1921,6 +1974,10 @@ END
        $cgiparams{'ONLY_PROPOSED'}             = 'on'; #[24];
        $cgiparams{'PFS'}                               = 'on'; #[28];
        $cgiparams{'INACTIVITY_TIMEOUT'}        = 900;
+       $cgiparams{'MODE'}                      = "tunnel";
+       $cgiparams{'INTERFACE_MODE'}            = "";
+       $cgiparams{'INTERFACE_ADDRESS'}         = "";
+       $cgiparams{'INTERFACE_MTU'}             = 1500;
 }
 
 VPNCONF_ERROR:
@@ -1976,6 +2033,11 @@ VPNCONF_ERROR:
        <input type='hidden' name='DPD_DELAY' value='$cgiparams{'DPD_DELAY'}' />
        <input type='hidden' name='DPD_TIMEOUT' value='$cgiparams{'DPD_TIMEOUT'}' />
        <input type='hidden' name='FORCE_MOBIKE' value='$cgiparams{'FORCE_MOBIKE'}' />
+       <input type='hidden' name='INACTIVITY_TIMEOUT' value='$cgiparams{'INACTIVITY_TIMEOUT'}' />
+       <input type='hidden' name='MODE' value='$cgiparams{'MODE'}' />
+       <input type='hidden' name='INTERFACE_MODE' value='$cgiparams{'INTERFACE_MODE'}' />
+       <input type='hidden' name='INTERFACE_ADDRESS' value='$cgiparams{'INTERFACE_ADDRESS'}' />
+       <input type='hidden' name='INTERFACE_MTU' value='$cgiparams{'INTERFACE_MTU'}' />
 END
 ;
        if ($cgiparams{'KEY'}) {
@@ -2270,6 +2332,26 @@ if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) ||
                        goto ADVANCED_ERROR;
                }
 
+               if ($cgiparams{'MODE'} !~ /^(tunnel|transport)$/) {
+                       $errormessage = $Lang::tr{'invalid input for mode'};
+                       goto ADVANCED_ERROR;
+               }
+
+               if ($cgiparams{'INTERFACE_MODE'} !~ /^(|gre|vti)$/) {
+                       $errormessage = $Lang::tr{'invalid input for interface mode'};
+                       goto ADVANCED_ERROR;
+               }
+
+               if (($cgiparams{'INTERFACE_MODE'} ne "") && !&Network::check_subnet($cgiparams{'INTERFACE_ADDRESS'})) {
+                       $errormessage = $Lang::tr{'invalid input for interface address'};
+                       goto ADVANCED_ERROR;
+               }
+
+               if ($cgiparams{'INTERFACE_MTU'} !~ /^\d+$/) {
+                       $errormessage = $Lang::tr{'invalid input for interface mtu'};
+                       goto ADVANCED_ERROR;
+               }
+
                $confighash{$cgiparams{'KEY'}}[29] = $cgiparams{'IKE_VERSION'};
                $confighash{$cgiparams{'KEY'}}[18] = $cgiparams{'IKE_ENCRYPTION'};
                $confighash{$cgiparams{'KEY'}}[19] = $cgiparams{'IKE_INTEGRITY'};
@@ -2289,6 +2371,10 @@ if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) ||
                $confighash{$cgiparams{'KEY'}}[32] = $cgiparams{'FORCE_MOBIKE'};
                $confighash{$cgiparams{'KEY'}}[33] = $cgiparams{'START_ACTION'};
                $confighash{$cgiparams{'KEY'}}[34] = $cgiparams{'INACTIVITY_TIMEOUT'};
+               $confighash{$cgiparams{'KEY'}}[35] = $cgiparams{'MODE'};
+               $confighash{$cgiparams{'KEY'}}[36] = $cgiparams{'INTERFACE_MODE'};
+               $confighash{$cgiparams{'KEY'}}[37] = $cgiparams{'INTERFACE_ADDRESS'};
+               $confighash{$cgiparams{'KEY'}}[38] = $cgiparams{'INTERFACE_MTU'};
                &General::writehasharray("${General::swroot}/vpn/config", \%confighash);
                &writeipsecfiles();
                if (&vpnenabled) {
@@ -2318,6 +2404,10 @@ if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) ||
                $cgiparams{'FORCE_MOBIKE'}              = $confighash{$cgiparams{'KEY'}}[32];
                $cgiparams{'START_ACTION'}              = $confighash{$cgiparams{'KEY'}}[33];
                $cgiparams{'INACTIVITY_TIMEOUT'}        = $confighash{$cgiparams{'KEY'}}[34];
+               $cgiparams{'MODE'}                      = $confighash{$cgiparams{'KEY'}}[35];
+               $cgiparams{'INTERFACE_MODE'}            = $confighash{$cgiparams{'KEY'}}[36];
+               $cgiparams{'INTERFACE_ADDRESS'}         = $confighash{$cgiparams{'KEY'}}[37];
+               $cgiparams{'INTERFACE_MTU'}             = $confighash{$cgiparams{'KEY'}}[38];
 
                if (!$cgiparams{'DPD_DELAY'}) {
                        $cgiparams{'DPD_DELAY'} = 30;
@@ -2334,6 +2424,10 @@ if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) ||
                if ($cgiparams{'INACTIVITY_TIMEOUT'} eq "") {
                        $cgiparams{'INACTIVITY_TIMEOUT'} = 900; # 15 min
                }
+
+               if ($cgiparams{'MODE'} eq "") {
+                       $cgiparams{'MODE'} = "tunnel";
+               }
        }
 
        ADVANCED_ERROR:
@@ -2442,6 +2536,15 @@ if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) ||
        }
        $selected{'INACTIVITY_TIMEOUT'}{$cgiparams{'INACTIVITY_TIMEOUT'}} = "selected";
 
+       $selected{'MODE'}{'tunnel'} = '';
+       $selected{'MODE'}{'transport'} = '';
+       $selected{'MODE'}{$cgiparams{'MODE'}} = "selected='selected'";
+
+       $selected{'INTERFACE_MODE'}{''} = '';
+       $selected{'INTERFACE_MODE'}{'gre'} = '';
+       $selected{'INTERFACE_MODE'}{'vti'} = '';
+       $selected{'INTERFACE_MODE'}{$cgiparams{'INTERFACE_MODE'}} = "selected='selected'";
+
        &Header::showhttpheaders();
        &Header::openpage($Lang::tr{'ipsec'}, 1, '');
        &Header::openbigbox('100%', 'left', '', $errormessage);
@@ -2466,6 +2569,45 @@ if(($cgiparams{'ACTION'} eq $Lang::tr{'advanced'}) ||
        <input type='hidden' name='ADVANCED' value='yes' />
        <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />
 
+       <table width="100%">
+               <tbody>
+                       <tr>
+                               <td width="15%">$Lang::tr{'mode'}:</td>
+                               <td>
+                                       <select name='MODE'>
+                                               <option value='tunnel' $selected{'MODE'}{'tunnel'}>$Lang::tr{'ipsec mode tunnel'}</option>
+                                               <option value='transport' $selected{'MODE'}{'transport'}>$Lang::tr{'ipsec mode transport'}</option>
+                                       </select>
+                               </td>
+                               <td></td>
+                       </tr>
+
+                       <tr>
+                               <td width="15%">$Lang::tr{'interface mode'}:</td>
+                               <td>
+                                       <label></label>
+                                       <select name='INTERFACE_MODE'>
+                                               <option value='' $selected{'INTERFACE_MODE'}{''}>$Lang::tr{'ipsec interface mode none'}</option>
+                                               <option value='gre' $selected{'INTERFACE_MODE'}{'gre'}>$Lang::tr{'ipsec interface mode gre'}</option>
+                                               <option value='vti' $selected{'INTERFACE_MODE'}{'vti'}>$Lang::tr{'ipsec interface mode vti'}</option>
+                                       </select>
+                               </td>
+                               <td>
+                                       <label>$Lang::tr{'ip address'}/$Lang::tr{'subnet mask'}</label>
+                                       <input type="text" name="INTERFACE_ADDRESS" value="$cgiparams{'INTERFACE_ADDRESS'}">
+                               </td>
+                               <td>
+                                       <label>$Lang::tr{'mtu'}</label>
+                                       <input type="number" name="INTERFACE_MTU" value="$cgiparams{'INTERFACE_MTU'}" min="576" max="9000">
+                               </td>
+                       </tr>
+               </tbody>
+       </table>
+
+       <br><br>
+
+       <h2>$Lang::tr{'cryptographic settings'}</h2>
+
        <table width='100%'>
        <thead>
                <tr>