]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/ovpnmain.cgi
OpenVPN: Added additional configuration for server and clients
[ipfire-2.x.git] / html / cgi-bin / ovpnmain.cgi
index 0cb41696fb58db26c1f61368ee5595c0d8ac52b7..7048ca206cf0773c4f773b75ca6a7e81c2cdd0a5 100644 (file)
@@ -70,6 +70,9 @@ my $configgrp="${General::swroot}/fwhosts/customgroups";
 my $customnet="${General::swroot}/fwhosts/customnetworks";
 my $name;
 my $col="";
+my $local_serverconf = "${General::swroot}/ovpn/scripts/server.conf.local";
+my $local_clientconf = "${General::swroot}/ovpn/scripts/client.conf.local";
+
 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
 $cgiparams{'ENABLED'} = 'off';
 $cgiparams{'ENABLED_BLUE'} = 'off';
@@ -94,10 +97,33 @@ $cgiparams{'DCIPHER'} = '';
 $cgiparams{'DAUTH'} = '';
 $cgiparams{'TLSAUTH'} = '';
 $routes_push_file = "${General::swroot}/ovpn/routes_push";
-unless (-e $routes_push_file)    { system("touch $routes_push_file"); }
-unless (-e "${General::swroot}/ovpn/ccd.conf")    { system("touch ${General::swroot}/ovpn/ccd.conf"); }
-unless (-e "${General::swroot}/ovpn/ccdroute")    { system("touch ${General::swroot}/ovpn/ccdroute"); }
-unless (-e "${General::swroot}/ovpn/ccdroute2")    { system("touch ${General::swroot}/ovpn/ccdroute2"); }
+
+# Add CCD files if not already presant
+unless (-e $routes_push_file) {
+       open(RPF, ">$routes_push_file");
+       close(RPF);
+}
+unless (-e "${General::swroot}/ovpn/ccd.conf") {
+       open(CCDC, ">${General::swroot}/ovpn/ccd.conf");
+       close (CCDC);
+}
+unless (-e "${General::swroot}/ovpn/ccdroute") {
+       open(CCDR, ">${General::swroot}/ovpn/ccdroute");
+       close (CCDR);
+}
+unless (-e "${General::swroot}/ovpn/ccdroute2") {
+       open(CCDRT, ">${General::swroot}/ovpn/ccdroute2");
+       close (CCDRT);
+}
+# Add additional configs if not already presant
+unless (-e "$local_serverconf") {
+       open(LSC, ">$local_serverconf");
+       close (LSC);
+}
+unless (-e "$local_clientconf") {
+       open(LCC, ">$local_clientconf");
+       close (LCC);
+}
 
 &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'});
 
@@ -306,7 +332,22 @@ sub writeserverconf {
                print CONF "verb $sovpnsettings{LOG_VERB}\n";
        } else {
                print CONF "verb 3\n";
-       }       
+       }
+    # Print server.conf.local if entries exist to server.conf
+    if ( !-z $local_serverconf  && $sovpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') {
+       open (LSC, "$local_serverconf");
+               print CONF "\n#---------------------------\n";
+               print CONF "# Start of custom directives\n";
+               print CONF "# from server.conf.local\n";
+               print CONF "#---------------------------\n\n";
+       while (<LSC>) {
+               print CONF $_;
+       }
+               print CONF "\n#-----------------------------\n";
+               print CONF "# End of custom directives\n";
+               print CONF "#-----------------------------\n";
+       close (LSC);
+    }
     print CONF "\n";
     
     close(CONF);
@@ -685,6 +726,7 @@ if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) {
     $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'};
     $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'};
     $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'};
+    $vpnsettings{'ADDITIONAL_CONFIGS'} = $cgiparams{'ADDITIONAL_CONFIGS'};
     $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'};
     $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'};
     $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'};
@@ -908,7 +950,7 @@ unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General
   }
   if ($cgiparams{'COMPLZO'} eq 'on') {
    print SERVERCONF "# Enable Compression\n";
-   print SERVERCONF "comp-lzo\r\n";
+   print SERVERCONF "comp-lzo\n";
      }
   print SERVERCONF "# Debug Level\n"; 
   print SERVERCONF "verb 3\n"; 
