mirror of
https://github.com/opnsense/plugins.git
synced 2026-05-28 04:34:15 -04:00
net/wireguard: new plugin (#779)
(cherry picked from commit31a46df890) (cherry picked from commit68a0b0b46f) (cherry picked from commitafb93f56a6)
This commit is contained in:
parent
a697f541aa
commit
e0a2e9bd72
28 changed files with 1036 additions and 1 deletions
|
|
@ -44,7 +44,7 @@ misc/theme-tukan -- The tukan theme - blue/white
|
|||
net-mgmt/collectd -- Collect system and application performance metrics periodically
|
||||
net-mgmt/lldpd -- LLDP allows you to know exactly on which port is a server
|
||||
net-mgmt/net-snmp -- Net-SNMP is a daemon for the SNMP protocol
|
||||
net-mgmt/snmp -- SNMP Server via bsnmpd
|
||||
net-mgmt/snmp -- End of life, superseded by Net-SNMP plugin
|
||||
net-mgmt/telegraf -- Agent for collecting metrics and data
|
||||
net-mgmt/zabbix-agent -- Enterprise-class open source distributed monitoring agent
|
||||
net-mgmt/zabbix-proxy -- Zabbix Proxy enables decentralized monitoring
|
||||
|
|
@ -63,6 +63,7 @@ net/relayd -- Relayd Load Balancer
|
|||
net/shadowsocks -- Secure socks5 proxy
|
||||
net/siproxd -- Siproxd is a proxy daemon for the SIP protocol
|
||||
net/upnp -- Universal Plug and Play Service
|
||||
net/wireguard -- WireGuard VPN service
|
||||
net/wol -- Wake on LAN Service
|
||||
net/zerotier -- Virtual Networks That Just Work
|
||||
security/acme-client -- Let's Encrypt client
|
||||
|
|
|
|||
8
net/wireguard/Makefile
Normal file
8
net/wireguard/Makefile
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
PLUGIN_NAME= wireguard
|
||||
PLUGIN_VERSION= 0.1
|
||||
PLUGIN_COMMENT= WireGuard VPN service
|
||||
PLUGIN_DEPENDS= wireguard
|
||||
PLUGIN_MAINTAINER= m.muenz@gmail.com
|
||||
PLUGIN_DEVEL= yes
|
||||
|
||||
.include "../../Mk/plugins.mk"
|
||||
14
net/wireguard/pkg-descr
Normal file
14
net/wireguard/pkg-descr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
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/
|
||||
70
net/wireguard/src/etc/inc/plugins.inc.d/wireguard.inc
Normal file
70
net/wireguard/src/etc/inc/plugins.inc.d/wireguard.inc
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2018 Michael Muenz
|
||||
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 = array();
|
||||
|
||||
if (!wireguard_enabled()) {
|
||||
return $services;
|
||||
}
|
||||
|
||||
$services[] = array(
|
||||
'description' => gettext('Wireguard VPN'),
|
||||
'configd' => array(
|
||||
'restart' => array('wireguard restart'),
|
||||
'start' => array('wireguard start'),
|
||||
'stop' => array('wireguard stop'),
|
||||
),
|
||||
'name' => 'wireguard-go'
|
||||
);
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
function wireguard_interfaces()
|
||||
{
|
||||
$interfaces = array();
|
||||
if (!wireguard_enabled()) {
|
||||
return $interfaces;
|
||||
}
|
||||
$oic = array('enable' => true);
|
||||
$oic['if'] = 'wg';
|
||||
$oic['descr'] = 'WireGuard';
|
||||
$oic['type'] = 'group';
|
||||
$oic['virtual'] = true;
|
||||
$oic['networks'] = array();
|
||||
$interfaces['wg'] = $oic;
|
||||
return $interfaces;
|
||||
}
|
||||
45
net/wireguard/src/etc/rc.d/opnsense-wireguard
Executable file
45
net/wireguard/src/etc/rc.d/opnsense-wireguard
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# PROVIDE: opnsense-wireguard
|
||||
# REQUIRE: SERVERS
|
||||
# KEYWORD: shutdown
|
||||
#
|
||||
|
||||
. /etc/rc.subr
|
||||
|
||||
name=wireguard
|
||||
|
||||
stop_cmd=wireguard_stop
|
||||
start_cmd=wireguard_start
|
||||
status_cmd=wireguard_status
|
||||
rcvar=wireguard_enable
|
||||
|
||||
load_rc_config opnsense-wireguard
|
||||
command=/usr/local/bin/wg-quick
|
||||
|
||||
[ -z "$wireguard_enable" ] && wireguard_enable="NO"
|
||||
|
||||
# stop wireguard
|
||||
wireguard_stop()
|
||||
{
|
||||
echo "stopping wireguard"
|
||||
for STARTER in ${wireguard_config}; do
|
||||
$command down $STARTER
|
||||
ifconfig destroy $STARTER
|
||||
pkill -f wg-quick
|
||||
done
|
||||
}
|
||||
|
||||
# start wireguard
|
||||
wireguard_start()
|
||||
{
|
||||
echo "starting wireguard"
|
||||
for STARTER in ${wireguard_config}; do
|
||||
$command up $STARTER
|
||||
ifconfig $STARTER group wireguard
|
||||
done
|
||||
}
|
||||
|
||||
run_rc_command $1
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (C) 2018 Michael Muenz
|
||||
*
|
||||
* 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
|
||||
{
|
||||
static protected $internalModelName = 'client';
|
||||
static protected $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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2018 Michael Muenz
|
||||
*
|
||||
* 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 GeneralController extends ApiMutableModelControllerBase
|
||||
{
|
||||
static protected $internalModelClass = '\OPNsense\Wireguard\General';
|
||||
static protected $internalModelName = 'general';
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (C) 2018 Michael Muenz
|
||||
*
|
||||
* 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
|
||||
{
|
||||
static protected $internalModelName = 'server';
|
||||
static protected $internalModelClass = '\OPNsense\Wireguard\Server';
|
||||
|
||||
public function searchServerAction()
|
||||
{
|
||||
return $this->searchBase('servers.server', array("enabled", "name", "networks", "pubkey", "port", "tunneladdress"));
|
||||
}
|
||||
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 = $keyspriv;
|
||||
$node->pubkey = $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 = $keyspriv;
|
||||
$node->pubkey = $keyspub;
|
||||
}
|
||||
return $this->validateAndSave($node, 'server');
|
||||
}
|
||||
return array("result"=>"failed");
|
||||
}
|
||||
public function toggleServerAction($uuid)
|
||||
{
|
||||
return $this->toggleBase('servers.server', $uuid);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2018 Michael Muenz
|
||||
*
|
||||
* 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
|
||||
{
|
||||
static protected $internalServiceClass = '\OPNsense\Wireguard\General';
|
||||
static protected $internalServiceTemplate = 'OPNsense/Wireguard';
|
||||
static protected $internalServiceEnabled = 'enabled';
|
||||
static protected $internalServiceName = 'wireguard';
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2018 Michael Muenz
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<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.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>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>
|
||||
</form>
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
<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>Set the instance number needed for interface calculation. It has to be unique for each instance.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.pubkey</id>
|
||||
<label>Public Key</label>
|
||||
<type>info</type>
|
||||
<help>Public key of this instance. After saving you will see here your public key.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.privkey</id>
|
||||
<label>Private Key</label>
|
||||
<type>info</type>
|
||||
<help>Private key of this instance. After saving you will see here your public key, please keep it safe.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>server.port</id>
|
||||
<label>Listen Port</label>
|
||||
<type>text</type>
|
||||
<help>Set port for this instance to listen on.</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>
|
||||
</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
|
||||
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,36 @@
|
|||
<model>
|
||||
<mount>//OPNsense/wireguard/client</mount>
|
||||
<description>Wireguard Client configuration</description>
|
||||
<version>0.0.2</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,32}$/u</mask>
|
||||
<ValidationMessage>Should be a string between 1 and 32 characters. Allowed characters are 0-9a-zA-Z</ValidationMessage>
|
||||
</name>
|
||||
<pubkey type="TextField">
|
||||
<Required>N</Required>
|
||||
</pubkey>
|
||||
<tunneladdress type="NetworkField">
|
||||
<default></default>
|
||||
<FieldSeparator>,</FieldSeparator>
|
||||
<Required>Y</Required>
|
||||
<asList>Y</asList>
|
||||
</tunneladdress>
|
||||
<serveraddress type="NetworkField">
|
||||
<Required>N</Required>
|
||||
</serveraddress>
|
||||
<serverport type="PortField">
|
||||
<Required>N</Required>
|
||||
</serverport>
|
||||
</client>
|
||||
</clients>
|
||||
</items>
|
||||
</model>
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2018 Michael Muenz
|
||||
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="20" />
|
||||
</VPN>
|
||||
</menu>
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2018 Michael Muenz
|
||||
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
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<model>
|
||||
<mount>//OPNsense/wireguard/server</mount>
|
||||
<description>Wireguard Server configuration</description>
|
||||
<version>0.0.1</version>
|
||||
<items>
|
||||
<servers>
|
||||
<server 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,32}$/u</mask>
|
||||
<ValidationMessage>Should be a string between 1 and 32 characters. Allowed characters are 0-9a-zA-Z</ValidationMessage>
|
||||
</name>
|
||||
<instance type="AutoNumberField">
|
||||
<MinimumValue>0</MinimumValue>
|
||||
<MaximumValue>19</MaximumValue>
|
||||
<ValidationMessage>Maximum number of instances reached</ValidationMessage>
|
||||
<Required>Y</Required>
|
||||
</instance>
|
||||
<pubkey type="TextField">
|
||||
<Required>N</Required>
|
||||
</pubkey>
|
||||
<privkey type="TextField">
|
||||
<Required>N</Required>
|
||||
</privkey>
|
||||
<port type="PortField">
|
||||
<default>51820</default>
|
||||
<Required>Y</Required>
|
||||
</port>
|
||||
<tunneladdress type="NetworkField">
|
||||
<default></default>
|
||||
<FieldSeparator>,</FieldSeparator>
|
||||
<Required>Y</Required>
|
||||
<asList>Y</asList>
|
||||
</tunneladdress>
|
||||
<peers type="ModelRelationField">
|
||||
<Model>
|
||||
<template>
|
||||
<source>OPNsense.Wireguard.Client</source>
|
||||
<items>clients.client</items>
|
||||
<display>name</display>
|
||||
</template>
|
||||
</Model>
|
||||
<Multiple>Y</Multiple>
|
||||
<Required>N</Required>
|
||||
<ValidationMessage>Choose an Peer.</ValidationMessage>
|
||||
</peers>
|
||||
</server>
|
||||
</servers>
|
||||
</items>
|
||||
</model>
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
{#
|
||||
|
||||
OPNsense® is Copyright © 2014 – 2018 by Deciso B.V.
|
||||
This file is Copyright © 2018 by Michael Muenz
|
||||
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.
|
||||
|
||||
#}
|
||||
|
||||
<!-- Navigation bar -->
|
||||
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
|
||||
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#servers">{{ lang._('Server') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#clients">{{ lang._('Endpoints') }}</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content content-box tab-content">
|
||||
<div id="general" class="tab-pane fade in active">
|
||||
<div class="content-box" style="padding-bottom: 1.5em;">
|
||||
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}}
|
||||
<div class="col-md-12">
|
||||
<hr />
|
||||
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b><i id="saveAct_progress"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="clients" class="tab-pane fade in">
|
||||
<table id="grid-clients" class="table table-responsive" data-editDialog="dialogEditWireguardClient">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
|
||||
<th data-column-id="name" data-type="string" data-visible="true">{{ lang._('Name') }}</th>
|
||||
<th data-column-id="serveraddress" data-type="string" data-visible="true">{{ lang._('Endpoint Address') }}</th>
|
||||
<th data-column-id="tunneladdress" data-type="string" data-visible="true">{{ lang._('Tunnel Address') }}</th>
|
||||
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
|
||||
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="5"></td>
|
||||
<td>
|
||||
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div class="col-md-12">
|
||||
<hr />
|
||||
<button class="btn btn-primary" id="saveAct_client" type="button"><b>{{ lang._('Save') }}</b><i id="saveAct_client_progress"></i></button>
|
||||
<br /><br />
|
||||
</div>
|
||||
</div>
|
||||
<div id="servers" class="tab-pane fade in">
|
||||
<table id="grid-servers" class="table table-responsive" data-editDialog="dialogEditWireguardServer">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
|
||||
<th data-column-id="name" data-type="string" data-visible="true">{{ lang._('Name') }}</th>
|
||||
<th data-column-id="port" data-type="string" data-visible="true">{{ lang._('Port') }}</th>
|
||||
<th data-column-id="tunneladdress" data-type="string" data-visible="true">{{ lang._('Tunnel Address') }}</th>
|
||||
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
|
||||
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="5"></td>
|
||||
<td>
|
||||
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div class="col-md-12">
|
||||
<hr />
|
||||
<button class="btn btn-primary" id="saveAct_server" type="button"><b>{{ lang._('Save') }}</b><i id="saveAct_server_progress"></i></button>
|
||||
<br /><br />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogEditWireguardClient,'id':'dialogEditWireguardClient','label':lang._('Edit Endpoint')])}}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogEditWireguardServer,'id':'dialogEditWireguardServer','label':lang._('Edit Server')])}}
|
||||
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
var data_get_map = {'frm_general_settings':"/api/wireguard/general/get"};
|
||||
mapDataToFormUI(data_get_map).done(function(data){
|
||||
formatTokenizersUI();
|
||||
$('.selectpicker').selectpicker('refresh');
|
||||
});
|
||||
|
||||
$("#grid-clients").UIBootgrid(
|
||||
{ 'search':'/api/wireguard/client/searchClient',
|
||||
'get':'/api/wireguard/client/getClient/',
|
||||
'set':'/api/wireguard/client/setClient/',
|
||||
'add':'/api/wireguard/client/addClient/',
|
||||
'del':'/api/wireguard/client/delClient/',
|
||||
'toggle':'/api/wireguard/client/toggleClient/'
|
||||
}
|
||||
);
|
||||
|
||||
$("#grid-servers").UIBootgrid(
|
||||
{ 'search':'/api/wireguard/server/searchServer',
|
||||
'get':'/api/wireguard/server/getServer/',
|
||||
'set':'/api/wireguard/server/setServer/',
|
||||
'add':'/api/wireguard/server/addServer/',
|
||||
'del':'/api/wireguard/server/delServer/',
|
||||
'toggle':'/api/wireguard/server/toggleServer/'
|
||||
}
|
||||
);
|
||||
|
||||
$("#saveAct").click(function(){
|
||||
saveFormToEndpoint(url="/api/wireguard/general/set", formid='frm_general_settings',callback_ok=function(){
|
||||
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse");
|
||||
ajaxCall(url="/api/wireguard/service/reconfigure", sendData={}, callback=function(data,status) {
|
||||
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$("#saveAct_client").click(function(){
|
||||
saveFormToEndpoint(url="/api/wireguard/client/set", formid='frm_general_settings',callback_ok=function(){
|
||||
$("#saveAct_client_progress").addClass("fa fa-spinner fa-pulse");
|
||||
ajaxCall(url="/api/wireguard/service/reconfigure", sendData={}, callback=function(data,status) {
|
||||
$("#saveAct_client_progress").removeClass("fa fa-spinner fa-pulse");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$("#saveAct_server").click(function(){
|
||||
saveFormToEndpoint(url="/api/wireguard/server/set", formid='frm_general_settings',callback_ok=function(){
|
||||
$("#saveAct_server_progress").addClass("fa fa-spinner fa-pulse");
|
||||
ajaxCall(url="/api/wireguard/service/reconfigure", sendData={}, callback=function(data,status) {
|
||||
$("#saveAct_server_progress").removeClass("fa fa-spinner fa-pulse");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
55
net/wireguard/src/opnsense/scripts/OPNsense/Wireguard/genkey.sh
Executable file
55
net/wireguard/src/opnsense/scripts/OPNsense/Wireguard/genkey.sh
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Copyright (c) 2018 Michael Muenz <m.muenz@gmail.com>
|
||||
#
|
||||
# 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
|
||||
|
||||
TMPDIR="/tmp"
|
||||
GENPRIV="/usr/local/bin/wg genkey"
|
||||
GENPUB="/usr/local/bin/wg pubkey"
|
||||
|
||||
cleanup() {
|
||||
# Delete old files
|
||||
rm -f $TMPDIR/wireguard.*
|
||||
}
|
||||
|
||||
private() {
|
||||
# Generate a private key and put it to /tmp
|
||||
umask 077 && ${GENPRIV} | tee ${TMPDIR}/wireguard.priv
|
||||
}
|
||||
|
||||
public() {
|
||||
# Generate a public key and put it to /tmp
|
||||
${GENPUB} < ${TMPDIR}/wireguard.priv | tee ${TMPDIR}/wireguard.pub
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
private)
|
||||
cleanup
|
||||
private
|
||||
;;
|
||||
public)
|
||||
public
|
||||
;;
|
||||
esac
|
||||
4
net/wireguard/src/opnsense/scripts/OPNsense/Wireguard/setup.sh
Executable file
4
net/wireguard/src/opnsense/scripts/OPNsense/Wireguard/setup.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
mkdir -p /var/run/wireguard
|
||||
chmod 755 /var/run/wireguard
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
[start]
|
||||
command:/usr/local/opnsense/scripts/OPNsense/Wireguard/setup.sh;/usr/local/etc/rc.d/opnsense-wireguard start
|
||||
parameters:
|
||||
type:script
|
||||
message:starting Wireguard
|
||||
|
||||
[stop]
|
||||
command:/usr/local/etc/rc.d/opnsense-wireguard stop
|
||||
parameters:
|
||||
type:script
|
||||
message:stopping Wireguard
|
||||
|
||||
[restart]
|
||||
command:/usr/local/opnsense/scripts/OPNsense/Wireguard/setup.sh;/usr/local/etc/rc.d/opnsense-wireguard restart
|
||||
parameters:
|
||||
type:script
|
||||
message:restarting Wireguard
|
||||
|
||||
[genkey]
|
||||
command:/usr/local/opnsense/scripts/OPNsense/Wireguard/genkey.sh
|
||||
parameters: %s
|
||||
type:script_output
|
||||
message:generating Wireguard keys
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
opnsense-wireguard:/etc/rc.conf.d/opnsense-wireguard
|
||||
wireguard-server.conf:/usr/local/etc/wireguard/wg[OPNsense.wireguard.server.servers.server.%.instance].conf
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
{% if helpers.exists('OPNsense.wireguard.general.enabled') and OPNsense.wireguard.general.enabled == '1' %}
|
||||
wireguard_var_script="/usr/local/opnsense/scripts/OPNsense/Wireguard/setup.sh"
|
||||
wireguard_enable="YES"
|
||||
{% if helpers.exists('OPNsense.wireguard.server.servers.server') %}
|
||||
{% set activeservers=[] %}
|
||||
{% for servers in helpers.toList('OPNsense.wireguard.server.servers.server') %}
|
||||
{% if servers.enabled == '1' %}
|
||||
{% do activeservers.append("wg" + servers.instance) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
wireguard_config="{{ activeservers | join(' ') }}"
|
||||
{% else %}
|
||||
wireguard_enable="NO"
|
||||
{% endif %}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
{% if helpers.exists('OPNsense.wireguard.general.enabled') and OPNsense.wireguard.general.enabled == '1' %}
|
||||
|
||||
{% if helpers.exists('OPNsense.wireguard.server.servers.server') %}
|
||||
{% for server_list in helpers.toList('OPNsense.wireguard.server.servers.server') %}
|
||||
{% if TARGET_FILTERS['OPNsense.wireguard.server.servers.server.' ~ loop.index0] or TARGET_FILTERS['OPNsense.wireguard.server.servers.server'] %}
|
||||
{% if server_list.enabled == '1' %}
|
||||
[Interface]
|
||||
Address = {{ server_list.tunneladdress }}
|
||||
PrivateKey = {{ server_list.privkey }}
|
||||
ListenPort = {{ server_list.port }}
|
||||
{% if server_list.peers|default('') != '' %}
|
||||
{% for peerlist in server_list.peers.split(",") %}
|
||||
{% set peerlist2_data = helpers.getUUID(peerlist) %}
|
||||
{% if peerlist2_data != {} and peerlist2_data.enabled == '1' %}
|
||||
[Peer]
|
||||
PublicKey = {{ peerlist2_data.pubkey }}
|
||||
AllowedIPs = {{ peerlist2_data.tunneladdress }}
|
||||
{% if peerlist2_data.serveraddress|default('') != '' %}
|
||||
Endpoint = {{ peerlist2_data.serveraddress }}:{{ peerlist2_data.serverport }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
Loading…
Reference in a new issue