mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
net/wireguard-go: make a copy in preparation for kmod improvements
The Go variant will be phased out in 24.1, but for 23.7.x it is retained as such. The kmod variant will be improved and rewritten to not require wg-quick so it might eventually move into the core.
This commit is contained in:
@@ -66,7 +66,8 @@ net/tayga -- Tayga NAT64
|
||||
net/udpbroadcastrelay -- Control ubpbroadcastrelay processes
|
||||
net/upnp -- Universal Plug and Play Service
|
||||
net/vnstat -- Network traffic monitor
|
||||
net/wireguard -- WireGuard VPN service
|
||||
net/wireguard -- WireGuard VPN service kernel implementation
|
||||
net/wireguard-go -- WireGuard VPN service Go implementation (pending removal)
|
||||
net/wol -- Wake on LAN Service
|
||||
net/zerotier -- Virtual Networks That Just Work
|
||||
net-mgmt/collectd -- Collect system and application performance metrics periodically
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
PLUGIN_NAME= wireguard-go
|
||||
PLUGIN_VERSION= 1.13
|
||||
PLUGIN_REVISION= 7
|
||||
PLUGIN_COMMENT= WireGuard VPN service Go implementation
|
||||
PLUGIN_CONFLICTS= wireguard
|
||||
PLUGIN_OBSOLETE= yes
|
||||
PLUGIN_DEPENDS= wireguard-go wireguard-tools
|
||||
PLUGIN_MAINTAINER= m.muenz@gmail.com
|
||||
|
||||
.include "../../Mk/plugins.mk"
|
||||
@@ -0,0 +1,78 @@
|
||||
WireGuard® is an extremely simple yet fast and modern VPN
|
||||
that utilizes state-of-the-art cryptography. It aims to be
|
||||
faster, simpler, leaner, and more useful than IPSec, while
|
||||
avoiding the massive headache. It intends to be considerably
|
||||
more performant than OpenVPN. WireGuard is designed as a
|
||||
general purpose VPN for running on embedded interfaces and
|
||||
super computers alike, fit for many different circumstances.
|
||||
Initially released for the Linux kernel, it is now
|
||||
cross-platform and widely deployable. It is currently under
|
||||
heavy development, but already it might be regarded as the
|
||||
most secure, easiest to use, and simplest VPN solution in
|
||||
the industry.
|
||||
|
||||
WWW: https://www.wireguard.com/
|
||||
|
||||
Changelog
|
||||
---------
|
||||
|
||||
1.13
|
||||
|
||||
* Reworked widget and assorted cleanups (contributed by Patrik Kernstock)
|
||||
* Improve widget public key overlapping (contributed by Victor Haggqvist)
|
||||
|
||||
1.12
|
||||
|
||||
* Adjust validation for naming local instance and endpoints
|
||||
|
||||
1.11
|
||||
|
||||
* Add script for renewal of Wireguard DNS-based entries for stale connections (#2956)
|
||||
* Trim whitespace around new public and private keys in config (#2982)
|
||||
|
||||
1.10
|
||||
|
||||
* Remove instance limit
|
||||
|
||||
1.9
|
||||
|
||||
* Rename interface label in filter rules (#2577)
|
||||
|
||||
1.8
|
||||
|
||||
* Empty port in Endpoint is allowed
|
||||
|
||||
1.7
|
||||
|
||||
* Make tunnel address (wg interface address) optional
|
||||
|
||||
1.6
|
||||
|
||||
* Move DNS setting to advanced
|
||||
* Make listen port optional
|
||||
|
||||
1.5
|
||||
|
||||
* Allow synchronization of config
|
||||
|
||||
1.4
|
||||
|
||||
* Add IPv6 gateway support (contributed by Alexander Korinek)
|
||||
|
||||
1.3
|
||||
|
||||
* Client/peer name validation to use HostnameField
|
||||
|
||||
1.2
|
||||
|
||||
* Dashboard widget (contributed by D. Domig)
|
||||
|
||||
1.1
|
||||
|
||||
* Allow adding interface route for PBR
|
||||
|
||||
1.0
|
||||
|
||||
* Support for most features like S2S, Roadwarrior
|
||||
* DNS, MTU, PSK
|
||||
* Allow to disable setting routes for PBR
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
function wireguard_enabled()
|
||||
{
|
||||
$model = new \OPNsense\Wireguard\General();
|
||||
return (string)$model->enabled == '1';
|
||||
}
|
||||
|
||||
function wireguard_services()
|
||||
{
|
||||
$services = [];
|
||||
|
||||
if (!wireguard_enabled()) {
|
||||
return $services;
|
||||
}
|
||||
|
||||
$service = [
|
||||
'description' => gettext('WireGuard VPN'),
|
||||
'configd' => [
|
||||
'restart' => ['wireguard restart'],
|
||||
'start' => ['wireguard start'],
|
||||
'stop' => ['wireguard stop'],
|
||||
],
|
||||
'name' => 'wireguard-go',
|
||||
];
|
||||
|
||||
if (file_exists('/boot/modules/if_wg.ko') || file_exists('/boot/kernel/if_wg.ko')) {
|
||||
$service['name'] = 'wireguard';
|
||||
$service['nocheck'] = true;
|
||||
}
|
||||
|
||||
$services[] = $service;
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
function wireguard_interfaces()
|
||||
{
|
||||
$interfaces = [];
|
||||
|
||||
if (!wireguard_enabled()) {
|
||||
return $interfaces;
|
||||
}
|
||||
|
||||
$interfaces['wireguard'] = [
|
||||
'descr' => gettext('WireGuard (Group)'),
|
||||
'if' => 'wireguard',
|
||||
'virtual' => true,
|
||||
'enable' => true,
|
||||
'type' => 'group',
|
||||
'networks' => [],
|
||||
];
|
||||
|
||||
return $interfaces;
|
||||
}
|
||||
|
||||
function wireguard_xmlrpc_sync()
|
||||
{
|
||||
$result = [];
|
||||
|
||||
$result['id'] = 'wireguard';
|
||||
$result['section'] = 'OPNsense.wireguard';
|
||||
$result['description'] = gettext('WireGuard');
|
||||
$result['services'] = ['wireguard-go'];
|
||||
|
||||
if (file_exists('/boot/modules/if_wg.ko') || file_exists('/boot/kernel/if_wg.ko')) {
|
||||
$result['services'] = ['wireguard'];
|
||||
}
|
||||
|
||||
return [$result];
|
||||
}
|
||||
|
||||
function wireguard_devices()
|
||||
{
|
||||
return [['pattern' => '^wg', 'volatile' => true]];
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
# start again to fix problems with failed name resolution (no need to restart)
|
||||
configctl -dq wireguard start
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OPNsense\Wireguard\Api;
|
||||
|
||||
use OPNsense\Base\ApiMutableModelControllerBase;
|
||||
|
||||
class ClientController extends ApiMutableModelControllerBase
|
||||
{
|
||||
protected static $internalModelName = 'client';
|
||||
protected static $internalModelClass = '\OPNsense\Wireguard\Client';
|
||||
|
||||
public function searchClientAction()
|
||||
{
|
||||
return $this->searchBase('clients.client', array("enabled", "name", "pubkey", "tunneladdress", "serveraddress", "serverport"));
|
||||
}
|
||||
|
||||
public function getClientAction($uuid = null)
|
||||
{
|
||||
$this->sessionClose();
|
||||
return $this->getBase('client', 'clients.client', $uuid);
|
||||
}
|
||||
|
||||
public function addClientAction()
|
||||
{
|
||||
return $this->addBase('client', 'clients.client');
|
||||
}
|
||||
|
||||
public function delClientAction($uuid)
|
||||
{
|
||||
return $this->delBase('clients.client', $uuid);
|
||||
}
|
||||
|
||||
public function setClientAction($uuid)
|
||||
{
|
||||
return $this->setBase('client', 'clients.client', $uuid);
|
||||
}
|
||||
|
||||
public function toggleClientAction($uuid)
|
||||
{
|
||||
return $this->toggleBase('clients.client', $uuid);
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
* Copyright (C) 2022 Patrik Kernstock <patrik@kernstock.net>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OPNsense\Wireguard\Api;
|
||||
|
||||
use OPNsense\Base\ApiMutableModelControllerBase;
|
||||
use OPNsense\Core\Config;
|
||||
use OPNsense\Core\Backend;
|
||||
|
||||
class GeneralController extends ApiMutableModelControllerBase
|
||||
{
|
||||
protected static $internalModelClass = '\OPNsense\Wireguard\General';
|
||||
protected static $internalModelName = 'general';
|
||||
|
||||
public function getStatusAction()
|
||||
{
|
||||
// get wireguard configuration
|
||||
$config = Config::getInstance()->object();
|
||||
$config = $config->OPNsense->wireguard;
|
||||
|
||||
// craft peers array
|
||||
$peers = [];
|
||||
$peers_uuid_pubkey = [];
|
||||
// enabled, name, pubkey
|
||||
foreach ($config->client->clients->client as $client) {
|
||||
$peerUuid = (string)$client->attributes()['uuid'];
|
||||
$peers_uuid_pubkey[$peerUuid] = (string) $client->pubkey;
|
||||
$peers[$peerUuid] = [
|
||||
"name" => (string) $client->name,
|
||||
"enabled" => (int) $client->enabled,
|
||||
"publicKey" => (string) $client->pubkey,
|
||||
];
|
||||
}
|
||||
|
||||
// prepare and initialize the server array
|
||||
$status = [];
|
||||
$peer_pubkey_reference = [];
|
||||
foreach ($config->server->servers->server as $server) {
|
||||
if ($server->enabled != "1") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// build basic server array
|
||||
$interface = "wg" . $server->instance;
|
||||
$status[$interface] = [
|
||||
"instance" => (int) $server->instance,
|
||||
"interface" => (string) $interface,
|
||||
"enabled" => (int) $server->enabled,
|
||||
"name" => (string) $server->name,
|
||||
"peers" => [],
|
||||
];
|
||||
|
||||
// parse and add peers with initial values to array
|
||||
if (strlen($server->peers) > 0) {
|
||||
// there is at least one peer defined
|
||||
$serverPeers = explode(",", (string) $server->peers);
|
||||
// iteriate over each peer uuid
|
||||
foreach ($serverPeers as $peerUuid) {
|
||||
// skipping removed peer that is still referenced in server
|
||||
if (!isset($peers[$peerUuid])) {
|
||||
continue;
|
||||
}
|
||||
// remember interface and pubkey <> peer-uuid reference for referencing handshake logic below
|
||||
$peer_pubkey_reference[$interface][$peers_uuid_pubkey[$peerUuid]] = $peerUuid;
|
||||
// merge peer info and initial values for handshake data
|
||||
$status[$interface]["peers"][$peerUuid] = array_merge(
|
||||
$peers[$peerUuid],
|
||||
[
|
||||
"lastHandshake" => "0000-00-00 00:00:00+00:00",
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get latest handshakes by running CLI command locally
|
||||
$data = (new Backend())->configdRun("wireguard showhandshake");
|
||||
|
||||
// parse and set handshake to status datastructure
|
||||
$data = trim($data);
|
||||
if (strlen($data) !== 0) {
|
||||
$wgHandshakes = explode("\n", $data);
|
||||
foreach ($wgHandshakes as $handshake) {
|
||||
$item = explode("\t", trim($handshake));
|
||||
|
||||
// set interface name and publickey
|
||||
$interface = trim($item[0]);
|
||||
$pubkey = trim($item[1]);
|
||||
|
||||
// calculate handshake time based on local timezone
|
||||
$epoch = $item[2];
|
||||
if ($epoch > 0) {
|
||||
$dt = new \DateTime("@$epoch");
|
||||
$dt->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
$latest = $dt->format("Y-m-d H:i:sP");
|
||||
|
||||
// set handshake
|
||||
$peerUuid = $peer_pubkey_reference[$interface][$pubkey];
|
||||
if (!empty($peerUuid)) {
|
||||
$status[$interface]["peers"][$peerUuid]["lastHandshake"] = $latest;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
"items" => $status
|
||||
];
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace OPNsense\Wireguard\Api;
|
||||
|
||||
use OPNsense\Base\ApiMutableModelControllerBase;
|
||||
use OPNsense\Core\Backend;
|
||||
|
||||
class ServerController extends ApiMutableModelControllerBase
|
||||
{
|
||||
protected static $internalModelName = 'server';
|
||||
protected static $internalModelClass = '\OPNsense\Wireguard\Server';
|
||||
|
||||
public function searchServerAction()
|
||||
{
|
||||
$search = $this->searchBase('servers.server', array("enabled", "instance", "peers", "name", "networks", "pubkey", "port", "tunneladdress"));
|
||||
// prepend "wg" to all instance IDs to use as interface name
|
||||
foreach ($search["rows"] as $key => $server) {
|
||||
$search["rows"][$key]["interface"] = "wg" . $server["instance"];
|
||||
}
|
||||
return $search;
|
||||
}
|
||||
|
||||
public function getServerAction($uuid = null)
|
||||
{
|
||||
$this->sessionClose();
|
||||
return $this->getBase('server', 'servers.server', $uuid);
|
||||
}
|
||||
|
||||
public function addServerAction($uuid = null)
|
||||
{
|
||||
if ($this->request->isPost() && $this->request->hasPost("server")) {
|
||||
if ($uuid != null) {
|
||||
$node = $this->getModel()->getNodeByReference('servers.server.' . $uuid);
|
||||
} else {
|
||||
$node = $this->getModel()->servers->server->Add();
|
||||
}
|
||||
$node->setNodes($this->request->getPost("server"));
|
||||
if (empty((string)$node->pubkey) && empty((string)$node->privkey)) {
|
||||
// generate new keypair
|
||||
$backend = new Backend();
|
||||
$keyspriv = $backend->configdpRun("wireguard genkey", 'private');
|
||||
$keyspub = $backend->configdpRun("wireguard genkey", 'public');
|
||||
$node->privkey = trim($keyspriv);
|
||||
$node->pubkey = trim($keyspub);
|
||||
}
|
||||
return $this->validateAndSave($node, 'server');
|
||||
}
|
||||
return array("result" => "failed");
|
||||
}
|
||||
|
||||
public function delServerAction($uuid)
|
||||
{
|
||||
return $this->delBase('servers.server', $uuid);
|
||||
}
|
||||
|
||||
public function setServerAction($uuid = null)
|
||||
{
|
||||
if ($this->request->isPost() && $this->request->hasPost("server")) {
|
||||
if ($uuid != null) {
|
||||
$node = $this->getModel()->getNodeByReference('servers.server.' . $uuid);
|
||||
} else {
|
||||
$node = $this->getModel()->servers->server->Add();
|
||||
}
|
||||
$node->setNodes($this->request->getPost("server"));
|
||||
if (empty((string)$node->pubkey) && empty((string)$node->privkey)) {
|
||||
// generate new keypair
|
||||
$backend = new Backend();
|
||||
$keyspriv = $backend->configdpRun("wireguard genkey", 'private');
|
||||
$keyspub = $backend->configdpRun("wireguard genkey", 'public');
|
||||
$node->privkey = trim($keyspriv);
|
||||
$node->pubkey = trim($keyspub);
|
||||
}
|
||||
return $this->validateAndSave($node, 'server');
|
||||
}
|
||||
return array("result" => "failed");
|
||||
}
|
||||
|
||||
public function toggleServerAction($uuid)
|
||||
{
|
||||
return $this->toggleBase('servers.server', $uuid);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace OPNsense\Wireguard\Api;
|
||||
|
||||
use OPNsense\Base\ApiMutableServiceControllerBase;
|
||||
use OPNsense\Core\Backend;
|
||||
use OPNsense\Wireguard\General;
|
||||
|
||||
/**
|
||||
* Class ServiceController
|
||||
* @package OPNsense\Wireguard
|
||||
*/
|
||||
class ServiceController extends ApiMutableServiceControllerBase
|
||||
{
|
||||
protected static $internalServiceClass = '\OPNsense\Wireguard\General';
|
||||
protected static $internalServiceTemplate = 'OPNsense/Wireguard';
|
||||
protected static $internalServiceEnabled = 'enabled';
|
||||
protected static $internalServiceName = 'wireguard';
|
||||
|
||||
/**
|
||||
* hook group interface registration on reconfigure
|
||||
* @return bool
|
||||
*/
|
||||
protected function invokeInterfaceRegistration()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* show wireguard config
|
||||
* @return array
|
||||
*/
|
||||
public function showconfAction()
|
||||
{
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun("wireguard showconf");
|
||||
return array("response" => $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* show wireguard handshakes
|
||||
* @return array
|
||||
*/
|
||||
public function showhandshakeAction()
|
||||
{
|
||||
$backend = new Backend();
|
||||
$response = $backend->configdRun("wireguard showhandshake");
|
||||
return array("response" => $response);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace OPNsense\Wireguard;
|
||||
|
||||
class GeneralController extends \OPNsense\Base\IndexController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->generalForm = $this->getForm("general");
|
||||
$this->view->formDialogEditWireguardClient = $this->getForm("dialogEditWireguardClient");
|
||||
$this->view->formDialogEditWireguardServer = $this->getForm("dialogEditWireguardServer");
|
||||
$this->view->pick('OPNsense/Wireguard/general');
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<form>
|
||||
<field>
|
||||
<id>client.enabled</id>
|
||||
<label>Enabled</label>
|
||||
<type>checkbox</type>
|
||||
<help>This will enable or disable the client config.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>client.name</id>
|
||||
<label>Name</label>
|
||||
<type>text</type>
|
||||
<help>Set the name for this instance.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>client.pubkey</id>
|
||||
<label>Public Key</label>
|
||||
<type>text</type>
|
||||
<help>Public key of this instance.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>client.psk</id>
|
||||
<label>Shared Secret</label>
|
||||
<type>text</type>
|
||||
<help>Shared secret (PSK) for this peer. You can generate a key using "wg genpsk" on a client with WireGuard installed.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>client.tunneladdress</id>
|
||||
<label>Allowed IPs</label>
|
||||
<style>tokenize</style>
|
||||
<type>select_multiple</type>
|
||||
<allownew>true</allownew>
|
||||
<help>List of addresses allowed to pass trough the tunnel adapter. Please use CIDR notation like 10.0.0.1/24.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>client.serveraddress</id>
|
||||
<label>Endpoint Address</label>
|
||||
<type>text</type>
|
||||
<help>Set public IP address the endpoint listens to.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>client.serverport</id>
|
||||
<label>Endpoint Port</label>
|
||||
<type>text</type>
|
||||
<help>Set port the endpoint listens to.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>client.keepalive</id>
|
||||
<label>Keepalive Interval</label>
|
||||
<type>text</type>
|
||||
<help>Set persistent keepalive interval in seconds.</help>
|
||||
</field>
|
||||
</form>
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
<form>
|
||||
<field>
|
||||
<id>server.enabled</id>
|
||||
<label>Enabled</label>
|
||||
<type>checkbox</type>
|
||||
<help>This will enable or disable the server config.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.name</id>
|
||||
<label>Name</label>
|
||||
<type>text</type>
|
||||
<help>Set the name for this instance.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.instance</id>
|
||||
<label>Instance</label>
|
||||
<type>info</type>
|
||||
<help>This is the instance number to give the wg interface a unique name (wgX).</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.pubkey</id>
|
||||
<label>Public Key</label>
|
||||
<type>text</type>
|
||||
<help>Public key of this instance. You can specify your own one, or a key will be generated after saving.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.privkey</id>
|
||||
<label>Private Key</label>
|
||||
<type>text</type>
|
||||
<help>Private key of this instance. You can specify your own one, or a key will be generated after saving. Please keep this key safe.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.port</id>
|
||||
<label>Listen Port</label>
|
||||
<type>text</type>
|
||||
<help>Optionally set a fixed port for this instance to listen on. The standard port range starts at 51820.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.mtu</id>
|
||||
<label>MTU</label>
|
||||
<type>text</type>
|
||||
<advanced>true</advanced>
|
||||
<help>Set the interface MTU for this interface. Leaving empty uses the MTU from main interface which is fine for most setups.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.dns</id>
|
||||
<label>DNS Server</label>
|
||||
<type>select_multiple</type>
|
||||
<style>tokenize</style>
|
||||
<allownew>true</allownew>
|
||||
<advanced>true</advanced>
|
||||
<help>Set the interface specific DNS server.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.tunneladdress</id>
|
||||
<label>Tunnel Address</label>
|
||||
<style>tokenize</style>
|
||||
<type>select_multiple</type>
|
||||
<allownew>true</allownew>
|
||||
<help>List of addresses to configure on the tunnel adapter. Please use CIDR notation like 10.0.0.1/24.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.peers</id>
|
||||
<label>Peers</label>
|
||||
<type>select_multiple</type>
|
||||
<allownew>true</allownew>
|
||||
<help>List of peers for this server.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.disableroutes</id>
|
||||
<label>Disable Routes</label>
|
||||
<type>checkbox</type>
|
||||
<help>This will prevent installing routes. Usually you only enable this to do own routing decisions via a local gateway and gateway rules.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.gateway</id>
|
||||
<label>Gateway</label>
|
||||
<type>text</type>
|
||||
<advanced>true</advanced>
|
||||
<help>Set the gateway IP here when using Disable Routes feature. You also have to add this as a gateway in OPNsense.</help>
|
||||
</field>
|
||||
</form>
|
||||
@@ -0,0 +1,8 @@
|
||||
<form>
|
||||
<field>
|
||||
<id>general.enabled</id>
|
||||
<label>Enable WireGuard</label>
|
||||
<type>checkbox</type>
|
||||
<help>This will activate WireGuard and start all enabled instances.</help>
|
||||
</field>
|
||||
</form>
|
||||
@@ -0,0 +1,9 @@
|
||||
<acl>
|
||||
<page-wireguard-config>
|
||||
<name>VPN: Wireguard</name>
|
||||
<patterns>
|
||||
<pattern>ui/wireguard/*</pattern>
|
||||
<pattern>api/wireguard/*</pattern>
|
||||
</patterns>
|
||||
</page-wireguard-config>
|
||||
</acl>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace OPNsense\Wireguard;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
|
||||
class Client extends BaseModel
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<model>
|
||||
<mount>//OPNsense/wireguard/client</mount>
|
||||
<description>Wireguard Client configuration</description>
|
||||
<version>0.0.7</version>
|
||||
<items>
|
||||
<clients>
|
||||
<client type="ArrayField">
|
||||
<enabled type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>Y</Required>
|
||||
</enabled>
|
||||
<name type="TextField">
|
||||
<default></default>
|
||||
<Required>Y</Required>
|
||||
<mask>/^([0-9a-zA-Z._\-]){1,64}$/u</mask>
|
||||
<ValidationMessage>Should be a string between 1 and 64 characters. Allowed characters are alphanumeric characters, dash and underscores.</ValidationMessage>
|
||||
</name>
|
||||
<pubkey type="Base64Field">
|
||||
<Required>Y</Required>
|
||||
<ValidationMessage>Should be a base64-encoded 32 byte string.</ValidationMessage>
|
||||
</pubkey>
|
||||
<psk type="Base64Field">
|
||||
<Required>N</Required>
|
||||
<ValidationMessage>Should be a base64-encoded 32 byte string.</ValidationMessage>
|
||||
</psk>
|
||||
<tunneladdress type="NetworkField">
|
||||
<default></default>
|
||||
<FieldSeparator>,</FieldSeparator>
|
||||
<Required>Y</Required>
|
||||
<asList>Y</asList>
|
||||
</tunneladdress>
|
||||
<serveraddress type="HostnameField">
|
||||
<Required>N</Required>
|
||||
</serveraddress>
|
||||
<serverport type="PortField">
|
||||
<Required>N</Required>
|
||||
</serverport>
|
||||
<keepalive type="IntegerField">
|
||||
<MinimumValue>1</MinimumValue>
|
||||
<MaximumValue>86400</MaximumValue>
|
||||
<ValidationMessage>Please specify a value between 1 and 86400.</ValidationMessage>
|
||||
<Required>N</Required>
|
||||
</keepalive>
|
||||
</client>
|
||||
</clients>
|
||||
</items>
|
||||
</model>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace OPNsense\Wireguard;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
|
||||
class General extends BaseModel
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<model>
|
||||
<mount>//OPNsense/wireguard/general</mount>
|
||||
<description>WireGuard configuration</description>
|
||||
<version>0.0.1</version>
|
||||
<items>
|
||||
<enabled type="BooleanField">
|
||||
<default>0</default>
|
||||
<Required>Y</Required>
|
||||
</enabled>
|
||||
</items>
|
||||
</model>
|
||||
@@ -0,0 +1,5 @@
|
||||
<menu>
|
||||
<VPN>
|
||||
<WireGuard cssClass="fa fa-lock fa-fw" url="/ui/wireguard/general/index" order="150" />
|
||||
</VPN>
|
||||
</menu>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace OPNsense\Wireguard;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
|
||||
class Server extends BaseModel
|
||||
{
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user