OpenVPN: Added additional configuration for server and clients
authorErik Kapfer <erik.kapfer@ipfire.org>
Thu, 13 Nov 2014 02:09:51 +0000 (03:09 +0100)
committerErik Kapfer <erik.kapfer@ipfire.org>
Thu, 13 Nov 2014 02:09:51 +0000 (03:09 +0100)
* Added a possibility to manualy extend OpenVPNs server and client configuration.
* Added also a checkbox (on/off) in the WUI under 'Advanced server options' .
* Changed the order in 'Miscellaneous options' section for better overview.
* Optimized code in particular sections a little.
    Added a filehandle instead of system(touch...) for ccd* file generation.
    Unified the html code tags in processed section.
Fixes #10577

html/cgi-bin/ovpnmain.cgi
langs/de/cgi-bin/de.pl
langs/en/cgi-bin/en.pl

index 969b255..7048ca2 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'};
@@ -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'>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'>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'>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>
index b7692ee..4420f72 100644 (file)
 'outgoing traffic in bytes per second' => 'Abgehender Verkehr',
 'override mtu' => '√úberschreibe Standard MTU',
 'ovpn' => 'OpenVPN',
+'ovpn add conf' => 'Erweiterte Konfiguration',
 'ovpn con stat' => 'OpenVPN Verbindungs-Statistik',
 'ovpn config' => 'OVPN-Konfiguration',
 'ovpn crypt options' => 'Kryptografieoptionen',
index 1986409..0843ae5 100644 (file)
 'outgoing traffic in bytes per second' => 'Outgoing Traffic',
 'override mtu' => 'Override default MTU',
 'ovpn' => 'OpenVPN',
+'ovpn add conf' => 'Additional configuration',
 'ovpn con stat' => 'OpenVPN Connection Statistics',
 'ovpn config' => 'OVPN-Config',
 'ovpn crypt options' => 'Cryptographic options',