]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
ovpnmain.cgi: Refactor function to remove a static pool
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 20 Mar 2024 10:33:16 +0000 (11:33 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Jun 2025 19:45:52 +0000 (19:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
html/cgi-bin/ovpnmain.cgi

index add25cb36f2bd2e9318acaf588e6bc064d39d800..d041b9474195dba1735fa3e6fdb9661466f68b1b 100644 (file)
@@ -350,29 +350,39 @@ sub writeserverconf {
     close(CONF);
 }
 
-sub delccdnet
-{
-       my %ccdconfhash = ();
-       my %ccdhash = ();
-       my $ccdnetname=$_[0];
-       if (-f "${General::swroot}/ovpn/ovpnconfig"){
-               &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash);
-               foreach my $key (keys %ccdhash) {
-                       if ($ccdhash{$key}[32] eq $ccdnetname) {
-                               $errormessage=$Lang::tr{'ccd err hostinnet'};
-                               return;
-                       }
+sub delccdnet($) {
+       my $name = shift;
+
+       my %conns = ();
+       my %subnets = ();
+
+       # Load all connections
+       &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%conns);
+
+       # Check if the subnet is in use
+       foreach my $key (keys %conns) {
+               if ($conns{$key}[32] eq $name) {
+                       $errormessage = $Lang::tr{'ccd err hostinnet'};
+                       return 1;
                }
        }
-       &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
-       foreach my $key (keys %ccdconfhash) {
-                       if ($ccdconfhash{$key}[0] eq $ccdnetname){
-                               delete $ccdconfhash{$key};
+
+       # Load all subnets
+       &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%subnets);
+
+       # Remove the subnet
+       foreach my $key (keys %subnets) {
+                       if ($subnets{$key}[0] eq $name){
+                               delete $subnets{$key};
                        }
        }
-       &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash);
 
-       &writeserverconf;
+       # Write the subnets back
+       &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%subnets);
+
+       # Update the server configuration to remove routes
+       &writeserverconf();
+
        return 0;
 }