mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
wireguard: Implement adding client
Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
8 files changed
+164
-4
No files matched your search
@@ -18,6 +18,7 @@
|
||||
FreedomBox app for wireguard.
|
||||
"""
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from plinth import app as app_module
|
||||
@@ -71,8 +72,9 @@ class WireguardApp(app_module.App):
|
||||
|
||||
shortcut = frontpage.Shortcut(
|
||||
'shortcut-wireguard', name, short_description=short_description,
|
||||
icon='wireguard', url='/wireguard', clients=clients,
|
||||
login_required=True)
|
||||
icon='wireguard', description=description,
|
||||
configure_url=reverse_lazy('wireguard:index'), login_required=True,
|
||||
clients=clients)
|
||||
self.add(shortcut)
|
||||
|
||||
firewall = Firewall('firewall-wireguard', name,
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
Forms for wireguard module.
|
||||
"""
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class AddClientForm(forms.Form):
|
||||
"""Form to add client."""
|
||||
public_key = forms.CharField(
|
||||
label=_('Public Key'), strip=True,
|
||||
help_text=_('Public key of the peer.'))
|
||||
@@ -33,7 +33,8 @@ clients = validate([{
|
||||
'os':
|
||||
'windows',
|
||||
'url':
|
||||
'https://download.wireguard.com/windows-client/wireguard-amd64-0.0.23.msi'
|
||||
'https://download.wireguard.com/windows-client/'
|
||||
'wireguard-amd64-0.0.23.msi'
|
||||
}, {
|
||||
'type':
|
||||
'download',
|
||||
|
||||
@@ -27,7 +27,12 @@
|
||||
<ul>{% trans "public key" %}</ul>
|
||||
<ul>{% trans "last connected time" %}</ul>
|
||||
<ul>{% trans "edit" %}</ul>
|
||||
<ul>{% trans "Add Client" %}</ul>
|
||||
<a title="{% trans 'Add a new peer' %}"
|
||||
role="button" class="btn btn-default"
|
||||
href="{% url 'wireguard:add-client' %}">
|
||||
<span class="fa fa-plus" aria-hidden="true"></span>
|
||||
{% trans "Add Client" %}
|
||||
</a>
|
||||
|
||||
<h3>{% trans "Client" %}</h3>
|
||||
<p>{% trans "Peer servers that FreedomBox will connect to" %}</p>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
{% endcomment %}
|
||||
|
||||
{% load bootstrap %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>{{ title }}</h3>
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
{{ form|bootstrap }}
|
||||
|
||||
<input type="submit" class="btn btn-primary"
|
||||
value="{% trans "Add Client" %}"/>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@@ -24,4 +24,6 @@ from plinth.modules.wireguard import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^apps/wireguard/$', views.WireguardView.as_view(), name='index'),
|
||||
url(r'^apps/wireguard/client/add/$', views.AddClientView.as_view(),
|
||||
name='add-client')
|
||||
]
|
||||
@@ -18,9 +18,17 @@
|
||||
Views for WireGuard application.
|
||||
"""
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import FormView
|
||||
|
||||
import plinth.modules.wireguard as wireguard
|
||||
from plinth import actions
|
||||
from plinth.views import AppView
|
||||
|
||||
from . import forms
|
||||
|
||||
|
||||
class WireguardView(AppView):
|
||||
"""Serve configuration page."""
|
||||
@@ -32,3 +40,22 @@ class WireguardView(AppView):
|
||||
show_status_block = False
|
||||
template_name = 'wireguard.html'
|
||||
port_forwarding_info = wireguard.port_forwarding_info
|
||||
|
||||
|
||||
class AddClientView(SuccessMessageMixin, FormView):
|
||||
"""View to add a client."""
|
||||
form_class = forms.AddClientForm
|
||||
template_name = 'wireguard_add_client.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Return additional context for rendering the template."""
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['title'] = _('Add Client')
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Add the client."""
|
||||
public_key = form.cleaned_data.get('public_key')
|
||||
actions.superuser_run(
|
||||
'wireguard', ['add-client', public_key])
|
||||
messages.success(self.request, _('Added new client.'))
|
||||
Reference in new issue
Block a user