@@ -1003,7 +1045,7 @@ unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General
   }
   if ($cgiparams{'COMPLZO'} eq 'on') {
    print CLIENTCONF "# Enable Compression\n";
-   print CLIENTCONF "comp-lzo\r\n";
+   print CLIENTCONF "comp-lzo\n";
   }
   print CLIENTCONF "# Debug Level\n"; 
   print CLIENTCONF "verb 3\n"; 
@@ -2103,7 +2145,7 @@ if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){
    }
    if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') {
    print CLIENTCONF "# Enable Compression\n";
-   print CLIENTCONF "comp-lzo\r\n";
+   print CLIENTCONF "comp-lzo\n";
      }
    print CLIENTCONF "# Debug Level\n"; 
    print CLIENTCONF "verb 3\n"; 
@@ -2226,6 +2268,21 @@ else
                print CLIENTCONF "mtu-disc $vpnsettings{'PMTU_DISCOVERY'}\r\n";
        }
     }
+    # Print client.conf.local if entries exist to client.ovpn
+    if (!-z $local_clientconf && $vpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') {
+       open (LCC, "$local_clientconf");
+               print CLIENTCONF "\n#---------------------------\n";
+               print CLIENTCONF "# Start of custom directives\n";
+               print CLIENTCONF "# from client.conf.local\n";
+               print CLIENTCONF "#---------------------------\n\n";
+       while (<LCC>) {
+               print CLIENTCONF $_;
+       }
+               print CLIENTCONF "\n#---------------------------\n";
+               print CLIENTCONF "# End of custom directives\n";
+               print CLIENTCONF "#---------------------------\n\n";
+       close (LCC);
+    }
     close(CLIENTCONF);
         
     $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n";
@@ -2458,6 +2515,9 @@ ADV_ERROR:
     $checked{'REDIRECT_GW_DEF1'}{'off'} = '';
     $checked{'REDIRECT_GW_DEF1'}{'on'} = '';
     $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED';
+    $checked{'ADDITIONAL_CONFIGS'}{'off'} = '';
+    $checked{'ADDITIONAL_CONFIGS'}{'on'} = '';
+    $checked{'ADDITIONAL_CONFIGS'}{$cgiparams{'ADDITIONAL_CONFIGS'}} = 'CHECKED';
     $checked{'MSSFIX'}{'off'} = '';
     $checked{'MSSFIX'}{'on'} = '';
     $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED';
@@ -2538,39 +2598,52 @@ print <<END;
 </table>
 <hr size='1'>
 <table width='100%'>
-    <tr>
+       <tr>
                <td class'base'><b>$Lang::tr{'misc-options'}</b></td>
-    </tr>
-    <tr>
+       </tr>
+
+       <tr>
                <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td>
-    </tr>
-    <tr>
+       </tr>
+
+       <tr>
                <td class='base'>Client-To-Client</td>
                <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td>
-    </tr>
-    <tr>       
+       </tr>
+
+       <tr>
                <td class='base'>Redirect-Gateway def1</td>
                <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td>
-    </tr>
-    <tr>       
-        <td class='base'>Max-Clients</td>
-        <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td>
-    </tr>      
+       </tr>
+
        <tr>
-         <td class='base'>Keepalive <br />
-           (ping/ping-restart)</td>
-         <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td>
-         <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td>
-    </tr>
+               <td class='base'>$Lang::tr{'ovpn add conf'}</td>
+               <td><input type='checkbox' name='ADDITIONAL_CONFIGS' $checked{'ADDITIONAL_CONFIGS'}{'on'} /></td>
+               <td>$Lang::tr{'openvpn default'}: off</td>
+       </tr>
+
        <tr>
