wireguard: Show next available client IP in Add Client form

Display the next available IP address that will be
automatically assigned when adding a new client.

Helps admins know what client IP to provide when configuring client
connections back to this server.

Signed-off-by: Frederico Gomes <fredericojfgomes@gmail.com>
[sunil: Turn the IP address styling into a form element]
[sunil: Update the comment style for consistency]
[sunil: Update the label for clarity]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Frederico Gomes 2026-01-26 12:39:19 +00:00 committed by Sunil Mohan Adapa
parent 0fa77cbe30
commit b0a841c63a
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 22 additions and 0 deletions

View File

@ -15,6 +15,18 @@
{{ form|bootstrap }}
{% if next_ip %}
<div class="form-group">
<label for="id_next_ip" class="control-label">
{% trans "IP address that will be assigned to this client" %}
</label>
<div>
<input type="text" id="id_next_ip" class="form-control"
value="{{ next_ip }}" disabled="disabled">
</div>
</div>
{% endif %}
<input type="submit" class="btn btn-primary"
value="{% trans "Add Client" %}"/>
</form>

View File

@ -46,6 +46,16 @@ class AddClientView(SuccessMessageMixin, FormView):
"""Return additional context for rendering the template."""
context = super().get_context_data(**kwargs)
context['title'] = _('Add Allowed Client')
# Show next available IP.
try:
connection = utils._server_connection()
setting_name = utils.nm.SETTING_WIREGUARD_SETTING_NAME
settings = connection.get_setting_by_name(setting_name)
context['next_ip'] = utils._get_next_available_ip_address(settings)
except Exception:
context['next_ip'] = None
return context
def form_valid(self, form):