]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
wireguard.cgi: Don't allow creating RW connections if there is no address space
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 14 Aug 2024 16:23:55 +0000 (18:23 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Apr 2025 14:48:52 +0000 (16:48 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
html/cgi-bin/wireguard.cgi

index 8349fd6225409efd820f7558f80b3dee8fe60d48..d79f7b896b853ca5481be0730ae3933881b58323 100644 (file)
@@ -682,19 +682,36 @@ ADD:
        # Open a new box
        &Header::openbox('100%', '', $Lang::tr{'connection type'});
 
+       my %disabled = (
+               "host" => "",
+       );
+
+       # If there is no CLIENT_POOL configured, we disable the option
+       if ($settings{'CLIENT_POOL'} eq "") {
+               $disabled{"host"} = "disabled";
+
+       # If the client pool is out of addresses, we do the same
+       } else {
+               my @free_addresses = &free_pool_addresses($settings{'CLIENT_POOL'}, 1);
+
+               if (scalar @free_addresses == 0) {
+                       $disabled{"host"} = "disabled";
+               }
+       }
+
        print <<END;
                <form method="POST" ENCTYPE="multipart/form-data">
                        <ul>
                                <li>
                                        <label>
-                                               <input type='radio' name='TYPE' value='host' checked />
+                                               <input type='radio' name='TYPE' value='host' $disabled{'host'} />
                                                $Lang::tr{'host to net vpn'}
                                        </label>
                                </li>
 
                                <li>
                                        <label>
-                                               <input type='radio' name='TYPE' value='net' />
+                                               <input type='radio' name='TYPE' value='net' checked />
                                                $Lang::tr{'net to net vpn'}
                                        </label>
                                </li>