-         <td class='base'>fragment <br></td>
-         <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td>
-      </tr>
-       <tr>
-         <td class='base'>mssfix</td>
-         <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td>
-         <td>$Lang::tr{'openvpn default'}: off</td>
-         </tr>
+               <td class='base'>mssfix</td>
+               <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td>
+               <td>$Lang::tr{'openvpn default'}: off</td>
+       </tr>
+
+       <tr>
+               <td class='base'>fragment <br></td>
+               <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td>
+       </tr>
+
+
+       <tr>
+               <td class='base'>Max-Clients</td>
+               <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td>
+       </tr>
+       <tr>
+               <td class='base'>Keepalive <br />
+               (ping/ping-restart)</td>
+               <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td>
+               <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td>
+       </tr>
 
        <tr>
                <td class='base'>$Lang::tr{'ovpn mtu-disc'}</td>
@@ -3968,10 +4041,8 @@ if ($cgiparams{'TYPE'} eq 'net') {
                $errormessage = $Lang::tr{'name too long'};
                goto VPNCONF_ERROR;
            }
-           if ($cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) {
+           if ($cgiparams{'CERT_NAME'} eq '' || $cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) {
                $errormessage = $Lang::tr{'invalid input for name'};
-               unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!";
-               rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!";
                goto VPNCONF_ERROR;
            }
            if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) {
@@ -5024,24 +5095,41 @@ END
 ###
 
     &Header::openbox('100%', 'LEFT', $Lang::tr{'connection status and controlc' });
-    print <<END;
-
-
-    <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
-<tr>
-    <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th>
-    <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th>
-    <th width='22%' class='boldbase' align='center'><b>$Lang::tr{'network'}</b></th>
-    <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th>
-    <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th>
-    <th width='5%' class='boldbase' colspan='6' align='center'><b>$Lang::tr{'action'}</b></th>
-</tr>
-END
        ;
        my $id = 0;
        my $gif;
        my $col1="";
-       foreach my $key (sort { ncmp ($confighash{$a}[3],$confighash{$b}[3]) } sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) {
+       my $lastnet;
+       foreach my $key (sort { ncmp ($confighash{$a}[32],$confighash{$b}[32]) } sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) {
+               if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'net' ){$confighash{$key}[32]=$Lang::tr{'fwhost OpenVPN N-2-N'};}
+               if ($confighash{$key}[32] eq "dynamic"){$confighash{$key}[32]=$Lang::tr{'ccd dynrange'};}
+               if($id == 0){
+                       print"<b>$confighash{$key}[32]</b>";
+                       print <<END;
+       <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
+<tr>
+       <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th>
+       <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th>
+       <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th>
+       <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th>
+       <th width='5%' class='boldbase' colspan='6' align='center'><b>$Lang::tr{'action'}</b></th>
+</tr>
+END
+               }
+               if ($id > 0 && $lastnet ne $confighash{$key}[32]){
+                       print "</table><br>";
+                       print"<b>$confighash{$key}[32]</b>";
+                       print <<END;
+       <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
+<tr>
+       <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th>
+       <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th>
+       <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th>
+       <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th>
+       <th width='5%' class='boldbase' colspan='6' align='center'><b>$Lang::tr{'action'}</b></th>
+</tr>
+END
+               }
        if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; }
        if ($id % 2) {
                print "<tr>";
@@ -5060,9 +5148,6 @@ END
        my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`;
        $cavalid    =~ /Not After : (.*)[\n]/;
        $cavalid    = $1;
-       if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'net' ){$confighash{$key}[32]="net-2-net";}
-       if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'host' ){$confighash{$key}[32]="dynamic";}
-       print "<td align='center' $col>$confighash{$key}[32]</td>";
        print "<td align='center' $col>$confighash{$key}[25]</td>";
        $col1="bgcolor='${Header::colourred}'";
        my $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>";
@@ -5191,7 +5276,9 @@ END
 END
        ;
        $id++;
+       $lastnet = $confighash{$key}[32];
     }
+    print"</table>";
     ;
 
     # If the config file contains entries, print Key to action icons